Posted January 7, 20214 yr Can i set NonNullList size to 4096 ? i can't put my item slot 512 from my tile entity, when i put some item slot 512 it will change tile entity to slot 0.
January 8, 20214 yr Author Okay bro i know you don't understand i will exaple explain again when i set the my tileentity inventory max size to 4096 then and i create my slot on container max size (i mean track slot 4096) when i put some my item to slot id 512 and i leave the game and return to join world agian that item will change to slot id 0 from slot id 512. This my code : package test; import net.minecraft.block.BlockState; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.ItemStackHelper; import net.minecraft.inventory.container.Container; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.LockableLootTileEntity; import net.minecraft.util.IIntArray; import net.minecraft.util.NonNullList; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TranslationTextComponent; public class TileEntityExample extends LockableLootTileEntity{ private NonNullList<ItemStack> chestContents = NonNullList.withSize(4096, ItemStack.EMPTY); public TileEntityDM() { super(Register.TileEntityDM); } @Override public void read(BlockState state, CompoundNBT compound) { super.read(state, compound); this.chestContents = NonNullList.withSize(this.getSizeInventory(), ItemStack.EMPTY); if (!this.checkLootAndRead(compound)) { ItemStackHelper.loadAllItems(compound, this.chestContents); } } @Override public CompoundNBT write(CompoundNBT compound) { super.write(compound); if (!this.checkLootAndWrite(compound)) { ItemStackHelper.saveAllItems(compound, this.chestContents); } return compound; } @Override public CompoundNBT getUpdateTag() { return this.write(new CompoundNBT()); } @Override public int getSizeInventory() { return this.chestContents.size(); } @Override public NonNullList<ItemStack> getItems() { return this.chestContents; } @Override protected void setItems(NonNullList<ItemStack> itemsIn) { this.chestContents = itemsIn; } @Override protected ITextComponent getDefaultName() { return new TranslationTextComponent("container.chest"); } @Override protected Container createMenu(int id, PlayerInventory player) {return new GuiSomeServer(id, player, this);} }
January 8, 20214 yr First, do not use IInventory. Use capabilities via IItemHandler. Second, look into the methods you are using. The maximum index those methods can read is 255. So, whenever index 256 rolls around, the lowest eight bits are kept making index 256 act as index 0 when reloaded and repeats for every 256 values (this is also known as a narrowing primitive conversion as referenced by $5.1.3 of the JLS). This is not to mention the load method bitwise ANDs the resulting byte received making the limit even more guaranteed.
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.