Jump to content

GUI displays same item in 2 slots


loawkise

Recommended Posts

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

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.