@Override
  public boolean onBlockDestroyed(
      ItemStack stack, World world, int blockID, int x, int y, int z, EntityPlayer player) {
    boolean b = false;
    Block block = Block.blocksList[blockID];
    int plant = (int) ModuleManager.computeModularProperty(stack, PLANT_RADIUS);
    int leaf = (int) ModuleManager.computeModularProperty(stack, LEAF_RADIUS);
    int totalEnergyDrain = 0;

    // Leaves
    if (block != null && block.isLeaves(world, x, y, z)) {
      for (int i = -leaf; i < leaf; i++) {
        for (int j = -leaf; j < leaf; j++) {
          for (int k = -leaf; k < leaf; k++) {
            int id = world.getBlockId(x + i, y + j, z + k);
            int meta = world.getBlockId(x + i, y + j, z + k);
            Block tempBlock = Block.blocksList[id];
            if (tempBlock != null && tempBlock.isLeaves(world, x + i, y + j, z + k)) {
              if (block.canHarvestBlock(player, meta)) {
                block.harvestBlock(world, player, x + i, y + j, z + k, meta);
                totalEnergyDrain +=
                    ModuleManager.computeModularProperty(stack, LEAF_BLOWER_ENERGY_CONSUMPTION);
              }
              world.setBlock(x + i, y + j, z + k, 0);
              b = true;
            }
          }
        }
      }
    }

    for (int i = -plant; i < plant; i++) {
      for (int j = -plant; j < plant; j++) {
        for (int k = -plant; k < plant; k++) {
          int id = world.getBlockId(x + i, y + j, z + k);
          int meta = world.getBlockId(x + i, y + j, z + k);
          Block tempBlock = Block.blocksList[id];
          if (tempBlock != null && tempBlock instanceof BlockFlower) {
            if (block.canHarvestBlock(player, meta)) {
              block.harvestBlock(world, player, x + i, y + j, z + k, meta);
              totalEnergyDrain +=
                  ModuleManager.computeModularProperty(stack, LEAF_BLOWER_ENERGY_CONSUMPTION);
            }
            world.setBlock(x + i, y + j, z + k, 0);
            b = true;
          }
        }
      }
    }
    ElectricItemUtils.drainPlayerEnergy(player, totalEnergyDrain);
    return b;
  }
Esempio n. 2
0
  public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5) {
    int l;

    Block block = null;
    do {
      block = Block.blocksList[par1World.getBlockId(par3, par4, par5)];
      if (block != null && !block.isLeaves(par1World, par3, par4, par5)) {
        break;
      }
      par4--;
    } while (par4 > 0);

    for (int i1 = 0; i1 < 128; ++i1) {
      int j1 = par3 + par2Random.nextInt(8) - par2Random.nextInt(8);
      int k1 = par4 + par2Random.nextInt(4) - par2Random.nextInt(4);
      int l1 = par5 + par2Random.nextInt(8) - par2Random.nextInt(8);

      if (par1World.isAirBlock(j1, k1, l1)
          && Block.blocksList[this.tallGrassID].canBlockStay(par1World, j1, k1, l1)) {
        par1World.setBlock(j1, k1, l1, this.tallGrassID, this.tallGrassMetadata, 2);
      }
    }

    return true;
  }
Esempio n. 3
0
  public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5) {
    int var11;

    Block block = null;
    do {
      block = par1World.getBlock(par3, par4, par5);
      if (block != null && !block.isLeaves(par1World, par3, par4, par5)) {
        break;
      }
      par4--;
    } while (par4 > 0);

    for (int var7 = 0; var7 < 4; ++var7) {
      int var8 = par3 + par2Random.nextInt(8) - par2Random.nextInt(8);
      int var9 = par4 + par2Random.nextInt(4) - par2Random.nextInt(4);
      int var10 = par5 + par2Random.nextInt(8) - par2Random.nextInt(8);

      if (par1World.isAirBlock(var8, var9, var10)
          && this.deadBush.canBlockStay(par1World, var8, var9, var10)) {
        par1World.setBlock(var8, var9, var10, this.deadBush, 0, 2);
      }
    }

    return true;
  }
 protected boolean isReplaceable(World world, int x, int y, int z) {
   Block block = world.getBlock(x, y, z);
   return block.isAir(world, x, y, z)
       || block.isLeaves(world, x, y, z)
       || block.isWood(world, x, y, z)
       || func_150523_a(block);
 }
  public void setBlock(World world, int x, int y, int z, Block block, int metadata) {
    Block b1 = world.getBlock(x, y, z);

    if (b1.isAir(world, x, y, z) || b1.isLeaves(world, x, y, z)) {
      world.setBlock(x, y, z, block, metadata, 2);
    }
  }
Esempio n. 6
0
  void placeTrunk(World world, int xPos, int yPos, int zPos, int height) {
    for (int localHeight = 0; localHeight < height; ++localHeight) {
      int blockID = world.getBlockId(xPos, yPos + localHeight, zPos);

      Block block = Block.blocksList[blockID];

      if (blockID == 0 || block == null || block.isLeaves(world, xPos, yPos + localHeight, zPos)) {
        this.setBlockAndMetadata(
            world, xPos, yPos + localHeight, zPos, NContent.rareTree.blockID, this.metaWood);
      }
    }
  }
Esempio n. 7
0
  @Override
  public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPlayer player) {
    if (!stack.hasTagCompound()) return false;

    World world = player.worldObj;
    final Block wood = world.getBlock(x, y, z);
    ;
    if (wood == null) {
      return super.onBlockStartBreak(stack, x, y, z, player);
    }
    if (wood.isWood(world, x, y, z) || wood.getMaterial() == Material.sponge) {
      int height = y;
      boolean foundTop = false;
      do {
        height++;
        Block block = world.getBlock(x, height, z);
        if (block != wood) {
          height--;
          foundTop = true;
        }
      } while (!foundTop);

      int numLeaves = 0;
      if (height - y < 50) {
        for (int xPos = x - 1; xPos <= x + 1; xPos++) {
          for (int yPos = height - 1; yPos <= height + 1; yPos++) {
            for (int zPos = z - 1; zPos <= z + 1; zPos++) {
              Block leaves = world.getBlock(xPos, yPos, zPos);
              if (leaves != null && leaves.isLeaves(world, xPos, yPos, zPos)) numLeaves++;
            }
          }
        }
      }

      NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
      int meta = world.getBlockMetadata(x, y, z);
      if (numLeaves > 3) breakTree(world, x, y, z, stack, tags, wood, meta, player);
      else destroyWood(world, x, y, z, stack, tags, player);

      if (!world.isRemote)
        world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(wood) + (meta << 12));
    } else if (wood.getMaterial() == Material.wood) {
      NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
      int meta = world.getBlockMetadata(x, y, z);
      destroyWood(world, x, y, z, stack, tags, player);
      if (!world.isRemote)
        world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(wood) + (meta << 12));
    }
    return super.onBlockStartBreak(stack, x, y, z, player);
  }
  public boolean generate(World worldIn, Random p_180709_2_, BlockPos p_180709_3_) {
    Block block;

    do {
      block = worldIn.getBlockState(p_180709_3_).getBlock();
      if (!block.isLeaves(worldIn, p_180709_3_) && !block.isLeaves(worldIn, p_180709_3_)) break;
      p_180709_3_ = p_180709_3_.down();
    } while (p_180709_3_.getY() > 0);

    for (int i = 0; i < 4; ++i) {
      BlockPos blockpos1 =
          p_180709_3_.add(
              p_180709_2_.nextInt(8) - p_180709_2_.nextInt(8),
              p_180709_2_.nextInt(4) - p_180709_2_.nextInt(4),
              p_180709_2_.nextInt(8) - p_180709_2_.nextInt(8));

      if (worldIn.isAirBlock(blockpos1)
          && Blocks.deadbush.canBlockStay(worldIn, blockpos1, Blocks.deadbush.getDefaultState())) {
        worldIn.setBlockState(blockpos1, Blocks.deadbush.getDefaultState(), 2);
      }
    }

    return true;
  }
Esempio n. 9
0
  public static int getSurfaceBlockY(World world, int x, int z) {

    int y = world.getChunkFromBlockCoords(x, z).getTopFilledSegment() + 16;

    Block block;
    do {
      if (--y < 0) {
        break;
      }
      block = world.getBlock(x, y, z);
    } while (block.isAir(world, x, y, z)
        || block.isReplaceable(world, x, y, z)
        || block.isLeaves(world, x, y, z)
        || block.isFoliage(world, x, y, z)
        || block.canBeReplacedByLeaves(world, x, y, z));
    return y;
  }
Esempio n. 10
0
  boolean checkClear(World world, int x, int y, int z, int treeHeight) {
    for (int yPos = 0; yPos < treeHeight + 1; yPos++) {
      int range = 1;

      if (yPos == 0) range = 0;
      else if (yPos >= treeHeight - 1) range = 2;

      for (int xPos = range; xPos <= range; xPos++) {
        for (int zPos = range; zPos <= range; zPos++) {
          int blockID = world.getBlockId(x + xPos, y + yPos, z + zPos);
          Block block = Block.blocksList[blockID];
          if (block != null
              && blockID != NContent.rareSapling.blockID
              && !block.isLeaves(world, x + xPos, y + yPos, z + zPos)) return false;
        }
      }
    }
    return true;
  }
Esempio n. 11
0
  @Override
  public boolean generate(World world, Random rand, int x, int y, int z) {
    Block block;
    do {
      block = world.getBlock(x, y, z);
      if (!(block.isLeaves(world, x, y, z) || block.isAir(world, x, y, z))) {
        break;
      }
      --y;
    } while (y > 0);

    Block block1 = world.getBlock(x, y, z);

    if (TFC_Core.isSoil(block1)) {
      ++y;
      this.setBlockAndNotifyAdequately(world, x, y, z, TFCBlocks.logNatural, this.meta);

      for (int l = y; l <= y + 2; ++l) {
        int i1 = l - y;
        int j1 = 2 - i1;

        for (int k1 = x - j1; k1 <= x + j1; ++k1) {
          int l1 = k1 - x;

          for (int i2 = z - j1; i2 <= z + j1; ++i2) {
            int j2 = i2 - z;

            if ((Math.abs(l1) != j1 || Math.abs(j2) != j1 || rand.nextInt(2) != 0)
                && world.getBlock(k1, l, i2).canBeReplacedByLeaves(world, k1, l, i2)) {
              this.setBlockAndNotifyAdequately(world, k1, l, i2, TFCBlocks.leaves, this.meta);
            }
          }
        }
      }
    }
    return true;
  }
  public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5) {
    int var6 = par2Random.nextInt(2) + this.minTreeHeight;
    boolean var7 = true;

    if (par4 >= 1 && par4 + var6 + 1 <= 256) {
      int var8;
      byte var9;
      int var11;
      int var12;

      for (var8 = par4; var8 <= par4 + 1 + var6; ++var8) {
        var9 = 1;

        if (var8 == par4) {
          var9 = 0;
        }

        if (var8 >= par4 + 1 + var6 - 2) {
          var9 = 2;
        }

        for (int var10 = par3 - var9; var10 <= par3 + var9 && var7; ++var10) {
          for (var11 = par5 - var9; var11 <= par5 + var9 && var7; ++var11) {
            if (var8 >= 0 && var8 < 256) {
              var12 = par1World.getBlockId(var10, var8, var11);

              Block block = Block.blocksList[var12];

              if (var12 != 0
                  && !block.isLeaves(par1World, var10, var8, var11)
                  && var12 != Block.grass.blockID
                  && var12 != Block.dirt.blockID
                  && !block.isWood(par1World, var10, var8, var11)) {
                var7 = false;
              }
            } else {
              var7 = false;
            }
          }
        }
      }

      if (!var7) {
        return false;
      } else {
        var8 = par1World.getBlockId(par3, par4 - 1, par5);

        if ((var8 == Block.grass.blockID || var8 == Block.dirt.blockID) && par4 < 256 - var6 - 1) {
          this.setBlock(par1World, par3, par4 - 1, par5, Block.dirt.blockID);
          var9 = 3;
          byte var18 = 0;
          int var13;
          int var14;
          int var15;

          for (var11 = par4 - var9 + var6; var11 <= par4 + var6; ++var11) {
            var12 = var11 - (par4 + var6);
            var13 = var18 + 1 - var12 / 2;

            for (var14 = par3 - var13; var14 <= par3 + var13; ++var14) {
              var15 = var14 - par3;

              for (int var16 = par5 - var13; var16 <= par5 + var13; ++var16) {
                int var17 = var16 - par5;

                Block block = Block.blocksList[par1World.getBlockId(var14, var11, var16)];

                if ((Math.abs(var15) != var13
                        || Math.abs(var17) != var13
                        || par2Random.nextInt(2) != 0 && var12 != 0)
                    && (block == null
                        || block.canBeReplacedByLeaves(par1World, var14, var11, var16))) {
                  this.setBlockAndMetadata(
                      par1World, var14, var11, var16, Block.leaves.blockID, this.metaLeaves);
                }
              }
            }
          }

          for (var11 = 0; var11 < var6; ++var11) {
            var12 = par1World.getBlockId(par3, par4 + var11, par5);

            Block block = Block.blocksList[var12];

            if (var12 == 0
                || block == null
                || block.isLeaves(par1World, par3, par4 + var11, par5)) {
              this.setBlockAndMetadata(
                  par1World, par3, par4 + var11, par5, Block.wood.blockID, this.metaWood);

              if (this.vinesGrow && var11 > 0) {
                if (par2Random.nextInt(3) > 0
                    && par1World.isAirBlock(par3 - 1, par4 + var11, par5)) {
                  this.setBlockAndMetadata(
                      par1World, par3 - 1, par4 + var11, par5, Block.vine.blockID, 8);
                }

                if (par2Random.nextInt(3) > 0
                    && par1World.isAirBlock(par3 + 1, par4 + var11, par5)) {
                  this.setBlockAndMetadata(
                      par1World, par3 + 1, par4 + var11, par5, Block.vine.blockID, 2);
                }

                if (par2Random.nextInt(3) > 0
                    && par1World.isAirBlock(par3, par4 + var11, par5 - 1)) {
                  this.setBlockAndMetadata(
                      par1World, par3, par4 + var11, par5 - 1, Block.vine.blockID, 1);
                }

                if (par2Random.nextInt(3) > 0
                    && par1World.isAirBlock(par3, par4 + var11, par5 + 1)) {
                  this.setBlockAndMetadata(
                      par1World, par3, par4 + var11, par5 + 1, Block.vine.blockID, 4);
                }
              }
            }
          }

          if (this.vinesGrow) {
            for (var11 = par4 - 3 + var6; var11 <= par4 + var6; ++var11) {
              var12 = var11 - (par4 + var6);
              var13 = 2 - var12 / 2;

              for (var14 = par3 - var13; var14 <= par3 + var13; ++var14) {
                for (var15 = par5 - var13; var15 <= par5 + var13; ++var15) {
                  Block block = Block.blocksList[par1World.getBlockId(var14, var11, var15)];
                  if (block != null && block.isLeaves(par1World, var14, var11, var15)) {
                    if (par2Random.nextInt(4) == 0
                        && par1World.getBlockId(var14 - 1, var11, var15) == 0) {
                      this.growVines(par1World, var14 - 1, var11, var15, 8);
                    }

                    if (par2Random.nextInt(4) == 0
                        && par1World.getBlockId(var14 + 1, var11, var15) == 0) {
                      this.growVines(par1World, var14 + 1, var11, var15, 2);
                    }

                    if (par2Random.nextInt(4) == 0
                        && par1World.getBlockId(var14, var11, var15 - 1) == 0) {
                      this.growVines(par1World, var14, var11, var15 - 1, 1);
                    }

                    if (par2Random.nextInt(4) == 0
                        && par1World.getBlockId(var14, var11, var15 + 1) == 0) {
                      this.growVines(par1World, var14, var11, var15 + 1, 4);
                    }
                  }
                }
              }
            }

            if (par2Random.nextInt(5) == 0 && var6 > 5) {
              for (var11 = 0; var11 < 2; ++var11) {
                for (var12 = 0; var12 < 4; ++var12) {
                  if (par2Random.nextInt(4 - var11) == 0) {
                    var13 = par2Random.nextInt(3);
                    this.setBlockAndMetadata(
                        par1World,
                        par3 + Direction.offsetX[Direction.footInvisibleFaceRemap[var12]],
                        par4 + var6 - 5 + var11,
                        par5 + Direction.offsetZ[Direction.footInvisibleFaceRemap[var12]],
                        Block.cocoaPlant.blockID,
                        var13 << 2 | var12);
                  }
                }
              }
            }
          }

          return true;
        } else {
          return false;
        }
      }
    } else {
      return false;
    }
  }
  public boolean generate(World par1World, Random par2Random, int x, int y, int z) {
    int height = par2Random.nextInt(3) + this.minTreeHeight;
    boolean allClear = true;

    if (y >= 1 && y + height + 1 <= 256) {
      int cy;
      byte width;
      int cz;
      Block blockID;

      for (cy = y; cy <= y + 1 + height; ++cy) {
        width = 1;

        if (cy == y) {
          width = 0;
        }

        if (cy >= y + 1 + height - 2) {
          width = 2;
        }

        for (int cx = x - width; cx <= x + width && allClear; ++cx) {
          for (cz = z - width; cz <= z + width && allClear; ++cz) {
            if (cy >= 0 && cy < 256) {
              blockID = par1World.getBlock(cx, cy, cz);

              Block block = blockID;

              if (blockID != Blocks.air
                  && !block.isLeaves(par1World, cx, cy, cz)
                  && blockID != Blocks.grass
                  && blockID != Blocks.dirt
                  && !block.isWood(par1World, cx, cy, cz)) {
                allClear = false;
              }
            } else {
              allClear = false;
            }
          }
        }
      }

      if (!allClear) {
        return false;
      } else {
        Block blockUsing = par1World.getBlock(x, y - 1, z);

        if ((blockUsing == Blocks.grass || blockUsing == Blocks.dirt) && y < 256 - height - 1) {
          this.setBlock(par1World, x, y - 1, z, Blocks.dirt);
          width = 3;
          byte var18 = 0;
          int treeWidth;
          int tx;
          int var15;

          for (cz = y - width + height; cz <= y + height; ++cz) {
            int number = cz - (y + height);
            treeWidth = var18 + 1 - number / 2;

            for (tx = x - treeWidth; tx <= x + treeWidth; ++tx) {
              var15 = tx - x;

              for (int tz = z - treeWidth; tz <= z + treeWidth; ++tz) {
                int var17 = tz - z;

                Block block = par1World.getBlock(tx, cz, tz);

                if ((Math.abs(var15) != treeWidth
                        || Math.abs(var17) != treeWidth
                        || par2Random.nextInt(2) != 0 && number != 0)
                    && (block == null || block.canBeReplacedByLeaves(par1World, tx, cz, tz))) {
                  this.setBlockAndMetadata(par1World, tx, cz, tz, this.leafBlock, this.leafMeta);
                }
              }
            }
          }

          for (cz = 0; cz < height; ++cz) {
            blockID = par1World.getBlock(x, y + cz, z);

            Block block = blockID;

            if (blockID == Blocks.air || block == null || block.isLeaves(par1World, x, y + cz, z)) {
              this.setBlockAndMetadata(par1World, x, y + cz, z, this.treeBlock, this.treeMeta);
            }
          }

          return true;
        } else {
          return false;
        }
      }
    } else {
      return false;
    }
  }
  public boolean growTree(World world, Random rand, int x, int y, int z) {
    int treeHeight = rand.nextInt(3) + 5, worldHeight = world.getHeight();
    Block block;

    if (y >= 1 && y + treeHeight + 1 <= worldHeight) {
      int blockId;
      int xOffset;
      int yOffset;
      int zOffset;

      blockId = world.getBlockId(x, y - 1, z);
      block = Block.blocksList[blockId];

      boolean isGrass = blockId == Block.grass.blockID;

      if ((block != null
              && ((isGrass | blockId == Block.dirt.blockID)
                  || block.canSustainPlant(
                      world,
                      x,
                      y - 1,
                      z,
                      ForgeDirection.UP,
                      ((BlockSapling) MineFactoryReloadedCore.rubberSaplingBlock))))
          && y < worldHeight - treeHeight - 1) {
        for (yOffset = y; yOffset <= y + 1 + treeHeight; ++yOffset) {
          byte radius = 1;

          if (yOffset == y) {
            radius = 0;
          }

          if (yOffset >= y + 1 + treeHeight - 2) {
            radius = 2;
          }

          if (yOffset >= 0 & yOffset < worldHeight) {
            for (xOffset = x - radius; xOffset <= x + radius; ++xOffset) {
              for (zOffset = z - radius; zOffset <= z + radius; ++zOffset) {
                blockId = world.getBlockId(xOffset, yOffset, zOffset);

                block = Block.blocksList[blockId];

                if (block != null
                    && !(block.isLeaves(world, xOffset, yOffset, zOffset)
                        || block.isAirBlock(world, xOffset, yOffset, zOffset)
                        || block.canBeReplacedByLeaves(world, xOffset, yOffset, zOffset))) {
                  return false;
                }
              }
            }
          } else {
            return false;
          }
        }

        if (isGrass) {
          this.setBlock(world, x, y - 1, z, Block.dirt.blockID);
        }

        for (yOffset = y - 3 + treeHeight; yOffset <= y + treeHeight; ++yOffset) {
          int var12 = yOffset - (y + treeHeight), center = 1 - var12 / 2;

          for (xOffset = x - center; xOffset <= x + center; ++xOffset) {
            int xPos = xOffset - x, t = xPos >> 31;
            xPos = (xPos + t) ^ t;

            for (zOffset = z - center; zOffset <= z + center; ++zOffset) {
              int zPos = zOffset - z;
              zPos = (zPos + (t = zPos >> 31)) ^ t;

              block = Block.blocksList[world.getBlockId(xOffset, yOffset, zOffset)];

              if (((xPos != center | zPos != center) || rand.nextInt(2) != 0 && var12 != 0)
                  && (block == null
                      || block.isLeaves(world, xOffset, yOffset, zOffset)
                      || block.isAirBlock(world, xOffset, yOffset, zOffset)
                      || block.canBeReplacedByLeaves(world, xOffset, yOffset, zOffset))) {
                this.setBlockAndMetadata(
                    world,
                    xOffset,
                    yOffset,
                    zOffset,
                    MineFactoryReloadedCore.rubberLeavesBlock.blockID,
                    0);
              }
            }
          }
        }

        for (yOffset = 0; yOffset < treeHeight; ++yOffset) {
          xOffset = world.getBlockId(x, y + yOffset, z);

          block = Block.blocksList[xOffset];

          if (block == null
              || block.isAirBlock(world, x, y + yOffset, z)
              || block.isLeaves(world, x, y + yOffset, z)) {
            this.setBlockAndMetadata(
                world, x, y + yOffset, z, MineFactoryReloadedCore.rubberWoodBlock.blockID, 1);
          }
        }

        return true;
      }
    }
    return false;
  }
  public boolean generate(
      World p_76484_1_, Random p_76484_2_, int p_76484_3_, int p_76484_4_, int p_76484_5_) {
    int l = p_76484_2_.nextInt(height * 2) + height * 2;
    int i1 = height + p_76484_2_.nextInt(height);
    int j1 = l - i1;
    int k1 = 2 + p_76484_2_.nextInt(2);
    boolean flag = true;

    if (p_76484_4_ >= 1 && p_76484_4_ + l + 1 <= 256) {
      int i2;
      int l3;

      for (int l1 = p_76484_4_; l1 <= p_76484_4_ + 1 + l && flag; ++l1) {
        boolean flag1 = true;

        if (l1 - p_76484_4_ < i1) {
          l3 = 0;
        } else {
          l3 = k1;
        }

        for (i2 = p_76484_3_ - l3; i2 <= p_76484_3_ + l3 && flag; ++i2) {
          for (int j2 = p_76484_5_ - l3; j2 <= p_76484_5_ + l3 && flag; ++j2) {
            if (l1 >= 0 && l1 < 256) {
              Block block = p_76484_1_.getBlock(i2, l1, j2);

              if (!block.isAir(p_76484_1_, i2, l1, j2)
                  && !block.isLeaves(p_76484_1_, i2, l1, j2)
                  && block != Blocks.snow_layer) {
                flag = false;
              }
            } else {
              flag = false;
            }
          }
        }
      }

      if (!flag) {
        return false;
      } else {
        Block block1 = p_76484_1_.getBlock(p_76484_3_, p_76484_4_ - 1, p_76484_5_);

        boolean isSoil =
            block1.canSustainPlant(
                p_76484_1_,
                p_76484_3_,
                p_76484_4_ - 1,
                p_76484_5_,
                ForgeDirection.UP,
                (BlockSapling) Blocks.sapling);
        if (isSoil && p_76484_4_ < 256 - l - 1) {
          block1.onPlantGrow(
              p_76484_1_,
              p_76484_3_,
              p_76484_4_ - 1,
              p_76484_5_,
              p_76484_3_,
              p_76484_4_,
              p_76484_5_);
          l3 = p_76484_2_.nextInt(2);
          i2 = 1;
          byte b0 = 0;
          int k2;
          int i4;

          for (i4 = 0; i4 <= j1; ++i4) {
            k2 = p_76484_4_ + l - i4;

            for (int l2 = p_76484_3_ - l3; l2 <= p_76484_3_ + l3; ++l2) {
              int i3 = l2 - p_76484_3_;

              for (int j3 = p_76484_5_ - l3; j3 <= p_76484_5_ + l3; ++j3) {
                int k3 = j3 - p_76484_5_;

                if ((Math.abs(i3) != l3 || Math.abs(k3) != l3 || l3 <= 0)
                    && p_76484_1_
                        .getBlock(l2, k2, j3)
                        .canBeReplacedByLeaves(p_76484_1_, l2, k2, j3)) {
                  p_76484_1_.setBlock(l2, k2, j3, Blocks.leaves, metadata, 0);
                }
              }
            }

            if (l3 >= i2) {
              l3 = b0;
              b0 = 1;
              ++i2;

              if (i2 > k1) {
                i2 = k1;
              }
            } else {
              ++l3;
            }
          }

          i4 = p_76484_2_.nextInt(3);

          for (k2 = 0; k2 < l - i4; ++k2) {
            Block block2 = p_76484_1_.getBlock(p_76484_3_, p_76484_4_ + k2, p_76484_5_);

            if (block2.isAir(p_76484_1_, p_76484_3_, p_76484_4_ + k2, p_76484_5_)
                || block2.isLeaves(p_76484_1_, p_76484_3_, p_76484_4_ + k2, p_76484_5_)
                || block2 == Blocks.snow_layer) {
              p_76484_1_.setBlock(p_76484_3_, p_76484_4_ + k2, p_76484_5_, Blocks.log, 0, 0);
            }
          }

          if (height > 4) {
            createTrunk(p_76484_1_, p_76484_2_, p_76484_3_, p_76484_4_, p_76484_5_);
          }

          return true;
        } else {
          return false;
        }
      }
    } else {
      return false;
    }
  }
