package me.km; import java.awt.Color; import me.km.blocks.ModBlocks; import me.km.blocks.cauldron.TileEntityCauldron; import me.km.entities.ModEntities; import me.km.items.ItemColoredSoup; import me.km.items.ItemGemStone; import me.km.items.ModItems; import me.km.items.ModelCylinder; import me.km.items.ModelHat; import me.km.networking.KeyManager; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.model.ModelBiped; import net.minecraft.client.renderer.block.model.ModelBakery; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.client.renderer.block.statemap.StateMapperBase; import net.minecraft.client.renderer.color.BlockColors; import net.minecraft.client.renderer.color.IBlockColor; import net.minecraft.client.renderer.color.ItemColors; import net.minecraft.client.renderer.entity.Render; import net.minecraft.entity.Entity; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; import net.minecraft.world.ColorizerGrass; import net.minecraft.world.IBlockAccess; import net.minecraft.world.biome.BiomeColorHelper; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fluids.IFluidBlock; import net.minecraftforge.fml.client.registry.RenderingRegistry; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class ClientProxy extends CommonProxy { @Override public void registerItemRenderer(Item item, int meta, String id, String variant) { ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(KajetansMod.MODID + ":" + id, variant)); } @Override public void registerItemRenderer(Item item, int meta, String id) { registerItemRenderer(item, meta, id, null); } @Override public void registerFluidModel(IFluidBlock fluidBlock) { final Item item = Item.getItemFromBlock((Block) fluidBlock); assert item != null; ModelBakery.registerItemVariants(item); ModelResourceLocation modelResourceLocation = new ModelResourceLocation(KajetansMod.MODID + ":fluids", fluidBlock.getFluid().getName()); ModelLoader.setCustomMeshDefinition(item, MeshDefinitionFix.create(stack -> modelResourceLocation)); ModelLoader.setCustomStateMapper((Block) fluidBlock, new StateMapperBase() { @Override protected ModelResourceLocation getModelResourceLocation(IBlockState state) { return modelResourceLocation; } }); } @Override public void registerEntityRenderer(Class c, Render r) { RenderingRegistry.registerEntityRenderingHandler(c, r); } @Override public void init() { ModEntities.initClient(); MinecraftForge.EVENT_BUS.register(new ClientEvents()); MinecraftForge.EVENT_BUS.register(new KeyManager()); BlockColors bColors = Minecraft.getMinecraft().getBlockColors(); bColors.registerBlockColorHandler((IBlockState state, IBlockAccess w, BlockPos pos, int tintIndex) -> { TileEntityCauldron tile = (TileEntityCauldron) w.getTileEntity(pos); if(tile == null) { return -16777216; } Color c = tile.getColor(); return -16777216 | c.getRed() << 16 | c.getGreen() << 8 | c.getBlue(); }, ModBlocks.cauldronOak, ModBlocks.cauldronAcacia, ModBlocks.cauldronBigOak, ModBlocks.cauldronBirch, ModBlocks.cauldronJungle, ModBlocks.cauldronSpruce); IBlockColor tallGrass = (IBlockState state, IBlockAccess w, BlockPos pos, int tintIndex) -> { if(w != null && pos != null) { return BiomeColorHelper.getGrassColorAtPos(w, pos); } else { return ColorizerGrass.getGrassColor(0.5D, 1.0D); } }; bColors.registerBlockColorHandler(tallGrass, ModBlocks.tallGrass); ItemColors iColors = Minecraft.getMinecraft().getItemColors(); iColors.registerItemColorHandler((ItemStack stack, int tintIndex) -> tintIndex > 0 ? -1 : ((ItemColoredSoup) stack.getItem()).getColor(stack), ModItems.coloredSoup); iColors.registerItemColorHandler((ItemStack stack, int tintIndex) -> tintIndex > 0 ? -1 : ((ItemGemStone) stack.getItem()).getColor(stack), ModItems.gemStone, ModItems.rawGemStone, ModItems.flawlessGemStone); iColors.registerItemColorHandler((ItemStack stack, int tintIndex) -> { IBlockState state = ((ItemBlock) stack.getItem()).getBlock().getStateFromMeta(stack.getMetadata()); return tallGrass.colorMultiplier(state, null, null, tintIndex); }, ModBlocks.tallGrass); } @SideOnly(Side.CLIENT) private final static ModelHat STRAW_HAT = new ModelHat(1.0f); @SideOnly(Side.CLIENT) private final static ModelCylinder CYLINDER = new ModelCylinder(1.0f); @Override public ModelBiped getCylinderModel() { return CYLINDER; } @Override public ModelBiped getStrawHatModel() { return STRAW_HAT; } }