Simplify synchronization

This commit is contained in:
TheMode 2021-06-28 23:27:12 +02:00
parent 018a9263ee
commit 790e99bce3

View File

@ -204,16 +204,14 @@ public abstract class ItemMetaBuilder implements TagWritable {
protected abstract @NotNull Supplier<@NotNull ItemMetaBuilder> getSupplier(); protected abstract @NotNull Supplier<@NotNull ItemMetaBuilder> getSupplier();
protected void mutateNbt(Consumer<NBTCompound> consumer) { protected synchronized void mutateNbt(Consumer<NBTCompound> consumer) {
if (built) { if (built) {
built = false; built = false;
final var currentNbt = nbt; final var currentNbt = nbt;
NBT_UPDATER.compareAndSet(this, currentNbt, currentNbt.deepClone()); NBT_UPDATER.compareAndSet(this, currentNbt, currentNbt.deepClone());
} }
synchronized (this) {
consumer.accept(nbt); consumer.accept(nbt);
} }
}
protected synchronized NBTCompound nbt() { protected synchronized NBTCompound nbt() {
return nbt; return nbt;