Fixed #15 pathfinding going through contractors itself

This commit is contained in:
Calclavia 2013-08-05 14:04:47 -04:00
parent 6b5f8cbf14
commit d1c9529ab9
3 changed files with 40 additions and 30 deletions

View file

@ -4,6 +4,7 @@
package resonantinduction.contractor;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@ -62,7 +63,7 @@ public class PathfinderEMContractor
ForgeDirection direction = ForgeDirection.getOrientation(i);
Vector3 neighbor = this.target.clone().translate(new Vector3(direction.offsetX, direction.offsetY, direction.offsetZ));
if (!TileEntityEMContractor.canBePath(this.world, neighbor))
if (!TileEntityEMContractor.canBePath(this.world, neighbor, this.target))
{
blockCount++;
}
@ -109,7 +110,7 @@ public class PathfinderEMContractor
Vector3 neighbor = currentNode.clone().translate(new Vector3(direction.offsetX, direction.offsetY, direction.offsetZ));
if (TileEntityEMContractor.canBePath(this.world, neighbor))
if (TileEntityEMContractor.canBePath(this.world, neighbor, this.target))
{
double tentativeG = this.gScore.get(currentNode) + currentNode.distance(neighbor);

View file

@ -6,6 +6,9 @@ import java.util.List;
import java.util.Set;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLadder;
import net.minecraft.block.BlockSnow;
import net.minecraft.block.BlockVine;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
@ -53,7 +56,7 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
private TileEntityEMContractor linked;
/** Color of beam */
private int dyeID = 13;
private int dyeID = TileEntityTesla.DEFAULT_COLOR;
private Vector3 tempLinkVector;
@Override
@ -115,7 +118,11 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
}
}
if (!this.suck && this.linked != null && !this.linked.isInvalid())
if (this.linked != null && !this.linked.isInvalid())
{
ResonantInduction.proxy.renderElectricShock(this.worldObj, new Vector3(this).translate(0.5), new Vector3(this).translate(new Vector3(this.getDirection())).translate(0.5), TileEntityTesla.dyeColors[dyeID]);
if (!this.suck)
{
if (this.pathfinder != null)
{
@ -123,7 +130,7 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
{
Vector3 result = this.pathfinder.results.get(i);
if (TileEntityEMContractor.canBePath(this.worldObj, result))
if (TileEntityEMContractor.canBePath(this.worldObj, result, new Vector3(this.linked)))
{
if (i - 1 >= 0)
{
@ -141,6 +148,7 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
this.moveEntity(entityItem, direction, result);
}
}
}
else
{
@ -150,6 +158,7 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
}
}
}
}
else
{
this.pathfinder = null;
@ -170,10 +179,10 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
}
}
public static boolean canBePath(World world, Vector3 position)
public static boolean canBePath(World world, Vector3 position, Vector3 target)
{
Block block = Block.blocksList[position.getBlockID(world)];
return block == null || position.getTileEntity(world) instanceof TileEntityEMContractor || (block != null && !block.isBlockNormalCube(world, (int) position.x, (int) position.y, (int) position.z));
return block == null || (block instanceof BlockSnow || block instanceof BlockVine || block instanceof BlockLadder);
}
private void moveEntity(EntityItem entityItem, ForgeDirection direction, Vector3 lockVector)
@ -508,7 +517,7 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
Vector3 start = new Vector3(this).translate(new Vector3(this.getDirection()));
Vector3 target = new Vector3(this.linked).translate(new Vector3(this.linked.getDirection()));
if (TileEntityEMContractor.canBePath(this.worldObj, start) && TileEntityEMContractor.canBePath(this.worldObj, target))
if (TileEntityEMContractor.canBePath(this.worldObj, start, new Vector3(this.linked)) && TileEntityEMContractor.canBePath(this.worldObj, target, new Vector3(this.linked)))
{
this.pathfinder = new PathfinderEMContractor(this.worldObj, target);
this.pathfinder.find(start);

View file

@ -41,7 +41,7 @@ public class TileEntityTesla extends TileEntityBase implements ITesla, IPacketRe
{
public static final Vector3[] dyeColors = new Vector3[] { new Vector3(), new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector3(0.5, 0.5, 0), new Vector3(0, 0, 1), new Vector3(0.5, 0, 05), new Vector3(0, 0.3, 1), new Vector3(0.8, 0.8, 0.8), new Vector3(0.3, 0.3, 0.3), new Vector3(0.7, 0.2, 0.2), new Vector3(0.1, 0.872, 0.884), new Vector3(0, 0.8, 0.8), new Vector3(0.46f, 0.932, 1), new Vector3(0.5, 0.2, 0.5), new Vector3(0.7, 0.5, 0.1), new Vector3(1, 1, 1) };
private final int DEFAULT_COLOR = 12;
public final int DEFAULT_COLOR = 12;
private int dyeID = DEFAULT_COLOR;
private float energy = 0;
private boolean doTransfer = false;