Posted January 14, 201312 yr I'm trying to make an item which decays into another item over time. I've managed to get the decaying to work properly, which was a post i put on here a while ago and got no responses to, but now when the stack changes the Item it is replaced with is not of the same type as it should be (i.e. i tried changing it to stone for test purposes but the item it is replaced with will not stack with stone. Anyone know how to fix this? Here's the relevant parts of the code: @Override public void onCreated(ItemStack stack,World world,EntityPlayer player) { if(stack.itemID == ModResorces.decay.shiftedIndex){ setWorldTimer(stack, world); } } @Override public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5) { if(stack.stackTagCompound == null && stack.itemID == ModResorces.decay.shiftedIndex){ setWorldTimer(stack, world); return; }else if(stack.itemID != ModResorces.decay.shiftedIndex){ return; } if(world.getTotalWorldTime() >= stack.stackTagCompound.getLong("EndTime")){ stack.itemID = 1; }else{ stack.setItemDamage(201 - (int)(stack.stackTagCompound.getLong("EndTime") - world.getTotalWorldTime())); } } public void setWorldTimer(ItemStack stack, World world) { if(stack.itemID == ModResorces.decay.shiftedIndex && stack.stackTagCompound == null) { stack.setTagCompound(new NBTTagCompound()); } stack.stackTagCompound.setLong("EndTime", world.getTotalWorldTime() + 200); } github
January 14, 201312 yr Probably the player don't get the changes,add this after changing itemstack. ((EntityPlayer)entity).inventoryContainer.detectAndSendChanges();
January 14, 201312 yr Author sounds reasonable but there doesn't seem to be a method called "detectAndSendChanges()", or anything similar github
January 14, 201312 yr Author FIXED IT @Override public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5) { if(stack.stackTagCompound == null && stack.itemID == ModResorces.decay.shiftedIndex){ setWorldTimer(stack, world); return; }else if(stack.itemID != ModResorces.decay.shiftedIndex){ return; } if(world.getTotalWorldTime() >= stack.stackTagCompound.getLong("EndTime")) { stack.itemID = ModItems.adamantiumBucket.shiftedIndex; for(int i = 0; i < 36; i++){ if (((EntityPlayer)entity).inventory.mainInventory[i] != null){ if(((EntityPlayer)entity).inventory.mainInventory[i] == stack){ ((EntityPlayer)entity).inventory.mainInventory[i] = new ItemStack(Block.stone); } } } }else{ stack.setItemDamage(201 - (int)(stack.stackTagCompound.getLong("EndTime") - world.getTotalWorldTime())); } } Not sure if the null check is needed, but it doesn't hurt to put it there, Thanks for putting me onto the track of looking at what i could do with the inventory Thanks a tonne github
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.