Jump to content

[1.8] getInventoryStackLimit


Mistram

Recommended Posts

I am triing to make a chest that can contain stacks with more then 64 Items.

My problem is that it seems that it wont accept if I let getInventoryStackLimit return more then 64. Any way to get around that?

 

Heres my code

 


public class TileEntityInfiniteChest extends TileEntity implements IInventory{


private ItemStack[] items;

@Override
public void writeToNBT(NBTTagCompound compound) {
	// TODO Auto-generated method stub
	super.writeToNBT(compound);

	NBTTagList items = new NBTTagList();

	for (int i=0; i<getSizeInventory(); i++)
	{
		ItemStack stack = getStackInSlot(i);
		if (stack!=null)
		{
			NBTTagCompound item = new NBTTagCompound();
			item.setByte("Slot", (byte) i);
			stack.writeToNBT(item);
			items.appendTag(item);
		}
	}
	compound.setTag("Items", items);
}

@Override
public void readFromNBT(NBTTagCompound compound) {
	super.readFromNBT(compound);

	NBTTagList items = (NBTTagList) compound.getTag("Items");
	if (items==null)
	{
		return;
	}

	for (int i = 0; i <items.tagCount(); i++) {
		NBTTagCompound item = items.getCompoundTagAt(i);
		byte slot = item.getByte("Slot");
		setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(item));
	}
}

public TileEntityInfiniteChest()
{
	items = new ItemStack[3];

}

@Override
public String getName() {
	return null;
}

@Override
public boolean hasCustomName() {
	return false;
}

@Override
public IChatComponent getDisplayName() {
	return null;
}

@Override
public int getSizeInventory() {
	return items.length;
}

@Override
public ItemStack getStackInSlot(int index) {
	return items[index];
}

@Override
public ItemStack decrStackSize(int index, int count) {
	ItemStack itemstack = getStackInSlot(index);

	if (itemstack!=null)
	{
		if (itemstack.stackSize <=count)
		{
			setInventorySlotContents(index, null);
		}
		else
		{
			itemstack= itemstack.splitStack(count);
			markDirty();

		}

	}


	return itemstack;
}

@Override
public ItemStack getStackInSlotOnClosing(int index) {
	ItemStack item = getStackInSlot(index);
	setInventorySlotContents(index, null);
	return item;
}

@Override
public void setInventorySlotContents(int index, ItemStack stack) {
	items[index] = stack;

}

@Override
public int getInventoryStackLimit() {
	return 128;
}

@Override
public boolean isUseableByPlayer(EntityPlayer player) {
	return player.getDistanceSqToCenter(pos)<=64;
}

@Override
public void openInventory(EntityPlayer player) {
	// TODO Auto-generated method stub

}

@Override
public void closeInventory(EntityPlayer player) {
	// TODO Auto-generated method stub

}

@Override
public boolean isItemValidForSlot(int index, ItemStack stack) {
	// TODO Auto-generated method stub
	return true;
}

@Override
public int getField(int id) {
	// TODO Auto-generated method stub
	return 0;
}

@Override
public void setField(int id, int value) {
	// TODO Auto-generated method stub

}

@Override
public int getFieldCount() {
	// TODO Auto-generated method stub
	return 0;
}

@Override
public void clear() {
	// TODO Auto-generated method stub

}

}

 

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.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.