Ejemplo n.º 1
0
 private Collection<ItemStack> getDrops(World world, int x, int y, int z, Block b, int meta) {
   float f = this.getYield(b, meta);
   if (ReikaRandomHelper.doWithChance(f)) {
     Collection<ItemStack> ret =
         b.getDrops(world, x, y, z, meta, this.getEnchantment(Enchantment.fortune));
     if (tree.getTreeType() == ModWoodList.SLIME) {
       Block log = tree.getTreeType().getLogID();
       if (b == log) {
         ret.clear();
         ret.add(new ItemStack(Items.slime_ball));
       }
     }
     return ret;
   } else return new ArrayList();
 }
  private ItemStack dropLittleBlockAsNormalBlock(
      World world, int x, int y, int z, Block blockId, int metaData) {
    boolean dropsBlocks = blockId.getDrops(world, x, y, z, metaData, 0).size() > 0 ? true : false;
    if (dropsBlocks) {
      Item idDropped = blockId.getItemDropped(metaData, world.rand, 0);
      int quantityDropped = blockId.quantityDropped(world.rand);
      int damageDropped = blockId.damageDropped(metaData);
      ItemStack itemstack = new ItemStack(idDropped, quantityDropped, damageDropped);

      if (quantityDropped > 0) {
        return itemstack;
      }
    }
    return null;
  }
Ejemplo n.º 3
0
  public static List<ItemStack> getItemsFromBlock(
      World world, Block block, int x, int y, int z, int meta, boolean silkTouch, int fortune) {
    boolean canSilk = block.canSilkHarvest(world, null, x, y, z, meta);

    if (canSilk && silkTouch) {
      ArrayList<ItemStack> items = new ArrayList<ItemStack>();
      ItemStack item = new ItemStack(block, 1, meta);

      items.add(item);

      return items;
    } else {
      return block.getDrops(world, x, y, z, meta, fortune);
    }
  }
Ejemplo n.º 4
0
 private void dropBlock(
     World world, int x, int y, int z, int dx, int dy, int dz, Block id, int meta2) {
   if (this.silkTouch()) {
     this.dropItems(world, x, y, z, ReikaJavaLibrary.makeListFrom(new ItemStack(id, 1, meta2)));
   } else {
     this.dropItems(world, x, y, z, id.getDrops(world, dx, dy, dz, meta2, 0));
   }
   this.getFillerBlock(world, dx, dy, dz, id, meta2).place(world, dx, dy, dz);
   ReikaSoundHelper.playBreakSound(world, dx, dy, dz, id);
   ReikaPacketHelper.sendDataPacket(
       DragonAPIInit.packetChannel,
       PacketIDs.BREAKPARTICLES.ordinal(),
       world,
       dx,
       dy,
       dz,
       Block.getIdFromBlock(id),
       meta2);
 }
Ejemplo n.º 5
0
  public static List<ItemStack> breakBlock(
      World worldObj,
      EntityPlayer player,
      int x,
      int y,
      int z,
      Block block,
      int fortune,
      boolean doBreak,
      boolean silkTouch) {

    if (block.getBlockHardness(worldObj, x, y, z) == -1) {
      return new LinkedList<ItemStack>();
    }
    int meta = worldObj.getBlockMetadata(x, y, z);
    List<ItemStack> stacks = null;
    if (silkTouch && block.canSilkHarvest(worldObj, player, x, y, z, meta)) {
      stacks = new LinkedList<ItemStack>();
      stacks.add(createStackedBlock(block, meta));
    } else {
      stacks = block.getDrops(worldObj, x, y, z, meta, fortune);
    }
    if (!doBreak) {
      return stacks;
    }
    worldObj.playAuxSFXAtEntity(player, 2001, x, y, z, Block.getIdFromBlock(block) + (meta << 12));
    worldObj.setBlockToAir(x, y, z);

    List<EntityItem> result =
        worldObj.getEntitiesWithinAABB(
            EntityItem.class,
            AxisAlignedBB.getBoundingBox(x - 2, y - 2, z - 2, x + 3, y + 3, z + 3));
    for (int i = 0; i < result.size(); i++) {
      EntityItem entity = result.get(i);
      if (entity.isDead || entity.getEntityItem().stackSize <= 0) {
        continue;
      }
      stacks.add(entity.getEntityItem());
      entity.worldObj.removeEntity(entity);
    }
    return stacks;
  }
 private void processItem(World world, int x, int y, int z) {
   if (ReikaItemHelper.isBlock(inv[0])) {
     Block b = Block.getBlockFromItem(inv[0].getItem());
     ArrayList<ItemStack> li =
         b.getDrops(
             world, x, y, z, inv[0].getItemDamage(), this.getEnchantment(Enchantment.fortune));
     li = ReikaItemHelper.collateItemList(li);
     if (!li.isEmpty()) {
       inv[1] = li.remove(0);
       overflow.addAll(li);
     }
   } else if (ModList.IC2.isLoaded() && IC2Handler.IC2Stacks.SCRAPBOX.match(inv[0])) {
     inv[1] = Recipes.scrapboxDrops.getDrop(inv[0], false);
   } else if (ModList.MYSTCRAFT.isLoaded()
       && inv[0].getItem() == MystCraftHandler.getInstance().folderID) {
     List<ItemStack> li = ReikaMystcraftHelper.getPagesInFolder(this.getPlacer(), inv[0], true);
     if (!li.isEmpty()) {
       inv[1] = li.remove(0);
       overflow.addAll(li);
     }
   } else if (inv[0].getItem().getClass() == lootBagClass) {
     ArrayList<ItemStack> li = new ArrayList();
     int n = 8 + rand.nextInt(5);
     for (int i = 0; i < n; i++) {
       try {
         ItemStack is = (ItemStack) generateBagLoot.invoke(null, inv[0].getItemDamage(), rand);
         if (is != null) {
           li.add(is);
         }
       } catch (Exception e) {
         e.printStackTrace();
         this.writeError(e);
       }
     }
     li = ReikaItemHelper.collateItemList(li);
     if (!li.isEmpty()) {
       inv[1] = li.remove(0);
       overflow.addAll(li);
     }
   }
   ReikaInventoryHelper.decrStack(0, inv);
 }
Ejemplo n.º 7
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();
    }
  }
  /**
   * *****************************************************************************************************************
   * ********************************************** Tile Methods
   * ******************************************************
   * *****************************************************************************************************************
   */
  @Override
  @SuppressWarnings("unchecked")
  public void updateEntity() {
    super.updateEntity();
    if (!worldObj.isRemote
        && !isPowered()
        && getCore() != null
        && pickSlot.getStackInSlot(0) != null
        && worldObj.rand.nextInt(20) == 0) {
      SixWayRotation rotation = new SixWayRotation();
      ForgeDirection dir =
          rotation.convertMetaToDirection(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
      Location blockBreakLocation = new Location(this);
      blockBreakLocation.travel(dir);
      if (!worldObj.isAirBlock(blockBreakLocation.x, blockBreakLocation.y, blockBreakLocation.z)) {
        Block toBreak =
            worldObj.getBlock(blockBreakLocation.x, blockBreakLocation.y, blockBreakLocation.z);
        if (toBreak.getMaterial() == Material.water || toBreak.getMaterial() == Material.lava)
          return;
        int harvestLevel =
            pickSlot
                .getStackInSlot(0)
                .getItem()
                .getHarvestLevel(pickSlot.getStackInSlot(0), "pickaxe");
        if (toBreak.getHarvestLevel(
                worldObj.getBlockMetadata(
                    blockBreakLocation.x, blockBreakLocation.y, blockBreakLocation.z))
            <= harvestLevel) {

          int fortune = 0;
          boolean silkTouch =
              toBreak.canSilkHarvest(
                  worldObj,
                  null,
                  blockBreakLocation.x,
                  blockBreakLocation.y,
                  blockBreakLocation.x,
                  worldObj.getBlockMetadata(
                      blockBreakLocation.x, blockBreakLocation.y, blockBreakLocation.z));
          boolean hasSilkTouch = false;
          NBTTagList enchantList = pickSlot.getStackInSlot(0).getEnchantmentTagList();
          if (enchantList != null) {
            for (int i = 0; i < enchantList.tagCount(); i++) {
              NBTTagCompound tag = enchantList.getCompoundTagAt(i);
              if (tag.hasKey("id") && tag.getInteger("id") == 35) fortune = tag.getInteger("lvl");
              else if (tag.hasKey("id") && tag.getInteger("id") == 33) hasSilkTouch = true;
            }
          }
          ArrayList<ItemStack> itemStacks = new ArrayList<>();
          if (silkTouch && hasSilkTouch) {
            itemStacks.add(
                new ItemStack(
                    toBreak,
                    1,
                    worldObj.getBlockMetadata(
                        blockBreakLocation.x, blockBreakLocation.y, blockBreakLocation.z)));
          } else {
            itemStacks =
                toBreak.getDrops(
                    worldObj,
                    blockBreakLocation.x,
                    blockBreakLocation.y,
                    blockBreakLocation.z,
                    worldObj.getBlockMetadata(
                        blockBreakLocation.x, blockBreakLocation.y, blockBreakLocation.z),
                    fortune);
          }
          for (ItemStack itemStack : itemStacks) {
            if (itemStack != null && itemStack.stackSize > 0) {
              float rx = worldObj.rand.nextFloat() * 0.8F + 0.1F;
              float ry = worldObj.rand.nextFloat() * 0.8F + 0.1F;
              float rz = worldObj.rand.nextFloat() * 0.8F + 0.1F;

              EntityItem entityItem =
                  new EntityItem(
                      worldObj,
                      blockBreakLocation.x + rx,
                      blockBreakLocation.y + ry,
                      blockBreakLocation.z + rz,
                      new ItemStack(
                          itemStack.getItem(), itemStack.stackSize, itemStack.getItemDamage()));

              if (itemStack.hasTagCompound())
                entityItem
                    .getEntityItem()
                    .setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());

              float factor = 0.05F;
              entityItem.motionX = worldObj.rand.nextGaussian() * factor;
              entityItem.motionY = worldObj.rand.nextGaussian() * factor + 0.2F;
              entityItem.motionZ = worldObj.rand.nextGaussian() * factor;
              worldObj.spawnEntityInWorld(entityItem);

              itemStack.stackSize = 0;
            }
          }
          worldObj.playAuxSFX(
              2001,
              blockBreakLocation.x,
              blockBreakLocation.y,
              blockBreakLocation.z,
              Block.getIdFromBlock(toBreak)
                  + (worldObj.getBlockMetadata(
                          blockBreakLocation.x, blockBreakLocation.y, blockBreakLocation.z)
                      << 12));
          worldObj.setBlockToAir(blockBreakLocation.x, blockBreakLocation.y, blockBreakLocation.z);
          pickSlot.getStackInSlot(0).setItemDamage(pickSlot.getStackInSlot(0).getItemDamage() + 1);
          if (pickSlot.getStackInSlot(0).getItemDamage()
              > pickSlot.getStackInSlot(0).getMaxDamage()) pickSlot.setStackInSlot(null, 0);
        }
      }
    }
  }
