package common.block.foliage;

import common.block.Block;
import common.block.Rotatable;
import common.block.Material;
import common.entity.types.EntityLiving;
import common.item.CheatTab;
import common.model.Model;
import common.model.ModelProvider;
import common.model.ModelRotation;
import common.properties.Property;
import common.util.BlockPos;
import common.util.Facing;
import common.world.State;
import common.world.World;

public class BlockPumpkin extends Block implements Rotatable {
	public BlockPumpkin() {
		super(Material.SOFT);
		this.setDefaultState(this.getBaseState().withProperty(FACING, Facing.NORTH));
		this.setTab(CheatTab.PLANTS);
	}

	public boolean canPlaceBlockAt(World world, BlockPos pos) {
		return world.getState(pos).getBlock().getMaterial().isReplaceable() && world.isBlockSolid(pos.down());
	}

	public State onBlockPlaced(World world, BlockPos pos, Facing face, float hitX, float hitY, float hitZ, EntityLiving placer) {
		return this.getState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
	}

	public State getStateFromMeta(int meta) {
		return this.getState().withProperty(FACING, Facing.getHorizontal(meta));
	}

	public int getMetaFromState(State state) {
		return state.getValue(FACING).getHorizontalIndex();
	}

	protected Property[] getProperties() {
		return new Property[] {FACING};
	}

	public Model getModel(ModelProvider provider, String name, State state) {
		return provider.getModel("pumpkin_side").add().du("pumpkin_top").n("pumpkin_face_" + (this.getLightValue() == 0 ? "off" : "on")).s().we()
				.rotate(ModelRotation.getNorthRot(state.getValue(FACING)));
	}
}
