From 1ba7f878c480149ac9a9b0c30be005e418a55e5d Mon Sep 17 00:00:00 2001 From: tgame14 Date: Thu, 17 Apr 2014 13:09:44 +0300 Subject: [PATCH] Abstracting PartRailing from being an IItemRailing and instead making nodes implement it --- .../electrical/itemrailing/NodeRailing.java | 70 +++++++++++++++++-- .../electrical/itemrailing/PartRailing.java | 65 +---------------- .../itemrailing/interfaces/IItemRailing.java | 4 +- 3 files changed, 66 insertions(+), 73 deletions(-) diff --git a/electrical/src/main/scala/resonantinduction/electrical/itemrailing/NodeRailing.java b/electrical/src/main/scala/resonantinduction/electrical/itemrailing/NodeRailing.java index 3015aa26e..ee8df22bb 100644 --- a/electrical/src/main/scala/resonantinduction/electrical/itemrailing/NodeRailing.java +++ b/electrical/src/main/scala/resonantinduction/electrical/itemrailing/NodeRailing.java @@ -1,25 +1,34 @@ package resonantinduction.electrical.itemrailing; import calclavia.lib.grid.Node; +import calclavia.lib.render.EnumColor; +import com.google.common.collect.Lists; import net.minecraft.inventory.IInventory; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; import resonantinduction.electrical.itemrailing.interfaces.IItemRailing; +import resonantinduction.electrical.itemrailing.interfaces.IItemRailingTransfer; import universalelectricity.api.vector.IVectorWorld; +import universalelectricity.api.vector.VectorWorld; import java.util.ArrayList; -import java.util.List; +import java.util.HashSet; +import java.util.Set; /** * @author tgame14 * @since 18/03/14 */ -public class NodeRailing extends Node implements IVectorWorld +public class NodeRailing extends Node implements IVectorWorld, IItemRailing { + private EnumColor color; + private Set itemNodeSet; + public NodeRailing(PartRailing parent) { super(parent); + this.itemNodeSet = new HashSet(); } @Override @@ -28,14 +37,10 @@ public class NodeRailing extends Node im return new GridRailing(getClass()); } - /** - * @return possibly null, a IInventory to target - */ - @Override public double z() { - return parent.getWorldPos().z(); + return this.getWorldPos().z(); } @Override @@ -55,4 +60,55 @@ public class NodeRailing extends Node im { return parent.getWorldPos().y(); } + + @Override + public boolean canItemEnter (IItemRailingTransfer item) + { + return this.color != null ? this.color == item.getColor() : false; + } + + @Override + public boolean canConnectToRailing (IItemRailing railing, ForgeDirection from) + { + return this.color != null ? this.color == railing.getRailingColor() : true; + } + + @Override + public EnumColor getRailingColor () + { + return this.color; + } + + @Override + public IItemRailing setRailingColor (EnumColor color) + { + this.color = color; + return this; + } + + @Override + public VectorWorld getWorldPos() + { + return parent.getWorldPos(); + } + + @Override + public IInventory[] getInventoriesNearby() + { + ArrayList invList = Lists.newArrayList(); + for (TileEntity tile : parent.getConnections()) + { + if (tile instanceof IInventory) + { + invList.add((IInventory) tile); + } + } + return (IInventory[]) invList.toArray(); + } + + @Override + public boolean isLeaf() + { + return parent.getConnections().length < 2; + } } diff --git a/electrical/src/main/scala/resonantinduction/electrical/itemrailing/PartRailing.java b/electrical/src/main/scala/resonantinduction/electrical/itemrailing/PartRailing.java index 6e86a8b1d..866dfc1de 100644 --- a/electrical/src/main/scala/resonantinduction/electrical/itemrailing/PartRailing.java +++ b/electrical/src/main/scala/resonantinduction/electrical/itemrailing/PartRailing.java @@ -30,7 +30,7 @@ import java.util.List; * @since 16/03/14 * @author tgame14 */ -public class PartRailing extends PartFramedConnection implements IConductor, IItemRailing +public class PartRailing extends PartFramedConnection implements IConductor, INodeProvider { public static enum EnumRailing @@ -74,72 +74,11 @@ public class PartRailing extends PartFramedConnection invList = new ArrayList(); - for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) - { - TileEntity te = this.getWorldPos().translate(dir).getTileEntity(this.getWorldPos().world()); - if (te != null && te instanceof IInventory) - { - invList.add((IInventory) te); - } - } - return (IInventory[]) invList.toArray(); - } - - @Override - public boolean isLeaf() - { - int connectionsCount = 0; - for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) - { - if (this.getWorldPos().translate(dir).getTileEntity(this.getWorldPos().world()) instanceof IItemRailing) - { - connectionsCount++; - if (connectionsCount >= 2) - { - return false; - } - } - } - return true; - } - @Override public float getResistance () { @@ -193,7 +132,7 @@ public class PartRailing extends PartFramedConnection