2023-08-06 04:33:18 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Sat, 21 Aug 2021 18:53:03 -0700
Subject: [PATCH] Only capture actual tree growth
2023-09-17 01:53:21 +02:00
diff --git a/src/main/java/net/minecraft/core/dispenser/DispenseItemBehavior.java b/src/main/java/net/minecraft/core/dispenser/DispenseItemBehavior.java
2024-01-16 19:27:39 +01:00
index 97cff1d1c92f3c06897c7ef5da612eca0ee49b2f..6e19de21b6bb643961afc1d5eced3e0d0d98a027 100644
2023-09-17 01:53:21 +02:00
--- a/src/main/java/net/minecraft/core/dispenser/DispenseItemBehavior.java
+++ b/src/main/java/net/minecraft/core/dispenser/DispenseItemBehavior.java
2024-01-02 19:29:53 +01:00
@@ -862,6 +862,7 @@ public interface DispenseItemBehavior {
2023-09-17 01:53:21 +02:00
if (!fertilizeEvent.isCancelled()) {
for (org.bukkit.block.BlockState blockstate : blocks) {
blockstate.update(true);
+ worldserver.checkCapturedTreeStateForObserverNotify(blockposition, (org.bukkit.craftbukkit.block.CraftBlockState) blockstate); // Paper - notify observers even if grow failed
}
}
2023-08-06 04:33:18 +02:00
}
2023-09-17 01:53:21 +02:00
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
2024-01-18 18:52:00 +01:00
index 734672b38bd9be4ff63d61febc141278f14d7065..74fb996f54783948ee1351f3d437666b4d462cba 100644
2023-09-17 01:53:21 +02:00
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
2023-12-06 17:34:54 +01:00
@@ -422,6 +422,7 @@ public final class ItemStack {
2023-09-17 01:53:21 +02:00
}
for (CraftBlockState blockstate : blocks) {
world.setBlock(blockstate.getPosition(),blockstate.getHandle(), blockstate.getFlag()); // SPIGOT-7248 - manual update to avoid physics where appropriate
+ world.checkCapturedTreeStateForObserverNotify(blockposition, blockstate); // Paper - notify observers even if grow failed
2024-01-15 12:38:39 +01:00
if (blockstate instanceof org.bukkit.craftbukkit.block.CapturedBlockState capturedBlockState) capturedBlockState.checkTreeBlockHack(); // Paper - Fix beehives generating from using bonemeal
2023-09-17 01:53:21 +02:00
}
entityhuman.awardStat(Stats.ITEM_USED.get(item)); // SPIGOT-7236 - award stat
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
2024-01-18 18:52:00 +01:00
index 7311a9a3b8c4b62b232ea54568c4090a8e121f26..03c43220425411e0a135e7d63df276c4571d23d0 100644
2023-09-17 01:53:21 +02:00
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
2024-01-13 21:31:02 +01:00
@@ -1898,4 +1898,14 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
2023-09-17 01:53:21 +02:00
return null;
2023-08-06 04:33:18 +02:00
}
2023-09-22 22:13:57 +02:00
// Paper end - optimize redstone (Alternate Current)
+ // Paper start - notify observers even if grow failed
2023-09-17 01:53:21 +02:00
+ public void checkCapturedTreeStateForObserverNotify(final BlockPos pos, final CraftBlockState craftBlockState) {
2024-01-13 21:31:02 +01:00
+ // notify observers if the block state is the same and the Y level equals the original y level (for mega trees)
+ // blocks at the same Y level with the same state can be assumed to be saplings which trigger observers regardless of if the
+ // tree grew or not
2024-01-16 19:27:39 +01:00
+ if (craftBlockState.getPosition().getY() == pos.getY() && this.getBlockState(craftBlockState.getPosition()) == craftBlockState.getHandle()) {
2023-09-17 01:53:21 +02:00
+ this.notifyAndUpdatePhysics(craftBlockState.getPosition(), null, craftBlockState.getHandle(), craftBlockState.getHandle(), craftBlockState.getHandle(), craftBlockState.getFlag(), 512);
2023-08-06 04:33:18 +02:00
+ }
+ }
2023-09-22 22:13:57 +02:00
+ // Paper end - notify observers even if grow failed
2023-08-06 04:33:18 +02:00
}
2023-09-17 01:53:21 +02:00
diff --git a/src/main/java/net/minecraft/world/level/block/SaplingBlock.java b/src/main/java/net/minecraft/world/level/block/SaplingBlock.java
2023-12-06 17:34:54 +01:00
index 7e6ee9c1ccef3eaa6b2edc39e414bd186426aee5..836c86104ed4f0d375330c9123af5d502efefa4d 100644
2023-09-17 01:53:21 +02:00
--- a/src/main/java/net/minecraft/world/level/block/SaplingBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/SaplingBlock.java
2023-12-06 17:34:54 +01:00
@@ -85,6 +85,7 @@ public class SaplingBlock extends BushBlock implements BonemealableBlock {
2023-09-17 01:53:21 +02:00
if (event == null || !event.isCancelled()) {
for (BlockState blockstate : blocks) {
blockstate.update(true);
+ world.checkCapturedTreeStateForObserverNotify(pos, (org.bukkit.craftbukkit.block.CraftBlockState) blockstate); // Paper - notify observers even if grow failed
}
}
}
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
2023-12-06 17:34:54 +01:00
index 0a96b00a98227714ef99005e0a223765feae8fe9..e5506a7d074a9f89d41f4d5d7549a458779bef20 100644
2023-09-17 01:53:21 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
2023-12-06 17:34:54 +01:00
@@ -566,6 +566,7 @@ public class CraftBlock implements Block {
2023-09-17 01:53:21 +02:00
if (!event.isCancelled()) {
for (BlockState blockstate : blocks) {
blockstate.update(true);
+ world.checkCapturedTreeStateForObserverNotify(this.position, (org.bukkit.craftbukkit.block.CraftBlockState) blockstate); // Paper - notify observers even if grow failed
}
}
}