Jump to content

Custom Item Disappears After Exiting World


qpwoeiruty

Recommended Posts

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;
        
    }

}

Link to comment
Share on other sites

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")))); 

	}

Link to comment
Share on other sites

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

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