Example #1
0
  /**
   * Get the actual Block state of this Block at the given position. This applies properties not
   * visible in the metadata, such as fence connections.
   */
  public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
    EnumFacing.Axis enumfacing$axis = ((EnumFacing) state.getValue(FACING)).getAxis();

    if (enumfacing$axis == EnumFacing.Axis.Z
            && (worldIn.getBlockState(pos.west()).getBlock() == Blocks.COBBLESTONE_WALL
                || worldIn.getBlockState(pos.east()).getBlock() == Blocks.COBBLESTONE_WALL)
        || enumfacing$axis == EnumFacing.Axis.X
            && (worldIn.getBlockState(pos.north()).getBlock() == Blocks.COBBLESTONE_WALL
                || worldIn.getBlockState(pos.south()).getBlock() == Blocks.COBBLESTONE_WALL)) {
      state = state.withProperty(IN_WALL, Boolean.valueOf(true));
    }

    return state;
  }
  /**
   * returns whether or not there is dirt underneath the block where the tree will be grown. It also
   * generates dirt around the block in a 2x2 square if there is dirt underneath the blockpos.
   */
  private boolean ensureDirtsUnderneath(BlockPos pos, World worldIn) {
    BlockPos blockpos = pos.down();
    IBlockState state = worldIn.getBlockState(blockpos);
    boolean isSoil =
        state
            .getBlock()
            .canSustainPlant(
                state,
                worldIn,
                blockpos,
                net.minecraft.util.EnumFacing.UP,
                ((net.minecraft.block.BlockSapling) Blocks.SAPLING));

    if (isSoil && pos.getY() >= 2) {
      this.onPlantGrow(worldIn, blockpos, pos);
      this.onPlantGrow(worldIn, blockpos.east(), pos);
      this.onPlantGrow(worldIn, blockpos.south(), pos);
      this.onPlantGrow(worldIn, blockpos.south().east(), pos);
      return true;
    } else {
      return false;
    }
  }
  @Override
  public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
    if (worldIn.getGameRules().getBoolean("doFireTick")) {
      if (!canPlaceBlockAt(worldIn, pos)) worldIn.setBlockToAir(pos);

      if (worldIn.isRaining() && canDie(worldIn, pos)) worldIn.setBlockToAir(pos);
      else {
        int i = state.getValue(AGE).intValue();

        if (i < 4) {
          state = state.withProperty(AGE, Integer.valueOf(i + rand.nextInt(3) / 2));
          worldIn.setBlockState(pos, state, 4);
        }

        worldIn.scheduleUpdate(pos, this, tickRate(worldIn) + rand.nextInt(10));

        if (!canNeighborCatchFire(worldIn, pos)) {
          if (!worldIn.getBlockState(pos.down()).isSideSolid(worldIn, pos.down(), EnumFacing.UP)
              || i > 3) worldIn.setBlockToAir(pos);

          return;
        }

        if (!this.canCatchFire(worldIn, pos.down(), EnumFacing.UP)
            && i >= 4
            && rand.nextInt(4) == 0) {
          worldIn.setBlockToAir(pos);
          return;
        }

        boolean flag1 = worldIn.isBlockinHighHumidity(pos);
        int j = 0;

        if (flag1) j = -50;

        tryCatchFire(worldIn, pos.east(), 300 + j, rand, i, EnumFacing.WEST);
        tryCatchFire(worldIn, pos.west(), 300 + j, rand, i, EnumFacing.EAST);
        tryCatchFire(worldIn, pos.down(), 250 + j, rand, i, EnumFacing.UP);
        tryCatchFire(worldIn, pos.up(), 250 + j, rand, i, EnumFacing.DOWN);
        tryCatchFire(worldIn, pos.north(), 300 + j, rand, i, EnumFacing.SOUTH);
        tryCatchFire(worldIn, pos.south(), 300 + j, rand, i, EnumFacing.NORTH);

        for (int k = -1; k <= 1; ++k)
          for (int l = -1; l <= 1; ++l)
            for (int i1 = -1; i1 <= 4; ++i1)
              if (k != 0 || i1 != 0 || l != 0) {
                int j1 = 100;

                if (i1 > 1) j1 += (i1 - 1) * 100;

                BlockPos blockpos = pos.add(k, i1, l);
                int k1 = getNeighborEncouragement(worldIn, blockpos);

                if (k1 > 0) {
                  int l1 = (k1 + 40 + worldIn.getDifficulty().getDifficultyId() * 7) / (i + 30);

                  if (flag1) l1 /= 2;

                  if (l1 > 0
                      && rand.nextInt(j1) <= l1
                      && (!worldIn.isRaining() || !canDie(worldIn, blockpos))) {
                    int i2 = i + rand.nextInt(5) / 4;

                    if (i2 > 15) i2 = 15;

                    worldIn.setBlockState(
                        blockpos, state.withProperty(AGE, Integer.valueOf(i2)), 3);
                  }
                }
              }
      }
    }
  }