Ejemplo n.º 1
0
  @Override
  public boolean displaceIfPossible(World world, BlockPos pos) {

    if (!world.isRemote) {
      if (!world.provider.isSurfaceWorld()) {
        if (world.getBlockState(pos).getBlock() == Blocks.WATER
            && AbyssalCraft.shouldSpread == false) return false;
        if (world.getBlockState(pos).getMaterial().isLiquid()
            && world.getBlockState(pos).getBlock() != this
            && world.getBlockState(pos).getBlock() != ACBlocks.liquid_antimatter)
          world.setBlockState(pos, getDefaultState());
        if (AbyssalCraft.breakLogic == true
            && world
                .getBlockState(new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ()))
                .getMaterial()
                .isLiquid()
            && world.getBlockState(new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ())).getBlock()
                != this
            && world.getBlockState(new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ())).getBlock()
                != ACBlocks.liquid_antimatter)
          world.setBlockState(
              new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ()), getDefaultState());
      } else {
        if (BiomeDictionary.isBiomeOfType(world.getBiomeGenForCoords(pos), Type.OCEAN)
            && world.getBlockState(pos).getBlock() == this)
          if (AbyssalCraft.destroyOcean) world.setBlockState(pos, getDefaultState());
          else world.setBlockState(pos, Blocks.COBBLESTONE.getDefaultState());

        if (AbyssalCraft.shouldSpread) {
          if (world.getBlockState(pos).getMaterial().isLiquid()
              && world.getBlockState(pos).getBlock() != this
              && world.getBlockState(pos).getBlock() != ACBlocks.liquid_antimatter)
            world.setBlockState(pos, getDefaultState());
          if (AbyssalCraft.breakLogic == true
              && world
                  .getBlockState(new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ()))
                  .getMaterial()
                  .isLiquid()
              && world
                      .getBlockState(new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ()))
                      .getBlock()
                  != this
              && world
                      .getBlockState(new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ()))
                      .getBlock()
                  != ACBlocks.liquid_antimatter)
            world.setBlockState(
                new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ()), getDefaultState());
        }
      }
      if (dusts.contains(world.getBlockState(pos))
          && world.getBlockState(pos) != ACBlocks.abyssal_nitre_ore.getDefaultState()
          && world.getBlockState(pos) != ACBlocks.abyssal_coralium_ore)
        if (oresToBlocks(OreDictionary.getOres("oreSaltpeter")).contains(world.getBlockState(pos)))
          world.setBlockState(pos, ACBlocks.abyssal_nitre_ore.getDefaultState());
        else world.setBlockState(pos, ACBlocks.abyssal_coralium_ore.getDefaultState());
      else if (metalloids.contains(world.getBlockState(pos))
          && !metals.contains(world.getBlockState(pos)))
        if (oresToBlocks(OreDictionary.getOres("oreIron")).contains(world.getBlockState(pos)))
          world.setBlockState(pos, ACBlocks.abyssal_iron_ore.getDefaultState());
        else if (oresToBlocks(OreDictionary.getOres("oreGold")).contains(world.getBlockState(pos)))
          world.setBlockState(pos, ACBlocks.abyssal_gold_ore.getDefaultState());
        else if (oresToBlocks(OreDictionary.getOres("oreTin")).contains(world.getBlockState(pos)))
          world.setBlockState(pos, ACBlocks.abyssal_tin_ore.getDefaultState());
        else if (oresToBlocks(OreDictionary.getOres("oreCopper"))
            .contains(world.getBlockState(pos)))
          world.setBlockState(pos, ACBlocks.abyssal_copper_ore.getDefaultState());
        else world.setBlockState(pos, ACBlocks.liquified_coralium_ore.getDefaultState());
      else if (gems.contains(world.getBlockState(pos))
          && world.getBlockState(pos) != ACBlocks.abyssal_diamond_ore.getDefaultState())
        if (oresToBlocks(OreDictionary.getOres("oreDiamond")).contains(world.getBlockState(pos)))
          world.setBlockState(pos, ACBlocks.abyssal_diamond_ore.getDefaultState());
        else world.setBlockState(pos, ACBlocks.pearlescent_coralium_ore.getDefaultState());
      else if (stones.contains(world.getBlockState(pos)))
        if (BiomeDictionary.isBiomeOfType(world.getBiomeGenForCoords(pos), Type.OCEAN)) {
          if (world.getBlockState(pos).getBlock() != Blocks.COBBLESTONE)
            world.setBlockState(pos, ACBlocks.abyssal_stone.getDefaultState());
        } else world.setBlockState(pos, ACBlocks.abyssal_stone.getDefaultState());
      else if (bricks.contains(world.getBlockState(pos)))
        world.setBlockState(pos, ACBlocks.abyssal_stone_brick.getDefaultState());
    }
    return super.displaceIfPossible(world, pos);
  }
