From d075d614f130414c328b40523d0b5626bc338a49 Mon Sep 17 00:00:00 2001 From: Naxgeneral Date: Mon, 2 Mar 2026 10:59:53 +0700 Subject: [PATCH 1/5] Modified VehicleD_Moving to have function to check if it about to enter unloaded chunk or not --- .../instances/AEntityVehicleD_Moving.java | 85 ++++++++++++++----- 1 file changed, 65 insertions(+), 20 deletions(-) diff --git a/mccore/src/main/java/minecrafttransportsimulator/entities/instances/AEntityVehicleD_Moving.java b/mccore/src/main/java/minecrafttransportsimulator/entities/instances/AEntityVehicleD_Moving.java index b31a5d20e..976d276a8 100644 --- a/mccore/src/main/java/minecrafttransportsimulator/entities/instances/AEntityVehicleD_Moving.java +++ b/mccore/src/main/java/minecrafttransportsimulator/entities/instances/AEntityVehicleD_Moving.java @@ -44,11 +44,11 @@ * @author don_bruce */ abstract class AEntityVehicleD_Moving extends AEntityVehicleC_Colliding { - //Variables - public final ComputedVariable leftTurnLightVar; - public final ComputedVariable rightTurnLightVar; - public final ComputedVariable brakeVar; - public final ComputedVariable parkingBrakeVar; + //Variables + public final ComputedVariable leftTurnLightVar; + public final ComputedVariable rightTurnLightVar; + public final ComputedVariable brakeVar; + public final ComputedVariable parkingBrakeVar; public final ComputedVariable lockedVar; public static final double MAX_BRAKE = 1D; public UUID keyUUID; @@ -58,6 +58,9 @@ abstract class AEntityVehicleD_Moving extends AEntityVehicleC_Colliding { public boolean slipping; public boolean skidSteerActive; public boolean lockedOnRoad; + public double modifiedSpeedFactor = speedFactor; + public boolean chunkCacheStat; + public int cachedChunkTimeout = 0; private boolean updateGroundDevicesRequest; private int lastBlockCollisionBoxesCount; private int crashDebounce; @@ -113,6 +116,8 @@ abstract class AEntityVehicleD_Moving extends AEntityVehicleC_Colliding { private final Point3D tempBoxPosition = new Point3D(); private final Point3D normalizedGroundVelocityVector = new Point3D(); private final Point3D normalizedGroundHeadingVector = new Point3D(); + private final Point3D chunkGuardDirection = new Point3D(); + private final Point3D cachedChunkGuardDirection = new Point3D(); public final List allBlockCollisionBoxes = new ArrayList<>(); //Public so we can add ground device boxes to this set. private AEntityE_Interactable lastCollidedEntity; public VehicleGroundDeviceCollection groundDeviceCollective; @@ -137,7 +142,7 @@ public AEntityVehicleD_Moving(AWrapperWorld world, IWrapperPlayer placingPlayer, this.groundDeviceCollective = new VehicleGroundDeviceCollection((EntityVehicleF_Physics) this); this.placingPlayer = placingPlayer; this.blockBreakDelay = 500; - + addVariable(this.leftTurnLightVar = new ComputedVariable(this, "left_turn_signal", data)); addVariable(this.rightTurnLightVar = new ComputedVariable(this, "right_turn_signal", data)); addVariable(this.brakeVar = new ComputedVariable(this, "brake", data)); @@ -223,6 +228,7 @@ public void update() { } else { slipping = false; } + modifySpeedFactor(); world.beginProfiling("TotalMovement", false); moveVehicle(); if (!world.isClient()) { @@ -236,7 +242,6 @@ public void update() { @Override public void doPostUpdateLogic() { super.doPostUpdateLogic(); - //Move all entities that are touching this entity. if (velocity != 0) { world.beginProfiling("MoveAlongEntities", true); @@ -598,7 +603,7 @@ private double getTurningForce() { //This is because the faster we go the quicker we need to turn to keep pace with the vehicle's movement. //We need to take speed-factor into account here, as that will make us move different lengths per tick. //Finally, we need to reduce this by a constant to get "proper" force.. - return turningForce * groundVelocity * (speedFactor / 0.35D) / 2D; + return turningForce * groundVelocity * (modifiedSpeedFactor / 0.35D) / 2D; } } return 0; @@ -787,11 +792,11 @@ private void moveVehicle() { //whichever is the lower of the two. If we apply boost, update our collision boxes before the next step. //Note that this logic is not applied on trailers, as they use special checks with only rotations for movement. world.beginProfiling("GroundBoostCheck", false); - groundMotion.y = groundDeviceCollective.getMaxCollisionDepth() / speedFactor; + groundMotion.y = groundDeviceCollective.getMaxCollisionDepth() / modifiedSpeedFactor; if (groundMotion.y > 0) { world.beginProfiling("GroundBoostApply", false); //Make sure boost doesn't exceed the config value. - groundMotion.y = Math.min(groundMotion.y, climbSpeedVar.currentValue / speedFactor); + groundMotion.y = Math.min(groundMotion.y, climbSpeedVar.currentValue / modifiedSpeedFactor); //If adding our boost would make motion.y positive, set motion.y to zero and apply the remaining boost. //This is done as it's clear motion.y is just moving the vehicle into the ground. @@ -890,7 +895,7 @@ private void moveVehicle() { //Now that that the movement has been checked, move the vehicle. world.beginProfiling("ApplyMotions", false); - motionApplied.set(motion).scale(speedFactor).add(groundMotion); + motionApplied.set(motion).scale(modifiedSpeedFactor).add(groundMotion); rotationApplied.angles.set(rotation.angles); //Add road contributions. @@ -903,7 +908,7 @@ private void moveVehicle() { pathingApplied = -pathingApplied; } } else { - pathingApplied = goingInReverse ? -velocity * speedFactor : velocity * speedFactor; + pathingApplied = goingInReverse ? -velocity * modifiedSpeedFactor : velocity * modifiedSpeedFactor; } } else { pathingApplied = 0; @@ -943,7 +948,7 @@ private void moveVehicle() { //Note that orientation wasn't a direct angle-addition, as the rotation is applied relative to the current //orientation. This means that if we yaw 5 degrees, but are rolling 10 degrees, then we need to not do the //yaw rotation in the XZ plane, but instead in that relative-rotated plane. - //To account for this, we get the angle delta between the prior and current orientation, and use that for the delta. + //To account for this, we get the angle delta between the prior and current orientation, and use that for the delta. //Though before we do this we check if those angles were non-zero, as no need to do math if they are. if (!rotationApplied.angles.isZero()) { rotationApplied.angles.set(orientation.angles).subtract(prevOrientation.angles).clamp180(); @@ -978,8 +983,9 @@ private void moveVehicle() { } } else { //Mounted vehicles don't do most motions, only a sub-set of them. + modifySpeedFactor(); world.beginProfiling("ApplyMotions", true); - motionApplied.set(motion).scale(speedFactor); + motionApplied.set(motion).scale(modifiedSpeedFactor); position.add(motionApplied); //Rotation for mounted connections aligns using orientation, not angle-deltas. @@ -1000,6 +1006,45 @@ private void moveVehicle() { world.endProfiling(); } + + private void modifySpeedFactor() {//Function used for modify speed factor for use in moving vehicle no Clanker used so ask me for more info + if (world.isClient()) {//do not do this in client level + return; + } + + //get a sample of block blocks in front of vehicle + chunkGuardDirection.set(position.x + (motionApplied.x * 42), 1D, position.z + (motionApplied.z * 42)); + + //check for stat 1 is cached unloaded chunk present , 0 is no cached chunks. + if(!chunkCacheStat){ + //check the chunk sample is it not loaded if it is not loaded set vehicle speed factor to 0.008 + // if it is loaded make it follow its respective speed factor. + if(!world.chunkLoaded(chunkGuardDirection)){ + chunkCacheStat = true;//tell them that there unloaded chunk cached so it will not do this again + cachedChunkGuardDirection.set(chunkGuardDirection); //throw sample into quarantine zone to monitor it. + modifiedSpeedFactor = 0.009; // set speed factor + cachedChunkTimeout = 0; //set timer in case player turn around. + } + else { + modifiedSpeedFactor = speedFactor; // in case it stuck in this if. + } + } + else{ + if(world.chunkLoaded(cachedChunkGuardDirection)){//check the quarantine zone does this chunk sample finally loaded + modifiedSpeedFactor = speedFactor; // set speed factor back to default if it is loaded + chunkCacheStat = false;// tell them that there no more chunk in quarantine + } + else if(cachedChunkTimeout == 1000){//check if cycle already run for 1000 tick + chunkCacheStat = false; + cachedChunkTimeout = 0;// if yes tell chunk cache to stop and do cycle above again to get new sample which used incase player turn around to loaded chunks + } + else { + cachedChunkTimeout++; // +1 to timer each cycle + modifiedSpeedFactor = 0.009; // in case it fell off the chair. + } + } + } + /** * Checks if we have a collided collision box. If so, true is returned. */ @@ -1007,7 +1052,7 @@ private boolean isCollisionBoxCollided() { if (!ConfigSystem.settings.general.noclipVehicles.value && motion.length() > 0.001) { boolean clearedCache = false; for (BoundingBox box : allBlockCollisionBoxes) { - tempBoxPosition.set(box.globalCenter).subtract(position).rotate(rotation).subtract(box.globalCenter).add(position).addScaled(motion, speedFactor); + tempBoxPosition.set(box.globalCenter).subtract(position).rotate(rotation).subtract(box.globalCenter).add(position).addScaled(motion, modifiedSpeedFactor); if (!box.collidesWithLiquids && world.checkForCollisions(box, tempBoxPosition, !clearedCache, !world.isClient() && ConfigSystem.settings.damage.vehicleBlockBreaking.value)) { return true; } @@ -1029,7 +1074,7 @@ private boolean isCollisionBoxCollided() { */ private boolean correctCollidingMovement() { double hardnessHitThisTick = 0; - Point3D collisionMotion = motion.copy().scale(speedFactor); + Point3D collisionMotion = motion.copy().scale(modifiedSpeedFactor); for (BoundingBox box : allBlockCollisionBoxes) { //If we collided, so check to see if we can break some blocks or if we need to explode. //Don't bother with this logic if it's impossible for us to break anything. @@ -1106,8 +1151,8 @@ private boolean correctCollidingMovement() { //If we didn't break all our blocks, we need to inhibit our movement to prevent us from going inside them. if (inhibitMovement) { - motion.subtract(box.currentCollisionDepth.scale(1 / speedFactor)); - collisionMotion.set(motion.copy().scale(speedFactor)); + motion.subtract(box.currentCollisionDepth.scale(1 / modifiedSpeedFactor)); + collisionMotion.set(motion.copy().scale(modifiedSpeedFactor)); } } } @@ -1115,7 +1160,7 @@ private boolean correctCollidingMovement() { //Check the rotation. if (!rotation.angles.isZero()) { for (BoundingBox box : allBlockCollisionBoxes) { - tempBoxPosition.set(box.globalCenter).subtract(position).rotate(rotation).add(position).addScaled(motion, speedFactor); + tempBoxPosition.set(box.globalCenter).subtract(position).rotate(rotation).add(position).addScaled(motion, modifiedSpeedFactor); if (box.updateCollisions(world, tempBoxPosition.subtract(box.globalCenter), false)) { rotation.setToZero(); rotation.angles.set(0, 0, 0); @@ -1199,4 +1244,4 @@ public IWrapperNBT save(IWrapperNBT data) { data.setDouble("serverDeltaP", serverDeltaP); return data; } -} +} \ No newline at end of file From 0c52ba3773e5435d86ebb3454c53fec2d1c2f4b5 Mon Sep 17 00:00:00 2001 From: Natsuka <79125581+Naxgeneral@users.noreply.github.com> Date: Mon, 2 Mar 2026 18:55:59 +0700 Subject: [PATCH 2/5] Update AEntityVehicleD_Moving.java Edit the part where it call the SF modifier. --- .../entities/instances/AEntityVehicleD_Moving.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mccore/src/main/java/minecrafttransportsimulator/entities/instances/AEntityVehicleD_Moving.java b/mccore/src/main/java/minecrafttransportsimulator/entities/instances/AEntityVehicleD_Moving.java index 976d276a8..c3ed8d69e 100644 --- a/mccore/src/main/java/minecrafttransportsimulator/entities/instances/AEntityVehicleD_Moving.java +++ b/mccore/src/main/java/minecrafttransportsimulator/entities/instances/AEntityVehicleD_Moving.java @@ -228,7 +228,7 @@ public void update() { } else { slipping = false; } - modifySpeedFactor(); + world.beginProfiling("TotalMovement", false); moveVehicle(); if (!world.isClient()) { @@ -919,7 +919,7 @@ private void moveVehicle() { motionApplied.add(vehicleCollisionMotion); rotationApplied.angles.add(vehicleCollisionRotation.angles); } - + modifySpeedFactor(); //All contributions done, add calculated motions. position.add(motionApplied); if (!rotationApplied.angles.isZero()) { @@ -986,8 +986,8 @@ private void moveVehicle() { modifySpeedFactor(); world.beginProfiling("ApplyMotions", true); motionApplied.set(motion).scale(modifiedSpeedFactor); + modifySpeedFactor(); position.add(motionApplied); - //Rotation for mounted connections aligns using orientation, not angle-deltas. orientation.set(rotation).convertToAngles(); @@ -1244,4 +1244,4 @@ public IWrapperNBT save(IWrapperNBT data) { data.setDouble("serverDeltaP", serverDeltaP); return data; } -} \ No newline at end of file +} From a5526633fe3d163c75418e6ed7017510c1daa0d9 Mon Sep 17 00:00:00 2001 From: Natsuka <79125581+Naxgeneral@users.noreply.github.com> Date: Mon, 2 Mar 2026 19:35:53 +0700 Subject: [PATCH 3/5] Update AEntityVehicleD_Moving.java Changed part where it call the function --- .../entities/instances/AEntityVehicleD_Moving.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mccore/src/main/java/minecrafttransportsimulator/entities/instances/AEntityVehicleD_Moving.java b/mccore/src/main/java/minecrafttransportsimulator/entities/instances/AEntityVehicleD_Moving.java index c3ed8d69e..b2c85dc46 100644 --- a/mccore/src/main/java/minecrafttransportsimulator/entities/instances/AEntityVehicleD_Moving.java +++ b/mccore/src/main/java/minecrafttransportsimulator/entities/instances/AEntityVehicleD_Moving.java @@ -614,6 +614,7 @@ private double getTurningForce() { * Failure to do this will result in things going badly! */ private void moveVehicle() { + modifySpeedFactor(); if (towedByConnection == null || !towedByConnection.hitchConnection.mounted) { //First, update the vehicle ground device boxes. world.beginProfiling("GDBInit", true); @@ -919,7 +920,7 @@ private void moveVehicle() { motionApplied.add(vehicleCollisionMotion); rotationApplied.angles.add(vehicleCollisionRotation.angles); } - modifySpeedFactor(); + //All contributions done, add calculated motions. position.add(motionApplied); if (!rotationApplied.angles.isZero()) { @@ -983,10 +984,8 @@ private void moveVehicle() { } } else { //Mounted vehicles don't do most motions, only a sub-set of them. - modifySpeedFactor(); world.beginProfiling("ApplyMotions", true); motionApplied.set(motion).scale(modifiedSpeedFactor); - modifySpeedFactor(); position.add(motionApplied); //Rotation for mounted connections aligns using orientation, not angle-deltas. orientation.set(rotation).convertToAngles(); @@ -1013,7 +1012,7 @@ private void modifySpeedFactor() {//Function used for modify speed factor for us } //get a sample of block blocks in front of vehicle - chunkGuardDirection.set(position.x + (motionApplied.x * 42), 1D, position.z + (motionApplied.z * 42)); + chunkGuardDirection.set(position.x + (motionApplied.x * 52), 1D, position.z + (motionApplied.z * 52)); //check for stat 1 is cached unloaded chunk present , 0 is no cached chunks. if(!chunkCacheStat){ From 8ba35c8af063556adf3af4e4c82998c16f049c64 Mon Sep 17 00:00:00 2001 From: Natsuka <79125581+Naxgeneral@users.noreply.github.com> Date: Mon, 2 Mar 2026 22:30:08 +0700 Subject: [PATCH 4/5] Update AEntityVehicleD_Moving.java Fine tune the code a little bit From 6cb49d1a91c89810e2a35129ccd641d4b03ca48b Mon Sep 17 00:00:00 2001 From: Natsuka <79125581+Naxgeneral@users.noreply.github.com> Date: Wed, 4 Mar 2026 22:56:43 +0700 Subject: [PATCH 5/5] Commented out section that force it to only work on server. i added this section just to make it only check by server side as i afraid of false detection or desync but it not work on SP at all so i comment it out --- .../entities/instances/AEntityVehicleD_Moving.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mccore/src/main/java/minecrafttransportsimulator/entities/instances/AEntityVehicleD_Moving.java b/mccore/src/main/java/minecrafttransportsimulator/entities/instances/AEntityVehicleD_Moving.java index b2c85dc46..2d7f31bc3 100644 --- a/mccore/src/main/java/minecrafttransportsimulator/entities/instances/AEntityVehicleD_Moving.java +++ b/mccore/src/main/java/minecrafttransportsimulator/entities/instances/AEntityVehicleD_Moving.java @@ -1007,9 +1007,9 @@ private void moveVehicle() { private void modifySpeedFactor() {//Function used for modify speed factor for use in moving vehicle no Clanker used so ask me for more info - if (world.isClient()) {//do not do this in client level + /*if (world.isClient()) {//do not do this in client level //commented this section as i wanted this to be only done on serverside but this backfire so hard as it not work in SP at all as i used to understnad that even in SP game still host local server for it return; - } + }*/ //get a sample of block blocks in front of vehicle chunkGuardDirection.set(position.x + (motionApplied.x * 52), 1D, position.z + (motionApplied.z * 52));