Jump to content

Recommended Posts

Posted

Hey all!

 

So while making a crate, that displays a 3x3 grid, I get this error.

 

I already tried messing with it and still haven't found a fix, here is the class:

 

  Reveal hidden contents

 

 

Here is where its crashing:

	for (int y = 0; y < TE_INVENTORY_SLOT_COUNT_ROW; y++) {
		for (int x = 0; x < TE_INVENTORY_SLOT_COUNT_COLUMN; x++) {
			int slotNumber = TE_INVENTORY_SLOT_COUNT + y * TE_INVENTORY_SLOT_COUNT_COLUMN + x;
			int xpos = TILE_INVENTORY_XPOS + x * SLOT_X_SPACING;
			int ypos = TILE_INVENTORY_YPOS + y * SLOT_Y_SPACING;
			addSlotToContainer(new Slot(tileEntityInventoryBasic, slotNumber, TILE_INVENTORY_XPOS + SLOT_X_SPACING * x, TILE_INVENTORY_YPOS));
		}
	}
}

 

Thanks!

Not new to java >> New to modding.

Posted

int slotNumber = TE_INVENTORY_SLOT_COUNT + y * TE_INVENTORY_SLOT_COUNT_COLUMN + x;

 

Run that math through your head again.

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.

Posted
  On 11/15/2016 at 12:56 AM, Jazzable said:

It's everyone's favourite zero index problem. Slot index = slot count - 1.

 

Actually, its not.  See my post.

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.

Posted
  On 11/15/2016 at 12:43 AM, Draco18s said:

int slotNumber = TE_INVENTORY_SLOT_COUNT + y * TE_INVENTORY_SLOT_COUNT_COLUMN + x;

 

Run that math through your head again.

 

yeah, it gets me the 9 slots that I want. I dont see any other way i could do that.

Not new to java >> New to modding.

Posted

int slotNumber = TE_INVENTORY_SLOT_COUNT + y * TE_INVENTORY_SLOT_COUNT_COLUMN + x;

(3+0)*(3+0) = 9

(3+0)*(3+1) = 12

(3+0)*(3+2) = 15

....

(3+3)*(3+3) = 36

 

I don't think your implementation & your expectation of what should happen are the same.

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Posted

Okay, look back at the crafting table and found this:

 

            this.addSlotToContainer(new Slot(tileEntityInventoryBasic, x + y * 3, TILE_INVENTORY_XPOS + x * 18,TILE_INVENTORY_YPOS  + y * 18));

 

This seems to work, can somebody explain?

Not new to java >> New to modding.

Posted
  On 11/15/2016 at 1:43 AM, diesieben07 said:

  Quote

int slotNumber = TE_INVENTORY_SLOT_COUNT + y * TE_INVENTORY_SLOT_COUNT_COLUMN + x;

(3+0)*(3+0) = 9

(3+0)*(3+1) = 12

(3+0)*(3+2) = 15

....

(3+3)*(3+3) = 36

Ehm, those brackets are wrong.

It should be

3+(0*3)+0 = 3

3+(0*3)+1 = 4

3+(0*3)+2 = 5

....

3+(3*3)+3 = 15

 

The first

TE_INVENTORY_SLOT_COUNT

in that calculation just doesn't make sense there...

 

Correction:

  Quote
private final int TE_INVENTORY_SLOT_COUNT = 9;

9+(0*3)+0 = 9

9+(0*3)+1 = 10

9+(0*3)+2 = 11

....

9+(3*3)+3 = 21

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.

Posted
  On 11/15/2016 at 2:17 AM, gmod622 said:

Okay, look back at the crafting table and found this:

 

            this.addSlotToContainer(new Slot(tileEntityInventoryBasic, x + y * 3, TILE_INVENTORY_XPOS + x * 18,TILE_INVENTORY_YPOS  + y * 18));

 

This seems to work, can somebody explain?

 

It works because it doesn't have the TE_INVENTORY_SLOT_COUNT added at the beginning like your code in the OP does - so it results in 0, 1, 2, ... 8. Your code results in 9, 10, 11, ... 17. When you add a Slot, you need to give it the index for the inventory it is connected to, not the index of the slot in the container.

Posted

Hi

 

I think the confusion is because the "TE_INVENTORY_SLOT_COUNT" offset is necessary for the player hotbar and the inventory - which is how the vanilla chest is set up (the GUI shows the player hotbar, the player inventory, and the chest contents).  For your own TileEntity it will usually start from zero.

 

//  0 - 8 = hotbar slots (which will map to the InventoryPlayer slot numbers 0 - 
//  9 - 35 = player inventory slots (which map to the InventoryPlayer slot numbers 9 - 35)
//  36 - 44 = TileInventory slots, which map to our TileEntity slot numbers 0 - 

	// Add the players hotbar to the gui - the [xpos, ypos] location of each item
	for (int x = 0; x < HOTBAR_SLOT_COUNT; x++) {
		int slotNumber = x;
		addSlotToContainer(new Slot(invPlayer, slotNumber, HOTBAR_XPOS + SLOT_X_SPACING * x, HOTBAR_YPOS));
	}

	// Add the rest of the players inventory to the gui
	for (int y = 0; y < PLAYER_INVENTORY_ROW_COUNT; y++) {
		for (int x = 0; x < PLAYER_INVENTORY_COLUMN_COUNT; x++) {
			int slotNumber = HOTBAR_SLOT_COUNT + y * PLAYER_INVENTORY_COLUMN_COUNT + x;
			int xpos = PLAYER_INVENTORY_XPOS + x * SLOT_X_SPACING;
			int ypos = PLAYER_INVENTORY_YPOS + y * SLOT_Y_SPACING;
			addSlotToContainer(new Slot(invPlayer, slotNumber,  xpos, ypos));
		}
	}

	// Add the tile inventory container to the gui
	for (int x = 0; x < TE_INVENTORY_SLOT_COUNT; x++) {
		int slotNumber = x;
		addSlotToContainer(new Slot(tileEntityInventoryBasic, slotNumber,
                            TILE_INVENTORY_XPOS + SLOT_X_SPACING * x, TILE_INVENTORY_YPOS));
	}

 

-TGG

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.