Example #1
0
  /** Checks if the dragon egg can fall down, and if so, makes it fall. */
  private void fallIfPossible(World par1World, int par2, int par3, int par4) {
    if (BlockSand.canFallBelow(par1World, par2, par3 - 1, par4) && par3 >= 0) {
      byte b0 = 32;

      if (!BlockSand.fallInstantly
          && par1World.checkChunksExist(
              par2 - b0, par3 - b0, par4 - b0, par2 + b0, par3 + b0, par4 + b0)) {
        EntityFallingSand entityfallingsand =
            new EntityFallingSand(
                par1World,
                (double) ((float) par2 + 0.5F),
                (double) ((float) par3 + 0.5F),
                (double) ((float) par4 + 0.5F),
                this.blockID);
        par1World.spawnEntityInWorld(entityfallingsand);
      } else {
        par1World.func_94571_i(par2, par3, par4);

        while (BlockSand.canFallBelow(par1World, par2, par3 - 1, par4) && par3 > 0) {
          --par3;
        }

        if (par3 > 0) {
          par1World.setBlockAndMetadataWithNotify(par2, par3, par4, this.blockID, 0, 2);
        }
      }
    }
  }
  @Override
  public void updateEntity(World world, int x, int y, int z, int meta) {
    super.updateTileEntity();
    tickcount++;

    tree.setWorld(world);
    treeCopy.setWorld(world);

    this.getIOSides(world, x, y, z, meta);
    this.getPower(false);

    if (power < MINPOWER || torque < MINTORQUE) {
      return;
    }

    if (this.isJammed()) return;

    if (world.isRemote) return;

    if (tree.isEmpty() && this.hasWood()) {
      tree.reset();
      ModWoodList wood =
          ModWoodList.getModWood(
              world.getBlock(editx, edity, editz), world.getBlockMetadata(editx, edity, editz));
      ReikaTreeHelper vanilla =
          ReikaTreeHelper.getTree(
              world.getBlock(editx, edity, editz), world.getBlockMetadata(editx, edity, editz));

      for (int i = -1; i <= 1; i++) {
        for (int j = -1; j <= 1; j++) {
          tree.checkAndAddDyeTree(world, editx + i, edity, editz + j);
          if (tree.isEmpty() || !tree.isValidTree()) tree.clear();
        }
      }
      if (tree.isEmpty()) {
        for (int i = -1; i <= 1; i++) {
          for (int j = -1; j <= 1; j++) {
            tree.checkAndAddRainbowTree(world, editx + i, edity, editz + j);
            if (tree.isEmpty() || !tree.isValidTree()) tree.clear();
          }
        }
      }

      if (tree.isEmpty()) {

        if (wood == ModWoodList.SEQUOIA) {
          for (int i = -32; i < 255; i += 16)
            tree.addSequoia(world, editx, edity + i, editz, RotaryCraft.logger.shouldDebug());
        } else if (wood == ModWoodList.DARKWOOD) {
          tree.addDarkForest(
              world,
              editx,
              edity,
              editz,
              editx - 8,
              editx + 8,
              editz - 8,
              editz + 8,
              RotaryCraft.logger.shouldDebug());
        } else if (wood == ModWoodList.IRONWOOD) {
          for (int i = -2; i < 128; i += 16)
            tree.addIronwood(world, editx, edity + i, editz, RotaryCraft.logger.shouldDebug());
        } else if (wood != null) {
          for (int i = -1; i <= 1; i++) {
            for (int j = -1; j <= 1; j++) {
              // tree.addGenerousTree(world, editx+i, edity, editz+j, 16);
              tree.setTree(wood);
              tree.addModTree(world, editx + i, edity, editz + j);
            }
            // ReikaJavaLibrary.pConsole(tree, Side.SERVER);
          }
        } else if (vanilla != null) {
          for (int i = -1; i <= 1; i++) {
            for (int j = -1; j <= 1; j++) {
              // tree.addGenerousTree(world, editx+i, edity, editz+j, 16);
              tree.setTree(vanilla);
              tree.addTree(world, editx + i, edity, editz + j);
            }
          }
        }
      }

      this.checkAndMatchInventory();

      tree.sortBlocksByHeight();
      tree.reverseBlockOrder();
      tree.sort(inwardsComparator);
      tree.sort(leafPriority);
      treeCopy = (TreeReader) tree.copy();
    }

    Block b = world.getBlock(x, y + 1, z);
    if (b != Blocks.air) {
      if (b.getMaterial() == Material.wood || b.getMaterial() == Material.leaves) {
        ReikaItemHelper.dropItems(
            world,
            dropx,
            y - 0.25,
            dropz,
            this.getDrops(world, x, y + 1, z, b, world.getBlockMetadata(x, y, z)));
        world.setBlockToAir(x, y + 1, z);
      }
    }

    // RotaryCraft.logger.debug(tree);

    if (tree.isEmpty()) return;

    if (tickcount < this.getOperationTime()) return;
    tickcount = 0;

    if (!tree.isValidTree()) {
      tree.reset();
      tree.clear();
      return;
    }

    for (int i = 0; i < this.getNumberConsecutiveOperations(); i++) {
      Coordinate c = tree.getNextAndMoveOn();
      Block drop = c.getBlock(world);
      int dropmeta = c.getBlockMetadata(world);

      if (drop != Blocks.air) {
        Material mat = ReikaWorldHelper.getMaterial(world, c.xCoord, c.yCoord, c.zCoord);
        if (ConfigRegistry.INSTACUT.getState()) {
          // ReikaItemHelper.dropItems(world, dropx, y-0.25, dropz, dropBlocks.getDrops(world,
          // c.xCoord, c.yCoord, c.zCoord, dropmeta, 0));
          this.cutBlock(world, x, y, z, c, mat);

          if (c.yCoord == edity) {
            Block idbelow = world.getBlock(c.xCoord, c.yCoord - 1, c.zCoord);
            Block root = TwilightForestHandler.BlockEntry.ROOT.getBlock();
            if (ReikaPlantHelper.SAPLING.canPlantAt(world, c.xCoord, c.yCoord, c.zCoord)) {
              ItemStack plant = this.getPlantedSapling();
              if (plant != null) {
                if (inv[0] != null && !this.hasEnchantment(Enchantment.infinity))
                  ReikaInventoryHelper.decrStack(0, inv);
                ReikaWorldHelper.setBlock(world, c.xCoord, c.yCoord, c.zCoord, plant);
              }
            } else if (tree.getTreeType() == ModWoodList.TIMEWOOD
                && (idbelow == root || idbelow == Blocks.air)) {
              ItemStack plant = this.getPlantedSapling();
              if (plant != null) {
                if (inv[0] != null && !this.hasEnchantment(Enchantment.infinity))
                  ReikaInventoryHelper.decrStack(0, inv);
                world.setBlock(c.xCoord, c.yCoord - 1, c.zCoord, Blocks.dirt);
                ReikaWorldHelper.setBlock(world, c.xCoord, c.yCoord, c.zCoord, plant);
              }
            }
          }
        } else {
          boolean fall = BlockSand.func_149831_e(world, c.xCoord, c.yCoord - 1, c.zCoord);
          if (fall) {
            EntityFallingBlock e =
                new EntityFallingBlock(
                    world, c.xCoord + 0.5, c.yCoord + 0.65, c.zCoord + 0.5, drop, dropmeta);
            e.field_145812_b = -5000;
            if (!world.isRemote) {
              world.spawnEntityInWorld(e);
            }
            c.setBlock(world, Blocks.air);
          } else {
            this.cutBlock(world, x, y, z, c, mat);
            if (c.yCoord == edity) {
              Block idbelow = world.getBlock(c.xCoord, c.yCoord - 1, c.zCoord);
              Block root = TwilightForestHandler.BlockEntry.ROOT.getBlock();
              if (ReikaPlantHelper.SAPLING.canPlantAt(world, c.xCoord, c.yCoord, c.zCoord)) {
                ItemStack plant = this.getPlantedSapling();
                if (plant != null) {
                  if (inv[0] != null && !this.hasEnchantment(Enchantment.infinity))
                    ReikaInventoryHelper.decrStack(0, inv);
                  ReikaWorldHelper.setBlock(world, c.xCoord, c.yCoord, c.zCoord, plant);
                }
              } else if (tree.getTreeType() == ModWoodList.TIMEWOOD
                  && (idbelow == root || idbelow == Blocks.air)) {
                ItemStack plant = this.getPlantedSapling();
                if (plant != null) {
                  if (inv[0] != null && !this.hasEnchantment(Enchantment.infinity))
                    ReikaInventoryHelper.decrStack(0, inv);
                  world.setBlock(c.xCoord, c.yCoord - 1, c.zCoord, Blocks.dirt);
                  ReikaWorldHelper.setBlock(world, c.xCoord, c.yCoord, c.zCoord, plant);
                }
              }
            }
          }
        }
      }
      if (tree.isEmpty()) break;
    }
  }