Skip to content

Commit

Permalink
Fix waterwheel issues
Browse files Browse the repository at this point in the history
 - Lack of calculating rotation on client meant the wheels stuttered when they got synced
 - Left in print statement was printing on every update
 - Deferred updates were handling incorrectly, correct comparison is now in place using Long.MAX
  • Loading branch information
voidsong-dragonfly committed Jul 14, 2024
1 parent ad56673 commit d3355e0
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class WatermillBlockEntity extends IEBaseBlockEntity implements IEServerT
private double rotation = 0;
private double speed = 0;
private double powerOut = 0;
private long defferedUpdateTick = 0;
private long deferredUpdateTick = 0;
private boolean beingBroken = false;
private IEBlockCapabilityCache<IRotationAcceptor> dynamo = null;
//These are position lists for blocks to check for flowrate. First 11 are breastshot, all 16 are overshot
Expand Down Expand Up @@ -106,13 +106,17 @@ public void tickClient()
@Override
public void tickServer()
{
//Update rotation to make sure we sync it with client correctly
rotation += speed;
rotation %= 1;
//Do the rest of the update for the actual wheel logic
if(dynamo!=null&&powerOut>0&&dynamo.getCapability()!=null)
{
dynamo.getCapability().inputRotation(powerOut);
if(level.getGameTime()%1024==((getBlockPos().getX()^getBlockPos().getZ())&1023))
handleUpdate(null);
}
if(dynamo==null||level.getGameTime()<defferedUpdateTick)
if(dynamo==null||level.getGameTime()> deferredUpdateTick)
handleUpdate(null);
}

Expand All @@ -129,8 +133,6 @@ public void onLoad()
public void onNeighborBlockChange(BlockPos pos)
{
super.onNeighborBlockChange(pos);
if(isDummy()&&(pos.relative(getFacing()).equals(getBlockPos())||pos.relative(getFacing().getOpposite()).equals(getBlockPos())))
return;
if(master() instanceof WatermillBlockEntity master)
master.setShouldUpdate();
}
Expand All @@ -156,7 +158,6 @@ public void handleUpdate(@Nullable Direction search)
while(wheels<MAX_WHEELS)
{
BlockEntity be = SafeChunkUtils.getSafeBE(level, getBlockPos().relative(step, wheels));
System.out.println(be);
if(be instanceof WatermillBlockEntity watermill)
if(watermill.isBlocked())
break;
Expand Down Expand Up @@ -202,7 +203,7 @@ else if(search == null)
if(be instanceof WatermillBlockEntity watermill) watermill.handleUpdate(search);
}
//Set this block's deferred update tick to -1
defferedUpdateTick = -1;
deferredUpdateTick = Long.MAX_VALUE;
//Mark chunk dirty so data saves
markChunkDirty();
}
Expand Down Expand Up @@ -477,6 +478,6 @@ public double getSpeed()
public void setShouldUpdate()
{
if(isDummy()) return;
defferedUpdateTick = Math.max(defferedUpdateTick, level.getGameTime());
deferredUpdateTick = Math.min(deferredUpdateTick, level.getGameTime());
}
}

0 comments on commit d3355e0

Please sign in to comment.