Java Code Examples for net.minecraft.item.Item#getIdFromItem()
The following examples show how to use
net.minecraft.item.Item#getIdFromItem() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TooltipCache.java From bartworks with MIT License | 6 votes |
static boolean put(ItemStack itemStack, List<String> tooltip){ Pair<Integer, Short> p = new Pair<>(Item.getIdFromItem(itemStack.getItem()), (short) itemStack.getItemDamage()); if (TooltipCache.cache.containsKey(p)) return false; if (!tooltip.isEmpty()) { StringBuilder sb = new StringBuilder(); for (String s : tooltip) { sb.append(s); sb.append(System.lineSeparator()); } char[] rettype = sb.toString().toCharArray(); return TooltipCache.cache.put(p,rettype) == rettype; } else { return false; } }
Example 2
Source File: LayoutManager.java From NotEnoughItems with MIT License | 6 votes |
@Override public List<String> handleItemDisplayName(GuiContainer gui, ItemStack stack, List<String> currenttip) { String overridename = ItemInfo.getNameOverride(stack); if (overridename != null) currenttip.set(0, overridename); String mainname = currenttip.get(0); if (showIDs()) { mainname += " " + Item.getIdFromItem(stack.getItem()); if (stack.getItemDamage() != 0) mainname += ":" + stack.getItemDamage(); currenttip.set(0, mainname); } return currenttip; }
Example 3
Source File: OreDictHandler.java From bartworks with MIT License | 6 votes |
public static void adaptCacheForWorld(){ Set<String> used = new HashSet<>(OreDictHandler.cache.keySet()); OreDictHandler.cache.clear(); OreDictHandler.cacheNonBW.clear(); for (String s : used) { if (!OreDictionary.getOres(s).isEmpty()) { ItemStack tmpstack = OreDictionary.getOres(s).get(0).copy(); Pair<Integer, Short> p = new Pair<>(Item.getIdFromItem(tmpstack.getItem()), (short) tmpstack.getItemDamage()); OreDictHandler.cache.put(s, p); for (ItemStack tmp : OreDictionary.getOres(s)) { Pair<Integer, Short> p2 = new Pair<>(Item.getIdFromItem(tmp.getItem()), (short) tmp.getItemDamage()); GameRegistry.UniqueIdentifier UI = GameRegistry.findUniqueIdentifierFor(tmp.getItem()); if (UI == null) UI = GameRegistry.findUniqueIdentifierFor(Block.getBlockFromItem(tmp.getItem())); if (!UI.modId.equals(MainMod.MOD_ID) && !UI.modId.equals(BartWorksCrossmod.MOD_ID) && !UI.modId.equals("BWCore")) { OreDictHandler.cacheNonBW.add(p2); } } } } }
Example 4
Source File: ToolSpecificStat.java From GokiStats with MIT License | 6 votes |
public void addSupportForItem(ItemStack item) { reloadConfig(); if (item == null) { return; } boolean hasSubtypes = item.getHasSubtypes(); int id = Item.getIdFromItem(item.getItem()); int meta = 0; if (hasSubtypes) { meta = item.getItemDamage(); } ItemIdMetadataTuple iimt = new ItemIdMetadataTuple(item.getItem().getRegistryName().toString(), meta); if (!this.supports.contains(iimt)) { this.supports.add(iimt); } saveConfig(); }
Example 5
Source File: NEIServerUtils.java From NotEnoughItems with MIT License | 6 votes |
/** * A simple function for comparing ItemStacks in a compatible with comparators. * * @param stack1 The {@link ItemStack} being compared. * @param stack2 The {@link ItemStack} to compare to. * @return The ordering of stack1 relative to stack2. */ public static int compareStacks(ItemStack stack1, ItemStack stack2) { if (stack1 == stack2) { return 0;//catches both null } if (stack1.isEmpty() || stack2.isEmpty()) { return stack1.isEmpty() ? -1 : 1;//null stack goes first } if (stack1.getItem() != stack2.getItem()) { return Item.getIdFromItem(stack1.getItem()) - Item.getIdFromItem(stack2.getItem()); } if (stack1.getCount() != stack2.getCount()) { return stack1.getCount() - stack2.getCount(); } return stack1.getItemDamage() - stack2.getItemDamage(); }
Example 6
Source File: ThaumcraftApi.java From ForbiddenMagic with Do What The F*ck You Want To Public License | 5 votes |
public static Object[] getCraftingRecipeKey(EntityPlayer player, ItemStack stack) { int[] key = new int[] {Item.getIdFromItem(stack.getItem()),stack.getItemDamage()}; if (keyCache.containsKey(key)) { if (keyCache.get(key)==null) return null; if (ThaumcraftApiHelper.isResearchComplete(player.getCommandSenderName(), (String)(keyCache.get(key))[0])) return keyCache.get(key); else return null; } for (ResearchCategoryList rcl:ResearchCategories.researchCategories.values()) { for (ResearchItem ri:rcl.research.values()) { if (ri.getPages()==null) continue; for (int a=0;a<ri.getPages().length;a++) { ResearchPage page = ri.getPages()[a]; if (page.recipe!=null && page.recipe instanceof CrucibleRecipe[]) { CrucibleRecipe[] crs = (CrucibleRecipe[]) page.recipe; for (CrucibleRecipe cr:crs) { if (cr.getRecipeOutput().isItemEqual(stack)) { keyCache.put(key,new Object[] {ri.key,a}); if (ThaumcraftApiHelper.isResearchComplete(player.getCommandSenderName(), ri.key)) return new Object[] {ri.key,a}; } } } else if (page.recipeOutput!=null && stack !=null && page.recipeOutput.isItemEqual(stack)) { keyCache.put(key,new Object[] {ri.key,a}); if (ThaumcraftApiHelper.isResearchComplete(player.getCommandSenderName(), ri.key)) return new Object[] {ri.key,a}; else return null; } } } } keyCache.put(key,null); return null; }
Example 7
Source File: ThaumcraftApi.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
public static Object[] getCraftingRecipeKey(EntityPlayer player, ItemStack stack) { int[] key = new int[] {Item.getIdFromItem(stack.getItem()),stack.getItemDamage()}; if (keyCache.containsKey(key)) { if (keyCache.get(key)==null) return null; if (ThaumcraftApiHelper.isResearchComplete(player.getCommandSenderName(), (String)(keyCache.get(key))[0])) return keyCache.get(key); else return null; } for (ResearchCategoryList rcl:ResearchCategories.researchCategories.values()) { for (ResearchItem ri:rcl.research.values()) { if (ri.getPages()==null) continue; for (int a=0;a<ri.getPages().length;a++) { ResearchPage page = ri.getPages()[a]; if (page.recipe!=null && page.recipe instanceof CrucibleRecipe[]) { CrucibleRecipe[] crs = (CrucibleRecipe[]) page.recipe; for (CrucibleRecipe cr:crs) { if (cr.getRecipeOutput().isItemEqual(stack)) { keyCache.put(key,new Object[] {ri.key,a}); if (ThaumcraftApiHelper.isResearchComplete(player.getCommandSenderName(), ri.key)) return new Object[] {ri.key,a}; } } } else if (page.recipeOutput!=null && stack !=null && page.recipeOutput.isItemEqual(stack)) { keyCache.put(key,new Object[] {ri.key,a}); if (ThaumcraftApiHelper.isResearchComplete(player.getCommandSenderName(), ri.key)) return new Object[] {ri.key,a}; else return null; } } } } keyCache.put(key,null); return null; }
Example 8
Source File: ForgePlayer.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
@Override public BaseBlock getBlockInHand() { ItemStack is = this.player.getHeldItem(EnumHand.MAIN_HAND); return is == null ? EditSession.nullBlock : new BaseBlock(Item.getIdFromItem(is.getItem()), is.isItemStackDamageable() ? 0 : is.getItemDamage()); }
Example 9
Source File: StatDigging.java From GokiStats with MIT License | 4 votes |
@Override public String[] getDefaultSupportedItems() { return new String[] {Item.getIdFromItem(Items.WOODEN_SHOVEL) + ":0", Item.getIdFromItem(Items.STONE_SHOVEL) + ":0", Item.getIdFromItem(Items.IRON_SHOVEL) + ":0", Item.getIdFromItem(Items.GOLDEN_SHOVEL) + ":0", Item.getIdFromItem(Items.DIAMOND_SHOVEL) + ":0"}; }
Example 10
Source File: ForgePlayer.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
@Override public BaseBlock getBlockInHand() { ItemStack is = this.player.getHeldItem(EnumHand.MAIN_HAND); return is == null ? EditSession.nullBlock : new BaseBlock(Item.getIdFromItem(is.getItem()), is.isItemStackDamageable() ? 0 : is.getItemDamage()); }
Example 11
Source File: ForgePlayerBlockBag.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
@Override public void storeItem(BaseItem item) throws BlockBagException { final int id = item.getType(); final int damage = item.getData(); int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1; assert(amount <= 64); boolean usesDamageValue = ItemType.usesDamageValue(id); if (id == BlockID.AIR) { throw new IllegalArgumentException("Can't store air block"); } loadInventory(); int freeSlot = -1; for (int slot = 0; slot < items.length; ++slot) { ItemStack forgeItem = items[slot]; if (forgeItem == null) { // Delay using up a free slot until we know there are no stacks // of this item to merge into if (freeSlot == -1) { freeSlot = slot; } continue; } int itemId = Item.getIdFromItem(forgeItem.getItem()); if (itemId != id) { // Type id doesn't fit continue; } if (usesDamageValue && forgeItem.getItemDamage() != damage) { // Damage value doesn't fit. continue; } int currentAmount = forgeItem.getCount(); if (currentAmount < 0) { // Unlimited return; } if (currentAmount >= 64) { // Full stack continue; } changed = true; int spaceLeft = 64 - currentAmount; if (spaceLeft >= amount) { forgeItem.setCount(forgeItem.getCount() + amount); return; } forgeItem.setCount(64); amount -= spaceLeft; } if (freeSlot > -1) { changed = true; items[freeSlot] = new ItemStack(Item.getItemById(id), amount); return; } throw new OutOfSpaceException(id); }
Example 12
Source File: ForgePlayer.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
@Override public int getItemInHand() { ItemStack is = this.player.getCurrentEquippedItem(); return is == null ? 0 : Item.getIdFromItem(is.getItem()); }
Example 13
Source File: StatTrimming.java From GokiStats with MIT License | 4 votes |
@Override public String[] getDefaultSupportedItems() { return new String[] {Item.getIdFromItem(Items.SHEARS) + ":0"}; }
Example 14
Source File: MinecraftStateGeneratorHelper.java From burlapcraft with GNU Lesser General Public License v3.0 | 4 votes |
public static State getCurrentState(Dungeon d) { dungeonPose = d.getPose(); length = d.getLength(); width = d.getWidth(); height = d.getHeight(); GenericOOState s = new GenericOOState(); for (int i = 0; i < height; i++) { for (int j = 0; j < length; j++) { for (int k = 0; k < width; k++) { Block block = HelperActions.getBlock( dungeonPose.getX() + j, dungeonPose.getY() + i, dungeonPose.getZ() + k); if (HelperActions.blockIsOneOf(block, HelperActions.mineableBlocks) || HelperActions.blockIsOneOf(block, HelperActions.dangerBlocks)) { int blockID = HelperActions.getBlockId( dungeonPose.getX() + j, dungeonPose.getY() + i, dungeonPose.getZ() + k); int keyX = (int) dungeonPose.getX() + j; int keyY = (int) dungeonPose.getY() + i; int keyZ = (int) dungeonPose.getZ() + k; String blockName; blockName = "block"; String key = keyX + "," + keyY + "," + keyZ; if (blockNameMap.containsKey(key)) { blockName = blockNameMap.get(key); } else { blockName += blockCount; blockNameMap.put(key, blockName); blockCount += 1; } BCBlock blockInstance = new BCBlock(j, i, k, blockID, blockName); s.addObject(blockInstance); } } } } HelperPos curPos = HelperActions.getPlayerPosition(); int rotateDirection = HelperActions.getYawDirection(); int rotateVertDirection = HelperActions.getPitchDirection(); //int selectedItemID = HelperActions.getCurrentItemID(); int selectedItemID = HelperActions.currentItemIndex(); System.out.println("Player position: " + curPos); System.out.println("Dungeon: " + dungeonPose); BCAgent agent = new BCAgent( (int)(curPos.x - dungeonPose.getX()), (int)(curPos.y - dungeonPose.getY()), (int)(curPos.z - dungeonPose.getZ()), rotateDirection, rotateVertDirection, selectedItemID); BCInventory inv = new BCInventory(); Minecraft mc = Minecraft.getMinecraft(); for(int i = 0; i < 9; i++){ ItemStack itemStack = mc.thePlayer.inventory.mainInventory[i]; if(itemStack == null){ inv.inv[i] = new BCInventory.BCIStack(-1, 0); } else { Item item = itemStack.getItem(); inv.inv[i] = new BCInventory.BCIStack(Item.getIdFromItem(item), itemStack.stackSize); } } s.addObject(inv); s.addObject(agent); BCMap map = new BCMap(getMap(d)); s.addObject(map); validate(s); return s; }
Example 15
Source File: ForgePlayer.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
@Override public BaseBlock getBlockInHand() { ItemStack is = this.player.getCurrentEquippedItem(); return is == null ? EditSession.nullBlock : new BaseBlock(Item.getIdFromItem(is.getItem()), is.isItemStackDamageable() ? 0 : is.getItemDamage()); }
Example 16
Source File: ForgePlayer.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
@Override public int getItemInHand() { ItemStack is = this.player.getHeldItem(EnumHand.MAIN_HAND); return is == null ? 0 : Item.getIdFromItem(is.getItem()); }
Example 17
Source File: ForgePlayer.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
@Override public BaseBlock getBlockInHand() { ItemStack is = this.player.getCurrentEquippedItem(); return is == null ? EditSession.nullBlock : new BaseBlock(Item.getIdFromItem(is.getItem()), is.isItemStackDamageable() ? 0 : is.getItemDamage()); }
Example 18
Source File: ForgePlayerBlockBag.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
@Override public void fetchItem(BaseItem item) throws BlockBagException { final int id = item.getType(); final int damage = item.getData(); int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1; assert(amount == 1); boolean usesDamageValue = ItemType.usesDamageValue(id); if (id == BlockID.AIR) { throw new IllegalArgumentException("Can't fetch air block"); } loadInventory(); boolean found = false; for (int slot = 0; slot < items.length; ++slot) { ItemStack forgeItem = items[slot]; if (forgeItem == null) { continue; } int itemId = Item.getIdFromItem(forgeItem.getItem()); if (itemId != id) { // Type id doesn't fit continue; } if (usesDamageValue && forgeItem.getItemDamage() != damage) { // Damage value doesn't fit. continue; } int currentAmount = forgeItem.stackSize; if (currentAmount < 0) { // Unlimited return; } changed = true; if (currentAmount > 1) { forgeItem.stackSize--; found = true; } else { items[slot] = null; found = true; } break; } if (!found) { throw new OutOfBlocksException(); } }
Example 19
Source File: ForgePlayerBlockBag.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
@Override public void fetchItem(BaseItem item) throws BlockBagException { final int id = item.getType(); final int damage = item.getData(); int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1; assert(amount == 1); boolean usesDamageValue = ItemType.usesDamageValue(id); if (id == BlockID.AIR) { throw new IllegalArgumentException("Can't fetch air block"); } loadInventory(); boolean found = false; for (int slot = 0; slot < items.length; ++slot) { ItemStack forgeItem = items[slot]; if (forgeItem == null) { continue; } int itemId = Item.getIdFromItem(forgeItem.getItem()); if (itemId != id) { // Type id doesn't fit continue; } if (usesDamageValue && forgeItem.getItemDamage() != damage) { // Damage value doesn't fit. continue; } int currentAmount = forgeItem.stackSize; if (currentAmount < 0) { // Unlimited return; } changed = true; if (currentAmount > 1) { forgeItem.stackSize--; found = true; } else { items[slot] = null; found = true; } break; } if (!found) { throw new OutOfBlocksException(); } }
Example 20
Source File: ItemUtils.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 2 votes |
/** * Compares an ItemStack, Useful for comparators. * * @param stack1 First Stack. * @param stack2 Second Stack. * @return Returns the difference. */ public static int compareItemStack(@Nonnull ItemStack stack1, @Nonnull ItemStack stack2) { int itemStack1ID = Item.getIdFromItem(stack1.getItem()); int itemStack2ID = Item.getIdFromItem(stack1.getItem()); return itemStack1ID != itemStack2ID ? itemStack1ID - itemStack2ID : (stack1.getDamage() == stack2.getDamage() ? 0 : stack1.getDamage() - stack2.getDamage()); }