Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions patchwork-dispatcher/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
archivesBaseName = "patchwork-dispatcher"
version = getSubprojectVersion(project, "0.2.0")
version = getSubprojectVersion(project, "0.3.0")

dependencies {
compile project(path: ':patchwork-fml', configuration: 'dev')
compile project(path: ':patchwork-registries', configuration: 'dev')
compile project(path: ':patchwork-events-lifecycle', configuration: 'dev')
compile project(path: ':patchwork-client-colors', configuration: 'dev')
compile project(path: ':patchwork-events-rendering', configuration: 'dev')
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import net.fabricmc.loader.api.FabricLoader;

import net.patchworkmc.api.ForgeInitializer;
import net.patchworkmc.impl.event.colors.ColorEvents;
import net.patchworkmc.impl.event.render.RenderEvents;
import net.patchworkmc.impl.registries.RegistryEventDispatcher;

public class Patchwork implements ModInitializer {
Expand Down Expand Up @@ -120,7 +120,7 @@ public void onInitialize() {

DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> {
dispatch(mods, container -> new FMLClientSetupEvent(MinecraftClient::getInstance, container));
ColorEvents.registerEventDispatcher(event -> dispatch(mods, event));
RenderEvents.registerEventDispatcher(event -> dispatch(mods, event));
});

DistExecutor.runWhenOn(Dist.DEDICATED_SERVER, () -> () -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Minecraft Forge, Patchwork Project
* Copyright (c) 2016-2020, 2019-2020
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

package net.minecraftforge.client.event;

import java.util.Set;

import net.minecraftforge.eventbus.api.Event;

import net.minecraft.client.texture.SpriteAtlasTexture;
import net.minecraft.util.Identifier;

public class TextureStitchEvent extends Event {
private final SpriteAtlasTexture map;

public TextureStitchEvent(SpriteAtlasTexture map) {
this.map = map;
}

public SpriteAtlasTexture getMap() {
return map;
}

/**
* Fired when the {@link SpriteAtlasTexture} is told to refresh its stitched texture.
* Called before the {@link SpriteAtlasTexture} is loaded.
*/
public static class Pre extends TextureStitchEvent {
private final Set<Identifier> sprites;

public Pre(SpriteAtlasTexture map, Set<Identifier> sprites) {
super(map);
this.sprites = sprites;
}

/**
* Add a sprite to be stitched into the texture atlas.
*/
public boolean addSprite(Identifier sprite) {
return this.sprites.add(sprite);
}
}

/**
* This event is fired once the texture map has loaded all textures and
* stitched them together. All sprites should have there locations defined
* by the time this is fired.
*/
public static class Post extends TextureStitchEvent {
public Post(SpriteAtlasTexture map) {
super(map);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

package net.patchworkmc.impl.event.colors;
package net.patchworkmc.impl.event.render;

import java.util.Set;
import java.util.function.Consumer;

import net.minecraftforge.client.event.ColorHandlerEvent;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.eventbus.api.Event;

import net.minecraft.client.color.block.BlockColors;
import net.minecraft.client.color.item.ItemColors;
import net.minecraft.client.texture.SpriteAtlasTexture;
import net.minecraft.util.Identifier;

public class ColorEvents {
public class RenderEvents {
private static Consumer<Event> eventDispatcher;

public static void registerEventDispatcher(Consumer<Event> dispatcher) {
Expand All @@ -41,4 +45,12 @@ public static void onBlockColorsInit(BlockColors blockColors) {
public static void onItemColorsInit(ItemColors itemColors, BlockColors blockColors) {
eventDispatcher.accept(new ColorHandlerEvent.Item(itemColors, blockColors));
}

public static void onTextureStitchPre(SpriteAtlasTexture spriteAtlasTexture, Set<Identifier> set) {
eventDispatcher.accept(new TextureStitchEvent.Pre(spriteAtlasTexture, set));
}

public static void onTextureStitchPost(SpriteAtlasTexture spriteAtlasTexture) {
eventDispatcher.accept(new TextureStitchEvent.Post(spriteAtlasTexture));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

package net.patchworkmc.mixin.event.colors;
package net.patchworkmc.mixin.event.render;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -26,12 +26,12 @@

import net.minecraft.client.color.block.BlockColors;

import net.patchworkmc.impl.event.colors.ColorEvents;
import net.patchworkmc.impl.event.render.RenderEvents;

@Mixin(BlockColors.class)
public class MixinBlockColors {
@Inject(method = "create", at = @At("RETURN"))
private static void onCreate(CallbackInfoReturnable<BlockColors> cir) {
ColorEvents.onBlockColorsInit(cir.getReturnValue());
RenderEvents.onBlockColorsInit(cir.getReturnValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

package net.patchworkmc.mixin.event.colors;
package net.patchworkmc.mixin.event.render;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -27,12 +27,12 @@
import net.minecraft.client.color.block.BlockColors;
import net.minecraft.client.color.item.ItemColors;

import net.patchworkmc.impl.event.colors.ColorEvents;
import net.patchworkmc.impl.event.render.RenderEvents;

@Mixin(ItemColors.class)
public class MixinItemColors {
@Inject(method = "create", at = @At("RETURN"))
private static void onCreate(BlockColors blockColors, CallbackInfoReturnable<ItemColors> cir) {
ColorEvents.onItemColorsInit(cir.getReturnValue(), blockColors);
RenderEvents.onItemColorsInit(cir.getReturnValue(), blockColors);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Minecraft Forge, Patchwork Project
* Copyright (c) 2016-2020, 2019-2020
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

package net.patchworkmc.mixin.event.render;

import java.util.Set;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import net.minecraft.client.texture.SpriteAtlasTexture;
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;
import net.minecraft.util.profiler.Profiler;

import net.patchworkmc.impl.event.render.RenderEvents;

@Mixin(SpriteAtlasTexture.class)
public class MixinSpriteAtlasTexture {
@Inject(method = "stitch", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/texture/SpriteAtlasTexture;loadSprites(Lnet/minecraft/resource/ResourceManager;Ljava/util/Set;)Ljava/util/Collection;", ordinal = 0), locals = LocalCapture.CAPTURE_FAILHARD)
private void onStitch(ResourceManager resourceManager, Iterable<Identifier> iterable, Profiler profiler, CallbackInfoReturnable<SpriteAtlasTexture.Data> cir, Set<Identifier> set) {
RenderEvents.onTextureStitchPre((SpriteAtlasTexture) (Object) this, set);
}

@Inject(method = "upload", at = @At("RETURN"))
private void onUpload(SpriteAtlasTexture.Data data, CallbackInfo ci) {
RenderEvents.onTextureStitchPost((SpriteAtlasTexture) (Object) this);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"schemaVersion": 1,
"id": "patchwork-client-colors",
"name": "Patchwork Colors",
"id": "patchwork-events-rendering",
"name": "Patchwork Rendering Events",
"version": "${version}",
"license": "LGPL-2.1-only",
"icon": "assets/patchwork-client-colors/icon.png",
"icon": "assets/patchwork-events-rendering/icon.png",
"contact": {
"issues": "https://github.com/PatchworkMC/patchwork-api/issues",
"sources": "https://github.com/PatchworkMC/patchwork-api"
Expand All @@ -17,9 +17,9 @@
"patchwork-fml": "*"
},
"mixins": [
"patchwork-client-colors.mixins.json"
"patchwork-events-rendering.mixins.json"
],
"description": "Implementation of the Forge Item and Block Color Hooks.",
"description": "Implementation of the Minecraft Forge rendering events.",
"custom": {
"modmenu:api": true,
"modmenu:parent": "patchwork"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"required": true,
"package": "net.patchworkmc.mixin.event.colors",
"package": "net.patchworkmc.mixin.event.render",
"compatibilityLevel": "JAVA_8",
"client": [
"MixinItemColors",
"MixinBlockColors"
"MixinBlockColors",
"MixinSpriteAtlasTexture"
],
"injectors": {
"defaultRequire": 1
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ rootProject.name = "patchwork-api"

include 'patchwork-biomes'
include 'patchwork-capabilities'
include 'patchwork-client-colors'
include 'patchwork-data-generators'
include 'patchwork-dispatcher'
include 'patchwork-enum-hacks'
include 'patchwork-events-entity'
include 'patchwork-events-input'
include 'patchwork-events-lifecycle'
include 'patchwork-events-rendering'
include 'patchwork-events-world'
include 'patchwork-extensions'
include 'patchwork-extensions-block'
Expand Down