package common.block;

import java.util.List;

import common.entity.Entity;
import common.entity.npc.EntityNPC;
import common.entity.types.EntityLiving;
import common.init.Items;
import common.inventory.Container;
import common.inventory.InventoryHelper;
import common.item.Item;
import common.item.ItemStack;
import common.material.Material;
import common.model.BlockLayer;
import common.model.Model;
import common.model.ModelProvider;
import common.model.ParticleType;
import common.properties.IProperty;
import common.properties.PropertyBool;
import common.rng.Random;
import common.tileentity.TileEntity;
import common.tileentity.TileEntityBrewingStand;
import common.util.BlockPos;
import common.util.BoundingBox;
import common.util.Facing;
import common.world.AWorldClient;
import common.world.State;
import common.world.World;
import common.world.AWorldServer;

public class BlockBrewingStand extends BlockContainer
{
	private static final Model brewing_stand_bottles_2 = ModelProvider.getModelProvider().getModel("brewing_stand")
			.add(7, 0, 7, 9, 14, 9)
				.d().uv(7, 7, 9, 9).noCull()
				.u().uv(7, 7, 9, 9).noCull()
				.n().uv(7, 2, 9, 16).noCull()
				.s().uv(7, 2, 9, 16).noCull()
				.w().uv(7, 2, 9, 16).noCull()
				.e().uv(7, 2, 9, 16).noCull()
			.add(9, 0, 5, 15, 2, 11)
				.d("brewing_stand_base").uv(9, 5, 15, 11).noCull()
				.u("brewing_stand_base").uv(9, 5, 15, 11).noCull()
				.n("brewing_stand_base").uv(9, 14, 15, 16).noCull()
				.s("brewing_stand_base").uv(9, 14, 15, 16).noCull()
				.w("brewing_stand_base").uv(5, 14, 11, 16).noCull()
				.e("brewing_stand_base").uv(5, 14, 11, 16).noCull()
			.add(2, 0, 1, 8, 2, 7)
				.d("brewing_stand_base").uv(2, 1, 8, 7).noCull()
				.u("brewing_stand_base").uv(2, 1, 8, 7).noCull()
				.n("brewing_stand_base").uv(2, 14, 8, 16).noCull()
				.s("brewing_stand_base").uv(2, 14, 8, 16).noCull()
				.w("brewing_stand_base").uv(1, 14, 7, 16).noCull()
				.e("brewing_stand_base").uv(1, 14, 7, 16).noCull()
			.add(2, 0, 9, 8, 2, 15)
				.d("brewing_stand_base").uv(2, 9, 8, 15).noCull()
				.u("brewing_stand_base").uv(2, 9, 8, 15).noCull()
				.n("brewing_stand_base").uv(2, 14, 8, 16).noCull()
				.s("brewing_stand_base").uv(2, 14, 8, 16).noCull()
				.w("brewing_stand_base").uv(9, 14, 15, 16).noCull()
				.e("brewing_stand_base").uv(9, 14, 15, 16).noCull()
			.add(8, 0, 8, 16, 16, 8)
				.n().uv(16, 0, 8, 16).noCull()
				.s().uv(8, 0, 16, 16).noCull()
			.add(0, 0, 8, 8, 16, 8).rotate(8, 8, 8, Facing.Axis.Y, 45, true)
				.n().uv(8, 0, 16, 16).noCull()
				.s().uv(16, 0, 8, 16).noCull()
			.add(0, 0, 8, 8, 16, 8).rotate(8, 8, 8, Facing.Axis.Y, -45, true)
				.n().uv(8, 0, 0, 16).noCull()
				.s().uv(0, 0, 8, 16).noCull()
	;
	private static final Model brewing_stand_bottles_123 = ModelProvider.getModelProvider().getModel("brewing_stand")
			.add(7, 0, 7, 9, 14, 9)
				.d().uv(7, 7, 9, 9).noCull()
				.u().uv(7, 7, 9, 9).noCull()
				.n().uv(7, 2, 9, 16).noCull()
				.s().uv(7, 2, 9, 16).noCull()
				.w().uv(7, 2, 9, 16).noCull()
				.e().uv(7, 2, 9, 16).noCull()
			.add(9, 0, 5, 15, 2, 11)
				.d("brewing_stand_base").uv(9, 5, 15, 11).noCull()
				.u("brewing_stand_base").uv(9, 5, 15, 11).noCull()
				.n("brewing_stand_base").uv(9, 14, 15, 16).noCull()
				.s("brewing_stand_base").uv(9, 14, 15, 16).noCull()
				.w("brewing_stand_base").uv(5, 14, 11, 16).noCull()
				.e("brewing_stand_base").uv(5, 14, 11, 16).noCull()
			.add(2, 0, 1, 8, 2, 7)
				.d("brewing_stand_base").uv(2, 1, 8, 7).noCull()
				.u("brewing_stand_base").uv(2, 1, 8, 7).noCull()
				.n("brewing_stand_base").uv(2, 14, 8, 16).noCull()
				.s("brewing_stand_base").uv(2, 14, 8, 16).noCull()
				.w("brewing_stand_base").uv(1, 14, 7, 16).noCull()
				.e("brewing_stand_base").uv(1, 14, 7, 16).noCull()
			.add(2, 0, 9, 8, 2, 15)
				.d("brewing_stand_base").uv(2, 9, 8, 15).noCull()
				.u("brewing_stand_base").uv(2, 9, 8, 15).noCull()
				.n("brewing_stand_base").uv(2, 14, 8, 16).noCull()
				.s("brewing_stand_base").uv(2, 14, 8, 16).noCull()
				.w("brewing_stand_base").uv(9, 14, 15, 16).noCull()
				.e("brewing_stand_base").uv(9, 14, 15, 16).noCull()
			.add(8, 0, 8, 16, 16, 8)
				.n().uv(0, 0, 8, 16).noCull()
				.s().uv(8, 0, 0, 16).noCull()
			.add(0, 0, 8, 8, 16, 8).rotate(8, 8, 8, Facing.Axis.Y, 45, true)
				.n().uv(8, 0, 0, 16).noCull()
				.s().uv(0, 0, 8, 16).noCull()
			.add(0, 0, 8, 8, 16, 8).rotate(8, 8, 8, Facing.Axis.Y, -45, true)
				.n().uv(8, 0, 0, 16).noCull()
				.s().uv(0, 0, 8, 16).noCull()
	;
	private static final Model brewing_stand_empty = ModelProvider.getModelProvider().getModel("brewing_stand")
			.add(7, 0, 7, 9, 14, 9)
				.d().uv(7, 7, 9, 9).noCull()
				.u().uv(7, 7, 9, 9).noCull()
				.n().uv(7, 2, 9, 16).noCull()
				.s().uv(7, 2, 9, 16).noCull()
				.w().uv(7, 2, 9, 16).noCull()
				.e().uv(7, 2, 9, 16).noCull()
			.add(9, 0, 5, 15, 2, 11)
				.d("brewing_stand_base").uv(9, 5, 15, 11).noCull()
				.u("brewing_stand_base").uv(9, 5, 15, 11).noCull()
				.n("brewing_stand_base").uv(9, 14, 15, 16).noCull()
				.s("brewing_stand_base").uv(9, 14, 15, 16).noCull()
				.w("brewing_stand_base").uv(5, 14, 11, 16).noCull()
				.e("brewing_stand_base").uv(5, 14, 11, 16).noCull()
			.add(2, 0, 1, 8, 2, 7)
				.d("brewing_stand_base").uv(2, 1, 8, 7).noCull()
				.u("brewing_stand_base").uv(2, 1, 8, 7).noCull()
				.n("brewing_stand_base").uv(2, 14, 8, 16).noCull()
				.s("brewing_stand_base").uv(2, 14, 8, 16).noCull()
				.w("brewing_stand_base").uv(1, 14, 7, 16).noCull()
				.e("brewing_stand_base").uv(1, 14, 7, 16).noCull()
			.add(2, 0, 9, 8, 2, 15)
				.d("brewing_stand_base").uv(2, 9, 8, 15).noCull()
				.u("brewing_stand_base").uv(2, 9, 8, 15).noCull()
				.n("brewing_stand_base").uv(2, 14, 8, 16).noCull()
				.s("brewing_stand_base").uv(2, 14, 8, 16).noCull()
				.w("brewing_stand_base").uv(9, 14, 15, 16).noCull()
				.e("brewing_stand_base").uv(9, 14, 15, 16).noCull()
			.add(8, 0, 8, 16, 16, 8)
				.n().uv(16, 0, 8, 16).noCull()
				.s().uv(8, 0, 16, 16).noCull()
			.add(0, 0, 8, 8, 16, 8).rotate(8, 8, 8, Facing.Axis.Y, 45, true)
				.n().uv(8, 0, 16, 16).noCull()
				.s().uv(16, 0, 8, 16).noCull()
			.add(0, 0, 8, 8, 16, 8).rotate(8, 8, 8, Facing.Axis.Y, -45, true)
				.n().uv(8, 0, 16, 16).noCull()
				.s().uv(16, 0, 8, 16).noCull()
	;
	private static final Model brewing_stand_bottles_3 = ModelProvider.getModelProvider().getModel("brewing_stand")
			.add(7, 0, 7, 9, 14, 9)
				.d().uv(7, 7, 9, 9).noCull()
				.u().uv(7, 7, 9, 9).noCull()
				.n().uv(7, 2, 9, 16).noCull()
				.s().uv(7, 2, 9, 16).noCull()
				.w().uv(7, 2, 9, 16).noCull()
				.e().uv(7, 2, 9, 16).noCull()
			.add(9, 0, 5, 15, 2, 11)
				.d("brewing_stand_base").uv(9, 5, 15, 11).noCull()
				.u("brewing_stand_base").uv(9, 5, 15, 11).noCull()
				.n("brewing_stand_base").uv(9, 14, 15, 16).noCull()
				.s("brewing_stand_base").uv(9, 14, 15, 16).noCull()
				.w("brewing_stand_base").uv(5, 14, 11, 16).noCull()
				.e("brewing_stand_base").uv(5, 14, 11, 16).noCull()
			.add(2, 0, 1, 8, 2, 7)
				.d("brewing_stand_base").uv(2, 1, 8, 7).noCull()
				.u("brewing_stand_base").uv(2, 1, 8, 7).noCull()
				.n("brewing_stand_base").uv(2, 14, 8, 16).noCull()
				.s("brewing_stand_base").uv(2, 14, 8, 16).noCull()
				.w("brewing_stand_base").uv(1, 14, 7, 16).noCull()
				.e("brewing_stand_base").uv(1, 14, 7, 16).noCull()
			.add(2, 0, 9, 8, 2, 15)
				.d("brewing_stand_base").uv(2, 9, 8, 15).noCull()
				.u("brewing_stand_base").uv(2, 9, 8, 15).noCull()
				.n("brewing_stand_base").uv(2, 14, 8, 16).noCull()
				.s("brewing_stand_base").uv(2, 14, 8, 16).noCull()
				.w("brewing_stand_base").uv(9, 14, 15, 16).noCull()
				.e("brewing_stand_base").uv(9, 14, 15, 16).noCull()
			.add(8, 0, 8, 16, 16, 8)
				.n().uv(16, 0, 8, 16).noCull()
				.s().uv(8, 0, 16, 16).noCull()
			.add(0, 0, 8, 8, 16, 8).rotate(8, 8, 8, Facing.Axis.Y, 45, true)
				.n().uv(8, 0, 0, 16).noCull()
				.s().uv(0, 0, 8, 16).noCull()
			.add(0, 0, 8, 8, 16, 8).rotate(8, 8, 8, Facing.Axis.Y, -45, true)
				.n().uv(8, 0, 16, 16).noCull()
				.s().uv(16, 0, 8, 16).noCull()
	;
	private static final Model brewing_stand_bottles_13 = ModelProvider.getModelProvider().getModel("brewing_stand")
			.add(7, 0, 7, 9, 14, 9)
				.d().uv(7, 7, 9, 9).noCull()
				.u().uv(7, 7, 9, 9).noCull()
				.n().uv(7, 2, 9, 16).noCull()
				.s().uv(7, 2, 9, 16).noCull()
				.w().uv(7, 2, 9, 16).noCull()
				.e().uv(7, 2, 9, 16).noCull()
			.add(9, 0, 5, 15, 2, 11)
				.d("brewing_stand_base").uv(9, 5, 15, 11).noCull()
				.u("brewing_stand_base").uv(9, 5, 15, 11).noCull()
				.n("brewing_stand_base").uv(9, 14, 15, 16).noCull()
				.s("brewing_stand_base").uv(9, 14, 15, 16).noCull()
				.w("brewing_stand_base").uv(5, 14, 11, 16).noCull()
				.e("brewing_stand_base").uv(5, 14, 11, 16).noCull()
			.add(2, 0, 1, 8, 2, 7)
				.d("brewing_stand_base").uv(2, 1, 8, 7).noCull()
				.u("brewing_stand_base").uv(2, 1, 8, 7).noCull()
				.n("brewing_stand_base").uv(2, 14, 8, 16).noCull()
				.s("brewing_stand_base").uv(2, 14, 8, 16).noCull()
				.w("brewing_stand_base").uv(1, 14, 7, 16).noCull()
				.e("brewing_stand_base").uv(1, 14, 7, 16).noCull()
			.add(2, 0, 9, 8, 2, 15)
				.d("brewing_stand_base").uv(2, 9, 8, 15).noCull()
				.u("brewing_stand_base").uv(2, 9, 8, 15).noCull()
				.n("brewing_stand_base").uv(2, 14, 8, 16).noCull()
				.s("brewing_stand_base").uv(2, 14, 8, 16).noCull()
				.w("brewing_stand_base").uv(9, 14, 15, 16).noCull()
				.e("brewing_stand_base").uv(9, 14, 15, 16).noCull()
			.add(8, 0, 8, 16, 16, 8)
				.n().uv(0, 0, 8, 16).noCull()
				.s().uv(8, 0, 0, 16).noCull()
			.add(0, 0, 8, 8, 16, 8).rotate(8, 8, 8, Facing.Axis.Y, 45, true)
				.n().uv(8, 0, 0, 16).noCull()
				.s().uv(0, 0, 8, 16).noCull()
			.add(0, 0, 8, 8, 16, 8).rotate(8, 8, 8, Facing.Axis.Y, -45, true)
				.n().uv(8, 0, 16, 16).noCull()
				.s().uv(16, 0, 8, 16).noCull()
	;
	private static final Model brewing_stand_bottles_12 = ModelProvider.getModelProvider().getModel("brewing_stand")
			.add(7, 0, 7, 9, 14, 9)
				.d().uv(7, 7, 9, 9).noCull()
				.u().uv(7, 7, 9, 9).noCull()
				.n().uv(7, 2, 9, 16).noCull()
				.s().uv(7, 2, 9, 16).noCull()
				.w().uv(7, 2, 9, 16).noCull()
				.e().uv(7, 2, 9, 16).noCull()
			.add(9, 0, 5, 15, 2, 11)
				.d("brewing_stand_base").uv(9, 5, 15, 11).noCull()
				.u("brewing_stand_base").uv(9, 5, 15, 11).noCull()
				.n("brewing_stand_base").uv(9, 14, 15, 16).noCull()
				.s("brewing_stand_base").uv(9, 14, 15, 16).noCull()
				.w("brewing_stand_base").uv(5, 14, 11, 16).noCull()
				.e("brewing_stand_base").uv(5, 14, 11, 16).noCull()
			.add(2, 0, 1, 8, 2, 7)
				.d("brewing_stand_base").uv(2, 1, 8, 7).noCull()
				.u("brewing_stand_base").uv(2, 1, 8, 7).noCull()
				.n("brewing_stand_base").uv(2, 14, 8, 16).noCull()
				.s("brewing_stand_base").uv(2, 14, 8, 16).noCull()
				.w("brewing_stand_base").uv(1, 14, 7, 16).noCull()
				.e("brewing_stand_base").uv(1, 14, 7, 16).noCull()
			.add(2, 0, 9, 8, 2, 15)
				.d("brewing_stand_base").uv(2, 9, 8, 15).noCull()
				.u("brewing_stand_base").uv(2, 9, 8, 15).noCull()
				.n("brewing_stand_base").uv(2, 14, 8, 16).noCull()
				.s("brewing_stand_base").uv(2, 14, 8, 16).noCull()
				.w("brewing_stand_base").uv(9, 14, 15, 16).noCull()
				.e("brewing_stand_base").uv(9, 14, 15, 16).noCull()
			.add(8, 0, 8, 16, 16, 8)
				.n().uv(0, 0, 8, 16).noCull()
				.s().uv(8, 0, 0, 16).noCull()
			.add(0, 0, 8, 8, 16, 8).rotate(8, 8, 8, Facing.Axis.Y, 45, true)
				.n().uv(8, 0, 16, 16).noCull()
				.s().uv(16, 0, 8, 16).noCull()
			.add(0, 0, 8, 8, 16, 8).rotate(8, 8, 8, Facing.Axis.Y, -45, true)
				.n().uv(8, 0, 0, 16).noCull()
				.s().uv(0, 0, 8, 16).noCull()
	;
	private static final Model brewing_stand_bottles_23 = ModelProvider.getModelProvider().getModel("brewing_stand")
			.add(7, 0, 7, 9, 14, 9)
				.d().uv(7, 7, 9, 9).noCull()
				.u().uv(7, 7, 9, 9).noCull()
				.n().uv(7, 2, 9, 16).noCull()
				.s().uv(7, 2, 9, 16).noCull()
				.w().uv(7, 2, 9, 16).noCull()
				.e().uv(7, 2, 9, 16).noCull()
			.add(9, 0, 5, 15, 2, 11)
				.d("brewing_stand_base").uv(9, 5, 15, 11).noCull()
				.u("brewing_stand_base").uv(9, 5, 15, 11).noCull()
				.n("brewing_stand_base").uv(9, 14, 15, 16).noCull()
				.s("brewing_stand_base").uv(9, 14, 15, 16).noCull()
				.w("brewing_stand_base").uv(5, 14, 11, 16).noCull()
				.e("brewing_stand_base").uv(5, 14, 11, 16).noCull()
			.add(2, 0, 1, 8, 2, 7)
				.d("brewing_stand_base").uv(2, 1, 8, 7).noCull()
				.u("brewing_stand_base").uv(2, 1, 8, 7).noCull()
				.n("brewing_stand_base").uv(2, 14, 8, 16).noCull()
				.s("brewing_stand_base").uv(2, 14, 8, 16).noCull()
				.w("brewing_stand_base").uv(1, 14, 7, 16).noCull()
				.e("brewing_stand_base").uv(1, 14, 7, 16).noCull()
			.add(2, 0, 9, 8, 2, 15)
				.d("brewing_stand_base").uv(2, 9, 8, 15).noCull()
				.u("brewing_stand_base").uv(2, 9, 8, 15).noCull()
				.n("brewing_stand_base").uv(2, 14, 8, 16).noCull()
				.s("brewing_stand_base").uv(2, 14, 8, 16).noCull()
				.w("brewing_stand_base").uv(9, 14, 15, 16).noCull()
				.e("brewing_stand_base").uv(9, 14, 15, 16).noCull()
			.add(8, 0, 8, 16, 16, 8)
				.n().uv(16, 0, 8, 16).noCull()
				.s().uv(8, 0, 16, 16).noCull()
			.add(0, 0, 8, 8, 16, 8).rotate(8, 8, 8, Facing.Axis.Y, 45, true)
				.n().uv(8, 0, 0, 16).noCull()
				.s().uv(0, 0, 8, 16).noCull()
			.add(0, 0, 8, 8, 16, 8).rotate(8, 8, 8, Facing.Axis.Y, -45, true)
				.n().uv(8, 0, 0, 16).noCull()
				.s().uv(0, 0, 8, 16).noCull()
	;
	private static final Model brewing_stand_bottles_1 = ModelProvider.getModelProvider().getModel("brewing_stand")
			.add(7, 0, 7, 9, 14, 9)
				.d().uv(7, 7, 9, 9).noCull()
				.u().uv(7, 7, 9, 9).noCull()
				.n().uv(7, 2, 9, 16).noCull()
				.s().uv(7, 2, 9, 16).noCull()
				.w().uv(7, 2, 9, 16).noCull()
				.e().uv(7, 2, 9, 16).noCull()
			.add(9, 0, 5, 15, 2, 11)
				.d("brewing_stand_base").uv(9, 5, 15, 11).noCull()
				.u("brewing_stand_base").uv(9, 5, 15, 11).noCull()
				.n("brewing_stand_base").uv(9, 14, 15, 16).noCull()
				.s("brewing_stand_base").uv(9, 14, 15, 16).noCull()
				.w("brewing_stand_base").uv(5, 14, 11, 16).noCull()
				.e("brewing_stand_base").uv(5, 14, 11, 16).noCull()
			.add(2, 0, 1, 8, 2, 7)
				.d("brewing_stand_base").uv(2, 1, 8, 7).noCull()
				.u("brewing_stand_base").uv(2, 1, 8, 7).noCull()
				.n("brewing_stand_base").uv(2, 14, 8, 16).noCull()
				.s("brewing_stand_base").uv(2, 14, 8, 16).noCull()
				.w("brewing_stand_base").uv(1, 14, 7, 16).noCull()
				.e("brewing_stand_base").uv(1, 14, 7, 16).noCull()
			.add(2, 0, 9, 8, 2, 15)
				.d("brewing_stand_base").uv(2, 9, 8, 15).noCull()
				.u("brewing_stand_base").uv(2, 9, 8, 15).noCull()
				.n("brewing_stand_base").uv(2, 14, 8, 16).noCull()
				.s("brewing_stand_base").uv(2, 14, 8, 16).noCull()
				.w("brewing_stand_base").uv(9, 14, 15, 16).noCull()
				.e("brewing_stand_base").uv(9, 14, 15, 16).noCull()
			.add(8, 0, 8, 16, 16, 8)
				.n().uv(0, 0, 8, 16).noCull()
				.s().uv(8, 0, 0, 16).noCull()
			.add(0, 0, 8, 8, 16, 8).rotate(8, 8, 8, Facing.Axis.Y, 45, true)
				.n().uv(8, 0, 16, 16).noCull()
				.s().uv(16, 0, 8, 16).noCull()
			.add(0, 0, 8, 8, 16, 8).rotate(8, 8, 8, Facing.Axis.Y, -45, true)
				.n().uv(8, 0, 16, 16).noCull()
				.s().uv(16, 0, 8, 16).noCull()
	;
	private static final Model[] brewing_stand_bottles = new Model[] {
			brewing_stand_empty, brewing_stand_bottles_1, brewing_stand_bottles_2, brewing_stand_bottles_12, 
			brewing_stand_bottles_3, brewing_stand_bottles_13, brewing_stand_bottles_23, brewing_stand_bottles_123
	};
	
