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 have a Bug with my GUI Container...I want to make a Machine but there is a Bug with the Slots. I have a little Video from the Bug, here you can see:

And here is the Code:

TileEntity:

public class TileEntityChemicalMixer extends TileEntity{

public InventoryBasic INVENTORY;

public TileEntityChemicalMixer(){
	INVENTORY = new InventoryBasic("Chemical Mixer", false, 3);
}

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

	NBTTagList list = new NBTTagList();

	for(int i = 0; i < INVENTORY.getSizeInventory(); i++){
		if(INVENTORY.getStackInSlot(i) != null){
			NBTTagCompound tag = new NBTTagCompound();
			tag.setByte("Slot", (byte) i);
			INVENTORY.getStackInSlot(i).writeToNBT(tag);
			list.appendTag(tag);
		}
	}

	compound.setTag("ItemStacks", list);
}

@Override
public void readFromNBT(NBTTagCompound compound) {
	super.readFromNBT(compound);
	NBTTagList list = compound.getTagList("ItemStacks", 10);
	this.INVENTORY = new InventoryBasic("Chemical Mixer", false, 3);
	for(int i = 0; i < list.tagCount(); i++){
		NBTTagCompound tag = list.getCompoundTagAt(i);
		byte b = tag.getByte("Slot");
		if(b >= 0 && b < INVENTORY.getSizeInventory()){
			INVENTORY.setInventorySlotContents(b, ItemStack.loadItemStackFromNBT(tag));
		}
	}
}

}

Container:

public class ContainerChemicalMixer extends Container{

private TileEntityChemicalMixer tileentiy;

public ContainerChemicalMixer(IInventory inv, TileEntityChemicalMixer tileentity) {
	this.tileentiy = tileentity;
	this.addSlotToContainer(new Slot(inv, 0, 30, 17));
	this.addSlotToContainer(new Slot(inv, 0, 130, 17));

    // Player Inventory, Slot 9-35, Slot IDs 9-35
    for (int y = 0; y < 3; ++y) {
        for (int x = 0; x < 9; ++x) {
            this.addSlotToContainer(new Slot(inv, x + y * 9 + 9, 8 + x * 18, 84 + y * 18));
        }
    }

    // Player Inventory, Slot 0-8, Slot IDs 36-44
    for (int x = 0; x < 9; ++x) {
        this.addSlotToContainer(new Slot(inv, x, 8 + x * 18, 142));
    }
}

@Override
public boolean canInteractWith(EntityPlayer playerIn) {
	return true;
}

}

And GUI:

public class GuiChemicalMixer extends GuiContainer{

public static final ResourceLocation BACKGROUND = new ResourceLocation(Main.MODID + ":textures/gui/chemicalmixergui.png");

public GuiChemicalMixer(Container inventorySlotsIn) {
	super(inventorySlotsIn);
	this.ySize = 166;
	this.xSize = 176;
}

@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
	mc.renderEngine.bindTexture(BACKGROUND);
	int k = (this.width - this.xSize) / 2;
	int l = (this.height - this.ySize) / 2;
	drawTexturedModalRect(k, l, 0, 0, xSize, ySize);
}

}

Issue is here:

	this.addSlotToContainer(new Slot(inv, 0, 30, 17));
	this.addSlotToContainer(new Slot(inv, 0, 130, 17));

    // Player Inventory, Slot 0-8, Slot IDs 36-44
    for (int x = 0; x < 9; ++x) {
        this.addSlotToContainer(new Slot(inv, x, 8 + x * 18, 142));
    }

The Slot takes in the parameters IInventory, Index, xPos, yPos.

You have to declare the two top slots as something else. You declare the player's hotbar with the id's 0->8, not as the commented 36-44. The player's inventory 9->35. I'd recommend setting the two "main" slots to 36 & 37 respectively.

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.

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.