--- a/net/minecraft/core/dispenser/IDispenseBehavior.java
+++ b/net/minecraft/core/dispenser/IDispenseBehavior.java
@@ -79,6 +79,20 @@
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
+// CraftBukkit start
+import net.minecraft.world.item.ItemBucket;
+import net.minecraft.world.level.block.BlockSapling;
+import net.minecraft.world.level.block.IFluidContainer;
+import net.minecraft.world.level.material.Material;
+import org.bukkit.Location;
+import org.bukkit.TreeType;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.craftbukkit.util.DummyGeneratorAccess;
+import org.bukkit.event.block.BlockDispenseEvent;
+import org.bukkit.event.block.BlockFertilizeEvent;
+import org.bukkit.event.world.StructureGrowEvent;
+// CraftBukkit end
+
 public interface IDispenseBehavior {
 
     Logger LOGGER = LogManager.getLogger();
@@ -120,7 +134,7 @@
         BlockDispenser.a((IMaterial) Items.EGG, (IDispenseBehavior) (new DispenseBehaviorProjectile() {
             @Override
             protected IProjectile a(World world, IPosition iposition, ItemStack itemstack) {
-                return (IProjectile) SystemUtils.a((Object) (new EntityEgg(world, iposition.getX(), iposition.getY(), iposition.getZ())), (entityegg) -> {
+                return (IProjectile) SystemUtils.a((new EntityEgg(world, iposition.getX(), iposition.getY(), iposition.getZ())), (entityegg) -> { // CraftBukkit - decompile error
                     entityegg.setItem(itemstack);
                 });
             }
@@ -128,7 +142,7 @@
         BlockDispenser.a((IMaterial) Items.SNOWBALL, (IDispenseBehavior) (new DispenseBehaviorProjectile() {
             @Override
             protected IProjectile a(World world, IPosition iposition, ItemStack itemstack) {
-                return (IProjectile) SystemUtils.a((Object) (new EntitySnowball(world, iposition.getX(), iposition.getY(), iposition.getZ())), (entitysnowball) -> {
+                return (IProjectile) SystemUtils.a((new EntitySnowball(world, iposition.getX(), iposition.getY(), iposition.getZ())), (entitysnowball) -> { // CraftBukkit - decompile error
                     entitysnowball.setItem(itemstack);
                 });
             }
@@ -136,7 +150,7 @@
         BlockDispenser.a((IMaterial) Items.EXPERIENCE_BOTTLE, (IDispenseBehavior) (new DispenseBehaviorProjectile() {
             @Override
             protected IProjectile a(World world, IPosition iposition, ItemStack itemstack) {
-                return (IProjectile) SystemUtils.a((Object) (new EntityThrownExpBottle(world, iposition.getX(), iposition.getY(), iposition.getZ())), (entitythrownexpbottle) -> {
+                return (IProjectile) SystemUtils.a((new EntityThrownExpBottle(world, iposition.getX(), iposition.getY(), iposition.getZ())), (entitythrownexpbottle) -> { // CraftBukkit - decompile error
                     entitythrownexpbottle.setItem(itemstack);
                 });
             }
@@ -157,7 +171,7 @@
                 return (new DispenseBehaviorProjectile() {
                     @Override
                     protected IProjectile a(World world, IPosition iposition, ItemStack itemstack1) {
-                        return (IProjectile) SystemUtils.a((Object) (new EntityPotion(world, iposition.getX(), iposition.getY(), iposition.getZ())), (entitypotion) -> {
+                        return (IProjectile) SystemUtils.a((new EntityPotion(world, iposition.getX(), iposition.getY(), iposition.getZ())), (entitypotion) -> { // CraftBukkit - decompile error
                             entitypotion.setItem(itemstack1);
                         });
                     }
@@ -180,7 +194,7 @@
                 return (new DispenseBehaviorProjectile() {
                     @Override
                     protected IProjectile a(World world, IPosition iposition, ItemStack itemstack1) {
-                        return (IProjectile) SystemUtils.a((Object) (new EntityPotion(world, iposition.getX(), iposition.getY(), iposition.getZ())), (entitypotion) -> {
+                        return (IProjectile) SystemUtils.a((new EntityPotion(world, iposition.getX(), iposition.getY(), iposition.getZ())), (entitypotion) -> { // CraftBukkit - decompile error
                             entitypotion.setItem(itemstack1);
                         });
                     }
@@ -203,14 +217,42 @@
                 EnumDirection enumdirection = (EnumDirection) isourceblock.getBlockData().get(BlockDispenser.FACING);
                 EntityTypes entitytypes = ((ItemMonsterEgg) itemstack.getItem()).a(itemstack.getTag());
 
+                // CraftBukkit start
+                WorldServer worldserver = isourceblock.getWorld();
+                ItemStack itemstack1 = itemstack.cloneAndSubtract(1);
+                org.bukkit.block.Block block = worldserver.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
+                CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
+
+                BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(0, 0, 0));
+                if (!BlockDispenser.eventFired) {
+                    worldserver.getCraftServer().getPluginManager().callEvent(event);
+                }
+
+                if (event.isCancelled()) {
+                    itemstack.add(1);
+                    return itemstack;
+                }
+
+                if (!event.getItem().equals(craftItem)) {
+                    itemstack.add(1);
+                    // Chain to handler for new item
+                    ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
+                    IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.DISPENSER_REGISTRY.get(eventStack.getItem());
+                    if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != this) {
+                        idispensebehavior.dispense(isourceblock, eventStack);
+                        return itemstack;
+                    }
+                }
+
                 try {
                     entitytypes.spawnCreature(isourceblock.getWorld(), itemstack, (EntityHuman) null, isourceblock.getBlockPosition().shift(enumdirection), EnumMobSpawn.DISPENSER, enumdirection != EnumDirection.UP, false);
                 } catch (Exception exception) {
-                    null.LOGGER.error("Error while dispensing spawn egg from dispenser at {}", isourceblock.getBlockPosition(), exception);
+                    LOGGER.error("Error while dispensing spawn egg from dispenser at {}", isourceblock.getBlockPosition(), exception); // CraftBukkit - decompile error
                     return ItemStack.EMPTY;
                 }
 
-                itemstack.subtract(1);
+                // itemstack.subtract(1); // Handled during event processing
+                // CraftBukkit end
                 isourceblock.getWorld().a(GameEvent.ENTITY_PLACE, isourceblock.getBlockPosition());
                 return itemstack;
             }
@@ -229,12 +271,40 @@
                 EnumDirection enumdirection = (EnumDirection) isourceblock.getBlockData().get(BlockDispenser.FACING);
                 BlockPosition blockposition = isourceblock.getBlockPosition().shift(enumdirection);
                 WorldServer worldserver = isourceblock.getWorld();
+
+                // CraftBukkit start
+                ItemStack itemstack1 = itemstack.cloneAndSubtract(1);
+                org.bukkit.block.Block block = worldserver.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
+                CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
+
+                BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(0, 0, 0));
+                if (!BlockDispenser.eventFired) {
+                    worldserver.getCraftServer().getPluginManager().callEvent(event);
+                }
+
+                if (event.isCancelled()) {
+                    itemstack.add(1);
+                    return itemstack;
+                }
+
+                if (!event.getItem().equals(craftItem)) {
+                    itemstack.add(1);
+                    // Chain to handler for new item
+                    ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
+                    IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.DISPENSER_REGISTRY.get(eventStack.getItem());
+                    if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != this) {
+                        idispensebehavior.dispense(isourceblock, eventStack);
+                        return itemstack;
+                    }
+                }
+                // CraftBukkit end
+
                 EntityArmorStand entityarmorstand = new EntityArmorStand(worldserver, (double) blockposition.getX() + 0.5D, (double) blockposition.getY(), (double) blockposition.getZ() + 0.5D);
 
                 EntityTypes.a((World) worldserver, (EntityHuman) null, (Entity) entityarmorstand, itemstack.getTag());
                 entityarmorstand.setYRot(enumdirection.o());
                 worldserver.addEntity(entityarmorstand);
-                itemstack.subtract(1);
+                // itemstack.subtract(1); // CraftBukkit - Handled during event processing
                 return itemstack;
             }
         }));
@@ -335,12 +405,41 @@
             @Override
             public ItemStack a(ISourceBlock isourceblock, ItemStack itemstack) {
                 EnumDirection enumdirection = (EnumDirection) isourceblock.getBlockData().get(BlockDispenser.FACING);
+                // CraftBukkit start
+                WorldServer worldserver = isourceblock.getWorld();
+                ItemStack itemstack1 = itemstack.cloneAndSubtract(1);
+                org.bukkit.block.Block block = worldserver.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
+                CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
+
+                BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(enumdirection.getAdjacentX(), enumdirection.getAdjacentY(), enumdirection.getAdjacentZ()));
+                if (!BlockDispenser.eventFired) {
+                    worldserver.getCraftServer().getPluginManager().callEvent(event);
+                }
+
+                if (event.isCancelled()) {
+                    itemstack.add(1);
+                    return itemstack;
+                }
+
+                if (!event.getItem().equals(craftItem)) {
+                    itemstack.add(1);
+                    // Chain to handler for new item
+                    ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
+                    IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.DISPENSER_REGISTRY.get(eventStack.getItem());
+                    if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != this) {
+                        idispensebehavior.dispense(isourceblock, eventStack);
+                        return itemstack;
+                    }
+                }
+
+                itemstack1 = CraftItemStack.asNMSCopy(event.getItem());
                 EntityFireworks entityfireworks = new EntityFireworks(isourceblock.getWorld(), itemstack, isourceblock.getX(), isourceblock.getY(), isourceblock.getX(), true);
 
                 IDispenseBehavior.a(isourceblock, entityfireworks, enumdirection);
                 entityfireworks.shoot((double) enumdirection.getAdjacentX(), (double) enumdirection.getAdjacentY(), (double) enumdirection.getAdjacentZ(), 0.5F, 1.0F);
                 isourceblock.getWorld().addEntity(entityfireworks);
-                itemstack.subtract(1);
+                // itemstack.subtract(1); // Handled during event processing
+                // CraftBukkit end
                 return itemstack;
             }
 
@@ -362,12 +461,40 @@
                 double d3 = random.nextGaussian() * 0.05D + (double) enumdirection.getAdjacentX();
                 double d4 = random.nextGaussian() * 0.05D + (double) enumdirection.getAdjacentY();
                 double d5 = random.nextGaussian() * 0.05D + (double) enumdirection.getAdjacentZ();
-                EntitySmallFireball entitysmallfireball = new EntitySmallFireball(worldserver, d0, d1, d2, d3, d4, d5);
 
-                worldserver.addEntity((Entity) SystemUtils.a((Object) entitysmallfireball, (entitysmallfireball1) -> {
-                    entitysmallfireball1.setItem(itemstack);
-                }));
-                itemstack.subtract(1);
+                // CraftBukkit start
+                ItemStack itemstack1 = itemstack.cloneAndSubtract(1);
+                org.bukkit.block.Block block = worldserver.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
+                CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
+
+                BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(d3, d4, d5));
+                if (!BlockDispenser.eventFired) {
+                    worldserver.getCraftServer().getPluginManager().callEvent(event);
+                }
+
+                if (event.isCancelled()) {
+                    itemstack.add(1);
+                    return itemstack;
+                }
+
+                if (!event.getItem().equals(craftItem)) {
+                    itemstack.add(1);
+                    // Chain to handler for new item
+                    ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
+                    IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.DISPENSER_REGISTRY.get(eventStack.getItem());
+                    if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != this) {
+                        idispensebehavior.dispense(isourceblock, eventStack);
+                        return itemstack;
+                    }
+                }
+
+                EntitySmallFireball entitysmallfireball = new EntitySmallFireball(worldserver, d0, d1, d2, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ());
+                entitysmallfireball.setItem(itemstack1);
+                entitysmallfireball.projectileSource = new org.bukkit.craftbukkit.projectiles.CraftBlockProjectileSource((TileEntityDispenser) isourceblock.getTileEntity());
+
+                worldserver.addEntity(entitysmallfireball);
+                // itemstack.subtract(1); // Handled during event processing
+                // CraftBukkit end
                 return itemstack;
             }
 
@@ -391,9 +518,52 @@
                 BlockPosition blockposition = isourceblock.getBlockPosition().shift((EnumDirection) isourceblock.getBlockData().get(BlockDispenser.FACING));
                 WorldServer worldserver = isourceblock.getWorld();
 
+                // CraftBukkit start
+                int x = blockposition.getX();
+                int y = blockposition.getY();
+                int z = blockposition.getZ();
+                IBlockData iblockdata = worldserver.getType(blockposition);
+                Material material = iblockdata.getMaterial();
+                if (worldserver.isEmpty(blockposition) || !material.isBuildable() || material.isReplaceable() || (dispensiblecontaineritem instanceof ItemBucket && iblockdata.getBlock() instanceof IFluidContainer && ((IFluidContainer) iblockdata.getBlock()).canPlace(worldserver, blockposition, iblockdata, ((ItemBucket) dispensiblecontaineritem).content))) {
+                    org.bukkit.block.Block block = worldserver.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
+                    CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack);
+
+                    BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(x, y, z));
+                    if (!BlockDispenser.eventFired) {
+                        worldserver.getCraftServer().getPluginManager().callEvent(event);
+                    }
+
+                    if (event.isCancelled()) {
+                        return itemstack;
+                    }
+
+                    if (!event.getItem().equals(craftItem)) {
+                        // Chain to handler for new item
+                        ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
+                        IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.DISPENSER_REGISTRY.get(eventStack.getItem());
+                        if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != this) {
+                            idispensebehavior.dispense(isourceblock, eventStack);
+                            return itemstack;
+                        }
+                    }
+
+                    dispensiblecontaineritem = (DispensibleContainerItem) CraftItemStack.asNMSCopy(event.getItem()).getItem();
+                }
+                // CraftBukkit end
+
                 if (dispensiblecontaineritem.a((EntityHuman) null, worldserver, blockposition, (MovingObjectPositionBlock) null)) {
                     dispensiblecontaineritem.a((EntityHuman) null, worldserver, itemstack, blockposition);
-                    return new ItemStack(Items.BUCKET);
+                    // CraftBukkit start - Handle stacked buckets
+                    Item item = Items.BUCKET;
+                    itemstack.subtract(1);
+                    if (itemstack.isEmpty()) {
+                        itemstack.setItem(Items.BUCKET);
+                        itemstack.setCount(1);
+                    } else if (((TileEntityDispenser) isourceblock.getTileEntity()).addItem(new ItemStack(item)) < 0) {
+                        this.defaultDispenseItemBehavior.dispense(isourceblock, new ItemStack(item));
+                    }
+                    // CraftBukkit end
+                    return itemstack;
                 } else {
                     return this.defaultDispenseItemBehavior.dispense(isourceblock, itemstack);
                 }
@@ -419,7 +589,7 @@
                 Block block = iblockdata.getBlock();
 
                 if (block instanceof IFluidSource) {
-                    ItemStack itemstack1 = ((IFluidSource) block).removeFluid(worldserver, blockposition, iblockdata);
+                    ItemStack itemstack1 = ((IFluidSource) block).removeFluid(DummyGeneratorAccess.INSTANCE, blockposition, iblockdata); // CraftBukkit
 
                     if (itemstack1.isEmpty()) {
                         return super.a(isourceblock, itemstack);
@@ -427,6 +597,32 @@
                         worldserver.a((Entity) null, GameEvent.FLUID_PICKUP, blockposition);
                         Item item = itemstack1.getItem();
 
+                        // CraftBukkit start
+                        org.bukkit.block.Block bukkitBlock = worldserver.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
+                        CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack);
+
+                        BlockDispenseEvent event = new BlockDispenseEvent(bukkitBlock, craftItem.clone(), new org.bukkit.util.Vector(blockposition.getX(), blockposition.getY(), blockposition.getZ()));
+                        if (!BlockDispenser.eventFired) {
+                            worldserver.getCraftServer().getPluginManager().callEvent(event);
+                        }
+
+                        if (event.isCancelled()) {
+                            return itemstack;
+                        }
+
+                        if (!event.getItem().equals(craftItem)) {
+                            // Chain to handler for new item
+                            ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
+                            IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.DISPENSER_REGISTRY.get(eventStack.getItem());
+                            if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != this) {
+                                idispensebehavior.dispense(isourceblock, eventStack);
+                                return itemstack;
+                            }
+                        }
+
+                        itemstack1 = ((IFluidSource) block).removeFluid(worldserver, blockposition, iblockdata); // From above
+                        // CraftBukkit end
+
                         itemstack.subtract(1);
                         if (itemstack.isEmpty()) {
                             return new ItemStack(item);
@@ -448,14 +644,42 @@
             protected ItemStack a(ISourceBlock isourceblock, ItemStack itemstack) {
                 WorldServer worldserver = isourceblock.getWorld();
 
+                // CraftBukkit start
+                org.bukkit.block.Block bukkitBlock = worldserver.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
+                CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack);
+
+                BlockDispenseEvent event = new BlockDispenseEvent(bukkitBlock, craftItem.clone(), new org.bukkit.util.Vector(0, 0, 0));
+                if (!BlockDispenser.eventFired) {
+                    worldserver.getCraftServer().getPluginManager().callEvent(event);
+                }
+
+                if (event.isCancelled()) {
+                    return itemstack;
+                }
+
+                if (!event.getItem().equals(craftItem)) {
+                    // Chain to handler for new item
+                    ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
+                    IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.DISPENSER_REGISTRY.get(eventStack.getItem());
+                    if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != this) {
+                        idispensebehavior.dispense(isourceblock, eventStack);
+                        return itemstack;
+                    }
+                }
+                // CraftBukkit end
+
                 this.a(true);
                 EnumDirection enumdirection = (EnumDirection) isourceblock.getBlockData().get(BlockDispenser.FACING);
                 BlockPosition blockposition = isourceblock.getBlockPosition().shift(enumdirection);
                 IBlockData iblockdata = worldserver.getType(blockposition);
 
                 if (BlockFireAbstract.a((World) worldserver, blockposition, enumdirection)) {
-                    worldserver.setTypeUpdate(blockposition, BlockFireAbstract.a((IBlockAccess) worldserver, blockposition));
-                    worldserver.a((Entity) null, GameEvent.BLOCK_PLACE, blockposition);
+                    // CraftBukkit start - Ignition by dispensing flint and steel
+                    if (!org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(worldserver, blockposition, isourceblock.getBlockPosition()).isCancelled()) {
+                        worldserver.setTypeUpdate(blockposition, BlockFireAbstract.a((IBlockAccess) worldserver, blockposition));
+                        worldserver.a((Entity) null, GameEvent.BLOCK_PLACE, blockposition);
+                    }
+                    // CraftBukkit end
                 } else if (!BlockCampfire.h(iblockdata) && !CandleBlock.g(iblockdata) && !CandleCakeBlock.g(iblockdata)) {
                     if (iblockdata.getBlock() instanceof BlockTNT) {
                         BlockTNT.a((World) worldserver, blockposition);
@@ -481,12 +705,62 @@
                 this.a(true);
                 WorldServer worldserver = isourceblock.getWorld();
                 BlockPosition blockposition = isourceblock.getBlockPosition().shift((EnumDirection) isourceblock.getBlockData().get(BlockDispenser.FACING));
+                // CraftBukkit start
+                org.bukkit.block.Block block = worldserver.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
+                CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack);
+
+                BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(0, 0, 0));
+                if (!BlockDispenser.eventFired) {
+                    worldserver.getCraftServer().getPluginManager().callEvent(event);
+                }
+
+                if (event.isCancelled()) {
+                    return itemstack;
+                }
+
+                if (!event.getItem().equals(craftItem)) {
+                    // Chain to handler for new item
+                    ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
+                    IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.DISPENSER_REGISTRY.get(eventStack.getItem());
+                    if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != this) {
+                        idispensebehavior.dispense(isourceblock, eventStack);
+                        return itemstack;
+                    }
+                }
+
+                worldserver.captureTreeGeneration = true;
+                // CraftBukkit end
 
                 if (!ItemBoneMeal.a(itemstack, (World) worldserver, blockposition) && !ItemBoneMeal.a(itemstack, (World) worldserver, blockposition, (EnumDirection) null)) {
                     this.a(false);
                 } else if (!worldserver.isClientSide) {
                     worldserver.triggerEffect(1505, blockposition, 0);
                 }
+                // CraftBukkit start
+                worldserver.captureTreeGeneration = false;
+                if (worldserver.capturedBlockStates.size() > 0) {
+                    TreeType treeType = BlockSapling.treeType;
+                    BlockSapling.treeType = null;
+                    Location location = new Location(worldserver.getWorld(), blockposition.getX(), blockposition.getY(), blockposition.getZ());
+                    List<org.bukkit.block.BlockState> blocks = new java.util.ArrayList<>(worldserver.capturedBlockStates.values());
+                    worldserver.capturedBlockStates.clear();
+                    StructureGrowEvent structureEvent = null;
+                    if (treeType != null) {
+                        structureEvent = new StructureGrowEvent(location, treeType, false, null, blocks);
+                        org.bukkit.Bukkit.getPluginManager().callEvent(structureEvent);
+                    }
+
+                    BlockFertilizeEvent fertilizeEvent = new BlockFertilizeEvent(location.getBlock(), null, blocks);
+                    fertilizeEvent.setCancelled(structureEvent != null && structureEvent.isCancelled());
+                    org.bukkit.Bukkit.getPluginManager().callEvent(fertilizeEvent);
+
+                    if (!fertilizeEvent.isCancelled()) {
+                        for (org.bukkit.block.BlockState blockstate : blocks) {
+                            blockstate.update(true);
+                        }
+                    }
+                }
+                // CraftBukkit end
 
                 return itemstack;
             }
@@ -496,12 +770,41 @@
             protected ItemStack a(ISourceBlock isourceblock, ItemStack itemstack) {
                 WorldServer worldserver = isourceblock.getWorld();
                 BlockPosition blockposition = isourceblock.getBlockPosition().shift((EnumDirection) isourceblock.getBlockData().get(BlockDispenser.FACING));
-                EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(worldserver, (double) blockposition.getX() + 0.5D, (double) blockposition.getY(), (double) blockposition.getZ() + 0.5D, (EntityLiving) null);
+                // EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(worldserver, (double) blockposition.getX() + 0.5D, (double) blockposition.getY(), (double) blockposition.getZ() + 0.5D, (EntityLiving) null);
+
+                // CraftBukkit start
+                ItemStack itemstack1 = itemstack.cloneAndSubtract(1);
+                org.bukkit.block.Block block = worldserver.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
+                CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
+
+                BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector((double) blockposition.getX() + 0.5D, (double) blockposition.getY(), (double) blockposition.getZ() + 0.5D));
+                if (!BlockDispenser.eventFired) {
+                   worldserver.getCraftServer().getPluginManager().callEvent(event);
+                }
+
+                if (event.isCancelled()) {
+                    itemstack.add(1);
+                    return itemstack;
+                }
+
+                if (!event.getItem().equals(craftItem)) {
+                    itemstack.add(1);
+                    // Chain to handler for new item
+                    ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
+                    IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.DISPENSER_REGISTRY.get(eventStack.getItem());
+                    if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != this) {
+                        idispensebehavior.dispense(isourceblock, eventStack);
+                        return itemstack;
+                    }
+                }
+
+                EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(worldserver, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ(), (EntityLiving) null);
+                // CraftBukkit end
 
                 worldserver.addEntity(entitytntprimed);
                 worldserver.playSound((EntityHuman) null, entitytntprimed.locX(), entitytntprimed.locY(), entitytntprimed.locZ(), SoundEffects.TNT_PRIMED, SoundCategory.BLOCKS, 1.0F, 1.0F);
                 worldserver.a((Entity) null, GameEvent.ENTITY_PLACE, blockposition);
-                itemstack.subtract(1);
+                // itemstack.subtract(1); // CraftBukkit - handled above
                 return itemstack;
             }
         }));
@@ -525,6 +828,30 @@
                 EnumDirection enumdirection = (EnumDirection) isourceblock.getBlockData().get(BlockDispenser.FACING);
                 BlockPosition blockposition = isourceblock.getBlockPosition().shift(enumdirection);
 
+                // CraftBukkit start
+                org.bukkit.block.Block bukkitBlock = worldserver.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
+                CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack);
+
+                BlockDispenseEvent event = new BlockDispenseEvent(bukkitBlock, craftItem.clone(), new org.bukkit.util.Vector(blockposition.getX(), blockposition.getY(), blockposition.getZ()));
+                if (!BlockDispenser.eventFired) {
+                    worldserver.getCraftServer().getPluginManager().callEvent(event);
+                }
+
+                if (event.isCancelled()) {
+                    return itemstack;
+                }
+
+                if (!event.getItem().equals(craftItem)) {
+                    // Chain to handler for new item
+                    ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
+                    IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.DISPENSER_REGISTRY.get(eventStack.getItem());
+                    if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != this) {
+                        idispensebehavior.dispense(isourceblock, eventStack);
+                        return itemstack;
+                    }
+                }
+                // CraftBukkit end
+
                 if (worldserver.isEmpty(blockposition) && BlockWitherSkull.b((World) worldserver, blockposition, itemstack)) {
                     worldserver.setTypeAndData(blockposition, (IBlockData) Blocks.WITHER_SKELETON_SKULL.getBlockData().set(BlockSkull.ROTATION, enumdirection.n() == EnumDirection.EnumAxis.Y ? 0 : enumdirection.opposite().get2DRotationValue() * 4), 3);
                     worldserver.a((Entity) null, GameEvent.BLOCK_PLACE, blockposition);
@@ -550,6 +877,30 @@
                 BlockPosition blockposition = isourceblock.getBlockPosition().shift((EnumDirection) isourceblock.getBlockData().get(BlockDispenser.FACING));
                 BlockPumpkinCarved blockpumpkincarved = (BlockPumpkinCarved) Blocks.CARVED_PUMPKIN;
 
+                // CraftBukkit start
+                org.bukkit.block.Block bukkitBlock = worldserver.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
+                CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack);
+
+                BlockDispenseEvent event = new BlockDispenseEvent(bukkitBlock, craftItem.clone(), new org.bukkit.util.Vector(blockposition.getX(), blockposition.getY(), blockposition.getZ()));
+                if (!BlockDispenser.eventFired) {
+                    worldserver.getCraftServer().getPluginManager().callEvent(event);
+                }
+
+                if (event.isCancelled()) {
+                    return itemstack;
+                }
+
+                if (!event.getItem().equals(craftItem)) {
+                    // Chain to handler for new item
+                    ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
+                    IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.DISPENSER_REGISTRY.get(eventStack.getItem());
+                    if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != this) {
+                        idispensebehavior.dispense(isourceblock, eventStack);
+                        return itemstack;
+                    }
+                }
+                // CraftBukkit end
+
                 if (worldserver.isEmpty(blockposition) && blockpumpkincarved.a((IWorldReader) worldserver, blockposition)) {
                     if (!worldserver.isClientSide) {
                         worldserver.setTypeAndData(blockposition, blockpumpkincarved.getBlockData(), 3);
@@ -599,6 +950,30 @@
                 BlockPosition blockposition = isourceblock.getBlockPosition().shift((EnumDirection) isourceblock.getBlockData().get(BlockDispenser.FACING));
                 IBlockData iblockdata = worldserver.getType(blockposition);
 
+                // CraftBukkit start
+                org.bukkit.block.Block bukkitBlock = worldserver.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
+                CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack);
+
+                BlockDispenseEvent event = new BlockDispenseEvent(bukkitBlock, craftItem.clone(), new org.bukkit.util.Vector(blockposition.getX(), blockposition.getY(), blockposition.getZ()));
+                if (!BlockDispenser.eventFired) {
+                    worldserver.getCraftServer().getPluginManager().callEvent(event);
+                }
+
+                if (event.isCancelled()) {
+                    return itemstack;
+                }
+
+                if (!event.getItem().equals(craftItem)) {
+                    // Chain to handler for new item
+                    ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
+                    IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.DISPENSER_REGISTRY.get(eventStack.getItem());
+                    if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != this) {
+                        idispensebehavior.dispense(isourceblock, eventStack);
+                        return itemstack;
+                    }
+                }
+                // CraftBukkit end
+
                 if (iblockdata.a((Tag) TagsBlock.BEEHIVES, (blockbase_blockdata) -> {
                     return blockbase_blockdata.b(BlockBeehive.HONEY_LEVEL);
                 }) && (Integer) iblockdata.get(BlockBeehive.HONEY_LEVEL) >= 5) {
