mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-12 02:11:36 +01:00
Added ItemStack#fromNBT
This commit is contained in:
parent
32430882a5
commit
2b74d7697c
@ -8,6 +8,7 @@ import net.minestom.server.utils.NBTUtils;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
@ -55,6 +56,22 @@ public final class ItemStack implements HoverEventSource<HoverEvent.ShowItem> {
|
||||
return of(material, 1);
|
||||
}
|
||||
|
||||
@Contract(value = "_, _, _ -> new", pure = true)
|
||||
public static @NotNull ItemStack fromNBT(@NotNull Material material, @NotNull NBTCompound nbtCompound, int amount) {
|
||||
return ItemStack.builder(material)
|
||||
.amount(amount)
|
||||
.meta(metaBuilder -> {
|
||||
metaBuilder.nbt = nbtCompound.deepClone();
|
||||
NBTUtils.loadDataIntoMeta(metaBuilder, nbtCompound);
|
||||
return metaBuilder;
|
||||
}).build();
|
||||
}
|
||||
|
||||
@Contract(value = "_, _ -> new", pure = true)
|
||||
public static @NotNull ItemStack fromNBT(@NotNull Material material, @NotNull NBTCompound nbtCompound) {
|
||||
return fromNBT(material, nbtCompound, 1);
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
public @NotNull Material getMaterial() {
|
||||
return material;
|
||||
|
Loading…
Reference in New Issue
Block a user