From 262f82fb854237f43932ea6fc21ee081c733ea39 Mon Sep 17 00:00:00 2001 From: KiloJoel Date: Sat, 9 Jan 2021 08:26:20 +0000 Subject: Fixed lag reduction on file saving (#48) --- .../tectech/mechanics/anomaly/AnomalyHandler.java | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/main/java/com') diff --git a/src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java b/src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java index 0beb5e0af8..dd388bc233 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java +++ b/src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java @@ -233,23 +233,32 @@ public class AnomalyHandler implements IChunkMetaDataHandler { ChunkCoordIntPair pair = new ChunkCoordIntPair(player.chunkCoordX, player.chunkCoordZ); NBTTagCompound compound = data.get(player.worldObj.provider.dimensionId).get(pair); NBTTagCompound playerTag = TecTech.playerPersistence.getDataOrSetToNewTag(player); + boolean saveRequired = false; if(player.capabilities.isCreativeMode){ - playerTag.setDouble(SPACE_CANCER, 0); + if (playerTag.getDouble(SPACE_CANCER) != 0) { + playerTag.setDouble(SPACE_CANCER, 0); + saveRequired = true; + } }else { if (compound != null) { int badness = (int) Math.min(COUNT_DIV, compound.getDouble(INTENSITY) / PER_PARTICLE); if (badness > 0) { playerTag.setDouble(SPACE_CANCER, Math.min(2, playerTag.getDouble(SPACE_CANCER) + 9.765625E-4f * badness)); player.attackEntityFrom(MainLoader.subspace,Math.max(1,badness/8f)); + saveRequired = true; } } else if (playerTag.getDouble(SPACE_CANCER) > 0 && !player.isDead) { - if (playerTag.getDouble(SPACE_CANCER) == 0 || player.ticksExisted % 10 != 0) - return; - playerTag.setDouble(SPACE_CANCER, Math.max(0, playerTag.getDouble(SPACE_CANCER) - 7.6293945E-5f)); + if (player.ticksExisted % 10 == 0) { + playerTag.setDouble(SPACE_CANCER, Math.max(0, playerTag.getDouble(SPACE_CANCER) - 7.6293945E-5f)); + saveRequired = true; + } } } - TecTech.playerPersistence.saveData(player); - NetworkDispatcher.INSTANCE.sendTo(new PlayerDataMessage.PlayerDataData(player), (EntityPlayerMP) player); + + if (saveRequired) { + TecTech.playerPersistence.saveData(player); + NetworkDispatcher.INSTANCE.sendTo(new PlayerDataMessage.PlayerDataData(player), (EntityPlayerMP) player); + } } } -- cgit