Turret ammo sync

This commit is contained in:
Anuken 2024-07-16 14:17:10 -04:00
parent afc8d5e396
commit 2f1f334d65
4 changed files with 22 additions and 2 deletions

View file

@ -478,7 +478,7 @@ public class NetClient implements ApplicationListener{
Log.warn("Block ID mismatch at @: @ != @. Skipping block snapshot.", tile, tile.build.block.id, block);
break;
}
tile.build.readAll(Reads.get(input), tile.build.version());
tile.build.readSync(Reads.get(input), tile.build.version());
}
}catch(Exception e){
Log.err(e);

View file

@ -913,7 +913,7 @@ public class NetServer implements ApplicationListener{
dataStream.writeInt(entity.pos());
dataStream.writeShort(entity.block.id);
entity.writeAll(Writes.get(dataStream));
entity.writeSync(Writes.get(dataStream));
if(syncStream.size() > maxSnapshotSize){
dataStream.close();

View file

@ -261,6 +261,14 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
read(read, revision);
}
public void writeSync(Writes write){
writeAll(write);
}
public void readSync(Reads read, byte revision){
readAll(read, revision);
}
@CallSuper
public void write(Writes write){
//overriden by subclasses!

View file

@ -140,6 +140,7 @@ public class Turret extends ReloadTurret{
quickRotate = false;
outlinedIcon = 1;
drawLiquidLight = false;
sync = true;
}
@Override
@ -664,6 +665,17 @@ public class Turret extends ReloadTurret{
public byte version(){
return 1;
}
@Override
public void readSync(Reads read, byte revision){
//maintain rotation and reload when syncing so clients don't see turrets snapping around
float oldRot = rotation, oldReload = reloadCounter;
readAll(read, revision);
rotation = oldRot;
reloadCounter = oldReload;
}
}
public static class BulletEntry{