From fc763709e26ea07431f940ab70b4c82816f69330 Mon Sep 17 00:00:00 2001 From: "Joseph T. McQuigg" Date: Mon, 2 Dec 2024 17:07:01 -0500 Subject: [PATCH] Move ItemColor Handlers to Common Client (Forge/NeoForge) Signed-off-by: Joseph T. McQuigg --- .../client/BiomesWeveGoneClient.java | 13 ++++++++++++ .../client/BiomesWeveGoneClientForge.java | 20 +------------------ .../client/BiomesWeveGoneClientNeoForge.java | 19 +----------------- 3 files changed, 15 insertions(+), 37 deletions(-) diff --git a/Common/src/main/java/net/potionstudios/biomeswevegone/client/BiomesWeveGoneClient.java b/Common/src/main/java/net/potionstudios/biomeswevegone/client/BiomesWeveGoneClient.java index 7702140ef..fd5360717 100644 --- a/Common/src/main/java/net/potionstudios/biomeswevegone/client/BiomesWeveGoneClient.java +++ b/Common/src/main/java/net/potionstudios/biomeswevegone/client/BiomesWeveGoneClient.java @@ -1,6 +1,8 @@ package net.potionstudios.biomeswevegone.client; import net.minecraft.client.color.block.BlockColor; +import net.minecraft.client.color.block.BlockColors; +import net.minecraft.client.color.item.ItemColor; import net.minecraft.client.model.BoatModel; import net.minecraft.client.model.ChestBoatModel; import net.minecraft.client.model.geom.ModelLayerLocation; @@ -17,8 +19,10 @@ import net.minecraft.util.FastColor; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; +import net.minecraft.world.item.BlockItem; import net.minecraft.world.level.FoliageColor; import net.minecraft.world.level.GrassColor; +import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.StemBlock; import net.minecraft.world.level.block.entity.BlockEntity; @@ -133,6 +137,15 @@ public static void registerBlockColors(BiConsumer consumer) }, new Block[] {BWGBlocks.PALE_PUMPKIN_STEM.get()}); consumer.accept((state, view, pos, tintIndex) -> -2046180, new Block[] {BWGBlocks.ATTACHED_PALE_PUMPKIN_STEM.get()}); } + + public static void registerItemColors(BiConsumer consumer, BlockColors blockColors) { + consumer.accept((stack, tintIndex) -> { + Block block = ((BlockItem) stack.getItem()).getBlock(); + return blockColors.getColor(block.defaultBlockState(), null, null, tintIndex); + }, new ItemLike[]{BWGBlocks.TINY_LILY_PADS.get(), BWGBlocks.FLOWERING_TINY_LILY_PADS.get(), BWGBlocks.CLOVER_PATCH.get(), BWGBlocks.LEAF_PILE.get(), BWGBlocks.POISON_IVY.get() + , BWGWood.MAHOGANY.leaves(), BWGWood.WILLOW.leaves(), BWGWood.MAPLE.leaves(), BWGWood.YUCCA_LEAVES.get(), BWGWood.FLOWERING_YUCCA_LEAVES.get(), BWGWood.RIPE_YUCCA_LEAVES.get(), BWGWood.CYPRESS.leaves(), BWGBlocks.LUSH_GRASS_BLOCK.get() + , BWGBlocks.OVERGROWN_DACITE.get(), BWGBlocks.OVERGROWN_STONE.get()}); + } private static final ImprovedNoise NOISE = new ImprovedNoise(new XoroshiroRandomSource(1)); diff --git a/Forge/src/main/java/net/potionstudios/biomeswevegone/forge/client/BiomesWeveGoneClientForge.java b/Forge/src/main/java/net/potionstudios/biomeswevegone/forge/client/BiomesWeveGoneClientForge.java index d1708c14b..188640583 100644 --- a/Forge/src/main/java/net/potionstudios/biomeswevegone/forge/client/BiomesWeveGoneClientForge.java +++ b/Forge/src/main/java/net/potionstudios/biomeswevegone/forge/client/BiomesWeveGoneClientForge.java @@ -1,7 +1,5 @@ package net.potionstudios.biomeswevegone.forge.client; -import net.minecraft.world.item.BlockItem; -import net.minecraft.world.level.block.Block; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.client.event.EntityRenderersEvent; @@ -10,8 +8,6 @@ import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.potionstudios.biomeswevegone.client.BiomesWeveGoneClient; -import net.potionstudios.biomeswevegone.world.level.block.BWGBlocks; -import net.potionstudios.biomeswevegone.world.level.block.wood.BWGWood; /** * This class is used to initialize the Forge client side of the mod. @@ -33,20 +29,6 @@ public static void init(final IEventBus eventBus) { eventBus.addListener((RegisterParticleProvidersEvent event) -> BiomesWeveGoneClient.registerParticles((type, spriteProviderFactory) -> event.registerSpriteSet(type, spriteProviderFactory::apply))); eventBus.addListener((EntityRenderersEvent.RegisterLayerDefinitions event) -> BiomesWeveGoneClient.registerLayerDefinitions(event::registerLayerDefinition)); eventBus.addListener((RegisterColorHandlersEvent.Block event) -> BiomesWeveGoneClient.registerBlockColors(event::register)); - eventBus.addListener(BiomesWeveGoneClientForge::registerItemColorHandlers); - } - - /** - * Registers the item color handlers for the mod. - * @param event The event to register the item color handlers to. - * @see RegisterColorHandlersEvent.Item - */ - private static void registerItemColorHandlers(final RegisterColorHandlersEvent.Item event) { - event.register((stack, tintIndex) -> { - Block block = ((BlockItem) stack.getItem()).getBlock(); - return event.getBlockColors().getColor(block.defaultBlockState(), null, null, tintIndex); - }, BWGBlocks.TINY_LILY_PADS.get(), BWGBlocks.FLOWERING_TINY_LILY_PADS.get(), BWGBlocks.CLOVER_PATCH.get(), BWGBlocks.LEAF_PILE.get(), BWGBlocks.POISON_IVY.get() - , BWGWood.MAHOGANY.leaves(), BWGWood.WILLOW.leaves(), BWGWood.MAPLE.leaves(), BWGWood.YUCCA_LEAVES.get(), BWGWood.FLOWERING_YUCCA_LEAVES.get(), BWGWood.RIPE_YUCCA_LEAVES.get(), BWGWood.CYPRESS.leaves(), BWGBlocks.LUSH_GRASS_BLOCK.get() - , BWGBlocks.OVERGROWN_DACITE.get(), BWGBlocks.OVERGROWN_STONE.get()); + eventBus.addListener((RegisterColorHandlersEvent.Item event) -> BiomesWeveGoneClient.registerItemColors(event::register, event.getBlockColors())); } } diff --git a/NeoForge/src/main/java/net/potionstudios/biomeswevegone/neoforge/client/BiomesWeveGoneClientNeoForge.java b/NeoForge/src/main/java/net/potionstudios/biomeswevegone/neoforge/client/BiomesWeveGoneClientNeoForge.java index 85a46ed60..61f430116 100644 --- a/NeoForge/src/main/java/net/potionstudios/biomeswevegone/neoforge/client/BiomesWeveGoneClientNeoForge.java +++ b/NeoForge/src/main/java/net/potionstudios/biomeswevegone/neoforge/client/BiomesWeveGoneClientNeoForge.java @@ -2,8 +2,6 @@ import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.Minecraft; -import net.minecraft.world.item.BlockItem; -import net.minecraft.world.level.block.Block; import net.neoforged.api.distmarker.Dist; import net.neoforged.bus.api.IEventBus; import net.neoforged.fml.common.Mod; @@ -16,7 +14,6 @@ import net.potionstudios.biomeswevegone.BiomesWeveGone; import net.potionstudios.biomeswevegone.client.BiomesWeveGoneClient; import net.potionstudios.biomeswevegone.world.level.block.BWGBlocks; -import net.potionstudios.biomeswevegone.world.level.block.wood.BWGWood; /** * This class is used to initialize the Forge client side of the mod. @@ -38,24 +35,10 @@ public BiomesWeveGoneClientNeoForge(final IEventBus eventBus) { eventBus.addListener((RegisterParticleProvidersEvent event) -> BiomesWeveGoneClient.registerParticles((type, spriteProviderFactory) -> event.registerSpriteSet(type, spriteProviderFactory::apply))); eventBus.addListener((EntityRenderersEvent.RegisterLayerDefinitions event) -> BiomesWeveGoneClient.registerLayerDefinitions(event::registerLayerDefinition)); eventBus.addListener((RegisterColorHandlersEvent.Block event) -> BiomesWeveGoneClient.registerBlockColors(event::register)); - eventBus.addListener(BiomesWeveGoneClientNeoForge::registerItemColorHandlers); + eventBus.addListener((RegisterColorHandlersEvent.Item event) -> BiomesWeveGoneClient.registerItemColors(event::register, event.getBlockColors())); eventBus.addListener(BiomesWeveGoneClientNeoForge::registerGUILayers); } - /** - * Registers the item color handlers for the mod. - * @param event The event to register the item color handlers to. - * @see RegisterColorHandlersEvent.Item - */ - private static void registerItemColorHandlers(final RegisterColorHandlersEvent.Item event) { - event.register((stack, tintIndex) -> { - Block block = ((BlockItem) stack.getItem()).getBlock(); - return event.getBlockColors().getColor(block.defaultBlockState(), null, null, tintIndex); - }, BWGBlocks.TINY_LILY_PADS.get(), BWGBlocks.FLOWERING_TINY_LILY_PADS.get(), BWGBlocks.CLOVER_PATCH.get(), BWGBlocks.LEAF_PILE.get(), BWGBlocks.POISON_IVY.get() - , BWGWood.MAHOGANY.leaves(), BWGWood.WILLOW.leaves(), BWGWood.MAPLE.leaves(), BWGWood.YUCCA_LEAVES.get(), BWGWood.FLOWERING_YUCCA_LEAVES.get(), BWGWood.RIPE_YUCCA_LEAVES.get(), BWGWood.CYPRESS.leaves(), BWGBlocks.LUSH_GRASS_BLOCK.get() - , BWGBlocks.OVERGROWN_DACITE.get(), BWGBlocks.OVERGROWN_STONE.get()); - } - /** * Registers the GUI layers for the mod. * @see RegisterGuiLayersEvent