Fixed up pathfinder, fixed most bugs and began work on a restriction transporter
This commit is contained in:
parent
a2443f902d
commit
a3afca5b64
4 changed files with 65 additions and 26 deletions
|
@ -71,7 +71,7 @@ public class TileEntityLogisticalTransporter extends TileEntity implements ITile
|
||||||
|
|
||||||
if(!stack.isFinal(this))
|
if(!stack.isFinal(this))
|
||||||
{
|
{
|
||||||
if(next != null && stack.canInsert(stack.getNext(this).getTileEntity(worldObj)))
|
if(next != null && stack.canInsertToTransporter(stack.getNext(this).getTileEntity(worldObj)))
|
||||||
{
|
{
|
||||||
TileEntityLogisticalTransporter nextTile = (TileEntityLogisticalTransporter)next.getTileEntity(worldObj);
|
TileEntityLogisticalTransporter nextTile = (TileEntityLogisticalTransporter)next.getTileEntity(worldObj);
|
||||||
nextTile.entityEntering(stack);
|
nextTile.entityEntering(stack);
|
||||||
|
@ -138,7 +138,7 @@ public class TileEntityLogisticalTransporter extends TileEntity implements ITile
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(!stack.canInsert(stack.getNext(this).getTileEntity(worldObj)))
|
if(!stack.canInsertToTransporter(stack.getNext(this).getTileEntity(worldObj)))
|
||||||
{
|
{
|
||||||
if(!recalculate(stack))
|
if(!recalculate(stack))
|
||||||
{
|
{
|
||||||
|
@ -193,7 +193,7 @@ public class TileEntityLogisticalTransporter extends TileEntity implements ITile
|
||||||
stack.originalLocation = original;
|
stack.originalLocation = original;
|
||||||
stack.color = color;
|
stack.color = color;
|
||||||
|
|
||||||
if(!stack.canInsert(this))
|
if(!stack.canInsertToTransporter(this))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,10 @@ import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import mekanism.api.EnumColor;
|
||||||
import mekanism.api.Object3D;
|
import mekanism.api.Object3D;
|
||||||
import mekanism.common.tileentity.TileEntityLogisticalTransporter;
|
import mekanism.common.tileentity.TileEntityLogisticalTransporter;
|
||||||
import mekanism.common.util.TransporterUtils;
|
import mekanism.common.util.TransporterUtils;
|
||||||
|
@ -23,7 +25,7 @@ public final class TransporterPathfinder
|
||||||
|
|
||||||
public TileEntityLogisticalTransporter start;
|
public TileEntityLogisticalTransporter start;
|
||||||
|
|
||||||
public Object3D lastFound;
|
public Map<Object3D, Integer> destinations = new HashMap<Object3D, Integer>();
|
||||||
|
|
||||||
public TransporterStack transportStack;
|
public TransporterStack transportStack;
|
||||||
|
|
||||||
|
@ -34,40 +36,57 @@ public final class TransporterPathfinder
|
||||||
transportStack = stack;
|
transportStack = stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loop(TileEntityLogisticalTransporter pointer)
|
public void loop(TileEntityLogisticalTransporter pointer, int dist)
|
||||||
{
|
{
|
||||||
if(pointer == null || lastFound != null)
|
if(pointer == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
iterated.add(pointer);
|
iterated.add(pointer);
|
||||||
|
|
||||||
|
if(pointer.color == EnumColor.BLACK)
|
||||||
|
{
|
||||||
|
dist += 1000;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dist++;
|
||||||
|
}
|
||||||
|
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
|
|
||||||
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
|
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
|
||||||
{
|
{
|
||||||
TileEntity tile = Object3D.get(pointer).getFromSide(side).getTileEntity(worldObj);
|
TileEntity tile = Object3D.get(pointer).getFromSide(side).getTileEntity(worldObj);
|
||||||
|
|
||||||
if(transportStack.canInsert(tile) && !iterated.contains(tile))
|
if(transportStack.canInsertToTransporter(tile) && !iterated.contains(tile))
|
||||||
{
|
{
|
||||||
loop((TileEntityLogisticalTransporter)tile);
|
loop((TileEntityLogisticalTransporter)tile, dist);
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!found)
|
if(!found)
|
||||||
{
|
{
|
||||||
lastFound = Object3D.get(pointer);
|
destinations.put(Object3D.get(pointer), dist);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object3D find()
|
public Object3D find()
|
||||||
{
|
{
|
||||||
loop(start);
|
loop(start, 0);
|
||||||
|
|
||||||
return lastFound;
|
Object3D farthest = null;
|
||||||
|
|
||||||
|
for(Map.Entry<Object3D, Integer> entry : destinations.entrySet())
|
||||||
|
{
|
||||||
|
if(farthest == null || destinations.get(farthest) < entry.getValue())
|
||||||
|
{
|
||||||
|
farthest = entry.getKey();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return farthest;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,9 +96,10 @@ public final class TransporterPathfinder
|
||||||
|
|
||||||
public Set<TileEntityLogisticalTransporter> iterated = new HashSet<TileEntityLogisticalTransporter>();
|
public Set<TileEntityLogisticalTransporter> iterated = new HashSet<TileEntityLogisticalTransporter>();
|
||||||
|
|
||||||
|
public Map<Object3D, Integer> destinations = new HashMap<Object3D, Integer>();
|
||||||
|
public Map<Object3D, Object3D> prevNodes = new HashMap<Object3D, Object3D>();
|
||||||
|
|
||||||
public TileEntityLogisticalTransporter start;
|
public TileEntityLogisticalTransporter start;
|
||||||
public Object3D destination;
|
|
||||||
public Object3D finalNode;
|
|
||||||
|
|
||||||
public TransporterStack transportStack;
|
public TransporterStack transportStack;
|
||||||
|
|
||||||
|
@ -90,38 +110,56 @@ public final class TransporterPathfinder
|
||||||
transportStack = stack;
|
transportStack = stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loop(TileEntityLogisticalTransporter pointer)
|
public void loop(TileEntityLogisticalTransporter pointer, int dist)
|
||||||
{
|
{
|
||||||
if(pointer == null || destination != null)
|
if(pointer == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
iterated.add(pointer);
|
iterated.add(pointer);
|
||||||
|
|
||||||
|
if(pointer.color == EnumColor.BLACK)
|
||||||
|
{
|
||||||
|
dist += 1000;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dist++;
|
||||||
|
}
|
||||||
|
|
||||||
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
|
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
|
||||||
{
|
{
|
||||||
TileEntity tile = Object3D.get(pointer).getFromSide(side).getTileEntity(worldObj);
|
TileEntity tile = Object3D.get(pointer).getFromSide(side).getTileEntity(worldObj);
|
||||||
|
|
||||||
if(TransporterUtils.canInsert(tile, transportStack.itemStack, side.ordinal()) && !(tile instanceof TileEntityLogisticalTransporter))
|
if(TransporterUtils.canInsert(tile, transportStack.itemStack, side.ordinal()) && !(tile instanceof TileEntityLogisticalTransporter))
|
||||||
{
|
{
|
||||||
destination = Object3D.get(tile);
|
destinations.put(Object3D.get(tile), dist);
|
||||||
finalNode = Object3D.get(pointer);
|
prevNodes.put(Object3D.get(tile), Object3D.get(pointer));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(transportStack.canInsert(tile) && !iterated.contains(tile))
|
if(transportStack.canInsertToTransporter(tile) && !iterated.contains(tile))
|
||||||
{
|
{
|
||||||
loop((TileEntityLogisticalTransporter)tile);
|
loop((TileEntityLogisticalTransporter)tile, dist);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object3D find()
|
public Object3D find()
|
||||||
{
|
{
|
||||||
loop(start);
|
loop(start, 0);
|
||||||
|
|
||||||
return destination;
|
Object3D closest = null;
|
||||||
|
|
||||||
|
for(Map.Entry<Object3D, Integer> entry : destinations.entrySet())
|
||||||
|
{
|
||||||
|
if(closest == null || destinations.get(closest) > entry.getValue())
|
||||||
|
{
|
||||||
|
closest = entry.getKey();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return closest;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,7 +215,7 @@ public final class TransporterPathfinder
|
||||||
ForgeDirection direction = ForgeDirection.getOrientation(i);
|
ForgeDirection direction = ForgeDirection.getOrientation(i);
|
||||||
Object3D neighbor = finalNode.translate(direction.offsetX, direction.offsetY, direction.offsetZ);
|
Object3D neighbor = finalNode.translate(direction.offsetX, direction.offsetY, direction.offsetZ);
|
||||||
|
|
||||||
if(!transportStack.canInsert(neighbor.getTileEntity(worldObj)))
|
if(!transportStack.canInsertToTransporter(neighbor.getTileEntity(worldObj)))
|
||||||
{
|
{
|
||||||
blockCount++;
|
blockCount++;
|
||||||
}
|
}
|
||||||
|
@ -223,7 +261,7 @@ public final class TransporterPathfinder
|
||||||
ForgeDirection direction = ForgeDirection.getOrientation(i);
|
ForgeDirection direction = ForgeDirection.getOrientation(i);
|
||||||
Object3D neighbor = currentNode.getFromSide(direction);
|
Object3D neighbor = currentNode.getFromSide(direction);
|
||||||
|
|
||||||
if(transportStack.canInsert(neighbor.getTileEntity(worldObj)))
|
if(transportStack.canInsertToTransporter(neighbor.getTileEntity(worldObj)))
|
||||||
{
|
{
|
||||||
double tentativeG = gScore.get(currentNode) + currentNode.distanceTo(neighbor);
|
double tentativeG = gScore.get(currentNode) + currentNode.distanceTo(neighbor);
|
||||||
|
|
||||||
|
@ -295,7 +333,7 @@ public final class TransporterPathfinder
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Path p = new Path(d.worldObj, d.finalNode, Object3D.get(start), closest, stack);
|
Path p = new Path(d.worldObj, d.prevNodes.get(closest), Object3D.get(start), closest, stack);
|
||||||
return p.getPath();
|
return p.getPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -208,7 +208,7 @@ public class TransporterStack
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canInsert(TileEntity tileEntity)
|
public boolean canInsertToTransporter(TileEntity tileEntity)
|
||||||
{
|
{
|
||||||
if(!(tileEntity instanceof TileEntityLogisticalTransporter))
|
if(!(tileEntity instanceof TileEntityLogisticalTransporter))
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,6 +35,7 @@ public final class TransporterUtils
|
||||||
ret.add(EnumColor.RED);
|
ret.add(EnumColor.RED);
|
||||||
ret.add(EnumColor.PINK);
|
ret.add(EnumColor.PINK);
|
||||||
ret.add(EnumColor.YELLOW);
|
ret.add(EnumColor.YELLOW);
|
||||||
|
ret.add(EnumColor.BLACK);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue