Jump to content

Recommended Posts

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?

Posted

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

}

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.