Posted May 26, 20178 yr Hello, I have my code all set to create custom armor from my bronze ingots that is dyeable like vanilla leather armor. The dying itself works, the nbt tags gets applied and the armor model itself gets properly colored. The only thing that doesnt get colored is the actual inventory sprite. Kind of ironic considering for most solutions ive been searching for have the inverse problem. My code as follows: Colorable Armor Class: protected String name; public static int DEFAULT_COLOR = 14277081;// white // = 8388608; //6684672 // white = 14277081 //public static final int DEFAULT_COLOR = 11324652; public ItemModArmor(ArmorMaterial materialIn, int renderIndexIn, EntityEquipmentSlot equipmentSlotIn, String name) { super(materialIn, renderIndexIn, equipmentSlotIn); //this.DEFAULT_COLOR = BASE_COLOR; this.name = name; setUnlocalizedName(name); setRegistryName(name); setCreativeTab(resTab.resItems); } @Override public void registerItemModel(Item item) { respublica.proxy.registerItemRenderer(this, 0, name); } @Override public ItemModArmor setCreativeTab(CreativeTabs tab) { super.setCreativeTab(tab); return this; } /* If to use overlay */ public boolean hasOverlay(ItemStack stack) { return true; } @Override public boolean hasColor(ItemStack stack) { return !stack.hasTagCompound() ? false : (!stack.getTagCompound().hasKey("display", 10) ? false : stack.getTagCompound().getCompoundTag("display").hasKey("color", 3)); } @Override public int getColor(ItemStack stack) { NBTTagCompound nbttagcompound = stack.getTagCompound(); if (nbttagcompound != null) { NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("display"); if (nbttagcompound1 != null && nbttagcompound1.hasKey("color", 3)){ return nbttagcompound1.getInteger("color"); } } return DEFAULT_COLOR; } public void removeColor(ItemStack stack) { NBTTagCompound nbttagcompound = stack.getTagCompound(); if (nbttagcompound != null) { NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("display"); if (nbttagcompound1.hasKey("color")) { nbttagcompound1.removeTag("color"); } } } public void setColor(ItemStack stack, int color) { NBTTagCompound nbttagcompound = stack.getTagCompound(); if (nbttagcompound == null) { nbttagcompound = new NBTTagCompound(); stack.setTagCompound(nbttagcompound); } NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("display"); if (!nbttagcompound.hasKey("display", 10)){ nbttagcompound.setTag("display", nbttagcompound1); } nbttagcompound1.setInteger("color", color); } Armor dying color: /* Copied and Modified MineCraft->Item->Crafting->RecipesArmorDyes */ public class armorDyes implements IRecipe { /* Receives Item Stack of the armor */ public boolean matches(InventoryCrafting inv, World worldIn) { ItemStack itemstack = ItemStack.EMPTY; List<ItemStack> list = Lists.<ItemStack>newArrayList(); for (int i = 0; i < inv.getSizeInventory(); ++i) { ItemStack itemstack1 = inv.getStackInSlot(i); if (!itemstack1.isEmpty()) { if (itemstack1.getItem() instanceof ItemModArmor) { ItemModArmor itemarmor = (ItemModArmor)itemstack1.getItem(); itemstack = itemstack1; } else { if (itemstack1.getItem() != Items.DYE) { return false; } list.add(itemstack1); } } } return !itemstack.isEmpty() && !list.isEmpty(); } /* Returns an Item that is the result of this recipe */ public ItemStack getCraftingResult(InventoryCrafting inv) { ItemStack itemstack = ItemStack.EMPTY; int[] aint = new int[3]; int i = 0; int j = 0; ItemModArmor itemarmor = null; for (int k = 0; k < inv.getSizeInventory(); ++k) { ItemStack itemstack1 = inv.getStackInSlot(k); if (!itemstack1.isEmpty()) { if (itemstack1.getItem() instanceof ItemModArmor) { itemarmor = (ItemModArmor)itemstack1.getItem(); itemstack = itemstack1.copy(); itemstack.setCount(1); if (itemarmor.hasColor(itemstack1)) { int l = itemarmor.getColor(itemstack); float f = (float)(l >> 16 & 255) / 255.0F; float f1 = (float)(l >> 8 & 255) / 255.0F; float f2 = (float)(l & 255) / 255.0F; i = (int)((float)i + Math.max(f, Math.max(f1, f2)) * 255.0F); aint[0] = (int)((float)aint[0] + f * 255.0F); aint[1] = (int)((float)aint[1] + f1 * 255.0F); aint[2] = (int)((float)aint[2] + f2 * 255.0F); ++j; } } else { if (itemstack1.getItem() != Items.DYE) { return ItemStack.EMPTY; } float[] afloat = EntitySheep.getDyeRgb(EnumDyeColor.byDyeDamage(itemstack1.getMetadata())); int l1 = (int)(afloat[0] * 255.0F); int i2 = (int)(afloat[1] * 255.0F); int j2 = (int)(afloat[2] * 255.0F); i += Math.max(l1, Math.max(i2, j2)); aint[0] += l1; aint[1] += i2; aint[2] += j2; ++j; } } } if (itemarmor == null) { return ItemStack.EMPTY; } else { int i1 = aint[0] / j; int j1 = aint[1] / j; int k1 = aint[2] / j; float f3 = (float)i / (float)j; float f4 = (float)Math.max(i1, Math.max(j1, k1)); i1 = (int)((float)i1 * f3 / f4); j1 = (int)((float)j1 * f3 / f4); k1 = (int)((float)k1 * f3 / f4); int lvt_12_3_ = (i1 << 8) + j1; lvt_12_3_ = (lvt_12_3_ << 8) + k1; itemarmor.setColor(itemstack, lvt_12_3_); return itemstack; } } /* Returns the size of the recipe area */ public int getRecipeSize() { return 10; } public ItemStack getRecipeOutput() { return ItemStack.EMPTY; } public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv) { NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(inv.getSizeInventory(), ItemStack.EMPTY); for (int i = 0; i < nonnulllist.size(); ++i) { ItemStack itemstack = inv.getStackInSlot(i); nonnulllist.set(i, net.minecraftforge.common.ForgeHooks.getContainerItem(itemstack)); } return nonnulllist; } } Edited May 27, 20178 yr by daruskiy
May 27, 20178 yr You need to register an IItemColor implementation using ItemColors::registerItemColorHandler. You can obtain an instance of ItemColors with Minecraft::getItemColors
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.