Posted April 2, 20178 yr Lately, I've been stuck trying to give certain 'energy' tools a different texture, depending on whether the player is holding the tool or not. The tools should how up in an 'active' state when held, and in a 'dormant' state otherwise. The code for the switching of states work jut fine, but I cannot figure out how to change the texture depending on the state. Either changing the texture altogether or adding a second layer onto an existing texture works for me. Thanks in advance! Here is all the (potentially) relevant code: Spoiler package items; import net.minecraft.entity.Entity; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; public class ItemModEnergyAxe extends ItemModAxe { ItemModEnergyAxe(String unlocalizedName, ToolMaterial material) { super(unlocalizedName, material); } ItemModEnergyAxe(String unlocalizedName, ToolMaterial material, String[] toolTip) { super(unlocalizedName, material, toolTip); } public String getUnlocalizedName(ItemStack stack) { if (stack.hasTagCompound()) { return "item.energy_axe_" + stack.getTagCompound().getString("state"); } return "item.energy_axe_dormant"; } public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { if (stack.getTagCompound() == null) { stack.setTagCompound(new NBTTagCompound()); } stack.getTagCompound().setString("state", isSelected ? "active" : "dormant"); } } Spoiler package items; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemAxe; import net.minecraft.item.ItemStack; import java.lang.reflect.Array; import java.util.List; class ItemModAxe extends ItemAxe { private final String[] toolTip; ItemModAxe(String unlocalizedName, ToolMaterial material, String[] toolTip) { super(material); this.setUnlocalizedName(unlocalizedName); this.toolTip = toolTip; } ItemModAxe(String unlocalizedName, ToolMaterial material) { super(material); this.setUnlocalizedName(unlocalizedName); this.toolTip = null; } public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) { if (toolTip != null) { for (int i = 0; i < Array.getLength(toolTip); i++) { tooltip.add("§5§o" + Array.get(toolTip, i)); } } } } Spoiler package items; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.EnumAction; import net.minecraft.item.Item; import net.minecraft.item.Item.ToolMaterial; import net.minecraft.item.ItemArmor.ArmorMaterial; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraftforge.common.util.EnumHelper; import net.minecraftforge.fml.common.registry.GameRegistry; public final class ModItems { //Other stuff public static Item energyPickaxe; public static Item energyAxe; public static Item energySpade; public static Item energyHoe; public static Item energySword; public static Item energyShears; //Other stuff public static void createItems() { //Other stuff GameRegistry.registerItem(energyPickaxe = new ItemModEnergyPickaxe("energy_pickaxe", energy), "energy_pickaxe"); GameRegistry.registerItem(energyAxe = new ItemModEnergyAxe("energy_axe", energy), "energy_axe"); GameRegistry.registerItem(energySpade = new ItemModEnergySpade("energy_spade", energy), "energy_spade"); GameRegistry.registerItem(energyHoe = new ItemModEnergyHoe("energy_hoe", energy), "energy_hoe"); GameRegistry.registerItem(energySword = new ItemModEnergySword("energy_sword", energy), "energy_sword"); GameRegistry.registerItem(energyShears = new ItemModEnergyShears("energy_shears", 999), "energy_shears"); //Other stuff } //Other sstuff private static final ToolMaterial energy = EnumHelper.addToolMaterial("energy", 8, 199, 20.0F, 15.0F, 75); } Spoiler package joienl.elementalmadness.client.render.items; import items.ModItems; import joienl.elementalmadness.ElementalMadness; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.item.Item; public final class ItemRenderRegister { public static void registerItemRenderer() { //Other stuff reg(ModItems.energyAxe); reg(ModItems.energyPickaxe); reg(ModItems.energySpade); reg(ModItems.energyHoe); reg(ModItems.energySword); reg(ModItems.energyShears); //Other stuff } private static void reg(Item item) { Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(ElementalMadness.MODID + ":" + item.getUnlocalizedName().substring(5), "inventory")); } } Spoiler package joienl.elementalmadness; import joienl.elementalmadness.client.model.ModelCobaltKobold; import joienl.elementalmadness.client.render.blocks.BlockRenderRegister; import joienl.elementalmadness.client.render.entity.EntityRenderRegister; import joienl.elementalmadness.client.render.entity.RenderCobaltKobold; import joienl.elementalmadness.client.render.items.ItemRenderRegister; import joienl.elementalmadness.entity.EntityCobaltKobold; import net.minecraft.client.Minecraft; import net.minecraftforge.fml.client.registry.RenderingRegistry; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; @SuppressWarnings("unused") public class ClientProxy extends CommonProxy { @Override public void preInit(FMLPreInitializationEvent e) { super.preInit(e); } @Override @SuppressWarnings({"deprecation", "unchecked"}) public void init(FMLInitializationEvent e) { super.init(e); BlockRenderRegister.registerBlockRenderer(); BlockRenderRegister.preInit(); ItemRenderRegister.registerItemRenderer(); EntityRenderRegister.registerEntityRenderer(); RenderingRegistry.registerEntityRenderingHandler(EntityCobaltKobold.class, new RenderCobaltKobold(Minecraft.getMinecraft().getRenderManager(), new ModelCobaltKobold())); } @Override public void postInit(FMLPostInitializationEvent e) { super.postInit(e); } } Spoiler package joienl.elementalmadness; import blocks.ModBlocks; import items.ModItems; import joienl.elementalmadness.crafting.ModCrafting; import joienl.elementalmadness.event.ModItemCraftedEvent; import joienl.elementalmadness.event.ModItemSmeltedEvent; import joienl.elementalmadness.event.ModPlayerTickEvent; import joienl.elementalmadness.network.ModGuiHandler; import joienl.elementalmadness.world.WorldGen; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.registry.GameRegistry; class CommonProxy { public void preInit(FMLPreInitializationEvent e) { ModBlocks.createBlocks(); ModItems.createItems(); ModBlocks.init(); } public void init(FMLInitializationEvent e) { ModCrafting.initCrafting(); GameRegistry.registerWorldGenerator(new WorldGen(), 0); NetworkRegistry.INSTANCE.registerGuiHandler(ElementalMadness.instance, new ModGuiHandler()); MinecraftForge.EVENT_BUS.register(new ModPlayerTickEvent()); MinecraftForge.EVENT_BUS.register(new ModItemSmeltedEvent()); MinecraftForge.EVENT_BUS.register(new ModItemCraftedEvent()); AchievementRegistry.registerAchievements(); } public void postInit(FMLPostInitializationEvent e) {} } Edited April 2, 20178 yr by JoieNL Misplaced some spoilers
April 2, 20178 yr Stumped on this same thing. I want the item from an earlier thread of mine to change textures when the NBT "Amount" is set. Would appreciate help!
April 2, 20178 yr You can probably use an IItemPropertyGetter, which can be used to change item models based on certain criteria. They are used by bows to change the texture depending on how long you have been holding down right click, for example. You can see how to use them in ItemBow and its associated json files. Edit: Also this post if you want another example. Edited April 2, 20178 yr by TheMasterGabriel
April 3, 20178 yr Alternatively, https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/java/com/draco18s/industry/item/ItemCastingMold.java#L80 https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/java/com/draco18s/hardlib/client/ClientEasyRegistry.java#L103-L109 Rather a bit more complicated, but very flexible. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
April 6, 20178 yr Author On 02/04/2017 at 7:26 PM, TheMasterGabriel said: You can probably use an IItemPropertyGetter, which can be used to change item models based on certain criteria. They are used by bows to change the texture depending on how long you have been holding down right click, for example. You can see how to use them in ItemBow and its associated json files. Edit: Also this post if you want another example. I've looked around a bit, and I believe IItemPropertyGetter is a 1.9+ interface. Could you point me to the exact location of the interface so I can doublecheck? On 03/04/2017 at 2:44 AM, Draco18s said: Alternatively, https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/java/com/draco18s/industry/item/ItemCastingMold.java#L80 https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/java/com/draco18s/hardlib/client/ClientEasyRegistry.java#L103-L109 Rather a bit more complicated, but very flexible. I notice you are using libraries I do not have. I haven't much experience with using libraries myself, but I'm not sure this helps out. Still, I thank you both for the quick replies.
April 6, 20178 yr All the libraries I use are my own. They're in the same repository. In fact, my second link is in said library. It shows how I use the interface I created in order to let the Item class dictate how it should handle its own NBT data for rendering, rather than having it externally. It's not any different than vanilla's IItemPropertyGetter, really. The only difference is that IItemPropertyGetter can only handle one type: floats. Edited April 6, 20178 yr by Draco18s Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
April 6, 20178 yr 1 hour ago, JoieNL said: I've looked around a bit, and I believe IItemPropertyGetter is a 1.9+ interface. Could you point me to the exact location of the interface so I can doublecheck? net.minecraft.item.IItemPropertyGetter. But this shouldn't be an issue to find, as you should be using 1.9+ already. Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
April 14, 20178 yr Author First of all, please excuse my recent absence. I've been quite busy lately. On 06/04/2017 at 7:06 PM, Draco18s said: All the libraries I use are my own. They're in the same repository. In fact, my second link is in said library. It shows how I use the interface I created in order to let the Item class dictate how it should handle its own NBT data for rendering, rather than having it externally. It's not any different than vanilla's IItemPropertyGetter, really. The only difference is that IItemPropertyGetter can only handle one type: floats. What I mean is that you are referencing some other classes and interfaces in your code (most notably IItemWithMeshDefinition and EasyRegistry) in your libraries. I cannot trace the data flow of your code so I can figure out what to do myself without these files (or I'm just being stupid, hell if I know). On 06/04/2017 at 7:57 PM, larsgerrits said: net.minecraft.item.IItemPropertyGetter. But this shouldn't be an issue to find, as you should be using 1.9+ already. Well, the title of this thread does say "[1.8]". That is, I'm modding in Minecraft version 1.8...
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.