Skip to content

Commit

Permalink
register backpack model layer definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
UpcraftLP committed Jan 13, 2024
1 parent a6c6850 commit fd9a576
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dev.cammiescorner.camsbackpacks.CamsBackpacks;
import dev.cammiescorner.camsbackpacks.block.BackpackBlock;
import dev.cammiescorner.camsbackpacks.client.CamsBackpacksClient;
import dev.cammiescorner.camsbackpacks.client.models.BackpackModel;
import dev.cammiescorner.camsbackpacks.config.BackpacksConfig;
import dev.cammiescorner.camsbackpacks.init.ModBlocks;
import dev.cammiescorner.camsbackpacks.item.BackpackItem;
Expand All @@ -14,16 +15,16 @@
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.ConfigScreenHandler;
import net.minecraftforge.client.event.EntityRenderersEvent;
import net.minecraftforge.client.event.RegisterColorHandlersEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.ForgeRegistries;

@OnlyIn(Dist.CLIENT)
@Mod.EventBusSubscriber(modid = CamsBackpacks.MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.FORGE)
@Mod.EventBusSubscriber(modid = CamsBackpacks.MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD)
public class Client {

public static void init() {
Expand All @@ -34,14 +35,18 @@ public static void init() {
(minecraft, parent) -> new ConfigScreen(parent, null, CamsBackpacks.CONFIGURATOR.getConfig(BackpacksConfig.class))
)
);

FMLJavaModLoadingContext.get().getModEventBus().addListener(Client::clientSetup);
}

private static void clientSetup(FMLClientSetupEvent event) {
@SubscribeEvent
public static void clientSetup(FMLClientSetupEvent event) {
event.enqueueWork(CamsBackpacksClient::init);
}

@SubscribeEvent
public static void registerModelDefinitions(EntityRenderersEvent.RegisterLayerDefinitions event) {
event.registerLayerDefinition(CamsBackpacksClient.BACKPACK, BackpackModel::getTexturedModelData);
}

@SubscribeEvent
public static void registerBlockColors(RegisterColorHandlersEvent.Block event) {
event.register((state, world, pos, tintIndex) -> ColorHelper.dyeToDecimal(((BackpackBlock) state.getBlock()).getColour()), ForgeRegistries.BLOCKS.getValues().stream().filter(block -> block instanceof BackpackBlock backpack && (backpack.getColour() != DyeColor.WHITE || backpack == ModBlocks.WHITE_BACKPACK.get())).toArray(Block[]::new));
Expand Down

0 comments on commit fd9a576

Please sign in to comment.