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