Clone instead of caching

This commit is contained in:
TheMode 2021-04-10 00:25:50 +02:00
parent 5e8e7cbaf4
commit f5b8f267d6

View File

@ -7,7 +7,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jglrxavpok.hephaistos.nbt.NBTCompound; import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import java.lang.ref.SoftReference;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -29,8 +28,6 @@ public class ItemMeta {
private final NBTCompound nbt; private final NBTCompound nbt;
private final ItemMetaBuilder emptyBuilder; private final ItemMetaBuilder emptyBuilder;
private SoftReference<NBTCompound> nbtCache;
protected ItemMeta(@NotNull ItemMetaBuilder metaBuilder) { protected ItemMeta(@NotNull ItemMetaBuilder metaBuilder) {
this.damage = metaBuilder.damage; this.damage = metaBuilder.damage;
this.unbreakable = metaBuilder.unbreakable; this.unbreakable = metaBuilder.unbreakable;
@ -106,12 +103,7 @@ public class ItemMeta {
} }
public @NotNull NBTCompound toNBT() { public @NotNull NBTCompound toNBT() {
NBTCompound cache = nbtCache.get(); return nbt.deepClone();
if (cache == null) {
cache = nbt.deepClone();
nbtCache = new SoftReference<>(cache);
}
return cache;
} }
@Override @Override