Esempio n. 16
0
  @Override
  public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5) {
    final int var6 = par2Random.nextInt(3) + 5;
    boolean var7 = true;

    if (par4 >= 1 && par4 + var6 + 1 <= 256) {
      int var8;
      int var10;
      int var11;
      int var12;

      for (var8 = par4; var8 <= par4 + 1 + var6; ++var8) {
        byte var9 = 1;

        if (var8 == par4) {
          var9 = 0;
        }

        if (var8 >= par4 + 1 + var6 - 2) {
          var9 = 2;
        }

        for (var10 = par3 - var9; var10 <= par3 + var9 && var7; ++var10) {
          for (var11 = par5 - var9; var11 <= par5 + var9 && var7; ++var11) {
            if (var8 >= 0 && var8 < 256) {
              Block var12b = par1World.getBlock(var10, var8, var11);

              if (var12b != Blocks.air && !var12b.isLeaves(par1World, var10, var8, var11)) {
                var7 = false;
              }
            } else {
              var7 = false;
            }
          }
        }
      }

      if (!var7) {
        return false;
      } else {
        Block var8b = par1World.getBlock(par3, par4 - 1, par5);
        final int var10a = par1World.getBlockMetadata(par3, par4 - 1, par5);

        int waterBlocksNearby = 0;

        for (int i = -4; i < 5; i++) {
          for (int j = -4; j < 5; j++) {
            if (par1World.getBlock(par3 + i, par4 - 1, par5 + j) == Blocks.flowing_water
                || par1World.getBlock(par3 + i, par4 - 1, par5 + j) == Blocks.water) {
              waterBlocksNearby++;
            }
          }
        }

        final boolean flag =
            var8b instanceof IPlantableBlock
                || var8b instanceof IPlantableBlock
                    && ((IPlantableBlock) var8b).isPlantable(var10a);
        final boolean flag2 =
            var8b instanceof IPlantableBlock
                    && waterBlocksNearby >= ((IPlantableBlock) var8b).requiredLiquidBlocksNearby()
                || var8b instanceof IPlantableBlock
                    && waterBlocksNearby >= ((IPlantableBlock) var8b).requiredLiquidBlocksNearby();
        final boolean flag3 = par4 < 256 - var6 - 1;
        final boolean flag4 =
            (var8b instanceof BlockGrass || var8b instanceof BlockDirt) && waterBlocksNearby >= 4;

        if (flag && flag2 && flag3 || flag4) {
          int var16;

          for (var16 = par4 - 3 + var6; var16 <= par4 + var6; ++var16) {
            var10 = var16 - (par4 + var6);
            var11 = 1 - var10 / 2;

            for (var12 = par3 - var11; var12 <= par3 + var11; ++var12) {
              final int var13 = var12 - par3;

              for (int var14 = par5 - var11; var14 <= par5 + var11; ++var14) {
                final int var15 = var14 - par5;

                final Block block = par1World.getBlock(var12, var16, var14);

                if ((Math.abs(var13) != var11
                        || Math.abs(var15) != var11
                        || par2Random.nextInt(2) != 0 && var10 != 0)
                    && (block == null
                        || block.canBeReplacedByLeaves(par1World, var12, var16, var14))) {
                  this.setBlockAndNotifyAdequately(
                      par1World, var12, var16, var14, Blocks.leaves, 2);
                }
              }
            }
          }

          for (var16 = 0; var16 < var6; ++var16) {
            Block block = par1World.getBlock(par3, par4 + var16, par5);

            if (block == Blocks.air || block.isLeaves(par1World, par3, par4 + var16, par5)) {
              this.setBlockAndNotifyAdequately(
                  par1World, par3, par4 + var16, par5, Blocks.planks, 2);
            }
          }

          return true;
        } else {
          return false;
        }
      }
    } else {
      return false;
    }
  }
  @Override
  public void handleCommand(ICommandSender sender, String[] args) {

    if (args.length < 7) {
      sender.addChatMessage(new ChatComponentTranslation("info.cofh.command.syntaxError"));
      throw new WrongUsageException("info.cofh.command." + getCommandName() + ".syntax");
    }
    World world = sender.getEntityWorld();
    if (world.isRemote) {
      return;
    }

    ChunkCoordinates center = null;
    int i = 1;
    int xS, xL;
    if ("@".equals(args[i])) {
      center = sender.getPlayerCoordinates();
      ++i;
      xS = CommandBase.parseInt(sender, args[i++]);
    } else {
      try {
        xS = CommandBase.parseInt(sender, args[i++]);
      } catch (Throwable t) {
        center = CommandBase.getPlayer(sender, args[i - 1]).getPlayerCoordinates();
        xS = CommandBase.parseInt(sender, args[i++]);
      }
    }
    int yS = CommandBase.parseInt(sender, args[i++]), yL;
    int zS = CommandBase.parseInt(sender, args[i++]), zL;
    int t = i + 1;

    try {
      xL = CommandBase.parseInt(sender, args[i++]);
      yL = CommandBase.parseInt(sender, args[i++]);
      zL = CommandBase.parseInt(sender, args[i++]);
    } catch (Throwable e) {
      if (i > t || center == null) {
        throw Throwables.propagate(e);
      }
      --i;
      xL = xS;
      yL = yS;
      zL = zS;
    }

    if (center != null) {
      xS = center.posX - xS;
      yS = center.posY - yS;
      zS = center.posZ - zS;

      xL = center.posX + xL;
      yL = center.posY + yL;
      zL = center.posZ + zL;
    }

    yS &= ~yS >> 31; // max(yS, 0)
    yL &= ~yL >> 31; // max(yL, 0)

    if (xL < xS) {
      t = xS;
      xS = xL;
      xL = t;
    }
    if (yL < yS) {
      t = yS;
      yS = yL;
      yL = t;
    }
    if (zL < zS) {
      t = zS;
      zS = zL;
      zL = t;
    }

    if (yS > 255) {
      sender.addChatMessage(new ChatComponentTranslation("info.cofh.command.syntaxError"));
      sender.addChatMessage(
          new ChatComponentTranslation("info.cofh.command." + getCommandName() + ".syntax"));
      return;
    } else if (yL > 255) {
      yL = 255;
    }

    Block replBlock;
    int replMeta;
    String blockReplRaw;
    {
      int meta = 0;
      String blockRaw = args[i];
      blockReplRaw = blockRaw;
      t = blockRaw.indexOf('#');
      if (t > 0) {
        meta = CommandBase.parseInt(sender, blockRaw.substring(t + 1));
        blockRaw = blockRaw.substring(0, t);
      }
      Block block = Block.getBlockFromName(blockRaw);
      if (block == Blocks.air || meta > 15 || meta < 0) {
        sender.addChatMessage(new ChatComponentTranslation("info.cofh.command.syntaxError"));
        sender.addChatMessage(
            new ChatComponentTranslation("info.cofh.command." + getCommandName() + ".syntax"));
        // TODO: more descriptive error
        return;
      }
      replBlock = block;
      replMeta = meta;
    }

    long blockCounter = ((long) xL - xS) * ((long) yL - yS) * ((long) zL - zS);
    CommandHandler.logAdminCommand(
        sender,
        this,
        "info.cofh.command.replaceblocks.start",
        blockCounter,
        xS,
        yS,
        zS,
        xL,
        yL,
        zL,
        blockReplRaw);

    THashSet<Chunk> set = new THashSet<Chunk>();

    blockCounter = 0;
    for (int e = args.length; i < e; ++i) {
      String blockRaw = args[i];
      if (blockRaw.charAt(0) == '*') {
        if (blockRaw.equals("*fluid")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                if (block.getMaterial().isLiquid()) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        } else if (blockRaw.equals("*tree")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                if (block.isWood(world, x, y, z) || block.isLeaves(world, x, y, z)) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        } else if (blockRaw.startsWith("*repl")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                if (block.isReplaceable(world, x, y, z)) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        } else if (blockRaw.equals("*stone")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                if (block.isReplaceableOreGen(world, x, y, z, Blocks.stone)
                    || block.isReplaceableOreGen(world, x, y, z, Blocks.netherrack)
                    || block.isReplaceableOreGen(world, x, y, z, Blocks.end_stone)) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        } else if (blockRaw.equals("*rock")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                if (block.getMaterial() == Material.rock) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        } else if (blockRaw.equals("*sand")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                if (block.getMaterial() == Material.sand) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        } else if (blockRaw.equals("*dirt")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                Material m = block.getMaterial();
                if (m == Material.grass
                    || m == Material.ground
                    || m == Material.clay
                    || m == Material.snow
                    || m == Material.craftedSnow
                    || m == Material.ice
                    || m == Material.packedIce) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        } else if (blockRaw.startsWith("*plant")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                Material m = block.getMaterial();
                if (m == Material.plants
                    || m == Material.vine
                    || m == Material.cactus
                    || m == Material.leaves) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        } else if (blockRaw.equals("*fire")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                Material m = block.getMaterial();
                if (m == Material.fire || m == Material.lava || block.isBurning(world, x, y, z)) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        }
        continue;
      }
      int meta = -1;
      t = blockRaw.indexOf('#');
      if (t > 0) {
        meta = CommandBase.parseInt(sender, blockRaw.substring(t + 1));
        blockRaw = blockRaw.substring(0, t);
      }
      Block block = Block.getBlockFromName(blockRaw);
      if (block == Blocks.air) {
        continue;
      }

      for (int x = xS; x <= xL; ++x) {
        for (int z = zS; z <= zL; ++z) {
          Chunk chunk = world.getChunkFromBlockCoords(x, z);
          int cX = x & 15, cZ = z & 15;
          for (int y = yS; y <= yL; ++y) {
            boolean v = meta == -1 || chunk.getBlockMetadata(cX, y, cZ) == meta;
            if (v && chunk.getBlock(cX, y, cZ) == block) {
              if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                ++blockCounter;
                set.add(chunk);
              }
            }
          }
        }
      }
    }
    if (!set.isEmpty()) {
      CommandHandler.logAdminCommand(
          sender,
          this,
          "info.cofh.command.replaceblocks.success",
          blockCounter,
          xS,
          yS,
          zS,
          xL,
          yL,
          zL,
          blockReplRaw);
    } else {
      CommandHandler.logAdminCommand(sender, this, "info.cofh.command.replaceblocks.failure");
    }

    if (world instanceof WorldServer) {
      TObjectHashIterator<Chunk> c = set.iterator();
      for (int k = 0, e = set.size(); k < e; ++k) {
        Chunk chunk = c.next();
        PlayerManager manager = ((WorldServer) world).getPlayerManager();
        if (manager == null) {
          return;
        }
        PlayerInstance watcher =
            manager.getOrCreateChunkWatcher(chunk.xPosition, chunk.zPosition, false);
        if (watcher != null) {
          watcher.sendToAllPlayersWatchingChunk(new S21PacketChunkData(chunk, false, -1));
        }
      }
    }
  }
  public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5) {
    int l = par2Random.nextInt(2);

    if (this.mushroomType >= 0) {
      l = this.mushroomType;
    }

    int i1 = par2Random.nextInt(3) + 4;
    boolean flag = true;

    if (par4 >= 1 && par4 + i1 + 1 < 256) {
      int k1;
      int l1;

      for (int j1 = par4; j1 <= par4 + 1 + i1; ++j1) {
        byte b0 = 3;

        if (j1 <= par4 + 3) {
          b0 = 0;
        }

        for (k1 = par3 - b0; k1 <= par3 + b0 && flag; ++k1) {
          for (l1 = par5 - b0; l1 <= par5 + b0 && flag; ++l1) {
            if (j1 >= 0 && j1 < 256) {
              Block block = par1World.getBlock(k1, j1, l1);

              if (!block.isAir(par1World, k1, j1, l1) && !block.isLeaves(par1World, k1, j1, l1)) {
                flag = false;
              }
            } else {
              flag = false;
            }
          }
        }
      }

      if (!flag) {
        return false;
      } else {
        Block block1 = par1World.getBlock(par3, par4 - 1, par5);

        if (block1 != Blocks.dirt && block1 != Blocks.grass && block1 != Blocks.mycelium) {
          return false;
        } else {
          int k2 = par4 + i1;

          if (l == 1) {
            k2 = par4 + i1 - 3;
          }

          for (k1 = k2; k1 <= par4 + i1; ++k1) {
            l1 = 1;

            if (k1 < par4 + i1) {
              ++l1;
            }

            if (l == 0) {
              l1 = 3;
            }

            for (int l2 = par3 - l1; l2 <= par3 + l1; ++l2) {
              for (int i2 = par5 - l1; i2 <= par5 + l1; ++i2) {
                int j2 = 5;

                if (l2 == par3 - l1) {
                  --j2;
                }

                if (l2 == par3 + l1) {
                  ++j2;
                }

                if (i2 == par5 - l1) {
                  j2 -= 3;
                }

                if (i2 == par5 + l1) {
                  j2 += 3;
                }

                if (l == 0 || k1 < par4 + i1) {
                  if ((l2 == par3 - l1 || l2 == par3 + l1)
                      && (i2 == par5 - l1 || i2 == par5 + l1)) {
                    continue;
                  }

                  if (l2 == par3 - (l1 - 1) && i2 == par5 - l1) {
                    j2 = 1;
                  }

                  if (l2 == par3 - l1 && i2 == par5 - (l1 - 1)) {
                    j2 = 1;
                  }

                  if (l2 == par3 + (l1 - 1) && i2 == par5 - l1) {
                    j2 = 3;
                  }

                  if (l2 == par3 + l1 && i2 == par5 - (l1 - 1)) {
                    j2 = 3;
                  }

                  if (l2 == par3 - (l1 - 1) && i2 == par5 + l1) {
                    j2 = 7;
                  }

                  if (l2 == par3 - l1 && i2 == par5 + (l1 - 1)) {
                    j2 = 7;
                  }

                  if (l2 == par3 + (l1 - 1) && i2 == par5 + l1) {
                    j2 = 9;
                  }

                  if (l2 == par3 + l1 && i2 == par5 + (l1 - 1)) {
                    j2 = 9;
                  }
                }

                if (j2 == 5 && k1 < par4 + i1) {
                  j2 = 0;
                }

                if ((j2 != 0 || par4 >= par4 + i1 - 1)
                    && par1World
                        .getBlock(l2, k1, i2)
                        .canBeReplacedByLeaves(par1World, l2, k1, i2)) {
                  this.setBlockAndNotifyAdequately(
                      par1World,
                      l2,
                      k1,
                      i2,
                      Block.getBlockById(Block.getIdFromBlock(Blocks.brown_mushroom_block) + l),
                      j2);
                }
              }
            }
          }

          for (k1 = 0; k1 < i1; ++k1) {
            Block block2 = par1World.getBlock(par3, par4 + k1, par5);

            if (block2.canBeReplacedByLeaves(par1World, par3, par4 + k1, par5)) {
              this.setBlockAndNotifyAdequately(
                  par1World,
                  par3,
                  par4 + k1,
                  par5,
                  Block.getBlockById(Block.getIdFromBlock(Blocks.brown_mushroom_block) + l),
                  10);
            }
          }

          return true;
        }
      }
    } else {
      return false;
    }
  }
Esempio n. 19
0
  public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5) {
    int l = par2Random.nextInt(3) + this.minTreeHeight;
    boolean flag = true;

    if (par4 >= 1 && par4 + l + 1 <= 256) {
      int i1;
      byte b0;
      int j1;
      int k1;

      for (i1 = par4; i1 <= par4 + 1 + l; ++i1) {
        b0 = 1;

        if (i1 == par4) {
          b0 = 0;
        }

        if (i1 >= par4 + 1 + l - 2) {
          b0 = 2;
        }

        for (int l1 = par3 - b0; l1 <= par3 + b0 && flag; ++l1) {
          for (j1 = par5 - b0; j1 <= par5 + b0 && flag; ++j1) {
            if (i1 >= 0 && i1 < 256) {
              Block block = par1World.getBlock(l1, i1, j1);

              if (block != Blocks.air
                  && !block.isLeaves(par1World, l1, i1, j1)
                  && block != Blocks.grass
                  && block != Blocks.dirt
                  && !block.isWood(par1World, l1, i1, j1)) {
                flag = false;
              }
            } else {
              flag = false;
            }
          }
        }
      }

      if (!flag) {
        return false;
      } else {
        Block soil = par1World.getBlock(par3, par4 - 1, par5);
        boolean isSoil =
            (soil != null
                && soil.canSustainPlant(
                    par1World,
                    par3,
                    par4 - 1,
                    par5,
                    ForgeDirection.UP,
                    (BlockSapling) Blocks.sapling));

        if (isSoil && par4 < 256 - l - 1) {
          soil.onPlantGrow(par1World, par3, par4 - 1, par5, par3, par4, par5);
          b0 = 3;
          byte b1 = 0;
          int i2;
          int j2;
          int k2;

          for (j1 = par4 - b0 + l; j1 <= par4 + l; ++j1) {
            k1 = j1 - (par4 + l);
            i2 = b1 + 1 - k1 / 2;

            for (j2 = par3 - i2; j2 <= par3 + i2; ++j2) {
              k2 = j2 - par3;

              for (int l2 = par5 - i2; l2 <= par5 + i2; ++l2) {
                int i3 = l2 - par5;

                if (Math.abs(k2) != i2
                    || Math.abs(i3) != i2
                    || par2Random.nextInt(2) != 0 && k1 != 0) {

                  Block block = par1World.getBlock(j2, j1, l2);

                  if (block == null || block.canBeReplacedByLeaves(par1World, j2, j1, l2)) {
                    this.setBlockAndNotifyAdequately(par1World, j2, j1, l2, this.blockLeaves, 0);
                  }
                }
              }
            }
          }

          for (j1 = 0; j1 < l; ++j1) {
            Block block = par1World.getBlock(par3, par4 + j1, par5);

            // TODO- removed k1 = 0, right fix?
            if (block == Blocks.air || block.isLeaves(par1World, par3, par4 + j1, par5)) {
              this.setBlockAndNotifyAdequately(par1World, par3, par4 + j1, par5, this.blockWood, 0);

              if (this.vinesGrow && j1 > 0) {
                if (par2Random.nextInt(3) > 0 && par1World.isAirBlock(par3 - 1, par4 + j1, par5)) {
                  this.setBlockAndNotifyAdequately(
                      par1World, par3 - 1, par4 + j1, par5, Blocks.vine, 8);
                }

                if (par2Random.nextInt(3) > 0 && par1World.isAirBlock(par3 + 1, par4 + j1, par5)) {
                  this.setBlockAndNotifyAdequately(
                      par1World, par3 + 1, par4 + j1, par5, Blocks.vine, 2);
                }

                if (par2Random.nextInt(3) > 0 && par1World.isAirBlock(par3, par4 + j1, par5 - 1)) {
                  this.setBlockAndNotifyAdequately(
                      par1World, par3, par4 + j1, par5 - 1, Blocks.vine, 1);
                }

                if (par2Random.nextInt(3) > 0 && par1World.isAirBlock(par3, par4 + j1, par5 + 1)) {
                  this.setBlockAndNotifyAdequately(
                      par1World, par3, par4 + j1, par5 + 1, Blocks.vine, 4);
                }
              }
            }
          }

          if (this.vinesGrow) {
            for (j1 = par4 - 3 + l; j1 <= par4 + l; ++j1) {
              k1 = j1 - (par4 + l);
              i2 = 2 - k1 / 2;

              for (j2 = par3 - i2; j2 <= par3 + i2; ++j2) {
                for (k2 = par5 - i2; k2 <= par5 + i2; ++k2) {
                  Block block = par1World.getBlock(j2, j1, k2);
                  if (block != null && block.isLeaves(par1World, j2, j1, k2)) {
                    if (par2Random.nextInt(4) == 0
                        && par1World.getBlock(j2 - 1, j1, k2) == Blocks.air) {
                      this.growVines(par1World, j2 - 1, j1, k2, 8);
                    }

                    if (par2Random.nextInt(4) == 0
                        && par1World.getBlock(j2 + 1, j1, k2) == Blocks.air) {
                      this.growVines(par1World, j2 + 1, j1, k2, 2);
                    }

                    if (par2Random.nextInt(4) == 0
                        && par1World.getBlock(j2, j1, k2 - 1) == Blocks.air) {
                      this.growVines(par1World, j2, j1, k2 - 1, 1);
                    }

                    if (par2Random.nextInt(4) == 0
                        && par1World.getBlock(j2, j1, k2 + 1) == Blocks.air) {
                      this.growVines(par1World, j2, j1, k2 + 1, 4);
                    }
                  }
                }
              }
            }
          }

          return true;
        } else {
          return false;
        }
      }
    } else {
      return false;
    }
  }
  public boolean generate(
      World p_76484_1_, Random p_76484_2_, int p_76484_3_, int p_76484_4_, int p_76484_5_) {
    int l = p_76484_2_.nextInt(2);

    if (this.mushroomType >= 0) {
      l = this.mushroomType;
    }

    int i1 = p_76484_2_.nextInt(3) + 4;
    boolean flag = true;

    if (p_76484_4_ >= 1 && p_76484_4_ + i1 + 1 < 256) {
      int k1;
      int l1;

      for (int j1 = p_76484_4_; j1 <= p_76484_4_ + 1 + i1; ++j1) {
        byte b0 = 3;

        if (j1 <= p_76484_4_ + 3) {
          b0 = 0;
        }

        for (k1 = p_76484_3_ - b0; k1 <= p_76484_3_ + b0 && flag; ++k1) {
          for (l1 = p_76484_5_ - b0; l1 <= p_76484_5_ + b0 && flag; ++l1) {
            if (j1 >= 0 && j1 < 256) {
              Block block = p_76484_1_.getBlock(k1, j1, l1);

              if (!block.isAir(p_76484_1_, k1, j1, l1) && !block.isLeaves(p_76484_1_, k1, j1, l1)) {
                flag = false;
              }
            } else {
              flag = false;
            }
          }
        }
      }

      if (!flag) {
        return false;
      } else {
        Block block1 = p_76484_1_.getBlock(p_76484_3_, p_76484_4_ - 1, p_76484_5_);

        if (block1 != Blocks.dirt
            && block1 != Blocks.grass
            && block1 != EnhancedBiomesBlocks.dirtEB
            && block1 != EnhancedBiomesBlocks.grassEB
            && block1 != Blocks.mycelium) {
          return false;
        } else {
          int k2 = p_76484_4_ + i1;

          if (l == 1) {
            k2 = p_76484_4_ + i1 - 3;
          }

          for (k1 = k2; k1 <= p_76484_4_ + i1; ++k1) {
            l1 = 1;

            if (k1 < p_76484_4_ + i1) {
              ++l1;
            }

            if (l == 0) {
              l1 = 3;
            }

            for (int l2 = p_76484_3_ - l1; l2 <= p_76484_3_ + l1; ++l2) {
              for (int i2 = p_76484_5_ - l1; i2 <= p_76484_5_ + l1; ++i2) {
                int j2 = 5;

                if (l2 == p_76484_3_ - l1) {
                  --j2;
                }

                if (l2 == p_76484_3_ + l1) {
                  ++j2;
                }

                if (i2 == p_76484_5_ - l1) {
                  j2 -= 3;
                }

                if (i2 == p_76484_5_ + l1) {
                  j2 += 3;
                }

                if (l == 0 || k1 < p_76484_4_ + i1) {
                  if ((l2 == p_76484_3_ - l1 || l2 == p_76484_3_ + l1)
                      && (i2 == p_76484_5_ - l1 || i2 == p_76484_5_ + l1)) {
                    continue;
                  }

                  if (l2 == p_76484_3_ - (l1 - 1) && i2 == p_76484_5_ - l1) {
                    j2 = 1;
                  }

                  if (l2 == p_76484_3_ - l1 && i2 == p_76484_5_ - (l1 - 1)) {
                    j2 = 1;
                  }

                  if (l2 == p_76484_3_ + (l1 - 1) && i2 == p_76484_5_ - l1) {
                    j2 = 3;
                  }

                  if (l2 == p_76484_3_ + l1 && i2 == p_76484_5_ - (l1 - 1)) {
                    j2 = 3;
                  }

                  if (l2 == p_76484_3_ - (l1 - 1) && i2 == p_76484_5_ + l1) {
                    j2 = 7;
                  }

                  if (l2 == p_76484_3_ - l1 && i2 == p_76484_5_ + (l1 - 1)) {
                    j2 = 7;
                  }

                  if (l2 == p_76484_3_ + (l1 - 1) && i2 == p_76484_5_ + l1) {
                    j2 = 9;
                  }

                  if (l2 == p_76484_3_ + l1 && i2 == p_76484_5_ + (l1 - 1)) {
                    j2 = 9;
                  }
                }

                if (j2 == 5 && k1 < p_76484_4_ + i1) {
                  j2 = 0;
                }

                if ((j2 != 0 || p_76484_4_ >= p_76484_4_ + i1 - 1)
                    && p_76484_1_
                        .getBlock(l2, k1, i2)
                        .canBeReplacedByLeaves(p_76484_1_, l2, k1, i2)) {
                  this.setBlockAndNotifyAdequately(
                      p_76484_1_,
                      l2,
                      k1,
                      i2,
                      Block.getBlockById(Block.getIdFromBlock(Blocks.brown_mushroom_block) + l),
                      j2);
                }
              }
            }
          }

          for (k1 = 0; k1 < i1; ++k1) {
            Block block2 = p_76484_1_.getBlock(p_76484_3_, p_76484_4_ + k1, p_76484_5_);

            if (block2.canBeReplacedByLeaves(p_76484_1_, p_76484_3_, p_76484_4_ + k1, p_76484_5_)) {
              this.setBlockAndNotifyAdequately(
                  p_76484_1_,
                  p_76484_3_,
                  p_76484_4_ + k1,
                  p_76484_5_,
                  Block.getBlockById(Block.getIdFromBlock(Blocks.brown_mushroom_block) + l),
                  10);
            }
          }

          return true;
        }
      }
    } else {
      return false;
    }
  }
Esempio n. 21
0
  @Override
  public void updateTick(World world, int x, int y, int z, Random random) {
    if (world.isRemote) return;

    int meta = world.getBlockMetadata(x, y, z);

    if ((meta & 8) != 0 /* && (meta & 4) == 0*/) {
      byte b0 = 4;
      int i1 = b0 + 1;
      byte b1 = 32;
      int j1 = b1 * b1;
      int k1 = b1 / 2;

      if (adjacentTreeBlocks == null) {
        adjacentTreeBlocks = new int[b1 * b1 * b1];
      }

      int l1;

      if (world.checkChunksExist(x - i1, y - i1, z - i1, x + i1, y + i1, z + i1)) {
        int i2;
        int j2;
        int k2;

        for (l1 = -b0; l1 <= b0; ++l1) {
          for (i2 = -b0; i2 <= b0; ++i2) {
            for (j2 = -b0; j2 <= b0; ++j2) {
              k2 = world.getBlockId(x + l1, y + i2, z + j2);

              Block block = Block.blocksList[k2];

              if (block != null && block.canSustainLeaves(world, x + l1, y + i2, z + j2)) {
                adjacentTreeBlocks[(l1 + k1) * j1 + (i2 + k1) * b1 + j2 + k1] = 0;
              } else if (block != null && block.isLeaves(world, x + l1, y + i2, z + j2)) {
                adjacentTreeBlocks[(l1 + k1) * j1 + (i2 + k1) * b1 + j2 + k1] = -2;
              } else {
                adjacentTreeBlocks[(l1 + k1) * j1 + (i2 + k1) * b1 + j2 + k1] = -1;
              }
            }
          }
        }

        for (l1 = 1; l1 <= 4; ++l1) {
          for (i2 = -b0; i2 <= b0; ++i2) {
            for (j2 = -b0; j2 <= b0; ++j2) {
              for (k2 = -b0; k2 <= b0; ++k2) {
                if (adjacentTreeBlocks[(i2 + k1) * j1 + (j2 + k1) * b1 + k2 + k1] == l1 - 1) {
                  if (adjacentTreeBlocks[(i2 + k1 - 1) * j1 + (j2 + k1) * b1 + k2 + k1] == -2) {
                    adjacentTreeBlocks[(i2 + k1 - 1) * j1 + (j2 + k1) * b1 + k2 + k1] = l1;
                  }

                  if (adjacentTreeBlocks[(i2 + k1 + 1) * j1 + (j2 + k1) * b1 + k2 + k1] == -2) {
                    adjacentTreeBlocks[(i2 + k1 + 1) * j1 + (j2 + k1) * b1 + k2 + k1] = l1;
                  }

                  if (adjacentTreeBlocks[(i2 + k1) * j1 + (j2 + k1 - 1) * b1 + k2 + k1] == -2) {
                    adjacentTreeBlocks[(i2 + k1) * j1 + (j2 + k1 - 1) * b1 + k2 + k1] = l1;
                  }

                  if (adjacentTreeBlocks[(i2 + k1) * j1 + (j2 + k1 + 1) * b1 + k2 + k1] == -2) {
                    adjacentTreeBlocks[(i2 + k1) * j1 + (j2 + k1 + 1) * b1 + k2 + k1] = l1;
                  }

                  if (adjacentTreeBlocks[(i2 + k1) * j1 + (j2 + k1) * b1 + (k2 + k1 - 1)] == -2) {
                    adjacentTreeBlocks[(i2 + k1) * j1 + (j2 + k1) * b1 + (k2 + k1 - 1)] = l1;
                  }

                  if (adjacentTreeBlocks[(i2 + k1) * j1 + (j2 + k1) * b1 + k2 + k1 + 1] == -2) {
                    adjacentTreeBlocks[(i2 + k1) * j1 + (j2 + k1) * b1 + k2 + k1 + 1] = l1;
                  }
                }
              }
            }
          }
        }
      }

      l1 = adjacentTreeBlocks[k1 * j1 + k1 * b1 + k1];

      if (l1 >= 0) {
        world.setBlockMetadataWithNotify(x, y, z, meta & -9, 4);
      } else {
        this.removeLeaves(world, x, y, z);
      }
    }
  }
