Jump to content

Dynamic-Size Container


Reika

Recommended Posts

I have a chest whose inventory size changes depending on the variables in the TileEntity. While it runs perfectly at "open time", the container only ever gets that one chance to calculate the number of slots to draw. Trying to reload the container failed horribly (Java.lang.ArrayIndexOutOfBounds with Index = NaN) and I know of no way to "refresh" it, seeing as all calculations are called from the constructor. Is there a way to do what I want to do, without simply forcing the GUI to closeGui (which is annoying and impractical)?

My Container:

public ContainerScaleChest(IInventory par1IInventory, TileEntityScaleableChest par2IInventory)
{
	lowerScaleChestInventory = par2IInventory;
	chest = par2IInventory;
	size = par2IInventory.getSizeInventory();
	par2IInventory.openChest();
	this.setSlots(par1IInventory, par2IInventory);
}
private void setSlots(IInventory par1IInventory, TileEntityScaleableChest te) {
	int var3 = 0;
	int var4 = 8;
	int var5 = 18;
	int page = chest.page;
	int rowsize = size;
	if (rowsize > chest.MAXROWS*9)
		rowsize = chest.MAXROWS*9;
	if (page == chest.getMaxPage()) {
		rowsize = size-(page*9*chest.MAXROWS);
	}
	int rows = (int)Math.ceil(rowsize/9D);
	int x = 0; int y = 0;
	//ReikaJavaLibrary.pConsole(size);
	//ReikaJavaLibrary.pConsole(rowsize);
	//ReikaJavaLibrary.pConsole(page);

	for (var3 = 0; var3 < rowsize; var3++) {
		y = var5+var3/9*18; x = var4+18*(var3%9);
		//ReikaJavaLibrary.pConsole(var3+"  ->   "+x+", "+y);
		this.addSlotToContainer(new Slot(te, var3+page*9*chest.MAXROWS, x, y));
	}
	var5 = chest.MAXROWS*18+31;//rows*18+31;
	//var4 = 44+18*(rows-1);
	int k;
	for (k = 0; k < 3; ++k) {
		for (int m = 0; m < 9; ++m) {
			var3 = m+9*k;
			y = var5+k*18; x = var4+18*m;
			this.addSlotToContainer(new Slot(par1IInventory, m + k * 9 + 9, x, y));
		}
	}
	var5 += 58;
	for (k = 0; k < 9; ++k) {
		y = var5; x = var4+18*k;
		this.addSlotToContainer(new Slot(par1IInventory, k, x, y));
	}
}
public void reset(IInventory par1IInventory, TileEntityScaleableChest te) {
	//inventorySlots.clear();
	//this.func_94533_d();
	//this.setSlots(par1IInventory, te);
}

Link to comment
Share on other sites

My guess is client/server disparity.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

My guess is client/server disparity.

Containers are only loaded server-side, so how I could get a disparity within itself is beyond me.

 

But the GUI is client side! ;)

(And the tile entity is on both)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

My guess is client/server disparity.

Containers are only loaded server-side, so how I could get a disparity within itself is beyond me.

 

But the GUI is client side! ;)

(And the tile entity is on both)

 

The GUI works fine. The item slots (that is, what index slots correlate to what index in inventory[]) are controlled by the Container alone.

Link to comment
Share on other sites

  • 3 weeks later...

That thing is something what i want to know too.

 

Is it possible to change the container with a number inside of an tile?

 

i mean if in the tile is something like that:

 

int containermode = -1;

 

if(containermode == 0)

{

  loadContainerSize1;

}

else if(containermode == 1)

{

  loadContainerSize2;

}

else

{

loadContainerSize0;

}

 

is this possible?

Link to comment
Share on other sites

That thing is something what i want to know too.

 

Is it possible to change the container with a number inside of an tile?

 

i mean if in the tile is something like that:

 

int containermode = -1;

 

if(containermode == 0)

{

  loadContainerSize1;

}

else if(containermode == 1)

{

  loadContainerSize2;

}

else

{

loadContainerSize0;

}

 

is this possible?

Easily. Put a check in getClientGUIElement(TE).

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

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.