Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I am just starting to learn how to make GUIs and I have recently made one that has a 2x3 inventory at the top and a 2x1 inventory at the bottom, like the normal inventory just 2 wide. When I put anything in the top left slot it also appears in the bottom left slot and I don't understand why.

  • Author

Here it is, I am using the one you gave me and I ma trying to adapt it.

 

 

package com.blocklings.entity;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;

public class ContainerBlockling extends Container {
protected IInventory gear;

private int player_inventory_x = 70;
private int player_inventory_y = 8;
private int loot_x = 8;
private int loot_y = 10;

public ContainerBlockling(InventoryPlayer inventoryPlayer, IInventory c) {
	gear = c;
	{
		int isize = c.getSizeInventory();
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 2; j++) {
				addSlotToContainer(new Slot(c, j + i * 2, (loot_x + j * 18), (loot_y + i * 18)));
			}
		}
		for (int j = 0; j < 2; j++) {
			addSlotToContainer(new SlotUpgrade(c, j * 2, (loot_x + j * 18), (loot_y + j + 4 * 18)));
		}
	}
	bindPlayerInventory(inventoryPlayer);
}

public boolean canInteractWith(EntityPlayer player) {
	return gear.isUseableByPlayer(player);
}

protected void bindPlayerInventory(InventoryPlayer inventoryPlayer) {
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 9; j++) {
			addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, player_inventory_x + j * 18, player_inventory_y + i * 18));
		}
	}

	for (int i = 0; i < 9; i++) {
		addSlotToContainer(new Slot(inventoryPlayer, i, player_inventory_x + i * 18, player_inventory_y + 54 + 4));
	}
}

public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) {
	ItemStack itemstack = null;
	Slot slot = (Slot) this.inventorySlots.get(par2);

	if (slot != null && slot.getHasStack()) {
		ItemStack itemstack1 = slot.getStack();
		itemstack = itemstack1.copy();

		int s = gear.getSizeInventory();

		if (par2 < s) {
			if (!this.mergeItemStack(itemstack1, s, this.inventorySlots.size(), true)) {
				return null;
			}
		} else if (!this.mergeItemStack(itemstack1, 0, s, false)) {
			return null;
		}

		if (itemstack1.stackSize == 0) {
			slot.putStack(null);
		} else {
			slot.onSlotChanged();
		}
	}

	return itemstack;
}

public void onContainerClosed(EntityPlayer par1EntityPlayer) {
	super.onContainerClosed(par1EntityPlayer);
	this.gear.closeInventory();
}
}

 

Slots in container numerated from 0 to inventory_size - 1

 

Let's look at your code.

 

for (int i = 0; i < 3; i++) {
for (int j = 0; j < 2; j++) {
  addSlotToContainer(new Slot(c, j + i * 2, (loot_x + j * 18), (loot_y + i * 18)));
}

 

This code adds slots: 0, 1, 2, 3, 4, 5

 

for (int j = 0; j < 2; j++) {
addSlotToContainer(new SlotUpgrade(c, j * 2, (loot_x + j * 18), (loot_y + j + 4 * 18)));
}

 

This code adds slots: 0 (again), and 5 (again)

 

I think you should edit second part to this:

for (int j = 0; j < 2; j++) {
addSlotToContainer(new SlotUpgrade(c, 6 + j, (loot_x + j * 18), (loot_y + j + 4 * 18)));
}

And it will add slots 6 and 7 instead of 0 and 5

  • Author

Thanks for explaining it and showing me what to do. It makes a lot more sense now. Once last thing though, I want to check the item in a current slot so how would I go about that?

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.