package com.mrcrayfish.furniture.blocks;
import java.util.List;
import com.mrcrayfish.furniture.MrCrayfishFurnitureMod;
import com.mrcrayfish.furniture.entity.EntitySittableBlock;
import com.mrcrayfish.furniture.util.CollisionHelper;
import com.mrcrayfish.furniture.util.SittableUtil;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class BlockBench extends BlockFurniture
{
public static final PropertyBool LEFT = PropertyBool.create("left");
public static final PropertyBool RIGHT = PropertyBool.create("right");
public BlockBench(Material material)
{
super(material);
this.setHardness(1.0F);
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(LEFT, false).withProperty(RIGHT, false));
this.setCreativeTab(MrCrayfishFurnitureMod.tabFurniture);
}
@Override
public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
{
int metadata = getMetaFromState(worldIn.getBlockState(pos));
CollisionHelper.setBlockBounds(this, metadata, 1 * 0.0625F, 0.0F, 0.0F, 15 * 0.0625F, 10 * 0.0625F, 1.0F);
}
@Override
public void addCollisionBoxesToList(World worldIn, BlockPos pos, IBlockState state, AxisAlignedBB mask, List list, Entity collidingEntity)
{
if (!(collidingEntity instanceof EntitySittableBlock))
{
int metadata = getMetaFromState(state);
CollisionHelper.setBlockBounds(this, metadata, 2 * 0.0625F, 0.0F, 1 * 0.0625F, 14 * 0.0625F, 9 * 0.0625F, 15 * 0.0625F);
super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
}
}
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
EnumFacing facing = (EnumFacing) state.getValue(FACING);
if(facing == EnumFacing.NORTH | facing == EnumFacing.SOUTH)
{
IBlockState right = worldIn.getBlockState(pos.east());
IBlockState left = worldIn.getBlockState(pos.west());
if(worldIn.getBlockState(pos.east()).getBlock() == this && (right.getValue(FACING) == EnumFacing.NORTH | right.getValue(FACING) == EnumFacing.SOUTH))
{
state = state.withProperty(RIGHT, true);
}
if(worldIn.getBlockState(pos.west()).getBlock() == this && (left.getValue(FACING) == EnumFacing.NORTH | left.getValue(FACING) == EnumFacing.SOUTH))
{
state = state.withProperty(LEFT, true);
}
return state;
}
if(facing == EnumFacing.EAST | facing == EnumFacing.WEST)
{
IBlockState right = worldIn.getBlockState(pos.north());
IBlockState left = worldIn.getBlockState(pos.south());
if(right.getBlock() == this && (right.getValue(FACING) == EnumFacing.EAST | right.getValue(FACING) == EnumFacing.WEST))
{
state = state.withProperty(RIGHT, true);
}
if(left.getBlock() == this && (left.getValue(FACING) == EnumFacing.EAST | left.getValue(FACING) == EnumFacing.WEST))
{
state = state.withProperty(LEFT, true);
}
return state;
}
return state;
}
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
{
return SittableUtil.sitOnBlock(worldIn, pos.getX(), pos.getY(), pos.getZ(), playerIn, 0.4);
}
@Override
protected BlockState createBlockState()
{
return new BlockState(this, new IProperty[] { FACING, LEFT, RIGHT });
}
}