mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-29 11:42:55 +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.
95 lines
5.1 KiB
Diff
95 lines
5.1 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
Date: Thu, 2 Jan 2020 12:25:07 -0600
|
|
Subject: [PATCH] Improve Block#breakNaturally API
|
|
|
|
Adds bool parameter to play world effect on block break
|
|
|
|
Adds bool parameter to drop xp from blocks
|
|
|
|
Fixes fluid-logged blocks not leaving fluid behind if
|
|
broken
|
|
|
|
Handles special cases for ice and turtle eggs
|
|
|
|
== AT ==
|
|
public net.minecraft.world.level.block.TurtleEggBlock decreaseEggs(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)V
|
|
|
|
Co-authored-by: William Blake Galbreath <Blake.Galbreath@GMail.com>
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/IceBlock.java b/src/main/java/net/minecraft/world/level/block/IceBlock.java
|
|
index 363dd6ab9c7b650913795ef350374d5c4e7e4925..e862814c1e54776f11050623b52476accc2f1f79 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/IceBlock.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/IceBlock.java
|
|
@@ -35,6 +35,11 @@ public class IceBlock extends HalfTransparentBlock {
|
|
@Override
|
|
public void playerDestroy(Level world, Player player, BlockPos pos, BlockState state, @Nullable BlockEntity blockEntity, ItemStack tool) {
|
|
super.playerDestroy(world, player, pos, state, blockEntity, tool);
|
|
+ // Paper start - Improve Block#breakNaturally API
|
|
+ this.afterDestroy(world, pos, tool);
|
|
+ }
|
|
+ public void afterDestroy(Level world, BlockPos pos, ItemStack tool) {
|
|
+ // Paper end - Improve Block#breakNaturally API
|
|
if (!EnchantmentHelper.hasTag(tool, EnchantmentTags.PREVENTS_ICE_MELTING)) {
|
|
if (world.dimensionType().ultraWarm()) {
|
|
world.removeBlock(pos, false);
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
|
index d4e14ac1514e2d8b87b4667a91c90eded3ba6636..f041b5d80bff9c022b007e04ef1558e9116acc6b 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
|
@@ -452,6 +452,18 @@ public class CraftBlock implements Block {
|
|
|
|
@Override
|
|
public boolean breakNaturally(ItemStack item) {
|
|
+ // Paper start
|
|
+ return this.breakNaturally(item, false);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean breakNaturally(boolean triggerEffect, boolean dropExperience) {
|
|
+ return this.breakNaturally(null, triggerEffect, dropExperience);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean breakNaturally(ItemStack item, boolean triggerEffect, boolean dropExperience) {
|
|
+ // Paper end
|
|
// Order matters here, need to drop before setting to air so skulls can get their data
|
|
net.minecraft.world.level.block.state.BlockState iblockdata = this.getNMS();
|
|
net.minecraft.world.level.block.Block block = iblockdata.getBlock();
|
|
@@ -461,11 +473,35 @@ public class CraftBlock implements Block {
|
|
// Modelled off EntityHuman#hasBlock
|
|
if (block != Blocks.AIR && (item == null || !iblockdata.requiresCorrectToolForDrops() || nmsItem.isCorrectToolForDrops(iblockdata))) {
|
|
net.minecraft.world.level.block.Block.dropResources(iblockdata, this.world.getMinecraftWorld(), this.position, this.world.getBlockEntity(this.position), null, nmsItem);
|
|
+ // Paper start - improve Block#breanNaturally
|
|
+ if (triggerEffect) {
|
|
+ if (iblockdata.getBlock() instanceof net.minecraft.world.level.block.BaseFireBlock) {
|
|
+ this.world.levelEvent(net.minecraft.world.level.block.LevelEvent.SOUND_EXTINGUISH_FIRE, this.position, 0);
|
|
+ } else {
|
|
+ this.world.levelEvent(net.minecraft.world.level.block.LevelEvent.PARTICLES_DESTROY_BLOCK, this.position, net.minecraft.world.level.block.Block.getId(iblockdata));
|
|
+ }
|
|
+ }
|
|
+ if (dropExperience) block.popExperience(this.world.getMinecraftWorld(), this.position, block.getExpDrop(iblockdata, this.world.getMinecraftWorld(), this.position, nmsItem, true));
|
|
+ // Paper end
|
|
result = true;
|
|
}
|
|
|
|
// SPIGOT-6778: Directly call setBlock instead of setTypeAndData, so that the tile entiy is not removed and custom remove logic is run.
|
|
- return this.world.setBlock(this.position, Blocks.AIR.defaultBlockState(), 3) && result;
|
|
+ // Paper start - improve breakNaturally
|
|
+ boolean destroyed = this.world.removeBlock(this.position, false);
|
|
+ if (destroyed) {
|
|
+ block.destroy(this.world, this.position, iblockdata);
|
|
+ }
|
|
+ if (result) {
|
|
+ // special cases
|
|
+ if (block instanceof net.minecraft.world.level.block.IceBlock iceBlock) {
|
|
+ iceBlock.afterDestroy(this.world.getMinecraftWorld(), this.position, nmsItem);
|
|
+ } else if (block instanceof net.minecraft.world.level.block.TurtleEggBlock turtleEggBlock) {
|
|
+ turtleEggBlock.decreaseEggs(this.world.getMinecraftWorld(), this.position, iblockdata);
|
|
+ }
|
|
+ }
|
|
+ return destroyed && result;
|
|
+ // Paper end
|
|
}
|
|
|
|
@Override
|