This tutorial introduces the core concepts of the Allay Items API and shows practical ways to find item types, work
with item stacks, enchantments, and item data.
// Create a stack of 64 diamondsItemStackdiamonds=ItemTypes.DIAMOND.createItemStack(64);// Get item informationintcount=diamonds.getCount();ItemType<?>type=diamonds.getItemType();
ItemType<?>diamondType=ItemTypes.DIAMOND;ItemType<?>swordType=ItemTypes.DIAMOND_SWORD;// Create an item stack from the typeItemStackstack=diamondType.createItemStack(32);
ItemDatadata=ItemTypes.DIAMOND_SWORD.getItemData();intmaxDamage=data.maxDamage();// DurabilityintattackDamage=data.attackDamage();// Base attack damageintmaxStack=data.maxStackSize();// Usually 1 for tools
// Check if an item type has a specific tagbooleanisSword=ItemTypes.DIAMOND_SWORD.hasItemTag(ItemTags.IS_SWORD);booleanisFood=ItemTypes.APPLE.hasItemTag(ItemTags.IS_FOOD);booleanisDiamondTier=ItemTypes.DIAMOND_PICKAXE.hasItemTag(ItemTags.DIAMOND_TIER);
importorg.allaymc.api.item.type.ItemType;importorg.allaymc.api.registry.Registries;importorg.allaymc.api.utils.identifier.Identifier;// Look up by identifierIdentifierid=newIdentifier("minecraft:diamond");ItemType<?>diamond=Registries.ITEM_TYPE.get(id);// may be null if not found// Or use string directlyItemType<?>sword=Registries.ITEM_TYPE.get(newIdentifier("minecraft:diamond_sword"));
importorg.allaymc.api.item.type.ItemTypes;importorg.allaymc.api.item.ItemStack;// Create a single itemItemStackoneApple=ItemTypes.APPLE.createItemStack();// Create a stack with specific countItemStackdiamonds=ItemTypes.DIAMOND.createItemStack(64);// Create with count and meta (damage value)ItemStackcoloredWool=ItemTypes.WOOL.createItemStack(32,14);// Red wool
importorg.allaymc.api.item.ItemStack;importorg.allaymc.api.item.type.ItemTypes;ItemStackstack=ItemTypes.DIAMOND.createItemStack(32);// Get countintcount=stack.getCount();// Set countstack.setCount(64);// Reduce countstack.reduceCount(10);// Now 54// Increase countstack.increaseCount(5);// Now 59// Check if stack is fullbooleanisFull=stack.isFull();// Check if empty or airbooleanisEmpty=stack.isEmptyOrAir();
importorg.allaymc.api.item.ItemStack;importorg.allaymc.api.item.type.ItemTypes;importjava.util.List;ItemStacksword=ItemTypes.DIAMOND_SWORD.createItemStack();// Set custom namesword.setCustomName("§6Excalibur");// Get custom nameStringname=sword.getCustomName();// Set lore (description lines)sword.setLore(List.of("§7A legendary sword","§7forged in ancient times","§c+10 Attack Damage"));// Get loreList<String>lore=sword.getLore();
importorg.allaymc.api.item.ItemStack;importorg.allaymc.api.item.type.ItemTypes;ItemStackpickaxe=ItemTypes.DIAMOND_PICKAXE.createItemStack();// Get max durabilityintmaxDurability=pickaxe.getMaxDamage();// Get current damage (higher = more damaged)intcurrentDamage=pickaxe.getDamage();// Set damagepickaxe.setDamage(100);// Check if brokenbooleanisBroken=pickaxe.isBroken();// Try to increase damage (respects Unbreaking enchantment)booleandamaged=pickaxe.tryIncreaseDamage(1);
importorg.allaymc.api.item.ItemStack;importorg.allaymc.api.item.type.ItemTypes;ItemStackoriginal=ItemTypes.DIAMOND_SWORD.createItemStack();original.setCustomName("Original");// Copy the item (with new network ID)ItemStackcopy=original.copy();// Copy without new network IDItemStackexactCopy=original.copy(false);
importorg.allaymc.api.item.ItemStack;importorg.allaymc.api.item.type.ItemTypes;importorg.allaymc.api.item.enchantment.EnchantmentTypes;ItemStacksword=ItemTypes.DIAMOND_SWORD.createItemStack();// Add a single enchantmentsword.addEnchantment(EnchantmentTypes.SHARPNESS,5);sword.addEnchantment(EnchantmentTypes.UNBREAKING,3);sword.addEnchantment(EnchantmentTypes.FIRE_ASPECT,2);
importorg.allaymc.api.item.ItemStack;importorg.allaymc.api.item.enchantment.EnchantmentTypes;importorg.allaymc.api.item.enchantment.EnchantmentInstance;// Check if item has any enchantmentsbooleanhasEnchants=sword.hasEnchantments();// Check for specific enchantmentbooleanhasSharpness=sword.hasEnchantment(EnchantmentTypes.SHARPNESS);// Get enchantment level (0 if not present)intsharpnessLevel=sword.getEnchantmentLevel(EnchantmentTypes.SHARPNESS);// Get all enchantmentsCollection<EnchantmentInstance>enchants=sword.getEnchantments();for(EnchantmentInstanceenchant:enchants){System.out.println(enchant.getType().getIdentifier()+" Level "+enchant.getLevel());}
importorg.allaymc.api.item.enchantment.EnchantmentTypes;importorg.allaymc.api.item.enchantment.EnchantmentInstance;// Remove specific enchantmentEnchantmentInstanceremoved=sword.removeEnchantment(EnchantmentTypes.FIRE_ASPECT);// Remove all enchantmentssword.removeAllEnchantments();
importorg.allaymc.api.item.enchantment.EnchantmentTypes;importorg.allaymc.api.item.enchantment.EnchantmentType;importjava.util.Set;// Check if an enchantment is compatible with existing enchantmentsbooleancompatible=sword.checkEnchantmentCompatibility(EnchantmentTypes.SMITE);// Get incompatible enchantmentsSet<EnchantmentType>incompatible=sword.getIncompatibleEnchantmentTypes(EnchantmentTypes.SMITE);// Smite is incompatible with Sharpness and Bane of Arthropods
importorg.allaymc.api.item.ItemStack;importorg.allaymc.api.item.type.ItemTypes;importorg.allaymc.api.block.type.BlockType;importorg.allaymc.api.block.state.BlockState;// Get the block type associated with an itemBlockType<?>blockType=ItemTypes.STONE.getBlockType();// Convert an item stack to a block stateItemStackstoneItem=ItemTypes.STONE.createItemStack();BlockStatestoneBlock=stoneItem.toBlockState();
importorg.allaymc.api.item.ItemStack;importorg.allaymc.api.item.type.ItemTypes;importorg.allaymc.api.item.enchantment.EnchantmentTypes;importorg.allaymc.api.entity.interfaces.EntityPlayer;publicvoidgiveEnchantedSword(EntityPlayerplayer){// Create a diamond swordItemStacksword=ItemTypes.DIAMOND_SWORD.createItemStack();// Customize itsword.setCustomName("§6Dragon Slayer");sword.setLore(List.of("§7A blade forged to slay dragons"));sword.addEnchantment(EnchantmentTypes.SHARPNESS,5);sword.addEnchantment(EnchantmentTypes.UNBREAKING,3);sword.addEnchantment(EnchantmentTypes.FIRE_ASPECT,2);// Give to player (if inventory is full, item will be dropped)player.tryAddItem(sword);}