mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-27 15:33:06 +00:00
156 lines
4.0 KiB
Java
156 lines
4.0 KiB
Java
package crazypants.enderio.teleport;
|
|
|
|
import java.awt.Point;
|
|
import java.util.List;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import com.enderio.core.client.gui.widget.GhostSlot;
|
|
import com.enderio.core.common.ContainerEnder;
|
|
import com.enderio.core.common.util.ArrayInventory;
|
|
|
|
import crazypants.enderio.machine.gui.IContainerWithTileEntity;
|
|
import crazypants.enderio.teleport.ContainerTravelAuth.AuthInventory;
|
|
|
|
public class ContainerTravelAuth extends ContainerEnder<AuthInventory> implements IContainerWithTileEntity {
|
|
|
|
static class AuthInventory extends ArrayInventory {
|
|
|
|
private ContainerTravelAuth container;
|
|
|
|
private AuthInventory(ItemStack[] inv) {
|
|
super(inv);
|
|
}
|
|
|
|
private void setContainer(ContainerTravelAuth container) {
|
|
this.container = container;
|
|
}
|
|
|
|
@Override
|
|
public void markDirty() {
|
|
super.markDirty();
|
|
container.dirty = true;
|
|
}
|
|
|
|
@Override
|
|
public int getSizeInventory() {
|
|
return items.length;
|
|
}
|
|
|
|
@Override
|
|
public ItemStack getStackInSlot(int i) {
|
|
if (i < 0 || i >= items.length) {
|
|
return null;
|
|
}
|
|
return items[i];
|
|
}
|
|
|
|
@Override
|
|
public ItemStack decrStackSize(int fromSlot, int amount) {
|
|
ItemStack item = items[fromSlot];
|
|
items[fromSlot] = null;
|
|
if (item == null) {
|
|
return null;
|
|
}
|
|
item.stackSize = 0;
|
|
return item;
|
|
}
|
|
|
|
@Override
|
|
public ItemStack getStackInSlotOnClosing(int i) {
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public void setInventorySlotContents(int i, ItemStack itemstack) {
|
|
if (itemstack != null) {
|
|
items[i] = itemstack.copy();
|
|
items[i].stackSize = 0;
|
|
} else {
|
|
items[i] = null;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public String getInventoryName() {
|
|
return "Password";
|
|
}
|
|
|
|
@Override
|
|
public int getInventoryStackLimit() {
|
|
return 0;
|
|
}
|
|
|
|
public ItemStack[] getInventory() {
|
|
return this.items;
|
|
}
|
|
}
|
|
|
|
private final TileEntity te;
|
|
boolean dirty = false;
|
|
|
|
public ContainerTravelAuth(InventoryPlayer playerInv, TileEntity te) {
|
|
super(playerInv, new AuthInventory(new ItemStack[5]));
|
|
this.te = te;
|
|
getInv().setContainer(this);
|
|
}
|
|
|
|
@Override
|
|
protected void addSlots(InventoryPlayer playerInv) {}
|
|
|
|
public void addGhostSlots(List<GhostSlot> ghostSlots) {
|
|
int x = 44;
|
|
int y = 28;
|
|
for (int i = 0; i < 5; i++) {
|
|
ghostSlots.add(new AuthGhostSlot(getInv(), i, x, y));
|
|
x += 18;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public Point getPlayerInventoryOffset() {
|
|
Point p = super.getPlayerInventoryOffset();
|
|
p.translate(0, -1);
|
|
return p;
|
|
}
|
|
|
|
@Override
|
|
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) {
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public TileEntity getTileEntity() {
|
|
return te;
|
|
}
|
|
|
|
private static class AuthGhostSlot extends GhostSlot {
|
|
|
|
private AuthInventory inv;
|
|
|
|
public AuthGhostSlot(AuthInventory ta, int slotIndex, int x, int y) {
|
|
this.slot = slotIndex;
|
|
this.x = x;
|
|
this.y = y;
|
|
this.displayStdOverlay = false;
|
|
this.grayOut = true;
|
|
this.stackSizeLimit = 1;
|
|
this.inv = ta;
|
|
}
|
|
|
|
@Override
|
|
public ItemStack getStack() {
|
|
ItemStack stack = inv.getStackInSlot(slot);
|
|
return stack;
|
|
}
|
|
|
|
@Override
|
|
public void putStack(ItemStack stack) {
|
|
inv.setInventorySlotContents(slot, stack);
|
|
}
|
|
}
|
|
}
|