Added ItemStack#fromNBT

This commit is contained in:
TheMode 2021-04-13 03:27:51 +02:00
parent 32430882a5
commit 2b74d7697c

View File

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