Advertisement
Guest User

Untitled

a guest
Mar 12th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.72 KB | None | 0 0
  1. package com.theishiopian.foragecraft.blocks;
  2.  
  3. import net.minecraft.block.BlockHorizontal;
  4. import net.minecraft.block.SoundType;
  5. import net.minecraft.block.material.Material;
  6. import net.minecraft.block.properties.IProperty;
  7. import net.minecraft.block.state.BlockStateContainer;
  8. import net.minecraft.block.state.IBlockState;
  9. import net.minecraft.creativetab.CreativeTabs;
  10. import net.minecraft.entity.EntityLivingBase;
  11. import net.minecraft.util.BlockRenderLayer;
  12. import net.minecraft.util.EnumFacing;
  13. import net.minecraft.util.Mirror;
  14. import net.minecraft.util.Rotation;
  15. import net.minecraft.util.math.AxisAlignedBB;
  16. import net.minecraft.util.math.BlockPos;
  17. import net.minecraft.world.IBlockAccess;
  18. import net.minecraft.world.World;
  19. import net.minecraftforge.fml.relauncher.Side;
  20. import net.minecraftforge.fml.relauncher.SideOnly;
  21. import com.theishiopian.foragecraft.world.ScarecrowTracking;
  22.  
  23. public class Scarecrow extends BlockHorizontal
  24. {
  25.    
  26.     private final static AxisAlignedBB hitbox = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 2.0D, 1.0D);
  27.    
  28.     public Scarecrow()
  29.     {
  30.         super(Material.WOOD);
  31.         setUnlocalizedName("scarecrow");
  32.         setRegistryName("scarecrow");
  33.         setCreativeTab(CreativeTabs.DECORATIONS);
  34.         setSoundType(SoundType.WOOD);
  35.         this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
  36.        
  37.     }
  38.    
  39.     @Override
  40.     public void onBlockAdded(World world, BlockPos pos, IBlockState state)
  41.     {
  42.         ScarecrowTracking.get(world).addScarecrow(pos);
  43.     }
  44.     @Override
  45.     public void breakBlock(World world, BlockPos pos, IBlockState state)
  46.     {
  47.         ScarecrowTracking.get(world).removeScarecrow(pos);
  48.     }
  49.     @Override
  50.     public boolean isFullCube(IBlockState state)
  51.     {
  52.         return false;
  53.     }
  54.     @Override
  55.     public boolean isOpaqueCube(IBlockState state)
  56.     {
  57.         return false;
  58.     }
  59.     @SideOnly(Side.CLIENT)
  60.     public BlockRenderLayer getBlockLayer()
  61.     {
  62.         return BlockRenderLayer.CUTOUT;
  63.     }
  64.    
  65.     @Override
  66.     @SideOnly(Side.CLIENT)
  67.     public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
  68.     {
  69.         //return new AxisAlignedBB(pos.getX(), pos.getY(), pos.getZ(), pos.getX()+1, pos.getY()+2, pos.getZ()+1);
  70.         return hitbox;
  71.     }
  72.  
  73.     @Override
  74.     public AxisAlignedBB getSelectedBoundingBox(IBlockState state, World worldIn, BlockPos pos)
  75.     {
  76.         return hitbox;
  77.     }
  78.  
  79.    
  80.     @Override
  81.     protected BlockStateContainer createBlockState()
  82.     {
  83.         return new BlockStateContainer(this, new IProperty[] {FACING});
  84.     }
  85.    
  86.     @Override
  87.     public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
  88.     {
  89.         return worldIn.getBlockState(pos).getBlock().isReplaceable(worldIn, pos) && worldIn.getBlockState(pos.down()).isSideSolid(worldIn, pos, EnumFacing.UP);
  90.     }
  91.  
  92.     @Override
  93.     public IBlockState withRotation(IBlockState state, Rotation rot)
  94.     {
  95.         return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
  96.     }
  97.  
  98.     @Override
  99.     public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
  100.     {
  101.         return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
  102.     }
  103.  
  104.     @Override
  105.     public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
  106.     {
  107.         return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
  108.     }
  109.  
  110.     @Override
  111.     public IBlockState getStateFromMeta(int meta)
  112.     {
  113.         return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta));
  114.     }
  115.  
  116.     @Override
  117.     public int getMetaFromState(IBlockState state)
  118.     {
  119.         return ((EnumFacing)state.getValue(FACING)).getHorizontalIndex();
  120.     }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement