コード例 #1
0
 private ForgeDirection getSideForItem(ItemStack is) {
   for (int k = 0; k < mappings.length; k++) {
     ItemStack map = mappings[k];
     if (map != null) {
       Item item = is.getItem();
       Item item2 = map.getItem();
       if (item.getHasSubtypes() || item2.getHasSubtypes()) {
         if (ReikaItemHelper.matchStacks(map, is)) return this.getDirection(k);
       } else {
         if (is.getItem() == map.getItem()) return this.getDirection(k);
       }
     }
   }
   return ForgeDirection.DOWN;
 }
コード例 #2
0
ファイル: BlockHelper.java プロジェクト: pl10123/MageCraft
  public static ItemStack createStackedBlock(Block block, int bMeta) {

    Item item = Item.getItemFromBlock(block);
    if (item.getHasSubtypes()) {
      return new ItemStack(item, 1, bMeta);
    }
    return new ItemStack(item, 1, 0);
  }
コード例 #3
0
  public static ItemStack createStackedBlock(Block block, int metadata) {
    int md = 0;
    Item item = Item.getItemFromBlock(block);

    if ((item != null) && item.getHasSubtypes()) {
      md = metadata;
    }

    return new ItemStack(item, 1, md);
  }
コード例 #4
0
 public boolean setMapping(int index, ItemStack item) {
   if (item == null) {
     mappings[index] = null;
     return true;
   } else {
     if (this.isValidForSlot(index, item)) {
       Item i = item.getItem();
       if (i.getHasSubtypes())
         mappings[index] = new ItemStack(item.getItem(), 1, item.getItemDamage());
       else mappings[index] = new ItemStack(item.getItem(), 1, 0);
       return true;
     } else return false;
   }
 }
コード例 #5
0
ファイル: ItemHelper.java プロジェクト: ZeroNoRyouki/ZeroCore
  public static ItemStack createItemStack(IBlockState state, int amount) {

    Block block = state.getBlock();
    Item item = Item.getItemFromBlock(block);

    if (null != item) {

      int meta = item.getHasSubtypes() ? block.getMetaFromState(state) : 0;

      return new ItemStack(item, amount, meta);
    }

    return null;
  }
コード例 #6
0
ファイル: ItemLuxSchema.java プロジェクト: rwtema/Luxcraft
  @SideOnly(Side.CLIENT)

  /** allows items to add custom lines of information to the mouseover description */
  public void addInformation(
      ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) {
    if (LuxLevels.instance.getItemStack(par1ItemStack.getItemDamage()) == null) return;
    int id = LuxLevels.instance.getItemStack(par1ItemStack.getItemDamage()).itemID;
    int damage = LuxLevels.instance.getItemStack(par1ItemStack.getItemDamage()).getItemDamage();

    if (id < 0) return;

    Item temp = Item.itemsList[id];

    if (temp != null) {
      String name1 = StatCollector.translateToLocal(temp.getItemName());

      if (temp.getHasSubtypes()) {
        name1 = StatCollector.translateToLocal(temp.getItemNameIS(new ItemStack(temp, 1, damage)));
      }

      if (name1 == null) name1 = "";

      String name = ("" + StringTranslate.getInstance().translateNamedKey(name1)).trim();

      par3List.set(0, name + " " + (String) par3List.get(0));

      LuxPacket tempPacket = LuxLevels.instance.GetLuxPacket(id, damage);

      if (tempPacket != null) {
        for (byte c = 0; c < 7; c++)
          if (tempPacket.luxLevel[c] > 0)
            par3List.add(
                LuxHelper.color_str[c]
                    + LuxHelper.color_abb[c]
                    + " "
                    + LuxHelper.display(tempPacket.luxLevel[c]));
      }
    }
  }
コード例 #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();
    }
  }