Home > Articles > Home & Office Computing > Entertainment/Gaming/Gadgets

  • Print
  • + Share This
This chapter is from the book

Using Special ItemStacks

It is possible to use a special ItemStack in a recipe. To do that, you first have to create an ItemStack object and then use that in the recipe. Following is an example that creates a stone sword with sharpness 1 from a stone sword and a flint. This code uses a new file, so be sure to import it.

ItemStack enchantedSwordItemStack = new ItemStack(Items.stone_sword);
enchantedSwordItemStack.addEnchantment(Enchantment.sharpness, 1);

       Items.flint, Items.stone_sword

This code first creates an object of a normal stone sword. It then adds the sharpness enchantment of level 1 to it. Next, a shapeless recipe is added with the enchanted stone sword as the resulting item. The sword is crafted using a flint and a normal stone sword.

Figure 3.5 displays this recipe in game.


FIGURE 3.5 An enchantment recipe.

  • + Share This
  • 🔖 Save To Your Account