--- a/net/minecraft/world/level/Level.java +++ b/net/minecraft/world/level/Level.java @@ -87,8 +_,19 @@ import net.minecraft.world.phys.Vec3; import net.minecraft.world.scores.Scoreboard; import org.apache.commons.lang3.mutable.MutableBoolean; +import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.jspecify.annotations.Nullable; +// CraftBukkit start +import java.util.Map; +import net.minecraft.server.level.ServerLevel; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.craftbukkit.block.CraftBlockState; +import org.bukkit.craftbukkit.block.data.CraftBlockData; +import org.bukkit.entity.SpawnCategory; +// CraftBukkit end + public abstract class Level implements LevelAccessor, AutoCloseable { public static final Codec> RESOURCE_KEY_CODEC = ResourceKey.codec(Registries.DIMENSION); public static final ResourceKey OVERWORLD = ResourceKey.create(Registries.DIMENSION, Identifier.withDefaultNamespace("overworld")); @@ -131,6 +_,55 @@ private final PalettedContainerFactory palettedContainerFactory; private long subTickCount; + // CraftBukkit start + private final CraftWorld world; + public org.bukkit.generator.@Nullable ChunkGenerator generator; + + public boolean captureBlockStates = false; + public boolean captureTreeGeneration = false; + public Map capturedBlockStates = new java.util.LinkedHashMap<>(); // Paper + public Map capturedBlockEntities = new java.util.LinkedHashMap<>(); // Paper - Retain block place order when capturing blockstates + @Nullable + public List captureDrops; + public final it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap ticksPerSpawnCategory = new it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap<>(); + public boolean populating; + public final org.spigotmc.SpigotWorldConfig spigotConfig; // Spigot + // Paper start - add paper world config + private final io.papermc.paper.configuration.WorldConfiguration paperConfig; + public io.papermc.paper.configuration.WorldConfiguration paperConfig() { + return this.paperConfig; + } + // Paper end - add paper world config + + public static @Nullable BlockPos lastPhysicsProblem; // Spigot + public final Map explosionDensityCache = new java.util.HashMap<>(); // Paper - Optimize explosions + public java.util.ArrayDeque redstoneUpdateInfos; // Paper - Faster redstone torch rapid clock removal; Move from Map in BlockRedstoneTorch to here + + public CraftWorld getWorld() { + return this.world; + } + + public CraftServer getCraftServer() { + return (CraftServer) org.bukkit.Bukkit.getServer(); + } + // Paper start - Use getChunkIfLoadedImmediately + @Override + public boolean hasChunk(int chunkX, int chunkZ) { + return this.getChunkIfLoaded(chunkX, chunkZ) != null; + } + // Paper end - Use getChunkIfLoadedImmediately + // Paper start - per world ticks per spawn + private int getTicksPerSpawn(SpawnCategory spawnCategory) { + final int perWorld = this.paperConfig().entities.spawning.ticksPerSpawn.getInt(org.bukkit.craftbukkit.util.CraftSpawnCategory.toNMS(spawnCategory)); + if (perWorld >= 0) { + return perWorld; + } + return this.getCraftServer().getTicksPerSpawns(spawnCategory); + } + // Paper end + + public abstract ResourceKey getTypeKey(); + protected Level( final WritableLevelData levelData, final ResourceKey dimension, @@ -140,7 +_,25 @@ final boolean isDebug, final long biomeZoomSeed, final int maxChainedNeighborUpdates + , String bukkitName, // Paper + org.bukkit.generator.@Nullable ChunkGenerator generator, // Paper + org.bukkit.generator.@Nullable BiomeProvider biomeProvider, // Paper + org.bukkit.World.Environment environment, // Paper + java.util.function.Function paperWorldConfigCreator // Paper - create paper world config ) { + final org.bukkit.NamespacedKey worldKey = CraftNamespacedKey.fromMinecraft(dimension.identifier()); // Paper + this.spigotConfig = new org.spigotmc.SpigotWorldConfig(bukkitName, worldKey); // Spigot + this.paperConfig = paperWorldConfigCreator.apply(this.spigotConfig); // Paper - create paper world config + this.generator = generator; + this.world = new CraftWorld((ServerLevel) this, worldKey, biomeProvider, environment); + + for (SpawnCategory spawnCategory : SpawnCategory.values()) { + if (org.bukkit.craftbukkit.util.CraftSpawnCategory.isValidForLimits(spawnCategory)) { + this.ticksPerSpawnCategory.put(spawnCategory, this.getTicksPerSpawn(spawnCategory)); + } + } + // CraftBukkit end this.levelData = levelData; this.dimensionTypeRegistration = dimensionTypeRegistration; this.dimension = dimension; @@ -158,6 +_,46 @@ return 0; } + // Paper start - Cancel hit for vanished players + // ret true if no collision + public final boolean checkEntityCollision(BlockState state, Entity source, net.minecraft.world.phys.shapes.CollisionContext context, + BlockPos pos, boolean checkCanSee) { + // Copied from CollisionGetter#isUnobstructed(BlockState, BlockPos, CollisionContext) & EntityGetter#isUnobstructed(Entity, VoxelShape) + net.minecraft.world.phys.shapes.VoxelShape shape = state.getCollisionShape(this, pos, context); + if (shape.isEmpty()) { + return true; + } + + shape = shape.move((double) pos.getX(), (double) pos.getY(), (double) pos.getZ()); + if (shape.isEmpty()) { + return true; + } + + List entities = this.getEntities(null, shape.bounds()); + for (int i = 0, len = entities.size(); i < len; ++i) { + Entity entity = entities.get(i); + + if (checkCanSee && source instanceof net.minecraft.server.level.ServerPlayer && entity instanceof net.minecraft.server.level.ServerPlayer + && !((net.minecraft.server.level.ServerPlayer) source).getBukkitEntity().canSee(((net.minecraft.server.level.ServerPlayer) entity).getBukkitEntity())) { + continue; + } + + // !entity.isRemoved() && entity.blocksBuilding && (source == null || !entity.isPassengerOfSameVehicle(source)) + // elide the last check since vanilla calls with source = null + // only we care about the source for the canSee check + if (entity.isRemoved() || !entity.blocksBuilding) { + continue; + } + + if (net.minecraft.world.phys.shapes.Shapes.joinIsNotEmpty(shape, net.minecraft.world.phys.shapes.Shapes.create(entity.getBoundingBox()), net.minecraft.world.phys.shapes.BooleanOp.AND)) { + return false; + } + } + + return true; + } + // Paper end - Cancel hit for vanished players + @Override public boolean isClientSide() { return this.isClientSide; @@ -168,8 +_,15 @@ return null; } + // Paper start + public net.minecraft.world.phys.BlockHitResult.Type clipDirect(Vec3 start, Vec3 end, net.minecraft.world.phys.shapes.CollisionContext context) { + // To be patched over + return this.clip(new ClipContext(start, end, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, context)).getType(); + } + // Paper end + public boolean isInWorldBounds(final BlockPos pos) { - return this.isInsideBuildHeight(pos) && isInWorldBoundsHorizontal(pos); + return pos.isInsideBuildHeightAndWorldBoundsHorizontal(this); // Paper - Perf: Optimize isInWorldBounds } public boolean isInValidBounds(final BlockPos pos) { @@ -181,7 +_,7 @@ } private static boolean isInWorldBoundsHorizontal(final BlockPos pos) { - return pos.getX() >= -30000000 && pos.getZ() >= -30000000 && pos.getX() < 30000000 && pos.getZ() < 30000000; + return pos.getX() >= -30000000 && pos.getZ() >= -30000000 && pos.getX() < 30000000 && pos.getZ() < 30000000; // Paper - Diff on change warnUnsafeChunk() and isInsideBuildHeightAndWorldBoundsHorizontal } private static boolean isInValidBoundsHorizontal(final BlockPos pos) { @@ -194,14 +_,78 @@ return y < -20000000 || y >= 20000000; } - public LevelChunk getChunkAt(final BlockPos pos) { + public final LevelChunk getChunkAt(final BlockPos pos) { // Paper - help inline return this.getChunk(SectionPos.blockToSectionCoord(pos.getX()), SectionPos.blockToSectionCoord(pos.getZ())); } @Override - public LevelChunk getChunk(final int chunkX, final int chunkZ) { - return (LevelChunk)this.getChunk(chunkX, chunkZ, ChunkStatus.FULL); - } + public final LevelChunk getChunk(final int chunkX, final int chunkZ) { // Paper - final to help inline + // Paper start - Perf: make sure loaded chunks get the inlined variant of this function + net.minecraft.server.level.ServerChunkCache cps = ((ServerLevel)this).getChunkSource(); + LevelChunk ifLoaded = cps.getChunkAtIfLoadedImmediately(chunkX, chunkZ); + if (ifLoaded != null) { + return ifLoaded; + } + return (LevelChunk) cps.getChunk(chunkX, chunkZ, ChunkStatus.FULL, true); // Paper - avoid a method jump + // Paper end - Perf: make sure loaded chunks get the inlined variant of this function + } + + // Paper start - if loaded + @Nullable + @Override + public final ChunkAccess getChunkIfLoadedImmediately(int x, int z) { + return ((ServerLevel)this).getChunkSource().getChunkAtIfLoadedImmediately(x, z); + } + + @Override + @Nullable + public final BlockState getBlockStateIfLoaded(BlockPos pos) { + // CraftBukkit start - tree generation + if (this.captureTreeGeneration) { + CraftBlockState previous = this.capturedBlockStates.get(pos); + if (previous != null) { + return previous.getHandle(); + } + } + // CraftBukkit end + if (this.isOutsideBuildHeight(pos)) { + return Blocks.VOID_AIR.defaultBlockState(); + } else { + ChunkAccess chunk = this.getChunkIfLoadedImmediately(pos.getX() >> 4, pos.getZ() >> 4); + + return chunk == null ? null : chunk.getBlockState(pos); + } + } + + @Override + @Nullable + public final FluidState getFluidIfLoaded(BlockPos pos) { + ChunkAccess chunk = this.getChunkIfLoadedImmediately(pos.getX() >> 4, pos.getZ() >> 4); + + return chunk == null ? null : chunk.getFluidState(pos); + } + + @Override + public final boolean hasChunkAt(BlockPos pos) { + return this.getChunkIfLoaded(pos.getX() >> 4, pos.getZ() >> 4) != null; // Paper - Perf: Optimize LevelReader.hasChunkAt(BlockPos)Z + } + + public final boolean isLoadedAndInBounds(BlockPos pos) { // Paper - final for inline + return this.getWorldBorder().isWithinBounds(pos) && this.getChunkIfLoadedImmediately(pos.getX() >> 4, pos.getZ() >> 4) != null; + } + + public @Nullable LevelChunk getChunkIfLoaded(int x, int z) { // Overridden in ServerLevel for ABI compat which has final + return ((ServerLevel) this).getChunkSource().getChunkAtIfLoadedImmediately(x, z); + } + + public final @Nullable LevelChunk getChunkIfLoaded(BlockPos pos) { + return ((ServerLevel) this).getChunkSource().getChunkAtIfLoadedImmediately(pos.getX() >> 4, pos.getZ() >> 4); + } + + public final @Nullable BlockState getBlockStateIfLoadedAndInBounds(BlockPos pos) { + return this.getWorldBorder().isWithinBounds(pos) ? this.getBlockStateIfLoaded(pos) : null; + } + // Paper end @Override public @Nullable ChunkAccess getChunk(final int chunkX, final int chunkZ, final ChunkStatus status, final boolean loadOrGenerate) { @@ -215,6 +_,22 @@ @Override public boolean setBlock(final BlockPos pos, final BlockState blockState, final @Block.UpdateFlags int updateFlags, final int updateLimit) { + // CraftBukkit start - tree generation + if (this.captureTreeGeneration) { + // Paper start - Protect Bedrock and End Portal/Frames from being destroyed + BlockState type = getBlockState(pos); + if (!type.isDestroyable()) return false; + // Paper end - Protect Bedrock and End Portal/Frames from being destroyed + CraftBlockState blockstate = this.capturedBlockStates.get(pos); + if (blockstate == null) { + blockstate = org.bukkit.craftbukkit.block.CapturedBlockState.getTreeBlockState(this, pos, updateFlags); + this.capturedBlockStates.put(pos.immutable(), blockstate); + } + blockstate.setBlock(blockState); + blockstate.setFlags(updateFlags); + return true; + } + // CraftBukkit end if (!this.isInValidBounds(pos)) { return false; } @@ -225,12 +_,32 @@ LevelChunk chunk = this.getChunkAt(pos); Block block = blockState.getBlock(); + // CraftBukkit start - capture blockstates + boolean captured = false; + if (this.captureBlockStates) { + final CraftBlockState snapshot; + if (!this.capturedBlockStates.containsKey(pos)) { + snapshot = (CraftBlockState) org.bukkit.craftbukkit.block.CraftBlock.at(this, pos).getState(); // Paper - use CB getState to get a suitable snapshot + this.capturedBlockStates.put(pos.immutable(), snapshot); + captured = true; + } else { + snapshot = this.capturedBlockStates.get(pos); + } + snapshot.setFlags(updateFlags); // Paper - always set the flag of the most recent call to mitigate issues with multiple update at the same pos with different flags + } + // CraftBukkit end - capture blockstates BlockState oldState = chunk.setBlockState(pos, blockState, updateFlags); if (oldState == null) { + // CraftBukkit start - remove blockstate if failed (or the same) + if (this.captureBlockStates && captured) { + this.capturedBlockStates.remove(pos); + } + // CraftBukkit end return false; } BlockState newState = this.getBlockState(pos); + /* // CraftBukkit if (newState == blockState) { if (oldState != newState) { this.setBlocksDirty(pos, oldState, newState); @@ -258,9 +_,64 @@ this.updatePOIOnBlockStateChange(pos, oldState, newState); } + */ // CraftBukkit + + // CraftBukkit start + if (!this.captureBlockStates) { // Don't notify clients or update physics while capturing blockstates + // Modularize client and physic updates + // Spigot start + try { + this.notifyAndUpdatePhysics(pos, chunk, oldState, blockState, newState, updateFlags, updateLimit); + } catch (StackOverflowError ex) { + Level.lastPhysicsProblem = pos.immutable(); + } + // Spigot end + } + // CraftBukkit end return true; } + + // CraftBukkit start - Split off from above in order to directly send client and physic updates + public void notifyAndUpdatePhysics(BlockPos pos, LevelChunk chunk, BlockState oldState, BlockState blockState, BlockState newState, @Block.UpdateFlags int updateFlags, int updateLimit) { + if (newState == blockState) { + if (oldState != newState) { + this.setBlocksDirty(pos, oldState, newState); + } + + if ((updateFlags & Block.UPDATE_CLIENTS) != 0 && (!this.isClientSide() || (updateFlags & Block.UPDATE_INVISIBLE) == 0) && (this.isClientSide() || chunk == null || (chunk.getFullStatus() != null && chunk.getFullStatus().isOrAfter(FullChunkStatus.BLOCK_TICKING)))) { // allow chunk to be null here as chunk.isReady() is false when we send our notification during block placement + this.sendBlockUpdated(pos, oldState, blockState, updateFlags); + } + + if ((updateFlags & Block.UPDATE_NEIGHBORS) != 0) { + this.updateNeighborsAt(pos, oldState.getBlock()); + if (!this.isClientSide() && blockState.hasAnalogOutputSignal()) { + this.updateNeighbourForOutputSignal(pos, blockState.getBlock()); + } + } + + if ((updateFlags & Block.UPDATE_KNOWN_SHAPE) == 0 && updateLimit > 0) { + int neighbourUpdateFlags = updateFlags & ~(Block.UPDATE_SUPPRESS_DROPS | Block.UPDATE_NEIGHBORS); + + // CraftBukkit start + oldState.updateIndirectNeighbourShapes(this, pos, neighbourUpdateFlags, updateLimit - 1); // Don't call an event for the old block to limit event spam + boolean cancelledUpdates = false; // Paper - Fix block place logic + if (((ServerLevel)this).hasPhysicsEvent) { // Paper - BlockPhysicsEvent + org.bukkit.event.block.BlockPhysicsEvent event = new org.bukkit.event.block.BlockPhysicsEvent(org.bukkit.craftbukkit.block.CraftBlock.at(this, pos), blockState.asBlockData()); + cancelledUpdates = !event.callEvent(); // Paper - Fix block place logic + } + // CraftBukkit end + if (!cancelledUpdates) { // Paper - Fix block place logic + blockState.updateNeighbourShapes(this, pos, neighbourUpdateFlags, updateLimit - 1); + blockState.updateIndirectNeighbourShapes(this, pos, neighbourUpdateFlags, updateLimit - 1); + } // Paper - Fix block place logic + } + + if ((updateFlags & Block.UPDATE_SKIP_POI) == 0) // Paper - temporary flag + this.updatePOIOnBlockStateChange(pos, oldState, newState); + } + } + // CraftBukkit end public void updatePOIOnBlockStateChange(final BlockPos pos, final BlockState oldState, final BlockState newState) { } @@ -272,19 +_,41 @@ } @Override - public boolean destroyBlock(final BlockPos pos, final boolean dropResources, final @Nullable Entity breaker, final int updateLimit) { + public boolean destroyBlock(final BlockPos pos, boolean dropResources, final @Nullable Entity breaker, final int updateLimit) { // Paper - make dropResources non-final BlockState blockState = this.getBlockState(pos); if (blockState.isAir()) { return false; } - blockState.getBlock().spawnDestroyParticles(this, pos, blockState); + // Paper start - BlockDestroyEvent; while the above removeBlock method looks very similar + // they are NOT used with same intent and the above should not fire this event. The above method is more of a BlockSetToAirEvent, + // it doesn't imply destruction of a block that plays a sound effect / drops an item. + FluidState fluidState = this.getFluidState(pos); + boolean playEffect = true; + BlockState effectType = blockState; + int xp = blockState.getBlock().getExpDrop(blockState, (ServerLevel) this, pos, ItemStack.EMPTY, true); + if (com.destroystokyo.paper.event.block.BlockDestroyEvent.getHandlerList().getRegisteredListeners().length > 0) { + com.destroystokyo.paper.event.block.BlockDestroyEvent event = new com.destroystokyo.paper.event.block.BlockDestroyEvent(org.bukkit.craftbukkit.block.CraftBlock.at(this, pos), fluidState.createLegacyBlock().asBlockData(), effectType.asBlockData(), xp, dropResources); + if (!event.callEvent()) { + return false; + } + effectType = ((CraftBlockData) event.getEffectBlock()).getState(); + playEffect = event.playEffect(); + dropResources = event.willDrop(); + xp = event.getExpToDrop(); + } + // Paper end - BlockDestroyEvent + if (playEffect) { // Paper - BlockDestroyEvent + effectType.getBlock().spawnDestroyParticles(this, pos, effectType); // Paper - BlockDestroyEvent + } + if (dropResources) { BlockEntity blockEntity = blockState.hasBlockEntity() ? this.getBlockEntity(pos) : null; - Block.dropResources(blockState, this, pos, blockEntity, breaker, ItemStack.EMPTY); + Block.dropResources(blockState, this, pos, blockEntity, breaker, ItemStack.EMPTY, false); // Paper - Properly handle xp dropping + blockState.getBlock().popExperience((ServerLevel) this, pos, xp, breaker); // Paper - Properly handle xp dropping; custom amount } - FluidState fluidState = this.getFluidState(pos); + // FluidState fluidState = this.getFluidState(pos); // Paper - move up boolean destroyed = this.setBlock(pos, fluidState.createLegacyBlock(), Block.UPDATE_ALL, updateLimit); if (destroyed) { this.gameEvent(GameEvent.BLOCK_DESTROY, pos, GameEvent.Context.of(breaker, blockState)); @@ -352,11 +_,19 @@ @Override public BlockState getBlockState(final BlockPos pos) { + // CraftBukkit start - tree generation + if (this.captureTreeGeneration) { + CraftBlockState previous = this.capturedBlockStates.get(pos); // Paper + if (previous != null) { + return previous.getHandle(); + } + } + // CraftBukkit end if (!this.isInValidBounds(pos)) { return Blocks.VOID_AIR.defaultBlockState(); } - LevelChunk chunk = this.getChunk(SectionPos.blockToSectionCoord(pos.getX()), SectionPos.blockToSectionCoord(pos.getZ())); + ChunkAccess chunk = this.getChunk(pos.getX() >> 4, pos.getZ() >> 4, ChunkStatus.FULL, true); // Paper - manually inline to reduce hops and avoid unnecessary null check to reduce total byte code size, this should never return null and if it does we will see it the next line but the real stack trace will matter in the chunk engine return chunk.getBlockState(pos); } @@ -527,6 +_,7 @@ } public void addBlockEntityTicker(final TickingBlockEntity ticker) { + if (!this.paperConfig().unsupportedSettings.ticking.blockEntities) return; // Paper - option to disable ticking (this.tickingBlockEntities ? this.pendingBlockEntityTickers : this.blockEntityTickers).add(ticker); } @@ -537,18 +_,23 @@ this.pendingBlockEntityTickers.clear(); } - Iterator iterator = this.blockEntityTickers.iterator(); + // Paper - Fix MC-117075 use removeAll - remove iterator in favour of indexed for loop, ensuring compile error if something uses iter incorrectly boolean tickBlockEntities = this.tickRateManager().runsNormally(); - while (iterator.hasNext()) { - TickingBlockEntity ticker = iterator.next(); + // Paper start - Fix MC-117075 use removeAll + final it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<@Nullable TickingBlockEntity> toRemove = new it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<>(); + toRemove.add(null); + for (int tickerIndex = 0; tickerIndex < this.blockEntityTickers.size(); tickerIndex++) { + final TickingBlockEntity ticker = this.blockEntityTickers.get(tickerIndex); + // Paper end - Fix MC-117075 use removeAll if (ticker.isRemoved()) { - iterator.remove(); + toRemove.add(ticker); // Paper - Fix MC-117075 use removeAll } else if (tickBlockEntities && this.shouldTickBlocksAt(ticker.getPos())) { ticker.tick(); } } + this.blockEntityTickers.removeAll(toRemove); // Paper - Fix MC-117075 use removeAll this.tickingBlockEntities = false; } @@ -556,12 +_,23 @@ try { tick.accept(entity); } catch (Throwable t) { - CrashReport report = CrashReport.forThrowable(t, "Ticking entity"); - CrashReportCategory category = report.addCategory("Entity being ticked"); - entity.fillCrashReportCategory(category); - throw new ReportedException(report); + // Paper start - Prevent block entity and entity crashes + final String msg = String.format("Entity threw exception at %s:%s,%s,%s", io.papermc.paper.util.MCUtil.getLevelName(entity.level()), entity.getX(), entity.getY(), entity.getZ()); + MinecraftServer.LOGGER.error(msg, t); + getCraftServer().getPluginManager().callEvent(new com.destroystokyo.paper.event.server.ServerExceptionEvent(new com.destroystokyo.paper.exception.ServerInternalException(msg, t))); // Paper - ServerExceptionEvent + entity.discard(org.bukkit.event.entity.EntityRemoveEvent.Cause.DISCARD); + // Paper end - Prevent block entity and entity crashes } } + + // Paper start - Option to prevent armor stands from doing entity lookups + @Override + public boolean noCollision(@Nullable Entity entity, AABB box) { + if (entity instanceof net.minecraft.world.entity.decoration.ArmorStand && !entity.level().paperConfig().entities.armorStands.doCollisionEntityLookups) + return false; + return LevelAccessor.super.noCollision(entity, box); + } + // Paper end - Option to prevent armor stands from doing entity lookups public boolean shouldTickDeath(final Entity entity) { return true; @@ -695,6 +_,12 @@ @Override public @Nullable BlockEntity getBlockEntity(final BlockPos pos) { + // Paper start - Perf: Optimize capturedTileEntities lookup + net.minecraft.world.level.block.entity.BlockEntity blockEntity; + if (!this.capturedBlockEntities.isEmpty() && (blockEntity = this.capturedBlockEntities.get(pos)) != null) { + return blockEntity; + } + // Paper end - Perf: Optimize capturedTileEntities lookup if (!this.isInValidBounds(pos)) { return null; } else { @@ -707,6 +_,12 @@ public void setBlockEntity(final BlockEntity blockEntity) { BlockPos pos = blockEntity.getBlockPos(); if (this.isInValidBounds(pos)) { + // CraftBukkit start + if (this.captureBlockStates) { + this.capturedBlockEntities.put(pos.immutable(), blockEntity); + return; + } + // CraftBukkit end this.getChunkAt(pos).addAndRegisterBlockEntity(blockEntity); } } @@ -1125,7 +_,8 @@ BLOCK("block"), MOB("mob"), TNT("tnt"), - TRIGGER("trigger"); + TRIGGER("trigger"), + STANDARD("standard"); // CraftBukkit - Add STANDARD which will always use Explosion.Effect.DESTROY public static final Codec CODEC = StringRepresentable.fromEnum(Level.ExplosionInteraction::values); private final String id; @@ -1139,4 +_,16 @@ return this.id; } } + + // Paper start - allow patching this logic + public final int getEntityCount() { + int ret = 0; + for (net.minecraft.world.entity.Entity entity : this.getEntities().getAll()) { + if (entity.getBukkitEntity().isValid()) { + ++ret; + } + } + return ret; + } + // Paper end - allow patching this logic }