Abstracting PartRailing from being an IItemRailing and instead making nodes implement it
This commit is contained in:
parent
f9483a2db5
commit
1ba7f878c4
3 changed files with 66 additions and 73 deletions
|
@ -1,25 +1,34 @@
|
||||||
package resonantinduction.electrical.itemrailing;
|
package resonantinduction.electrical.itemrailing;
|
||||||
|
|
||||||
import calclavia.lib.grid.Node;
|
import calclavia.lib.grid.Node;
|
||||||
|
import calclavia.lib.render.EnumColor;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
import resonantinduction.electrical.itemrailing.interfaces.IItemRailing;
|
import resonantinduction.electrical.itemrailing.interfaces.IItemRailing;
|
||||||
|
import resonantinduction.electrical.itemrailing.interfaces.IItemRailingTransfer;
|
||||||
import universalelectricity.api.vector.IVectorWorld;
|
import universalelectricity.api.vector.IVectorWorld;
|
||||||
|
import universalelectricity.api.vector.VectorWorld;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author tgame14
|
* @author tgame14
|
||||||
* @since 18/03/14
|
* @since 18/03/14
|
||||||
*/
|
*/
|
||||||
public class NodeRailing extends Node<IItemRailing, GridRailing, NodeRailing> implements IVectorWorld
|
public class NodeRailing extends Node<PartRailing, GridRailing, NodeRailing> implements IVectorWorld, IItemRailing
|
||||||
{
|
{
|
||||||
|
private EnumColor color;
|
||||||
|
private Set<IItemRailingTransfer> itemNodeSet;
|
||||||
|
|
||||||
public NodeRailing(PartRailing parent)
|
public NodeRailing(PartRailing parent)
|
||||||
{
|
{
|
||||||
super(parent);
|
super(parent);
|
||||||
|
this.itemNodeSet = new HashSet<IItemRailingTransfer>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -28,14 +37,10 @@ public class NodeRailing extends Node<IItemRailing, GridRailing, NodeRailing> im
|
||||||
return new GridRailing(getClass());
|
return new GridRailing(getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return possibly null, a IInventory to target
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double z()
|
public double z()
|
||||||
{
|
{
|
||||||
return parent.getWorldPos().z();
|
return this.getWorldPos().z();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -55,4 +60,55 @@ public class NodeRailing extends Node<IItemRailing, GridRailing, NodeRailing> im
|
||||||
{
|
{
|
||||||
return parent.getWorldPos().y();
|
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<IInventory> invList = Lists.<IInventory>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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ import java.util.List;
|
||||||
* @since 16/03/14
|
* @since 16/03/14
|
||||||
* @author tgame14
|
* @author tgame14
|
||||||
*/
|
*/
|
||||||
public class PartRailing extends PartFramedConnection<PartRailing.EnumRailing, IConductor, IEnergyNetwork> implements IConductor, IItemRailing
|
public class PartRailing extends PartFramedConnection<PartRailing.EnumRailing, IConductor, IEnergyNetwork> implements IConductor, INodeProvider
|
||||||
{
|
{
|
||||||
|
|
||||||
public static enum EnumRailing
|
public static enum EnumRailing
|
||||||
|
@ -74,72 +74,11 @@ public class PartRailing extends PartFramedConnection<PartRailing.EnumRailing, I
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@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()
|
public VectorWorld getWorldPos()
|
||||||
{
|
{
|
||||||
return new VectorWorld(getWorld(), x(), y(), z());
|
return new VectorWorld(getWorld(), x(), y(), z());
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Handle the part as more of simply a host of Nodes, instead of the node itself
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IInventory[] getInventoriesNearby()
|
|
||||||
{
|
|
||||||
List<IInventory> invList = new ArrayList<IInventory>();
|
|
||||||
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
|
@Override
|
||||||
public float getResistance ()
|
public float getResistance ()
|
||||||
{
|
{
|
||||||
|
@ -193,7 +132,7 @@ public class PartRailing extends PartFramedConnection<PartRailing.EnumRailing, I
|
||||||
return network;
|
return network;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Fix up
|
//TODO: Fix up to proper data
|
||||||
@Override
|
@Override
|
||||||
public void setMaterial (int i)
|
public void setMaterial (int i)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
package resonantinduction.electrical.itemrailing.interfaces;
|
package resonantinduction.electrical.itemrailing.interfaces;
|
||||||
|
|
||||||
import calclavia.lib.grid.INodeProvider;
|
|
||||||
import calclavia.lib.render.EnumColor;
|
import calclavia.lib.render.EnumColor;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
import universalelectricity.api.vector.IVectorWorld;
|
|
||||||
import universalelectricity.api.vector.VectorWorld;
|
import universalelectricity.api.vector.VectorWorld;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -14,7 +12,7 @@ import universalelectricity.api.vector.VectorWorld;
|
||||||
* @author tgame14
|
* @author tgame14
|
||||||
*/
|
*/
|
||||||
// TODO: Fix up IVectorWorld implementation to somehow overturn error with ChickenBones Multiparts returning doubles
|
// TODO: Fix up IVectorWorld implementation to somehow overturn error with ChickenBones Multiparts returning doubles
|
||||||
public interface IItemRailing extends INodeProvider
|
public interface IItemRailing
|
||||||
{
|
{
|
||||||
public boolean canItemEnter (IItemRailingTransfer item);
|
public boolean canItemEnter (IItemRailingTransfer item);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue