Jump to content

[SOLVED] Armor item texture not changing color (Inventory Item) [1.11]


daruskiy

Recommended Posts

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 by daruskiy
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • https://pastebin.com/VwpAW6PX My game crashes upon launch when trying to implement the Oculus mod to this mod compilation, above is the crash report, I do not know where to begin to attempt to fix this issue and require assistance.
    • This has been released asย 49.0.49.
    • https://youtube.com/shorts/gqLTSMymgUg?si=5QOeSvA4TTs-bL46
    • CubeHaven is a SMP server with unique features that can't be found on the majority of other servers! Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132 3 different stores: - CubeHaven Store: Our store to purchase using real money. - Bitcoin Store: Store for Bitcoin. Bitcoin can be earned from playing the server. Giving options for players if they want to spend real money or grind to obtain exclusive packages. - Black Market: A hidden store for trading that operates outside our traditional stores, like custom enchantments, exclusive items and more. Some of our features include: Rank Up: Progress through different ranks to unlock new privileges and perks. ๐Ÿ“ˆ Skills: RPG-style skill system that enhances your gaming experience! ๐ŸŽฎ Leaderboards: Compete and shine! Top players are rewarded weekly! ๐Ÿ† Random Teleporter: Travel instantly across different worlds with a click! ๐ŸŒ Custom World Generation: Beautifully generated world. ๐ŸŒ Dungeons: Explore challenging and rewarding dungeons filled with treasures and monsters. ๐Ÿฐ Kits: Unlock ranks and gain access to various kits. ๐Ÿ› ๏ธ Fishing Tournament: Compete in a friendly fishing tournament! ๐ŸŽฃ Chat Games: Enjoy games right within the chat! ๐ŸŽฒ Minions: Get some help from your loyal minions. ๐Ÿ‘ฅ Piรฑata Party: Enjoy a festive party with Piรฑatas! ๐ŸŽ‰ Quests: Over 1000 quests that you can complete! ๐Ÿ“œ Bounty Hunter: Set a bounty on a player's head. ๐Ÿ’ฐ Tags: Displayed on nametags, in the tab list, and in chat. ๐Ÿท๏ธ Coinflip: Bet with other players on coin toss outcomes, victory, or defeat! ๐ŸŸข Invisible & Glowing Frames: Hide your frames for a cleaner look or apply a glow to it for a beautiful look. ๐Ÿ”ฒโœจ[ Player Warp: Set your own warp points for other players to teleport to. ๐ŸŒŸ Display Shop: Create your own shop and sell to other players! ๐Ÿ›’ Item Skins: Customize your items with unique skins. ๐ŸŽจ Pets: Your cute loyal companion to follow you wherever you go! ๐Ÿพ Cosmetics: Enhance the look of your character with beautiful cosmetics! ๐Ÿ’„ XP-Bottle: Store your exp safely in a bottle for later use! ๐Ÿถ Chest & Inventory Sorting: Keep your items neatly sorted in your inventory or chest! ๐Ÿ“ฆ Glowing: Stand out from other players with a colorful glow! โœจ Player Particles: Over 100 unique particle effects to show off. ๐ŸŽ‡ Portable Inventories: Over virtual inventories with ease. ๐Ÿงณ And a lot more! Become part of our growing community today! Discord:ย https://cubehaven.net/discord Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132
    • # Problematic frame: # C [libopenal.so+0x9fb4d] It is always the same issue - this refers to the Linux OS - so your system may prevent Java from working ย  I am not familiar with Linux - check for similar/related issues ย 
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.