mirror of
https://github.com/BX-Team/DivineMC.git
synced 2025-12-19 14:59:25 +00:00
Upstream has released updates that appear to apply and compile correctly Purpur Changes: PurpurMC/Purpur@c8a4f0b6 Updated Upstream (Paper) PurpurMC/Purpur@e8fe8ece forgot to commit this PurpurMC/Purpur@45bc9f41 Updated Upstream (Paper)
336 lines
18 KiB
Diff
336 lines
18 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
|
|
Date: Sat, 1 Feb 2025 18:38:26 +0300
|
|
Subject: [PATCH] Lag compensation
|
|
|
|
|
|
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
|
|
index f9d60a28763e2c45b5dcf9687b8999fb73817aa9..3de2d76bf118750932a56d02233e4e6aff0b2728 100644
|
|
--- a/net/minecraft/server/MinecraftServer.java
|
|
+++ b/net/minecraft/server/MinecraftServer.java
|
|
@@ -287,6 +287,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
public static final long SERVER_INIT = System.nanoTime(); // Paper - Lag compensation
|
|
public boolean lagging = false; // Purpur - Lagging threshold
|
|
protected boolean upnp = false; // Purpur - UPnP Port Forwarding
|
|
+ public final org.bxteam.divinemc.util.tps.TPSCalculator tpsCalculator = new org.bxteam.divinemc.util.tps.TPSCalculator(); // DivineMC - Lag compensation
|
|
// Paper start - improve tick loop
|
|
public final ca.spottedleaf.moonrise.common.time.TickData tickTimes1s = new ca.spottedleaf.moonrise.common.time.TickData(java.util.concurrent.TimeUnit.SECONDS.toNanos(1L));
|
|
public final ca.spottedleaf.moonrise.common.time.TickData tickTimes5s = new ca.spottedleaf.moonrise.common.time.TickData(java.util.concurrent.TimeUnit.SECONDS.toNanos(5L));
|
|
@@ -1598,6 +1599,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
}
|
|
|
|
this.server.spark.tickStart(); // Paper - spark
|
|
+ this.tpsCalculator.doTick(); // DivineMC - Lag compenstation
|
|
new com.destroystokyo.paper.event.server.ServerTickStartEvent(this.tickCount+1).callEvent(); // Paper - Server Tick Events
|
|
this.tickCount++;
|
|
this.tickRateManager.tick();
|
|
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
|
|
index 7766bc8f3d1de6e33c2ab9256b71c30624872a2a..e6e54f23e302292aa9e9495c00aaae22cf18dd94 100644
|
|
--- a/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/net/minecraft/server/level/ServerLevel.java
|
|
@@ -224,6 +224,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
private final alternate.current.wire.WireHandler wireHandler = new alternate.current.wire.WireHandler(this); // Paper - optimize redstone (Alternate Current)
|
|
public boolean hasRidableMoveEvent = false; // Purpur - Ridables
|
|
public net.minecraft.world.item.ItemStack ominousBanner; // DivineMC - Optimize Raids
|
|
+ public org.bxteam.divinemc.util.tps.TPSCalculator tpsCalculator = new org.bxteam.divinemc.util.tps.TPSCalculator(); // DivineMC - Lag Compensation
|
|
|
|
@Override
|
|
public @Nullable LevelChunk getChunkIfLoaded(int x, int z) {
|
|
@@ -787,6 +788,8 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
}
|
|
}
|
|
|
|
+ this.tpsCalculator.doTick(); // DivineMC - Lag compensation
|
|
+
|
|
this.updateSkyBrightness();
|
|
if (runsNormally) {
|
|
this.tickTime();
|
|
@@ -880,11 +883,18 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
this.setDayTime(this.preciseTime);
|
|
} else
|
|
// Purpur end - Configurable daylight cycle
|
|
- this.setDayTime(this.levelData.getDayTime() + 1L);
|
|
+ this.setDayTime(lagCompensation(this.levelData.getDayTime()) + 1L); // DivineMC - Lag compensation
|
|
}
|
|
}
|
|
}
|
|
|
|
+ // DivineMC start - Lag compensation
|
|
+ private long lagCompensation(long original) {
|
|
+ if (!org.bxteam.divinemc.config.DivineConfig.MiscCategory.lagCompensationEnabled || !org.bxteam.divinemc.config.DivineConfig.MiscCategory.timeAcceleration) return original;
|
|
+ return original + this.tpsCalculator.applicableMissedTicks();
|
|
+ }
|
|
+ // DivineMC end - Lag compensation
|
|
+
|
|
public void setDayTime(long time) {
|
|
this.serverLevelData.setDayTime(time);
|
|
// Purpur start - Configurable daylight cycle
|
|
diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java
|
|
index 509689bfffbe7b376ce3c4f9851342242ae3bab2..f15497ef868574ee2fe11611bfc31d9b102f80d0 100644
|
|
--- a/net/minecraft/world/entity/LivingEntity.java
|
|
+++ b/net/minecraft/world/entity/LivingEntity.java
|
|
@@ -525,6 +525,7 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin
|
|
}
|
|
}
|
|
|
|
+ lagCompensation(); // DivineMC - Lag Compensation
|
|
this.tickEffects();
|
|
this.yHeadRotO = this.yHeadRot;
|
|
this.yBodyRotO = this.yBodyRot;
|
|
@@ -532,6 +533,17 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin
|
|
this.xRotO = this.getXRot();
|
|
}
|
|
|
|
+ // DivineMC start - Lag Compensation
|
|
+ private void lagCompensation() {
|
|
+ if (!org.bxteam.divinemc.config.DivineConfig.MiscCategory.lagCompensationEnabled || !org.bxteam.divinemc.config.DivineConfig.MiscCategory.potionEffectAcceleration) return;
|
|
+ if (this.level().isClientSide()) return;
|
|
+
|
|
+ for (int i = 0; i < ((ServerLevel) this.level()).tpsCalculator.applicableMissedTicks(); i++) {
|
|
+ tickEffects();
|
|
+ }
|
|
+ }
|
|
+ // DivineMC end - Lag Compensation
|
|
+
|
|
protected boolean shouldTakeDrowningDamage() {
|
|
return this.getAirSupply() <= -this.level().purpurConfig.drowningDamageInterval; // Purpur - Drowning Settings
|
|
}
|
|
diff --git a/net/minecraft/world/entity/PortalProcessor.java b/net/minecraft/world/entity/PortalProcessor.java
|
|
index 88b07fbb96b20124777889830afa480673629d43..91f6d43b3785ddad7db8eb529ba3293c45f3588d 100644
|
|
--- a/net/minecraft/world/entity/PortalProcessor.java
|
|
+++ b/net/minecraft/world/entity/PortalProcessor.java
|
|
@@ -24,10 +24,20 @@ public class PortalProcessor {
|
|
return false;
|
|
} else {
|
|
this.insidePortalThisTick = false;
|
|
- return canChangeDimensions && this.portalTime++ >= this.portal.getPortalTransitionTime(level, entity);
|
|
+ return canChangeDimensions && lagCompensation(this.portalTime++, level) >= this.portal.getPortalTransitionTime(level, entity); // DivineMC - Lag compensation
|
|
}
|
|
}
|
|
|
|
+ // DivineMC start - Lag compensation
|
|
+ private int lagCompensation(int original, ServerLevel world) {
|
|
+ if (!org.bxteam.divinemc.config.DivineConfig.MiscCategory.lagCompensationEnabled || !org.bxteam.divinemc.config.DivineConfig.MiscCategory.portalAcceleration) return original;
|
|
+ if (world.isClientSide()) return original;
|
|
+
|
|
+ portalTime = portalTime + world.tpsCalculator.applicableMissedTicks();
|
|
+ return portalTime;
|
|
+ }
|
|
+ // DivineMC end - Lag compensation
|
|
+
|
|
@Nullable
|
|
public TeleportTransition getPortalDestination(ServerLevel level, Entity entity) {
|
|
return this.portal.getPortalDestination(level, entity, this.entryPosition);
|
|
diff --git a/net/minecraft/world/entity/item/ItemEntity.java b/net/minecraft/world/entity/item/ItemEntity.java
|
|
index 8153c870c0c822792ffbb0fa1ae96b201a1444e3..7525184fd5a801e39fbcba2afbcc968862a1cfbb 100644
|
|
--- a/net/minecraft/world/entity/item/ItemEntity.java
|
|
+++ b/net/minecraft/world/entity/item/ItemEntity.java
|
|
@@ -149,8 +149,25 @@ public class ItemEntity extends Entity implements TraceableEntity {
|
|
}
|
|
// Paper end - EAR 2
|
|
|
|
+ // DivineMC start - Lag compensation
|
|
+ private void lagCompensation() {
|
|
+ if (!org.bxteam.divinemc.config.DivineConfig.MiscCategory.lagCompensationEnabled || !org.bxteam.divinemc.config.DivineConfig.MiscCategory.pickupAcceleration) return;
|
|
+ if ((this).level().isClientSide()) return;
|
|
+
|
|
+ if (pickupDelay == 0) return;
|
|
+
|
|
+ if (pickupDelay - ((ServerLevel) this.level()).tpsCalculator.applicableMissedTicks() <= 0) {
|
|
+ pickupDelay = 0;
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ pickupDelay = pickupDelay - ((ServerLevel) this.level()).tpsCalculator.applicableMissedTicks();
|
|
+ }
|
|
+ // DivineMC end - Lag compensation
|
|
+
|
|
@Override
|
|
public void tick() {
|
|
+ lagCompensation(); // DivineMC - Lag compensation
|
|
if (this.getItem().isEmpty()) {
|
|
this.discard(org.bukkit.event.entity.EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
|
|
} else {
|
|
diff --git a/net/minecraft/world/item/Item.java b/net/minecraft/world/item/Item.java
|
|
index 5305b72c37ba0fcde811d46e781fb4c74817da52..fbae6ab5d5a999039ae8d67cd3df193ed5eec5d9 100644
|
|
--- a/net/minecraft/world/item/Item.java
|
|
+++ b/net/minecraft/world/item/Item.java
|
|
@@ -286,10 +286,25 @@ public class Item implements FeatureElement, ItemLike {
|
|
}
|
|
}
|
|
|
|
+ // DivineMC start - Lag compensation
|
|
+ private int lagCompensation(int original, net.minecraft.server.level.ServerLevel level) {
|
|
+ if (!org.bxteam.divinemc.config.DivineConfig.MiscCategory.lagCompensationEnabled || !org.bxteam.divinemc.config.DivineConfig.MiscCategory.eatingAcceleration || original == 0) return original;
|
|
+ return org.bxteam.divinemc.util.tps.TPSUtil.tt20(original, true, level);
|
|
+ }
|
|
+ // DivineMC end - Lag compensation
|
|
+
|
|
public int getUseDuration(ItemStack stack, LivingEntity entity) {
|
|
Consumable consumable = stack.get(DataComponents.CONSUMABLE);
|
|
if (consumable != null) {
|
|
- return consumable.consumeTicks();
|
|
+ // DivineMC start - Lag compensation
|
|
+ int original = consumable.consumeTicks();
|
|
+
|
|
+ if (entity.level() instanceof net.minecraft.server.level.ServerLevel serverLevel) {
|
|
+ return lagCompensation(original, serverLevel);
|
|
+ }
|
|
+
|
|
+ return original;
|
|
+ // DivineMC end - Lag compensation
|
|
} else {
|
|
BlocksAttacks blocksAttacks = stack.get(DataComponents.BLOCKS_ATTACKS);
|
|
return blocksAttacks != null ? 72000 : 0;
|
|
diff --git a/net/minecraft/world/level/GameRules.java b/net/minecraft/world/level/GameRules.java
|
|
index dbd3813cb0328b7b73c9b634b1b19be7ee3246f6..9b72f3266e3a7cf6bd934d2497f0c5332c09ae59 100644
|
|
--- a/net/minecraft/world/level/GameRules.java
|
|
+++ b/net/minecraft/world/level/GameRules.java
|
|
@@ -377,8 +377,31 @@ public class GameRules {
|
|
}
|
|
|
|
public int getInt(GameRules.Key<GameRules.IntegerValue> key) {
|
|
- return this.getRule(key).get();
|
|
+ return lagCompensation(this.getRule(key).get(), key); // DivineMC - Lag compensation
|
|
+ }
|
|
+
|
|
+ // DivineMC start - Lag compensation
|
|
+ private final java.util.concurrent.atomic.AtomicReference<net.minecraft.server.level.ServerLevel> level = new java.util.concurrent.atomic.AtomicReference<>();
|
|
+
|
|
+ private int lagCompensation(int original, GameRules.Key<GameRules.IntegerValue> rule) {
|
|
+ net.minecraft.server.level.ServerLevel level = getOrCacheLevel();
|
|
+ if (!org.bxteam.divinemc.config.DivineConfig.MiscCategory.lagCompensationEnabled || !org.bxteam.divinemc.config.DivineConfig.MiscCategory.randomTickSpeedAcceleration) return original;
|
|
+ if (!(rule == GameRules.RULE_RANDOMTICKING)) return original;
|
|
+ return (int) (original * org.bxteam.divinemc.util.tps.TPSCalculator.MAX_TPS / (float) level.tpsCalculator.getMostAccurateTPS());
|
|
+ }
|
|
+
|
|
+ private net.minecraft.server.level.ServerLevel getOrCacheLevel() {
|
|
+ if (level.get() == null) {
|
|
+ for (final net.minecraft.server.level.ServerLevel level : MinecraftServer.getServer().getAllLevels()) {
|
|
+ if (level.getGameRules() == this) {
|
|
+ this.level.set(level);
|
|
+ break;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ return level.get();
|
|
}
|
|
+ // DivineMC end - Lag compensation
|
|
|
|
public static class BooleanValue extends GameRules.Value<GameRules.BooleanValue> {
|
|
private boolean value;
|
|
diff --git a/net/minecraft/world/level/block/state/BlockBehaviour.java b/net/minecraft/world/level/block/state/BlockBehaviour.java
|
|
index 00ca563d6bfbe6182dc246d5f6ffca7fc9a5ba85..611b29ccba29558d8cf54eccb2136a305bf989db 100644
|
|
--- a/net/minecraft/world/level/block/state/BlockBehaviour.java
|
|
+++ b/net/minecraft/world/level/block/state/BlockBehaviour.java
|
|
@@ -350,13 +350,21 @@ public abstract class BlockBehaviour implements FeatureElement {
|
|
protected void tick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) {
|
|
}
|
|
|
|
+ // DivineMC start - Lag compensation
|
|
+ private float lagCompensation(float original, Player player) {
|
|
+ if (!org.bxteam.divinemc.config.DivineConfig.MiscCategory.lagCompensationEnabled || !org.bxteam.divinemc.config.DivineConfig.MiscCategory.blockBreakingAcceleration) return original;
|
|
+ if (player.level().isClientSide) return original;
|
|
+ return original * org.bxteam.divinemc.util.tps.TPSCalculator.MAX_TPS / (float) ((ServerLevel) player.level()).tpsCalculator.getMostAccurateTPS();
|
|
+ }
|
|
+ // DivineMC end - Lag compensation
|
|
+
|
|
protected float getDestroyProgress(BlockState state, Player player, BlockGetter level, BlockPos pos) {
|
|
float destroySpeed = state.getDestroySpeed(level, pos);
|
|
if (destroySpeed == -1.0F) {
|
|
- return 0.0F;
|
|
+ return lagCompensation(0.0F, player); // DivineMC - Lag compensation
|
|
} else {
|
|
int i = player.hasCorrectToolForDrops(state) ? 30 : 100;
|
|
- return player.getDestroySpeed(state) / destroySpeed / i;
|
|
+ return lagCompensation(player.getDestroySpeed(state) / destroySpeed / i, player); // DivineMC - Lag compensation
|
|
}
|
|
}
|
|
|
|
diff --git a/net/minecraft/world/level/chunk/LevelChunk.java b/net/minecraft/world/level/chunk/LevelChunk.java
|
|
index 84bc3ed25a30ede18f66859129dacd73d6837d1f..524f987ba5cbf3d9fa502b51419cb163e099597c 100644
|
|
--- a/net/minecraft/world/level/chunk/LevelChunk.java
|
|
+++ b/net/minecraft/world/level/chunk/LevelChunk.java
|
|
@@ -957,6 +957,19 @@ public class LevelChunk extends ChunkAccess implements DebugValueSource, ca.spot
|
|
this.ticker = ticker;
|
|
}
|
|
|
|
+ // DivineMC start - Lag compensation
|
|
+ private <T extends BlockEntity> void lagCompensation(Runnable original) {
|
|
+ original.run();
|
|
+ if (!org.bxteam.divinemc.config.DivineConfig.MiscCategory.lagCompensationEnabled) return;
|
|
+ if (!org.bxteam.divinemc.config.DivineConfig.MiscCategory.blockEntityAcceleration) return;
|
|
+ if (LevelChunk.this.level.isClientSide()) return;
|
|
+
|
|
+ for (int i = 0; i < ((ServerLevel) this.blockEntity.getLevel()).tpsCalculator.applicableMissedTicks(); i++) {
|
|
+ original.run();
|
|
+ }
|
|
+ }
|
|
+ // DivineMC end - Lag compensation
|
|
+
|
|
@Override
|
|
public void tick() {
|
|
if (!this.blockEntity.isRemoved() && this.blockEntity.hasLevel()) {
|
|
@@ -967,7 +980,11 @@ public class LevelChunk extends ChunkAccess implements DebugValueSource, ca.spot
|
|
profilerFiller.push(this::getType);
|
|
BlockState blockState = LevelChunk.this.getBlockState(blockPos);
|
|
if (this.blockEntity.getType().isValid(blockState)) {
|
|
- this.ticker.tick(LevelChunk.this.level, this.blockEntity.getBlockPos(), blockState, this.blockEntity);
|
|
+ // DivineMC start - Lag compensation
|
|
+ lagCompensation(() -> {
|
|
+ this.ticker.tick(LevelChunk.this.level, this.blockEntity.getBlockPos(), blockState, this.blockEntity);
|
|
+ });
|
|
+ // DivineMC end - Lag compensation
|
|
this.loggedInvalidBlockState = false;
|
|
// Paper start - Remove the Block Entity if it's invalid
|
|
} else {
|
|
diff --git a/net/minecraft/world/level/material/LavaFluid.java b/net/minecraft/world/level/material/LavaFluid.java
|
|
index 2d845b09abe3354f0999b117e78ffd00c41e8924..9630a1fd95853671812c3249f32a8a1e3a05f7ab 100644
|
|
--- a/net/minecraft/world/level/material/LavaFluid.java
|
|
+++ b/net/minecraft/world/level/material/LavaFluid.java
|
|
@@ -188,9 +188,22 @@ public abstract class LavaFluid extends FlowingFluid {
|
|
return fluidState.getHeight(level, pos) >= 0.44444445F && fluid.is(FluidTags.WATER);
|
|
}
|
|
|
|
+ // DivineMC start - Lag compensation
|
|
+ private int lagCompensation(int original, ServerLevel level) {
|
|
+ if (!org.bxteam.divinemc.config.DivineConfig.MiscCategory.lagCompensationEnabled || !org.bxteam.divinemc.config.DivineConfig.MiscCategory.fluidAcceleration) return original;
|
|
+ return org.bxteam.divinemc.util.tps.TPSUtil.tt20(original, true, level);
|
|
+ }
|
|
+ // DivineMC end - Lag compensation
|
|
+
|
|
@Override
|
|
public int getTickDelay(LevelReader level) {
|
|
- return level.dimensionType().ultraWarm() ? level.getWorldBorder().world.purpurConfig.lavaSpeedNether : level.getWorldBorder().world.purpurConfig.lavaSpeedNotNether; // Purpur - Make lava flow speed configurable
|
|
+ // DivineMC start - Lag compensation
|
|
+ int original = level.dimensionType().ultraWarm() ? level.getWorldBorder().world.purpurConfig.lavaSpeedNether : level.getWorldBorder().world.purpurConfig.lavaSpeedNotNether; // Purpur - Make lava flow speed configurable
|
|
+ if (level instanceof ServerLevel serverLevel) {
|
|
+ return lagCompensation(original, serverLevel);
|
|
+ }
|
|
+ return original;
|
|
+ // DivineMC end - Lag compensation
|
|
}
|
|
|
|
@Override
|
|
diff --git a/net/minecraft/world/level/material/WaterFluid.java b/net/minecraft/world/level/material/WaterFluid.java
|
|
index 19505eafb8b3aa09d7f889ecb62bcc28d835b4c8..790dcd8e71fc2e102a4aeae28b3a4a24680401ae 100644
|
|
--- a/net/minecraft/world/level/material/WaterFluid.java
|
|
+++ b/net/minecraft/world/level/material/WaterFluid.java
|
|
@@ -124,8 +124,16 @@ public abstract class WaterFluid extends FlowingFluid {
|
|
return 1;
|
|
}
|
|
|
|
+ // DivineMC start - Lag compensation
|
|
+ private int lagCompensation(ServerLevel level) {
|
|
+ if (!org.bxteam.divinemc.config.DivineConfig.MiscCategory.lagCompensationEnabled || !org.bxteam.divinemc.config.DivineConfig.MiscCategory.fluidAcceleration) return 5;
|
|
+ return org.bxteam.divinemc.util.tps.TPSUtil.tt20(5, true, level);
|
|
+ }
|
|
+ // DivineMC end - Lag compensation
|
|
+
|
|
@Override
|
|
public int getTickDelay(LevelReader level) {
|
|
+ if (level instanceof ServerLevel serverLevel) return lagCompensation(serverLevel); // DivineMC - Lag compensation
|
|
return 5;
|
|
}
|
|
|