public static ItemStack buildEnchantedBook(Enchantment ench, short level) { ItemStack stack = new ItemStack(Items.ENCHANTED_BOOK); //NOT THIS: if you are putting it on a normal stack (sword/weapon) yeah then that way // stack.addEnchantment(ench, level); ItemEnchantedBook.addEnchantment(stack, new EnchantmentData(ench, level)); //just to test it return stack; }
/** * Give maxed-out enchantments books from the enchantments list. * Used by battlegear creative tab for its display list * * @return list containing the enchantment books */ public Collection<ItemStack> getEnchantmentBooks() { Collection<ItemStack> list = new ArrayList<ItemStack>(enchants.size()); for(Enchantment enchantment:enchants){ list.add(Items.ENCHANTED_BOOK.getEnchantedItemStack(new EnchantmentData(enchantment, enchantment.getMaxLevel()))); } return list; }
public void onWanded(EntityPlayer player, ItemStack wand) { if(stage != State.IDLE || itemToEnchant.isEmpty() || !itemToEnchant.isItemEnchantable()) return; List<EntityItem> items = world.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(pos.getX() - 2, pos.getY(), pos.getZ() - 2, pos.getX() + 3, pos.getY() + 1, pos.getZ() + 3)); int count = items.size(); if(count > 0 && !world.isRemote) { for(EntityItem entity : items) { ItemStack item = entity.getItem(); if(item.getItem() == Items.ENCHANTED_BOOK) { NBTTagList enchants = ItemEnchantedBook.getEnchantments(item); if(enchants.tagCount() > 0) { NBTTagCompound enchant = enchants.getCompoundTagAt(0); short id = enchant.getShort("id"); if(isEnchantmentValid(Enchantment.getEnchantmentByID(id))) { advanceStage(); return; } } } } } }
private ItemStack extractEnchantFromItem(final ItemStack item) { final Map<Enchantment, Integer> enchants = EnchantmentHelper.getEnchantments(item); final ItemStack books = new ItemStack(Items.ENCHANTED_BOOK); for (final Map.Entry<Enchantment, Integer> entry : enchants.entrySet()) { ItemEnchantedBook.addEnchantment(books, new EnchantmentData(entry.getKey(), entry.getValue())); } worker.decreaseSaturationForAction(); return books; } }
ItemStack item = entity.getItem(); if(item.getItem() == Items.ENCHANTED_BOOK) { NBTTagList enchants = ItemEnchantedBook.getEnchantments(item); if(enchants.tagCount() > 0) { NBTTagCompound enchant = enchants.getCompoundTagAt(0);
private void setResultingEnchantmentBook(TilePurifier tile, Map<Enchantment, Integer> enchantments, Enchantment enchantment) { tile.setAdditionalItem(ItemEnchantedBook.getEnchantedItemStack( new EnchantmentData(enchantment, enchantments.get(enchantment)))); }
private void handleTome(ItemStack book, ItemStack tome, AnvilUpdateEvent event) { Map<Enchantment, Integer> enchantsBook = EnchantmentHelper.getEnchantments(book); Map<Enchantment, Integer> enchantsTome = EnchantmentHelper.getEnchantments(tome); for (Map.Entry<Enchantment, Integer> entry : enchantsTome.entrySet()) { if(enchantsBook.getOrDefault(entry.getKey(), 0).equals(entry.getValue())){ enchantsBook.put(entry.getKey(), entry.getValue() + 1); } else { return; } } ItemStack output = ProxyRegistry.newStack(Items.ENCHANTED_BOOK); for (Map.Entry<Enchantment, Integer> entry : enchantsBook.entrySet()) { ItemEnchantedBook.addEnchantment(output, new EnchantmentData(entry.getKey(), entry.getValue())); } event.setOutput(output); event.setCost(mergeTomeCost); }
@Override public boolean apply(@Nullable ItemStack target) { if (target == null || target.isEmpty()) return false; NBTTagList enchantments = target.getItem() == Items.ENCHANTED_BOOK ? ItemEnchantedBook.getEnchantments(target) : target.getEnchantmentTagList(); for (int i = 0; i < enchantments.tagCount(); ++i) { NBTTagCompound tag = enchantments.getCompoundTagAt(i); Enchantment itemEnchant = Enchantment.getEnchantmentByID(tag.getShort("id")); if (itemEnchant == enchantment) return (int) tag.getShort("lvl") >= minLevel; } return false; }
public ItemStack getEnchantedBook(EnchantmentData enchantmentData) { Enchantment enchantment = enchantmentData.enchantment; ResourceLocation registryName = enchantment.getRegistryName(); if (registryName == null) { throw new IllegalArgumentException("Enchantment has no registry name: " + enchantment.getName()); } return cache.computeIfAbsent(registryName, enchantmentData.enchantmentLevel, () -> ItemEnchantedBook.getEnchantedItemStack(enchantmentData)); }
@Override @Nonnull public ResultStack[] getCompletedResult(long nextSeed, float chanceMultiplier, @Nonnull NNList<MachineRecipeInput> inputs) { ItemStack slot1 = MachineRecipeInput.getInputForSlot(1, inputs); int level = getLevelForStackSize(slot1.getCount()); EnchantmentData enchantmentData = new EnchantmentData(enchantment, level); ItemStack output = new ItemStack(Items.ENCHANTED_BOOK); ItemEnchantedBook.addEnchantment(output, enchantmentData); return new ResultStack[] { new ResultStack(output) }; }
NBTTagList enchants = ItemEnchantedBook.getEnchantments(stack); for(int i = 0; i < enchants.tagCount(); i++) { NBTTagCompound cmp = enchants.getCompoundTagAt(i);
public static void addAllBooks(Enchantment enchantment, List<ItemStack> items) { for (int i = enchantment.getMinLevel(); i <= enchantment.getMaxLevel(); i++) items.add(ItemEnchantedBook.getEnchantedItemStack(new EnchantmentData(enchantment, i))); } }
@Override @Nonnull public ItemStack getInventorySlotContents(int slot) { if (slot < enchantments.size()) { EnchantmentData enchantmentData = new EnchantmentData(enchantments.get(slot), 1); ItemStack output = new ItemStack(Items.ENCHANTED_BOOK); ItemEnchantedBook.addEnchantment(output, enchantmentData); return output; } return Prep.getEmpty(); }
@Override public boolean matches(InventoryCrafting inv, World world) { if (super.matches(inv, world)) { NBTTagList enchantments = ItemEnchantedBook.getEnchantments(inv.getStackInSlot(1)); for (int i = 0; i < enchantments.tagCount(); ++i) { NBTTagCompound enchantmentNbt = enchantments.getCompoundTagAt(i); // @Volatile: NBT tags from ItemEnchantedBook if (Enchantment.getEnchantmentByID(enchantmentNbt.getShort("id")) == enchant.enchantment && enchantmentNbt.getShort("lvl") == enchant.enchantmentLevel) { return true; } } } return false; } }
public static void addDefaultEnchantmentRecipe(ItemStack input, String enchantName, int tier) { if (tier < 0 || tier > 4) { return; } Enchantment enchant = Enchantment.getEnchantmentByLocation(enchantName); if (enchant == null) { return; } addRecipe(DEFAULT_ENERGY[tier], ITEM_BOOK, input, ItemEnchantedBook.getEnchantedItemStack(new EnchantmentData(enchant, 1)), DEFAULT_EXPERIENCE[tier], Type.STANDARD); // if (enchant.getMaxLevel() > 1) { // addRecipe(DEFAULT_ENERGY[Math.min(tier + 1, 4)] * 3, ITEM_BOOK2, input, ItemEnchantedBook.getEnchantedItemStack(new EnchantmentData(enchant, enchant.getMaxLevel())), DEFAULT_EXPERIENCE[Math.min(tier + 1, 4)], Type.EMPOWERED); // } }
@Override protected void dropFewItems(boolean wasRecentlyHit, int lootingModifier) { if (wasRecentlyHit) { if ((rand.nextInt(4) == 0 || rand.nextInt(1 + lootingModifier) > 0)) { dropItem(GaiaItems.MISC_SOUL_FIRE, 1); } // Nuggets/Fragments int dropNugget = rand.nextInt(3) + 1; for (int i = 0; i < dropNugget; ++i) { dropItem(Items.IRON_NUGGET, 1); } if (GaiaConfig.OPTIONS.additionalOre) { int dropNuggetAlt = rand.nextInt(3) + 1; for (int i = 0; i < dropNuggetAlt; ++i) { ItemShard.dropNugget(this, 4); } } // Rare if ((rand.nextInt(EntityAttributes.RATE_RARE_DROP) == 0)) { dropItem(GaiaItems.BOX_IRON, 1); } // Unique Rare if ((rand.nextInt(EntityAttributes.RATE_UNIQUE_RARE_DROP) == 0)) { ItemStack enchantmentBook = new ItemStack(Items.ENCHANTED_BOOK); ItemEnchantedBook.addEnchantment(enchantmentBook, new EnchantmentData(Enchantments.SHARPNESS, 1)); this.entityDropItem(enchantmentBook, 1); } } }
subtypeRegistry.registerSubtypeInterpreter(Items.ENCHANTED_BOOK, itemStack -> { List<String> enchantmentNames = new ArrayList<>(); NBTTagList enchantments = ItemEnchantedBook.getEnchantments(itemStack); for (NBTBase nbt : enchantments) { if (nbt instanceof NBTTagCompound) {
public static void refresh() { Map<List<ComparableItemStackValidatedNBT>, EnchanterRecipe> tempMap = new Object2ObjectOpenHashMap<>(recipeMap.size()); Set<ComparableItemStackValidatedNBT> tempSet = new ObjectOpenHashSet<>(); EnchanterRecipe tempRecipe; for (Entry<List<ComparableItemStackValidatedNBT>, EnchanterRecipe> entry : recipeMap.entrySet()) { tempRecipe = entry.getValue(); ComparableItemStackValidatedNBT primary = convertInput(tempRecipe.primaryInput); ComparableItemStackValidatedNBT secondary = convertInput(tempRecipe.secondaryInput); if (!tempRecipe.enchantName.isEmpty() && tempRecipe.output.getItem() == Items.ENCHANTED_BOOK) { Enchantment enchant = Enchantment.getEnchantmentByLocation(tempRecipe.enchantName); if (enchant != null) { tempRecipe = new EnchanterRecipe(tempRecipe.primaryInput, tempRecipe.secondaryInput, ItemEnchantedBook.getEnchantedItemStack(new EnchantmentData(enchant, 1)), tempRecipe.experience, tempRecipe.energy, tempRecipe.type); } } tempMap.put(asList(primary, secondary), tempRecipe); tempSet.add(primary); tempSet.add(secondary); } recipeMap.clear(); recipeMap = tempMap; validationSet.clear(); validationSet = tempSet; Set<ComparableItemStackValidatedNBT> tempSet2 = new ObjectOpenHashSet<>(); for (ComparableItemStackValidatedNBT entry : lockSet) { ComparableItemStackValidatedNBT lock = convertInput(new ItemStack(entry.item, entry.stackSize, entry.metadata)); tempSet2.add(lock); } lockSet.clear(); lockSet = tempSet2; }
@Override protected void dropFewItems(boolean wasRecentlyHit, int lootingModifier) { if (wasRecentlyHit) { if ((rand.nextInt(2) == 0 || rand.nextInt(1 + lootingModifier) > 0)) { dropItem(GaiaItems.MISC_FUR, 1); } // Nuggets/Fragments int dropNugget = rand.nextInt(3) + 1; for (int i = 0; i < dropNugget; ++i) { dropItem(Items.IRON_NUGGET, 1); } if (GaiaConfig.OPTIONS.additionalOre) { int dropNuggetAlt = rand.nextInt(3) + 1; for (int i = 0; i < dropNuggetAlt; ++i) { ItemShard.dropNugget(this, 4); } } // Rare if ((rand.nextInt(EntityAttributes.RATE_RARE_DROP) == 0)) { dropItem(GaiaItems.BOX_IRON, 1); } // Unique Rare if ((rand.nextInt(EntityAttributes.RATE_UNIQUE_RARE_DROP) == 0)) { ItemStack enchantmentBook = new ItemStack(Items.ENCHANTED_BOOK); ItemEnchantedBook.addEnchantment(enchantmentBook, new EnchantmentData(Enchantments.SHARPNESS, 1)); this.entityDropItem(enchantmentBook, 1); } } }
flag = itemstack2.getItem() == Items.ENCHANTED_BOOK && !ItemEnchantedBook.getEnchantments(itemstack2).hasNoTags();