Skip to content

Commit

Permalink
experimental
Browse files Browse the repository at this point in the history
after the grace period transitions smoothly into the synced state instead of snapping to it
  • Loading branch information
MalkContent committed Feb 23, 2022
1 parent cff89c3 commit 58891dd
Showing 1 changed file with 28 additions and 8 deletions.
Expand Up @@ -48,13 +48,14 @@ public class WatermillBlockEntity extends IEBaseBlockEntity implements IEServerT
public boolean multiblock = false;
private boolean beingBroken = false;
public double perTick;
private double catchupSpeed;
private final CapabilityReference<IRotationAcceptor> outputCap = CapabilityReference.forNeighbor(
this, IRotationAcceptor.CAPABILITY, () -> getFacing().getOpposite()
);
private final CapabilityReference<IRotationAcceptor> reverseOutputCap = CapabilityReference.forNeighbor(
this, IRotationAcceptor.CAPABILITY, this::getFacing
);
private static final int globalSyncDelay = 20*20;
private static final int globalSyncDelay = 10*20;
private int globalSyncDelayCounter = 1;

public WatermillBlockEntity(BlockEntityType<WatermillBlockEntity> type, BlockPos pos, BlockState state)
Expand All @@ -65,7 +66,7 @@ public WatermillBlockEntity(BlockEntityType<WatermillBlockEntity> type, BlockPos
@Override
public void tickClient()
{
rotation += perTick;
rotation += perTick+catchupSpeed;
rotation %= 1;
}

Expand Down Expand Up @@ -133,21 +134,38 @@ private void setPerTickAndAdvance(double newValue)
perTick = newValue;
markContainingBlockForUpdate(null);
}
else if(globalSyncDelayCounter >= 0)
else if(globalSyncDelayCounter > 0)
globalSyncDelayCounter--;

if(globalSyncDelayCounter==0)
{
float newrot = (float)(level.getGameTime()*perTick);
if(rotation!=newrot)
if(Math.abs((newrot%.125)-(rotation%.125)) < perTick)
{
rotation = newrot;
//update so changing perTick client side a second time AFTER globalSyncDelayCounter went to zero once does not jank from the markContainingBlockForUpdate above
rotation = (float)(newrot-perTick);
catchupSpeed = 0;
globalSyncDelayCounter--;
markContainingBlockForUpdate(null);
}
else
{
double oldCatchupSpeed = catchupSpeed;
catchupSpeed = perTick/8 < 0.0002?perTick/8: 0.0002;
if(oldCatchupSpeed!=catchupSpeed)
markContainingBlockForUpdate(null);
}

// rotation += perTick+(perTick/2 < 0.002?perTick/2: 0.002);

// if(rotation!=newrot)
// {
// rotation = newrot;
// //update so changing perTick client side a second time AFTER globalSyncDelayCounter went to zero once does not jank from the markContainingBlockForUpdate above
// markContainingBlockForUpdate(null);
// }
}
else
rotation += perTick;
// else
rotation += perTick+catchupSpeed;
rotation %= 1;
}

Expand Down Expand Up @@ -252,6 +270,7 @@ public void readCustomNBT(CompoundTag nbt, boolean descPacket)
offset = nbt.getIntArray("offset");
rotation = nbt.getFloat("rotation");
perTick = nbt.getDouble("perTick");
catchupSpeed = nbt.getDouble("catchupSpeed");

if(offset==null||offset.length < 2)
offset = new int[]{0, 0};
Expand All @@ -263,6 +282,7 @@ public void writeCustomNBT(CompoundTag nbt, boolean descPacket)
nbt.putIntArray("offset", offset);
nbt.putFloat("rotation", rotation);
nbt.putDouble("perTick", perTick);
nbt.putDouble("catchupSpeed", catchupSpeed);
}

private AABB renderAABB;
Expand Down

0 comments on commit 58891dd

Please sign in to comment.