package com.five35.minecraft.greenthumb;

import net.minecraft.block.BlockDispenser;
import net.minecraft.dispenser.IBehaviorDispenseItem;
import net.minecraft.dispenser.IBlockSource;
import net.minecraft.item.ItemDye;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.util.FakePlayerFactory;

public class FertilizerDispenserBehavior implements IBehaviorDispenseItem {
	@Override
	public ItemStack dispense(final IBlockSource source, final ItemStack stack) {
		final EnumFacing facing = BlockDispenser.func_149937_b(source.getBlockMetadata());
		final World world = source.getWorld();
		final int x = source.getXInt();
		final int y = source.getYInt();
		final int z = source.getZInt();
		final int dx = facing.getFrontOffsetX();
		final int dy = facing.getFrontOffsetY();
		final int dz = facing.getFrontOffsetZ();

		if (world instanceof WorldServer) {
			if (ItemDye.applyBonemeal(stack, world, x + dx, y + dy, z + dz, FakePlayerFactory.getMinecraft((WorldServer) world))) {
				if (!world.isRemote) {
					// plant growth particles
					world.playAuxSFX(2005, x + dx, y + dy, z + dz, 0);
				}

				// dispenser "success" click
				world.playAuxSFX(1000, x, y, z, 0);
			} else {
				// dispenser "failure" click
				world.playAuxSFX(1001, x, y, z, 0);
			}
		}

		// smoke particles
		world.playAuxSFX(2000, x, y, z, dx + 1 + 3 * (dz + 1));

		return stack;
	}
}

@@ -275,26 +275,95 @@
 ft.util.
-EnumFacing
+BlockPos;%0Aimport net.minecraft.util.EnumFacing;%0Aimport net.minecraft.util.Vec3i
 ;%0Aimport
@@ -701,21 +701,17 @@
 ser.
-func_149937_b
+getFacing
 (sou
@@ -788,227 +788,95 @@
 nal 
-int x = source.getXInt();%0A%09%09final int y = source.getYInt();%0A%09%09final int z = source.getZInt();%0A%09%09final int dx = facing.getFrontOffsetX();%0A%09%09final int dy = facing.getFrontOffsetY();%0A%09%09final int dz = facing.getFrontOffsetZ
+BlockPos position = source.getBlockPos();%0A%09%09final Vec3i offset = facing.getDirectionVec
 ();%0A
@@ -957,38 +957,36 @@
  world, 
-x + dx, y + dy, z + dz
+position.add(offset)
 , FakePl
@@ -1125,30 +1125,28 @@
 05, 
-x + dx, y + dy, z + dz
+position.add(offset)
 , 0)
@@ -1214,23 +1214,24 @@
 X(1000, 
-x, y, z
+position
 , 0);%0A%09%09
@@ -1300,23 +1300,24 @@
 X(1001, 
-x, y, z
+position
 , 0);%0A%09%09
@@ -1374,33 +1374,78 @@
 00, 
-x, y, z, dx + 1 + 3 * (dz
+position, facing.getFrontOffsetX() + 1 + 3 * (facing.getFrontOffsetZ()
  + 1

update dispenser behavior for 1.8