Posted June 25, 20205 yr Hi there, I've implemented an Item with a 1-slot inventory using capabilities. The inventory is then accessible through a GUI on item right click. Everything seems to work fine, but I've observed that the `serializeNBT()` method is fired too often (every tick apparently) when the item is in the players' inventory, even though I do not fire at all such method manually (afaik...). Is this the expected behaviour of the capabilities system, or am I missing or wrongdoing something? Thanks in advance public class MyItem extends Item { public MyItem(){ super(); } @Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand){ ItemStack stack = player.getHeldItem(hand); if(!world.isRemote) player.openGui(MyMod.instance, 0, world, (int)player.posX, (int)player.posY, (int)player.posZ); return ActionResult.newResult(EnumActionResult.PASS, stack); } @Override public ICapabilityProvider initCapabilities(ItemStack item, NBTTagCompound nbt) { if(item.getItem() instanceof MyItem) { return new MyCapabilityProvider(); } return null; } public class MyCapabilityProvider implements ICapabilityProvider, ICapabilitySerializable<NBTTagCompound> { private final IItemHandler inventory; public MyCapabilityProvider(){ inventory = new ItemStackHandler(1); } @Override public NBTTagCompound serializeNBT() { return ((ItemStackHandler)inventory).serializeNBT(); } @Override public void deserializeNBT(NBTTagCompound nbt) { ((ItemStackHandler)inventory).deserializeNBT(nbt); } @Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return true; return false; } @Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return (T)inventory; } return null; } } } Edited June 25, 20205 yr by logalu Marked as solved
June 25, 20205 yr Author Thanks for the reply. Good to know I didn't cause this, not so good to know this is unavoidable, but it is what it is Marking as solved
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.