Jump to content

[1.6.2][Items][Solved] Having to leave world for inventory to update.


Palaster

Recommended Posts

I have an item, when right clicked on a zombie, will consume current items and give another item. What is happening is that when I right click the zombie, the first items is being consumed, but the I'm not getting the other item, till I leave my world and re-login onto the world.

 

Here is the Item Code:

 

 

package evilmobs.items;

 

import java.util.List;

 

import net.minecraft.client.renderer.texture.IconRegister;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.entity.EntityLiving;

import net.minecraft.entity.EntityLivingBase;

import net.minecraft.entity.monster.EntityZombie;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.util.Icon;

import net.minecraft.util.MathHelper;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import evilmobs.EvilMobs;

import evilmobs.core.config.EvilMobsItems;

 

public class ItemSyringe extends Item {

 

@SideOnly(Side.CLIENT)

private Icon[] icons;

 

public static final String[] names = new String[] {"normal", "zombie"};

 

public ItemSyringe(int par1) {

super(par1);

setUnlocalizedName("syringe");

setCreativeTab(EvilMobs.tabEvilMobs);

setHasSubtypes(true);

setMaxDamage(0);

}

 

@Override

@SideOnly(Side.CLIENT)

public void registerIcons(IconRegister par1IconRegister) {

 

icons = new Icon[2];

 

for(int i = 0; i < icons.length; i++) {

icons = par1IconRegister.registerIcon("EvilMobs:syringe"+ i);

}

}

 

@Override

public Icon getIconFromDamage(int par1) {

return icons[par1];

}

 

@Override

@SideOnly(Side.CLIENT)

public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List) {

for (int x = 0; x < 2; x++) {

par3List.add(new ItemStack(this, 1, x));

}

}

 

@Override

public String getUnlocalizedName(ItemStack par1ItemStack) {

int i = MathHelper.clamp_int(par1ItemStack.getItemDamage(), 0, 15);

    return super.getUnlocalizedName() + "." + names;

}

 

@Override

public boolean func_111207_a(ItemStack itemstack, EntityPlayer player, EntityLivingBase entity) {

 

if (entity.worldObj.isRemote) {

return false;

}

 

if(player.isSneaking()) {

return false;

} else if(player.inventory.getFirstEmptyStack() != -1) {

 

if(itemstack.isItemEqual(new ItemStack(EvilMobsItems.syringe, 1, 0))) {

 

if (entity instanceof EntityZombie) {

 

entity.attackEntityAsMob(entity);

player.inventory.consumeInventoryItem(new ItemStack(EvilMobsItems.syringe, 1, 0).itemID);

player.inventory.addItemStackToInventory(new ItemStack(EvilMobsItems.syringe, 1, 1));

 

return true;

 

}

}

}

 

return false;

}

 

public static String itemName(int n) {

if(n == 0) {

return "Syringe";

}else if(n == 1) {

return "Zombie Blood";

}

return null;

}

 

}

 

 

 

 

Please help!

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.