Skip to content

Commit 960ad6e

Browse files
committed
remove redundant flags and check place result
isBlockPlaceCancelled is covered by UPDATE_SKIP_BLOCK_ENTITY_SIDEEFFECTS and the the lack of UPDATE_NEIGHBORS / UPDATE_MOVE_BY_PISTON in revertPlace preventPoiUpdated is not relevant anymore
1 parent c2e18c6 commit 960ad6e

File tree

10 files changed

+26
-49
lines changed

10 files changed

+26
-49
lines changed

paper-server/patches/sources/net/minecraft/world/item/ItemStack.java.patch

+1-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
}
2424
}
2525
};
26-
@@ -373,10 +_,171 @@
26+
@@ -373,10 +_,167 @@
2727
return InteractionResult.PASS;
2828
} else {
2929
Item item = this.getItem();
@@ -104,13 +104,9 @@
104104
+ player.containerMenu.sendAllDataToRemote();
105105
+ serverLevel.capturedTileEntities.clear(); // Paper - Allow chests to be placed with NBT data; clear out block entities as chests and such will pop loot
106106
+ // revert back all captured blocks
107-
+ serverLevel.preventPoiUpdated = true; // CraftBukkit - SPIGOT-5710
108-
+ serverLevel.isBlockPlaceCancelled = true; // Paper - prevent calling cleanup logic when undoing a block place upon a cancelled BlockPlaceEvent
109107
+ for (org.bukkit.block.BlockState blockstate : blocks) {
110108
+ ((org.bukkit.craftbukkit.block.CraftBlockState) blockstate).revertPlace();
111109
+ }
112-
+ serverLevel.isBlockPlaceCancelled = false; // Paper - prevent calling cleanup logic when undoing a block place upon a cancelled BlockPlaceEvent
113-
+ serverLevel.preventPoiUpdated = false;
114110
+
115111
+ SignItem.openSign = null; // SPIGOT-6758 - Reset on early return
116112
+ } else {

paper-server/patches/sources/net/minecraft/world/level/Level.java.patch

+3-9
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
protected final NeighborUpdater neighborUpdater;
3939
private final List<TickingBlockEntity> pendingBlockEntityTickers = Lists.newArrayList();
4040
private boolean tickingBlockEntities;
41-
@@ -119,6 +_,61 @@
41+
@@ -119,6 +_,59 @@
4242
private final DamageSources damageSources;
4343
private long subTickCount;
4444

@@ -47,10 +47,8 @@
4747
+ public boolean pvpMode;
4848
+ public org.bukkit.generator.ChunkGenerator generator;
4949
+
50-
+ public boolean preventPoiUpdated = false; // CraftBukkit - SPIGOT-5710
5150
+ public boolean captureBlockStates = false;
5251
+ public boolean captureTreeGeneration = false;
53-
+ public boolean isBlockPlaceCancelled = false; // Paper - prevent calling cleanup logic when undoing a block place upon a cancelled BlockPlaceEvent
5452
+ public Map<BlockPos, org.bukkit.craftbukkit.block.CraftBlockState> capturedBlockStates = new java.util.LinkedHashMap<>(); // Paper
5553
+ public Map<BlockPos, BlockEntity> capturedTileEntities = new java.util.LinkedHashMap<>(); // Paper - Retain block place order when capturing blockstates
5654
+ public List<net.minecraft.world.entity.item.ItemEntity> captureDrops;
@@ -393,7 +391,7 @@
393391
if (blockState1 == state) {
394392
if (blockState != blockState1) {
395393
this.setBlocksDirty(pos, blockState, blockState1);
396-
@@ -251,12 +_,72 @@
394+
@@ -251,12 +_,68 @@
397395

398396
this.updatePOIOnBlockStateChange(pos, blockState, blockState1);
399397
}
@@ -455,11 +453,7 @@
455453
+ } // Paper - Fix block place logic
456454
+ }
457455
+
458-
+ // CraftBukkit start - SPIGOT-5710
459-
+ if (!this.preventPoiUpdated) {
460-
+ this.updatePOIOnBlockStateChange(pos, blockState, blockState1);
461-
+ }
462-
+ // CraftBukkit end
456+
+ this.updatePOIOnBlockStateChange(pos, blockState, blockState1);
463457
+ }
464458
+ }
465459
+ // CraftBukkit end

