From 29654598415c3973ddd1b8e7bbc7781e0f56399d Mon Sep 17 00:00:00 2001 From: Falkreon Date: Tue, 2 Jan 2024 12:21:45 -0600 Subject: [PATCH] Make scarves show their colors on the item icon! --- .../endless/scarves/client/ScarvesClient.java | 60 +++++ .../assets/scarves/models/item/scarf.json | 214 +++++++++++++++++- .../assets/scarves/models/item/scarf_old.json | 6 + .../assets/scarves/textures/item/scarf.png | Bin 249 -> 1652 bytes .../scarves/textures/item/scarf_old.png | Bin 0 -> 249 bytes 5 files changed, 276 insertions(+), 4 deletions(-) create mode 100644 src/main/resources/assets/scarves/models/item/scarf_old.json create mode 100644 src/main/resources/assets/scarves/textures/item/scarf_old.png diff --git a/src/main/java/blue/endless/scarves/client/ScarvesClient.java b/src/main/java/blue/endless/scarves/client/ScarvesClient.java index 1b2af36..c02a3be 100644 --- a/src/main/java/blue/endless/scarves/client/ScarvesClient.java +++ b/src/main/java/blue/endless/scarves/client/ScarvesClient.java @@ -1,23 +1,60 @@ package blue.endless.scarves.client; +import java.util.HashMap; import java.util.List; +import java.util.Map; import blue.endless.scarves.ScarvesBlocks; +import blue.endless.scarves.ScarvesItems; import blue.endless.scarves.ghost.GhostInventoryNetworking; import blue.endless.scarves.gui.ScarfStaplerGuiDescription; import blue.endless.scarves.gui.ScarfTableGuiDescription; import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; +import net.minecraft.block.Blocks; +import net.minecraft.block.MapColor; import net.minecraft.client.gui.screen.ingame.HandledScreens; import net.minecraft.client.render.LightmapTextureManager; import net.minecraft.entity.Entity; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.nbt.NbtElement; +import net.minecraft.nbt.NbtList; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.LightType; public class ScarvesClient implements ClientModInitializer { public static final double SCARF_GRAVITY = -0.01; + public static final int UNCOLORED_SCARF_TINT = 0xFF_ddc8ab; + + private static Map ALT_COLORS = new HashMap<>(); + + static { + ALT_COLORS.put("minecraft:block/white_wool", Blocks.WHITE_WOOL.getDefaultMapColor().getRenderColor(MapColor.Brightness.NORMAL)); + ALT_COLORS.put("minecraft:block/orange_wool", Blocks.ORANGE_WOOL.getDefaultMapColor().getRenderColor(MapColor.Brightness.NORMAL)); + ALT_COLORS.put("minecraft:block/magenta_wool", Blocks.MAGENTA_WOOL.getDefaultMapColor().getRenderColor(MapColor.Brightness.NORMAL)); + ALT_COLORS.put("minecraft:block/light_blue_wool", Blocks.LIGHT_BLUE_WOOL.getDefaultMapColor().getRenderColor(MapColor.Brightness.NORMAL)); + ALT_COLORS.put("minecraft:block/yellow_wool", Blocks.YELLOW_WOOL.getDefaultMapColor().getRenderColor(MapColor.Brightness.NORMAL)); + ALT_COLORS.put("minecraft:block/lime_wool", Blocks.LIME_WOOL.getDefaultMapColor().getRenderColor(MapColor.Brightness.NORMAL)); + ALT_COLORS.put("minecraft:block/pink_wool", Blocks.PINK_WOOL.getDefaultMapColor().getRenderColor(MapColor.Brightness.NORMAL)); + ALT_COLORS.put("minecraft:block/gray_wool", Blocks.GRAY_WOOL.getDefaultMapColor().getRenderColor(MapColor.Brightness.NORMAL)); + ALT_COLORS.put("minecraft:block/light_gray_wool", Blocks.LIGHT_GRAY_WOOL.getDefaultMapColor().getRenderColor(MapColor.Brightness.NORMAL)); + ALT_COLORS.put("minecraft:block/cyan_wool", Blocks.CYAN_WOOL.getDefaultMapColor().getRenderColor(MapColor.Brightness.NORMAL)); + ALT_COLORS.put("minecraft:block/purple_wool", Blocks.PURPLE_WOOL.getDefaultMapColor().getRenderColor(MapColor.Brightness.NORMAL)); + ALT_COLORS.put("minecraft:block/blue_wool", Blocks.BLUE_WOOL.getDefaultMapColor().getRenderColor(MapColor.Brightness.NORMAL)); + ALT_COLORS.put("minecraft:block/brown_wool", Blocks.BROWN_WOOL.getDefaultMapColor().getRenderColor(MapColor.Brightness.NORMAL)); + ALT_COLORS.put("minecraft:block/green_wool", Blocks.GREEN_WOOL.getDefaultMapColor().getRenderColor(MapColor.Brightness.NORMAL)); + ALT_COLORS.put("minecraft:block/red_wool", Blocks.RED_WOOL.getDefaultMapColor().getRenderColor(MapColor.Brightness.NORMAL)); + ALT_COLORS.put("minecraft:block/black_wool", Blocks.BLACK_WOOL.getDefaultMapColor().getRenderColor(MapColor.Brightness.NORMAL)); + ALT_COLORS.put("minecraft:block/water_still", 0xFF_3f51eb); + ALT_COLORS.put("minecraft:block/lava_still", 0xFF_ff5100); + ALT_COLORS.put("minecraft:block/redstone_block", 0xFF_b50000); + ALT_COLORS.put("minecraft:block/glowstone", 0xFF_f6c921); + ALT_COLORS.put("minecraft:block/bedrock", 0xFF_4a4a4a); + } @Override public void onInitializeClient() { @@ -27,6 +64,29 @@ public void onInitializeClient() { HandledScreens.register(ScarvesBlocks.SCARF_STAPLER_SCREEN_HANDLER, (gui, inventory, title) -> new ScarfStaplerScreen(gui, inventory, title)); HandledScreens.register(ScarvesBlocks.SCARF_TABLE_SCREEN_HANDLER, (gui, inventory, title) -> new ScarfTableScreen(gui, inventory, title)); + + ColorProviderRegistry.ITEM.register(ScarvesClient::getScarfTint, ScarvesItems.SCARF); + } + + public static int getScarfTint(ItemStack stack, int index) { + NbtCompound tag = stack.getNbt(); + if (tag == null) return UNCOLORED_SCARF_TINT; + NbtList leftScarf = tag.getList("LeftScarf", NbtElement.COMPOUND_TYPE); + NbtList rightScarf = tag.getList("RightScarf", NbtElement.COMPOUND_TYPE); + NbtList scarf = (leftScarf == null || leftScarf.size() == 0) ? rightScarf : leftScarf; + if (scarf.size() == 0) return UNCOLORED_SCARF_TINT; + + NbtCompound square = scarf.getCompound(index % scarf.size()); + + int color = (square.contains("Color", NbtElement.INT_TYPE)) ? square.getInt("Color") : 0xFF_FFFFFF; + if (color == 0xFF_FFFFFF) { + try { + String id = square.getString("Id"); + return ALT_COLORS.getOrDefault(id, 0xFF_FFFFFF); + } catch (Throwable t) {} + } + + return color; } public static void beforeEntities(WorldRenderContext ctx) { diff --git a/src/main/resources/assets/scarves/models/item/scarf.json b/src/main/resources/assets/scarves/models/item/scarf.json index 7a2d22f..c0deee9 100644 --- a/src/main/resources/assets/scarves/models/item/scarf.json +++ b/src/main/resources/assets/scarves/models/item/scarf.json @@ -1,6 +1,212 @@ { - "parent": "minecraft:item/generated", - "textures": { - "layer0": "scarves:item/scarf" - } + "textures": { + "0": "scarves:item/scarf", + "particle": "scarves:item/scarf" + }, + "gui_light": "front", + "elements": [ + { + "from": [4, 6, 8], + "to": [8, 8, 9], + "faces": { + "north": {"uv": [8, 8, 12, 10], "texture": "#0", "tintindex": 0}, + "south": {"uv": [8, 8, 12, 10], "texture": "#0", "tintindex": 0}, + "west": {"uv": [11, 8, 12, 10], "texture": "#0", "tintindex": 0}, + "up": {"uv": [8, 8, 12, 9], "texture": "#0", "tintindex": 0}, + "down": {"uv": [8, 9, 12, 10], "texture": "#0", "tintindex": 0} + } + }, + { + "from": [8, 6, 8], + "to": [13, 8, 9], + "faces": { + "north": {"uv": [3, 8, 8, 10], "texture": "#0", "tintindex": 1}, + "east": {"uv": [3, 8, 4, 10], "texture": "#0", "tintindex": 1}, + "south": {"uv": [3, 8, 8, 10], "texture": "#0", "tintindex": 1}, + "up": {"uv": [3, 8, 8, 9], "texture": "#0", "tintindex": 1}, + "down": {"uv": [3, 9, 8, 10], "texture": "#0", "tintindex": 1} + } + }, + { + "from": [13, 7, 8], + "to": [14, 10, 9], + "faces": { + "north": {"uv": [2, 6, 3, 9], "texture": "#0", "tintindex": 2}, + "east": {"uv": [2, 6, 3, 9], "texture": "#0", "tintindex": 2}, + "south": {"uv": [2, 6, 3, 9], "texture": "#0", "tintindex": 2}, + "up": {"uv": [2, 6, 3, 7], "texture": "#0", "tintindex": 2}, + "down": {"uv": [2, 8, 3, 9], "texture": "#0", "tintindex": 2} + } + }, + { + "from": [11, 8, 8], + "to": [13, 11, 9], + "faces": { + "north": {"uv": [3, 5, 5, 8], "texture": "#0", "tintindex": 2}, + "east": {"uv": [3, 5, 4, 8], "texture": "#0", "tintindex": 2}, + "south": {"uv": [5, 5, 3, 8], "texture": "#0", "tintindex": 2}, + "west": {"uv": [4, 5, 5, 8], "texture": "#0", "tintindex": 2}, + "up": {"uv": [3, 5, 5, 6], "rotation": 180, "texture": "#0", "tintindex": 2} + } + }, + { + "from": [7, 9, 8], + "to": [11, 11, 9], + "faces": { + "north": {"uv": [5, 5, 9, 7], "texture": "#0", "tintindex": 3}, + "south": {"uv": [5, 5, 9, 7], "texture": "#0", "tintindex": 3}, + "up": {"uv": [5, 5, 9, 6], "texture": "#0", "tintindex": 3}, + "down": {"uv": [5, 6, 9, 7], "texture": "#0", "tintindex": 3} + } + }, + { + "from": [4, 9, 8], + "to": [7, 11, 9], + "faces": { + "north": {"uv": [9, 5, 12, 7], "texture": "#0", "tintindex": 4}, + "south": {"uv": [9, 5, 12, 7], "texture": "#0", "tintindex": 4}, + "west": {"uv": [11, 5, 12, 7], "texture": "#0", "tintindex": 4}, + "up": {"uv": [9, 5, 12, 6], "texture": "#0", "tintindex": 4}, + "down": {"uv": [9, 6, 12, 7], "texture": "#0", "tintindex": 4} + } + }, + { + "from": [2, 7, 8], + "to": [4, 10, 9], + "faces": { + "north": {"uv": [12, 6, 14, 9], "texture": "#0", "tintindex": 5}, + "south": {"uv": [14, 6, 12, 9], "texture": "#0", "tintindex": 5}, + "west": {"uv": [13, 6, 14, 9], "texture": "#0", "tintindex": 5}, + "up": {"uv": [12, 6, 14, 7], "rotation": 180, "texture": "#0", "tintindex": 5}, + "down": {"uv": [12, 8, 14, 9], "texture": "#0", "tintindex": 5} + } + }, + { + "from": [4, 8, 8], + "to": [6, 9, 9], + "faces": { + "north": {"uv": [10, 7, 12, 8], "texture": "#0", "tintindex": 5}, + "east": {"uv": [10, 7, 11, 8], "texture": "#0", "tintindex": 5}, + "south": {"uv": [10, 7, 12, 8], "texture": "#0", "tintindex": 5} + } + }, + { + "from": [2, 2, 8], + "to": [7, 4, 9], + "faces": { + "north": {"uv": [9, 12, 14, 14], "texture": "#0", "tintindex": 7}, + "east": {"uv": [9, 12, 10, 14], "texture": "#0", "tintindex": 7}, + "south": {"uv": [14, 12, 9, 14], "texture": "#0", "tintindex": 7}, + "west": {"uv": [13, 12, 14, 14], "texture": "#0", "tintindex": 7}, + "up": {"uv": [9, 12, 14, 13], "texture": "#0", "tintindex": 7}, + "down": {"uv": [9, 13, 14, 14], "texture": "#0", "tintindex": 7} + } + }, + { + "from": [2, 1, 8], + "to": [3, 2, 9], + "faces": { + "north": {"uv": [13, 14, 14, 15], "texture": "#0", "tintindex": 7}, + "east": {"uv": [13, 14, 14, 15], "texture": "#0", "tintindex": 7}, + "south": {"uv": [13, 14, 14, 15], "texture": "#0", "tintindex": 7}, + "west": {"uv": [13, 14, 14, 15], "texture": "#0", "tintindex": 7}, + "down": {"uv": [13, 14, 14, 15], "texture": "#0", "tintindex": 7} + } + }, + { + "from": [2, 4, 8], + "to": [3, 5, 9], + "faces": { + "north": {"uv": [12, 10, 13, 11], "texture": "#0", "tintindex": 6}, + "south": {"uv": [12, 10, 13, 11], "texture": "#0", "tintindex": 6}, + "west": {"uv": [12, 10, 13, 11], "texture": "#0", "tintindex": 6}, + "up": {"uv": [12, 10, 13, 11], "texture": "#0", "tintindex": 6} + } + }, + { + "from": [4, 1, 8], + "to": [5, 2, 9], + "faces": { + "north": {"uv": [11, 14, 12, 15], "texture": "#0", "tintindex": 7}, + "east": {"uv": [11, 14, 12, 15], "texture": "#0", "tintindex": 7}, + "south": {"uv": [11, 14, 12, 15], "texture": "#0", "tintindex": 7}, + "west": {"uv": [11, 14, 12, 15], "texture": "#0", "tintindex": 7}, + "down": {"uv": [11, 14, 12, 15], "texture": "#0", "tintindex": 7} + } + }, + { + "from": [6, 1, 8], + "to": [7, 2, 9], + "faces": { + "north": {"uv": [9, 14, 10, 15], "texture": "#0", "tintindex": 7}, + "east": {"uv": [9, 14, 10, 15], "texture": "#0", "tintindex": 7}, + "south": {"uv": [9, 14, 10, 15], "texture": "#0", "tintindex": 7}, + "west": {"uv": [9, 14, 10, 15], "texture": "#0", "tintindex": 7}, + "down": {"uv": [9, 14, 10, 15], "texture": "#0", "tintindex": 7} + } + }, + { + "from": [3, 4, 8], + "to": [6, 6, 9], + "faces": { + "north": {"uv": [10, 10, 13, 12], "texture": "#0", "tintindex": 6}, + "east": {"uv": [10, 10, 11, 12], "texture": "#0", "tintindex": 6}, + "south": {"uv": [13, 10, 10, 12], "texture": "#0", "tintindex": 6}, + "west": {"uv": [12, 10, 13, 12], "texture": "#0", "tintindex": 6}, + "up": {"uv": [10, 10, 13, 11], "texture": "#0", "tintindex": 6} + } + } + ], + "display": { + "thirdperson_righthand": { + "rotation": [0, 90, 30], + "translation": [0, 0.75, -0.75], + "scale": [0.5, 0.5, 0.5] + }, + "thirdperson_lefthand": { + "rotation": [0, 90, 30], + "translation": [0, 0.75, -0.75], + "scale": [0.5, 0.5, 0.5] + }, + "firstperson_righthand": { + "rotation": [0, 142, 0], + "translation": [1.75, 1.75, 0], + "scale": [0.5, 0.5, 0.5] + }, + "firstperson_lefthand": { + "rotation": [0, 142, 0], + "translation": [1.75, 1.75, 0], + "scale": [0.5, 0.5, 0.5] + }, + "ground": { + "translation": [0, 3, 0], + "scale": [0.75, 0.75, 0.75] + }, + "gui": { + "rotation": [0, 180, 0], + "translation": [0, 1.5, 0] + }, + "head": { + "rotation": [-68, 0, 0], + "translation": [0, -0.5, 2], + "scale": [1.51, 3.6, 1] + }, + "fixed": { + "translation": [0, 0, -0.25] + } + }, + "groups": [ + { + "name": "Loop", + "origin": [0, 0, 0], + "color": 0, + "children": [0, 1, 2, 3, 4, 5, 6, 7] + }, + { + "name": "Tassel", + "origin": [0, 0, 0], + "color": 0, + "children": [8, 9, 10, 11, 12, 13] + } + ] } diff --git a/src/main/resources/assets/scarves/models/item/scarf_old.json b/src/main/resources/assets/scarves/models/item/scarf_old.json new file mode 100644 index 0000000..7a2d22f --- /dev/null +++ b/src/main/resources/assets/scarves/models/item/scarf_old.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "scarves:item/scarf" + } +} diff --git a/src/main/resources/assets/scarves/textures/item/scarf.png b/src/main/resources/assets/scarves/textures/item/scarf.png index 5f0df7ed91bc44a0087a2885905fb702b76f8748..0bc20693005895385ed69759f1c49de6886cf0d7 100644 GIT binary patch delta 1636 zcmV-q2Alc$0rU)zBYy*&dQ@0+Qek%>aB^>EX>4U6ba`-PAZ2)IW&i+q+U-_bcH}q+ z{nsjH2?B&3%hB_k*}*J-u3VCxc2$y2I-hODfrAlTaltOr|ND2Ce{fOsY@CMZllK;v zOD=JS676;MC6l#d>JB$88=YQcetEDp!g^(ANP(1x@ysVPkbk_{;7>`f?4&oloN4$M zL~#dVtT*3koC0Hjfo>EA()zgcWVJ)sVBz zR$H(tC1Mgg$WfzAgZd#WRX}vyIY2U3mcte$aN;UfNSqNTjs^!w(j*E??ggQp>lYyMY zI4+=oRJj2qI}s0ZBG25|6X@_|<%by~1R_+t1W=PCgMTaM)Oq8Ai|C=OqE1!42926D zd-2Yz_dfVJi#bSeL4yw=#E?Rc5?$2jV~8=Pm`&m&m{m!D+Jwa|k;G&DV)e&cGNu0^?yafQIJDnT_Ne zPv*?z%qGTECz@Y2II_Tu?V(y7IgSr1MZ~T@yGpYLt=FFt-1#{25ypXy1>*;Y9y3RH@YkgI>W068{(lDgR-jSZsY=a*=B4lU@CK z%2~BxFGkEG2XBOZ`|#bF(?yYQPjxUK7U&Do zyi;M_NvV}>%;oHEJMK+v-s$QuOY<}qU6*>YE?Y@@LK3}gH1tD|OlSk&vwQ2DBe%O* z!!Nplu2UkH5{C@#) zc5qU3krMAq3N2#1@OU5R-E(;FK0v6KnPzoN0Ge)_sYG1NWLL$mR|FuSA47=A%rfRA zDGA^Dx~FccyC~1{@B6cQ)ttqEfJi*c4AUmwAfDc|4bJ<-VOEq?;&bA0lP*a7$aTfz zH_io@1)do;)2VslFtJ!@W2KE*(SOv4r-&n}rc=I<@mS@&#aSy?S@WL!g`u3jvdnc_ zBS>HoOOPN!K@}yGVIxYrPKt#ToyUFr!>(TJ%U`JjGoPf_T3X}?=-UP^u3MV22Y+1d0E174 zY|5?_q$T9@!220}Qx+Jw1$x%Jxi!ym`T(S9R>>RS;1C!qQ1-gdySv-x_HR#fem`TS za-q3fbe#YI0Ru@yK~y-)?UGB5!Y~j-%ccpR1&b(W;3_#SN8ke7fHgv9OJbC`W4l;o zM3j++`7GzHx);@5U25Q;Uw>m>8}B`j$0N$J#D2era}JNk1KaHu_xl|o1k`ms(b%!L z-EI^Skc5cfd_H5d*eVWkGEwBKh2c<;X|hZ2+XKXF*>0kZM?`@H1hIv|9lAp zo*$oH@-p+!=Q#XcK3;O(9oygXcN^~8?-LSd|!DUuysW diff --git a/src/main/resources/assets/scarves/textures/item/scarf_old.png b/src/main/resources/assets/scarves/textures/item/scarf_old.png new file mode 100644 index 0000000000000000000000000000000000000000..5f0df7ed91bc44a0087a2885905fb702b76f8748 GIT binary patch literal 249 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`2RvOILo7}wCrGf0FuSFk`@6dR z-+b#09gQH++sy9zaJ_uI1PC;3e!k#EVw0hseEfI$*=!}>Zmrb(|32Q9CHyo~@`n$d z1|Tq_I>qROhP3e_YthKd)BW=$40wKgddbVoKcD09d--_Dd3S7o%inFdZ@*7SoQ($v z*2vt65dHt}<5b7M+kF$)T!^zaeft0DA3X<3FVUv5mzS3cI;qa@MiN|@SwBh9MCTep00i_>zopr0N}o1WdHyG literal 0 HcmV?d00001