Пример #1
0
 private void onPlantGrow(
     World world, int x, int y, int z, int sourceX, int sourceY, int sourceZ) {
   Block block = Block.blocksList[world.getBlockId(x, y, z)];
   if (block != null) {
     block.onPlantGrow(world, x, y, z, sourceX, sourceY, sourceZ);
   }
 }
Пример #2
0
  public boolean generate(World world, Random random, int xPos, int yPos, int zPos) {
    int height = random.nextInt(this.treeHeightRange) + this.minTreeHeight;
    boolean flag = true;
    if (seekHeight) {
      yPos = findGround(world, xPos, yPos, zPos);
      if (yPos == -1) return false;
    }

    if (yPos >= 1 && yPos + height + 1 <= 256) {
      Block soil = Block.blocksList[world.getBlockId(xPos, yPos - 1, zPos)];
      boolean isSoil =
          (soil != null
              && soil.canSustainPlant(
                  world, xPos, yPos - 1, zPos, ForgeDirection.UP, NContent.rareSapling));

      if (isSoil) {
        if (!checkClear(world, xPos, yPos, zPos, height)) return false;

        soil.onPlantGrow(world, xPos, yPos - 1, zPos, xPos, yPos, zPos);
        placeCanopy(world, random, xPos, yPos, zPos, height);
        placeTrunk(world, xPos, yPos, zPos, height);
        return true;
      }
    }
    return false;
  }
Пример #3
0
  @Override
  public boolean generate(World world, Random random, int x, int y, int z) {

    while (world.isAirBlock(x, y, z) && y > 2) {
      y--;
    }

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

    if (block != Blocks.grass && block != Blocks.dirt) {
      return false;
    } else {
      for (int i = -2; i <= 2; i++) {
        for (int j = -2; j <= 2; j++) {
          if (world.isAirBlock(x + i, y - 1, z + j)
              && world.isAirBlock(x + i, y - 2, z + j)
              && !world.isAirBlock(x + i, y, z + j)) {
            return false;
          }
        }
      }

      int baselength = 2 + random.nextInt(4);
      int branches = 2 + random.nextInt(4);

      int h = 1;

      block.onPlantGrow(world, x, y - 1, z, x, y, z);

      for (int i = 0; i < baselength; i++) {
        buildBlock(world, x, y + h, z, ModBlocks.blockLog, 0);
        h++;
      }

      int c = 1;
      for (int i = 0; i < branches; i++) {
        generateBrance(world, random, x, y + h, z, c);
        c++;
        h += 2;
      }

      generateTop(world, x, y + h, z);
      return true;
    }
  }
Пример #4
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;
    }
  }
  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;
  }
  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;
    }
  }
Пример #7
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;
    }
  }
Пример #8
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;
    }
  }