Silivek Posted September 3, 2020 Posted September 3, 2020 (edited) My code is probably horrendous and an abomination, but I need some help figuring out where I went wrong. It's kinda difficult to find help on this by using google. Item Class: package soii.races.items; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.NonNullList; import soii.races.RaceType; import soii.races.Races; public class ChangerItem extends Item{ static ArrayList<String> tokenTypes = new ArrayList<String>(); //Colors I want to use static ArrayList<Integer> tokenColors = new ArrayList<Integer>(Arrays.asList(0x00AFAF, 0xD3D3D3, 0x13AA12, 0xCC00FA, 0x5061A4, 0xA80E0E, 0x565656, 0xE69494, 0xE67973, 0xFF0000, 0x967234, 0x2C8004, 0x6C6454, 0xCCC130, 0x5EA496, 0x525858)); private static final String NBT_COLOR = "TokenColor"; private static final String NBT_TYPE = "tokenType"; public ChangerItem() { super(new Item.Properties().group(Races.TAB).maxStackSize(1)); } public static void tokenTypeMaker(List<RaceType> races) { for(RaceType i : races) { tokenTypes.add(i.getName()); } } @Override public String getTranslationKey(ItemStack stack) { if(tokenTypes.size() == 0) { tokenTypeMaker(Races.RACES); } if(stack.hasTag()) { CompoundNBT itemData = stack.getTag(); if(itemData.contains(NBT_TYPE)) { return "item." + itemData.getString(NBT_TYPE) + "Token"; } } return "item.nullToken"; } public static int getTokenColor(ItemStack stack) { return stack.getOrCreateTag().getInt(NBT_COLOR); } public static void setTokenColor(ItemStack stack, int color) { stack.getOrCreateTag().putInt(NBT_COLOR, color); } public static String getTokenType(ItemStack stack) { return stack.getOrCreateTag().getString(NBT_TYPE); } public static void setTokenType(ItemStack stack, String name) { stack.getOrCreateTag().putString(NBT_TYPE, name); } public static int getItemColor(ItemStack stack, int tintIndex) { if(tintIndex == 0) { return getTokenColor(stack); } return 0xFFFFFF; } @Override public void fillItemGroup(ItemGroup group, NonNullList<ItemStack> items) { if(this.isInGroup(group)) { for (int i = 0; i < tokenTypes.size(); i++) { ItemStack stack = new ItemStack(this); setTokenType(stack, tokenTypes.get(i)); setTokenColor(stack, tokenColors.get(i)); items.add(stack); } } } } Color Handler: package soii.races.client; import net.minecraftforge.client.event.ColorHandlerEvent; import soii.races.ChangerColor; import soii.races.items.ChangerItem; public class ColorHandlers { public static void registerItemColors(ColorHandlerEvent.Item event) { ChangerItem item = new ChangerItem(); event.getItemColors().register(new ChangerColor(), item); } } Intermediary between IItemColor and other 2 classes (I don't know what i'm doing here): package soii.races; import net.minecraft.client.renderer.color.IItemColor; import net.minecraft.item.ItemStack; import soii.races.items.ChangerItem; public class ChangerColor implements IItemColor{ @Override public int getColor(ItemStack stack, int tintIndex) { return ChangerItem.getItemColor(stack, tintIndex); } } There isn't an error code or anything, the textures just show up as the default texture instead of the colored one. Let me know if you have any input or if you need more information. Edited September 3, 2020 by Silivek Quote
poopoodice Posted September 3, 2020 Posted September 3, 2020 (edited) Is the event triggered? Edited September 4, 2020 by poopoodice Quote
Silivek Posted September 3, 2020 Author Posted September 3, 2020 I have a listener set to the ColorHandler's function if that's what you mean Quote
Beethoven92 Posted September 3, 2020 Posted September 3, 2020 4 minutes ago, Silivek said: I have a listener set to the ColorHandler's function if that's what you mean But are you sure this event is actually triggering? That's what poopoodice meant..you can test if the event is triggering for example by logging something on the console or any other action that produce a visible result (of course inside the event handler) Quote Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port
Silivek Posted September 4, 2020 Author Posted September 4, 2020 Sorry I took so long to get back to you. I was a little bit busy. I did a println in the event handler and it did not output anything, so does that mean I'm using the wrong event or that my item isn't triggering the event? Quote
Beethoven92 Posted September 4, 2020 Posted September 4, 2020 Look, right now you event handler is just a normal class with a method inside..there is nothing making it an actual event listener. Your event handler is missing something Quote Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port
Silivek Posted September 4, 2020 Author Posted September 4, 2020 Okay, I added a tag to the Handler, is this more correct? It caused the println to happen once at the beginning, but not ingame. package soii.races.client; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.event.ColorHandlerEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import soii.races.ChangerColor; import soii.races.items.ChangerItem; @EventBusSubscriber(value = Dist.CLIENT) public class ColorHandlers { @SubscribeEvent public static void registerItemColors(ColorHandlerEvent.Item event) { System.out.println("Working!"); event.getItemColors().register(new ChangerColor(), new ChangerItem()); } } Quote
Beethoven92 Posted September 4, 2020 Posted September 4, 2020 That means your event handler is now actually doing something, and correctly listening to the ColorHandlerEvent Quote Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port
Silivek Posted September 4, 2020 Author Posted September 4, 2020 So that just means my other code is wrong now? Quote
Silivek Posted September 4, 2020 Author Posted September 4, 2020 I got it working! Thanks for your help! package soii.races.client; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.event.ColorHandlerEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import soii.races.items.ChangerItem; import soii.races.util.RegistryHandler; @EventBusSubscriber(value = Dist.CLIENT) public class ColorHandlers { @SubscribeEvent public static void registerItemColors(ColorHandlerEvent.Item event) { event.getItemColors().register(ChangerItem::getItemColor, RegistryHandler.CHANGER_TOKEN.get()); } } Quote
Recommended Posts
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.