public static void registerColorHandlers() { final IItemColor ammoColor = (stack, tintIndex) -> { switch (tintIndex) { case 1: return getAmmoColor(stack); default: return Color.WHITE.getRGB(); } }; final IItemColor plasticColor = (stack, tintIndex) -> { int plasticColour = ItemPlastic.getColour(stack); return plasticColour >= 0 ? plasticColour : 0xffffff; }; Minecraft.getMinecraft().getItemColors().registerItemColorHandler(ammoColor, Itemss.GUN_AMMO); Minecraft.getMinecraft().getItemColors().registerItemColorHandler(plasticColor, Itemss.PLASTIC); }
public static void init() { RenderItem renderItem = Minecraft.getMinecraft().getRenderItem(); for (Map.Entry<String, Block> ent : renderMap.entrySet()) { renderItem.getItemModelMesher().register(Item.getItemFromBlock(ent.getValue()), 0, new ModelResourceLocation(Reference.MODID + ":" + ent.getKey(), "inventory")); } //TODO Convert to Lambda for (Map.Entry<Material, Block> entry : oreBlockMap.entrySet()) { Minecraft.getMinecraft().getItemColors().registerItemColorHandler(new IItemColor() { @Override public int getColorFromItemstack(ItemStack stack, int tintIndex) { return entry.getKey().getColour().getRGB(); } }, entry.getValue()); } }
@Override public void init() { super.init(); Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(BackpackMod.backpackItem, 0, new ModelResourceLocation("meddleBackpack", "inventory")); Minecraft.getMinecraft().itemColors.registerItemColor(new IItemColor() { @Override public int getItemColor(ItemStack arg0, int arg1) { Item item = arg0.getItem(); if (item instanceof ItemBackpack) { return ((ItemBackpack)item).getColorFromItemStack(arg0, arg1); } return 0xFFFFFFFF; } }, BackpackMod.backpackItem); MeddleClient.registerGuiHandler(this); }
@SideOnly(Side.CLIENT) public static void registerColoredBlocksAndItems() { NNList<Block> blocklist = new NNList<Block>(); NNList<Item> itemlist = new NNList<Item>(); for (RegistrationHolder<?, ?> holder : blocks) { Block block = holder.block; Item item = Item.getItemFromBlock(block); if (block instanceof IPaintable || block instanceof ITintedBlock || block instanceof ITintedItem || item instanceof ITintedItem) { blocklist.add(block); if (item != Items.AIR) { itemlist.add(item); } } else { if (block instanceof IBlockColor) { Minecraft.getMinecraft().getBlockColors().registerBlockColorHandler((IBlockColor) block, block); } if (item instanceof IItemColor) { Minecraft.getMinecraft().getItemColors().registerItemColorHandler((IItemColor) item, item); } } } PaintTintHandler handler = new PaintTintHandler(); Minecraft.getMinecraft().getBlockColors().registerBlockColorHandler(handler, blocklist.toArray(new Block[0])); Minecraft.getMinecraft().getItemColors().registerItemColorHandler(handler, itemlist.toArray(new Item[0])); }
@Load(side = Side.CLIENT, value = LoaderState.POSTINITIALIZATION) @SideOnly(Side.CLIENT) public void loadColors() { try { Field field = ItemColors.class.getDeclaredField("itemColorMap"); field.setAccessible(true); Map<IRegistryDelegate<Item>, IItemColor> itemColorMap = (Map<IRegistryDelegate<Item>, IItemColor>) field.get(Minecraft.getMinecraft().getItemColors()); cachedLiqueurs.forEach(liqueur -> itemColorMap.entrySet().stream().filter(entry -> entry.getKey().get().equals(liqueur)).forEach(entry -> Minecraft.getMinecraft().getItemColors().registerItemColorHandler(entry.getValue(), entry.getKey().get()))); } catch (Exception e) { FoodCraftReloaded.getLogger().error("Cannot get custom mesh definitions", e); } }
@Override public void registerItemColorHandlers(@Nonnull FMLInitializationEvent initializationEvent) { Minecraft.getMinecraft().getItemColors().registerItemColorHandler(new IItemColor() { @Override public int colorMultiplier(@Nonnull ItemStack stack, int tintIndex) { return tintIndex > 0 ? -1 : ((ItemWolfArmor) stack.getItem()).getColor(stack); } }, Items.LEATHER_WOLF_ARMOR); }
@Override @SideOnly(Side.CLIENT) public IItemColor getItemColor() { return new IItemColor() { @Override public int getColorFromItemstack(ItemStack item, int index) { return index == 0 ? color : -1; } }; }
@Override @SideOnly(Side.CLIENT) public IItemColor getItemColor() { return new IItemColor() { @Override public int getColorFromItemstack(ItemStack item, int index) { return color == null ? -1 : color.getColorFromItemstack(item, index); } }; }
@Override @SideOnly(Side.CLIENT) public IItemColor getItemColor() { return new IItemColor() { @Override public int getColorFromItemstack(ItemStack stack, int tintIndex) { return color; } }; }
private static <T extends Item & IColorItem> void registerItemColor() { ItemColors colors = Minecraft.getMinecraft().getItemColors(); for (T t : (List<T>) item_color) { IItemColor color = t.getItemColor(); if (color != null) { colors.registerItemColorHandler(color, t); AlchemyInitHook.push_event(t); } } }
@Override public void registerRenders() { int i; for (i = 0; i < ItemEnderBag.COLOURS.length; ++i) { Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(ModItems.enderbag, i, new ModelResourceLocation("enderbags" + ":" + "enderbag", "inventory")); } ItemColors items = Minecraft.getMinecraft().getItemColors(); items.registerItemColorHandler(new IItemColor() { @Override public int getColorFromItemstack(ItemStack stack, int tintIndex) { Item item = stack.getItem(); if (item instanceof IColorable) { return ((IColorable) item).getColorFromItemStack(stack, tintIndex); } else { return 0xFFFFFF; } } }, ModItems.enderbag); }
@Override public void registerRenders() { int i; for (i = 0; i < OpenLootBagsApi.INSTANCE.getBagManager().getBagTypes().size(); ++i) { Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(OpenLootBags.lootbag, i, new ModelResourceLocation("openlootbags" + ":" + "lootbag", "inventory")); } ItemColors items = Minecraft.getMinecraft().getItemColors(); items.registerItemColorHandler(new IItemColor() { @Override public int getColorFromItemstack(ItemStack stack, int tintIndex) { Item item = stack.getItem(); if (item instanceof IColorable) { return ((IColorable) item).getColorFromItemStack(stack, tintIndex); } else { return 0xFFFFFF; } } }, OpenLootBags.lootbag); }
@SideOnly(Side.CLIENT) public static void registerItemColour(Object object, IItemColor colourProvider) { ItemColors itemColors = Minecraft.getMinecraft().getItemColors(); if (object instanceof Item) itemColors.registerItemColorHandler(colourProvider, (Item) object); else if (object instanceof Block) itemColors.registerItemColorHandler(colourProvider, (Block) object); }
@Override public void registerItemColorHandler(Block block){ Item item = Item.getItemFromBlock(block); if (item instanceof IItemColor){ IItemColor iItemColor = (IItemColor)item; itemColor.registerItemColorHandler(iItemColor,block); } }
@Override public void registerItemColorHandler(Item item){ if (item instanceof IItemColor){ IItemColor iItemColor = (IItemColor)item; itemColor.registerItemColorHandler(iItemColor,item); } }
public static void init() { Minecraft.getMinecraft().getItemColors().registerItemColorHandler(new IItemColor() { @Override public int colorMultiplier(ItemStack stack, int tintIndex) { return ((ItemLootBag) stack.getItem()).getColor(stack, tintIndex); } }, (Item[]) ItemLootBag.getLootBags()); }
@Override public int getColorFromItemstack(@Nonnull ItemStack stack, int tintIndex) { if (Prep.isInvalid(stack)) { return -1; } Item item = stack.getItem(); Block block = Block.getBlockFromItem(item); if (block instanceof IPaintable) { IBlockState paintSource = ((IPaintable) block).getPaintSource(block, stack); if (paintSource != null) { final ItemStack paintStack = new ItemStack(paintSource.getBlock(), 1, paintSource.getBlock().getMetaFromState(paintSource)); if (paintStack.getItem() != item) { return Minecraft.getMinecraft().getItemColors().getColorFromItemstack(paintStack, tintIndex); } } } if (item instanceof IItemColor) { return ((IItemColor) item).getColorFromItemstack(stack, tintIndex); } if (item instanceof ITintedItem) { return ((ITintedItem) item).getItemTint(stack, tintIndex); } if (block instanceof IItemColor) { return ((IItemColor) block).getColorFromItemstack(stack, tintIndex); } if (block instanceof ITintedItem) { return ((ITintedItem) block).getItemTint(stack, tintIndex); } return -1; }
@Override public IItemColor getItemColor() { return ColorHandlers.MIMIC_COLORING; }
@Override public IItemColor getItemColor() { return ColorHandlers.ARMOR_COLORING; }
@Override public IItemColor getItemColor() { return ColorHandlers.BLOCK_ITEM_COLORING; }
@Override public IItemColor getItemColor() { return ColorHandlers.ECKSIE_COLORING; }
@SideOnly(Side.CLIENT) IItemColor getItemColor();
@Override public IItemColor getItemColor() { return null; }
@SideOnly(Side.CLIENT) public void addItemColors(IItemColor itemColor, Collection<Item> blocks) { addItemColors(itemColor, blocks.toArray(new Item[0])); }
@SideOnly(Side.CLIENT) public void addItemColors(IItemColor itemColor, Item... blocks) { Minecraft.getMinecraft().getItemColors().registerItemColorHandler(itemColor, blocks); }
@SideOnly(Side.CLIENT) public void addItemColors(IItemColor itemColor, Block[] blocks) { Minecraft.getMinecraft().getItemColors().registerItemColorHandler(itemColor, blocks); }
@Override @SideOnly(Side.CLIENT) public IItemColor getItemColor() { return null; }
@Override @SideOnly(Side.CLIENT) public void registerRenderThings(){ KeyBindings.init(); RenderingRegistry.registerEntityRenderingHandler(EntityBouncingBetty.class, new RenderBouncingBetty(Minecraft.getMinecraft().getRenderManager())); RenderingRegistry.registerEntityRenderingHandler(EntityIMSBomb.class, new RenderIMSBomb(Minecraft.getMinecraft().getRenderManager())); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityKeypadChest.class, new TileEntityKeypadChestRenderer()); ClientRegistry.bindTileEntitySpecialRenderer(TileEntitySecurityCamera.class, new TileEntitySecurityCameraRenderer()); TileEntityItemStackRenderer.instance = new ItemKeypadChestRenderer(); Block[] blocksToTint = { SCContent.reinforcedBrick, SCContent.reinforcedCobblestone, SCContent.reinforcedCompressedBlocks, SCContent.reinforcedDirt, SCContent.reinforcedDoubleStoneSlabs, SCContent.reinforcedDoubleStoneSlabs2, SCContent.reinforcedDoubleWoodSlabs, SCContent.reinforcedEndStoneBricks, SCContent.reinforcedHardenedClay, SCContent.reinforcedMetals, SCContent.reinforcedMossyCobblestone, SCContent.reinforcedNetherBrick, SCContent.reinforcedNewLogs, SCContent.reinforcedOldLogs, SCContent.reinforcedPrismarine, SCContent.reinforcedPurpur, SCContent.reinforcedQuartz, SCContent.reinforcedRedNetherBrick, SCContent.reinforcedRedSandstone, SCContent.reinforcedSandstone, SCContent.reinforcedStainedHardenedClay, SCContent.reinforcedStairsAcacia, SCContent.reinforcedStairsBirch, SCContent.reinforcedStairsBrick, SCContent.reinforcedStairsCobblestone, SCContent.reinforcedStairsDarkoak, SCContent.reinforcedStairsJungle, SCContent.reinforcedStairsNetherBrick, SCContent.reinforcedStairsOak, SCContent.reinforcedStairsPurpur, SCContent.reinforcedStairsQuartz, SCContent.reinforcedStairsRedSandstone, SCContent.reinforcedStairsSandstone, SCContent.reinforcedStairsSpruce, SCContent.reinforcedStairsStone, SCContent.reinforcedStairsStoneBrick, SCContent.reinforcedStone, SCContent.reinforcedStoneBrick, SCContent.reinforcedStoneSlabs, SCContent.reinforcedStoneSlabs2, SCContent.reinforcedWoodPlanks, SCContent.reinforcedWoodSlabs, SCContent.reinforcedWool }; //registering reinforced blocks color overlay for world Minecraft.getMinecraft().getBlockColors().registerBlockColorHandler((state, worldIn, pos, tintIndex) -> 0x999999, blocksToTint); //same thing for inventory Minecraft.getMinecraft().getItemColors().registerItemColorHandler((IItemColor)(stack, tintIndex) -> 0x999999, blocksToTint); }
@Override @SideOnly(Side.CLIENT) public void registerRenderThings(){ KeyBindings.init(); RenderingRegistry.registerEntityRenderingHandler(EntityBouncingBetty.class, new RenderBouncingBetty(Minecraft.getMinecraft().getRenderManager())); RenderingRegistry.registerEntityRenderingHandler(EntityIMSBomb.class, new RenderIMSBomb(Minecraft.getMinecraft().getRenderManager())); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityKeypadChest.class, new TileEntityKeypadChestRenderer()); ClientRegistry.bindTileEntitySpecialRenderer(TileEntitySecurityCamera.class, new TileEntitySecurityCameraRenderer()); TileEntityItemStackRenderer.instance = new ItemKeypadChestRenderer(); Block[] blocksToTint = { SCContent.reinforcedBrick, SCContent.reinforcedCobblestone, SCContent.reinforcedCompressedBlocks, SCContent.reinforcedConcrete, SCContent.reinforcedDirt, SCContent.reinforcedDoubleStoneSlabs, SCContent.reinforcedDoubleStoneSlabs2, SCContent.reinforcedDoubleWoodSlabs, SCContent.reinforcedEndStoneBricks, SCContent.reinforcedHardenedClay, SCContent.reinforcedMetals, SCContent.reinforcedMossyCobblestone, SCContent.reinforcedNetherBrick, SCContent.reinforcedNewLogs, SCContent.reinforcedOldLogs, SCContent.reinforcedPrismarine, SCContent.reinforcedPurpur, SCContent.reinforcedQuartz, SCContent.reinforcedRedNetherBrick, SCContent.reinforcedRedSandstone, SCContent.reinforcedSandstone, SCContent.reinforcedStainedHardenedClay, SCContent.reinforcedStairsAcacia, SCContent.reinforcedStairsBirch, SCContent.reinforcedStairsBrick, SCContent.reinforcedStairsCobblestone, SCContent.reinforcedStairsDarkoak, SCContent.reinforcedStairsJungle, SCContent.reinforcedStairsNetherBrick, SCContent.reinforcedStairsOak, SCContent.reinforcedStairsPurpur, SCContent.reinforcedStairsQuartz, SCContent.reinforcedStairsRedSandstone, SCContent.reinforcedStairsSandstone, SCContent.reinforcedStairsSpruce, SCContent.reinforcedStairsStone, SCContent.reinforcedStairsStoneBrick, SCContent.reinforcedStone, SCContent.reinforcedStoneBrick, SCContent.reinforcedStoneSlabs, SCContent.reinforcedStoneSlabs2, SCContent.reinforcedWoodPlanks, SCContent.reinforcedWoodSlabs, SCContent.reinforcedWool }; //registering reinforced blocks color overlay for world Minecraft.getMinecraft().getBlockColors().registerBlockColorHandler((state, worldIn, pos, tintIndex) -> 0x999999, blocksToTint); //same thing for inventory Minecraft.getMinecraft().getItemColors().registerItemColorHandler((IItemColor)(stack, tintIndex) -> 0x999999, blocksToTint); }
/** * Gets the color handler for the item. * * @return The color handler for the item. */ @SideOnly(Side.CLIENT) public IItemColor getColorHandler ();
/** * Registers a color handler for an item. This method is client side only, and should be * called during the init stage. * * @param item The item to register the handler for. * @param color The color handler to register. */ @SideOnly(Side.CLIENT) public void registerColorHandler (@Nonnull Item item, @Nonnull IItemColor color) { Minecraft.getMinecraft().getItemColors().registerItemColorHandler(color, item); }