    public static final PropertyBool[] HAS_BOTTLE = new PropertyBool[] {PropertyBool.create("has_bottle_0"), PropertyBool.create("has_bottle_1"), PropertyBool.create("has_bottle_2")};

    public BlockBrewingStand()
    {
        super(Material.iron);
        this.setDefaultState(this.getBaseState().withProperty(HAS_BOTTLE[0], Boolean.valueOf(false)).withProperty(HAS_BOTTLE[1], Boolean.valueOf(false)).withProperty(HAS_BOTTLE[2], Boolean.valueOf(false)));
    }

//    /**
//     * Gets the localized name of this block. Used for the statistics page.
//     */
//    public String getLocalizedName()
//    {
//        return "Braustand";
//    }

    /**
     * Used to determine ambient occlusion and culling when rebuilding chunks for render
     */
    public boolean isOpaqueCube()
    {
        return false;
    }

    /**
     * The type of render function called. 3 for standard block models, 2 for TESR's, 1 for liquids, -1 is no render
     */
    public int getRenderType()
    {
        return 3;
    }

    /**
     * Returns a new instance of a block's tile entity class. Called on placing the block.
     */
    public TileEntity createNewTileEntity(World worldIn, int meta)
    {
        return new TileEntityBrewingStand();
    }

    public boolean isFullCube()
    {
        return false;
    }

    /**
     * Add all collision boxes of this Block to the list that intersect with the given mask.
     */
    public void addCollisionBoxesToList(World worldIn, BlockPos pos, State state, BoundingBox mask, List<BoundingBox> list, Entity collidingEntity)
    {
        this.setBlockBounds(0.4375F, 0.0F, 0.4375F, 0.5625F, 0.875F, 0.5625F);
        super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
        this.setBlockBoundsForItemRender();
        super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
    }

    /**
     * Sets the block's bounds for rendering it as an item
     */
    public void setBlockBoundsForItemRender()
    {
        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.125F, 1.0F);
    }

    public boolean onBlockActivated(World worldIn, BlockPos pos, State state, EntityNPC playerIn, Facing side, float hitX, float hitY, float hitZ)
    {
        if (worldIn.client)
        {
            return true;
        }
        else
        {
            TileEntity tileentity = worldIn.getTileEntity(pos);

            if (tileentity instanceof TileEntityBrewingStand)
            {
                playerIn.displayGUIChest((TileEntityBrewingStand)tileentity);
//                playerIn.triggerAchievement(StatRegistry.brewingStat);
            }

            return true;
        }
    }

    /**
     * Called by ItemBlocks after a block is set in the world, to allow post-place logic
     */
    public void onBlockPlacedBy(World worldIn, BlockPos pos, State state, EntityLiving placer, ItemStack stack)
    {
        if (stack.hasDisplayName())
        {
            TileEntity tileentity = worldIn.getTileEntity(pos);

            if (tileentity instanceof TileEntityBrewingStand)
            {
                ((TileEntityBrewingStand)tileentity).setName(stack.getDisplayName());
            }
        }
    }

    public void randomDisplayTick(AWorldClient worldIn, BlockPos pos, State state, Random rand)
    {
        double d0 = (double)((float)pos.getX() + 0.4F + rand.floatv() * 0.2F);
        double d1 = (double)((float)pos.getY() + 0.7F + rand.floatv() * 0.3F);
        double d2 = (double)((float)pos.getZ() + 0.4F + rand.floatv() * 0.2F);
        worldIn.spawnParticle(ParticleType.SMOKE_NORMAL, d0, d1, d2, 0.0D, 0.0D, 0.0D);
    }

    public void onBlockRemoved(AWorldServer worldIn, BlockPos pos, State state)
    {
        TileEntity tileentity = worldIn.getTileEntity(pos);

        if (tileentity instanceof TileEntityBrewingStand)
        {
            InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntityBrewingStand)tileentity);
        }

        super.onBlockRemoved(worldIn, pos, state);
    }

    /**
     * Get the Item that this Block should drop when harvested.
     */
    public Item getItemDropped(State state, Random rand, int fortune)
    {
        return Items.brewing_stand;
    }

    public Item getItem(World worldIn, BlockPos pos)
    {
        return Items.brewing_stand;
    }

    public boolean hasComparatorInputOverride()
    {
        return true;
    }

    public int getComparatorInputOverride(World worldIn, BlockPos pos)
    {
        return Container.calcRedstone(worldIn.getTileEntity(pos));
    }

    public BlockLayer getBlockLayer()
    {
        return BlockLayer.CUTOUT;
    }

    /**
     * Convert the given metadata into a BlockState for this Block
     */
    public State getStateFromMeta(int meta)
    {
        State iblockstate = this.getState();

        for (int i = 0; i < 3; ++i)
        {
            iblockstate = iblockstate.withProperty(HAS_BOTTLE[i], Boolean.valueOf((meta & 1 << i) > 0));
        }

        return iblockstate;
    }

    /**
     * Convert the BlockState into the correct metadata value
     */
    public int getMetaFromState(State state)
    {
        int i = 0;

        for (int j = 0; j < 3; ++j)
        {
            if (((Boolean)state.getValue(HAS_BOTTLE[j])).booleanValue())
            {
                i |= 1 << j;
            }
        }

        return i;
    }

    protected IProperty[] getProperties()
    {
        return new IProperty[] {HAS_BOTTLE[0], HAS_BOTTLE[1], HAS_BOTTLE[2]};
    }
    
    public boolean isMagnetic() {
    	return true;
    }

    public Model getModel(ModelProvider provider, String name, State state) {
    	return brewing_stand_bottles[(state.getValue(HAS_BOTTLE[0]) ? 1 : 0) | (state.getValue(HAS_BOTTLE[1]) ? 2 : 0) 
    			| (state.getValue(HAS_BOTTLE[2]) ? 4 : 0)];
    }
}
