Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit 55237bb

Browse files
Rename patchwork-client-colors to patchwork-events-rendering and implement TextureStitchEvent (#80)
* Rename patchwork-client-colors to patchwork-events-rendering * Rename things to Render rather than Color * Implement TextureStitchEvent * Import order and Licenses * Javadoc updates * More stable mixin hook * ' Co-authored-by: coderbot <[email protected]> Co-authored-by: coderbot <[email protected]>
1 parent 6114862 commit 55237bb

File tree

13 files changed

+152
-20
lines changed

13 files changed

+152
-20
lines changed

patchwork-dispatcher/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
archivesBaseName = "patchwork-dispatcher"
2-
version = getSubprojectVersion(project, "0.2.0")
2+
version = getSubprojectVersion(project, "0.3.0")
33

44
dependencies {
55
compile project(path: ':patchwork-fml', configuration: 'dev')
66
compile project(path: ':patchwork-registries', configuration: 'dev')
77
compile project(path: ':patchwork-events-lifecycle', configuration: 'dev')
8-
compile project(path: ':patchwork-client-colors', configuration: 'dev')
8+
compile project(path: ':patchwork-events-rendering', configuration: 'dev')
99
}

patchwork-dispatcher/src/main/java/net/patchworkmc/impl/Patchwork.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
import net.fabricmc.loader.api.FabricLoader;
5151

5252
import net.patchworkmc.api.ForgeInitializer;
53-
import net.patchworkmc.impl.event.colors.ColorEvents;
53+
import net.patchworkmc.impl.event.render.RenderEvents;
5454
import net.patchworkmc.impl.registries.RegistryEventDispatcher;
5555

5656
public class Patchwork implements ModInitializer {
@@ -120,7 +120,7 @@ public void onInitialize() {
120120

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

126126
DistExecutor.runWhenOn(Dist.DEDICATED_SERVER, () -> () -> {
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Minecraft Forge, Patchwork Project
3+
* Copyright (c) 2016-2020, 2019-2020
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation version 2.1
8+
* of the License.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
package net.minecraftforge.client.event;
21+
22+
import java.util.Set;
23+
24+
import net.minecraftforge.eventbus.api.Event;
25+
26+
import net.minecraft.client.texture.SpriteAtlasTexture;
27+
import net.minecraft.util.Identifier;
28+
29+
public class TextureStitchEvent extends Event {
30+
private final SpriteAtlasTexture map;
31+
32+
public TextureStitchEvent(SpriteAtlasTexture map) {
33+
this.map = map;
34+
}
35+
36+
public SpriteAtlasTexture getMap() {
37+
return map;
38+
}
39+
40+
/**
41+
* Fired when the {@link SpriteAtlasTexture} is told to refresh its stitched texture.
42+
* Called before the {@link SpriteAtlasTexture} is loaded.
43+
*/
44+
public static class Pre extends TextureStitchEvent {
45+
private final Set<Identifier> sprites;
46+
47+
public Pre(SpriteAtlasTexture map, Set<Identifier> sprites) {
48+
super(map);
49+
this.sprites = sprites;
50+
}
51+
52+
/**
53+
* Add a sprite to be stitched into the texture atlas.
54+
*/
55+
public boolean addSprite(Identifier sprite) {
56+
return this.sprites.add(sprite);
57+
}
58+
}
59+
60+
/**
61+
* This event is fired once the texture map has loaded all textures and
62+
* stitched them together. All sprites should have there locations defined
63+
* by the time this is fired.
64+
*/
65+
public static class Post extends TextureStitchEvent {
66+
public Post(SpriteAtlasTexture map) {
67+
super(map);
68+
}
69+
}
70+
}

patchwork-client-colors/src/main/java/net/patchworkmc/impl/event/colors/ColorEvents.java renamed to patchwork-events-rendering/src/main/java/net/patchworkmc/impl/event/render/RenderEvents.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,21 @@
1717
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1818
*/
1919

20-
package net.patchworkmc.impl.event.colors;
20+
package net.patchworkmc.impl.event.render;
2121

22+
import java.util.Set;
2223
import java.util.function.Consumer;
2324

2425
import net.minecraftforge.client.event.ColorHandlerEvent;
26+
import net.minecraftforge.client.event.TextureStitchEvent;
2527
import net.minecraftforge.eventbus.api.Event;
2628

2729
import net.minecraft.client.color.block.BlockColors;
2830
import net.minecraft.client.color.item.ItemColors;
31+
import net.minecraft.client.texture.SpriteAtlasTexture;
32+
import net.minecraft.util.Identifier;
2933

30-
public class ColorEvents {
34+
public class RenderEvents {
3135
private static Consumer<Event> eventDispatcher;
3236

3337
public static void registerEventDispatcher(Consumer<Event> dispatcher) {
@@ -41,4 +45,12 @@ public static void onBlockColorsInit(BlockColors blockColors) {
4145
public static void onItemColorsInit(ItemColors itemColors, BlockColors blockColors) {
4246
eventDispatcher.accept(new ColorHandlerEvent.Item(itemColors, blockColors));
4347
}
48+
49+
public static void onTextureStitchPre(SpriteAtlasTexture spriteAtlasTexture, Set<Identifier> set) {
50+
eventDispatcher.accept(new TextureStitchEvent.Pre(spriteAtlasTexture, set));
51+
}
52+
53+
public static void onTextureStitchPost(SpriteAtlasTexture spriteAtlasTexture) {
54+
eventDispatcher.accept(new TextureStitchEvent.Post(spriteAtlasTexture));
55+
}
4456
}

patchwork-client-colors/src/main/java/net/patchworkmc/mixin/event/colors/MixinBlockColors.java renamed to patchwork-events-rendering/src/main/java/net/patchworkmc/mixin/event/render/MixinBlockColors.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1818
*/
1919

20-
package net.patchworkmc.mixin.event.colors;
20+
package net.patchworkmc.mixin.event.render;
2121

2222
import org.spongepowered.asm.mixin.Mixin;
2323
import org.spongepowered.asm.mixin.injection.At;
@@ -26,12 +26,12 @@
2626

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

29-
import net.patchworkmc.impl.event.colors.ColorEvents;
29+
import net.patchworkmc.impl.event.render.RenderEvents;
3030

3131
@Mixin(BlockColors.class)
3232
public class MixinBlockColors {
3333
@Inject(method = "create", at = @At("RETURN"))
3434
private static void onCreate(CallbackInfoReturnable<BlockColors> cir) {
35-
ColorEvents.onBlockColorsInit(cir.getReturnValue());
35+
RenderEvents.onBlockColorsInit(cir.getReturnValue());
3636
}
3737
}

patchwork-client-colors/src/main/java/net/patchworkmc/mixin/event/colors/MixinItemColors.java renamed to patchwork-events-rendering/src/main/java/net/patchworkmc/mixin/event/render/MixinItemColors.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1818
*/
1919

20-
package net.patchworkmc.mixin.event.colors;
20+
package net.patchworkmc.mixin.event.render;
2121

2222
import org.spongepowered.asm.mixin.Mixin;
2323
import org.spongepowered.asm.mixin.injection.At;
@@ -27,12 +27,12 @@
2727
import net.minecraft.client.color.block.BlockColors;
2828
import net.minecraft.client.color.item.ItemColors;
2929

30-
import net.patchworkmc.impl.event.colors.ColorEvents;
30+
import net.patchworkmc.impl.event.render.RenderEvents;
3131

3232
@Mixin(ItemColors.class)
3333
public class MixinItemColors {
3434
@Inject(method = "create", at = @At("RETURN"))
3535
private static void onCreate(BlockColors blockColors, CallbackInfoReturnable<ItemColors> cir) {
36-
ColorEvents.onItemColorsInit(cir.getReturnValue(), blockColors);
36+
RenderEvents.onItemColorsInit(cir.getReturnValue(), blockColors);
3737
}
3838
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Minecraft Forge, Patchwork Project
3+
* Copyright (c) 2016-2020, 2019-2020
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation version 2.1
8+
* of the License.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
package net.patchworkmc.mixin.event.render;
21+
22+
import java.util.Set;
23+
24+
import org.spongepowered.asm.mixin.Mixin;
25+
import org.spongepowered.asm.mixin.injection.At;
26+
import org.spongepowered.asm.mixin.injection.Inject;
27+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
28+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
29+
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
30+
31+
import net.minecraft.client.texture.SpriteAtlasTexture;
32+
import net.minecraft.resource.ResourceManager;
33+
import net.minecraft.util.Identifier;
34+
import net.minecraft.util.profiler.Profiler;
35+
36+
import net.patchworkmc.impl.event.render.RenderEvents;
37+
38+
@Mixin(SpriteAtlasTexture.class)
39+
public class MixinSpriteAtlasTexture {
40+
@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)
41+
private void onStitch(ResourceManager resourceManager, Iterable<Identifier> iterable, Profiler profiler, CallbackInfoReturnable<SpriteAtlasTexture.Data> cir, Set<Identifier> set) {
42+
RenderEvents.onTextureStitchPre((SpriteAtlasTexture) (Object) this, set);
43+
}
44+
45+
@Inject(method = "upload", at = @At("RETURN"))
46+
private void onUpload(SpriteAtlasTexture.Data data, CallbackInfo ci) {
47+
RenderEvents.onTextureStitchPost((SpriteAtlasTexture) (Object) this);
48+
}
49+
}

patchwork-client-colors/src/main/resources/fabric.mod.json renamed to patchwork-events-rendering/src/main/resources/fabric.mod.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"schemaVersion": 1,
3-
"id": "patchwork-client-colors",
4-
"name": "Patchwork Colors",
3+
"id": "patchwork-events-rendering",
4+
"name": "Patchwork Rendering Events",
55
"version": "${version}",
66
"license": "LGPL-2.1-only",
7-
"icon": "assets/patchwork-client-colors/icon.png",
7+
"icon": "assets/patchwork-events-rendering/icon.png",
88
"contact": {
99
"issues": "https://github.com/PatchworkMC/patchwork-api/issues",
1010
"sources": "https://github.com/PatchworkMC/patchwork-api"
@@ -17,9 +17,9 @@
1717
"patchwork-fml": "*"
1818
},
1919
"mixins": [
20-
"patchwork-client-colors.mixins.json"
20+
"patchwork-events-rendering.mixins.json"
2121
],
22-
"description": "Implementation of the Forge Item and Block Color Hooks.",
22+
"description": "Implementation of the Minecraft Forge rendering events.",
2323
"custom": {
2424
"modmenu:api": true,
2525
"modmenu:parent": "patchwork"

patchwork-client-colors/src/main/resources/patchwork-client-colors.mixins.json renamed to patchwork-events-rendering/src/main/resources/patchwork-events-rendering.mixins.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"required": true,
3-
"package": "net.patchworkmc.mixin.event.colors",
3+
"package": "net.patchworkmc.mixin.event.render",
44
"compatibilityLevel": "JAVA_8",
55
"client": [
66
"MixinItemColors",
7-
"MixinBlockColors"
7+
"MixinBlockColors",
8+
"MixinSpriteAtlasTexture"
89
],
910
"injectors": {
1011
"defaultRequire": 1

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ rootProject.name = "patchwork-api"
1414

1515
include 'patchwork-biomes'
1616
include 'patchwork-capabilities'
17-
include 'patchwork-client-colors'
1817
include 'patchwork-data-generators'
1918
include 'patchwork-dispatcher'
2019
include 'patchwork-enum-hacks'
2120
include 'patchwork-events-entity'
2221
include 'patchwork-events-input'
2322
include 'patchwork-events-lifecycle'
23+
include 'patchwork-events-rendering'
2424
include 'patchwork-events-world'
2525
include 'patchwork-extensions'
2626
include 'patchwork-extensions-block'

0 commit comments

Comments
 (0)