prevent spamming packets (#3126)

1/20 less laggier tm
This commit is contained in:
AngelBottomless 2023-03-18 21:19:53 +09:00 committed by GitHub
parent 82978076d9
commit 92fce93890
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -73,7 +73,8 @@ public class MachineBaseBlockEntity extends BlockEntity implements BlockEntityTi
private RedstoneConfiguration redstoneConfiguration;
public boolean renderMultiblock = false;
private final static int syncCoolDown = 20;
private boolean markSync = false;
private int tickTime = 0;
/**
@ -119,11 +120,18 @@ public class MachineBaseBlockEntity extends BlockEntity implements BlockEntityTi
return verifier.isValid();
}
private void syncIfNecessary(){
if (this.markSync && this.tickTime % syncCoolDown == 0) {
this.markSync = false;
if (world == null || world.isClient) { return; }
NetworkManager.sendToTracking(ClientBoundPackets.createCustomDescriptionPacket(this), this);
}
}
public void writeMultiblock(MultiblockWriter writer) {}
public void syncWithAll() {
if (world == null || world.isClient) { return; }
NetworkManager.sendToTracking(ClientBoundPackets.createCustomDescriptionPacket(this), this);
this.markSync = true;
}
public void onLoad() {
@ -187,6 +195,7 @@ public class MachineBaseBlockEntity extends BlockEntity implements BlockEntityTi
if (fluidConfiguration != null && isActive(RedstoneConfiguration.FLUID_IO)) {
fluidConfiguration.update(this);
}
syncIfNecessary();
}
public void resetUpgrades() {