Ejemplo n.º 2
0
  public void mine() {
    if ((slots[1] == null) || (slots[2] == null) || (slots[3] == null)) return;
    if (currentBlock != null) {
      // continue to mine this block
      if (miningTime <= 0) {
        miningTime = 0;
        // clock is done, lets mine it
        Point2I currentPoint = spiral(currentColumn, pos.getX(), pos.getZ());
        BlockPos currentPosition =
            new BlockPos(currentPoint.getX(), currentYLevel, currentPoint.getY());
        // ProgressiveAutomation.logger.info("Point: "+miningWith+"
        // "+currentPoint.getX()+","+currentYLevel+","+currentPoint.getY());

        // don't harvest anything if the block is air or liquid
        if (miningWith != 4) {
          // get the inventory of anything under it
          if (worldObj.getTileEntity(currentPosition) instanceof IInventory) {
            IInventory inv = (IInventory) worldObj.getTileEntity(currentPosition);
            for (int i = 0; i < inv.getSizeInventory(); i++) {
              if (inv.getStackInSlot(i) != null) {
                addToInventory(inv.getStackInSlot(i));
                inv.setInventorySlotContents(i, null);
              }
            }
          }

          // silk touch the block if we have it
          int silkTouch = 0;
          if (miningWith != 1) {
            silkTouch =
                EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, slots[miningWith]);
          }

          if (silkTouch > 0) {
            int i = 0;
            Item item = Item.getItemFromBlock(currentBlock);
            if (item != null && item.getHasSubtypes())
              i = currentBlock.getMetaFromState(worldObj.getBlockState(currentPosition));

            ItemStack addItem = new ItemStack(currentBlock, 1, i);
            addToInventory(addItem);

          } else {
            // mine the block
            int fortuneLevel = 0;
            if (miningWith != 1) {
              fortuneLevel =
                  EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, slots[miningWith]);
            }

            // then break the block
            List<ItemStack> items =
                currentBlock.getDrops(
                    worldObj,
                    currentPosition,
                    worldObj.getBlockState(currentPosition),
                    fortuneLevel);
            // get the drops
            for (ItemStack item : items) {
              addToInventory(item);
            }
          }

          if (miningWith != 1) {
            if (ToolHelper.damageTool(
                slots[miningWith],
                worldObj,
                currentPoint.getX(),
                currentYLevel,
                currentPoint.getY())) {
              destroyTool(miningWith);
            }
          }
        }

        // remove the block and entity if there is one
        worldObj.removeTileEntity(currentPosition);
        worldObj.setBlockState(currentPosition, Blocks.COBBLESTONE.getDefaultState());
        slots[1].stackSize--;
        if (slots[1].stackSize == 0) {
          slots[1] = null;
        }
        currentMineBlocks++;
        addPartialUpdate("MinedBlocks", currentMineBlocks);
        currentBlock = null;

      } else {
        miningTime--;
      }
    } else {
      if (!isDone()) {
        currentBlock = getNextBlock();
        if (currentBlock != null) {
          Point2I currentPoint = spiral(currentColumn, pos.getX(), pos.getZ());
          BlockPos currentPosition =
              new BlockPos(currentPoint.getX(), currentYLevel, currentPoint.getY());
          IBlockState currentBlockState = worldObj.getBlockState(currentPosition);

          if (miningWith == 4) {
            miningTime = 1;
          } else {
            miningTime =
                (int)
                    Math.ceil(
                        currentBlock.getBlockHardness(currentBlockState, worldObj, currentPosition)
                            * 1.5
                            * 20);

            if (miningWith != 1) {
              float miningSpeed = ToolHelper.getDigSpeed(slots[miningWith], currentBlockState);

              // check for efficiency on the tool
              if (miningSpeed > 1) {
                int eff =
                    EnchantmentHelper.getEnchantmentLevel(
                        Enchantments.EFFICIENCY, slots[miningWith]);
                if (eff > 0) {
                  for (int i = 0; i < eff; i++) {
                    miningSpeed = miningSpeed * 1.3f;
                  }
                }
              }

              miningTime = (int) Math.ceil(miningTime / miningSpeed);
            }
          }

          // ProgressiveAutomation.logger.info("Mining: "+currentBlock.getUnlocalizedName()+" in
          // "+miningTime+" ticks");

        }
      }
    }

    if (isDone()) {
      // ProgressiveAutomation.logger.info("Done Update");
      scanBlocks();
      currentColumn = getRange();
    }
  }
