Posted October 30, 201411 yr My custom item leaves my inventory after I save and quit the world then enter again, no clue why.
October 30, 201411 yr Author There is the item code: package com.blocklings.items; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; import net.minecraft.entity.IEntityLivingData; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.MathHelper; import net.minecraft.util.StatCollector; import net.minecraft.world.World; import com.blocklings.entity.EntityBlockling; import com.blocklings.main.Blocklings; public class ItemBlockling extends Item { public EntityBlockling blockling; public int level, xp, upgrade, special; public String blocklingName, name; public ItemBlockling() { super(); this.setUnlocalizedName("blockling"); this.setMaxStackSize(1); this.setTextureName(Blocklings.MODID + ":" + "blockling"); } public ItemBlockling(String name, int level, int xp, int upgrade, int special) { super(); this.setUnlocalizedName("blockling"); this.setMaxStackSize(1); this.setTextureName(Blocklings.MODID + ":" + "blockling"); blocklingName = name; this.level = level; this.xp = xp; this.upgrade = upgrade; this.special = special; } @Override public void onUpdate(ItemStack itemStack, World world, Entity entity, int i, boolean b) { itemStack.stackTagCompound = new NBTTagCompound(); if(blocklingName.length() > 0) { name = blocklingName; } else { name = "Blockling"; } for(int j = 0; j < 1; j++) { itemStack.stackTagCompound.setString("name", blocklingName); itemStack.stackTagCompound.setInteger("level", level); itemStack.stackTagCompound.setInteger("xp", xp); itemStack.stackTagCompound.setInteger("upgrade", upgrade); itemStack.stackTagCompound.setInteger("special", special); } level = itemStack.stackTagCompound.getInteger("level"); } @Override public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) { EntityBlockling blockling = new EntityBlockling(world, level, xp, upgrade, special); blockling.setLocationAndAngles(player.posX, player.posY, player.posZ, MathHelper.wrapAngleTo180_float(world.rand.nextFloat() * 360.0F), 0.0F); blockling.onSpawnWithEgg((IEntityLivingData)null); if(!world.isRemote) world.spawnEntityInWorld(blockling); if(!world.isRemote) world.playSoundAtEntity(blockling, "fireworks.twinkle1", 1.0F, 1.0F); if(!world.isRemote) itemStack.stackSize--; return itemStack; } @Override public String getItemStackDisplayName(ItemStack itemStack) { return name; } }
October 30, 201411 yr Author I thought because I am using NBT that the variables would be different as they get saved and then set again, or am I missing something? When I have two different items they work fine, as if they were two different items.
October 30, 201411 yr Author They need to be used in multiple methods and I need to remove the first constructor.
October 31, 201411 yr Author That makes sense, sorry. However, why does doing this in my entity class, mean the item that I pick up disappears after I exit the world? if(this.isDead && !this.worldObj.isRemote) { this.worldObj.spawnEntityInWorld(new EntityItem(this.worldObj, posX, posY, posZ, new ItemStack(new ItemBow().setUnlocalizedName("bow").setTextureName("bow")))); }
October 31, 201411 yr new ItemBow() You are creating a new item instance. The game doesn't know what it is after reload. Thus the info gets discarded. Use "Items.bow".
October 31, 201411 yr Author If I wanted to do it like that for a custom item that takes parameters in the constructor depending on things within the entity class, how can I do that? I thought that would be the way to do it.
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.