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

Using Forge version 1.11-13.19.1.2195. I've set up a block, tile entity, container and GUI, and I want the container's slots to appear/disappear when a certain item is placed in one of the slots. I have tried setting each slot's xPosition, however the container's slots are only redrawn when the container is closed and re-opened. Is there a way to change the positions of the slots whilst the GUI for the block is still open?

  • Author

Sorry if I'm missing something really obvious here, but after the container has been opened, using addSlotToContainer() or slot.xDisplayPosition doesn't move the slots in my container.

  • Author

This is my container class. As far as I understand detectAndSendChanges() runs every tick, so that means as soon as the GUI is opened, slot 4 should be moved to position (0,0), and slot 3 should be moved to position (10,10). But this doesn't happen.

 

package kemm.common.container;

import kemm.Util;
import kemm.common.block.SingleSlotBlock;
import kemm.common.item.modules.Module;
import kemm.common.item.modules.Module.EnumPosition;
import kemm.common.tileentity.SingleSlot;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.SlotItemHandler;

public class ContainerBlock extends Container {

private SingleSlot te;
private World blockWorld;
private BlockPos position;
private IInventory plInv;

public ContainerBlock(IInventory playerInv, SingleSlot tile_entity, World worldIn, BlockPos pos) {
	this.te = tile_entity;
	this.blockWorld = worldIn;
	this.position = pos;
	this.plInv = playerInv;
	addBlockSlots();
	addPlayerSlots(playerInv);
	System.out.println("Drawing container");
}

private void addPlayerSlots(IInventory playerInv) {
	//Inventory
	for (int row = 0; row < 3; row++) {
		for (int col = 0; col < 9; col++) {
			int x = 48 + col * 18;
			int y = 171 + row * 18;
			this.addSlotToContainer(new Slot(playerInv, col + row * 9 + 9, x, y));
		}
	}
	//Hotbar
	for (int col = 0; col < 9; col++) {
		int x = 48 + col * 18;
		int y = 229;
		this.addSlotToContainer(new Slot(playerInv, col, x, y));
	}
}

private void addBlockSlots() {

	IItemHandler handler = this.te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
	//Draw module-input slots
	for (int col = 0; col < 2; col++ ) {
		for(int row = 0; row < 3; row++) {
			int slotNo = row + col*3;
			int x = col * 90 + 75;
			int y = row * 18 + 62;

			if (slotNo < SingleSlotBlock.size) {
				addSlotToContainer(new SlotModule(handler, this, slotNo, x, y));
			}
		}

	}		
}


@Override
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
	return null;
}

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


@Override
public void detectAndSendChanges() {
	setSlotPosition(this.getSlot(4), 0, 0);
	setSlotPosition(this.getSlot(3), 10, 10);
	super.detectAndSendChanges();
}



public void setSlotPosition(Slot slot, int xPos, int yPos) {
	slot.xDisplayPosition = xPos;
	slot.yDisplayPosition = yPos;
}

}

  • Author

Sorry, I was being stupid. Needed to change the positions in the container class and the GUI class (e.g. Client and Server so exactly what you said), thanks for your help  :)

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.