Jump to content

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


Recommended Posts

Posted (edited)

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

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

    • that happens every time I enter a new dimension.
    • This is the last line before the crash: [ebwizardry]: Synchronising spell emitters for PixelTraveler But I have no idea what this means
    • What in particular? I barely used that mod this time around, and it's never been a problem in the past.
    • Im trying to build my mod using shade since i use the luaj library however i keep getting this error Reason: Task ':reobfJar' uses this output of task ':shadowJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. So i try adding reobfJar.dependsOn shadowJar  Could not get unknown property 'reobfJar' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. my gradle file plugins { id 'eclipse' id 'idea' id 'maven-publish' id 'net.minecraftforge.gradle' version '[6.0,6.2)' id 'com.github.johnrengelman.shadow' version '7.1.2' id 'org.spongepowered.mixin' version '0.7.+' } apply plugin: 'net.minecraftforge.gradle' apply plugin: 'org.spongepowered.mixin' apply plugin: 'com.github.johnrengelman.shadow' version = mod_version group = mod_group_id base { archivesName = mod_id } // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. java.toolchain.languageVersion = JavaLanguageVersion.of(17) //jarJar.enable() println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" minecraft { mappings channel: mapping_channel, version: mapping_version copyIdeResources = true runs { configureEach { workingDirectory project.file('run') property 'forge.logging.markers', 'REGISTRIES' property 'forge.logging.console.level', 'debug' arg "-mixin.config=derp.mixin.json" mods { "${mod_id}" { source sourceSets.main } } } client { // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. property 'forge.enabledGameTestNamespaces', mod_id } server { property 'forge.enabledGameTestNamespaces', mod_id args '--nogui' } gameTestServer { property 'forge.enabledGameTestNamespaces', mod_id } data { workingDirectory project.file('run-data') args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') } } } sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { flatDir { dirs './libs' } maven { url = "https://jitpack.io" } } configurations { shade implementation.extendsFrom shade } dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" implementation 'org.luaj:luaj-jse-3.0.2' implementation fg.deobf("com.github.Virtuoel:Pehkui:${pehkui_version}") annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' minecraftLibrary 'luaj:luaj-jse:3.0.2' shade 'luaj:luaj-jse:3.0.2' } // Example for how to get properties into the manifest for reading at runtime. tasks.named('jar', Jar).configure { manifest { attributes([ 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors, 'Specification-Version' : '1', // We are version 1 of ourselves 'Implementation-Title' : project.name, 'Implementation-Version' : project.jar.archiveVersion, 'Implementation-Vendor' : mod_authors, 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", "TweakOrder" : 0, "MixinConfigs" : "derp.mixin.json" ]) } rename 'mixin.refmap.json', 'derp.mixin-refmap.json' } shadowJar { archiveClassifier = '' configurations = [project.configurations.shade] finalizedBy 'reobfShadowJar' } assemble.dependsOn shadowJar reobf { re shadowJar {} } publishing { publications { mavenJava(MavenPublication) { artifact jar } } repositories { maven { url "file://${project.projectDir}/mcmodsrepo" } } } my entire project:https://github.com/kevin051606/DERP-Mod/tree/Derp-1.0-1.20
  • Topics

×
×
  • Create New...

Important Information

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