Skip to content

Introduction

Piotr Zych edited this page Jan 9, 2024 · 4 revisions

CraftingLib

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.

Installation

CraftingLib can be easily integrated into your project using either Gradle or Maven.

Gradle

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.

Maven

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.

Getting Started

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:

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);

Removing Recipe in run-time without reloading server

CraftingManager craftingManager = [..]

Crafting pickaxe = [..]
craftingManager.removeCrafting(pickaxe);

Removing built-in recipes on bukkit server

ItemStack goldenApple = new ItemStack(Material.GOLDEN_APPLE);

CraftingUtil.removeRecipe(goldenApple);

Outro

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

Clone this wiki locally