January 28, 20169 yr Author ok this is what I have now and it works but sometimes is makes 2 items instead of 1 and it crashes after a couple jumps. public void onUpdate(ItemStack itemstack, World worldIn, Entity entity, int itemSlot, boolean isSelected) { EntityPlayer player = (EntityPlayer) entity; if (player.inventory.hasItem(this)) { List stacks = player.inventoryContainer.inventoryItemStacks; List slots = player.inventoryContainer.inventorySlots; int randintamount = slots.size(); int index = rand.nextInt(slots.size()); Slot slot = (Slot) slots.get(index); ItemStack stack = (ItemStack) stacks.get(index); if (player.worldObj.rand.nextInt(100) == 1) { if (stack == null) { player.inventory.setInventorySlotContents(index, itemstack); player.inventory.setInventorySlotContents(itemSlot, null); } else if (stack != null) { if (stack != itemstack) { player.inventory.setInventorySlotContents(index, itemstack); player.inventory.setInventorySlotContents(itemSlot, stack); } } } } } BioWarfare Mod: http://goo.gl/BYWQty
January 28, 20169 yr So. On update gets called everytime you have the item in your inventory. and still you are checking if you have items in your inventory. If you got a crash it helps A LOT if you show the crash.
January 28, 20169 yr Also im not sure why you are checking the random stack you get for null, since its not really making any difference. keep your code clean and it makes errors much easier to find
January 28, 20169 yr Author Ok so it duplicates when it goes into the Armour inventory so i need to stop that from happening. crash log: http://pastebin.com/g7b85G4N BioWarfare Mod: http://goo.gl/BYWQty
January 28, 20169 yr ur item has nothing to do in the armor slot. dont put it there..? modify ur random so its not giving u a random number that is a an armor slot
February 3, 20169 yr Author Fixed armour slot and crashing but it still multipies and I am not sure why becasue I make one item and delete the other thefore there should only be one item? private Random rand = new Random(); public void onUpdate(ItemStack itemstack, World worldIn, Entity entity, int itemSlot, boolean isSelected) { EntityPlayer player = (EntityPlayer) entity; if (player.inventory.hasItem(this)) { List stacks = player.inventoryContainer.inventoryItemStacks; List slots = player.inventoryContainer.inventorySlots; int index = rand.nextInt(35); Slot slot = (Slot) slots.get(index); ItemStack stack = (ItemStack) stacks.get(index); if (stack == null && index != itemSlot ) { player.inventory.setInventorySlotContents(index, itemstack); player.inventory.setInventorySlotContents(itemSlot, null); } else if (stack != null && index != itemSlot) { if (stack != itemstack) { player.inventory.setInventorySlotContents(index, itemstack); player.inventory.setInventorySlotContents(itemSlot, stack); } } } } BioWarfare Mod: http://goo.gl/BYWQty
February 3, 20169 yr Without even reading rest of code: You can (should, only exception is synchronization or administrative tools) only edit inventory from server: if(!world.isRemote){edit} 1.7.10 is no longer supported by forge, you are on your own.
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.