Advertisement
The_G0dPiXeL

Untitled

Jun 23rd, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.44 KB | None | 0 0
  1. public class BlockANDGate extends BlockHorizontal {
  2.     public static final PropertyBool POWERED = PropertyBool.create("powered");
  3.    
  4.     public BlockANDGate() {
  5.         super(Material.ROCK);
  6.         setUnlocalizedName(Reference.Blocks.ANDGATE.getUnlocalizedName());
  7.         setRegistryName(Reference.Blocks.ANDGATE.getRegistryName());
  8.         this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.SOUTH).withProperty(POWERED, Boolean.valueOf(false)));
  9.         this.setCreativeTab(CreativeTabs.REDSTONE);
  10.         System.out.println("Block init");
  11.     }
  12.    
  13.     @Override
  14.     protected BlockStateContainer createBlockState() {
  15.         System.out.println("createBlockState");
  16.         return new BlockStateContainer(this, new IProperty[] {FACING, POWERED});
  17.     }
  18.    
  19.     public IBlockState withRotation(IBlockState state, Rotation rot) {
  20.         System.out.println("withRotation");
  21.         return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
  22.     }
  23.  
  24.    
  25.     @Override
  26.     public int getMetaFromState(IBlockState state) {
  27.         System.out.println("getMetaFromState");
  28.         return ((Boolean)state.getValue(POWERED)).booleanValue() ? 1 : 0;
  29.     }
  30.    
  31.     @Override
  32.     public IBlockState getStateFromMeta(int meta) {
  33.         System.out.println("getStateFromMeta");
  34.         return meta == 0 ? this.blockState.getBaseState().withProperty(POWERED, Boolean.valueOf(false)): this.blockState.getBaseState().withProperty(POWERED, Boolean.valueOf(true));
  35.     }
  36.    
  37.     @Override
  38.     public boolean canProvidePower(IBlockState state) {
  39.         System.out.println("canProvidePower");
  40.         return true;
  41.     }
  42.    
  43.     @Override
  44.     public int getWeakPower(IBlockState state, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
  45.         System.out.println("getWeakPower");
  46.         return ((Boolean)state.getValue(POWERED)).booleanValue() && side == EnumFacing.SOUTH ? 15 : 0;
  47.     }
  48.    
  49.     @Override
  50.     public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos neighbor) {
  51.         System.out.println("onNeighborChange");
  52.         IBlockState neighborstate = world.getBlockState(neighbor);
  53.         if (neighborstate.canProvidePower()) {
  54.             if (neighborstate.getWeakPower(world, pos, EnumFacing.WEST) > 0 || neighborstate.getWeakPower(world, pos, EnumFacing.EAST) > 0) {
  55.                 System.out.println("weakpower");
  56.                 this.blockState.getBaseState().withProperty(POWERED, Boolean.valueOf(true));
  57.                 System.out.println("Done");
  58.             }
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement