aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/tileentities
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/tileentities')
-rw-r--r--src/main/java/tileentities/TE_ItemDistributionCable.java25
-rw-r--r--src/main/java/tileentities/TE_ItemDistributionNode.java119
-rw-r--r--src/main/java/tileentities/TE_ItemProxyCable.java77
-rw-r--r--src/main/java/tileentities/TE_ItemProxyEndpoint.java204
-rw-r--r--src/main/java/tileentities/TE_ItemProxySource.java101
-rw-r--r--src/main/java/tileentities/TE_ItemServerIOPort.java18
6 files changed, 395 insertions, 149 deletions
diff --git a/src/main/java/tileentities/TE_ItemDistributionCable.java b/src/main/java/tileentities/TE_ItemDistributionCable.java
deleted file mode 100644
index 325d04c211..0000000000
--- a/src/main/java/tileentities/TE_ItemDistributionCable.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package tileentities;
-
-import kekztech.IConduit;
-import kekztech.ItemDistributionNetworkController;
-import net.minecraft.tileentity.TileEntity;
-
-public class TE_ItemDistributionCable extends TileEntity implements IConduit {
-
- private ItemDistributionNetworkController network;
-
- public TE_ItemDistributionCable() {
- ItemDistributionNetworkController.placeConduit(this);
- }
-
- @Override
- public void setNetwork(ItemDistributionNetworkController network) {
- this.network = network;
- }
-
- @Override
- public ItemDistributionNetworkController getNetwork() {
- return network;
- }
-
-}
diff --git a/src/main/java/tileentities/TE_ItemDistributionNode.java b/src/main/java/tileentities/TE_ItemDistributionNode.java
deleted file mode 100644
index 20b6500598..0000000000
--- a/src/main/java/tileentities/TE_ItemDistributionNode.java
+++ /dev/null
@@ -1,119 +0,0 @@
-package tileentities;
-
-import kekztech.IConduit;
-import kekztech.ItemDistributionNetworkController;
-import net.minecraft.entity.player.EntityPlayer;
-import net.minecraft.inventory.IInventory;
-import net.minecraft.item.ItemStack;
-import net.minecraft.tileentity.TileEntity;
-
-public class TE_ItemDistributionNode extends TileEntity implements IConduit, IInventory {
-
-private ItemDistributionNetworkController network;
-
- public TE_ItemDistributionNode() {
- ItemDistributionNetworkController.placeConduit(this);
- }
-
- @Override
- public void setNetwork(ItemDistributionNetworkController network) {
- this.network = network;
- }
-
- @Override
- public ItemDistributionNetworkController getNetwork() {
- return network;
- }
-
- @Override
- public int getSizeInventory() {
- return 16;
- }
-
- @Override
- public ItemStack getStackInSlot(int slot) {
- return network.getStackInSlot(slot);
- }
-
- @Override
- public ItemStack decrStackSize(int slot, int amount) {
-
- if(network.getStackInSlot(slot) != null) {
- if(network.getStackInSlot(slot).stackSize == amount) {
- final ItemStack itemStack = network.getStackInSlot(slot);
- network.setStackInSlot(slot, null);
- super.markDirty();
- return itemStack;
- } else {
- final ItemStack itemStack = network.getStackInSlot(slot).splitStack(amount);
- if(network.getStackInSlot(slot).stackSize == 0) {
- network.setStackInSlot(slot, null);
- }
- super.markDirty();
- return itemStack;
- }
- }
-
- return null;
- }
-
- @Override
- public ItemStack getStackInSlotOnClosing(int slot) {
- if(network.getStackInSlot(slot) != null) {
- final ItemStack itemStack = network.getStackInSlot(slot);
- network.setStackInSlot(slot, null);
- return itemStack;
- }
- return null;
- }
-
- @Override
- public void setInventorySlotContents(int slot, ItemStack itemStack) {
- if(itemStack == null) {
- return;
- }
- if(itemStack.stackSize > getInventoryStackLimit()) {
- itemStack.stackSize = getInventoryStackLimit();
- }
- network.setStackInSlot(slot, itemStack);
- super.markDirty();
- }
-
- @Override
- public String getInventoryName() {
- return network.getUUID().toString();
- }
-
- @Override
- public boolean hasCustomInventoryName() {
- return true;
- }
-
- @Override
- public int getInventoryStackLimit() {
- return 64;
- }
-
- @Override
- public boolean isUseableByPlayer(EntityPlayer player) {
- return true;
- }
-
- @Override
- public void openInventory() {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void closeInventory() {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public boolean isItemValidForSlot(int slot, ItemStack itemStack) {
- return network.isInputSlot(slot) && network.getStackInSlot(slot).isItemEqual(itemStack);
- }
-
-}
diff --git a/src/main/java/tileentities/TE_ItemProxyCable.java b/src/main/java/tileentities/TE_ItemProxyCable.java
new file mode 100644
index 0000000000..43ebc07b13
--- /dev/null
+++ b/src/main/java/tileentities/TE_ItemProxyCable.java
@@ -0,0 +1,77 @@
+package tileentities;
+
+import net.minecraft.tileentity.TileEntity;
+import net.minecraftforge.common.util.ForgeDirection;
+
+public class TE_ItemProxyCable extends TileEntity {
+
+ private static final float THICKNESS = 0.3f;
+ private byte connections;
+ private String idCache = null;
+
+ public TE_ItemProxyCable() {
+ connections = 63; // set all connections active until I have something actually control connections
+ }
+
+ public static float getThickness() {
+ return THICKNESS;
+ }
+
+ /**
+ * Builds a simple unique identifier for this TileEntity by appending
+ * the x, y, and z coordinates in a string.
+ *
+ * @return unique identifier for this TileEntity
+ */
+ public String getIdentifier() {
+ if(idCache == null) {
+ idCache = "" + super.xCoord + super.yCoord + super.zCoord;
+ return idCache;
+ } else {
+ return idCache;
+ }
+ }
+
+ /**
+ * 0 0 0 0 0 0 0 0 = 0 -> no connection </br>
+ * 0 0 0 0 0 0 0 1 = 1 -> down </br>
+ * 0 0 0 0 0 0 1 0 = 2 -> up </br>
+ * 0 0 0 0 0 1 0 0 = 4 -> north </br>
+ * 0 0 0 0 1 0 0 0 = 8 -> south </br>
+ * 0 0 0 1 0 0 0 0 = 16 -> west </br>
+ * 0 0 1 0 0 0 0 0 = 32 -> east </br>
+ *
+ * @param side
+ * The side for which to set the connection status.
+ * @param connected
+ * Whether this side should be connected or not
+ */
+ public void setConnection(ForgeDirection side, boolean connected) {
+ switch(side) {
+ case DOWN: connections = (byte) ((connected) ? connections | 1 : connections ^ 1); break;
+ case UP: connections = (byte) ((connected) ? connections | 2 : connections ^ 2); break;
+ case NORTH: connections = (byte) ((connected) ? connections | 4 : connections ^ 4); break;
+ case SOUTH: connections = (byte) ((connected) ? connections | 8 : connections ^ 8); break;
+ case WEST: connections = (byte) ((connected) ? connections | 16 : connections ^ 16); break;
+ case EAST: connections = (byte) ((connected) ? connections | 32 : connections ^ 32); break;
+ default: break;
+ }
+ }
+
+ public boolean isConnected(ForgeDirection side) {
+ switch(side) {
+ case DOWN: return (connections & 1) == connections;
+ case UP: return (connections & 2) == connections;
+ case NORTH: return (connections & 4) == connections;
+ case SOUTH: return (connections & 8) == connections;
+ case WEST: return (connections & 16) == connections;
+ case EAST: return (connections & 32) == connections;
+ default: return false;
+ }
+ }
+
+ public byte getConnections() {
+ return connections;
+ }
+
+}
diff --git a/src/main/java/tileentities/TE_ItemProxyEndpoint.java b/src/main/java/tileentities/TE_ItemProxyEndpoint.java
new file mode 100644
index 0000000000..1fe32c9687
--- /dev/null
+++ b/src/main/java/tileentities/TE_ItemProxyEndpoint.java
@@ -0,0 +1,204 @@
+package tileentities;
+
+import java.util.HashSet;
+import java.util.UUID;
+
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.inventory.IInventory;
+import net.minecraft.inventory.ISidedInventory;
+import net.minecraft.item.ItemStack;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraftforge.common.util.ForgeDirection;
+
+public class TE_ItemProxyEndpoint extends TileEntity implements ISidedInventory {
+
+ private UUID channel = null;
+ private int subChannel = -1;
+ private IInventory proxyInventory = null;
+ private int tickCounter = 0;
+ private ItemStack[] slots = new ItemStack[2];
+
+ public void setChannel(UUID channel) {
+ this.channel = channel;
+ }
+
+ public void setSubChannel(int subChannel) {
+ this.subChannel = subChannel;
+ }
+
+ @Override
+ public void updateEntity() {
+ if(tickCounter == 20) {
+
+ if(slots[1] == null || !slots[1].getUnlocalizedName().equals("gt.integrated_circuit") || slots[1].getItemDamage() >= 16) {
+ setSubChannel(-1);
+ }
+
+ if(slots[1] != null && slots[1].getUnlocalizedName().equals("gt.integrated_circuit") && slots[1].getItemDamage() < 16) {
+ setSubChannel(slots[1].getItemDamage());
+ }
+
+ if(channel != null && subChannel != -1) {
+ TE_ItemProxySource source = searchSource(channel);
+ if(source != null) {
+ proxyInventory = source;
+ }
+ }
+ tickCounter = 0;
+ }
+ tickCounter++;
+ }
+
+ public TE_ItemProxySource searchSource(UUID channel) {
+
+ final HashSet<TE_ItemProxySource> sources = new HashSet<>();
+ final HashSet<String> visited = new HashSet<>();
+
+ for(ForgeDirection next : ForgeDirection.VALID_DIRECTIONS) {
+ final TileEntity te = super.getWorldObj().getTileEntity(
+ super.xCoord + next.offsetX,
+ super.yCoord + next.offsetY,
+ super.zCoord + next.offsetZ);
+ if(te instanceof TE_ItemProxyCable) {
+ final TE_ItemProxyCable cable = (TE_ItemProxyCable) te;
+ if(cable.isConnected(next.getOpposite())) {
+ searchSourceRecursive(sources, visited, next.getOpposite(), cable, channel);
+ }
+ }
+ }
+
+ if(sources.isEmpty()) {
+ return null;
+ } else {
+ return sources.iterator().next();
+ }
+
+ }
+
+ private void searchSourceRecursive(HashSet<TE_ItemProxySource> sources, HashSet<String> visited,
+ ForgeDirection from, TE_ItemProxyCable nextTarget, UUID channel) {
+
+ if(visited.contains(nextTarget.getIdentifier())) {
+ return;
+ } else {
+ visited.add(nextTarget.getIdentifier());
+
+ for(ForgeDirection next : ForgeDirection.VALID_DIRECTIONS) {
+ if(next == from || !nextTarget.isConnected(next)) {
+ continue;
+ }
+ final TileEntity te = super.getWorldObj().getTileEntity(
+ nextTarget.xCoord + next.offsetX,
+ nextTarget.yCoord + next.offsetY,
+ nextTarget.zCoord + next.offsetZ);
+ if(te instanceof TE_ItemProxyCable) {
+ final TE_ItemProxyCable cable = (TE_ItemProxyCable) te;
+ if(cable.isConnected(next.getOpposite())) {
+ searchSourceRecursive(sources, visited, next.getOpposite(), cable, channel);
+ }
+ } else if (te instanceof TE_ItemProxySource) {
+ final TE_ItemProxySource source = (TE_ItemProxySource) te;
+ if(source.getChannel().equals(channel)) {
+ sources.add((TE_ItemProxySource) te);
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ public int getSizeInventory() {
+ return slots.length;
+ }
+
+ @Override
+ public ItemStack getStackInSlot(int slot) {
+ if(slot == 0) {
+ return (proxyInventory != null) ? proxyInventory.getStackInSlot(subChannel) : null;
+ } else {
+ return slots[slot];
+ }
+ }
+
+ @Override
+ public ItemStack decrStackSize(int slot, int amount) {
+ if(slot == 0) {
+ return (proxyInventory != null) ? proxyInventory.decrStackSize(subChannel, amount) : null;
+ } else {
+ final ItemStack copy = slots[1].copy();
+ slots[1] = null;
+ super.markDirty();
+ return copy;
+ }
+ }
+
+ @Override
+ public ItemStack getStackInSlotOnClosing(int slot) {
+ return (proxyInventory != null) ? proxyInventory.getStackInSlotOnClosing(subChannel) : null;
+ }
+
+ @Override
+ public void setInventorySlotContents(int slot, ItemStack itemStack) {
+ if(slot == 0 && proxyInventory != null) {
+ proxyInventory.setInventorySlotContents(subChannel, itemStack);
+ } else {
+ slots[slot] = itemStack;
+ }
+ }
+
+ @Override
+ public String getInventoryName() {
+ return (proxyInventory != null) ? "Connected Proxy" : "Untethered Proxy";
+ }
+
+ @Override
+ public boolean hasCustomInventoryName() {
+ return true;
+ }
+
+ @Override
+ public int getInventoryStackLimit() {
+ return (proxyInventory != null) ? proxyInventory.getInventoryStackLimit() : 1;
+ }
+
+ @Override
+ public boolean isUseableByPlayer(EntityPlayer player) {
+ return true;
+ }
+
+ @Override
+ public void openInventory() {
+
+ }
+
+ @Override
+ public void closeInventory() {
+
+ }
+
+ @Override
+ public boolean isItemValidForSlot(int slot, ItemStack itemStack) {
+ if(slot == 0 && proxyInventory != null) {
+ return proxyInventory.isItemValidForSlot(subChannel, itemStack);
+ } else {
+ return itemStack != null && itemStack.getUnlocalizedName().equals("gt.integrated_circuit");
+ }
+ }
+
+ @Override
+ public int[] getAccessibleSlotsFromSide(int side) {
+ final int[] as = {0};
+ return as;
+ }
+
+ @Override
+ public boolean canInsertItem(int slot, ItemStack itemStack, int side) {
+ return isItemValidForSlot(slot, itemStack);
+ }
+
+ @Override
+ public boolean canExtractItem(int slot, ItemStack itemStack, int side) {
+ return (slot == 0) ? true : false;
+ }
+
+}
diff --git a/src/main/java/tileentities/TE_ItemProxySource.java b/src/main/java/tileentities/TE_ItemProxySource.java
new file mode 100644
index 0000000000..15ffba3090
--- /dev/null
+++ b/src/main/java/tileentities/TE_ItemProxySource.java
@@ -0,0 +1,101 @@
+package tileentities;
+
+import java.util.UUID;
+
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.inventory.IInventory;
+import net.minecraft.item.ItemStack;
+import net.minecraft.tileentity.TileEntity;
+
+public class TE_ItemProxySource extends TileEntity implements IInventory {
+
+ private final UUID channel = UUID.randomUUID();
+ private ItemStack[] slots = new ItemStack[16];
+
+ public UUID getChannel() {
+ return channel;
+ }
+
+ @Override
+ public int getSizeInventory() {
+ return slots.length;
+ }
+
+ @Override
+ public ItemStack getStackInSlot(int slot) {
+ return slots[slot];
+ }
+
+ @Override
+ public ItemStack decrStackSize(int slot, int amount) {
+ if(slots[slot] != null) {
+
+ ItemStack copy;
+
+ if(slots[slot].stackSize == amount) {
+ copy = slots[slot];
+ slots[slot] = null;
+ super.markDirty();
+ return copy;
+ } else {
+ copy = slots[slot].splitStack(amount);
+ if(slots[slot].stackSize == 0) {
+ slots[slot] = null;
+ }
+ return copy;
+ }
+
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public ItemStack getStackInSlotOnClosing(int slot) {
+ return null;
+ }
+
+ @Override
+ public void setInventorySlotContents(int slot, ItemStack itemStack) {
+ slots[slot] = itemStack;
+ if(itemStack != null && itemStack.stackSize > getInventoryStackLimit()) {
+ itemStack.stackSize = getInventoryStackLimit();
+ }
+ super.markDirty();
+ }
+
+ @Override
+ public String getInventoryName() {
+ return "Item Proxy Network Source";
+ }
+
+ @Override
+ public boolean hasCustomInventoryName() {
+ return true;
+ }
+
+ @Override
+ public int getInventoryStackLimit() {
+ return 64;
+ }
+
+ @Override
+ public boolean isUseableByPlayer(EntityPlayer p_70300_1_) {
+ return true;
+ }
+
+ @Override
+ public void openInventory() {
+
+ }
+
+ @Override
+ public void closeInventory() {
+
+ }
+
+ @Override
+ public boolean isItemValidForSlot(int slot, ItemStack itemStack) {
+ return true;
+ }
+}
diff --git a/src/main/java/tileentities/TE_ItemServerIOPort.java b/src/main/java/tileentities/TE_ItemServerIOPort.java
index 46a3a9c7bb..a8c0f25b83 100644
--- a/src/main/java/tileentities/TE_ItemServerIOPort.java
+++ b/src/main/java/tileentities/TE_ItemServerIOPort.java
@@ -47,15 +47,23 @@ public class TE_ItemServerIOPort extends TileEntity implements IInventory {
@Override
public void setInventorySlotContents(int slot, ItemStack itemStack) {
+ System.out.println("Set slot, MIH: " + mih);
if(mih != null) {
if(itemStack == null || !itemStack.isItemEqual(mih.getStackInSlot(slot))) {
return;
} else {
- final int change = itemStack.stackSize - mih.getStackInSlot(slot).stackSize;
- if(change < 0) {
- mih.reduceStackInSlot(slot, change);
+ if(mih.getStackInSlot(slot) == null) {
+ System.out.println("Set slot: Allocate new");
+ mih.insertStackInSlot(slot, itemStack);
} else {
- mih.increaseStackInSlot(slot, change);
+ final int change = itemStack.stackSize - mih.getStackInSlot(slot).stackSize;
+ if(change < 0) {
+ System.out.println("Set slot: reduce");
+ mih.reduceStackInSlot(slot, change);
+ } else {
+ System.out.println("Set slot: increase");
+ mih.increaseStackInSlot(slot, change);
+ }
}
super.markDirty();
}
@@ -79,7 +87,7 @@ public class TE_ItemServerIOPort extends TileEntity implements IInventory {
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
- return false;
+ return true;
}
@Override