fixed pipe items not going around corners nicely when directly connected to an inventory

This commit is contained in:
Ellpeck 2020-04-17 17:35:41 +02:00
parent 9682636103
commit 10645ac54d

View file

@ -106,10 +106,11 @@ public class PipeItem implements INBTSerializable<CompoundNBT> {
double dist = new Vec3d(this.currGoalPos).squareDistanceTo(this.x - 0.5F, this.y - 0.5F, this.z - 0.5F); double dist = new Vec3d(this.currGoalPos).squareDistanceTo(this.x - 0.5F, this.y - 0.5F, this.z - 0.5F);
if (dist < this.speed * this.speed) { if (dist < this.speed * this.speed) {
// we're past the start of the pipe, so move to the center of the next pipe // we're past the start of the pipe, so move to the center of the next pipe
BlockPos nextPos;
PipeTileEntity next = this.getNextTile(currPipe, false); PipeTileEntity next = this.getNextTile(currPipe, false);
if (next == null) { if (next == null) {
if (this.reachedDestination()) { if (this.reachedDestination()) {
this.currGoalPos = this.destInventory; nextPos = this.destInventory;
} else { } else {
currPipe.items.remove(this); currPipe.items.remove(this);
if (!currPipe.getWorld().isRemote) if (!currPipe.getWorld().isRemote)
@ -117,22 +118,25 @@ public class PipeItem implements INBTSerializable<CompoundNBT> {
return; return;
} }
} else { } else {
BlockPos nextPos = next.getPos(); nextPos = next.getPos();
if (dist >= 0.001F) { }
float tolerance = 0.001F;
if (dist >= tolerance * tolerance) {
// when going around corners, we want to move right up to the corner // when going around corners, we want to move right up to the corner
Vec3d motion = new Vec3d(this.x - this.lastX, this.y - this.lastY, this.z - this.lastZ); Vec3d motion = new Vec3d(this.x - this.lastX, this.y - this.lastY, this.z - this.lastZ);
Vec3d diff = new Vec3d(nextPos.getX() + 0.5F - this.x, nextPos.getY() + 0.5F - this.y, nextPos.getZ() + 0.5F - this.z); Vec3d diff = new Vec3d(nextPos.getX() + 0.5F - this.x, nextPos.getY() + 0.5F - this.y, nextPos.getZ() + 0.5F - this.z);
if (motion.crossProduct(diff).length() >= 0.001F) { if (motion.crossProduct(diff).length() >= tolerance) {
currSpeed = (float) Math.sqrt(dist); currSpeed = (float) Math.sqrt(dist);
} else { } else {
// we're not going around a corner, so continue
this.currGoalPos = nextPos; this.currGoalPos = nextPos;
} }
} else { } else {
// distance is very small, so continue
this.currGoalPos = nextPos; this.currGoalPos = nextPos;
} }
} }
} }
}
this.lastX = this.x; this.lastX = this.x;
this.lastY = this.y; this.lastY = this.y;