Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.theishiopian.foragecraft.blocks;
- import net.minecraft.block.BlockHorizontal;
- import net.minecraft.block.SoundType;
- import net.minecraft.block.material.Material;
- import net.minecraft.block.properties.IProperty;
- import net.minecraft.block.state.BlockStateContainer;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.creativetab.CreativeTabs;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.util.BlockRenderLayer;
- import net.minecraft.util.EnumFacing;
- import net.minecraft.util.Mirror;
- import net.minecraft.util.Rotation;
- import net.minecraft.util.math.AxisAlignedBB;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.world.IBlockAccess;
- import net.minecraft.world.World;
- import net.minecraftforge.fml.relauncher.Side;
- import net.minecraftforge.fml.relauncher.SideOnly;
- import com.theishiopian.foragecraft.world.ScarecrowTracking;
- public class Scarecrow extends BlockHorizontal
- {
- public Scarecrow()
- {
- super(Material.WOOD);
- setUnlocalizedName("scarecrow");
- setRegistryName("scarecrow");
- setCreativeTab(CreativeTabs.DECORATIONS);
- setSoundType(SoundType.WOOD);
- this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
- }
- @Override
- public void onBlockAdded(World world, BlockPos pos, IBlockState state)
- {
- ScarecrowTracking.get(world).addScarecrow(pos);
- }
- @Override
- public void breakBlock(World world, BlockPos pos, IBlockState state)
- {
- ScarecrowTracking.get(world).removeScarecrow(pos);
- }
- @Override
- public boolean isFullCube(IBlockState state)
- {
- return false;
- }
- @Override
- public boolean isOpaqueCube(IBlockState state)
- {
- return false;
- }
- @SideOnly(Side.CLIENT)
- public BlockRenderLayer getBlockLayer()
- {
- return BlockRenderLayer.CUTOUT;
- }
- @Override
- @SideOnly(Side.CLIENT)
- public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
- {
- return new AxisAlignedBB(pos.getX(), pos.getY(), pos.getZ(), pos.getX()+1, pos.getY()+2, pos.getZ()+1);
- }
- @Override
- public AxisAlignedBB getSelectedBoundingBox(IBlockState state, World worldIn, BlockPos pos)
- {
- return new AxisAlignedBB(pos.getX(), pos.getY(), pos.getZ(), pos.getX()+1, pos.getY()+2, pos.getZ()+1);
- }
- @Override
- protected BlockStateContainer createBlockState()
- {
- return new BlockStateContainer(this, new IProperty[] {FACING});
- }
- @Override
- public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
- {
- return worldIn.getBlockState(pos).getBlock().isReplaceable(worldIn, pos) && worldIn.getBlockState(pos.down()).isSideSolid(worldIn, pos, EnumFacing.UP);
- }
- @Override
- public IBlockState withRotation(IBlockState state, Rotation rot)
- {
- return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
- }
- @Override
- public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
- {
- return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
- }
- @Override
- public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
- {
- return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
- }
- @Override
- public IBlockState getStateFromMeta(int meta)
- {
- return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta));
- }
- @Override
- public int getMetaFromState(IBlockState state)
- {
- return ((EnumFacing)state.getValue(FACING)).getHorizontalIndex();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement