Fixed save data resetting

This commit is contained in:
Halbear
2026-06-03 15:09:45 +01:00
parent 569360d6a7
commit 77741a3b37
3 changed files with 16 additions and 6 deletions
@@ -65,6 +65,7 @@ public class VehicleBaseEntity extends Entity {
BASE_DOUBLE_PARAMETERS.put("GRAVITY",!vehicleBuildInfo.GetAdheresToGravity() ? 0 : vehicleBuildInfo.GetGravityStrength()/200.0); BASE_DOUBLE_PARAMETERS.put("GRAVITY",!vehicleBuildInfo.GetAdheresToGravity() ? 0 : vehicleBuildInfo.GetGravityStrength()/200.0);
BASE_BOOL_PARAMETERS.put("ADHERES_TO_GRAVITY",vehicleBuildInfo.GetAdheresToGravity()); BASE_BOOL_PARAMETERS.put("ADHERES_TO_GRAVITY",vehicleBuildInfo.GetAdheresToGravity());
BASE_BOOL_PARAMETERS.put("ON_GROUND",true); BASE_BOOL_PARAMETERS.put("ON_GROUND",true);
BASE_BOOL_PARAMETERS.put("WHEEL_FRICTION",vehicleBuildInfo.doWheelsDrag());
BASE_DOUBLE_PARAMETERS.put("CENTRE_OF_MASS_X",vehicleBuildInfo.GetCentreOfMass().x); BASE_DOUBLE_PARAMETERS.put("CENTRE_OF_MASS_X",vehicleBuildInfo.GetCentreOfMass().x);
BASE_DOUBLE_PARAMETERS.put("CENTRE_OF_MASS_Y",vehicleBuildInfo.GetCentreOfMass().y); BASE_DOUBLE_PARAMETERS.put("CENTRE_OF_MASS_Y",vehicleBuildInfo.GetCentreOfMass().y);
BASE_DOUBLE_PARAMETERS.put("CENTRE_OF_MASS_Z",vehicleBuildInfo.GetCentreOfMass().z); BASE_DOUBLE_PARAMETERS.put("CENTRE_OF_MASS_Z",vehicleBuildInfo.GetCentreOfMass().z);
@@ -257,14 +258,15 @@ public class VehicleBaseEntity extends Entity {
@Override @Override
protected void readAdditional(CompoundNBT compound) { protected void readAdditional(CompoundNBT compound) {
if (compound.contains("CustomNBTData")) { if (compound.contains("VehicleData")) {
this.dataManager.set(VEHICLE_SYNCHED_PARAMETERS, compound.getCompound("VehicleData")); this.dataManager.set(VEHICLE_SYNCHED_PARAMETERS, compound.getCompound("VehicleData"));
} }
} }
@Override @Override
protected void writeAdditional(CompoundNBT compound) { protected void writeAdditional(CompoundNBT compound) {
compound.put("VehicleData", this.dataManager.get(VEHICLE_SYNCHED_PARAMETERS)); CompoundNBT SynchedData = this.dataManager.get(VEHICLE_SYNCHED_PARAMETERS).copy();
compound.put("VehicleData", SynchedData);
} }
@Override @Override
@@ -278,7 +280,7 @@ public class VehicleBaseEntity extends Entity {
this.baseTick(); this.baseTick();
this.LastPositionVector = CurrentPositionVector; this.LastPositionVector = CurrentPositionVector;
CurrentPositionVector = getPositionVec(); CurrentPositionVector = getPositionVec();
PhysicsTick(); PhysicsTick(!this.world.isRemote());
this.setPosition(this.getPosX(), this.getPosY(), this.getPosZ()); this.setPosition(this.getPosX(), this.getPosY(), this.getPosZ());
Controller.PollInputs(GetByteArrayValue("INPUT_DATA")); Controller.PollInputs(GetByteArrayValue("INPUT_DATA"));
SubClassTickUpdateEvent(); SubClassTickUpdateEvent();
@@ -315,7 +317,8 @@ public class VehicleBaseEntity extends Entity {
VehicleVelocity = new Vector3(GetDoubleDataValue("VELOCITY_X"),GetDoubleDataValue("VELOCITY_Y"),GetDoubleDataValue("VELOCITY_Z")); VehicleVelocity = new Vector3(GetDoubleDataValue("VELOCITY_X"),GetDoubleDataValue("VELOCITY_Y"),GetDoubleDataValue("VELOCITY_Z"));
} }
public boolean TouchingGround(){return GetBooleanDataValue("ON_GROUND");} public boolean TouchingGround(){return GetBooleanDataValue("ON_GROUND");}
public void PhysicsTick(){
public void PhysicsTick(boolean ServerSided){
VehicleVelocity = new Vector3(GetDoubleDataValue("VELOCITY_X"),GetDoubleDataValue("VELOCITY_Y"),GetDoubleDataValue("VELOCITY_Z")); VehicleVelocity = new Vector3(GetDoubleDataValue("VELOCITY_X"),GetDoubleDataValue("VELOCITY_Y"),GetDoubleDataValue("VELOCITY_Z"));
Vector3d Velocity = Vector3.Positive(VehicleVelocity).GetDouble(); Vector3d Velocity = Vector3.Positive(VehicleVelocity).GetDouble();
Vector3d NormalisedVelocity = Velocity.normalize(); Vector3d NormalisedVelocity = Velocity.normalize();
@@ -81,8 +81,8 @@ public class VehicleCameraSettings {
PointOfView Cam = minecraftInstance.gameSettings.getPointOfView(); PointOfView Cam = minecraftInstance.gameSettings.getPointOfView();
if (Cam == PointOfView.FIRST_PERSON) { if (Cam == PointOfView.FIRST_PERSON) {
//event.setRoll(event.getRoll() - CurrentPreset.GetCameraTransformations().getZ()); //event.setRoll(event.getRoll() - CurrentPreset.GetCameraTransformations().getZ());
//event.setYaw(event.getYaw() + (180F - CurrentPreset.GetCameraTransformations().getX())); event.setYaw(event.getYaw() + (180F - CurrentPreset.GetCameraTransformations().getX()));
//event.setPitch(event.getPitch() - CurrentPreset.GetCameraTransformations().getY()); event.setPitch(event.getPitch() - CurrentPreset.GetCameraTransformations().getY());
} }
} }
} }
@@ -21,6 +21,7 @@ public class VehicleBuildInfo {
private float GasCelCapacity; private float GasCelCapacity;
private double Gravity = 4.9f; private double Gravity = 4.9f;
private boolean AdheresToGravity = true; private boolean AdheresToGravity = true;
private boolean WheelsHaveDragAndFriction = true;
private Vector3d PilotSeat; private Vector3d PilotSeat;
private List<String> BuiltInVehicleInputActions = new ArrayList<>(); private List<String> BuiltInVehicleInputActions = new ArrayList<>();
private List<Vector3d> PassengerSeats = new ArrayList<>(); private List<Vector3d> PassengerSeats = new ArrayList<>();
@@ -33,6 +34,12 @@ public class VehicleBuildInfo {
private Vector3d OriginOffset = new Vector3d(0,0,0); private Vector3d OriginOffset = new Vector3d(0,0,0);
private PhysicsPreset physicsPreset = PhysicsPreset.AdvancedMinecraft; private PhysicsPreset physicsPreset = PhysicsPreset.AdvancedMinecraft;
public boolean doWheelsDrag(){return WheelsHaveDragAndFriction;}
public VehicleBuildInfo SetWheelDrag(boolean WheelsDrag){
this.WheelsHaveDragAndFriction = WheelsDrag;
return this;
}
public VehicleBuildInfo SetOrigin(PivotOrigin OriginType, Vector3d OriginOffset){ public VehicleBuildInfo SetOrigin(PivotOrigin OriginType, Vector3d OriginOffset){
this.OriginType = OriginType; this.OriginType = OriginType;
this.OriginOffset = OriginOffset; this.OriginOffset = OriginOffset;