public static List<EnchantmentData> getEnchantmentDatas(int p_185291_0_, ItemStack p_185291_1_, boolean allowTreasure) { List<EnchantmentData> list = Lists.<EnchantmentData>newArrayList(); Item item = p_185291_1_.getItem(); boolean flag = p_185291_1_.getItem() == Items.BOOK; for (Enchantment enchantment : Enchantment.REGISTRY) { if ((!enchantment.isTreasureEnchantment() || allowTreasure) && (enchantment.type.canEnchantItem(item) || flag)) { for (int i = enchantment.getMaxLevel(); i > enchantment.getMinLevel() - 1; --i) { if (p_185291_0_ >= enchantment.getMinEnchantability(i) && p_185291_0_ <= enchantment.getMaxEnchantability(i)) { list.add(new EnchantmentData(enchantment, i)); break; } } } } return list; }
/** * Get the quantity dropped based on the given fortune level */ public int quantityDroppedWithBonus(int fortune, Random random) { if (fortune > 0 && Item.getItemFromBlock(this) != this.getItemDropped((IBlockState)this.getBlockState().getValidStates().iterator().next(), random, fortune)) { int i = random.nextInt(fortune + 2) - 1; if (i < 0) { i = 0; } return this.quantityDropped(random) * (i + 1); } else { return this.quantityDropped(random); } }
public RenderTarget(Entity entity) { this.entity = entity; trackEntries = EntityTrackHandler.getTrackersForEntity(entity); circle1 = new RenderTargetCircle(); circle2 = new RenderTargetCircle(); Item droppedItem = null; if (entity instanceof EntityLiving) { try { droppedItem = null;//TODO 1.8 EntityUtils.getLivingDrop((EntityLiving)entity); } catch (Throwable e) { } } if (droppedItem != null) { stat = new GuiAnimatedStat(null, entity.getName(), new ItemStack(droppedItem, 1, 0), 20, -20, 0x3000AA00, null, false); } else { stat = new GuiAnimatedStat(null, entity.getName(), "", 20, -20, 0x3000AA00, null, false); } stat.setMinDimensionsAndReset(0, 0); }
private static void initStats() { for (Item item : net.minecraftforge.fml.common.registry.GameData.getItemRegistry().typeSafeIterable()) { if (item != null) { int i = Item.getIdFromItem(item); String s = getItemName(item); if (s != null) { OBJECT_USE_STATS[i] = (new StatCrafting("stat.useItem.", s, new TextComponentTranslation("stat.useItem", new Object[] {(new ItemStack(item)).getTextComponent()}), item)).registerStat(); if (!(item instanceof ItemBlock)) { USE_ITEM_STATS.add((StatCrafting)OBJECT_USE_STATS[i]); } } } } replaceAllSimilarBlocks(OBJECT_USE_STATS, true); }
@Override public void call(String[] args) throws CmdException { if(args.length == 0) throw new CmdSyntaxError(); if(!WMinecraft.getPlayer().capabilities.isCreativeMode) throw new CmdError("Creative mode only."); ItemStack item = WMinecraft.getPlayer().inventory.getCurrentItem(); if(item == null || Item.getIdFromItem(item.getItem()) != 387) throw new CmdError( "You are not holding a written book in your hand."); String author = args[0]; for(int i = 1; i < args.length; i++) author += " " + args[i]; item.setTagInfo("author", new NBTTagString(author)); }
/** * Spawns this Block's drops into the World as EntityItems. */ public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune) { if (!worldIn.isRemote) { int i = this.quantityDroppedWithBonus(fortune, worldIn.rand); for (int j = 0; j < i; ++j) { if (worldIn.rand.nextFloat() <= chance) { Item item = this.getItemDropped(state, worldIn.rand, fortune); if (item != null) { spawnAsEntity(worldIn, pos, new ItemStack(item, 1, this.damageDropped(state))); } } } } }
/** * Makes an {@link ItemStack} based on the itemName reference, with supplied meta, stackSize and nbt, if possible * <p/> * Will return null if the item doesn't exist (because it's not from a loaded mod for example) * Will throw a {@link RuntimeException} if the nbtString is invalid for use in an {@link ItemStack} * * @param itemName a registry name reference * @param meta the meta * @param stackSize the stack size * @param nbtString an nbt stack as a string, will be processed by {@link JsonToNBT} * @return a new itemstack */ public static ItemStack makeItemStack(String itemName, int meta, int stackSize, String nbtString) { if (itemName == null) { throw new IllegalArgumentException("The itemName cannot be null"); } Item item = GameData.getItemRegistry().getObject(new ResourceLocation(itemName)); if (item == null) { FMLLog.getLogger().log(Level.TRACE, "Unable to find item with name {}", itemName); return null; } ItemStack is = new ItemStack(item, stackSize, meta); if (!Strings.isNullOrEmpty(nbtString)) { NBTBase nbttag = null; try { nbttag = JsonToNBT.getTagFromJson(nbtString); } catch (NBTException e) { FMLLog.getLogger().log(Level.WARN, "Encountered an exception parsing ItemStack NBT string {}", nbtString, e); throw Throwables.propagate(e); } if (!(nbttag instanceof NBTTagCompound)) { FMLLog.getLogger().log(Level.WARN, "Unexpected NBT string - multiple values {}", nbtString); throw new RuntimeException("Invalid NBT JSON"); } else { is.setTagCompound((NBTTagCompound)nbttag); } } return is; }
/** * Plays sounds and makes particles for item in use state */ protected void updateItemUse(ItemStack stack, int eatingParticleCount) { if (!stack.func_190926_b() && this.isHandActive()) { if (stack.getItemUseAction() == EnumAction.DRINK) { this.playSound(SoundEvents.ENTITY_GENERIC_DRINK, 0.5F, this.world.rand.nextFloat() * 0.1F + 0.9F); } if (stack.getItemUseAction() == EnumAction.EAT) { for (int i = 0; i < eatingParticleCount; ++i) { Vec3d vec3d = new Vec3d(((double)this.rand.nextFloat() - 0.5D) * 0.1D, Math.random() * 0.1D + 0.1D, 0.0D); vec3d = vec3d.rotatePitch(-this.rotationPitch * 0.017453292F); vec3d = vec3d.rotateYaw(-this.rotationYaw * 0.017453292F); double d0 = (double)(-this.rand.nextFloat()) * 0.6D - 0.3D; Vec3d vec3d1 = new Vec3d(((double)this.rand.nextFloat() - 0.5D) * 0.3D, d0, 0.6D); vec3d1 = vec3d1.rotatePitch(-this.rotationPitch * 0.017453292F); vec3d1 = vec3d1.rotateYaw(-this.rotationYaw * 0.017453292F); vec3d1 = vec3d1.addVector(this.posX, this.posY + (double)this.getEyeHeight(), this.posZ); if (stack.getHasSubtypes()) { this.world.spawnParticle(EnumParticleTypes.ITEM_CRACK, vec3d1.xCoord, vec3d1.yCoord, vec3d1.zCoord, vec3d.xCoord, vec3d.yCoord + 0.05D, vec3d.zCoord, new int[] {Item.getIdFromItem(stack.getItem()), stack.getMetadata()}); } else { this.world.spawnParticle(EnumParticleTypes.ITEM_CRACK, vec3d1.xCoord, vec3d1.yCoord, vec3d1.zCoord, vec3d.xCoord, vec3d.yCoord + 0.05D, vec3d.zCoord, new int[] {Item.getIdFromItem(stack.getItem())}); } } this.playSound(SoundEvents.ENTITY_GENERIC_EAT, 0.5F + 0.5F * (float)this.rand.nextInt(2), (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F); } } }
/** * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks) */ public void getSubBlocks(Item itemIn, CreativeTabs tab, NonNullList<ItemStack> list) { if (itemIn != Item.getItemFromBlock(Blocks.DOUBLE_STONE_SLAB)) { for (BlockStoneSlab.EnumType blockstoneslab$enumtype : BlockStoneSlab.EnumType.values()) { if (blockstoneslab$enumtype != BlockStoneSlab.EnumType.WOOD) { list.add(new ItemStack(itemIn, 1, blockstoneslab$enumtype.getMetadata())); } } } }
public static void registerToolModels() { List<Item> toolsList = Arrays.asList(ExPItems.knife, ExPItems.pickaxe, ExPItems.axe, ExPItems.shovel, ExPItems.hoe, ExPItems.sword, ExPItems.scythe, ExPItems.battleaxe, ExPItems.hammer, ExPItems.spear, ExPItems.watering_can, ExPItems.gardening_spade); toolsList.forEach(tool -> ModelLoader.setCustomMeshDefinition(tool, stack -> new ModelResourceLocation(new ResourceLocation(tool.getRegistryName().getResourceDomain(), "tools/" + tool.getRegistryName().getResourcePath()), "material=" + EnumToolStats.values()[stack.getMetadata()].getName()))); for (int i = 0; i < EnumToolStats.values().length; ++i) { Integer lambdaCaptureInt = i; toolsList.forEach(tool -> ModelLoader.registerItemVariants(tool, new ModelResourceLocation(new ResourceLocation(tool.getRegistryName().getResourceDomain(), "tools/" + tool.getRegistryName().getResourcePath()), "material=" + EnumToolStats.values()[lambdaCaptureInt].getName()))); } }
/** * Remap the missing item to the specified Item. * * Use this if you have renamed an Item. * Existing references using the old name will point to the new one. * * @param target Item to remap to. */ public void remap(Item target) { if (type != GameRegistry.Type.ITEM) throw new IllegalArgumentException("Can't remap a block to an item."); if (target == null) throw new NullPointerException("remap target is null"); if (GameData.getItemRegistry().getId(target) < 0) throw new IllegalArgumentException(String.format("The specified item %s hasn't been registered at startup.", target)); action = Action.REMAP; this.target = target; }
public static ItemStack doReaction(ItemStack reagent, ItemStack potionIn) { if (!potionIn.func_190926_b()) { PotionType potiontype = PotionUtils.getPotionFromItem(potionIn); Item item = potionIn.getItem(); int i = 0; for (int j = POTION_ITEM_CONVERSIONS.size(); i < j; ++i) { PotionHelper.MixPredicate<Item> mixpredicate = (PotionHelper.MixPredicate)POTION_ITEM_CONVERSIONS.get(i); if (mixpredicate.input == item && mixpredicate.reagent.apply(reagent)) { return PotionUtils.addPotionToItemStack(new ItemStack((Item)mixpredicate.output), potiontype); } } i = 0; for (int k = POTION_TYPE_CONVERSIONS.size(); i < k; ++i) { PotionHelper.MixPredicate<PotionType> mixpredicate1 = (PotionHelper.MixPredicate)POTION_TYPE_CONVERSIONS.get(i); if (mixpredicate1.input == potiontype && mixpredicate1.reagent.apply(reagent)) { return PotionUtils.addPotionToItemStack(new ItemStack(item), (PotionType)mixpredicate1.output); } } } return potionIn; }
@Override public void getSubItems(Item itemIn, CreativeTabs tab, NonNullList<ItemStack> subItems) { for (int c = 0; c < subs.size(); c++) { ItemStack is = new ItemStack(this, 1, c); subItems.add(is); } }
/** * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks) */ @SideOnly(Side.CLIENT) public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list) { for (BlockSandStone.EnumType blocksandstone$enumtype : BlockSandStone.EnumType.values()) { list.add(new ItemStack(itemIn, 1, blocksandstone$enumtype.getMetadata())); } }
/** * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks) */ public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list) { for (int i = 0; i < 16; ++i) { list.add(new ItemStack(itemIn, 1, i)); } }
@SubscribeEvent public void onItemRegistry(RegistryEvent.Register<Item> e) { e.getRegistry().registerAll(Ref.ITEMS.toArray(new Item[0])); for (Block block : Ref.BLOCKS) e.getRegistry().register(new ItemBlock(block).setRegistryName(block.getRegistryName())); }
private List<String> getVariantNames(Item p_177596_1_) { List<String> list = (List)this.variantNames.get(p_177596_1_); if (list == null) { list = Collections.<String>singletonList(((ResourceLocation)Item.itemRegistry.getNameForObject(p_177596_1_)).toString()); } return list; }
/** * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks) */ public void getSubBlocks(Item itemIn, CreativeTabs tab, NonNullList<ItemStack> list) { for (BlockWall.EnumType blockwall$enumtype : BlockWall.EnumType.values()) { list.add(new ItemStack(itemIn, 1, blockwall$enumtype.getMetadata())); } }
public ItemAndEmeraldToItem(Item p_i45813_1_, EntityVillager.PriceInfo p_i45813_2_, Item p_i45813_3_, EntityVillager.PriceInfo p_i45813_4_) { this.field_179411_a = new ItemStack(p_i45813_1_); this.field_179409_b = p_i45813_2_; this.field_179410_c = new ItemStack(p_i45813_3_); this.field_179408_d = p_i45813_4_; }
private static Item getRegisteredItem(String name) { Item item = (Item)Item.REGISTRY.getObject(new ResourceLocation(name)); if (item == null) { throw new IllegalStateException("Invalid Item requested: " + name); } else { return item; } }
protected void initItem(Item item, ContentHelper helper) { this.item = item; item.setUnlocalizedName(helper.getModId() + "." + id); item.setRegistryName(id); }
/** * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks) */ public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list) { for (BlockWall.EnumType blockwall$enumtype : BlockWall.EnumType.values()) { list.add(new ItemStack(itemIn, 1, blockwall$enumtype.getMetadata())); } }
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te) { if (!worldIn.isRemote && player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == Items.shears) { player.triggerAchievement(StatList.mineBlockStatArray[Block.getIdFromBlock(this)]); spawnAsEntity(worldIn, pos, new ItemStack(Item.getItemFromBlock(this), 1, ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata() - 4)); } else { super.harvestBlock(worldIn, player, pos, state, te); } }
@Override public Item getItemDropped(IBlockState state, Random rand, int fortune) { int meta = getMetaFromState(state); if (meta == EnumOreType.STARDUST.getMetadata()) { return ModItems.resource; } return super.getItemDropped(state, rand, fortune); }
/** * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks) */ @SideOnly(Side.CLIENT) public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list) { list.add(new ItemStack(itemIn, 1, 0)); list.add(new ItemStack(itemIn, 1, 1)); }
@Override public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack) { if (!worldIn.isRemote && stack.getItem() instanceof ItemShears) { player.addStat(StatList.getBlockStats(this)); spawnAsEntity(worldIn, pos, new ItemStack(Item.getItemFromBlock(this))); } else { super.harvestBlock(worldIn, player, pos, state, te, stack); } }
private void loadItemModels() { this.registerVariantNames(); for (Item item : Item.REGISTRY) { for (String s : this.getVariantNames(item)) { ResourceLocation resourcelocation = this.getItemLocation(s); ResourceLocation resourcelocation1 = (ResourceLocation)Item.REGISTRY.getNameForObject(item); this.loadItemModel(s, resourcelocation, resourcelocation1); if (item.hasCustomProperties()) { ModelBlock modelblock = (ModelBlock)this.models.get(resourcelocation); if (modelblock != null) { for (ResourceLocation resourcelocation2 : modelblock.getOverrideLocations()) { this.loadItemModel(resourcelocation2.toString(), resourcelocation2, resourcelocation1); } } } } } }
/** * Use {@link #register(IForgeRegistryEntry)} instead */ @Deprecated public static void registerItem(Item item, String name) { if (item.getRegistryName() == null && Strings.isNullOrEmpty(name)) throw new IllegalArgumentException("Attempted to register a item with no name: " + item); if (item.getRegistryName() != null && !item.getRegistryName().toString().equals(name)) throw new IllegalArgumentException("Attempted to register a item with conflicting names. Old: " + item.getRegistryName() + " New: " + name); register(item.getRegistryName() == null ? item.setRegistryName(name) : item); }
public StatCrafting(String p_i45910_1_, String p_i45910_2_, IChatComponent statNameIn, Item p_i45910_4_) { super(p_i45910_1_ + p_i45910_2_, statNameIn); this.field_150960_a = p_i45910_4_; int i = Item.getIdFromItem(p_i45910_4_); if (i != 0) { IScoreObjectiveCriteria.INSTANCES.put(p_i45910_1_ + i, this.func_150952_k()); } }
/** * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks) */ @SideOnly(Side.CLIENT) public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list) { for (BlockSand.EnumType blocksand$enumtype : BlockSand.EnumType.values()) { list.add(new ItemStack(itemIn, 1, blocksand$enumtype.getMetadata())); } }
/** * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks) */ public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list) { for (EnumDyeColor enumdyecolor : EnumDyeColor.values()) { list.add(new ItemStack(itemIn, 1, enumdyecolor.getMetadata())); } }
private static void registerUpgrades(IForgeRegistry<Item> registry) { for (EnumUpgrade upgrade : EnumUpgrade.values()) { if (upgrade != EnumUpgrade.THAUMCRAFT || Loader.isModLoaded(ModIds.THAUMCRAFT)) { String upgradeName = upgrade.toString().toLowerCase() + "_upgrade"; Item upgradeItem = new ItemMachineUpgrade(upgradeName, upgrade.ordinal()); registerItem(registry, upgradeItem); upgrades.put(upgrade, upgradeItem); } } }
@Override public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { if (world.isRemote) { return stack; } // Not doing this on client side if (stack.getItemDamage() == 0) { return stack; } // Already fully loaded if (stack.getItemDamage() < 25) { return stack; } // No room for another lapis block boolean doSFX = false; //if (player.inventory.hasItemStack(this.lapisStack)) if (player.inventory.hasItem(Item.getItemFromBlock(Blocks.lapis_block))) { //this.consumeItemStack(player.inventory, this.lapisStack); // We're just grabbing what we need from the inventory int dmg = stack.getItemDamage() - 25; stack.setItemDamage(dmg); player.inventory.consumeInventoryItem(Item.getItemFromBlock(Blocks.lapis_block)); // We're just grabbing what we need from the inventory // SFX doSFX = true; } // else, doesn't have what it takes if (doSFX) { world.playSoundAtEntity(player, "random.wood_click", 1.0F, 0.2F); } return stack; }
protected Barrier(World worldIn, double p_i46286_2_, double p_i46286_4_, double p_i46286_6_, Item p_i46286_8_) { super(worldIn, p_i46286_2_, p_i46286_4_, p_i46286_6_, 0.0D, 0.0D, 0.0D); this.setParticleTexture(Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getParticleIcon(p_i46286_8_)); this.particleRed = 1.0F; this.particleGreen = 1.0F; this.particleBlue = 1.0F; this.motionX = 0.0D; this.motionY = 0.0D; this.motionZ = 0.0D; this.particleGravity = 0.0F; this.particleMaxAge = 80; }
/** * Returns the number of ticks that the supplied fuel item will keep the furnace burning, or 0 if the item isn't * fuel */ public static int getItemBurnTime(ItemStack p_145952_0_) { if (p_145952_0_ == null) { return 0; } else { Item item = p_145952_0_.getItem(); if (item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.air) { Block block = Block.getBlockFromItem(item); if (block == Blocks.wooden_slab) { return 150; } if (block.getMaterial() == Material.wood) { return 300; } if (block == Blocks.coal_block) { return 16000; } } return item instanceof ItemTool && ((ItemTool)item).getToolMaterialName().equals("WOOD") ? 200 : (item instanceof ItemSword && ((ItemSword)item).getToolMaterialName().equals("WOOD") ? 200 : (item instanceof ItemHoe && ((ItemHoe)item).getMaterialName().equals("WOOD") ? 200 : (item == Items.stick ? 100 : (item == Items.coal ? 1600 : (item == Items.lava_bucket ? 20000 : (item == Item.getItemFromBlock(Blocks.sapling) ? 100 : (item == Items.blaze_rod ? 2400 : 0))))))); } }
@SubscribeEvent public static void init(RegistryEvent.Register<Item> event) { IForgeRegistry<Item> registry = event.getRegistry(); registerModule(registry, ModuleSafetyValve.class); registerModule(registry, ModulePressureGauge.class); registerModule(registry, ModuleFlowDetector.class); registerModule(registry, ModuleAirGrate.class); registerModule(registry, ModuleRegulatorTube.class); registerModule(registry, ModuleCharging.class); registerModule(registry, ModuleLogistics.class); }
public Item getItem(World worldIn, BlockPos pos) { return Item.getItemFromBlock(Blocks.stone_slab); }
protected ItemStack createStackedBlock(IBlockState state) { return new ItemStack(Item.getItemFromBlock(this), 1, ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata() - 4); }
@Override public Item getTabIconItem() { return new ItemStack(ModBlocks.TEMP_REGULATOR).getItem(); }
protected ItemStack createStackedBlock(IBlockState state) { return new ItemStack(Item.getItemFromBlock(this), 1, ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata()); }