@Override
  public boolean onBlockActivated(
      World world,
      BlockPos pos,
      IBlockState state,
      EntityPlayer player,
      EnumFacing side,
      float hitX,
      float hitY,
      float hitZ) {
    state = world.getBlockState(pos);
    int i = ((Integer) state.getValue(COLOR)).intValue();
    if (world.isBlockPowered(pos)) {
      world.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(true)));
    }

    if (((Boolean) state.getValue(POWERED)).booleanValue() == true) {
      if (i < 3) {
        world.setBlockState(pos, state.withProperty(COLOR, i + 1));
      } else if (i == 3) {
        world.setBlockState(pos, state.withProperty(COLOR, 0));
      } else {
        return false;
      }
    } else {
      return false;
    }

    return true;
  }
  /**
   * Called when a neighboring block was changed and marks that this state should perform any checks
   * during a neighbor change. Cases may include when redstone power is updated, cactus blocks
   * popping off due to a neighboring solid block, etc.
   */
  public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn) {
    if (!worldIn.isRemote) {
      boolean flag = worldIn.isBlockPowered(pos);

      if (flag || blockIn.getDefaultState().canProvidePower()) {
        if (flag
            && !((Boolean) state.getValue(OPEN)).booleanValue()
            && !((Boolean) state.getValue(POWERED)).booleanValue()) {
          worldIn.setBlockState(
              pos,
              state
                  .withProperty(OPEN, Boolean.valueOf(true))
                  .withProperty(POWERED, Boolean.valueOf(true)),
              2);
          worldIn.playEvent((EntityPlayer) null, 1008, pos, 0);
        } else if (!flag
            && ((Boolean) state.getValue(OPEN)).booleanValue()
            && ((Boolean) state.getValue(POWERED)).booleanValue()) {
          worldIn.setBlockState(
              pos,
              state
                  .withProperty(OPEN, Boolean.valueOf(false))
                  .withProperty(POWERED, Boolean.valueOf(false)),
              2);
          worldIn.playEvent((EntityPlayer) null, 1014, pos, 0);
        } else if (flag != ((Boolean) state.getValue(POWERED)).booleanValue()) {
          worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(flag)), 2);
        }
      }
    }
  }
  @Override
  public void onNeighborBlockChange(
      World world, BlockPos pos, IBlockState state, Block neighborBlock) {
    boolean flag = world.isBlockPowered(pos);
    state = world.getBlockState(pos);

    world.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(flag)));
  }
Exemple #4
0
 @Override
 public void onNeighborBlockChange(
     World worldIn, BlockPos pos, IBlockState state, Block neighborBlock) {
   if (worldIn.isBlockPowered(pos)) {
     this.onBlockDestroyedByPlayer(
         worldIn, pos, state.withProperty(EXPLODE, Boolean.valueOf(true)));
     worldIn.setBlockToAir(pos);
   }
 }
Exemple #5
0
  @Override
  public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
    super.onBlockAdded(worldIn, pos, state);

    if (worldIn.isBlockPowered(pos)) {
      this.onBlockDestroyedByPlayer(
          worldIn, pos, state.withProperty(EXPLODE, Boolean.valueOf(true)));
      worldIn.setBlockToAir(pos);
    }
  }
Exemple #6
0
  public void onNeighborBlockChange(
      World worldIn, BlockPos pos, IBlockState state, Block neighborBlock) {
    boolean var5 = worldIn.isBlockPowered(pos);
    TileEntity var6 = worldIn.getTileEntity(pos);

    if (var6 instanceof TileEntityNote) {
      TileEntityNote var7 = (TileEntityNote) var6;

      if (var7.previousRedstoneState != var5) {
        if (var5) {
          var7.func_175108_a(worldIn, pos);
        }

        var7.previousRedstoneState = var5;
      }
    }
  }
 @Override
 public void onNeighborBlockChange(
     World world, BlockPos pos, IBlockState state, Block neighborBlock) {
   TileEntityToaster tileEntityToaster = (TileEntityToaster) world.getTileEntity(pos);
   if (!tileEntityToaster.isToasting() && world.isBlockPowered(pos)) {
     tileEntityToaster.startToasting();
     world.markBlockForUpdate(pos);
     if (!world.isRemote) {
       world.playSoundEffect(
           pos.getX() + 0.5D,
           pos.getY() + 0.5D,
           pos.getZ() + 0.5D,
           "cfm:toaster_down",
           0.75F,
           1.0F);
     }
   }
 }