diff --git a/CHANGELOG.md b/CHANGELOG.md index 76172b7f..b1b37550 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ This change log includes the summarized changes. For the full changelog, please go to the [GitHub History][history] instead. +### v11.3.0 + +- Fixed #72 and #75 by moving the `removeWhenFarAway` check to a later stage to exclude the check + for the Endergetic Expansion mod. +- Smaller code optimizations and performance improvements. + ### v11.2.0 - Fixed #73 by ignoring corpse entities. diff --git a/core/src/main/java/de/markusbordihn/adaptiveperformancetweakscore/CoreConstants.java b/core/src/main/java/de/markusbordihn/adaptiveperformancetweakscore/CoreConstants.java index 097a8391..8b3af5a9 100644 --- a/core/src/main/java/de/markusbordihn/adaptiveperformancetweakscore/CoreConstants.java +++ b/core/src/main/java/de/markusbordihn/adaptiveperformancetweakscore/CoreConstants.java @@ -80,6 +80,10 @@ public final class CoreConstants { public static final String EASY_NPC_MOD = "easy_npc"; public static final String EASY_NPC_NAME = "Easy NPC"; public static final boolean EASY_NPC_LOADED = ModList.get().isLoaded(EASY_NPC_MOD); + public static final String THE_ENDERGETIC_EXPANSION_MOD = "endergetic"; + public static final String THE_ENDERGETIC_EXPANSION_NAME = "The Endergetic Expansion"; + public static final boolean THE_ENDERGETIC_EXPANSION_LOADED = + ModList.get().isLoaded(THE_ENDERGETIC_EXPANSION_MOD); public static final String FISH_OF_THIEVES_MOD = "fishofthieves"; public static final String FISH_OF_THIEVES_NAME = "Fish's Undead Rising"; public static final boolean FISH_OF_THIEVES_LOADED = ModList.get().isLoaded(FISH_OF_THIEVES_MOD); diff --git a/core/src/main/java/de/markusbordihn/adaptiveperformancetweakscore/entity/CoreEntityManager.java b/core/src/main/java/de/markusbordihn/adaptiveperformancetweakscore/entity/CoreEntityManager.java index c1d160c2..cdada907 100644 --- a/core/src/main/java/de/markusbordihn/adaptiveperformancetweakscore/entity/CoreEntityManager.java +++ b/core/src/main/java/de/markusbordihn/adaptiveperformancetweakscore/entity/CoreEntityManager.java @@ -429,10 +429,7 @@ public static boolean isRelevantEntity(Entity entity) { || (entity instanceof TamableAnimal tamableAnimal && (tamableAnimal.getOwner() != null || tamableAnimal.getOwnerUUID() != null)) || (entity instanceof Mob mob - && (mob.isLeashed() - || mob.isPersistenceRequired() - || mob.requiresCustomPersistence() - || !mob.removeWhenFarAway(512))) + && (mob.isLeashed() || mob.isPersistenceRequired() || mob.requiresCustomPersistence())) || (entity instanceof Bee bee && bee.hasHive()) || entity.hasCustomName()); } @@ -506,6 +503,14 @@ public static boolean isRelevantEntity(Entity entity, String entityName) { return false; } + // Disable specific checks for mods which accessing chunk data during entity spawn / despawn. + if (!(CoreConstants.THE_ENDERGETIC_EXPANSION_LOADED + && entityName.startsWith(CoreConstants.THE_ENDERGETIC_EXPANSION_MOD)) + && entity instanceof Mob mob + && !mob.removeWhenFarAway(512)) { + return false; + } + // Checking entity NBT data to catch custom entities which are not extending the right classes // or using some custom definitions which could not be easily checked. CompoundTag compoundTag = entity.getPersistentData(); diff --git a/core/src/main/java/de/markusbordihn/adaptiveperformancetweakscore/message/WarnMessages.java b/core/src/main/java/de/markusbordihn/adaptiveperformancetweakscore/message/WarnMessages.java index d153c8ec..2f9ade4e 100644 --- a/core/src/main/java/de/markusbordihn/adaptiveperformancetweakscore/message/WarnMessages.java +++ b/core/src/main/java/de/markusbordihn/adaptiveperformancetweakscore/message/WarnMessages.java @@ -43,9 +43,10 @@ public static String chunkPregeneratorModWarning(String modName) { modName, modName); } - public static String knownIssuesModWarning(String modName) { + public static String knownIssuesGeneralModWarning(String modName) { return String.format( - "⚠ There are known issue with the %s mod, please do not report any issue!", modName); + "⚠ There are known issues with the %s mod, please report any related issues to the %s mod author first!", + modName, modName); } public static String knownIssuesSpawnModWarning(String modName) { diff --git a/core/src/main/java/de/markusbordihn/adaptiveperformancetweakscore/player/PlayerPositionManager.java b/core/src/main/java/de/markusbordihn/adaptiveperformancetweakscore/player/PlayerPositionManager.java index 0930f1a8..dc1dbc57 100644 --- a/core/src/main/java/de/markusbordihn/adaptiveperformancetweakscore/player/PlayerPositionManager.java +++ b/core/src/main/java/de/markusbordihn/adaptiveperformancetweakscore/player/PlayerPositionManager.java @@ -81,22 +81,14 @@ private static void updatePlayerPositions() { } PlayerList playerList = minecraftServer.getPlayerList(); - if (playerList == null) { + if (playerList == null || playerList.getPlayerCount() == 0) { + playerPositionMap.clear(); return; } - int numberOfPlayers = playerList.getPlayerCount(); - if (numberOfPlayers == 0) { - if (!playerPositionMap.isEmpty()) { - playerPositionMap = new ConcurrentHashMap<>(); - } - return; - } - - List serverPlayerList = playerList.getPlayers(); int viewDistance = playerList.getViewDistance(); int simulationDistance = playerList.getSimulationDistance(); - for (ServerPlayer player : serverPlayerList) { + for (ServerPlayer player : playerList.getPlayers()) { if (player.isAlive() && !player.hasDisconnected()) { updatePlayerPosition(player, viewDistance, simulationDistance); } diff --git a/core/src/main/java/de/markusbordihn/adaptiveperformancetweakscore/server/ServerManager.java b/core/src/main/java/de/markusbordihn/adaptiveperformancetweakscore/server/ServerManager.java index 88fdec20..1eb7fb1c 100644 --- a/core/src/main/java/de/markusbordihn/adaptiveperformancetweakscore/server/ServerManager.java +++ b/core/src/main/java/de/markusbordihn/adaptiveperformancetweakscore/server/ServerManager.java @@ -135,10 +135,9 @@ public static long[] getTickTime(ResourceKey level) { public static double getAverageTickTime(ServerLevel serverLevel) { long[] tickTimes = getTickTime(serverLevel.dimension()); - if (tickTimes != null) { - return Arrays.stream(tickTimes).average().orElse(Double.NaN) / 1000000; - } - return 0; + return (tickTimes != null) + ? Arrays.stream(tickTimes).average().orElse(Double.NaN) / 1000000 + : 0; } public static float getAverageTickTime() { @@ -165,19 +164,13 @@ private static void updateGameDifficulty(Difficulty difficulty) { return; } gameDifficulty = difficulty; - switch (difficulty) { - case EASY: - gameDifficultyFactor = COMMON.gameDifficultyFactorEasy.get(); - break; - case PEACEFUL: - gameDifficultyFactor = COMMON.gameDifficultyFactorPeaceful.get(); - break; - case HARD: - gameDifficultyFactor = COMMON.gameDifficultyFactorHard.get(); - break; - default: - gameDifficultyFactor = COMMON.gameDifficultyFactorNormal.get(); - } + gameDifficultyFactor = + switch (difficulty) { + case EASY -> COMMON.gameDifficultyFactorEasy.get(); + case PEACEFUL -> COMMON.gameDifficultyFactorPeaceful.get(); + case HARD -> COMMON.gameDifficultyFactorHard.get(); + default -> COMMON.gameDifficultyFactorNormal.get(); + }; log.info( "{} Game difficulty is set to {} with a {} factor.", Constants.LOG_PREFIX, diff --git a/core/src/main/java/de/markusbordihn/adaptiveperformancetweakscore/viewarea/ViewArea.java b/core/src/main/java/de/markusbordihn/adaptiveperformancetweakscore/viewarea/ViewArea.java index ce236ceb..52dc7942 100644 --- a/core/src/main/java/de/markusbordihn/adaptiveperformancetweakscore/viewarea/ViewArea.java +++ b/core/src/main/java/de/markusbordihn/adaptiveperformancetweakscore/viewarea/ViewArea.java @@ -103,23 +103,16 @@ public boolean update(int posX, int posY, int posZ, int viewAreaDistance, String return false; } - // Update position for change detection and debugging purpose. + // Update position and level for change detection and better view area calculation. this.posX = posX; this.posY = posY; this.posZ = posZ; - - // Update level for better view area calculation. this.levelName = levelName; boolean isNether = levelName.equals(NETHER); boolean isTheEnd = levelName.equals(THE_END); - // Limit max view area distance to consider mods which changes these factors. - this.viewAreaDistance = viewAreaDistance; - if (viewAreaDistance > MAX_VIEW_AREA_DISTANCE) { - viewAreaDistance = MAX_VIEW_AREA_DISTANCE; - } - - // Expand view area distance for Nether and The End. + // Limit max view area distance and expand for Nether and The End. + this.viewAreaDistance = Math.min(viewAreaDistance, MAX_VIEW_AREA_DISTANCE); if (isNether) { viewAreaDistance = (int) (viewAreaDistance * NETHER_EXPAND_FACTOR); } else if (isTheEnd) { @@ -127,23 +120,16 @@ public boolean update(int posX, int posY, int posZ, int viewAreaDistance, String } this.blocksViewDistance = viewAreaDistance; - // Simple calculation for X + // Simple calculation for X, Y, and Z this.startX = posX - viewAreaDistance; this.stopX = posX + viewAreaDistance; - - // Simple calculation for Y - if (this.levelName.equals(NETHER)) { - this.startY = Math.max(posY - viewAreaDistance, MIN_BUILD_HEIGHT); - this.stopY = Math.min(posY + viewAreaDistance, MAX_BUILD_HEIGHT_NETHER); - } else if (this.levelName.equals(THE_END)) { - this.startY = Math.max(posY - viewAreaDistance, MIN_BUILD_HEIGHT); - this.stopY = Math.min(posY + viewAreaDistance, MAX_BUILD_HEIGHT_THE_END); - } else { - this.startY = Math.max(posY - viewAreaDistance, MIN_BUILD_HEIGHT); - this.stopY = Math.min(posY + viewAreaDistance, MAX_BUILD_HEIGHT); - } - - // Simple calculation for Z + this.startY = Math.max(posY - viewAreaDistance, MIN_BUILD_HEIGHT); + this.stopY = + Math.min( + posY + viewAreaDistance, + isNether + ? MAX_BUILD_HEIGHT_NETHER + : isTheEnd ? MAX_BUILD_HEIGHT_THE_END : MAX_BUILD_HEIGHT); this.startZ = posZ - viewAreaDistance; this.stopZ = posZ + viewAreaDistance; diff --git a/gradle.properties b/gradle.properties index 7f68b220..ec92d3ec 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,14 +3,14 @@ org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false # Project -version=11.2.0 +version=11.3.0 # Mod mod_author=Markus Bordihn vendor_name=markusbordihn # Common minecraft_version=1.21.1 # Forge -forge_version=52.0.16 +forge_version=52.0.21 # CurseForge curseforge_release_type=release # Modrinth diff --git a/spawn/src/main/java/de/markusbordihn/adaptiveperformancetweaksspawn/spawn/SpawnManager.java b/spawn/src/main/java/de/markusbordihn/adaptiveperformancetweaksspawn/spawn/SpawnManager.java index 40c5ac71..70ca7d89 100644 --- a/spawn/src/main/java/de/markusbordihn/adaptiveperformancetweaksspawn/spawn/SpawnManager.java +++ b/spawn/src/main/java/de/markusbordihn/adaptiveperformancetweaksspawn/spawn/SpawnManager.java @@ -96,53 +96,7 @@ public static void handleServerAboutToStartEvent(ServerAboutToStartEvent event) ignoreDimensionList = new HashSet<>(COMMON.spawnIgnoreDimensionList.get()); } - @SubscribeEvent - public static void handleServerStarting(ServerStartingEvent event) { - if (!allowList.isEmpty()) { - log.info("{} Spawn allow list: {}", Constants.LOG_PREFIX, allowList); - } - if (!denyList.isEmpty()) { - log.info("{} Spawn deny list: {}", Constants.LOG_PREFIX, denyList); - } - if (!ignoreDimensionList.isEmpty()) { - log.info("{} Ignore dimension list: {}", Constants.LOG_PREFIX, ignoreDimensionList); - } - if (Boolean.TRUE.equals(COMMON.spawnAggressiveMode.get())) { - log.warn("Enable more aggressive spawn optimizations!"); - } else { - log.info( - "If you want to use a more aggressive spawn optimization, please set 'spawnAggressiveMode' to 'true'"); - } - if (Boolean.FALSE.equals(COMMON.viewAreaEnabled.get())) { - log.info("Disable view area optimizations!"); - } - if (Boolean.TRUE.equals(COMMON.spawnLimitationEnabled.get())) { - if (COMMON.spawnLimitationLimiter.get() > 0) { - log.info( - "{} ✓ Enable limiter and block randomly every {} mob from spawning ...", - Constants.LOG_PREFIX, - COMMON.spawnLimitationLimiter.get()); - } - if (COMMON.spawnLimitationMaxMobsPerPlayer.get() > 0) { - log.info( - "{} ✓ Enable spawn rate control with max {} per player ...", - Constants.LOG_PREFIX, - COMMON.spawnLimitationMaxMobsPerPlayer.get()); - } - if (COMMON.spawnLimitationMaxMobsPerWorld.get() > 0) { - log.info( - "{} ✓ Enable spawn rate control with max {} per world ...", - Constants.LOG_PREFIX, - COMMON.spawnLimitationMaxMobsPerWorld.get()); - } - if (COMMON.spawnLimitationMaxMobsPerServer.get() > 0) { - log.info( - "{} ✓ Enable spawn rate control with max {} per server ...", - Constants.LOG_PREFIX, - COMMON.spawnLimitationMaxMobsPerServer.get()); - } - } - + private static void showModSpecificWarnings() { // Added warning for chunk optimization Mods if (CoreConstants.CHUNK_PREGEN_LOADED) { log.warn(() -> WarnMessages.chunkPregeneratorModWarning(CoreConstants.CHUNK_PREGEN_NAME)); @@ -167,6 +121,12 @@ public static void handleServerStarting(ServerStartingEvent event) { WarnMessages.conflictingFeaturesModWarning( CoreConstants.INCONTROL_NAME, "controls the mob spawns and entity spawns")); } + if (CoreConstants.THE_ENDERGETIC_EXPANSION_LOADED) { + log.warn( + () -> + WarnMessages.knownIssuesGeneralModWarning( + CoreConstants.THE_ENDERGETIC_EXPANSION_NAME)); + } // Disabled optimization warning for specific Mods if (CoreConstants.CREATE_LOADED) { @@ -179,9 +139,6 @@ public static void handleServerStarting(ServerStartingEvent event) { if (CoreConstants.BOTANIA_LOADED) { log.warn(() -> WarnMessages.disabledOptimizationModWarning(CoreConstants.BOTANIA_NAME)); } - if (CoreConstants.CREATE_LOADED) { - log.warn(() -> WarnMessages.disabledOptimizationModWarning(CoreConstants.CREATE_NAME)); - } if (CoreConstants.INDUSTRIAL_FOREGOING_LOADED) { log.warn( () -> @@ -212,6 +169,56 @@ public static void handleServerStarting(ServerStartingEvent event) { } } + @SubscribeEvent + public static void handleServerStarting(ServerStartingEvent event) { + if (!allowList.isEmpty()) { + log.info("{} Spawn allow list: {}", Constants.LOG_PREFIX, allowList); + } + if (!denyList.isEmpty()) { + log.info("{} Spawn deny list: {}", Constants.LOG_PREFIX, denyList); + } + if (!ignoreDimensionList.isEmpty()) { + log.info("{} Ignore dimension list: {}", Constants.LOG_PREFIX, ignoreDimensionList); + } + if (Boolean.TRUE.equals(COMMON.spawnAggressiveMode.get())) { + log.warn("Enable more aggressive spawn optimizations!"); + } else { + log.info( + "If you want to use a more aggressive spawn optimization, please set 'spawnAggressiveMode' to 'true'"); + } + if (Boolean.FALSE.equals(COMMON.viewAreaEnabled.get())) { + log.info("Disable view area optimizations!"); + } + if (Boolean.TRUE.equals(COMMON.spawnLimitationEnabled.get())) { + if (COMMON.spawnLimitationLimiter.get() > 0) { + log.info( + "{} ✓ Enable limiter and block randomly every {} mob from spawning ...", + Constants.LOG_PREFIX, + COMMON.spawnLimitationLimiter.get()); + } + if (COMMON.spawnLimitationMaxMobsPerPlayer.get() > 0) { + log.info( + "{} ✓ Enable spawn rate control with max {} per player ...", + Constants.LOG_PREFIX, + COMMON.spawnLimitationMaxMobsPerPlayer.get()); + } + if (COMMON.spawnLimitationMaxMobsPerWorld.get() > 0) { + log.info( + "{} ✓ Enable spawn rate control with max {} per world ...", + Constants.LOG_PREFIX, + COMMON.spawnLimitationMaxMobsPerWorld.get()); + } + if (COMMON.spawnLimitationMaxMobsPerServer.get() > 0) { + log.info( + "{} ✓ Enable spawn rate control with max {} per server ...", + Constants.LOG_PREFIX, + COMMON.spawnLimitationMaxMobsPerServer.get()); + } + } + + showModSpecificWarnings(); + } + @SubscribeEvent public static void handleServerStarted(ServerStartedEvent event) { serverStarted = true;