Ejemplo n.º 3
0
  @Override
  public boolean generate(World world, Random rand, BlockPos pos) {
    int i1 = rand.nextInt(2) + 2;
    int j1 = -i1 - 1;
    int k1 = i1 + 1;
    int i2 = rand.nextInt(2) + 2;
    int j2 = -i2 - 1;
    int k2 = i2 + 1;
    int count = 0;

    for (int x = j1; x <= k1; ++x) {
      for (int y = -1; y <= 4; ++y) {
        for (int z = j2; z <= k2; ++z) {
          BlockPos blockpos = pos.add(x, y, z);
          Material material = world.getBlockState(blockpos).getMaterial();
          boolean flag = material.isSolid();

          if (y == -1 && !flag) {
            return false;
          }

          if (y == 4 && !flag) {
            return false;
          }

          if ((x == j1 || x == k1 || z == j2 || z == k2)
              && y == 0
              && world.isAirBlock(blockpos)
              && world.isAirBlock(blockpos.up())) {
            ++count;
          }
        }
      }
    }

    if (count >= 1 && count <= 5) {
      int type = rand.nextInt(2);
      IBlockState state1;
      IBlockState state2;

      switch (type) {
        case 1:
          state1 = Blocks.STONEBRICK.getDefaultState();
          state2 =
              Blocks.STONEBRICK
                  .getDefaultState()
                  .withProperty(BlockStoneBrick.VARIANT, BlockStoneBrick.EnumType.MOSSY);
        default:
          state1 = Blocks.COBBLESTONE.getDefaultState();
          state2 = Blocks.MOSSY_COBBLESTONE.getDefaultState();
      }

      for (int x = j1; x <= k1; ++x) {
        for (int y = 3; y >= -1; --y) {
          for (int z = j2; z <= k2; ++z) {
            BlockPos blockpos = pos.add(x, y, z);

            if (x != j1 && y != -1 && z != j2 && x != k1 && y != 4 && z != k2) {
              if (world.getBlockState(blockpos).getBlock() != Blocks.CHEST) {
                world.setBlockToAir(blockpos);
              }
            } else if (blockpos.getY() >= 0
                && !world.getBlockState(blockpos.down()).getMaterial().isSolid()) {
              world.setBlockToAir(blockpos);
            } else if (world.getBlockState(blockpos).getMaterial().isSolid()
                && world.getBlockState(blockpos).getBlock() != Blocks.CHEST) {
              if (y == -1 && rand.nextInt(4) != 0) {
                world.setBlockState(blockpos, state2, 2);
              } else {
                world.setBlockState(blockpos, state1, 2);
              }
            }
          }
        }
      }

      for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < 3; ++j) {
          int x = pos.getX() + rand.nextInt(i1 * 2 + 1) - i1;
          int y = pos.getY();
          int z = pos.getZ() + rand.nextInt(i2 * 2 + 1) - i2;
          BlockPos blockpos = new BlockPos(x, y, z);

          if (world.isAirBlock(blockpos)) {
            count = 0;

            for (EnumFacing face : EnumFacing.Plane.HORIZONTAL) {
              if (world.getBlockState(blockpos.offset(face)).getMaterial().isSolid()) {
                ++count;
              }
            }

            if (count == 1) {
              world.setBlockState(
                  blockpos,
                  Blocks.CHEST.correctFacing(world, blockpos, Blocks.CHEST.getDefaultState()),
                  2);

              TileEntity tile = world.getTileEntity(blockpos);

              if (tile != null && tile instanceof TileEntityChest) {
                ((TileEntityChest) tile)
                    .setLootTable(LootTableList.CHESTS_SIMPLE_DUNGEON, rand.nextLong());
              }

              break;
            }
          }
        }
      }

      world.setBlockState(pos, Blocks.MOB_SPAWNER.getDefaultState(), 2);

      TileEntity tile = world.getTileEntity(pos);

      if (tile != null && tile instanceof TileEntityMobSpawner) {
        ((TileEntityMobSpawner) tile).getSpawnerBaseLogic().setEntityName(pickMobSpawner(rand));
      } else {
        CaveLog.warning(
            "Failed to fetch mob spawner entity at ("
                + pos.getX()
                + ", "
                + pos.getY()
                + ", "
                + pos.getZ()
                + ")");
      }

      return true;
    }

    return false;
  }