mirror of
https://github.com/PaperMC/Paper.git
synced 2025-05-19 13:40:24 -07:00
Add Throw EntityChangeBlockEvent for BrushableBlockEntity#brush (#12133)
This commit is contained in:
parent
5acfdd6af4
commit
2754d7c3b9
@ -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));
|
||||
|
Loading…
x
Reference in New Issue
Block a user