fix: fix some async bugs
This commit is contained in:
@@ -91,6 +91,7 @@ public class EntitiesCounterUtil {
|
||||
Object2IntOpenHashMap<MobCategory> map = new Object2IntOpenHashMap<>();
|
||||
for (ReferenceList<Entity> data : data0.values()) {
|
||||
for (Entity entity : GlobalEntitiesCounter.enabled ? data.copy() : data) {
|
||||
if (entity == null || entity.isRemoved() || !entity.isAlive()) continue;
|
||||
// Lophine start - Copy from net/minecraft/world/level/NaturalSpawner
|
||||
MobCategory category = entity.getType().getCategory();
|
||||
if (category != MobCategory.MISC) {
|
||||
@@ -132,6 +133,7 @@ public class EntitiesCounterUtil {
|
||||
// Lophine start - Copy from net/minecraft/world/level/NaturalSpawner
|
||||
PotentialCalculator potentialCalculator = new PotentialCalculator();
|
||||
for (Entity entity : entities) {
|
||||
if (entity == null || entity.isRemoved() || !entity.isAlive()) continue;
|
||||
// Paper start - Only count natural spawns
|
||||
if (!entity.level().paperConfig().entities.spawning.countAllMobsForSpawning &&
|
||||
!(entity.spawnReason == CreatureSpawnEvent.SpawnReason.NATURAL ||
|
||||
|
||||
@@ -26,7 +26,7 @@ public class RecordMetaData {
|
||||
public static final int CURRENT_FILE_FORMAT_VERSION = 14;
|
||||
|
||||
public boolean singleplayer = false;
|
||||
public String serverName = "Leaves";
|
||||
public String serverName = "Lophine";
|
||||
public int duration = 0;
|
||||
public long date;
|
||||
public String mcversion;
|
||||
@@ -37,4 +37,22 @@ public class RecordMetaData {
|
||||
public int selfId = -1;
|
||||
|
||||
public Set<UUID> players = new HashSet<>();
|
||||
|
||||
public RecordMetaData copy() {
|
||||
RecordMetaData ret = new RecordMetaData();
|
||||
synchronized (this) {
|
||||
ret.singleplayer = this.singleplayer;
|
||||
ret.serverName = this.serverName;
|
||||
ret.duration = this.duration;
|
||||
ret.date = this.date;
|
||||
ret.mcversion = this.mcversion;
|
||||
ret.fileFormat = this.fileFormat;
|
||||
ret.fileFormatVersion = this.fileFormatVersion;
|
||||
ret.protocol = this.protocol;
|
||||
ret.generator = this.generator;
|
||||
ret.selfId = this.selfId;
|
||||
ret.players = new HashSet<>(this.players);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,7 +195,9 @@ public class Recorder extends Connection {
|
||||
}
|
||||
case ClientboundAddEntityPacket packet1 -> {
|
||||
if (packet1.getType() == EntityType.PLAYER) {
|
||||
metaData.players.add(packet1.getUUID());
|
||||
synchronized (metaData) {
|
||||
metaData.players.add(packet1.getUUID());
|
||||
}
|
||||
saveMetadata();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import java.util.List;
|
||||
public class RecorderOption {
|
||||
|
||||
public int recordDistance = -1;
|
||||
public String serverName = "Leaves";
|
||||
public String serverName = "Lophine";
|
||||
public RecordWeather forceWeather = null;
|
||||
public int forceDayTime = -1;
|
||||
public boolean ignoreChat = false;
|
||||
|
||||
@@ -123,9 +123,10 @@ public class ReplayFile {
|
||||
data.fileFormatVersion = RecordMetaData.CURRENT_FILE_FORMAT_VERSION;
|
||||
data.protocol = SharedConstants.getCurrentVersion().protocolVersion();
|
||||
data.generator = ProtocolUtils.buildProtocolVersion("replay");
|
||||
RecordMetaData dataCopy = data.copy();
|
||||
|
||||
try (Writer writer = new OutputStreamWriter(new FileOutputStream(metaFile), StandardCharsets.UTF_8)) {
|
||||
writer.write(META_GSON.toJson(data));
|
||||
writer.write(META_GSON.toJson(dataCopy));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user