Esempio n. 22
0
  /** Ticks the block if it's been scheduled */
  public void updateTick(World var1, int var2, int var3, int var4, Random var5) {
    if (!var1.isRemote) {
      int var6 = var1.getBlockMetadata(var2, var3, var4);

      if ((var6 & 8) != 0 && (var6 & 4) == 0) {
        byte var7 = 4;
        int var8 = var7 + 1;
        byte var9 = 32;
        int var10 = var9 * var9;
        int var11 = var9 / 2;

        if (this.adjacentTreeBlocks == null) {
          this.adjacentTreeBlocks = new int[var9 * var9 * var9];
        }

        int var12;

        if (var1.checkChunksExist(
            var2 - var8, var3 - var8, var4 - var8, var2 + var8, var3 + var8, var4 + var8)) {
          int var13;
          int var14;
          int var15;

          for (var12 = -var7; var12 <= var7; ++var12) {
            for (var13 = -var7; var13 <= var7; ++var13) {
              for (var14 = -var7; var14 <= var7; ++var14) {
                var15 = var1.getBlockId(var2 + var12, var3 + var13, var4 + var14);
                Block var16 = Block.blocksList[var15];

                if (var16 != null
                    && var16.canSustainLeaves(var1, var2 + var12, var3 + var13, var4 + var14)) {
                  this.adjacentTreeBlocks[
                          (var12 + var11) * var10 + (var13 + var11) * var9 + var14 + var11] =
                      0;
                } else if (var16 != null
                    && var16.isLeaves(var1, var2 + var12, var3 + var13, var4 + var14)) {
                  this.adjacentTreeBlocks[
                          (var12 + var11) * var10 + (var13 + var11) * var9 + var14 + var11] =
                      -2;
                } else {
                  this.adjacentTreeBlocks[
                          (var12 + var11) * var10 + (var13 + var11) * var9 + var14 + var11] =
                      -1;
                }
              }
            }
          }

          for (var12 = 1; var12 <= 4; ++var12) {
            for (var13 = -var7; var13 <= var7; ++var13) {
              for (var14 = -var7; var14 <= var7; ++var14) {
                for (var15 = -var7; var15 <= var7; ++var15) {
                  if (this.adjacentTreeBlocks[
                          (var13 + var11) * var10 + (var14 + var11) * var9 + var15 + var11]
                      == var12 - 1) {
                    if (this.adjacentTreeBlocks[
                            (var13 + var11 - 1) * var10 + (var14 + var11) * var9 + var15 + var11]
                        == -2) {
                      this.adjacentTreeBlocks[
                              (var13 + var11 - 1) * var10
                                  + (var14 + var11) * var9
                                  + var15
                                  + var11] =
                          var12;
                    }

                    if (this.adjacentTreeBlocks[
                            (var13 + var11 + 1) * var10 + (var14 + var11) * var9 + var15 + var11]
                        == -2) {
                      this.adjacentTreeBlocks[
                              (var13 + var11 + 1) * var10
                                  + (var14 + var11) * var9
                                  + var15
                                  + var11] =
                          var12;
                    }

                    if (this.adjacentTreeBlocks[
                            (var13 + var11) * var10 + (var14 + var11 - 1) * var9 + var15 + var11]
                        == -2) {
                      this.adjacentTreeBlocks[
                              (var13 + var11) * var10
                                  + (var14 + var11 - 1) * var9
                                  + var15
                                  + var11] =
                          var12;
                    }

                    if (this.adjacentTreeBlocks[
                            (var13 + var11) * var10 + (var14 + var11 + 1) * var9 + var15 + var11]
                        == -2) {
                      this.adjacentTreeBlocks[
                              (var13 + var11) * var10
                                  + (var14 + var11 + 1) * var9
                                  + var15
                                  + var11] =
                          var12;
                    }

                    if (this.adjacentTreeBlocks[
                            (var13 + var11) * var10 + (var14 + var11) * var9 + (var15 + var11 - 1)]
                        == -2) {
                      this.adjacentTreeBlocks[
                              (var13 + var11) * var10
                                  + (var14 + var11) * var9
                                  + (var15 + var11 - 1)] =
                          var12;
                    }

                    if (this.adjacentTreeBlocks[
                            (var13 + var11) * var10 + (var14 + var11) * var9 + var15 + var11 + 1]
                        == -2) {
                      this.adjacentTreeBlocks[
                              (var13 + var11) * var10
                                  + (var14 + var11) * var9
                                  + var15
                                  + var11
                                  + 1] =
                          var12;
                    }
                  }
                }
              }
            }
          }
        }

        var12 = this.adjacentTreeBlocks[var11 * var10 + var11 * var9 + var11];

        if (var12 >= 0) {
          var1.setBlockMetadata(var2, var3, var4, var6 & -9);
        } else {
          this.removeLeaves(var1, var2, var3, var4);
        }
      }
    }
  }
Esempio n. 23
0
  @Override
  public boolean generate(World par1World, Random par2Random, int posX, int posY, int posZ) {
    int l = par2Random.nextInt(3) + 5;
    boolean flag = true;

    if (posY >= 1
        && posY + l + 1 <= 256) // generates tree if posY is greater than 1 and less than 256
    {
      int i1; // y
      int j1; // x
      int k1; // z
      int l1;

      for (i1 = posY; i1 <= posY + 1 + l; ++i1) {
        byte b0 = 1;

        if (i1 == posY) {
          b0 = 0;
        }

        if (i1 >= posY + 1 + l - 2) {
          b0 = 2;
        }

        for (j1 = posX - b0; j1 <= posX + b0 && flag; ++j1) {
          for (k1 = posZ - b0; k1 <= posZ + b0 && flag; ++k1) {
            if (i1 >= 0 && i1 < 256) {
              l1 = par1World.getBlockId(j1, i1, k1);

              Block block = Block.blocksList[l1];

              if (l1 != 0 && (block != null && !block.isLeaves(par1World, j1, i1, k1))) {
                flag = false;
              }
            } else {
              flag = false;
            }
          }
        }
      }

      if (!flag) {
        return false;
      } else {
        i1 = par1World.getBlockId(posX, posY - 1, posZ);
        Block soil = Block.blocksList[i1];
        boolean isValidSoil =
            soil != null
                && soil.canSustainPlant(
                    par1World,
                    posX,
                    posY - 1,
                    posZ,
                    ForgeDirection.UP,
                    (BlockDreamSaplings) ModBlocks.dreamSaplings);

        if (isValidSoil && posY < 256 - l - 1) {
          soil.onPlantGrow(par1World, posX, posY - 1, posZ, posX, posY, posZ);
          int i2;

          for (i2 = posY - 3 + l; i2 <= posY + l; ++i2) {
            j1 = i2 - (posY + l);
            k1 = 1 - j1 / 2;

            for (l1 = posX - k1; l1 <= posX + k1; ++l1) {
              int j2 = l1 - posX;

              for (int k2 = posZ - k1; k2 <= posZ + k1; ++k2) {
                int l2 = k2 - posZ;

                if (Math.abs(j2) != k1
                    || Math.abs(l2) != k1
                    || par2Random.nextInt(2) != 0 && j1 != 0) {
                  int i3 = par1World.getBlockId(l1, i2, k2);
                  Block block = Block.blocksList[i3];

                  if (block == null || block.canBeReplacedByLeaves(par1World, l1, i2, k2)) {
                    this.setBlockAndMetadata(
                        par1World, l1, i2, k2, ModBlocks.dreamLeaves.blockID, 1);
                  }
                }
              }
            }
          }

          for (i2 = 0; i2 < l; ++i2) {
            j1 = par1World.getBlockId(posX, posY + i2, posZ);

            Block block = Block.blocksList[j1];

            if (j1 == 0 || block == null || block.isLeaves(par1World, posX, posY + i2, posZ)) {
              this.setBlockAndMetadata(
                  par1World, posX, posY + i2, posZ, ModBlocks.nmLogs.blockID, 0);
            }
          }

          return true;
        } else {
          return false;
        }
      }
    } else {
      return false;
    }
  }
  public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5) {
    int l = par2Random.nextInt(3) + this.minTreeHeight;
    boolean flag = true;
    if (par4 >= 1 && par4 + l + 1 <= 256) {
      int i1;
      byte b0;
      int j1;
      int k1;
      for (i1 = par4; i1 <= par4 + 1 + l; ++i1) {
        b0 = 1;
        if (i1 == par4) {
          b0 = 0;
        }
        if (i1 >= par4 + 1 + l - 2) {
          b0 = 2;
        }
        for (int l1 = par3 - b0; l1 <= par3 + b0 && flag; ++l1) {
          for (j1 = par5 - b0; j1 <= par5 + b0 && flag; ++j1) {
            if (i1 >= 0 && i1 < 256) {
              k1 = par1World.getBlockId(l1, i1 - 1, j1);
              /** Custom grass block * */
              Block block = IntegratedBlocks.DarkSand;
              if (k1 != 0
                  && !block.isLeaves(par1World, l1, i1, j1)

                  /** Custom grass block * */
                  && k1 != IntegratedBlocks.DarkSand.blockID
                  && k1 != Block.dirt.blockID
                  && k1 != Block.grass.blockID
                  && k1 != Block.sand.blockID
                  && !block.isWood(par1World, l1, i1, j1)) {
                flag = false;
              }
            } else {
              flag = false;
            }
          }
        }
      }
      if (!flag) {
        return false;
      } else {
        i1 = par1World.getBlockId(par3, par4 - 1, par5);

        /** Custom grass block * */
        Block soil = IntegratedBlocks.DarkSand; // , Block.dirt, Block.sand, Block.grass;

        /** Custom Sapling block * */
        boolean isSoil =
            (soil != null
                && soil.canSustainPlant(
                    par1World,
                    par3,
                    par4 - 1,
                    par5,
                    ForgeDirection.UP,
                    (BlockCherryTreeSapling) IntegratedBlocks.CherryTreeSapling));
        if (isSoil && par4 < 256 - l - 1) {
          soil.onPlantGrow(par1World, par3, par4 - 1, par5, par3, par4, par5);
          b0 = 3;
          byte b1 = 0;
          int i2;
          int j2;
          int k2;
          for (j1 = par4 - b0 + l; j1 <= par4 + l; ++j1) {
            k1 = j1 - (par4 + l);
            i2 = b1 + 1 - k1 / 2;
            for (j2 = par3 - i2; j2 <= par3 + i2; ++j2) {
              k2 = j2 - par3;
              for (int l2 = par5 - i2; l2 <= par5 + i2; ++l2) {
                int i3 = l2 - par5;
                if (Math.abs(k2) != i2
                    || Math.abs(i3) != i2
                    || par2Random.nextInt(2) != 0 && k1 != 0) {
                  int j3 = par1World.getBlockId(j2, j1, l2);
                  Block block = Block.blocksList[j3];
                  if (block == null || block.canBeReplacedByLeaves(par1World, j2, j1, l2)) {
                    /** Custom leaf block * */
                    this.setBlockAndMetadata(
                        par1World,
                        j2,
                        j1,
                        l2,
                        IntegratedBlocks.CherryTreeLeaves.blockID,
                        this.metaLeaves);
                  }
                }
              }
            }
          }
          for (j1 = 0; j1 < l; ++j1) {
            k1 = par1World.getBlockId(par3, par4 + j1, par5);
            Block block = Block.blocksList[k1];
            if (k1 == 0 || block == null || block.isLeaves(par1World, par3, par4 + j1, par5)) {
              /** Custom Log block * */
              this.setBlockAndMetadata(
                  par1World,
                  par3,
                  par4 + j1,
                  par5,
                  IntegratedBlocks.Cherrywood.blockID,
                  this.metaWood);
            }
          }
          if (par2Random.nextInt(5) == 0 && l > 5) {
            for (j1 = 0; j1 < 2; ++j1) {
              for (k1 = 0; k1 < 4; ++k1) {
                if (par2Random.nextInt(4 - j1) == 0) {
                  i2 = par2Random.nextInt(3); // Fruit
                  this.setBlockAndMetadata(
                      par1World,
                      par3 + Direction.offsetX[Direction.rotateOpposite[k1]],
                      par4 + l - 5 + j1,
                      par5 + Direction.offsetZ[Direction.rotateOpposite[k1]],
                      IntegratedBlocks.CherryTreeLeaves.blockID,
                      i2 << 2 | k1);
                }
              }
            }
          }
        }
        return true;
      }
    }
    return flag;
  }
  @Override
  public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5) {
    final int var6 = par2Random.nextInt(4) + 6;
    final int var7 = 1 + par2Random.nextInt(2);
    final int var8 = var6 - var7;
    final int var9 = 2 + par2Random.nextInt(2);
    boolean var10 = true;

    if (par4 >= 1 && par4 + var6 + 1 <= 256) {
      int var11;
      int var13;
      int var15;
      int var10a;
      int var21 = 1;

      for (var11 = par4; var11 <= par4 + 1 + var6 && var10; ++var11) {
        if (var11 - par4 < var7) {
          var21 = 0;
        }

        if (var11 >= par4 + 1 + var6 - 2) {
          var21 = var9;
        }

        for (var13 = par3 - var21; var13 <= par3 + var21 && var10; ++var13) {
          for (int var14 = par5 - var21; var14 <= par5 + var21 && var10; ++var14) {
            if (var11 >= 0 && var11 < 256) {
              var15 = par1World.getBlockId(var13, var11, var14);

              final Block block = Block.blocksList[var15];

              if (var15 != 0 && block != null && !block.isLeaves(par1World, var13, var11, var14)) {
                var10 = false;
              }
            } else {
              var10 = false;
            }
          }
        }
      }

      if (!var10) {
        return false;
      } else {
        var11 = par1World.getBlockId(par3, par4 - 1, par5);
        var10a = par1World.getBlockMetadata(par3, par4 - 1, par5);

        int waterBlocksNearby = 0;

        for (int i = -4; i < 5; i++) {
          for (int j = -4; j < 5; j++) {
            if (par1World.getBlockId(par3 + i, par4 - 1, par5 + j) == Block.waterMoving.blockID
                || par1World.getBlockId(par3 + i, par4 - 1, par5 + j) == Block.waterStill.blockID) {
              waterBlocksNearby++;
            }
          }
        }

        if (Block.blocksList[var11] != null) {
          final boolean flag =
              Block.blocksList[var11] instanceof IPlantableBlock
                  || Block.blocksList[var11] instanceof IPlantableMetadataBlock
                      && ((IPlantableMetadataBlock) Block.blocksList[var11]).isPlantable(var10a);
          final boolean flag2 =
              Block.blocksList[var11] instanceof IPlantableBlock
                      && waterBlocksNearby
                          >= ((IPlantableBlock) Block.blocksList[var11])
                              .requiredLiquidBlocksNearby()
                  || Block.blocksList[var11] instanceof IPlantableMetadataBlock
                      && waterBlocksNearby
                          >= ((IPlantableMetadataBlock) Block.blocksList[var11])
                              .requiredLiquidBlocksNearby();
          final boolean flag3 =
              (Block.blocksList[var11] instanceof BlockGrass
                      || Block.blocksList[var11] instanceof BlockDirt)
                  && waterBlocksNearby >= 4;

          if (flag && flag2 || flag3) {
            var21 = par2Random.nextInt(2);
            var13 = 1;
            byte var22 = 0;
            int var17;
            int var16;

            for (var15 = 0; var15 <= var8; ++var15) {
              var16 = par4 + var6 - var15;

              for (var17 = par3 - var21; var17 <= par3 + var21; ++var17) {
                final int var18 = var17 - par3;

                for (int var19 = par5 - var21; var19 <= par5 + var21; ++var19) {
                  final int var20 = var19 - par5;

                  final Block block = Block.blocksList[par1World.getBlockId(var17, var16, var19)];

                  if ((Math.abs(var18) != var21 || Math.abs(var20) != var21 || var21 <= 0)
                      && (block == null
                          || block.canBeReplacedByLeaves(par1World, var17, var16, var19))) {
                    this.setBlockAndMetadata(
                        par1World, var17, var16, var19, Block.leaves.blockID, 1);
                  }
                }
              }

              if (var21 >= var13) {
                var21 = var22;
                var22 = 1;
                ++var13;

                if (var13 > var9) {
                  var13 = var9;
                }
              } else {
                ++var21;
              }
            }

            var15 = par2Random.nextInt(3);

            for (var16 = 0; var16 < var6 - var15; ++var16) {
              var17 = par1World.getBlockId(par3, par4 + var16, par5);

              final Block block = Block.blocksList[var17];

              if (var17 == 0
                  || block == null
                  || block.isLeaves(par1World, par3, par4 + var16, par5)) {
                this.setBlockAndMetadata(
                    par1World, par3, par4 + var16, par5, Block.wood.blockID, 1);
              }
            }

            return true;
          } else {
            return false;
          }
        } else {
          return false;
        }
      }
    } else {
      return false;
    }
  }
  public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5) {
    int l = par2Random.nextInt(5) + 7;
    int i1 = l - par2Random.nextInt(2) - 3;
    int j1 = l - i1;
    int k1 = 1 + par2Random.nextInt(j1 + 1);
    boolean flag = true;

    if (par4 >= 1 && par4 + l + 1 <= 128) {
      int l1;
      int i2;
      int j2;
      int k2;
      int l2;

      for (l1 = par4; l1 <= par4 + 1 + l && flag; ++l1) {
        boolean flag1 = true;

        if (l1 - par4 < i1) {
          l2 = 0;
        } else {
          l2 = k1;
        }

        for (i2 = par3 - l2; i2 <= par3 + l2 && flag; ++i2) {
          for (j2 = par5 - l2; j2 <= par5 + l2 && flag; ++j2) {
            if (l1 >= 0 && l1 < 128) {
              k2 = par1World.getBlockId(i2, l1, j2);

              Block block = Block.blocksList[k2];

              if (k2 != 0 && (block == null || !block.isLeaves(par1World, i2, l1, j2))) {
                flag = false;
              }
            } else {
              flag = false;
            }
          }
        }
      }

      if (!flag) {
        return false;
      } else {
        l1 = par1World.getBlockId(par3, par4 - 1, par5);

        if ((l1 == ItemBlockHolder.EGrass.blockID || l1 == ItemBlockHolder.EDirt.blockID)
            && par4 < 128 - l - 1) {
          this.setBlock(par1World, par3, par4 - 1, par5, ItemBlockHolder.EDirt.blockID);
          l2 = 0;

          for (i2 = par4 + l; i2 >= par4 + i1; --i2) {
            for (j2 = par3 - l2; j2 <= par3 + l2; ++j2) {
              k2 = j2 - par3;

              for (int i3 = par5 - l2; i3 <= par5 + l2; ++i3) {
                int j3 = i3 - par5;

                Block block = Block.blocksList[par1World.getBlockId(j2, i2, i3)];

                if ((Math.abs(k2) != l2 || Math.abs(j3) != l2 || l2 <= 0)
                    && (block == null || block.canBeReplacedByLeaves(par1World, j2, i2, i3))) {
                  this.setBlockAndMetadata(
                      par1World, j2, i2, i3, ItemBlockHolder.EclipseLeaves.blockID, 1);
                }
              }
            }

            if (l2 >= 1 && i2 == par4 + i1 + 1) {
              --l2;
            } else if (l2 < k1) {
              ++l2;
            }
          }

          for (i2 = 0; i2 < l - 1; ++i2) {
            j2 = par1World.getBlockId(par3, par4 + i2, par5);

            Block block = Block.blocksList[j2];

            if (j2 == 0 || block == null || block.isLeaves(par1World, par3, par4 + i2, par5)) {
              this.setBlockAndMetadata(
                  par1World, par3, par4 + i2, par5, ItemBlockHolder.EclipseLogs.blockID, 1);
            }
          }

          return true;
        } else {
          return false;
        }
      }
    } else {
      return false;
    }
  }
  @Override
  public void updateEntity() {
    super.updateEntity();

    if (!this.worldObj.isRemote) {
      this.produceOxygen();
      // if (this.getEnergyStored() > 0)
      // {
      // int gasToSend = Math.min(this.storedOxygen,
      // GCCoreTileEntityOxygenCollector.OUTPUT_PER_TICK);
      // GasStack toSend = new GasStack(GalacticraftCore.gasOxygen,
      // gasToSend);
      // this.storedOxygen -= GasTransmission.emitGasToNetwork(toSend,
      // this, this.getOxygenOutputDirection());
      //
      // Vector3 thisVec = new Vector3(this);
      // TileEntity tileEntity =
      // thisVec.modifyPositionFromSide(this.getOxygenOutputDirection()).getTileEntity(this.worldObj);
      //
      // if (tileEntity instanceof IGasAcceptor)
      // {
      // if (((IGasAcceptor)
      // tileEntity).canReceiveGas(this.getOxygenOutputDirection().getOpposite(),
      // GalacticraftCore.gasOxygen))
      // {
      // double sendingGas = 0;
      //
      // if (this.storedOxygen >=
      // GCCoreTileEntityOxygenCollector.OUTPUT_PER_TICK)
      // {
      // sendingGas = GCCoreTileEntityOxygenCollector.OUTPUT_PER_TICK;
      // }
      // else
      // {
      // sendingGas = this.storedOxygen;
      // }
      //
      // this.storedOxygen -= sendingGas - ((IGasAcceptor)
      // tileEntity).receiveGas(new GasStack(GalacticraftCore.gasOxygen,
      // (int) Math.floor(sendingGas)));
      // }
      // }
      // }

      // The later calculations are more efficient if power is a float, so
      // there are fewer casts
      float power = 0;

      if (this.getEnergyStoredGC() > 0) {
        if (this.worldObj.provider instanceof IGalacticraftWorldProvider) {
          // Pre-test to see if close to the map edges, so code
          // doesn't have to continually test for map edges inside the
          // loop
          if (this.xCoord > -29999995
              && this.xCoord < 2999995
              && this.zCoord > -29999995
              && this.zCoord < 29999995) {
            // Test the y coordinates, so code doesn't have to keep
            // testing that either
            int miny = this.yCoord - 5;
            int maxy = this.yCoord + 5;
            if (miny < 0) {
              miny = 0;
            }
            if (maxy >= this.worldObj.getHeight()) {
              maxy = this.worldObj.getHeight() - 1;
            }

            // Loop the x and the z first, so the y loop will be at
            // fixed (x,z) coordinates meaning fixed chunk
            // coordinates
            for (int x = this.xCoord - 5; x <= this.xCoord + 5; x++) {
              int chunkx = x >> 4;
              int intrachunkx = x & 15;
              // Preload the first chunk for the z loop - there
              // can be a maximum of 2 chunks in the z loop
              int chunkz = (this.zCoord - 5) >> 4;
              Chunk chunk = this.worldObj.getChunkFromChunkCoords(chunkx, chunkz);
              for (int z = this.zCoord - 5; z <= this.zCoord + 5; z++) {
                if ((z >> 4) != chunkz) {
                  // moved across z chunk boundary into a new
                  // chunk, so load the new chunk
                  chunkz = z >> 4;
                  chunk = this.worldObj.getChunkFromChunkCoords(chunkx, chunkz);
                }
                for (int y = miny; y <= maxy; y++) {
                  // chunk.getBlockID is like world.getBlock
                  // but faster - needs to be given
                  // intra-chunk coordinates though
                  final Block block = chunk.getBlock(intrachunkx, y, z & 15);
                  // Test for the two most common blocks (air
                  // and breatheable air) without looking up
                  // in the blocksList
                  if (block != Blocks.air && block != GCBlocks.breatheableAir) {
                    if (block.isLeaves(this.worldObj, x, y, z)
                        || block instanceof IPlantable
                            && ((IPlantable) block).getPlantType(this.worldObj, x, y, z)
                                == EnumPlantType.Crop) {
                      power += 0.075F;
                    }
                  }
                }
              }
            }
          }
        } else {
          power = 9.3F;
        }

        power = (float) Math.floor(power);

        this.lastOxygenCollected = power;

        this.storedOxygen = (int) Math.max(Math.min(this.storedOxygen + power, this.maxOxygen), 0);
      } else {
        this.lastOxygenCollected = 0;
      }
    }
  }
Esempio n. 28
0
  public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5) {
    int l = par2Random.nextInt(3) + 5;
    boolean flag = true;

    if (par4 >= 1 && par4 + l + 1 <= 256) {
      int i1;
      int j1;
      int k1;
      int l1;

      for (i1 = par4; i1 <= par4 + 1 + l; ++i1) {
        byte b0 = 1;

        if (i1 == par4) {
          b0 = 0;
        }

        if (i1 >= par4 + 1 + l - 2) {
          b0 = 2;
        }

        for (j1 = par3 - b0; j1 <= par3 + b0 && flag; ++j1) {
          for (k1 = par5 - b0; k1 <= par5 + b0 && flag; ++k1) {
            if (i1 >= 0 && i1 < 256) {
              l1 = par1World.getBlockId(j1, i1, k1);

              Block block = Block.blocksList[l1];

              if (l1 != 0 && (block != null && !block.isLeaves(par1World, j1, i1, k1))) {
                flag = false;
              }
            } else {
              flag = false;
            }
          }
        }
      }

      if (!flag) {
        return false;
      } else {
        i1 = par1World.getBlockId(par3, par4 - 1, par5);
        Block soil = Block.blocksList[i1];
        boolean isValidSoil =
            soil != null
                && soil.canSustainPlant(
                    par1World,
                    par3,
                    par4 - 1,
                    par5,
                    ForgeDirection.UP,
                    (BlockSapling) Block.sapling);

        if (isValidSoil && par4 < 256 - l - 1) {
          soil.onPlantGrow(par1World, par3, par4 - 1, par5, par3, par4, par5);
          int i2;

          for (i2 = par4 - 3 + l; i2 <= par4 + l; ++i2) {
            j1 = i2 - (par4 + l);
            k1 = 1 - j1 / 2;

            for (l1 = par3 - k1; l1 <= par3 + k1; ++l1) {
              int j2 = l1 - par3;

              for (int k2 = par5 - k1; k2 <= par5 + k1; ++k2) {
                int l2 = k2 - par5;

                if (Math.abs(j2) != k1
                    || Math.abs(l2) != k1
                    || par2Random.nextInt(2) != 0 && j1 != 0) {
                  int i3 = par1World.getBlockId(l1, i2, k2);
                  Block block = Block.blocksList[i3];

                  if (block == null || block.canBeReplacedByLeaves(par1World, l1, i2, k2)) {
                    this.setBlockAndMetadata(par1World, l1, i2, k2, Block.leaves.blockID, 2);
                  }
                }
              }
            }
          }

          for (i2 = 0; i2 < l; ++i2) {
            j1 = par1World.getBlockId(par3, par4 + i2, par5);

            Block block = Block.blocksList[j1];

            if (j1 == 0 || block == null || block.isLeaves(par1World, par3, par4 + i2, par5)) {
              this.setBlockAndMetadata(par1World, par3, par4 + i2, par5, Block.wood.blockID, 2);
            }
          }

          return true;
        } else {
          return false;
        }
      }
    } else {
      return false;
    }
  }
Esempio n. 29
0
  /** Ticks the block if it's been scheduled */
  public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random) {
    if (!par1World.isRemote) {
      int l = par1World.getBlockMetadata(par2, par3, par4);

      if ((l & 8) != 0 && (l & 4) == 0) {
        byte b0 = 4;
        int i1 = b0 + 1;
        byte b1 = 32;
        int j1 = b1 * b1;
        int k1 = b1 / 2;

        if (this.adjacentTreeBlocks == null) {
          this.adjacentTreeBlocks = new int[b1 * b1 * b1];
        }

        int l1;

        if (par1World.checkChunksExist(
            par2 - i1, par3 - i1, par4 - i1, par2 + i1, par3 + i1, par4 + i1)) {
          int i2;
          int j2;
          int k2;

          for (l1 = -b0; l1 <= b0; ++l1) {
            for (i2 = -b0; i2 <= b0; ++i2) {
              for (j2 = -b0; j2 <= b0; ++j2) {
                k2 = par1World.getBlockId(par2 + l1, par3 + i2, par4 + j2);

                Block block = Block.blocksList[k2];

                if (block != null
                    && block.canSustainLeaves(par1World, par2 + l1, par3 + i2, par4 + j2)) {
                  this.adjacentTreeBlocks[(l1 + k1) * j1 + (i2 + k1) * b1 + j2 + k1] = 0;
                } else if (block != null
                    && block.isLeaves(par1World, par2 + l1, par3 + i2, par4 + j2)) {
                  this.adjacentTreeBlocks[(l1 + k1) * j1 + (i2 + k1) * b1 + j2 + k1] = -2;
                } else {
                  this.adjacentTreeBlocks[(l1 + k1) * j1 + (i2 + k1) * b1 + j2 + k1] = -1;
                }
              }
            }
          }

          for (l1 = 1; l1 <= 4; ++l1) {
            for (i2 = -b0; i2 <= b0; ++i2) {
              for (j2 = -b0; j2 <= b0; ++j2) {
                for (k2 = -b0; k2 <= b0; ++k2) {
                  if (this.adjacentTreeBlocks[(i2 + k1) * j1 + (j2 + k1) * b1 + k2 + k1]
                      == l1 - 1) {
                    if (this.adjacentTreeBlocks[(i2 + k1 - 1) * j1 + (j2 + k1) * b1 + k2 + k1]
                        == -2) {
                      this.adjacentTreeBlocks[(i2 + k1 - 1) * j1 + (j2 + k1) * b1 + k2 + k1] = l1;
                    }

                    if (this.adjacentTreeBlocks[(i2 + k1 + 1) * j1 + (j2 + k1) * b1 + k2 + k1]
                        == -2) {
                      this.adjacentTreeBlocks[(i2 + k1 + 1) * j1 + (j2 + k1) * b1 + k2 + k1] = l1;
                    }

                    if (this.adjacentTreeBlocks[(i2 + k1) * j1 + (j2 + k1 - 1) * b1 + k2 + k1]
                        == -2) {
                      this.adjacentTreeBlocks[(i2 + k1) * j1 + (j2 + k1 - 1) * b1 + k2 + k1] = l1;
                    }

                    if (this.adjacentTreeBlocks[(i2 + k1) * j1 + (j2 + k1 + 1) * b1 + k2 + k1]
                        == -2) {
                      this.adjacentTreeBlocks[(i2 + k1) * j1 + (j2 + k1 + 1) * b1 + k2 + k1] = l1;
                    }

                    if (this.adjacentTreeBlocks[(i2 + k1) * j1 + (j2 + k1) * b1 + (k2 + k1 - 1)]
                        == -2) {
                      this.adjacentTreeBlocks[(i2 + k1) * j1 + (j2 + k1) * b1 + (k2 + k1 - 1)] = l1;
                    }

                    if (this.adjacentTreeBlocks[(i2 + k1) * j1 + (j2 + k1) * b1 + k2 + k1 + 1]
                        == -2) {
                      this.adjacentTreeBlocks[(i2 + k1) * j1 + (j2 + k1) * b1 + k2 + k1 + 1] = l1;
                    }
                  }
                }
              }
            }
          }
        }

        l1 = this.adjacentTreeBlocks[k1 * j1 + k1 * b1 + k1];

        if (l1 >= 0) {
          par1World.setBlockMetadataWithNotify(par2, par3, par4, l & -9, 4);
        } else {
          this.removeLeaves(par1World, par2, par3, par4);
        }
      }
    }
  }