From 9ea6f7353f047e47006b730a6194215a5acb4a6f Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 15 Apr 2020 20:53:56 +0200 Subject: [PATCH] fixed items looking funky in pipes sometimes --- .../prettypipes/blocks/pipe/PipeRenderer.java | 13 +++++++++---- .../ellpeck/prettypipes/network/PipeItem.java | 17 ++++++++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/ellpeck/prettypipes/blocks/pipe/PipeRenderer.java b/src/main/java/de/ellpeck/prettypipes/blocks/pipe/PipeRenderer.java index 11e68c9..f2c489e 100644 --- a/src/main/java/de/ellpeck/prettypipes/blocks/pipe/PipeRenderer.java +++ b/src/main/java/de/ellpeck/prettypipes/blocks/pipe/PipeRenderer.java @@ -25,13 +25,17 @@ public class PipeRenderer extends TileEntityRenderer { @Override public void render(PipeTileEntity tile, float v, MatrixStack matrixStack, IRenderTypeBuffer iRenderTypeBuffer, int k, int i1) { - BlockPos pos = tile.getPos(); + if (tile.items.isEmpty()) + return; + matrixStack.push(); + BlockPos tilePos = tile.getPos(); + matrixStack.translate(-tilePos.getX(), -tilePos.getY(), -tilePos.getZ()); for (PipeItem item : tile.items) { matrixStack.push(); matrixStack.translate( - MathHelper.lerp(v, item.lastX, item.x) - pos.getX(), - MathHelper.lerp(v, item.lastY, item.y) - pos.getY(), - MathHelper.lerp(v, item.lastZ, item.z) - pos.getZ()); + MathHelper.lerp(v, item.lastX, item.x), + MathHelper.lerp(v, item.lastY, item.y), + MathHelper.lerp(v, item.lastZ, item.z)); if (item.stack.getItem() instanceof BlockItem) { float scale = 0.7F; @@ -59,6 +63,7 @@ public class PipeRenderer extends TileEntityRenderer { } matrixStack.pop(); } + matrixStack.pop(); } protected int getModelCount(ItemStack stack) { diff --git a/src/main/java/de/ellpeck/prettypipes/network/PipeItem.java b/src/main/java/de/ellpeck/prettypipes/network/PipeItem.java index 1d9401e..307d92e 100644 --- a/src/main/java/de/ellpeck/prettypipes/network/PipeItem.java +++ b/src/main/java/de/ellpeck/prettypipes/network/PipeItem.java @@ -45,6 +45,7 @@ public class PipeItem implements INBTSerializable { private int pipeTimer; private int currentTile; private boolean dropOnObstruction; + private long lastWorldTick; public PipeItem(ItemStack stack, BlockPos startPipe, BlockPos startInventory) { this.stack = stack; @@ -69,6 +70,13 @@ public class PipeItem implements INBTSerializable { } public void updateInPipe(PipeTileEntity currPipe) { + // this prevents pipes being updated after one another + // causing an item that just switched to tick twice + long worldTick = currPipe.getWorld().getGameTime(); + if (this.lastWorldTick == worldTick) + return; + this.lastWorldTick = worldTick; + this.pipeTimer++; BlockPos goalPos; if (this.pipeTimer >= PIPE_TIME) { @@ -92,7 +100,7 @@ public class PipeItem implements INBTSerializable { this.pipeTimer = 0; goalPos = next.getPos(); } - } else if (this.pipeTimer >= PIPE_TIME / 2) { + } else if (this.pipeTimer > PIPE_TIME / 2) { // we're past the start of the pipe, so move to the center of the next pipe PipeTileEntity next = this.getNextTile(currPipe, false); if (next == null) { @@ -116,12 +124,11 @@ public class PipeItem implements INBTSerializable { this.lastY = this.y; this.lastZ = this.z; - float speed = 1 / (float) PIPE_TIME; Vec3d dist = new Vec3d(goalPos.getX() + 0.5F - this.x, goalPos.getY() + 0.5F - this.y, goalPos.getZ() + 0.5F - this.z); dist = dist.normalize(); - this.x += dist.x * speed; - this.y += dist.y * speed; - this.z += dist.z * speed; + this.x += dist.x / PIPE_TIME; + this.y += dist.y / PIPE_TIME; + this.z += dist.z / PIPE_TIME; } private void onPathObstructed(PipeTileEntity currPipe, boolean tryReturn) {