mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-11-22 11:53:29 +01:00
fixed items looking funky in pipes sometimes
This commit is contained in:
parent
ab7e472a0f
commit
9ea6f7353f
2 changed files with 21 additions and 9 deletions
|
@ -25,13 +25,17 @@ public class PipeRenderer extends TileEntityRenderer<PipeTileEntity> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(PipeTileEntity tile, float v, MatrixStack matrixStack, IRenderTypeBuffer iRenderTypeBuffer, int k, int i1) {
|
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) {
|
for (PipeItem item : tile.items) {
|
||||||
matrixStack.push();
|
matrixStack.push();
|
||||||
matrixStack.translate(
|
matrixStack.translate(
|
||||||
MathHelper.lerp(v, item.lastX, item.x) - pos.getX(),
|
MathHelper.lerp(v, item.lastX, item.x),
|
||||||
MathHelper.lerp(v, item.lastY, item.y) - pos.getY(),
|
MathHelper.lerp(v, item.lastY, item.y),
|
||||||
MathHelper.lerp(v, item.lastZ, item.z) - pos.getZ());
|
MathHelper.lerp(v, item.lastZ, item.z));
|
||||||
|
|
||||||
if (item.stack.getItem() instanceof BlockItem) {
|
if (item.stack.getItem() instanceof BlockItem) {
|
||||||
float scale = 0.7F;
|
float scale = 0.7F;
|
||||||
|
@ -59,6 +63,7 @@ public class PipeRenderer extends TileEntityRenderer<PipeTileEntity> {
|
||||||
}
|
}
|
||||||
matrixStack.pop();
|
matrixStack.pop();
|
||||||
}
|
}
|
||||||
|
matrixStack.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int getModelCount(ItemStack stack) {
|
protected int getModelCount(ItemStack stack) {
|
||||||
|
|
|
@ -45,6 +45,7 @@ public class PipeItem implements INBTSerializable<CompoundNBT> {
|
||||||
private int pipeTimer;
|
private int pipeTimer;
|
||||||
private int currentTile;
|
private int currentTile;
|
||||||
private boolean dropOnObstruction;
|
private boolean dropOnObstruction;
|
||||||
|
private long lastWorldTick;
|
||||||
|
|
||||||
public PipeItem(ItemStack stack, BlockPos startPipe, BlockPos startInventory) {
|
public PipeItem(ItemStack stack, BlockPos startPipe, BlockPos startInventory) {
|
||||||
this.stack = stack;
|
this.stack = stack;
|
||||||
|
@ -69,6 +70,13 @@ public class PipeItem implements INBTSerializable<CompoundNBT> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateInPipe(PipeTileEntity currPipe) {
|
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++;
|
this.pipeTimer++;
|
||||||
BlockPos goalPos;
|
BlockPos goalPos;
|
||||||
if (this.pipeTimer >= PIPE_TIME) {
|
if (this.pipeTimer >= PIPE_TIME) {
|
||||||
|
@ -92,7 +100,7 @@ public class PipeItem implements INBTSerializable<CompoundNBT> {
|
||||||
this.pipeTimer = 0;
|
this.pipeTimer = 0;
|
||||||
goalPos = next.getPos();
|
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
|
// we're past the start of the pipe, so move to the center of the next pipe
|
||||||
PipeTileEntity next = this.getNextTile(currPipe, false);
|
PipeTileEntity next = this.getNextTile(currPipe, false);
|
||||||
if (next == null) {
|
if (next == null) {
|
||||||
|
@ -116,12 +124,11 @@ public class PipeItem implements INBTSerializable<CompoundNBT> {
|
||||||
this.lastY = this.y;
|
this.lastY = this.y;
|
||||||
this.lastZ = this.z;
|
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);
|
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();
|
dist = dist.normalize();
|
||||||
this.x += dist.x * speed;
|
this.x += dist.x / PIPE_TIME;
|
||||||
this.y += dist.y * speed;
|
this.y += dist.y / PIPE_TIME;
|
||||||
this.z += dist.z * speed;
|
this.z += dist.z / PIPE_TIME;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onPathObstructed(PipeTileEntity currPipe, boolean tryReturn) {
|
private void onPathObstructed(PipeTileEntity currPipe, boolean tryReturn) {
|
||||||
|
|
Loading…
Reference in a new issue