From 2754d7c3b92e8fe5b04fde42fc62fc44c7737bff Mon Sep 17 00:00:00 2001 From: Miles <81843550+Y2Kwastaken@users.noreply.github.com> Date: Wed, 30 Apr 2025 18:03:40 +0000 Subject: [PATCH] Add Throw EntityChangeBlockEvent for BrushableBlockEntity#brush (#12133) --- .../entity/BrushableBlockEntity.java.patch | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/paper-server/patches/sources/net/minecraft/world/level/block/entity/BrushableBlockEntity.java.patch b/paper-server/patches/sources/net/minecraft/world/level/block/entity/BrushableBlockEntity.java.patch index 6f3f6b65d..a71b4f55a 100644 --- a/paper-server/patches/sources/net/minecraft/world/level/block/entity/BrushableBlockEntity.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/level/block/entity/BrushableBlockEntity.java.patch @@ -1,5 +1,67 @@ --- a/net/minecraft/world/level/block/entity/BrushableBlockEntity.java +++ b/net/minecraft/world/level/block/entity/BrushableBlockEntity.java +@@ -65,9 +_,26 @@ + return false; + } else { + this.coolDownEndsAtTick = startTick + 10L; ++ // Paper start - EntityChangeBlockEvent ++ // The vanilla logic here is *so* backwards, we'd be moving basically *all* following calls down. ++ // Instead, compute vanilla ourselves up here and just replace the below usages with our computed values for a free diff-on-change. ++ final int currentCompletionStage = this.getCompletionState(); ++ final boolean enoughBrushesToBreak = ++this.brushCount >= REQUIRED_BRUSHES_TO_BREAK; ++ final int nextCompletionStage = this.getCompletionState(); ++ final boolean differentCompletionStages = currentCompletionStage != nextCompletionStage; ++ final BlockState nextBrokenBlockState = this.getBlockState().setValue(BlockStateProperties.DUSTED, nextCompletionStage); ++ if (enoughBrushesToBreak || differentCompletionStages) { ++ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent( ++ brusher, this.worldPosition, enoughBrushesToBreak ? computeTurnsTo().defaultBlockState() : nextBrokenBlockState ++ )) { ++ brushCount--; ++ return false; ++ } ++ } ++ // Paper end - EntityChangeBlockEvent + this.unpackLootTable(level, brusher, stack); +- int completionState = this.getCompletionState(); +- if (++this.brushCount >= 10) { ++ int completionState = currentCompletionStage; // Paper - EntityChangeBlockEvent - use precomputed - diff on change ++ if (enoughBrushesToBreak) { // Paper - EntityChangeBlockEvent - use precomputed - diff on change + this.brushingCompleted(level, brusher, stack); + return true; + } else { +@@ -75,7 +_,7 @@ + int completionState1 = this.getCompletionState(); + if (completionState != completionState1) { + BlockState blockState = this.getBlockState(); +- BlockState blockState1 = blockState.setValue(BlockStateProperties.DUSTED, completionState1); ++ BlockState blockState1 = nextBrokenBlockState; // Paper - EntityChangeBlockEvent - use precomputed - diff on change + level.setBlock(this.getBlockPos(), blockState1, 3); + } + +@@ -116,6 +_,11 @@ + this.dropContent(level, brusher, stack); + BlockState blockState = this.getBlockState(); + level.levelEvent(3008, this.getBlockPos(), Block.getId(blockState)); ++ // Paper start - EntityChangeEvent - extract result block logic ++ this.brushingCompleteUpdateBlock(this.computeTurnsTo()); ++ } ++ private Block computeTurnsTo() { ++ // Paper end - EntityChangeEvent - extract result block logic + Block turnsInto; + if (this.getBlockState().getBlock() instanceof BrushableBlock brushableBlock) { + turnsInto = brushableBlock.getTurnsInto(); +@@ -123,6 +_,11 @@ + turnsInto = Blocks.AIR; + } + ++ // Paper start - EntityChangeEvent - extract result block logic ++ return turnsInto; ++ } ++ public void brushingCompleteUpdateBlock(final Block turnsInto) { ++ // Paper end - EntityChangeEvent - extract result block logic + level.setBlock(this.worldPosition, turnsInto.defaultBlockState(), 3); + } + @@ -139,7 +_,12 @@ double d5 = blockPos.getZ() + 0.5 * d1 + d2; ItemEntity itemEntity = new ItemEntity(level, d3, d4, d5, this.item.split(level.random.nextInt(21) + 10));