Advertisement
Exokem

Untitled

Jun 21st, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.52 KB | None | 0 0
  1. public class Machine extends Block {
  2.  
  3.     public static final PropertyDirection FACING = BlockHorizontal.FACING;
  4.     public static final PropertyBool ACTIVE = PropertyBool.create("burning");
  5.  
  6.     public Machine(String resource) {
  7.         super(Material.IRON);
  8.         setSoundType(SoundType.METAL);
  9.  
  10.         setUnlocalizedName(Exkva.MODID + "." + resource);
  11.         setRegistryName(new ResourceLocation(Exkva.MODID, resource));
  12.         this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(ACTIVE, false));
  13.     }
  14.  
  15.     public void initModel() {
  16.         ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, new ModelResourceLocation(getRegistryName(), "inventory"));
  17.     }
  18.  
  19.     @Override
  20.     public boolean hasTileEntity(IBlockState state) {
  21.         return true;
  22.     }
  23.  
  24.     @Override
  25.     protected BlockStateContainer createBlockState() {
  26.         return new BlockStateContainer(this, new IProperty[] {ACTIVE, FACING});
  27.     }
  28.  
  29.     @Override
  30.     public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
  31.         worldIn.setBlockState(pos, this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
  32.     }
  33.  
  34.     @Override
  35.     public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
  36.  
  37.         if(!worldIn.isRemote) {
  38.             IBlockState north, south, east, west;
  39.             north = worldIn.getBlockState(pos.north());
  40.             south = worldIn.getBlockState(pos.south());
  41.             east = worldIn.getBlockState(pos.east());
  42.             west = worldIn.getBlockState(pos.west());
  43.             EnumFacing face = (EnumFacing) state.getValue(FACING);
  44.  
  45.             if (face == EnumFacing.NORTH && north.isFullBlock() && south.isFullBlock()) {
  46.                 face = EnumFacing.SOUTH;
  47.             } else if (face == EnumFacing.SOUTH && south.isFullBlock() && north.isFullBlock()) {
  48.                 face = EnumFacing.NORTH;
  49.             } else if (face == EnumFacing.WEST && west.isFullBlock() && east.isFullBlock()) {
  50.                 face = EnumFacing.EAST;
  51.             } else if (face == EnumFacing.EAST && east.isFullBlock() && west.isFullBlock()) {
  52.                 face = EnumFacing.WEST;
  53.             }
  54.  
  55.             worldIn.setBlockState(pos, state.withProperty(FACING, face), 2);
  56.         }
  57.     }
  58.  
  59.     @Override
  60.     public int getMetaFromState(IBlockState state) {
  61.         return ((EnumFacing) state.getValue(FACING)).getIndex();
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement