package common.block;

import common.tileentity.TileEntity;
import common.util.BlockPos;
import common.util.Facing;
import common.world.State;
import common.world.World;
import common.world.AWorldServer;

public abstract class BlockContainer extends Block implements ITileEntityProvider {
	public BlockContainer(Material material) {
		super(material);
		this.hasTile = true;
	}

	protected boolean isInvalidNeighbor(World world, BlockPos pos, Facing face) {
		return world.getState(pos.offset(face)).getBlock().getMaterial() == Material.BLOCKING;
	}

	protected boolean hasInvalidNeighbor(World world, BlockPos pos) {
		return this.isInvalidNeighbor(world, pos, Facing.NORTH) || this.isInvalidNeighbor(world, pos, Facing.SOUTH)
				|| this.isInvalidNeighbor(world, pos, Facing.WEST) || this.isInvalidNeighbor(world, pos, Facing.EAST);
	}

	public int getRenderType() {
		return -1;
	}

	public void onBlockRemoved(AWorldServer world, BlockPos pos, State state) {
		super.onBlockRemoved(world, pos, state);
		world.removeTileEntity(pos);
	}

	public boolean onBlockEventReceived(World world, BlockPos pos, State state, int id, int param) {
		super.onBlockEventReceived(world, pos, state, id, param);
		TileEntity tile = world.getTileEntity(pos);
		return tile == null ? false : tile.receiveClientEvent(id, param);
	}
}
