mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-01 12:41:50 +01:00
c5a10665b8
Spigot still maintains some partial implementation of "tick skipping", a practice in which the MinecraftServer.currentTick field is updated not by an increment of one per actual tick, but instead set to System.currentTimeMillis() / 50. This behaviour means that the tracked tick may "skip" a tick value in case a previous tick took more than the expected 50ms. To compensate for this in important paths, spigot/craftbukkit implements "wall-time". Instead of incrementing/decrementing ticks on block entities/entities by one for each call to their tick() method, they instead increment/decrement important values, like an ItemEntity's age or pickupDelay, by the difference of `currentTick - lastTick`, where `lastTick` is the value of `currentTick` during the last tick() call. These "fixes" however do not play nicely with minecraft's simulation distance as entities/block entities implementing the above behaviour would "catch up" their values when moving from a non-ticking chunk to a ticking one as their `lastTick` value remains stuck on the last tick in a ticking chunk and hence lead to a large "catch up" once ticked again. Paper completely removes the "tick skipping" behaviour (See patch "Further-improve-server-tick-loop"), making the above precautions completely unnecessary, which also rids paper of the previous described incompatibility with non-ticking chunks.
39 lines
2.7 KiB
Diff
39 lines
2.7 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Nassim Jahnke <nassim@njahnke.dev>
|
|
Date: Fri, 7 Jan 2022 11:45:15 +0100
|
|
Subject: [PATCH] Reset placed block on exception
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/item/BlockItem.java b/src/main/java/net/minecraft/world/item/BlockItem.java
|
|
index cee3f1200af602b5dfd0b27d05eb01826c5bbb1d..7d76cdc59984b156628273c8357485eb10046007 100644
|
|
--- a/src/main/java/net/minecraft/world/item/BlockItem.java
|
|
+++ b/src/main/java/net/minecraft/world/item/BlockItem.java
|
|
@@ -77,6 +77,7 @@ public class BlockItem extends Item {
|
|
if (this instanceof PlaceOnWaterBlockItem || this instanceof SolidBucketItem) {
|
|
blockstate = org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(blockactioncontext1.getLevel(), blockactioncontext1.getClickedPos());
|
|
}
|
|
+ final org.bukkit.block.BlockState oldBlockstate = blockstate != null ? blockstate : org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(blockactioncontext1.getLevel(), blockactioncontext1.getClickedPos()); // Paper - Reset placed block on exception
|
|
// CraftBukkit end
|
|
|
|
if (iblockdata == null) {
|
|
@@ -92,8 +93,20 @@ public class BlockItem extends Item {
|
|
|
|
if (iblockdata1.is(iblockdata.getBlock())) {
|
|
iblockdata1 = this.updateBlockStateFromTag(blockposition, world, itemstack, iblockdata1);
|
|
+ // Paper start - Reset placed block on exception
|
|
+ try {
|
|
this.updateCustomBlockEntityTag(blockposition, world, entityhuman, itemstack, iblockdata1);
|
|
BlockItem.updateBlockEntityComponents(world, blockposition, itemstack);
|
|
+ } catch (Exception e) {
|
|
+ oldBlockstate.update(true, false);
|
|
+ if (entityhuman instanceof ServerPlayer player) {
|
|
+ org.apache.logging.log4j.LogManager.getLogger().error("Player {} tried placing invalid block", player.getScoreboardName(), e);
|
|
+ player.getBukkitEntity().kickPlayer("Packet processing error");
|
|
+ return InteractionResult.FAIL;
|
|
+ }
|
|
+ throw e; // Rethrow exception if not placed by a player
|
|
+ }
|
|
+ // Paper end - Reset placed block on exception
|
|
iblockdata1.getBlock().setPlacedBy(world, blockposition, iblockdata1, entityhuman, itemstack);
|
|
// CraftBukkit start
|
|
if (blockstate != null) {
|