package net.glowstone.block.itemtype;

import net.glowstone.block.GlowBlock;
import net.glowstone.block.GlowBlockState;
import net.glowstone.entity.GlowPlayer;
import net.glowstone.block.ItemTable;
import net.glowstone.block.blocktype.BlockType;
import net.glowstone.block.blocktype.IBlockGrowable;

import org.bukkit.DyeColor;
import org.bukkit.Effect;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.TreeSpecies;
import org.bukkit.block.BlockFace;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.CocoaPlant;
import org.bukkit.material.CocoaPlant.CocoaPlantSize;
import org.bukkit.material.Dye;
import org.bukkit.material.MaterialData;
import org.bukkit.material.Tree;
import org.bukkit.util.Vector;

public class ItemDye extends ItemType {

    @Override
    public void rightClickBlock(GlowPlayer player, GlowBlock target, BlockFace face, ItemStack holding, Vector clickedLoc) {
        MaterialData data = holding.getData();
        if (data instanceof Dye) {
            final Dye dye = (Dye) data;

            if (dye.getColor() == DyeColor.WHITE) { // player interacts with bone meal in hand
                BlockType blockType = ItemTable.instance().getBlock(target.getType());
                if (blockType instanceof IBlockGrowable) {
                    IBlockGrowable growable = (IBlockGrowable) blockType;
                    if (growable.isFertilizable(target)) {
                        // spawn some green particles
                        target.getWorld().playEffect(target.getLocation(), Effect.BONEMEAL_USE, 0);

                        if (growable.canGrowWithChance(target)) {
                            growable.grow(player, target);
                        }

                        // deduct from stack if not in creative mode
                        if (player.getGameMode() != GameMode.CREATIVE) {
                            holding.setAmount(holding.getAmount() - 1);
                        }
                    }
                }
            } else if (dye.getColor() == DyeColor.BROWN && target.getType() == Material.LOG) {
                data = target.getState().getData();
                if (data instanceof Tree &&
                        ((Tree) data).getSpecies() == TreeSpecies.JUNGLE &&
                        target.getRelative(face).getType() == Material.AIR) {
                    final GlowBlockState state = target.getRelative(face).getState();
                    state.setType(Material.COCOA);
                    state.setData(new CocoaPlant(CocoaPlantSize.SMALL, face.getOppositeFace()));
                    state.update(true);

                    // deduct from stack if not in creative mode
                    if (player.getGameMode() != GameMode.CREATIVE) {
                        holding.setAmount(holding.getAmount() - 1);
                    }
                }
            }
        }
    }
}

@@ -2344,24 +2344,210 @@
 rial.AIR) %7B%0A
+                    switch (face) %7B%0A                        case NORTH:%0A                        case EAST:%0A                        case SOUTH:%0A                        case WEST:%0A        
             
@@ -2632,32 +2632,40 @@
                 
+        
 state.setType(Ma
@@ -2691,32 +2691,40 @@
                 
+  
+      
 state.setData(ne
@@ -2800,24 +2800,32 @@
             
+     
+   
 state.update
@@ -2829,24 +2829,32 @@
 ate(true);%0A%0A
+        
             
@@ -2918,32 +2918,40 @@
                 
+ 
+       
 if (player.getGa
@@ -2999,32 +2999,40 @@
                 
+    
+    
 holding.setAmoun
@@ -3051,32 +3051,165 @@
 tAmount() - 1);%0A
+                            %7D%0A                            break;%0A                        default:%0A                            break;%0A
                 

Fix cocoa beans placement check