-
Notifications
You must be signed in to change notification settings - Fork 2
Introduction
CraftingLib is a versatile Java library designed to simplify crafting-related functionalities in Minecraft plugins. Whether you're working on a new plugin or enhancing an existing one, CraftingLib provides a set of tools to streamline the crafting process. This wiki guide will walk you through the installation process, getting started with the library, and showcase a practical example from the /example/ module.
CraftingLib can be easily integrated into your project using either Gradle or Maven.
Add the following dependency to your project's build.gradle file:
repositories {
maven("https://repo.eternalcode.pl/releases")
}
dependencies {
implementation 'dev.piotrulla:craftinglib:VERSION'
}
Make sure to replace "VERSION" with the latest release version. You can find the latest version here.
Add the following dependency to your project's pom.xml file:
<repository>
<id>eternalcode-reposilite-releases</id>
<name>EternalCode Repository</name>
<url>https://repo.eternalcode.pl/releases</url>
</repository>
<dependency>
<groupId>dev.piotrulla</groupId>
<artifactId>craftinglib</artifactId>
<version>VERSION</version>
</dependency>
Make sure to replace "VERSION" with the latest release version. You can find the latest version here.
After adding CraftingLib to your project, create a new instance of the CraftingLib class, passing the plugin instance as a parameter:
CraftingLib craftingLib = new CraftingLib(plugin);
Next, obtain the CraftingManager instance from CraftingLib:
CraftingManager craftingManager = craftingLib.getCraftingManager();
Now, you are ready to create custom crafting recipes using the Crafting builder. The provided example demonstrates creating crafting recipe:
CraftingManager craftingManager = [..]
String pickaxeName = "super-pickaxe";
Crafting pickaxeCrafting = Crafting.builder()
.withMaterial(1, Material.DIAMOND_BLOCK, 3)
.withMaterial(2, Material.DIAMOND_BLOCK, 3)
.withMaterial(3, Material.DIAMOND_BLOCK, 3)
.withMaterial(5, Material.STICK)
.withMaterial(8, Material.STICK)
.withName(pickaxeName)
.withResultItem(createPickaxe())
.build();
craftingManager.createCrafting(pickaxeName, pickaxeCrafting);
private ItemStack createPickaxe() {
ItemStack pickaxe = new ItemStack(Material.DIAMOND_PICKAXE);
ItemMeta itemMeta = pickaxe.getItemMeta();
itemMeta.addEnchant(Enchantment.DIG_SPEED, 6, true);
itemMeta.addEnchant(Enchantment.DURABILITY, 4, true);
itemMeta.addEnchant(Enchantment.LOOT_BONUS_BLOCKS, 4, true);
itemMeta.setDisplayName(this.color("&6&lSuper Pickaxe"));
itemMeta.setLore(Collections.singletonList(this.color("&cThis pickaxe is super fast!")));
pickaxe.setItemMeta(itemMeta);
return pickaxe;
}
private String color(String toColor) {
return ChatColor.translateAlternateColorCodes('&', toColor);
}
CraftingManager craftingManager = [..]
Crafting pickaxe = [..]
craftingManager.removeCrafting(pickaxe);
ItemStack goldenApple = new ItemStack(Material.GOLDEN_APPLE);
CraftingUtil.removeRecipe(goldenApple);
Feel free to adapt and modify the example code to suit your plugin's needs. The provided createPickaxe method demonstrates creating a custom ItemStack with enchantments and lore.
Now, you have successfully set up CraftingLib and created custom crafting recipes for your Minecraft plugin. Happy crafting!
Are you having problems with lib? Join our discord: EternalCode.pl Discord