Add EntityBlockStorage#clearEntities()

This commit is contained in:
Owen1212055
2021-04-05 18:12:29 -04:00
parent 2329a7b1c8
commit f24aec2051
2 changed files with 33 additions and 14 deletions

View File

@@ -55,7 +55,19 @@
}); });
if (!list.isEmpty()) { if (!list.isEmpty()) {
super.setChanged(); 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) { public void addOccupant(Bee entity) {
@@ -74,7 +86,7 @@
entity.stopRiding(); entity.stopRiding();
entity.ejectPassengers(); entity.ejectPassengers();
entity.dropLeash(); entity.dropLeash();
@@ -167,7 +188,7 @@ @@ -167,7 +193,7 @@
this.level.gameEvent((Holder) GameEvent.BLOCK_CHANGE, blockposition, GameEvent.Context.of(entity, this.getBlockState())); this.level.gameEvent((Holder) GameEvent.BLOCK_CHANGE, blockposition, GameEvent.Context.of(entity, this.getBlockState()));
} }
@@ -83,7 +95,7 @@
super.setChanged(); 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<Entity> entities, BeehiveBlockEntity.BeeReleaseStatus beeState, @Nullable BlockPos flowerPos) { private static boolean releaseOccupant(Level world, BlockPos pos, BlockState state, BeehiveBlockEntity.Occupant bee, @Nullable List<Entity> entities, BeehiveBlockEntity.BeeReleaseStatus beeState, @Nullable BlockPos flowerPos) {
@@ -112,7 +124,7 @@
if (entity != null) { if (entity != null) {
+ // CraftBukkit start + // CraftBukkit start
if (entity instanceof Bee) { + if (entity instanceof Bee) {
+ float f = entity.getBbWidth(); + float f = entity.getBbWidth();
+ double d0 = flag ? 0.0D : 0.55D + (double) (f / 2.0F); + double d0 = flag ? 0.0D : 0.55D + (double) (f / 2.0F);
+ double d1 = (double) blockposition.getX() + 0.5D + d0 * (double) enumdirection.getStepX(); + 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 + if (!world.addFreshEntity(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.BEEHIVE)) return false; // CraftBukkit - SpawnReason, moved from below
+ // CraftBukkit end + // CraftBukkit end
+ if (entity instanceof Bee) { if (entity instanceof Bee) {
Bee entitybee = (Bee) entity; Bee entitybee = (Bee) entity;
- if (flowerPos != null && !entitybee.hasSavedFlowerPos() && world.random.nextFloat() < 0.9F) { - if (flowerPos != null && !entitybee.hasSavedFlowerPos() && world.random.nextFloat() < 0.9F) {
@@ -144,7 +156,7 @@
if (i < 5) { if (i < 5) {
int j = world.random.nextInt(100) == 0 ? 2 : 1; int j = world.random.nextInt(100) == 0 ? 2 : 1;
@@ -211,27 +250,29 @@ @@ -211,27 +255,29 @@
--j; --j;
} }
@@ -183,7 +195,7 @@
} else { } else {
return false; return false;
} }
@@ -256,6 +297,10 @@ @@ -256,6 +302,10 @@
if (BeehiveBlockEntity.releaseOccupant(world, pos, state, tileentitybeehive_hivebee.toOccupant(), (List) null, tileentitybeehive_releasestatus, flowerPos)) { if (BeehiveBlockEntity.releaseOccupant(world, pos, state, tileentitybeehive_hivebee.toOccupant(), (List) null, tileentitybeehive_releasestatus, flowerPos)) {
flag = true; flag = true;
iterator.remove(); iterator.remove();
@@ -194,7 +206,7 @@
} }
} }
} }
@@ -282,7 +327,7 @@ @@ -282,7 +332,7 @@
@Override @Override
protected void loadAdditional(CompoundTag nbt, HolderLookup.Provider registries) { protected void loadAdditional(CompoundTag nbt, HolderLookup.Provider registries) {
super.loadAdditional(nbt, registries); super.loadAdditional(nbt, registries);
@@ -203,7 +215,7 @@
if (nbt.contains("bees")) { if (nbt.contains("bees")) {
BeehiveBlockEntity.Occupant.LIST_CODEC.parse(NbtOps.INSTANCE, nbt.get("bees")).resultOrPartial((s) -> { BeehiveBlockEntity.Occupant.LIST_CODEC.parse(NbtOps.INSTANCE, nbt.get("bees")).resultOrPartial((s) -> {
BeehiveBlockEntity.LOGGER.error("Failed to parse bees: '{}'", s); BeehiveBlockEntity.LOGGER.error("Failed to parse bees: '{}'", s);
@@ -291,7 +336,12 @@ @@ -291,7 +341,12 @@
}); });
} }
@@ -217,7 +229,7 @@
} }
@Override @Override
@@ -301,13 +351,14 @@ @@ -301,13 +356,14 @@
if (this.hasSavedFlowerPos()) { if (this.hasSavedFlowerPos()) {
nbt.put("flower_pos", NbtUtils.writeBlockPos(this.savedFlowerPos)); nbt.put("flower_pos", NbtUtils.writeBlockPos(this.savedFlowerPos));
} }
@@ -233,7 +245,7 @@
List<BeehiveBlockEntity.Occupant> list = (List) components.getOrDefault(DataComponents.BEES, List.of()); List<BeehiveBlockEntity.Occupant> list = (List) components.getOrDefault(DataComponents.BEES, List.of());
list.forEach(this::storeBee); list.forEach(this::storeBee);
@@ -348,7 +399,7 @@ @@ -348,7 +404,7 @@
CompoundTag nbttagcompound = new CompoundTag(); CompoundTag nbttagcompound = new CompoundTag();
entity.save(nbttagcompound); entity.save(nbttagcompound);
@@ -242,7 +254,7 @@
Objects.requireNonNull(nbttagcompound); Objects.requireNonNull(nbttagcompound);
list.forEach(nbttagcompound::remove); list.forEach(nbttagcompound::remove);
@@ -367,7 +418,7 @@ @@ -367,7 +423,7 @@
@Nullable @Nullable
public Entity createEntity(Level world, BlockPos pos) { public Entity createEntity(Level world, BlockPos pos) {
CompoundTag nbttagcompound = this.entityData.copyTag(); CompoundTag nbttagcompound = this.entityData.copyTag();
@@ -251,7 +263,7 @@
Objects.requireNonNull(nbttagcompound); Objects.requireNonNull(nbttagcompound);
list.forEach(nbttagcompound::remove); list.forEach(nbttagcompound::remove);
@@ -391,6 +442,7 @@ @@ -391,6 +447,7 @@
} }
private static void setBeeReleaseData(int ticksInHive, Bee beeEntity) { private static void setBeeReleaseData(int ticksInHive, Bee beeEntity) {
@@ -259,7 +271,7 @@
int j = beeEntity.getAge(); int j = beeEntity.getAge();
if (j < 0) { if (j < 0) {
@@ -400,6 +452,7 @@ @@ -400,6 +457,7 @@
} }
beeEntity.setInLoveTime(Math.max(0, beeEntity.getInLoveTime() - ticksInHive)); beeEntity.setInLoveTime(Math.max(0, beeEntity.getInLoveTime() - ticksInHive));

View File

@@ -95,4 +95,11 @@ public class CraftBeehive extends CraftBlockEntityState<BeehiveBlockEntity> impl
public CraftBeehive copy(Location location) { public CraftBeehive copy(Location location) {
return new CraftBeehive(this, location); return new CraftBeehive(this, location);
} }
// Paper start - Add EntityBlockStorage clearEntities
@Override
public void clearEntities() {
getSnapshot().clearBees();
}
// Paper end
} }