--- a/net/minecraft/world/level/block/entity/TileEntityBeehive.java +++ b/net/minecraft/world/level/block/entity/TileEntityBeehive.java @@ -42,6 +42,7 @@ private final List stored = Lists.newArrayList(); @Nullable public BlockPosition savedFlowerPos; + public int maxBees = 3; // CraftBukkit - allow setting max amount of bees a hive can hold public TileEntityBeehive(BlockPosition blockposition, IBlockData iblockdata) { super(TileEntityTypes.BEEHIVE, blockposition, iblockdata); @@ -81,7 +82,7 @@ } public boolean isFull() { - return this.stored.size() == 3; + return this.stored.size() == this.maxBees; // CraftBukkit } public void emptyAllLivingFromHive(@Nullable EntityHuman entityhuman, IBlockData iblockdata, TileEntityBeehive.ReleaseStatus tileentitybeehive_releasestatus) { @@ -98,7 +99,7 @@ if (entityhuman.position().distanceToSqr(entity.position()) <= 16.0D) { if (!this.isSedated()) { - entitybee.setTarget(entityhuman); + entitybee.setTarget(entityhuman, org.bukkit.event.entity.EntityTargetEvent.TargetReason.CLOSEST_PLAYER, true); // CraftBukkit } else { entitybee.setStayOutOfHiveCountdown(400); } @@ -110,10 +111,16 @@ } private List releaseAllOccupants(IBlockData iblockdata, TileEntityBeehive.ReleaseStatus tileentitybeehive_releasestatus) { + // CraftBukkit start - This allows us to bypass the night/rain/emergency check + return releaseBees(iblockdata, tileentitybeehive_releasestatus, false); + } + + public List releaseBees(IBlockData iblockdata, TileEntityBeehive.ReleaseStatus tileentitybeehive_releasestatus, boolean force) { List list = Lists.newArrayList(); this.stored.removeIf((tileentitybeehive_hivebee) -> { - return releaseOccupant(this.level, this.worldPosition, iblockdata, tileentitybeehive_hivebee, list, tileentitybeehive_releasestatus, this.savedFlowerPos); + return releaseBee(this.level, this.worldPosition, iblockdata, tileentitybeehive_hivebee, list, tileentitybeehive_releasestatus, this.savedFlowerPos, force); + // CraftBukkit end }); if (!list.isEmpty()) { super.setChanged(); @@ -141,7 +148,19 @@ } public void addOccupantWithPresetTicks(Entity entity, boolean flag, int i) { - if (this.stored.size() < 3) { + if (this.stored.size() < this.maxBees) { // CraftBukkit + // CraftBukkit start + if (this.level != null) { + org.bukkit.event.entity.EntityEnterBlockEvent event = new org.bukkit.event.entity.EntityEnterBlockEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(level, getBlockPos())); + org.bukkit.Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) { + if (entity instanceof EntityBee) { + ((EntityBee) entity).setStayOutOfHiveCountdown(400); + } + return; + } + } + // CraftBukkit end entity.stopRiding(); entity.ejectPassengers(); NBTTagCompound nbttagcompound = new NBTTagCompound(); @@ -172,7 +191,13 @@ } private static boolean releaseOccupant(World world, BlockPosition blockposition, IBlockData iblockdata, TileEntityBeehive.HiveBee tileentitybeehive_hivebee, @Nullable List list, TileEntityBeehive.ReleaseStatus tileentitybeehive_releasestatus, @Nullable BlockPosition blockposition1) { - if ((world.isNight() || world.isRaining()) && tileentitybeehive_releasestatus != TileEntityBeehive.ReleaseStatus.EMERGENCY) { + // CraftBukkit start - This allows us to bypass the night/rain/emergency check + return releaseBee(world, blockposition, iblockdata, tileentitybeehive_hivebee, list, tileentitybeehive_releasestatus, blockposition1, false); + } + + private static boolean releaseBee(World world, BlockPosition blockposition, IBlockData iblockdata, TileEntityBeehive.HiveBee tileentitybeehive_hivebee, @Nullable List list, TileEntityBeehive.ReleaseStatus tileentitybeehive_releasestatus, @Nullable BlockPosition blockposition1, boolean force) { + if (!force && (world.isNight() || world.isRaining()) && tileentitybeehive_releasestatus != TileEntityBeehive.ReleaseStatus.EMERGENCY) { + // CraftBukkit end return false; } else { NBTTagCompound nbttagcompound = tileentitybeehive_hivebee.entityData.copy(); @@ -195,6 +220,18 @@ if (!entity.getType().is(TagsEntity.BEEHIVE_INHABITORS)) { return false; } else { + // CraftBukkit start + if (entity instanceof EntityBee) { + 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(); + double d2 = (double) blockposition.getY() + 0.5D - (double) (entity.getBbHeight() / 2.0F); + double d3 = (double) blockposition.getZ() + 0.5D + d0 * (double) enumdirection.getStepZ(); + + entity.moveTo(d1, d2, d3, entity.getYRot(), entity.getXRot()); + } + if (!world.addFreshEntity(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.BEEHIVE)) return false; // CraftBukkit - SpawnReason, moved from below + // CraftBukkit end if (entity instanceof EntityBee) { EntityBee entitybee = (EntityBee) entity; @@ -226,6 +263,7 @@ list.add(entitybee); } + /* // CraftBukkit start 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(); @@ -233,10 +271,11 @@ double d3 = (double) blockposition.getZ() + 0.5D + d0 * (double) enumdirection.getStepZ(); entity.moveTo(d1, d2, d3, entity.getYRot(), entity.getXRot()); + */ // CraftBukkit end } world.playSound((EntityHuman) null, blockposition, SoundEffects.BEEHIVE_EXIT, SoundCategory.BLOCKS, 1.0F, 1.0F); - return world.addFreshEntity(entity); + return true; // return this.world.addFreshEntity(entity); // CraftBukkit - moved up } } else { return false; @@ -285,6 +324,10 @@ if (releaseOccupant(world, blockposition, iblockdata, tileentitybeehive_hivebee, (List) null, tileentitybeehive_releasestatus, blockposition1)) { flag = true; iterator.remove(); + // CraftBukkit start + } else { + tileentitybeehive_hivebee.ticksInHive = tileentitybeehive_hivebee.minOccupationTicks / 2; // Not strictly Vanilla behaviour in cases where bees cannot spawn but still reasonable + // CraftBukkit end } } } @@ -326,6 +369,11 @@ this.savedFlowerPos = GameProfileSerializer.readBlockPos(nbttagcompound.getCompound("FlowerPos")); } + // CraftBukkit start + if (nbttagcompound.contains("Bukkit.MaxEntities")) { + this.maxBees = nbttagcompound.getInt("Bukkit.MaxEntities"); + } + // CraftBukkit end } @Override @@ -335,6 +383,7 @@ if (this.hasSavedFlowerPos()) { nbttagcompound.put("FlowerPos", GameProfileSerializer.writeBlockPos(this.savedFlowerPos)); } + nbttagcompound.putInt("Bukkit.MaxEntities", this.maxBees); // CraftBukkit }