mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-03 23:17:48 +01:00
Allow null nbt, remove NBTUtils.loadItem
This commit is contained in:
parent
cb34d34799
commit
6b5f755bfd
@ -61,15 +61,17 @@ public final class ItemStack implements HoverEventSource<HoverEvent.ShowItem> {
|
||||
}
|
||||
|
||||
@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 -> ItemMetaBuilder.fromNBT(metaBuilder, nbtCompound))
|
||||
.build();
|
||||
public static @NotNull ItemStack fromNBT(@NotNull Material material, @Nullable NBTCompound nbtCompound, int amount) {
|
||||
var itemBuilder = ItemStack.builder(material)
|
||||
.amount(amount);
|
||||
if (nbtCompound != null) {
|
||||
itemBuilder.meta(metaBuilder -> ItemMetaBuilder.fromNBT(metaBuilder, nbtCompound));
|
||||
}
|
||||
return itemBuilder.build();
|
||||
}
|
||||
|
||||
@Contract(value = "_, _ -> new", pure = true)
|
||||
public static @NotNull ItemStack fromNBT(@NotNull Material material, @NotNull NBTCompound nbtCompound) {
|
||||
public static @NotNull ItemStack fromNBT(@NotNull Material material, @Nullable NBTCompound nbtCompound) {
|
||||
return fromNBT(material, nbtCompound, 1);
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,6 @@ import net.minestom.server.item.ItemMetaBuilder;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.item.Material;
|
||||
import net.minestom.server.registry.Registries;
|
||||
import net.minestom.server.utils.NBTUtils;
|
||||
import net.minestom.server.utils.validate.Check;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||
@ -156,8 +155,7 @@ public class CrossbowMeta extends ItemMeta implements ItemMetaBuilder.Provider<S
|
||||
final Material material = Registries.getMaterial(id);
|
||||
|
||||
final NBTCompound tagsCompound = projectileCompound.getCompound("tag");
|
||||
|
||||
ItemStack itemStack = NBTUtils.loadItem(material, count, tagsCompound);
|
||||
ItemStack itemStack = ItemStack.fromNBT(material, tagsCompound, count);
|
||||
|
||||
projectiles.add(itemStack);
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ public final class NBTUtils {
|
||||
if (tag.containsKey("tag")) {
|
||||
nbtCompound = tag.getCompound("tag");
|
||||
}
|
||||
ItemStack itemStack = loadItem(material, count, nbtCompound);
|
||||
ItemStack itemStack = ItemStack.fromNBT(material, nbtCompound, count);
|
||||
destination.setItemStack(tag.getByte("Slot"), itemStack);
|
||||
}
|
||||
}
|
||||
@ -138,20 +138,7 @@ public final class NBTUtils {
|
||||
MinecraftServer.getExceptionManager().handleException(e);
|
||||
}
|
||||
|
||||
return loadItem(material, count, nbtCompound);
|
||||
}
|
||||
|
||||
public static @NotNull ItemStack loadItem(@NotNull Material material, int count, @Nullable NBTCompound nbtCompound) {
|
||||
return ItemStack.builder(material)
|
||||
.amount(count)
|
||||
.meta(metaBuilder -> {
|
||||
if (nbtCompound != null) {
|
||||
return ItemMetaBuilder.fromNBT(metaBuilder, nbtCompound);
|
||||
} else {
|
||||
return metaBuilder;
|
||||
}
|
||||
})
|
||||
.build();
|
||||
return ItemStack.fromNBT(material, nbtCompound, count);
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
|
Loading…
Reference in New Issue
Block a user