Jump to content

[1.16.4] I have just a question about stack size.


zlappedx3

Recommended Posts

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);}
	
}

 

Link to comment
Share on other sites

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.

  • Thanks 1
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.