mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-11-22 19:58:35 +01:00
made pipe item movement more accurate
This commit is contained in:
parent
ee58eb30b3
commit
03a798649a
2 changed files with 62 additions and 56 deletions
|
@ -85,72 +85,78 @@ public class PipeItem implements INBTSerializable<CompoundNBT>, ILiquidContainer
|
||||||
return;
|
return;
|
||||||
this.lastWorldTick = worldTick;
|
this.lastWorldTick = worldTick;
|
||||||
|
|
||||||
float currSpeed = this.speed;
|
float motionLeft = this.speed;
|
||||||
BlockPos myPos = new BlockPos(this.x, this.y, this.z);
|
while (motionLeft > 0) {
|
||||||
if (!myPos.equals(currPipe.getPos()) && (currPipe.getPos().equals(this.getDestPipe()) || !myPos.equals(this.startInventory))) {
|
float currSpeed = Math.min(0.25F, motionLeft);
|
||||||
// we're done with the current pipe, so switch to the next one
|
motionLeft -= currSpeed;
|
||||||
currPipe.getItems().remove(this);
|
|
||||||
PipeTileEntity next = this.getNextTile(currPipe, true);
|
BlockPos myPos = new BlockPos(this.x, this.y, this.z);
|
||||||
if (next == null) {
|
if (!myPos.equals(currPipe.getPos()) && (currPipe.getPos().equals(this.getDestPipe()) || !myPos.equals(this.startInventory))) {
|
||||||
if (!currPipe.getWorld().isRemote) {
|
// we're done with the current pipe, so switch to the next one
|
||||||
if (currPipe.getPos().equals(this.getDestPipe())) {
|
currPipe.getItems().remove(this);
|
||||||
// ..or store in our destination container if we reached our destination
|
PipeTileEntity next = this.getNextTile(currPipe, true);
|
||||||
this.stack = this.store(currPipe);
|
|
||||||
if (!this.stack.isEmpty())
|
|
||||||
this.onPathObstructed(currPipe, true);
|
|
||||||
} else {
|
|
||||||
this.onPathObstructed(currPipe, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
next.getItems().add(this);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
double dist = Vector3d.copy(this.currGoalPos).squareDistanceTo(this.x - 0.5F, this.y - 0.5F, this.z - 0.5F);
|
|
||||||
if (dist < this.speed * this.speed) {
|
|
||||||
// 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);
|
|
||||||
if (next == null) {
|
if (next == null) {
|
||||||
if (currPipe.getPos().equals(this.getDestPipe())) {
|
if (!currPipe.getWorld().isRemote) {
|
||||||
nextPos = this.destInventory;
|
if (currPipe.getPos().equals(this.getDestPipe())) {
|
||||||
} else {
|
// ..or store in our destination container if we reached our destination
|
||||||
currPipe.getItems().remove(this);
|
this.stack = this.store(currPipe);
|
||||||
if (!currPipe.getWorld().isRemote)
|
if (!this.stack.isEmpty())
|
||||||
|
this.onPathObstructed(currPipe, true);
|
||||||
|
} else {
|
||||||
this.onPathObstructed(currPipe, false);
|
this.onPathObstructed(currPipe, false);
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
} else {
|
} else {
|
||||||
nextPos = next.getPos();
|
next.getItems().add(this);
|
||||||
|
currPipe = next;
|
||||||
}
|
}
|
||||||
float tolerance = 0.001F;
|
} else {
|
||||||
if (dist >= tolerance * tolerance) {
|
double dist = Vector3d.copy(this.currGoalPos).squareDistanceTo(this.x - 0.5F, this.y - 0.5F, this.z - 0.5F);
|
||||||
// when going around corners, we want to move right up to the corner
|
if (dist < currSpeed * currSpeed) {
|
||||||
Vector3d motion = new Vector3d(this.x - this.lastX, this.y - this.lastY, this.z - this.lastZ);
|
// we're past the start of the pipe, so move to the center of the next pipe
|
||||||
Vector3d diff = new Vector3d(nextPos.getX() + 0.5F - this.x, nextPos.getY() + 0.5F - this.y, nextPos.getZ() + 0.5F - this.z);
|
BlockPos nextPos;
|
||||||
if (motion.crossProduct(diff).length() >= tolerance) {
|
PipeTileEntity next = this.getNextTile(currPipe, false);
|
||||||
currSpeed = (float) Math.sqrt(dist);
|
if (next == null) {
|
||||||
|
if (currPipe.getPos().equals(this.getDestPipe())) {
|
||||||
|
nextPos = this.destInventory;
|
||||||
|
} else {
|
||||||
|
currPipe.getItems().remove(this);
|
||||||
|
if (!currPipe.getWorld().isRemote)
|
||||||
|
this.onPathObstructed(currPipe, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// we're not going around a corner, so continue
|
nextPos = next.getPos();
|
||||||
|
}
|
||||||
|
float tolerance = 0.001F;
|
||||||
|
if (dist >= tolerance * tolerance) {
|
||||||
|
// when going around corners, we want to move right up to the corner
|
||||||
|
Vector3d motion = new Vector3d(this.x - this.lastX, this.y - this.lastY, this.z - this.lastZ);
|
||||||
|
Vector3d diff = new Vector3d(nextPos.getX() + 0.5F - this.x, nextPos.getY() + 0.5F - this.y, nextPos.getZ() + 0.5F - this.z);
|
||||||
|
if (motion.crossProduct(diff).length() >= tolerance) {
|
||||||
|
currSpeed = (float) Math.sqrt(dist);
|
||||||
|
} else {
|
||||||
|
// we're not going around a corner, so continue
|
||||||
|
this.currGoalPos = nextPos;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// distance is very small, so continue
|
||||||
this.currGoalPos = nextPos;
|
this.currGoalPos = nextPos;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// distance is very small, so continue
|
|
||||||
this.currGoalPos = nextPos;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.lastX = this.x;
|
||||||
|
this.lastY = this.y;
|
||||||
|
this.lastZ = this.z;
|
||||||
|
|
||||||
|
Vector3d dist = new Vector3d(this.currGoalPos.getX() + 0.5F - this.x, this.currGoalPos.getY() + 0.5F - this.y, this.currGoalPos.getZ() + 0.5F - this.z);
|
||||||
|
dist = dist.normalize();
|
||||||
|
this.x += dist.x * currSpeed;
|
||||||
|
this.y += dist.y * currSpeed;
|
||||||
|
this.z += dist.z * currSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.lastX = this.x;
|
|
||||||
this.lastY = this.y;
|
|
||||||
this.lastZ = this.z;
|
|
||||||
|
|
||||||
Vector3d dist = new Vector3d(this.currGoalPos.getX() + 0.5F - this.x, this.currGoalPos.getY() + 0.5F - this.y, this.currGoalPos.getZ() + 0.5F - this.z);
|
|
||||||
dist = dist.normalize();
|
|
||||||
this.x += dist.x * currSpeed;
|
|
||||||
this.y += dist.y * currSpeed;
|
|
||||||
this.z += dist.z * currSpeed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onPathObstructed(PipeTileEntity currPipe, boolean tryReturn) {
|
protected void onPathObstructed(PipeTileEntity currPipe, boolean tryReturn) {
|
||||||
|
|
|
@ -219,7 +219,7 @@ public class PipeTileEntity extends TileEntity implements INamedContainerProvide
|
||||||
|
|
||||||
public float getItemSpeed(ItemStack stack) {
|
public float getItemSpeed(ItemStack stack) {
|
||||||
float moduleSpeed = (float) this.streamModules().mapToDouble(m -> m.getRight().getItemSpeedIncrease(m.getLeft(), this)).sum();
|
float moduleSpeed = (float) this.streamModules().mapToDouble(m -> m.getRight().getItemSpeedIncrease(m.getLeft(), this)).sum();
|
||||||
float pressureSpeed = this.pressurizer != null && !this.pressurizer.isRemoved() && this.pressurizer.pressurizeItem(stack, true) ? 0.4F : 0;
|
float pressureSpeed = this.pressurizer != null && !this.pressurizer.isRemoved() && this.pressurizer.pressurizeItem(stack, true) ? 0.45F : 0;
|
||||||
return 0.05F + moduleSpeed + pressureSpeed;
|
return 0.05F + moduleSpeed + pressureSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue