Simplify enchant nbt creation

This commit is contained in:
themode 2021-12-19 18:59:38 +01:00 committed by TheMode
parent f1112fc865
commit 6e2cfa8b2e

View File

@ -99,11 +99,8 @@ public abstract class ItemMetaBuilder implements TagWritable {
@Contract("_ -> this") @Contract("_ -> this")
public @NotNull ItemMetaBuilder enchantments(@NotNull Map<Enchantment, Short> enchantments) { public @NotNull ItemMetaBuilder enchantments(@NotNull Map<Enchantment, Short> enchantments) {
this.enchantmentMap = new HashMap<>(enchantments); this.enchantmentMap = new HashMap<>(enchantments);
handleMap(enchantmentMap, "Enchantments", () -> { handleMap(enchantmentMap, "Enchantments",
MutableNBTCompound mutableCopy = nbt.toMutableCompound(); (nbt) -> NBTUtils.writeEnchant(nbt, "Enchantments", enchantmentMap));
NBTUtils.writeEnchant(mutableCopy, "Enchantments", enchantmentMap);
return mutableCopy.get("Enchantments");
});
return this; return this;
} }
@ -248,10 +245,10 @@ public abstract class ItemMetaBuilder implements TagWritable {
protected void handleMap(@NotNull Map<?, ?> objects, protected void handleMap(@NotNull Map<?, ?> objects,
@NotNull String key, @NotNull String key,
@NotNull Supplier<@NotNull NBT> supplier) { @NotNull Consumer<MutableNBTCompound> consumer) {
mutateNbt(compound -> { mutateNbt(compound -> {
if (!objects.isEmpty()) { if (!objects.isEmpty()) {
compound.set(key, supplier.get()); consumer.accept(compound);
} else { } else {
compound.remove(key); compound.remove(key);
} }