paper-server/patches/sources/net/minecraft/world/level/block/ChangeOverTimeBlock.java.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
float f = 0.05688889F;
66
if (random.nextFloat() < 0.05688889F) {
77
- this.getNextState(state, level, pos, random).ifPresent(blockState -> level.setBlockAndUpdate(pos, blockState));
8-
+ this.getNextState(state, level, pos, random).ifPresent(blockState -> org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(level, pos, blockState)); // CraftBukkit
8+
+ this.getNextState(state, level, pos, random).ifPresent(blockState -> org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(level, pos, blockState, 3)); // CraftBukkit
99
}
1010
}
1111

paper-server/patches/sources/net/minecraft/world/level/block/LiquidBlock.java.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
- level.setBlockAndUpdate(pos, block.defaultBlockState());
4949
- this.fizz(level, pos);
5050
+ // CraftBukkit start
51-
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(level, pos, block.defaultBlockState())) {
51+
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(level, pos, block.defaultBlockState(), 3)) {
5252
+ this.fizz(level, pos);
5353
+ }
5454
+ // CraftBukkit end
@@ -59,7 +59,7 @@
5959
- level.setBlockAndUpdate(pos, Blocks.BASALT.defaultBlockState());
6060
- this.fizz(level, pos);
6161
+ // CraftBukkit start
62-
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(level, pos, Blocks.BASALT.defaultBlockState())) {
62+
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(level, pos, Blocks.BASALT.defaultBlockState(), 3)) {
6363
+ this.fizz(level, pos);
6464
+ }
6565
+ // CraftBukkit end

paper-server/patches/sources/net/minecraft/world/level/block/MultifaceSpreader.java.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
}
66

77
- return level.setBlock(pos.pos(), stateForPlacement, 2);
8-
+ return org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockSpreadEvent(level, pos.source(), pos.pos(), stateForPlacement, 2); // CraftBukkit
8+
+ return org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockSpreadEvent(level, pos.source(), pos.pos(), stateForPlacement, 2, true); // CraftBukkit
99
} else {
1010
return false;
1111
}

paper-server/patches/sources/net/minecraft/world/level/block/PointedDripstoneBlock.java.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
if (fluidAboveStalactite.get().sourceState.is(Blocks.MUD) && fluid == Fluids.WATER) {
2727
BlockState blockState = Blocks.CLAY.defaultBlockState();
2828
- level.setBlockAndUpdate(fluidAboveStalactite.get().pos, blockState);
29-
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(level, fluidAboveStalactite.get().pos, blockState)) { // Paper - Call BlockFormEvent
29+
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(level, fluidAboveStalactite.get().pos, blockState, 3)) { // Paper - Call BlockFormEvent
3030
Block.pushEntitiesUp(fluidAboveStalactite.get().sourceState, blockState, level, fluidAboveStalactite.get().pos);
3131
level.gameEvent(GameEvent.BLOCK_CHANGE, fluidAboveStalactite.get().pos, GameEvent.Context.of(blockState));
3232
level.levelEvent(1504, blockPos, 0);

paper-server/patches/sources/net/minecraft/world/level/chunk/LevelChunk.java.patch

+1-18
Original file line numberDiff line numberDiff line change
@@ -128,24 +128,7 @@
128128
}
129129

