Fix some messy saving issues

This commit is contained in:
Sollace 2023-08-06 18:28:51 +01:00
parent 9b70be38be
commit f5293546c5
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
3 changed files with 10 additions and 11 deletions

View file

@ -11,7 +11,6 @@ import com.minelittlepony.unicopia.util.NbtSerialisable;
import net.minecraft.nbt.*;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;
import net.minecraft.world.PersistentState;
import net.minecraft.world.World;
@ -66,9 +65,10 @@ public class Ether extends PersistentState implements CasterView {
public Entry put(SpellType<?> spellType, Caster<?> caster) {
synchronized (locker) {
getEntries(spellType.getId()).add(new Entry(caster));
var entry = new Entry(caster);
getEntries(spellType.getId()).add(entry);
markDirty();
return getEntry(spellType, caster).get();
return entry;
}
}
@ -77,7 +77,7 @@ public class Ether extends PersistentState implements CasterView {
Identifier typeId = spellType.getId();
Set<Entry> refs = advertisingEndpoints.get(typeId);
if (refs != null) {
refs.removeIf(ref -> ref.removed || ref.entity.getId().orElse(Util.NIL_UUID).equals(id));
refs.removeIf(ref -> ref.isDead() || ref.entity.getTarget().filter(target -> id.equals(target.uuid())).isPresent());
if (refs.isEmpty()) {
advertisingEndpoints.remove(typeId);
}
@ -149,7 +149,7 @@ public class Ether extends PersistentState implements CasterView {
}
public void markDead() {
Unicopia.LOGGER.debug("Marking " + entity.getId().orElse(null) + " as dead");
Unicopia.LOGGER.debug("Marking " + entity.getTarget().orElse(null) + " as dead");
removed = true;
markDirty();
}
@ -183,17 +183,16 @@ public class Ether extends PersistentState implements CasterView {
@Override
public boolean equals(Object other) {
return other instanceof Entry e
&& e.equals(entity.getId().orElse(Util.NIL_UUID));
return other instanceof Entry e && e.entity.referenceEquals(entity);
}
public boolean equals(UUID uuid) {
return entity.getId().orElse(Util.NIL_UUID).equals(uuid);
return entity.referenceEquals(uuid);
}
@Override
public int hashCode() {
return entity.getId().orElse(Util.NIL_UUID).hashCode();
return entity.hashCode();
}
}
}

View file

@ -40,7 +40,7 @@ public class WorldOverlay<T extends WorldOverlay.State> extends PersistentState
return serverWorld.getPersistentStateManager().getOrCreate(
compound -> loadFunc.apply(world, compound),
() -> factory.apply(world),
id.toString()
id.getNamespace() + "_" + id.getPath().replace('/', '_')
);
}

View file

@ -33,6 +33,6 @@ public class WorldTribeManager extends PersistentState {
}
public static WorldTribeManager forWorld(ServerWorld world) {
return world.getPersistentStateManager().getOrCreate(WorldTribeManager::new, WorldTribeManager::new, "unicopia:tribes");
return world.getPersistentStateManager().getOrCreate(WorldTribeManager::new, WorldTribeManager::new, "unicopia_tribes");
}
}