From 8878b3f9de81ddf7edc84efb1e3ec880997d0414 Mon Sep 17 00:00:00 2001 From: Boblet Date: Thu, 8 Feb 2024 16:28:12 +0100 Subject: [PATCH] arty sync fix --- changelog | 3 +- .../turret/TileEntityTurretArty.java | 56 ++++------ .../turret/TileEntityTurretBaseNT.java | 58 +++++----- .../turret/TileEntityTurretHIMARS.java | 101 ++++++++---------- 4 files changed, 98 insertions(+), 120 deletions(-) diff --git a/changelog b/changelog index ec43e17c2..080d89a35 100644 --- a/changelog +++ b/changelog @@ -45,4 +45,5 @@ * Fixed normal drones loading chunks * Fixed chunk-loading drones not loading chunks * Fixed several chemistry templates missing names -* Fixed rampant mode random scout spawns being able to appear inside blocks \ No newline at end of file +* Fixed rampant mode random scout spawns being able to appear inside blocks +* Fixed turret rotation sometimes desyncing when out of range, this is especially noticeable with slow-moving arty \ No newline at end of file diff --git a/src/main/java/com/hbm/tileentity/turret/TileEntityTurretArty.java b/src/main/java/com/hbm/tileentity/turret/TileEntityTurretArty.java index 3b9c8d3ec..03b54b68b 100644 --- a/src/main/java/com/hbm/tileentity/turret/TileEntityTurretArty.java +++ b/src/main/java/com/hbm/tileentity/turret/TileEntityTurretArty.java @@ -238,24 +238,20 @@ public class TileEntityTurretArty extends TileEntityTurretBaseArtillery implemen this.barrelPos = 0; } } - } - - if(this.mode == this.MODE_MANUAL) { - if(!this.targetQueue.isEmpty()) { - this.tPos = this.targetQueue.get(0); - } - } else { - this.targetQueue.clear(); - } - - if(worldObj.isRemote) { this.lastRotationPitch = this.rotationPitch; this.lastRotationYaw = this.rotationYaw; } - - this.aligned = false; if(!worldObj.isRemote) { + if(this.mode == this.MODE_MANUAL) { + if(!this.targetQueue.isEmpty()) { + this.tPos = this.targetQueue.get(0); + } + } else { + this.targetQueue.clear(); + } + + this.aligned = false; this.updateConnections(); @@ -263,15 +259,12 @@ public class TileEntityTurretArty extends TileEntityTurretBaseArtillery implemen this.target = null; this.stattrak++; } - } - if(target != null && this.mode != this.MODE_MANUAL) { - if(!this.entityInLOS(this.target)) { - this.target = null; + if(target != null && this.mode != this.MODE_MANUAL) { + if(!this.entityInLOS(this.target)) { + this.target = null; + } } - } - - if(!worldObj.isRemote) { if(target != null) { this.tPos = this.getEntityPos(target); @@ -280,18 +273,15 @@ public class TileEntityTurretArty extends TileEntityTurretBaseArtillery implemen this.tPos = null; } } - } - if(isOn() && hasPower()) { - - if(tPos != null) - this.alignTurret(); - } else { - this.target = null; - this.tPos = null; - } - - if(!worldObj.isRemote) { + if(isOn() && hasPower()) { + + if(tPos != null) + this.alignTurret(); + } else { + this.target = null; + this.tPos = null; + } if(!isOn()) this.targetQueue.clear(); @@ -335,10 +325,6 @@ public class TileEntityTurretArty extends TileEntityTurretBaseArtillery implemen } else { - Vec3 vec = Vec3.createVectorHelper(this.getBarrelLength(), 0, 0); - vec.rotateAroundZ((float) -this.rotationPitch); - vec.rotateAroundY((float) -(this.rotationYaw + Math.PI * 0.5)); - //this will fix the interpolation error when the turret crosses the 360° point if(Math.abs(this.lastRotationYaw - this.rotationYaw) > Math.PI) { diff --git a/src/main/java/com/hbm/tileentity/turret/TileEntityTurretBaseNT.java b/src/main/java/com/hbm/tileentity/turret/TileEntityTurretBaseNT.java index 4420667ba..48b8ea59f 100644 --- a/src/main/java/com/hbm/tileentity/turret/TileEntityTurretBaseNT.java +++ b/src/main/java/com/hbm/tileentity/turret/TileEntityTurretBaseNT.java @@ -84,6 +84,10 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple //only used by clients for interpolation public double lastRotationYaw; public double lastRotationPitch; + //only used by clients for approach + public double syncRotationYaw; + public double syncRotationPitch; + protected int turnProgress; //is the turret on? public boolean isOn = false; //is the turret aimed at the target? @@ -156,46 +160,41 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple if(worldObj.isRemote) { this.lastRotationPitch = this.rotationPitch; this.lastRotationYaw = this.rotationYaw; + this.rotationPitch = this.syncRotationPitch; + this.rotationYaw = this.syncRotationYaw; } - - this.aligned = false; if(!worldObj.isRemote) { - + + this.aligned = false; this.updateConnections(); if(this.target != null && !target.isEntityAlive()) { this.target = null; this.stattrak++; } - } - - if(target != null) { - if(!this.entityInLOS(this.target)) { - this.target = null; - } - } - - if(!worldObj.isRemote) { + if(target != null) { + if(!this.entityInLOS(this.target)) { + this.target = null; + } + } + if(target != null) { this.tPos = this.getEntityPos(target); } else { this.tPos = null; } - } - - if(isOn() && hasPower()) { - if(tPos != null) - this.alignTurret(); - } else { - - this.target = null; - this.tPos = null; - } - - if(!worldObj.isRemote) { + if(isOn() && hasPower()) { + + if(tPos != null) + this.alignTurret(); + } else { + + this.target = null; + this.tPos = null; + } if(this.target != null && !target.isEntityAlive()) { this.target = null; @@ -237,10 +236,6 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple } else { - Vec3 vec = Vec3.createVectorHelper(this.getBarrelLength(), 0, 0); - vec.rotateAroundZ((float) -this.rotationPitch); - vec.rotateAroundY((float) -(this.rotationYaw + Math.PI * 0.5)); - //this will fix the interpolation error when the turret crosses the 360° point if(Math.abs(this.lastRotationYaw - this.rotationYaw) > Math.PI) { @@ -260,6 +255,8 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple data.setDouble("tY", this.tPos.yCoord); data.setDouble("tZ", this.tPos.zCoord); } + data.setDouble("pitch", this.rotationPitch); + data.setDouble("yaw", this.rotationYaw); data.setLong("power", this.power); data.setBoolean("isOn", this.isOn); data.setBoolean("targetPlayers", this.targetPlayers); @@ -292,7 +289,10 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple @Override public void networkUnpack(NBTTagCompound nbt) { super.networkUnpack(nbt); - + + this.turnProgress = 2; + this.syncRotationPitch = nbt.getDouble("pitch"); + this.syncRotationYaw = nbt.getDouble("yaw"); this.power = nbt.getLong("power"); this.isOn = nbt.getBoolean("isOn"); this.targetPlayers = nbt.getBoolean("targetPlayers"); diff --git a/src/main/java/com/hbm/tileentity/turret/TileEntityTurretHIMARS.java b/src/main/java/com/hbm/tileentity/turret/TileEntityTurretHIMARS.java index 050040197..1e366da9f 100644 --- a/src/main/java/com/hbm/tileentity/turret/TileEntityTurretHIMARS.java +++ b/src/main/java/com/hbm/tileentity/turret/TileEntityTurretHIMARS.java @@ -135,40 +135,36 @@ public class TileEntityTurretHIMARS extends TileEntityTurretBaseArtillery implem @Override public void updateEntity() { - this.lastCrane = this.crane; - - if(this.mode == this.MODE_MANUAL) { - if(!this.targetQueue.isEmpty()) { - this.tPos = this.targetQueue.get(0); - } - } else { - this.targetQueue.clear(); - } - if(worldObj.isRemote) { this.lastRotationPitch = this.rotationPitch; this.lastRotationYaw = this.rotationYaw; + this.lastCrane = this.crane; } - - this.aligned = false; if(!worldObj.isRemote) { + if(this.mode == this.MODE_MANUAL) { + if(!this.targetQueue.isEmpty()) { + this.tPos = this.targetQueue.get(0); + } + } else { + this.targetQueue.clear(); + } + + this.aligned = false; + this.updateConnections(); if(this.target != null && !target.isEntityAlive()) { this.target = null; this.stattrak++; } - } - if(target != null && this.mode != this.MODE_MANUAL) { - if(!this.entityInLOS(this.target)) { - this.target = null; + if(target != null && this.mode != this.MODE_MANUAL) { + if(!this.entityInLOS(this.target)) { + this.target = null; + } } - } - - if(!worldObj.isRemote) { if(target != null) { this.tPos = this.getEntityPos(target); @@ -177,51 +173,48 @@ public class TileEntityTurretHIMARS extends TileEntityTurretBaseArtillery implem this.tPos = null; } } - } - if(isOn() && hasPower()) { - - if(!this.hasAmmo() || this.crane > 0) { + if(isOn() && hasPower()) { - this.turnTowardsAngle(0, this.rotationYaw); - - if(this.aligned) { + if(!this.hasAmmo() || this.crane > 0) { - if(this.hasAmmo()) { - this.crane -= 0.0125F; - } else { - this.crane += 0.0125F; + this.turnTowardsAngle(0, this.rotationYaw); + + if(this.aligned) { - if(this.crane >= 1F && !worldObj.isRemote) { - int available = this.getSpareRocket(); + if(this.hasAmmo()) { + this.crane -= 0.0125F; + } else { + this.crane += 0.0125F; - if(available != -1) { - HIMARSRocket type = ItemAmmoHIMARS.itemTypes[available]; - this.typeLoaded = available; - this.ammo = type.amount; - this.conusmeAmmo(new ComparableStack(ModItems.ammo_himars, 1, available)); + if(this.crane >= 1F) { + int available = this.getSpareRocket(); + + if(available != -1) { + HIMARSRocket type = ItemAmmoHIMARS.itemTypes[available]; + this.typeLoaded = available; + this.ammo = type.amount; + this.conusmeAmmo(new ComparableStack(ModItems.ammo_himars, 1, available)); + } } } } + + this.crane = MathHelper.clamp_float(this.crane, 0F, 1F); + + } else { + + if(tPos != null) { + this.alignTurret(); + } } - this.crane = MathHelper.clamp_float(this.crane, 0F, 1F); - } else { - - if(tPos != null) { - this.alignTurret(); - } + + this.target = null; + this.tPos = null; } - } else { - - this.target = null; - this.tPos = null; - } - - if(!worldObj.isRemote) { - if(!isOn()) this.targetQueue.clear(); if(this.target != null && !target.isEntityAlive()) { @@ -256,10 +249,6 @@ public class TileEntityTurretHIMARS extends TileEntityTurretBaseArtillery implem } else { - Vec3 vec = Vec3.createVectorHelper(this.getBarrelLength(), 0, 0); - vec.rotateAroundZ((float) -this.rotationPitch); - vec.rotateAroundY((float) -(this.rotationYaw + Math.PI * 0.5)); - //this will fix the interpolation error when the turret crosses the 360° point if(Math.abs(this.lastRotationYaw - this.rotationYaw) > Math.PI) { @@ -277,6 +266,7 @@ public class TileEntityTurretHIMARS extends TileEntityTurretBaseArtillery implem data.setShort("mode", this.mode); data.setInteger("type", this.typeLoaded); data.setInteger("ammo", this.ammo); + data.setFloat("crane", crane); return data; } @@ -286,6 +276,7 @@ public class TileEntityTurretHIMARS extends TileEntityTurretBaseArtillery implem this.mode = nbt.getShort("mode"); this.typeLoaded = nbt.getShort("type"); this.ammo = nbt.getInteger("ammo"); + this.crane = nbt.getFloat("crane"); } public boolean hasAmmo() {