Advertisement
Guest User

Untitled

a guest
Mar 4th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.68 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.     public Scarecrow()
  27.     {
  28.         super(Material.WOOD);
  29.         setUnlocalizedName("scarecrow");
  30.         setRegistryName("scarecrow");
  31.         setCreativeTab(CreativeTabs.DECORATIONS);
  32.         setSoundType(SoundType.WOOD);
  33.         this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
  34.     }
  35.     @Override
  36.     public void onBlockAdded(World world, BlockPos pos, IBlockState state)
  37.     {
  38.         ScarecrowTracking.get(world).addScarecrow(pos);
  39.     }
  40.     @Override
  41.     public void breakBlock(World world, BlockPos pos, IBlockState state)
  42.     {
  43.         ScarecrowTracking.get(world).removeScarecrow(pos);
  44.     }
  45.     @Override
  46.     public boolean isFullCube(IBlockState state)
  47.     {
  48.         return false;
  49.     }
  50.     @Override
  51.     public boolean isOpaqueCube(IBlockState state)
  52.     {
  53.         return false;
  54.     }
  55.     @SideOnly(Side.CLIENT)
  56.     public BlockRenderLayer getBlockLayer()
  57.     {
  58.         return BlockRenderLayer.CUTOUT;
  59.     }
  60.    
  61.     @Override
  62.     @SideOnly(Side.CLIENT)
  63.     public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
  64.     {
  65.         return new AxisAlignedBB(pos.getX(), pos.getY(), pos.getZ(), pos.getX()+1, pos.getY()+2, pos.getZ()+1);
  66.     }
  67.  
  68.     @Override
  69.     public AxisAlignedBB getSelectedBoundingBox(IBlockState state, World worldIn, BlockPos pos)
  70.     {
  71.         return new AxisAlignedBB(pos.getX(), pos.getY(), pos.getZ(), pos.getX()+1, pos.getY()+2, pos.getZ()+1);
  72.     }
  73.  
  74.    
  75.     @Override
  76.     protected BlockStateContainer createBlockState()
  77.     {
  78.         return new BlockStateContainer(this, new IProperty[] {FACING});
  79.     }
  80.    
  81.     @Override
  82.     public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
  83.     {
  84.         return worldIn.getBlockState(pos).getBlock().isReplaceable(worldIn, pos) && worldIn.getBlockState(pos.down()).isSideSolid(worldIn, pos, EnumFacing.UP);
  85.     }
  86.  
  87.     @Override
  88.     public IBlockState withRotation(IBlockState state, Rotation rot)
  89.     {
  90.         return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
  91.     }
  92.  
  93.     @Override
  94.     public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
  95.     {
  96.         return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
  97.     }
  98.  
  99.     @Override
  100.     public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
  101.     {
  102.         return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
  103.     }
  104.  
  105.     @Override
  106.     public IBlockState getStateFromMeta(int meta)
  107.     {
  108.         return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta));
  109.     }
  110.  
  111.     @Override
  112.     public int getMetaFromState(IBlockState state)
  113.     {
  114.         return ((EnumFacing)state.getValue(FACING)).getHorizontalIndex();
  115.     }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement