コード例 #1
0
  public void SurroundWithLeaves(World world, int i, int j, int k) {
    for (int y = 0; y <= 1; y++) {
      for (int x = 1; x >= -1; x--) {
        for (int z = 1; z >= -1; z--) {
          if (world.getBlockId(i + x, j + y, k + z) == 0
              && (world.getBlockId(i + x, j + y + 1, k + z) == 0
                  || world.getBlockId(i + x, j + y + 2, k + z) == 0)) {
            int meta = world.getBlockMetadata(i, j, k);
            int id =
                meta < 8 ? TFCBlocks.fruitTreeLeaves.blockID : TFCBlocks.fruitTreeLeaves2.blockID;

            if (world.getBlockId(i, j, k) != TFCBlocks.fruitTreeWood.blockID) id = 0;

            world.setBlockAndMetadata(i + x, j + y, k + z, id, world.getBlockMetadata(i, j, k));
          }
        }
      }
    }
  }
コード例 #2
0
  @Override
  public void harvestBlock(World world, EntityPlayer entityplayer, int i, int j, int k, int l) {
    // we need to make sure teh palyer has the correct tool out
    boolean isAxeorSaw = false;
    ItemStack equip = entityplayer.getCurrentEquippedItem();
    if (equip != null) {
      for (int cnt = 0; cnt < Recipes.Axes.length && !isAxeorSaw; cnt++) {
        if (equip.getItem() == Recipes.Axes[cnt]) {
          isAxeorSaw = true;
        }
      }
      for (int cnt = 0; cnt < Recipes.Saws.length && !isAxeorSaw; cnt++) {
        if (equip.getItem() == Recipes.Saws[cnt]) {
          isAxeorSaw = true;
        }
      }
    }
    if (isAxeorSaw) {
      int x = i;
      int y = 0;
      int z = k;
      int count = 0;

      if (world.getBlockId(i, j + 1, k) == blockID || world.getBlockId(i, j - 1, k) == blockID) {
        // super.harvestBlock(world, entityplayer, i, j, k, l);
        boolean checkArray[][][] = new boolean[11][50][11];

        if (TFC_Core.isGrass(world.getBlockId(i, j + y - 1, k))
            || TFC_Core.isDirt(world.getBlockId(i, j + y - 1, k))) {
          boolean reachedTop = false;
          while (!reachedTop) {
            if (l != 9 && l != 15 && world.getBlockId(x, j + y + 1, z) == 0) {
              reachedTop = true;
            } else if ((l == 9 || l == 15)
                && world.getBlockId(x, j + y + 1, z) == 0
                && world.getBlockId(x + 1, j + y + 1, z) != blockID
                && world.getBlockId(x - 1, j + y + 1, z) != blockID
                && world.getBlockId(x, j + y + 1, z + 1) != blockID
                && world.getBlockId(x, j + y + 1, z - 1) != blockID
                && world.getBlockId(x - 1, j + y + 1, z - 1) != blockID
                && world.getBlockId(x - 1, j + y + 1, z + 1) != blockID
                && world.getBlockId(x + 1, j + y + 1, z + 1) != blockID
                && world.getBlockId(x + 1, j + y + 1, z - 1) != blockID) {
              reachedTop = true;
            }

            scanLogs(world, i, j + y, k, l, checkArray, 6, y, 6);

            y++;
          }
        }
      } else if (world.getBlockId(i + 1, j, k) == blockID
          || world.getBlockId(i - 1, j, k) == blockID
          || world.getBlockId(i, j, k + 1) == blockID
          || world.getBlockId(i, j, k - 1) == blockID) {
        Random R = new Random();
        if (R.nextInt(100) > 50 && isAxeorSaw) {
          dropBlockAsItem_do(world, i, j, k, new ItemStack(TFCItems.FruitTreeSapling1, 1, l));
        }
      }
    } else {
      world.setBlockAndMetadata(i, j, k, blockID, l);
    }
  }
