From f24aec20519e6dfa7db2a6dbf10ca7181a375752 Mon Sep 17 00:00:00 2001 From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com> Date: Mon, 5 Apr 2021 18:12:29 -0400 Subject: [PATCH] Add EntityBlockStorage#clearEntities() --- .../entity/BeehiveBlockEntity.java.patch | 40 ++++++++++++------- .../craftbukkit/block/CraftBeehive.java | 7 ++++ 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/paper-server/patches/sources/net/minecraft/world/level/block/entity/BeehiveBlockEntity.java.patch b/paper-server/patches/sources/net/minecraft/world/level/block/entity/BeehiveBlockEntity.java.patch index 3c43e5c75a..35c8d44484 100644 --- a/paper-server/patches/sources/net/minecraft/world/level/block/entity/BeehiveBlockEntity.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/level/block/entity/BeehiveBlockEntity.java.patch @@ -55,7 +55,19 @@ }); if (!list.isEmpty()) { super.setChanged(); -@@ -151,7 +162,17 @@ +@@ -141,6 +152,11 @@ + return this.stored.size(); + } + ++ // Paper start - Add EntityBlockStorage clearEntities ++ public void clearBees() { ++ this.stored.clear(); ++ } ++ // Paper end - Add EntityBlockStorage clearEntities + public static int getHoneyLevel(BlockState state) { + return (Integer) state.getValue(BeehiveBlock.HONEY_LEVEL); + } +@@ -151,7 +167,17 @@ } public void addOccupant(Bee entity) { @@ -74,7 +86,7 @@ entity.stopRiding(); entity.ejectPassengers(); entity.dropLeash(); -@@ -167,7 +188,7 @@ +@@ -167,7 +193,7 @@ this.level.gameEvent((Holder) GameEvent.BLOCK_CHANGE, blockposition, GameEvent.Context.of(entity, this.getBlockState())); } @@ -83,7 +95,7 @@ super.setChanged(); } } -@@ -177,32 +198,50 @@ +@@ -177,32 +203,50 @@ } private static boolean releaseOccupant(Level world, BlockPos pos, BlockState state, BeehiveBlockEntity.Occupant bee, @Nullable List entities, BeehiveBlockEntity.BeeReleaseStatus beeState, @Nullable BlockPos flowerPos) { @@ -112,7 +124,7 @@ if (entity != null) { + // CraftBukkit start - if (entity instanceof Bee) { ++ if (entity instanceof Bee) { + float f = entity.getBbWidth(); + double d0 = flag ? 0.0D : 0.55D + (double) (f / 2.0F); + double d1 = (double) blockposition.getX() + 0.5D + d0 * (double) enumdirection.getStepX(); @@ -123,7 +135,7 @@ + } + if (!world.addFreshEntity(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.BEEHIVE)) return false; // CraftBukkit - SpawnReason, moved from below + // CraftBukkit end -+ if (entity instanceof Bee) { + if (entity instanceof Bee) { Bee entitybee = (Bee) entity; - if (flowerPos != null && !entitybee.hasSavedFlowerPos() && world.random.nextFloat() < 0.9F) { @@ -144,7 +156,7 @@ if (i < 5) { int j = world.random.nextInt(100) == 0 ? 2 : 1; -@@ -211,27 +250,29 @@ +@@ -211,27 +255,29 @@ --j; } @@ -183,7 +195,7 @@ } else { return false; } -@@ -256,6 +297,10 @@ +@@ -256,6 +302,10 @@ if (BeehiveBlockEntity.releaseOccupant(world, pos, state, tileentitybeehive_hivebee.toOccupant(), (List) null, tileentitybeehive_releasestatus, flowerPos)) { flag = true; iterator.remove(); @@ -194,7 +206,7 @@ } } } -@@ -282,7 +327,7 @@ +@@ -282,7 +332,7 @@ @Override protected void loadAdditional(CompoundTag nbt, HolderLookup.Provider registries) { super.loadAdditional(nbt, registries); @@ -203,7 +215,7 @@ if (nbt.contains("bees")) { BeehiveBlockEntity.Occupant.LIST_CODEC.parse(NbtOps.INSTANCE, nbt.get("bees")).resultOrPartial((s) -> { BeehiveBlockEntity.LOGGER.error("Failed to parse bees: '{}'", s); -@@ -291,7 +336,12 @@ +@@ -291,7 +341,12 @@ }); } @@ -217,7 +229,7 @@ } @Override -@@ -301,13 +351,14 @@ +@@ -301,13 +356,14 @@ if (this.hasSavedFlowerPos()) { nbt.put("flower_pos", NbtUtils.writeBlockPos(this.savedFlowerPos)); } @@ -233,7 +245,7 @@ List list = (List) components.getOrDefault(DataComponents.BEES, List.of()); list.forEach(this::storeBee); -@@ -348,7 +399,7 @@ +@@ -348,7 +404,7 @@ CompoundTag nbttagcompound = new CompoundTag(); entity.save(nbttagcompound); @@ -242,7 +254,7 @@ Objects.requireNonNull(nbttagcompound); list.forEach(nbttagcompound::remove); -@@ -367,7 +418,7 @@ +@@ -367,7 +423,7 @@ @Nullable public Entity createEntity(Level world, BlockPos pos) { CompoundTag nbttagcompound = this.entityData.copyTag(); @@ -251,7 +263,7 @@ Objects.requireNonNull(nbttagcompound); list.forEach(nbttagcompound::remove); -@@ -391,6 +442,7 @@ +@@ -391,6 +447,7 @@ } private static void setBeeReleaseData(int ticksInHive, Bee beeEntity) { @@ -259,7 +271,7 @@ int j = beeEntity.getAge(); if (j < 0) { -@@ -400,6 +452,7 @@ +@@ -400,6 +457,7 @@ } beeEntity.setInLoveTime(Math.max(0, beeEntity.getInLoveTime() - ticksInHive)); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBeehive.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBeehive.java index fbacbef0dd..1a2a05160b 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBeehive.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBeehive.java @@ -95,4 +95,11 @@ public class CraftBeehive extends CraftBlockEntityState impl public CraftBeehive copy(Location location) { return new CraftBeehive(this, location); } + + // Paper start - Add EntityBlockStorage clearEntities + @Override + public void clearEntities() { + getSnapshot().clearBees(); + } + // Paper end }