130130
@Nullable
131-
@@ -298,7 +_,7 @@
132-
if (flag && blockState.hasBlockEntity()) {
133-
if (!this.level.isClientSide && flag2) {
134-
BlockEntity blockEntity = this.level.getBlockEntity(pos);
135-
- if (blockEntity != null) {
136-
+ if (blockEntity != null && !this.level.isBlockPlaceCancelled) { // Paper - prevent calling cleanup logic when undoing a block place upon a cancelled BlockPlaceEvent
137-
blockEntity.preRemoveSideEffects(pos, blockState);
138-
}
139-
}
140-
@@ -306,14 +_,14 @@
141-
this.removeBlockEntity(pos);
142-
}
143-
144-
- if ((flag || block instanceof BaseRailBlock) && this.level instanceof ServerLevel serverLevel && ((flags & 1) != 0 || flag1)) {
145-
+ if ((flag || block instanceof BaseRailBlock) && this.level instanceof ServerLevel serverLevel && ((flags & 1) != 0 || flag1) && !this.level.isBlockPlaceCancelled) { // Paper - prevent calling cleanup logic when undoing a block place upon a cancelled BlockPlaceEvent
146-
blockState.affectNeighborsAfterRemoval(serverLevel, pos, flag1);
147-
}
148-
131+
@@ -313,7 +_,7 @@
149132
if (!section.getBlockState(i, i1, i2).is(block)) {
150133
return null;
151134
} else {

paper-server/src/main/java/org/bukkit/craftbukkit/block/CapturedBlockState.java

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import org.bukkit.Location;
1010
import org.bukkit.Material;
1111
import org.bukkit.block.Block;
12-
import org.bukkit.craftbukkit.util.CraftLocation;
1312

1413
@Deprecated(forRemoval = true)
1514
public final class CapturedBlockState extends CraftBlockState {

paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,9 @@ public boolean update(boolean force, boolean applyPhysics) {
245245
// used when the flags matter for non API usage
246246
public boolean place(int flags) {
247247
if (!this.isPlaced()) {
248-
return true;
248+
return false;
249249
}
250+
250251
return this.getWorldHandle().setBlock(this.position, this.data, flags);
251252
}
252253

paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java

+14-10
Original file line numberDiff line numberDiff line change
@@ -949,19 +949,23 @@ public static boolean handleMoistureChangeEvent(Level world, BlockPos pos, net.m
949949
public static BlockPos sourceBlockOverride = null; // SPIGOT-7068: Add source block override, not the most elegant way but better than passing down a BlockPosition up to five methods deep.
950950

951951
public static boolean handleBlockSpreadEvent(LevelAccessor world, BlockPos source, BlockPos target, net.minecraft.world.level.block.state.BlockState state, int flags) {
952+
return handleBlockSpreadEvent(world, source, target, state, flags, false);
953+
}
954+
955+
public static boolean handleBlockSpreadEvent(LevelAccessor world, BlockPos source, BlockPos target, net.minecraft.world.level.block.state.BlockState state, int flags, boolean checkSetResult) {
952956
// Suppress during worldgen
953957
if (!(world instanceof Level)) {
954-
world.setBlock(target, state, flags);
955-
return true;
958+
boolean result = world.setBlock(target, state, flags);
959+
return !checkSetResult || result;
956960
}
957961

958962
CraftBlockState snapshot = CraftBlockStates.getBlockState(world, target);
959963
snapshot.setData(state);
960964

961965
BlockSpreadEvent event = new BlockSpreadEvent(snapshot.getBlock(), CraftBlock.at(world, CraftEventFactory.sourceBlockOverride != null ? CraftEventFactory.sourceBlockOverride : source), snapshot);
962966
if (event.callEvent()) {
963-
snapshot.place(flags);
964-
return true;
967+
boolean result = snapshot.place(flags);
968+
return !checkSetResult || result;
965969
}
966970
return false;
967971
}
@@ -1905,10 +1909,6 @@ public static BlockPhysicsEvent callBlockPhysicsEvent(LevelAccessor world, Block
19051909
return event;
19061910
}
19071911

1908-
public static boolean handleBlockFormEvent(Level world, BlockPos pos, net.minecraft.world.level.block.state.BlockState block) {
1909-
return CraftEventFactory.handleBlockFormEvent(world, pos, block, 3);
1910-
}
1911-
19121912
public static EntityPotionEffectEvent callEntityPotionEffectChangeEvent(net.minecraft.world.entity.LivingEntity entity, @Nullable MobEffectInstance oldEffect, @Nullable MobEffectInstance newEffect, EntityPotionEffectEvent.Cause cause) {
19131913
return CraftEventFactory.callEntityPotionEffectChangeEvent(entity, oldEffect, newEffect, cause, true);
19141914
}
@@ -1945,13 +1945,17 @@ public static boolean handleBlockFormEvent(Level world, BlockPos pos, net.minecr
19451945
}
19461946

19471947
public static boolean handleBlockFormEvent(Level world, BlockPos pos, net.minecraft.world.level.block.state.BlockState state, int flags, @Nullable Entity entity) {
1948+
return CraftEventFactory.handleBlockFormEvent(world, pos, state, flags, entity, false);
1949+
}
1950+
1951+
public static boolean handleBlockFormEvent(Level world, BlockPos pos, net.minecraft.world.level.block.state.BlockState state, int flags, @Nullable Entity entity, boolean checkSetResult) {
19481952
CraftBlockState snapshot = CraftBlockStates.getBlockState(world, pos);
19491953
snapshot.setData(state);
19501954

19511955
BlockFormEvent event = (entity == null) ? new BlockFormEvent(snapshot.getBlock(), snapshot) : new EntityBlockFormEvent(entity.getBukkitEntity(), snapshot.getBlock(), snapshot);
19521956
if (event.callEvent()) {
1953-
snapshot.place(flags);
1954-
return true;
1957+
boolean result = snapshot.place(flags);
1958+
return !checkSetResult || result;
19551959
}
19561960

19571961
return false;

0 commit comments

Comments
 (0)