コード例 #3
0
  @Override
  public void updateTick(World world, int i, int j, int k, Random rand) {
    FloraManager manager = FloraManager.getInstance();
    FloraIndex fi = manager.findMatchingIndex(this.getType(world.getBlockMetadata(i, j, k)));

    float temp = TFC_Climate.getHeightAdjustedTemp(i, j, k);

    if (!world.isRemote
        && world.getBlockTileEntity(i, j, k) != null
        && TFC_Time.currentMonth < 6
        && fi != null
        && temp >= fi.minTemp
        && temp < fi.maxTemp) {
      TileEntityFruitTreeWood te = (TileEntityFruitTreeWood) world.getBlockTileEntity(i, j, k);
      int t = 1;
      if (TFC_Time.currentMonth < 3) t = 2;

      int leafGrowthRate = 20;
      int trunkGrowTime = 30;
      int branchGrowTime = 20;

      // grow upward
      if (te.birthTimeWood + trunkGrowTime < TFC_Time.totalDays()
          && te.height < 3
          && te.isTrunk
          && rand.nextInt(16 / t) == 0
          && (world.getBlockId(i, j + 1, k) == 0
              || world.getBlockId(i, j + 1, k) == TFCBlocks.fruitTreeLeaves.blockID)) {
        world.setBlockAndMetadata(i, j + 1, k, this.blockID, world.getBlockMetadata(i, j, k));
        ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j + 1, k)).setTrunk(true);
        ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j + 1, k)).setHeight(te.height + 1);
        ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j + 1, k)).setBirth();

        ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j, k)).setBirthWood(trunkGrowTime);
      } else if (te.birthTimeWood + branchGrowTime < TFC_Time.totalDays()
          && te.height == 2
          && te.isTrunk
          && rand.nextInt(16 / t) == 0
          && world.getBlockId(i, j + 1, k) != blockID) {
        int r = rand.nextInt(4);
        if (r == 0 && world.getBlockId(i + 1, j, k) == 0
            || world.getBlockId(i + 1, j, k) == TFCBlocks.fruitTreeLeaves.blockID) {
          world.setBlockAndMetadata(i + 1, j, k, this.blockID, world.getBlockMetadata(i, j, k));
          ((TileEntityFruitTreeWood) world.getBlockTileEntity(i + 1, j, k)).setTrunk(false);
          ((TileEntityFruitTreeWood) world.getBlockTileEntity(i + 1, j, k)).setHeight(te.height);
          ((TileEntityFruitTreeWood) world.getBlockTileEntity(i + 1, j, k)).setBirth();
        } else if (r == 1 && world.getBlockId(i, j, k - 1) == 0
            || world.getBlockId(i, j, k - 1) == TFCBlocks.fruitTreeLeaves.blockID) {
          world.setBlockAndMetadata(i, j, k - 1, this.blockID, world.getBlockMetadata(i, j, k));
          ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j, k - 1)).setTrunk(false);
          ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j, k - 1)).setHeight(te.height);
          ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j, k - 1)).setBirth();
        } else if (r == 2 && world.getBlockId(i - 1, j, k) == 0
            || world.getBlockId(i - 1, j, k) == TFCBlocks.fruitTreeLeaves.blockID) {
          world.setBlockAndMetadata(i - 1, j, k, this.blockID, world.getBlockMetadata(i, j, k));
          ((TileEntityFruitTreeWood) world.getBlockTileEntity(i - 1, j, k)).setTrunk(false);
          ((TileEntityFruitTreeWood) world.getBlockTileEntity(i - 1, j, k)).setHeight(te.height);
          ((TileEntityFruitTreeWood) world.getBlockTileEntity(i - 1, j, k)).setBirth();
        } else if (r == 3 && world.getBlockId(i, j, k + 1) == 0
            || world.getBlockId(i, j, k + 1) == TFCBlocks.fruitTreeLeaves.blockID) {
          world.setBlockAndMetadata(i, j, k + 1, this.blockID, world.getBlockMetadata(i, j, k));
          ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j, k + 1)).setTrunk(false);
          ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j, k + 1)).setHeight(te.height);
          ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j, k + 1)).setBirth();
        }

        ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j, k)).setBirthWood(branchGrowTime);
      } else if (te.birthTimeWood + 1 < TFC_Time.totalDays()
          && rand.nextInt(leafGrowthRate) == 0
          && world.getBlockId(i, j + 2, k) != blockID) {
        if (world.getBlockId(i, j + 1, k) == 0
            && world.getBlockId(i, j + 2, k) == 0
            && BlockFruitLeaves.canStay(
                world, i, j + 1, k, TFCBlocks.fruitTreeLeaves.blockID)) // above
        {
          world.setBlockAndMetadata(
              i, j + 1, k, TFCBlocks.fruitTreeLeaves.blockID, world.getBlockMetadata(i, j, k));
          world.markBlockForUpdate(i, j + 1, k);
        } else if (world.getBlockId(i + 1, j, k) == 0
            && world.getBlockId(i + 1, j + 1, k) == 0
            && BlockFruitLeaves.canStay(
                world, i + 1, j, k, TFCBlocks.fruitTreeLeaves.blockID)) // +x
        {
          world.setBlockAndMetadata(
              i + 1, j, k, TFCBlocks.fruitTreeLeaves.blockID, world.getBlockMetadata(i, j, k));
          world.markBlockForUpdate(i + 1, j, k);
        } else if (world.getBlockId(i - 1, j, k) == 0
            && world.getBlockId(i - 1, j + 1, k) == 0
            && BlockFruitLeaves.canStay(
                world, i - 1, j, k, TFCBlocks.fruitTreeLeaves.blockID)) // -x
        {
          world.setBlockAndMetadata(
              i - 1, j, k, TFCBlocks.fruitTreeLeaves.blockID, world.getBlockMetadata(i, j, k));
          world.markBlockForUpdate(i - 1, j, k);
        } else if (world.getBlockId(i, j, k + 1) == 0
            && world.getBlockId(i, j + 1, k + 1) == 0
            && BlockFruitLeaves.canStay(
                world, i, j, k + 1, TFCBlocks.fruitTreeLeaves.blockID)) // +z
        {
          world.setBlockAndMetadata(
              i, j, k + 1, TFCBlocks.fruitTreeLeaves.blockID, world.getBlockMetadata(i, j, k));
          world.markBlockForUpdate(i, j, k + 1);
        } else if (world.getBlockId(i, j, k - 1) == 0
            && world.getBlockId(i, j + 1, k - 1) == 0
            && BlockFruitLeaves.canStay(
                world, i, j, k - 1, TFCBlocks.fruitTreeLeaves.blockID)) // -z
        {
          world.setBlockAndMetadata(
              i, j, k - 1, TFCBlocks.fruitTreeLeaves.blockID, world.getBlockMetadata(i, j, k));
          world.markBlockForUpdate(i, j, k - 1);
        } else if (world.getBlockId(i + 1, j, k - 1) == 0
            && world.getBlockId(i + 1, j + 1, k - 1) == 0
            && BlockFruitLeaves.canStay(
                world, i + 1, j, k - 1, TFCBlocks.fruitTreeLeaves.blockID)) // +x/-z
        {
          world.setBlockAndMetadata(
              i + 1, j, k - 1, TFCBlocks.fruitTreeLeaves.blockID, world.getBlockMetadata(i, j, k));
          world.markBlockForUpdate(i + 1, j, k - 1);
        } else if (world.getBlockId(i + 1, j, k + 1) == 0
            && world.getBlockId(i + 1, j + 1, k + 1) == 0
            && BlockFruitLeaves.canStay(
                world, i + 1, j, k + 1, TFCBlocks.fruitTreeLeaves.blockID)) // +x/+z
        {
          world.setBlockAndMetadata(
              i + 1, j, k + 1, TFCBlocks.fruitTreeLeaves.blockID, world.getBlockMetadata(i, j, k));
          world.markBlockForUpdate(i + 1, j, k + 1);
        } else if (world.getBlockId(i - 1, j, k - 1) == 0
            && world.getBlockId(i - 1, j + 1, k - 1) == 0
            && BlockFruitLeaves.canStay(
                world, i - 1, j, k - 1, TFCBlocks.fruitTreeLeaves.blockID)) // -x/-z
        {
          world.setBlockAndMetadata(
              i - 1, j, k - 1, TFCBlocks.fruitTreeLeaves.blockID, world.getBlockMetadata(i, j, k));
          world.markBlockForUpdate(i - 1, j, k - 1);
        } else if (world.getBlockId(i - 1, j, k + 1) == 0
            && world.getBlockId(i - 1, j + 1, k + 1) == 0
            && BlockFruitLeaves.canStay(
                world, i - 1, j, k + 1, TFCBlocks.fruitTreeLeaves.blockID)) // -x/+z
        {
          world.setBlockAndMetadata(
              i - 1, j, k + 1, TFCBlocks.fruitTreeLeaves.blockID, world.getBlockMetadata(i, j, k));
          world.markBlockForUpdate(i - 1, j, k + 1);
        }
      }
    }
  }