Advertisement
Guest User

BlockCoil

a guest
Aug 15th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.04 KB | None | 0 0
  1. package net.secknv.nkmod.block;
  2.  
  3. import net.minecraft.block.Block;
  4. import net.minecraft.block.ITileEntityProvider;
  5. import net.minecraft.block.material.Material;
  6. import net.minecraft.block.properties.PropertyBool;
  7. import net.minecraft.block.properties.PropertyDirection;
  8. import net.minecraft.block.state.BlockStateContainer;
  9. import net.minecraft.block.state.IBlockState;
  10. import net.minecraft.entity.EntityLivingBase;
  11. import net.minecraft.item.ItemStack;
  12. import net.minecraft.tileentity.TileEntity;
  13. import net.minecraft.util.BlockRenderLayer;
  14. import net.minecraft.util.EnumFacing;
  15. import net.minecraft.util.math.BlockPos;
  16. import net.minecraft.world.World;
  17. import net.secknv.nkmod.Naschkatze;
  18. import net.secknv.nkmod.Reference;
  19. import net.secknv.nkmod.tileentity.TileEntityCoil;
  20.  
  21. public class BlockCoil extends Block
  22. {
  23.    
  24.     public static final PropertyDirection FACING = PropertyDirection.create("facing");
  25.     public static final PropertyBool ENABLED = PropertyBool.create("enabled");
  26.     private final String name = "copper_coil";
  27.    
  28.     public BlockCoil()
  29.     {
  30.         super(Material.ROCK);
  31.         setRegistryName(name);
  32.         setUnlocalizedName(Reference.MODID + "." + name);
  33.         setCreativeTab(Naschkatze.tabNk);
  34.         setHardness(1.0f);
  35.         setResistance(5.0f);
  36.     }
  37.    
  38.     @Override
  39.     public void neighborChanged(IBlockState state, World world, BlockPos pos, Block blockIn) {
  40.         int powered = world.isBlockIndirectlyGettingPowered(pos);
  41.         world.setBlockState(pos, state.withProperty(ENABLED, powered > 0), 3);
  42.     }
  43.    
  44.     @Override
  45.     public boolean isBlockNormalCube(IBlockState blockState) {
  46.         return false;
  47.     }
  48.  
  49.     @Override
  50.     public boolean isOpaqueCube(IBlockState blockState) {
  51.         return false;
  52.     }
  53.  
  54.  
  55.     @Override
  56.     public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
  57.         world.setBlockState(pos, state.withProperty(FACING, getFacingFromEntity(pos, placer)), 2);
  58.     }
  59.  
  60.     public static EnumFacing getFacingFromEntity(BlockPos clickedBlock, EntityLivingBase entity) {
  61.         return EnumFacing.getFacingFromVector(
  62.              (float) (entity.posX - clickedBlock.getX()),
  63.              (float) (entity.posY - clickedBlock.getY()),
  64.              (float) (entity.posZ - clickedBlock.getZ()));
  65.     }
  66.  
  67.     @Override
  68.     public IBlockState getStateFromMeta(int meta) {
  69.         return getDefaultState()
  70.                 .withProperty(FACING, EnumFacing.getFront(meta & 7))
  71.                 .withProperty(ENABLED, (meta & 8) != 0);
  72.     }
  73.  
  74.     @Override
  75.     public int getMetaFromState(IBlockState state) {
  76.         return state.getValue(FACING).getIndex() + (state.getValue(ENABLED) ? 8 : 0);
  77.     }
  78.  
  79.     @Override
  80.     protected BlockStateContainer createBlockState() {
  81.         return new BlockStateContainer(this, FACING, ENABLED);
  82.     }
  83.    
  84.     @Override
  85.     public boolean hasTileEntity(){
  86.         return true;
  87.     }
  88.    
  89.     @Override
  90.     public TileEntity createTileEntity(World world, IBlockState state)
  91.     {
  92.         return new TileEntityCoil();
  93.     }
  94.    
  95.    
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement