1
0
Fork 0
mirror of https://github.com/PaperMC/Paper.git synced 2025-03-28 09:17:21 +01:00

Add lag compensation for breaking blocks

This commit is contained in:
Spottedleaf 2023-09-23 22:10:40 -07:00
parent 38dc3b25d8
commit 84556f3cda
592 changed files with 160 additions and 104 deletions
patches/server
0339-Lag-compensate-eating.patch0339-Tracking-Range-Improvements.patch0340-Fix-items-vanishing-through-end-portal.patch0341-implement-optional-per-player-mob-spawns.patch0342-Anti-Xray.patch0343-Bees-get-gravity-in-void.-Fixes-MC-167279.patch0344-Improve-Block-breakNaturally-API.patch0345-Optimise-getChunkAt-calls-for-loaded-chunks.patch0346-Add-debug-for-sync-chunk-loads.patch0347-Improve-java-version-check.patch0348-Add-ThrownEggHatchEvent.patch0349-Entity-Jump-API.patch0350-Add-option-to-nerf-pigmen-from-nether-portals.patch0351-Make-the-GUI-graph-fancier.patch0352-add-hand-to-BlockMultiPlaceEvent.patch0353-Validate-tripwire-hook-placement-before-update.patch0354-Add-option-to-allow-iron-golems-to-spawn-in-air.patch0355-Configurable-chance-of-villager-zombie-infection.patch0356-Optimise-Chunk-getFluid.patch0357-Set-spigots-verbose-world-setting-to-false-by-def.patch0358-Add-tick-times-API-and-mspt-command.patch0359-Expose-MinecraftServer-isRunning.patch0360-Add-Raw-Byte-ItemStack-Serialization.patch0361-Pillager-patrol-spawn-settings-and-per-player-option.patch0362-Remote-Connections-shouldn-t-hold-up-shutdown.patch0363-Do-not-allow-bees-to-load-chunks-for-beehives.patch0364-Prevent-Double-PlayerChunkMap-adds-crashing-server.patch0365-Don-t-tick-dead-players.patch0366-Dead-Player-s-shouldn-t-be-able-to-move.patch0367-Optimize-Collision-to-not-load-chunks.patch0368-Don-t-move-existing-players-to-world-spawn.patch0369-Optimize-GoalSelector-Goal.Flag-Set-operations.patch0370-Improved-Watchdog-Support.patch0371-Optimize-Pathfinding.patch0372-Reduce-Either-Optional-allocation.patch0373-Reduce-memory-footprint-of-NBTTagCompound.patch0374-Prevent-opening-inventories-when-frozen.patch0375-Don-t-run-entity-collision-code-if-not-needed.patch0376-Implement-Player-Client-Options-API.patch0377-Don-t-crash-if-player-is-attempted-to-be-removed-fro.patch0378-Fix-Longstanding-Broken-behavior-of-PlayerJoinEvent.patch0379-Move-player-to-spawn-point-if-spawn-in-unloaded-worl.patch0380-Add-PlayerAttackEntityCooldownResetEvent.patch0381-Don-t-fire-BlockFade-on-worldgen-threads.patch0382-Add-phantom-creative-and-insomniac-controls.patch0383-Fix-numerous-item-duplication-issues-and-teleport-is.patch0384-Villager-Restocks-API.patch0385-Validate-PickItem-Packet-and-kick-for-invalid.patch0386-Expose-game-version.patch0387-Optimize-Voxel-Shape-Merging.patch0388-Set-cap-on-JDK-per-thread-native-byte-buffer-cache.patch0389-misc-debugging-dumps.patch0390-Prevent-teleporting-dead-entities.patch0391-Deobfuscate-stacktraces-in-log-messages-crash-report.patch0392-Implement-Mob-Goal-API.patch0393-Add-villager-reputation-API.patch0394-Option-for-maximum-exp-value-when-merging-orbs.patch0395-ExperienceOrbMergeEvent.patch0396-Fix-PotionEffect-ignores-icon-flag.patch0397-Optimize-brigadier-child-sorting-performance.patch0398-Potential-bed-API.patch0399-Wait-for-Async-Tasks-during-shutdown.patch0400-Ensure-EntityRaider-respects-game-and-entity-rules-f.patch0401-Protect-Bedrock-and-End-Portal-Frames-from-being-des.patch0402-Ensure-safe-gateway-teleport.patch0403-Add-option-for-console-having-all-permissions.patch0404-Fix-villager-trading-demand-MC-163962.patch0405-Maps-shouldn-t-load-chunks.patch0406-Use-seed-based-lookup-for-Treasure-Maps-Fixes-lag-fr.patch0407-Fix-CraftScheduler-runTaskTimerAsynchronously-Plugin.patch0408-Fix-piston-physics-inconsistency-MC-188840.patch0409-Fix-sand-duping.patch0410-Fix-missing-chunks-due-to-integer-overflow.patch0411-Prevent-position-desync-in-playerconnection-causing-.patch0412-Inventory-getHolder-method-without-block-snapshot.patch0413-Improve-Arrow-API.patch0414-Add-and-implement-PlayerRecipeBookClickEvent.patch0415-Hide-sync-chunk-writes-behind-flag.patch0416-Add-permission-for-command-blocks.patch0417-Ensure-Entity-AABB-s-are-never-invalid.patch0418-Fix-Per-World-Difficulty-Remembering-Difficulty.patch0419-Paper-dumpitem-command.patch0420-Improve-Legacy-Component-serialization-size.patch0421-Optimize-Bit-Operations-by-inlining.patch0422-Add-Plugin-Tickets-to-API-Chunk-Methods.patch0423-incremental-chunk-and-player-saving.patch0424-Support-old-UUID-format-for-NBT.patch0425-Convert-legacy-attributes-in-Item-Meta.patch0426-Remove-some-streams-from-structures.patch0427-Remove-streams-from-classes-related-villager-gossip.patch0428-Support-components-in-ItemMeta.patch0429-Improve-fix-EntityTargetLivingEntityEvent.patch0430-Add-entity-liquid-API.patch0431-Update-itemstack-legacy-name-and-lore.patch0432-Spawn-player-in-correct-world-on-login.patch0433-Add-PrepareResultEvent.patch0434-Don-t-check-chunk-for-portal-on-world-gen-entity-add.patch0435-Fix-arrows-never-despawning-MC-125757.patch0436-Thread-Safe-Vanilla-Command-permission-checking.patch0437-Fix-SPIGOT-5989.patch

View file

@ -1,74 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Tue, 14 Jan 2020 15:28:28 -0800
Subject: [PATCH] Lag compensate eating
When the server is lagging, players will wait longer when eating.
Change to also use a time check instead if it passes.
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index ac59a1e5ae4fe84af44220d721b60f2e157e0f1f..ca179b062fa6142da584ad1a091e63d89403a0f0 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -3653,6 +3653,11 @@ public abstract class LivingEntity extends Entity implements Attackable {
return ((Byte) this.entityData.get(LivingEntity.DATA_LIVING_ENTITY_FLAGS) & 2) > 0 ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND;
}
+ // Paper start - lag compensate eating
+ protected long eatStartTime;
+ protected int totalEatTimeTicks;
+ // Paper end
+
private void updatingUsingItem() {
if (this.isUsingItem()) {
if (ItemStack.isSameItem(this.getItemInHand(this.getUsedItemHand()), this.useItem)) {
@@ -3671,7 +3676,12 @@ public abstract class LivingEntity extends Entity implements Attackable {
this.triggerItemUseEffects(stack, 5);
}
- if (--this.useItemRemaining == 0 && !this.level().isClientSide && !stack.useOnRelease()) {
+ // Paper start - lag compensate eating
+ // we add 1 to the expected time to avoid lag compensating when we should not
+ boolean shouldLagCompensate = this.useItem.getItem().isEdible() && this.eatStartTime != -1 && (System.nanoTime() - this.eatStartTime) > ((1 + this.totalEatTimeTicks) * 50 * (1000 * 1000));
+ if ((--this.useItemRemaining == 0 || shouldLagCompensate) && !this.level().isClientSide && !stack.useOnRelease()) {
+ this.useItemRemaining = 0;
+ // Paper end
this.completeUsingItem();
}
@@ -3719,7 +3729,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
if (!itemstack.isEmpty() && !this.isUsingItem() || forceUpdate) { // Paper use override flag
this.useItem = itemstack;
- this.useItemRemaining = itemstack.getUseDuration();
+ // Paper start - lag compensate eating
+ this.useItemRemaining = this.totalEatTimeTicks = itemstack.getUseDuration();
+ this.eatStartTime = System.nanoTime();
+ // Paper end
if (!this.level().isClientSide) {
this.setLivingEntityFlag(1, true);
this.setLivingEntityFlag(2, hand == InteractionHand.OFF_HAND);
@@ -3744,7 +3757,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
}
} else if (!this.isUsingItem() && !this.useItem.isEmpty()) {
this.useItem = ItemStack.EMPTY;
- this.useItemRemaining = 0;
+ // Paper start - lag compensate eating
+ this.useItemRemaining = this.totalEatTimeTicks = 0;
+ this.eatStartTime = -1L;
+ // Paper end
}
}
@@ -3877,7 +3893,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
}
this.useItem = ItemStack.EMPTY;
- this.useItemRemaining = 0;
+ // Paper start - lag compensate eating
+ this.useItemRemaining = this.totalEatTimeTicks = 0;
+ this.eatStartTime = -1L;
+ // Paper end
}
public boolean isBlocking() {

View file

@ -5,7 +5,7 @@ Subject: [PATCH] Entity Jump API
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index ca179b062fa6142da584ad1a091e63d89403a0f0..4008d402b01d7ea25a56d16ebbf00e182b0d60c3 100644
index ac59a1e5ae4fe84af44220d721b60f2e157e0f1f..81a64f4fc3e06ff9b32f91fc502809e0436d6e26 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -3284,8 +3284,10 @@ public abstract class LivingEntity extends Entity implements Attackable {

View file

@ -12,7 +12,7 @@ The entity's current team collision rule causes them to NEVER collide.
Co-authored-by: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 4008d402b01d7ea25a56d16ebbf00e182b0d60c3..d8c337ae968f04af8870591da6c89dc25b5db311 100644
index 81a64f4fc3e06ff9b32f91fc502809e0436d6e26..5fe5fef2e10944edc0c43da6e9d137e418c189c9 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -3399,10 +3399,24 @@ public abstract class LivingEntity extends Entity implements Attackable {

View file

@ -5,7 +5,7 @@ Subject: [PATCH] Add PlayerAttackEntityCooldownResetEvent
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index d8c337ae968f04af8870591da6c89dc25b5db311..29c5372f48211e86fa8cfbdea9e10025a4f310d1 100644
index 5fe5fef2e10944edc0c43da6e9d137e418c189c9..1f8c62aa221241c6532eb60e2c9b7344ef834b23 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -2196,7 +2196,16 @@ public abstract class LivingEntity extends Entity implements Attackable {

View file

@ -80,7 +80,7 @@ index eed16b541a9c39ed4697e783612e6f7b7ff23b70..1d2dd9b8ae43f22d875cb530130118df
public float getBlockExplosionResistance(Explosion explosion, BlockGetter world, BlockPos pos, BlockState blockState, FluidState fluidState, float max) {
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 29c5372f48211e86fa8cfbdea9e10025a4f310d1..a8f51cb5be994783eca8ff13eb172fd651deb05e 100644
index 1f8c62aa221241c6532eb60e2c9b7344ef834b23..655bd3b1ba3c2c02d70d41ae343c4aa97c3ce9a0 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -1711,9 +1711,9 @@ public abstract class LivingEntity extends Entity implements Attackable {

View file

@ -5,7 +5,7 @@ Subject: [PATCH] Don't check chunk for portal on world gen entity add
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index a8f51cb5be994783eca8ff13eb172fd651deb05e..4d9149d3a1d5711b88ce86fb34dbdc926cbe8c31 100644
index 655bd3b1ba3c2c02d70d41ae343c4aa97c3ce9a0..b80192d4d35cfb6ad155ac34b5296d689a154387 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -3511,7 +3511,7 @@ public abstract class LivingEntity extends Entity implements Attackable {

Some files were not shown because too many files have changed in this diff Show more