Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.