This commit is contained in:
TheMode 2021-06-28 23:31:01 +02:00
parent 790e99bce3
commit 5dfecce5d5

View File

@ -112,7 +112,7 @@ public abstract class ItemMetaBuilder implements TagWritable {
@Contract("_, _ -> this") @Contract("_, _ -> this")
public @NotNull ItemMetaBuilder enchantment(@NotNull Enchantment enchantment, short level) { public @NotNull ItemMetaBuilder enchantment(@NotNull Enchantment enchantment, short level) {
this.enchantmentMap = Map.of(enchantment, level); this.enchantmentMap.put(enchantment, level);
enchantments(enchantmentMap); enchantments(enchantmentMap);
return this; return this;
} }
@ -251,53 +251,38 @@ public abstract class ItemMetaBuilder implements TagWritable {
protected void handleNullable(@Nullable Object value, protected void handleNullable(@Nullable Object value,
@NotNull String key, @NotNull String key,
@NotNull NBTCompound nbtCompound,
@NotNull Supplier<@NotNull NBT> supplier) { @NotNull Supplier<@NotNull NBT> supplier) {
mutateNbt(compound -> {
if (value != null) { if (value != null) {
nbtCompound.set(key, supplier.get()); compound.set(key, supplier.get());
} else { } else {
nbtCompound.removeTag(key); compound.removeTag(key);
}
}
protected void handleNullable(@Nullable Object value,
@NotNull String key,
@NotNull Supplier<@NotNull NBT> supplier) {
mutateNbt(compound -> handleNullable(value, key, compound, supplier));
}
protected void handleCollection(@NotNull Collection<?> objects,
@NotNull String key,
@NotNull NBTCompound nbtCompound,
@NotNull Supplier<@NotNull NBT> supplier) {
if (!objects.isEmpty()) {
nbtCompound.set(key, supplier.get());
} else {
nbtCompound.removeTag(key);
} }
});
} }
protected void handleCollection(@NotNull Collection<?> objects, protected void handleCollection(@NotNull Collection<?> objects,
@NotNull String key, @NotNull String key,
@NotNull Supplier<@NotNull NBT> supplier) { @NotNull Supplier<@NotNull NBT> supplier) {
mutateNbt(compound -> handleCollection(objects, key, compound, supplier)); mutateNbt(compound -> {
}
protected void handleMap(@NotNull Map<?, ?> objects,
@NotNull String key,
@NotNull NBTCompound nbtCompound,
@NotNull Supplier<@NotNull NBT> supplier) {
if (!objects.isEmpty()) { if (!objects.isEmpty()) {
nbtCompound.set(key, supplier.get()); compound.set(key, supplier.get());
} else { } else {
nbtCompound.removeTag(key); compound.removeTag(key);
} }
});
} }
protected void handleMap(@NotNull Map<?, ?> objects, protected void handleMap(@NotNull Map<?, ?> objects,
@NotNull String key, @NotNull String key,
@NotNull Supplier<@NotNull NBT> supplier) { @NotNull Supplier<@NotNull NBT> supplier) {
mutateNbt(compound -> handleMap(objects, key, compound, supplier)); mutateNbt(compound -> {
if (!objects.isEmpty()) {
compound.set(key, supplier.get());
} else {
compound.removeTag(key);
}
});
} }
@Contract(value = "_, _ -> new", pure = true) @Contract(value = "_, _ -> new", pure = true)