--- a/net/minecraft/world/level/block/entity/TileEntityBeehive.java
+++ b/net/minecraft/world/level/block/entity/TileEntityBeehive.java
@@ -43,6 +43,7 @@
     private final List<TileEntityBeehive.HiveBee> 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);
@@ -82,7 +83,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) {
@@ -99,7 +100,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);
                         }
@@ -111,10 +112,16 @@
     }
 
     private List<Entity> 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<Entity> releaseBees(IBlockData iblockdata, TileEntityBeehive.ReleaseStatus tileentitybeehive_releasestatus, boolean force) {
         List<Entity> 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();
@@ -142,7 +149,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();
@@ -174,7 +193,13 @@
     }
 
     private static boolean releaseOccupant(World world, BlockPosition blockposition, IBlockData iblockdata, TileEntityBeehive.HiveBee tileentitybeehive_hivebee, @Nullable List<Entity> 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<Entity> 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();
@@ -197,6 +222,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;
 
@@ -228,6 +265,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();
@@ -235,11 +273,12 @@
                             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);
                         world.gameEvent(GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of(entity, world.getBlockState(blockposition)));
-                        return world.addFreshEntity(entity);
+                        return true; // return this.world.addFreshEntity(entity); // CraftBukkit - moved up
                     }
                 } else {
                     return false;
@@ -288,6 +327,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
                 }
             }
         }
@@ -329,6 +372,11 @@
             this.savedFlowerPos = GameProfileSerializer.readBlockPos(nbttagcompound.getCompound("FlowerPos"));
         }
 
+        // CraftBukkit start
+        if (nbttagcompound.contains("Bukkit.MaxEntities")) {
+            this.maxBees = nbttagcompound.getInt("Bukkit.MaxEntities");
+        }
+        // CraftBukkit end
     }
 
     @Override
@@ -338,6 +386,7 @@
         if (this.hasSavedFlowerPos()) {
             nbttagcompound.put("FlowerPos", GameProfileSerializer.writeBlockPos(this.savedFlowerPos));
         }
+        nbttagcompound.putInt("Bukkit.MaxEntities", this.maxBees); // CraftBukkit
 
     }
 
