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