Jump to content

Dyeable Items


HobbyProgrammer

Recommended Posts

Hello,

I'm trying to create a spray can. You can craft it with dye to set the color of the spray can. My problem is that I can't manage to change the texture of every spray can. I have a red part in my texture, it should be colored in the corresponding color. My texture is saved as two images, one with the part to be colored and one with the part not to be colored (as different layers in the item json file). Here is the code for the spray can class:

import net.minecraft.item.*;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.NonNullList;

public class SprayCanItem extends Item {

    private static final String NBT_COLOR = "SprayCanColor";

    public SprayCanItem() {
        super(new Properties().group(ItemGroup.MISC).maxStackSize(1).maxDamage(1));
    }

    public static int getSprayCanColor(ItemStack stack){
        return stack.getOrCreateTag().getInt(NBT_COLOR);
    }

    public static void setSprayCanColor(ItemStack stack, int color){
        stack.getOrCreateTag().putInt(NBT_COLOR, color);
    }

    public static int getItemColor(ItemStack stack, int tintIndex){
        if(tintIndex == 0){
            return getSprayCanColor(stack);
        }
        return 0xFF0000;
    }

    @Override
    public void fillItemGroup(ItemGroup group, NonNullList<ItemStack> items) {
        if(isInGroup(group)){
            for(DyeColor color : DyeColor.values()){
                ItemStack stack = new ItemStack(this);
                setSprayCanColor(stack, color.getTextColor());
                items.add(stack);
            }
        }
    }
}

Here is my ColorHandlers class:

import de.finnfreitag.mymod.Init.ItemInit;
import de.finnfreitag.mymod.items.SprayCanItem;
import net.minecraftforge.client.event.ColorHandlerEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;

public class ColorHandlers {
    @SubscribeEvent
    public static void registerItemColor(ColorHandlerEvent.Item event){
        event.getItemColors().register(SprayCanItem::getItemColor, ItemInit.SPRAYCAN.get());
    }
}

I use this tutorial: https://www.youtube.com/watch?v=c434w7uGeRE

In the tutorial the items have the specific color. Only spray cans in one color are displayed for me.

 

I hope anyone can help me!

Edited by HobbyProgrammer
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



×
×
  • Create New...

Important Information

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