Adding utility methods and properly implementing several interfaces, Railings now are able to search around them
This commit is contained in:
parent
5443704ab0
commit
b536a284fb
4 changed files with 88 additions and 13 deletions
|
@ -1,10 +1,11 @@
|
||||||
package resonantinduction.electrical.itemrailing;
|
package resonantinduction.electrical.itemrailing;
|
||||||
|
|
||||||
import calclavia.lib.grid.NodeGrid;
|
import calclavia.lib.grid.NodeGrid;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
import resonantinduction.electrical.itemrailing.interfaces.IItemRailing;
|
import resonantinduction.electrical.itemrailing.interfaces.IItemRailing;
|
||||||
import resonantinduction.electrical.itemrailing.interfaces.IItemRailingTransfer;
|
import resonantinduction.electrical.itemrailing.interfaces.IItemRailingTransfer;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 18/03/14
|
* @since 18/03/14
|
||||||
|
@ -17,18 +18,29 @@ public class GridRailing extends NodeGrid<NodeRailing>
|
||||||
super(type);
|
super(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IItemRailing findTargetForIItemTransfer(IItemRailingTransfer itemRailingTransfer)
|
public IItemRailing findTargetForIItemTransfer(IItemRailingTransfer itemwrapper)
|
||||||
|
{
|
||||||
|
if (itemwrapper.getColor() == null)
|
||||||
|
{
|
||||||
|
return findNearestInventory(itemwrapper);
|
||||||
|
}
|
||||||
|
return findNearestColoredTarget(itemwrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IItemRailing findNearestInventory(IItemRailingTransfer itemwrapper)
|
||||||
|
{
|
||||||
|
IItemRailing endGoal = null;
|
||||||
|
IItemRailing[] arr = (IItemRailing[]) this.getNodes().toArray();
|
||||||
|
Arrays.sort();
|
||||||
|
|
||||||
|
for (NodeRailing node : this.getNodes())
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ComparatorRailing implements Comparator<IItemRailing>
|
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compare(IItemRailing o1, IItemRailing o2)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IItemRailing findNearestColoredTarget(IItemRailingTransfer itemwrapper)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,21 @@
|
||||||
package resonantinduction.electrical.itemrailing;
|
package resonantinduction.electrical.itemrailing;
|
||||||
|
|
||||||
import calclavia.lib.grid.Grid;
|
|
||||||
import calclavia.lib.grid.Node;
|
import calclavia.lib.grid.Node;
|
||||||
|
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.IItemRailing;
|
||||||
|
import universalelectricity.api.vector.IVectorWorld;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 18/03/14
|
* @since 18/03/14
|
||||||
* @author tgame14
|
* @author tgame14
|
||||||
*/
|
*/
|
||||||
public class NodeRailing extends Node<IItemRailing, GridRailing, NodeRailing>
|
public class NodeRailing extends Node<IItemRailing, GridRailing, NodeRailing> implements IVectorWorld
|
||||||
{
|
{
|
||||||
public NodeRailing (PartRailing parent)
|
public NodeRailing (PartRailing parent)
|
||||||
{
|
{
|
||||||
|
@ -21,6 +28,63 @@ public class NodeRailing extends Node<IItemRailing, GridRailing, NodeRailing>
|
||||||
return new GridRailing(getClass());
|
return new GridRailing(getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return possibly null, a IInventory to target
|
||||||
|
*/
|
||||||
|
public IInventory getInventoriesNearby()
|
||||||
|
{
|
||||||
|
List<IInventory> invList = new ArrayList<IInventory>();
|
||||||
|
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||||
|
{
|
||||||
|
TileEntity te = parent.getWorldPos().translate(dir).getTileEntity(parent.getWorldPos().world());
|
||||||
|
if (te != null && te instanceof IInventory)
|
||||||
|
{
|
||||||
|
invList.add((IInventory) te);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return invList.get(parent.getWorldPos().world().rand.nextInt(invList.size()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLeaf()
|
||||||
|
{
|
||||||
|
int connectionsCount = 0;
|
||||||
|
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||||
|
{
|
||||||
|
if (parent.getWorldPos().translate(dir).getTileEntity(parent.getWorldPos().world()) instanceof IItemRailing)
|
||||||
|
{
|
||||||
|
connectionsCount++;
|
||||||
|
if (connectionsCount >= 2)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double z()
|
||||||
|
{
|
||||||
|
return parent.getWorldPos().z();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public World world()
|
||||||
|
{
|
||||||
|
return parent.getWorldPos().world();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double x()
|
||||||
|
{
|
||||||
|
return parent.getWorldPos().x();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double y()
|
||||||
|
{
|
||||||
|
return parent.getWorldPos().y()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ public class PartRailing extends PartFramedConnection<PartRailing.EnumRailing, I
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IVectorWorld getWorldPos()
|
public VectorWorld getWorldPos()
|
||||||
{
|
{
|
||||||
return new VectorWorld(getWorld(), x(), y(), z());
|
return new VectorWorld(getWorld(), x(), y(), z());
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,8 @@ package resonantinduction.electrical.itemrailing.interfaces;
|
||||||
|
|
||||||
import calclavia.lib.grid.INodeProvider;
|
import calclavia.lib.grid.INodeProvider;
|
||||||
import calclavia.lib.render.EnumColor;
|
import calclavia.lib.render.EnumColor;
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
import universalelectricity.api.vector.IVectorWorld;
|
import universalelectricity.api.vector.VectorWorld;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* implement on Part Railings.
|
* implement on Part Railings.
|
||||||
|
@ -22,7 +21,7 @@ public interface IItemRailing extends INodeProvider
|
||||||
|
|
||||||
public IItemRailing setRailingColor (EnumColor color);
|
public IItemRailing setRailingColor (EnumColor color);
|
||||||
|
|
||||||
public IVectorWorld getWorldPos();
|
public VectorWorld getWorldPos();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue