Example #1
0
 @Override
 public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int i, int j, int k) {
   if (world.getBlockId(i, j - 1, k) == this.blockID || world.isBlockOpaqueCube(i, j - 1, k)) {
     return AxisAlignedBB.getBoundingBox(i + 0.3, j, k + 0.3, i + 0.7, j + 1, k + 0.7);
   }
   return AxisAlignedBB.getBoundingBox(i, j + 0.4, k, i + 1, j + 0.6, k + 1);
 }
 @Override
 public void updateTick(World world, int i, int j, int k, Random rand) {
   if (!world.isRemote) {
     if (!world.isBlockOpaqueCube(i, j - 1, k)) {
       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
           && world.getBlockId(i + 1, j, k + 1) != blockID
           && world.getBlockId(i + 1, j, k - 1) != blockID
           && world.getBlockId(i - 1, j, k + 1) != blockID
           && world.getBlockId(i - 1, j, k - 1) != blockID) {
         world.setBlock(i, j, k, 0);
       }
     }
   }
 }
Example #3
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));
          }
        }
      }
    }
  }
  private void ProcessTree(World world, int i, int j, int k, int l, ItemStack stack) {
    int x = i;
    int y = 0;
    int z = k;
    boolean checkArray[][][] = new boolean[11][50][11];

    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, stack);

      y++;
    }
  }
  /**
   * Returns a boolean array indicating which flow directions are optimal based on each direction's
   * calculated flow cost. Each array index corresponds to one of the four cardinal directions. A
   * value of true indicates the direction is optimal.
   */
  private boolean[] getOptimalFlowDirections(World par1World, int par2, int par3, int par4) {
    int var5;
    int var6;

    for (var5 = 0; var5 < 4; ++var5) {
      this.flowCost[var5] = 1000;
      var6 = par2;
      int var8 = par4;

      if (var5 == 0) {
        var6 = par2 - 1;
      }

      if (var5 == 1) {
        ++var6;
      }

      if (var5 == 2) {
        var8 = par4 - 1;
      }

      if (var5 == 3) {
        ++var8;
      }

      if (!this.blockBlocksFlow(par1World, var6, par3, var8)
          && (par1World.getBlockId(var6, par3, var8) != this.blockID
              || par1World.getBlockMetadata(var6, par3, var8) != 0)) {
        if (!this.blockBlocksFlow(par1World, var6, par3 - 1, var8)) {
          this.flowCost[var5] = 0;
        } else {
          this.flowCost[var5] = this.calculateFlowCost(par1World, var6, par3, var8, 1, var5);
        }
      }
    }

    var5 = this.flowCost[0];

    for (var6 = 1; var6 < 4; ++var6) {
      if (this.flowCost[var6] < var5) {
        var5 = this.flowCost[var6];
      }
    }

    for (var6 = 0; var6 < 4; ++var6) {
      this.isOptimalFlowDirection[var6] = this.flowCost[var6] == var5;
    }

    return this.isOptimalFlowDirection;
  }
