Skip to content

Commit

Permalink
Move ItemColor Handlers to Common Client (Forge/NeoForge)
Browse files Browse the repository at this point in the history
Signed-off-by: Joseph T. McQuigg <[email protected]>
  • Loading branch information
JT122406 committed Dec 2, 2024
1 parent add3e5a commit fc76370
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -133,6 +137,15 @@ public static void registerBlockColors(BiConsumer<BlockColor, Block[]> 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<ItemColor, ItemLike[]> 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));

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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.
Expand All @@ -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()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit fc76370

Please sign in to comment.