Skip to content

Commit

Permalink
dynamically_information_update only recalc every 1 gt
Browse files Browse the repository at this point in the history
  • Loading branch information
Fallen-Breath committed Mar 21, 2021
1 parent fcd5ca8 commit 2fc4588
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/main/java/me/fallenbreath/pistorder/impl/PistorderDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public class PistorderDisplay

private DisplayMode displayMode;

// used for dynamically_information_update
private long lastUpdateTime = -1;

public PistorderDisplay(World world, BlockPos pos, BlockState blockState, Direction direction, PistonActionType actionType)
{
this.world = world;
Expand Down Expand Up @@ -82,6 +85,9 @@ private void disable()
this.displayMode = DisplayMode.DISABLED;
}

/**
* Will trigger a refresh
*/
private void setDisplayMode(DisplayMode mode)
{
this.displayMode = mode;
Expand Down Expand Up @@ -112,6 +118,9 @@ private void refreshInformation()
}
}

/**
* Might make the piston blink for a while if the action type is retract
*/
private void analyze(World world, BlockPos pos, Direction pistonFacing, PistonActionType PistonActionType)
{
BlockState[] states = new BlockState[2];
Expand All @@ -132,19 +141,19 @@ private void analyze(World world, BlockPos pos, Direction pistonFacing, PistonAc
pistonHandler.calculatePush();
}

if (PistonActionType.isRetract())
{
world.setBlockState(pos, states[0], 18);
world.setBlockState(pos.offset(pistonFacing), states[1], 18);
}

this.brokenBlocks = pistonHandler.getBrokenBlocks();
this.movedBlocks = pistonHandler.getMovedBlocks();
// reverse the list for correct order
Collections.reverse(this.brokenBlocks);
Collections.reverse(this.movedBlocks);

PushLimitManager.getInstance().restorePushLimit();

if (PistonActionType.isRetract())
{
world.setBlockState(pos, states[0], 18);
world.setBlockState(pos.offset(pistonFacing), states[1], 18);
}
}

private boolean tryIndirectMode()
Expand Down Expand Up @@ -270,7 +279,11 @@ void render(float tickDelta)

if (PistorderConfigure.DYNAMICALLY_INFORMATION_UPDATE)
{
this.refreshInformation();
if (this.world.getTime() != this.lastUpdateTime)
{
this.refreshInformation();
this.lastUpdateTime = this.world.getTime();
}
}

String actionKey = this.actionType.isPush() ? "pistorder.push" : "pistorder.retract";
Expand Down

0 comments on commit 2fc4588

Please sign in to comment.