Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BlockANDGate extends BlockHorizontal {
- public static final PropertyBool POWERED = PropertyBool.create("powered");
- public BlockANDGate() {
- super(Material.ROCK);
- setUnlocalizedName(Reference.Blocks.ANDGATE.getUnlocalizedName());
- setRegistryName(Reference.Blocks.ANDGATE.getRegistryName());
- this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.SOUTH).withProperty(POWERED, Boolean.valueOf(false)));
- this.setCreativeTab(CreativeTabs.REDSTONE);
- System.out.println("Block init");
- }
- @Override
- protected BlockStateContainer createBlockState() {
- System.out.println("createBlockState");
- return new BlockStateContainer(this, new IProperty[] {FACING, POWERED});
- }
- public IBlockState withRotation(IBlockState state, Rotation rot) {
- System.out.println("withRotation");
- return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
- }
- @Override
- public int getMetaFromState(IBlockState state) {
- System.out.println("getMetaFromState");
- return ((Boolean)state.getValue(POWERED)).booleanValue() ? 1 : 0;
- }
- @Override
- public IBlockState getStateFromMeta(int meta) {
- System.out.println("getStateFromMeta");
- return meta == 0 ? this.blockState.getBaseState().withProperty(POWERED, Boolean.valueOf(false)): this.blockState.getBaseState().withProperty(POWERED, Boolean.valueOf(true));
- }
- @Override
- public boolean canProvidePower(IBlockState state) {
- System.out.println("canProvidePower");
- return true;
- }
- @Override
- public int getWeakPower(IBlockState state, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
- System.out.println("getWeakPower");
- return ((Boolean)state.getValue(POWERED)).booleanValue() && side == EnumFacing.SOUTH ? 15 : 0;
- }
- @Override
- public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos neighbor) {
- System.out.println("onNeighborChange");
- IBlockState neighborstate = world.getBlockState(neighbor);
- if (neighborstate.canProvidePower()) {
- if (neighborstate.getWeakPower(world, pos, EnumFacing.WEST) > 0 || neighborstate.getWeakPower(world, pos, EnumFacing.EAST) > 0) {
- System.out.println("weakpower");
- this.blockState.getBaseState().withProperty(POWERED, Boolean.valueOf(true));
- System.out.println("Done");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement