--- a/net/minecraft/world/item/trading/MerchantRecipe.java
+++ b/net/minecraft/world/item/trading/MerchantRecipe.java
@@ -5,6 +5,8 @@
 import net.minecraft.util.MathHelper;
 import net.minecraft.world.item.ItemStack;
 
+import org.bukkit.craftbukkit.inventory.CraftMerchantRecipe; // CraftBukkit
+
 public class MerchantRecipe {
 
     public ItemStack baseCostA;
@@ -17,6 +19,22 @@
     public int demand;
     public float priceMultiplier;
     public int xp;
+    // CraftBukkit start
+    private CraftMerchantRecipe bukkitHandle;
+
+    public CraftMerchantRecipe asBukkit() {
+        return (bukkitHandle == null) ? bukkitHandle = new CraftMerchantRecipe(this) : bukkitHandle;
+    }
+
+    public MerchantRecipe(ItemStack itemstack, ItemStack itemstack1, ItemStack itemstack2, int uses, int maxUses, int experience, float priceMultiplier, CraftMerchantRecipe bukkit) {
+        this(itemstack, itemstack1, itemstack2, uses, maxUses, experience, priceMultiplier, 0, bukkit);
+    }
+
+    public MerchantRecipe(ItemStack itemstack, ItemStack itemstack1, ItemStack itemstack2, int uses, int maxUses, int experience, float priceMultiplier, int demand, CraftMerchantRecipe bukkit) {
+        this(itemstack, itemstack1, itemstack2, uses, maxUses, experience, priceMultiplier, demand);
+        this.bukkitHandle = bukkit;
+    }
+    // CraftBukkit end
 
     public MerchantRecipe(NBTTagCompound nbttagcompound) {
         this.rewardExp = true;
@@ -81,6 +99,7 @@
             return ItemStack.EMPTY;
         } else {
             int i = this.baseCostA.getCount();
+            if (i <= 0) return ItemStack.EMPTY; // CraftBukkit - SPIGOT-5476
             int j = Math.max(0, MathHelper.floor((float) (i * this.demand) * this.priceMultiplier));
 
             return this.baseCostA.copyWithCount(MathHelper.clamp(i + j + this.specialPriceDiff, 1, this.baseCostA.getItem().getMaxStackSize()));
@@ -201,7 +220,11 @@
         if (!this.satisfiedBy(itemstack, itemstack1)) {
             return false;
         } else {
-            itemstack.shrink(this.getCostA().getCount());
+            // CraftBukkit start
+            if (!this.getCostA().isEmpty()) {
+                itemstack.shrink(this.getCostA().getCount());
+            }
+            // CraftBukkit end
             if (!this.getCostB().isEmpty()) {
                 itemstack1.shrink(this.getCostB().getCount());
             }