Ejemplo n.º 9
0
  @Override
  public void doExplosionB(boolean spawnParticles) {
    worldObj.playSoundEffect(
        this.explosionX,
        this.explosionY,
        this.explosionZ,
        "random.explode",
        4.0F,
        (1.0F + (this.worldObj.rand.nextFloat() - this.worldObj.rand.nextFloat()) * 0.2F) * 0.7F);

    if (this.explosionSize >= 2.0F && this.isSmoking)
      worldObj.spawnParticle(
          "hugeexplosion", this.explosionX, this.explosionY, this.explosionZ, 1.0D, 0.0D, 0.0D);
    else
      worldObj.spawnParticle(
          "largeexplode", this.explosionX, this.explosionY, this.explosionZ, 1.0D, 0.0D, 0.0D);

    Iterator iterator;
    ChunkPosition chunkposition;
    int i;
    int j;
    int k;
    Block block;
    List<ItemStack> list = Lists.newArrayList();

    if (this.isSmoking) {
      iterator = this.affectedBlockPositions.iterator();

      while (iterator.hasNext()) {
        chunkposition = (ChunkPosition) iterator.next();
        i = chunkposition.chunkPosX;
        j = chunkposition.chunkPosY;
        k = chunkposition.chunkPosZ;
        block = worldObj.getBlock(i, j, k);

        if (spawnParticles) {
          double d0 = (double) ((float) i + worldObj.rand.nextFloat());
          double d1 = (double) ((float) j + worldObj.rand.nextFloat());
          double d2 = (double) ((float) k + worldObj.rand.nextFloat());
          double d3 = d0 - this.explosionX;
          double d4 = d1 - this.explosionY;
          double d5 = d2 - this.explosionZ;
          double d6 = (double) MathHelper.sqrt_double(d3 * d3 + d4 * d4 + d5 * d5);
          d3 /= d6;
          d4 /= d6;
          d5 /= d6;
          double d7 = 0.5D / (d6 / (double) this.explosionSize + 0.1D);
          d7 *= (double) (worldObj.rand.nextFloat() * worldObj.rand.nextFloat() + 0.3F);
          d3 *= d7;
          d4 *= d7;
          d5 *= d7;
          worldObj.spawnParticle(
              "explode",
              (d0 + this.explosionX * 1.0D) / 2.0D,
              (d1 + this.explosionY * 1.0D) / 2.0D,
              (d2 + this.explosionZ * 1.0D) / 2.0D,
              d3,
              d4,
              d5);
          worldObj.spawnParticle("smoke", d0, d1, d2, d3, d4, d5);
        }

        if (block.getMaterial() != Material.air) {
          ArrayList<ItemStack> drops =
              block.getDrops(worldObj, i, j, k, worldObj.getBlockMetadata(i, j, k), 0);
          if (drops != null && drops.size() > 0) list.addAll(drops);

          block.onBlockExploded(worldObj, i, j, k, this);
        }
      }

      Entity ent = this.getExplosivePlacedBy();
      WorldHelper.createLootDrop(list, worldObj, explosionX, explosionY, explosionZ);
    }
  }