Posted June 7, 201510 yr I'm doing some experimenting, and that involves making a chestplate capable of storing an Item object. Unfortunately, this Item object is reset whenever the game is restarted (closed and reopened, leaving a world and coming back in the same instance of the game does not trigger the bug). I'm a novice modder, and, thus, I don't know what I've done wrong. I find it likely that the answer will be something blatantly obvious. Could someone please enlighten me? ItemInlayArmor class: package com.ferret.relics.items; import java.util.List; import com.ferret.myfirstmod.MyFirstMod; import com.ferret.myfirstmod.items.ModItems; import com.ferret.relics.Relics; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemArmor; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemArmor.ArmorMaterial; import net.minecraft.potion.PotionEffect; import net.minecraft.world.World; public class ItemInlayArmor extends ItemArmor { Item focus; public ItemInlayArmor(ArmorMaterial material, int renderIndex, int armorType, String name) { super(material, 0, armorType); setUnlocalizedName(Relics.MODID + "_" + name); System.out.println(this.getUnlocalizedName()); } public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type) { return Relics.MODID + ":models/armor/inlayarmor1.png"; } public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn) { if(itemStackIn.getItem() instanceof ItemInlayArmor) { if(playerIn.isSneaking()) { ItemInlayArmor item = (ItemInlayArmor)itemStackIn.getItem(); int focusTarget = playerIn.inventory.currentItem + 1; if(playerIn.inventory.getStackInSlot(focusTarget) != null) { Item focusItem = playerIn.inventory.getStackInSlot(focusTarget).getItem(); playerIn.inventory.decrStackSize(focusTarget, 1); item.focus = focusItem; itemStackIn.setItem(item); } } } return itemStackIn; } @Override public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4) { if(focus != null) list.add(focus.getUnlocalizedName()); else list.add("Empty"); } @Override public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) { if(itemStack.getItem() instanceof ItemInlayArmor) { if(focus != null) { if(focus.equals(Items.rabbit_foot)) { player.addPotionEffect(new PotionEffect(8, 300, 3)); } } } } }
June 7, 201510 yr Hi Having a member variable 'focus' in your Item class won't work for two reasons: 1) There is only one instance of ItemInlayArmor, so if you have more than one of these (eg two players both have the armour) it will overwrite. 2) You haven't written any load / save code for focus. You need to store this information in ItemStack NBT instead. It might help to read up on this background info about ItemStacks http://greyminecraftcoder.blogspot.com.au/2013/12/items.html This tutorial project has an example of an item which stores NBT information, which is what you need to do. https://github.com/TheGreyGhost/MinecraftByExample see MBE12 https://github.com/TheGreyGhost/MinecraftByExample/blob/master/src/main/java/minecraftbyexample/mbe12_item_nbt_animate/Notes.txt -TGG
June 8, 201510 yr Author Thanks! One more question: I haven't delved in to containers yet, but would I need knowledge of them if I wanted to have the item store an actual ItemStack?
June 8, 201510 yr You don't need the knowledge at least you are not using GUIs. I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.
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.