Skip to content

Commit

Permalink
Add StackResolver for backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Intybyte committed Sep 25, 2024
1 parent 6772c5d commit b75158a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ public enum MinecraftVersion {
*/
MINECRAFT_1_20_5(20, 5, "1.20.5+"),

/**
* This constant represents Minecraft (Java Edition) Version 1.21
* ("Tricky Trials")
*/
MINECRAFT_1_21(21, 0, "1.21+"),

/**
* This constant represents an exceptional state in which we were unable
* to identify the Minecraft Version we are using
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.github.thebusybiscuit.slimefun4.utils.multiversion;

import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;

/**
* This utility class provides backwards compatibility to versions of minecraft
* regarding the creation of ItemStacks.
*
* @author Vaan1310
*/
public final class StackResolver {

private StackResolver() {}

public static ItemStack of(Material material) {
return of(material, 1);
}

public static ItemStack of(Material material, int amount) {
var version = Slimefun.getMinecraftVersion();

if (version.isAtLeast(MinecraftVersion.MINECRAFT_1_21)) {
return ItemStack.of(material, amount);
} else {
return new ItemStack(material, amount);
}
}
}

0 comments on commit b75158a

Please sign in to comment.