mirror of
https://github.com/Minestom/Minestom.git
synced 2024-09-24 20:42:39 +02:00
Simplify enchant nbt creation
This commit is contained in:
parent
f1112fc865
commit
6e2cfa8b2e
@ -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);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user