Example #6
0
 @Override
 public void onNeighborBlockChange(World world, int i, int j, int k, int l) {
   boolean check = false;
   for (int h = -1; h <= 1; h++) {
     for (int g = -1; g <= 1; g++) {
       for (int f = -1; f <= 1; f++) {
         if (world.getBlockId(i + h, j + g, k + f) == blockID
             && world.getBlockMetadata(i + h, j + g, k + f) == world.getBlockMetadata(i, j, k)) {
           check = true;
         }
       }
     }
   }
   if (!check) {
     world.setBlock(i, j, k, 0);
   }
 }
 @Override
 public void onNeighborBlockChange(World world, int i, int j, int k, int l) {
   boolean check = false;
   for (int h = -2; h <= 2; h++) {
     for (int g = -2; g <= 2; g++) {
       for (int f = -2; f <= 2; f++) {
         if (world.getBlockId(i + h, j + g, k + f) == blockID
             && world.getBlockMetadata(i + h, j + g, k + f) == world.getBlockMetadata(i, j, k)) {
           check = true;
         }
       }
     }
   }
   if (!check) {
     world.setBlock(i, j, k, 0);
     dropBlockAsItem_do(world, i, j, k, new ItemStack(Item.itemsList[TFCItems.Logs.itemID], 1, l));
   }
 }
  /** Returns true if block at coords blocks fluids */
  private boolean blockBlocksFlow(World par1World, int par2, int par3, int par4) {
    int var5 = par1World.getBlockId(par2, par3, par4);

    if (var5 != Block.doorWood.blockID
        && var5 != Block.doorSteel.blockID
        && var5 != Block.signPost.blockID
        && var5 != Block.ladder.blockID
        && var5 != Block.reed.blockID) {
      if (var5 == 0) {
        return false;
      } else {
        Material var6 = Block.blocksList[var5].blockMaterial;
        return var6 == Material.portal ? true : var6.blocksMovement();
      }
    } else {
      return true;
    }
  }
  @ForgeSubscribe
  public void DrawBlockHighlightEvent(DrawBlockHighlightEvent evt) {
    World world = evt.player.worldObj;
    double var8 =
        evt.player.lastTickPosX
            + (evt.player.posX - evt.player.lastTickPosX) * (double) evt.partialTicks;
    double var10 =
        evt.player.lastTickPosY
            + (evt.player.posY - evt.player.lastTickPosY) * (double) evt.partialTicks;
    double var12 =
        evt.player.lastTickPosZ
            + (evt.player.posZ - evt.player.lastTickPosZ) * (double) evt.partialTicks;

    boolean isMetalHoe = false;

    if (evt.currentItem != null
        && evt.currentItem.getItem().shiftedIndex != TFCItems.IgInHoe.shiftedIndex
        && evt.currentItem.getItem().shiftedIndex != TFCItems.IgExHoe.shiftedIndex
        && evt.currentItem.getItem().shiftedIndex != TFCItems.SedHoe.shiftedIndex
        && evt.currentItem.getItem().shiftedIndex != TFCItems.MMHoe.shiftedIndex) {
      isMetalHoe = true;
    }

    if (evt.currentItem != null
        && evt.currentItem.getItem() instanceof ItemCustomHoe
        && isMetalHoe
        && PlayerManagerTFC.getInstance().getClientPlayer().hoeMode == 1) {
      int id = world.getBlockId(evt.target.blockX, evt.target.blockY, evt.target.blockZ);
      int crop = 0;
      if (id == Block.crops.blockID
          && (world.getBlockId(evt.target.blockX, evt.target.blockY - 1, evt.target.blockZ)
                  == TFCBlocks.tilledSoil.blockID
              || world.getBlockId(evt.target.blockX, evt.target.blockY - 1, evt.target.blockZ)
                  == TFCBlocks.tilledSoil2.blockID)) {
        id = TFCBlocks.tilledSoil.blockID;
        crop = 1;
      }

      if (id == TFCBlocks.tilledSoil.blockID || id == TFCBlocks.tilledSoil2.blockID) {
        TileEntityFarmland te =
            (TileEntityFarmland)
                world.getBlockTileEntity(
                    evt.target.blockX, evt.target.blockY - crop, evt.target.blockZ);
        te.requestNutrientData();

        float timeMultiplier = (float) TFC_Time.daysInYear / 360f;
        int soilMax = (int) (25000 * timeMultiplier);

        // Setup GL for the depthbox
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        GL11.glColor4ub(
            TFC_Settings.cropNutrientAColor[0],
            TFC_Settings.cropNutrientAColor[1],
            TFC_Settings.cropNutrientAColor[2],
            TFC_Settings.cropNutrientAColor[3]);
        GL11.glDisable(GL11.GL_CULL_FACE);
        // GL11.glLineWidth(6.0F);
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glDepthMask(false);

        double offset = 0;
        double nutrient = 1.02 + ((double) te.nutrients[0] / (double) soilMax) * 0.5;

        drawBox(
            AxisAlignedBB.getAABBPool()
                .addOrModifyAABBInPool(
                    evt.target.blockX + offset,
                    evt.target.blockY + 1.01 - crop,
                    evt.target.blockZ,
                    evt.target.blockX + offset + 0.3333,
                    evt.target.blockY + nutrient - crop,
                    evt.target.blockZ + 1)
                .expand(0.002F, 0.002F, 0.002F)
                .getOffsetBoundingBox(-var8, -var10, -var12));

        offset = 0.3333;
        nutrient = 1.02 + ((double) te.nutrients[1] / (double) soilMax) * 0.5;
        GL11.glColor4ub(
            TFC_Settings.cropNutrientBColor[0],
            TFC_Settings.cropNutrientBColor[1],
            TFC_Settings.cropNutrientBColor[2],
            TFC_Settings.cropNutrientBColor[3]);
        drawBox(
            AxisAlignedBB.getAABBPool()
                .addOrModifyAABBInPool(
                    evt.target.blockX + offset,
                    evt.target.blockY + 1.01 - crop,
                    evt.target.blockZ,
                    evt.target.blockX + offset + 0.3333,
                    evt.target.blockY + nutrient - crop,
                    evt.target.blockZ + 1)
                .expand(0.002F, 0.002F, 0.002F)
                .getOffsetBoundingBox(-var8, -var10, -var12));

        offset = 0.6666;
        nutrient = 1.02 + ((double) te.nutrients[2] / (double) soilMax) * 0.5;
        GL11.glColor4ub(
            TFC_Settings.cropNutrientCColor[0],
            TFC_Settings.cropNutrientCColor[1],
            TFC_Settings.cropNutrientCColor[2],
            TFC_Settings.cropNutrientCColor[3]);
        drawBox(
            AxisAlignedBB.getAABBPool()
                .addOrModifyAABBInPool(
                    evt.target.blockX + offset,
                    evt.target.blockY + 1.01 - crop,
                    evt.target.blockZ,
                    evt.target.blockX + offset + 0.3333,
                    evt.target.blockY + nutrient - crop,
                    evt.target.blockZ + 1)
                .expand(0.002F, 0.002F, 0.002F)
                .getOffsetBoundingBox(-var8, -var10, -var12));

        GL11.glEnable(GL11.GL_CULL_FACE);

        /** Draw the outliens around the boxes */
        GL11.glColor4f(0.1F, 0.1F, 0.1F, 1.0F);
        GL11.glLineWidth(3.0F);
        GL11.glDepthMask(false);

        offset = 0;
        nutrient = 1.02 + ((double) te.nutrients[0] / (double) soilMax) * 0.5;
        drawOutlinedBoundingBox(
            AxisAlignedBB.getAABBPool()
                .addOrModifyAABBInPool(
                    evt.target.blockX + offset,
                    evt.target.blockY + 1.01 - crop,
                    evt.target.blockZ,
                    evt.target.blockX + offset + 0.3333,
                    evt.target.blockY + nutrient - crop,
                    evt.target.blockZ + 1)
                .expand(0.002F, 0.002F, 0.002F)
                .getOffsetBoundingBox(-var8, -var10, -var12));

        offset = 0.3333;
        nutrient = 1.02 + ((double) te.nutrients[1] / (double) soilMax) * 0.5;
        drawOutlinedBoundingBox(
            AxisAlignedBB.getAABBPool()
                .addOrModifyAABBInPool(
                    evt.target.blockX + offset,
                    evt.target.blockY + 1.01 - crop,
                    evt.target.blockZ,
                    evt.target.blockX + offset + 0.3333,
                    evt.target.blockY + nutrient - crop,
                    evt.target.blockZ + 1)
                .expand(0.002F, 0.002F, 0.002F)
                .getOffsetBoundingBox(-var8, -var10, -var12));

        offset = 0.6666;
        nutrient = 1.02 + ((double) te.nutrients[2] / (double) soilMax) * 0.5;
        drawOutlinedBoundingBox(
            AxisAlignedBB.getAABBPool()
                .addOrModifyAABBInPool(
                    evt.target.blockX + offset,
                    evt.target.blockY + 1.01 - crop,
                    evt.target.blockZ,
                    evt.target.blockX + offset + 0.3333,
                    evt.target.blockY + nutrient - crop,
                    evt.target.blockZ + 1)
                .expand(0.002F, 0.002F, 0.002F)
                .getOffsetBoundingBox(-var8, -var10, -var12));
      }
    } else if (evt.currentItem != null
        && evt.currentItem.getItem() instanceof ItemCustomHoe
        && PlayerManagerTFC.getInstance().getClientPlayer().hoeMode == 2) {
      int id = world.getBlockId(evt.target.blockX, evt.target.blockY, evt.target.blockZ);
      int crop = 0;
      if (id == Block.crops.blockID
          && (world.getBlockId(evt.target.blockX, evt.target.blockY - 1, evt.target.blockZ)
                  == TFCBlocks.tilledSoil.blockID
              || world.getBlockId(evt.target.blockX, evt.target.blockY - 1, evt.target.blockZ)
                  == TFCBlocks.tilledSoil2.blockID)) {
        id = TFCBlocks.tilledSoil.blockID;
        crop = 1;
      }

      if (id == TFCBlocks.tilledSoil.blockID || id == TFCBlocks.tilledSoil2.blockID) {
        boolean water =
            TFC.Blocks.BlockFarmland.isWaterNearby(
                world, evt.target.blockX, evt.target.blockY - crop, evt.target.blockZ);

        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        if (water) GL11.glColor4ub((byte) 14, (byte) 23, (byte) 212, (byte) 200);
        else GL11.glColor4ub((byte) 0, (byte) 0, (byte) 0, (byte) 200);
        GL11.glDisable(GL11.GL_CULL_FACE);
        // GL11.glLineWidth(6.0F);
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glDepthMask(false);

        drawFace(
            AxisAlignedBB.getAABBPool()
                .addOrModifyAABBInPool(
                    evt.target.blockX,
                    evt.target.blockY + 1.01 - crop,
                    evt.target.blockZ,
                    evt.target.blockX + 1,
                    evt.target.blockY + 1.02 - crop,
                    evt.target.blockZ + 1)
                .expand(0.002F, 0.002F, 0.002F)
                .getOffsetBoundingBox(-var8, -var10, -var12));

        GL11.glEnable(GL11.GL_CULL_FACE);
      }
    } else if (evt.currentItem != null
        && evt.currentItem.getItem() instanceof ItemCustomHoe
        && PlayerManagerTFC.getInstance().getClientPlayer().hoeMode == 3) {
      int id = world.getBlockId(evt.target.blockX, evt.target.blockY, evt.target.blockZ);
      if (id == Block.crops.blockID
          && (world.getBlockId(evt.target.blockX, evt.target.blockY - 1, evt.target.blockZ)
                  == TFCBlocks.tilledSoil.blockID
              || world.getBlockId(evt.target.blockX, evt.target.blockY - 1, evt.target.blockZ)
                  == TFCBlocks.tilledSoil2.blockID)) {
        TileEntityCrop te =
            (TileEntityCrop)
                world.getBlockTileEntity(evt.target.blockX, evt.target.blockY, evt.target.blockZ);
        CropIndex index = CropManager.getInstance().getCropFromId(te.cropId);
        boolean fullyGrown = te.growth >= index.numGrowthStages;

        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        if (fullyGrown) GL11.glColor4ub((byte) 64, (byte) 200, (byte) 37, (byte) 200);
        else GL11.glColor4ub((byte) 200, (byte) 37, (byte) 37, (byte) 200);
        GL11.glDisable(GL11.GL_CULL_FACE);
        // GL11.glLineWidth(6.0F);
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glDepthMask(false);

        drawFace(
            AxisAlignedBB.getAABBPool()
                .addOrModifyAABBInPool(
                    evt.target.blockX,
                    evt.target.blockY + 0.01,
                    evt.target.blockZ,
                    evt.target.blockX + 1,
                    evt.target.blockY + 0.02,
                    evt.target.blockZ + 1)
                .expand(0.002F, 0.002F, 0.002F)
                .getOffsetBoundingBox(-var8, -var10, -var12));

        GL11.glEnable(GL11.GL_CULL_FACE);
      }
    }
  }
 private boolean checkOut(World world, int i, int j, int k, int l) {
   if (world.getBlockId(i, j, k) == blockID && world.getBlockMetadata(i, j, k) == l) {
     return true;
   }
   return false;
 }
Example #11
0
 /**
  * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed
  * (coordinates passed are their own) Args: x, y, z, neighbor blockID
  */
 public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5) {
   if (par1World.getBlockId(par2, par3, par4) == this.blockID) {
     par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, this.tickRate());
   }
 }
Example #12
0
  private boolean moveToBlock(World world, int x, int y, int z, int x2, int y2, int z2) {
    int blockID2 = world.getBlockId(x2, y2, z2);
    int originMeta = world.getBlockMetadata(x, y, z);
    int destMeta = world.getBlockMetadata(x2, y2, z2);
    if (blockID2 == this.blockID) {
      if (destMeta > originMeta || y > y2) {
        if (originMeta < 7 && destMeta > 0) {
          world.setBlockMetadata(x, y, z, originMeta + 1);
          world.markBlockForUpdate(x, y, z);
          world.setBlockMetadata(x2, y2, z2, destMeta - 1);
          world.markBlockForUpdate(x2, y2, z2);
          return true;
        } else if (destMeta > 0) {
          world.setBlockWithNotify(x, y, z, 0);
          world.markBlockForUpdate(x, y, z);
          world.setBlockMetadata(x2, y2, z2, destMeta - 1);
          world.markBlockForUpdate(x2, y2, z2);
          return true;
        } else {
          return false;
        }
      } else {
        return false;
      }
    } else if (liquidCanDisplaceBlock(world, x2, y2, z2)) {
      if (blockID2 > 0) {
        if (this.blockMaterial == Material.lava) {
          this.triggerLavaMixEffects(world, x2, y2, z2);
        } else if (blockID2 == Block.waterMoving.blockID || blockID2 == Block.waterStill.blockID) {
          if (originMeta < 7) {
            world.setBlockMetadataWithNotify(x, y, z, originMeta + 1);
            world.markBlockForUpdate(x, y, z);
            return true;
          } else {
            world.setBlockWithNotify(x, y, z, 0);
            world.markBlockForUpdate(x, y, z);
            return true;
          }
        } else {
          Block.blocksList[blockID2].dropBlockAsItem(
              world, x2, y2, z2, world.getBlockMetadata(x2, y2, z2), 0);
        }
      }

      if (y2 < y) {
        world.setBlockWithNotify(x, y, z, 0);
        world.markBlockForUpdate(x, y, z);
        world.setBlockAndMetadataWithNotify(x2, y2, z2, blockID, originMeta);
        world.markBlockForUpdate(x2, y2, z2);
        return true;
      }
      if (originMeta < 7) {
        world.setBlockMetadataWithNotify(x, y, z, originMeta + 1);
        world.markBlockForUpdate(x, y, z);
        world.setBlockAndMetadataWithNotify(x2, y2, z2, blockID, 7);
        world.markBlockForUpdate(x2, y2, z2);
        return true;
      } else if (world.getBlockId(x - 1, y, z) != this.blockID
          && world.getBlockId(x + 1, y, z) != this.blockID
          && world.getBlockId(x, y + 1, z) != this.blockID
          && world.getBlockId(x, y, z - 1) != this.blockID
          && world.getBlockId(x, y, z + 1) != this.blockID) {
        world.setBlockWithNotify(x, y, z, 0);
        return true;
      } else {
        world.setBlockWithNotify(x, y, z, 0);
        world.markBlockForUpdate(x, y, z);
        world.setBlockAndMetadataWithNotify(x2, y2, z2, blockID, 7);
        world.markBlockForUpdate(x2, y2, z2);
        return true;
      }
    } else {
      return false;
    }
  }
Example #13
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);
    }
  }
Example #14
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);
        }
      }
    }
  }