Skip to content

Commit

Permalink
Merge pull request #171 from LostLuma/add-fastload-softlock-workaround
Browse files Browse the repository at this point in the history
Add workaround for softlock in combination with Fastload
  • Loading branch information
LostLuma authored Feb 23, 2024
2 parents 39d8233 + fc3f319 commit e314d2b
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import dynamic_fps.impl.config.DynamicFPSConfig;
import dynamic_fps.impl.service.ModCompat;
import dynamic_fps.impl.util.Logging;
import dynamic_fps.impl.util.ModCompatHelper;
import dynamic_fps.impl.util.OptionsHolder;
import dynamic_fps.impl.util.duck.DuckScreen;
import dynamic_fps.impl.util.duck.DuckLoadingOverlay;
Expand Down Expand Up @@ -52,8 +53,12 @@ public class DynamicFPSMod {
// Internal "API" for Dynamic FPS itself

public static void init() {
ModCompatHelper.init();

Platform platform = Platform.getInstance();
Logging.getLogger().info("Dynamic FPS {} active on {}!", platform.modVersion(), platform.getName());
String version = platform.getModVersion(Constants.MOD_ID).orElseThrow();

Logging.getLogger().info("Dynamic FPS {} active on {}!", version, platform.getName());
}

public static boolean disabledByUser() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
package dynamic_fps.impl.service;

import java.util.Set;

public interface ModCompat {
boolean isDisabled();

boolean disableOverlayOptimization();
boolean isScreenOptedIn(String className);
boolean isScreenOptedOut(String className);
Set<String> getOptedInScreens();
Set<String> getOptedOutScreens();

default boolean isScreenOptedIn(String className) {
return getOptedInScreens().contains(className);
}

default boolean isScreenOptedOut(String className) {
return getOptedOutScreens().contains(className);
}

static ModCompat getInstance() {
return Services.MOD_COMPAT;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package dynamic_fps.impl.service;

import java.nio.file.Path;
import java.util.Optional;

public interface Platform {
String getName();
String modVersion();

Path getCacheDir();
Path getConfigDir();
boolean isDevelopmentEnvironment();

Optional<String> getModVersion(String modId);

void registerStartTickEvent(StartTickEvent event);

@FunctionalInterface
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package dynamic_fps.impl.util;

import dynamic_fps.impl.service.ModCompat;
import dynamic_fps.impl.service.Platform;

import java.util.Arrays;
import java.util.Optional;

public class ModCompatHelper {
public static void init() {
fixFastloadSoftLock();
}

/**
* Fix softlock in combination with Fastload <=3.4.0 due to our screen / loading overlay optimization.
*
* See the <a href="https://github.com/juliand665/Dynamic-FPS/issues/129">issue report</a> for more info.
*/
private static void fixFastloadSoftLock() {
Optional<String> optional = Platform.getInstance().getModVersion("fastload");

if (optional.isEmpty()) {
return;
}

String[] parts = optional.get().split("\\.");
int[] version = Arrays.stream(parts).mapToInt(Integer::parseInt).toArray();

if (version.length < 3) {
Logging.getLogger().warn("Unable to parse Fastload version: {}!", optional.get());
return;
}

// If a version below 3.4.0 is present opt their custom world loading screen out of our optimization
if (!(version[0] > 3 || version[0] == 3 && (version[1] > 4 || version[1] == 4 && version[2] > 0))) {
ModCompat.getInstance().getOptedOutScreens().add(
"io.github.bumblesoftware.fastload.client.BuildingTerrainScreen"
);

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public boolean disableOverlayOptimization() {
}

@Override
public boolean isScreenOptedIn(String className) {
return optedInScreens.contains(className);
public Set<String> getOptedInScreens() {
return optedInScreens;
}

@Override
public boolean isScreenOptedOut(String className) {
return optedOutScreens.contains(className);
public Set<String> getOptedOutScreens() {
return optedOutScreens;
}

private static void parseModMetadata(ModContainer mod) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,6 @@ public String getName() {
return "Fabric";
}

@Override
public String modVersion() {
Optional<ModContainer> optional = FabricLoader.getInstance().getModContainer(Constants.MOD_ID);

if (optional.isPresent()) {
return optional.get().getMetadata().getVersion().getFriendlyString();
} else {
throw new RuntimeException("Own mod container is somehow not available!");
}
}

@Override
public Path getCacheDir() {
Path base = FabricLoader.getInstance().getGameDir();
Expand All @@ -44,6 +33,12 @@ public boolean isDevelopmentEnvironment() {
return FabricLoader.getInstance().isDevelopmentEnvironment();
}

@Override
public Optional<String> getModVersion(String modId) {
Optional<ModContainer> optional = FabricLoader.getInstance().getModContainer(modId);
return optional.map(modContainer -> modContainer.getMetadata().getVersion().toString());
}

@Override
public void registerStartTickEvent(StartTickEvent event) {
ClientTickEvents.START_CLIENT_TICK.register((minecraft) -> event.onStartTick());
Expand Down
3 changes: 0 additions & 3 deletions platforms/fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@
"cloth-config": "*",
"quilt_loader": "*"
},
"breaks": {
"fastload": "<=3.4.0"
},
"mixins": [
"dynamic_fps.mixins.json",
"dynamic_fps-common.mixins.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@
import net.minecraft.client.gui.screens.ReceivingLevelScreen;
import net.minecraftforge.fml.ModList;

import java.util.HashSet;
import java.util.Set;

public class ForgeModCompat implements ModCompat {
private static final Set<String> optedOutScreens = new HashSet<>();

static {
optedOutScreens.add(ReceivingLevelScreen.class.getCanonicalName());
}

@Override
public boolean isDisabled() {
return false;
Expand All @@ -16,12 +25,12 @@ public boolean disableOverlayOptimization() {
}

@Override
public boolean isScreenOptedIn(String className) {
return false;
public Set<String> getOptedInScreens() {
return Set.of();
}

@Override
public boolean isScreenOptedOut(String className) {
return ReceivingLevelScreen.class.getCanonicalName().equals(className);
public Set<String> getOptedOutScreens() {
return optedOutScreens;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,11 @@
import java.util.Optional;

public class ForgePlatform implements Platform {

@Override
public String getName() {
return "Forge";
}

@Override
public String modVersion() {
Optional<? extends ModContainer> optional = ModList.get().getModContainerById(Constants.MOD_ID);

if (optional.isPresent()) {
return optional.get().getModInfo().getVersion().toString();
} else {
throw new RuntimeException("Own mod container is somehow not available!");
}
}

@Override
public Path getCacheDir() {
Path base = FMLPaths.GAMEDIR.get();
Expand All @@ -47,6 +35,12 @@ public boolean isDevelopmentEnvironment() {
return !FMLLoader.isProduction();
}

@Override
public Optional<String> getModVersion(String modId) {
Optional<? extends ModContainer> optional = ModList.get().getModContainerById(modId);
return optional.map(modContainer -> modContainer.getModInfo().getVersion().toString());
}

@Override
public void registerStartTickEvent(StartTickEvent event) {
DynamicFPSForgeMod.addTickEventListener(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@
import net.minecraft.client.gui.screens.ReceivingLevelScreen;
import net.neoforged.fml.ModList;

import java.util.HashSet;
import java.util.Set;

public class NeoForgeModCompat implements ModCompat {
private static final Set<String> optedOutScreens = new HashSet<>();

static {
optedOutScreens.add(ReceivingLevelScreen.class.getCanonicalName());
}

@Override
public boolean isDisabled() {
return false;
Expand All @@ -16,12 +25,12 @@ public boolean disableOverlayOptimization() {
}

@Override
public boolean isScreenOptedIn(String className) {
return false;
public Set<String> getOptedInScreens() {
return Set.of();
}

@Override
public boolean isScreenOptedOut(String className) {
return ReceivingLevelScreen.class.getCanonicalName().equals(className);
public Set<String> getOptedOutScreens() {
return optedOutScreens;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@

import dynamic_fps.impl.Constants;
import dynamic_fps.impl.service.Platform;
import net.neoforged.bus.EventBus;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.ModList;
import net.neoforged.fml.loading.FMLLoader;
import net.neoforged.fml.loading.FMLPaths;
import net.neoforged.neoforge.client.ClientHooks;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.common.NeoForgeEventHandler;
import net.neoforged.neoforge.event.TickEvent;

import java.io.IOException;
Expand All @@ -24,17 +20,6 @@ public String getName() {
return "NeoForge";
}

@Override
public String modVersion() {
Optional<? extends ModContainer> optional = ModList.get().getModContainerById(Constants.MOD_ID);

if (optional.isPresent()) {
return optional.get().getModInfo().getVersion().toString();
} else {
throw new RuntimeException("Own mod container is somehow not available!");
}
}

@Override
public Path getCacheDir() {
Path base = FMLPaths.GAMEDIR.get();
Expand All @@ -51,6 +36,12 @@ public boolean isDevelopmentEnvironment() {
return !FMLLoader.isProduction();
}

@Override
public Optional<String> getModVersion(String modId) {
Optional<? extends ModContainer> optional = ModList.get().getModContainerById(modId);
return optional.map(modContainer -> modContainer.getModInfo().getVersion().toString());
}

@Override
public void registerStartTickEvent(StartTickEvent event) {
NeoForge.EVENT_BUS.addListener(TickEvent.ClientTickEvent.class, (unused) -> event.onStartTick());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public boolean disableOverlayOptimization() {
}

@Override
public boolean isScreenOptedIn(String className) {
return optedInScreens.contains(className);
public Set<String> getOptedInScreens() {
return optedInScreens;
}

@Override
public boolean isScreenOptedOut(String className) {
return optedOutScreens.contains(className);
public Set<String> getOptedOutScreens() {
return optedOutScreens;
}

private static void parseModMetadata(ModContainer mod) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,6 @@ public String getName() {
return "Quilt";
}

@Override
public String modVersion() {
Optional<ModContainer> optional = QuiltLoader.getModContainer(Constants.MOD_ID);

if (optional.isPresent()) {
return optional.get().metadata().version().toString();
} else {
throw new RuntimeException("Own mod container is somehow not available!");
}
}

@Override
public Path getCacheDir() {
return this.ensureDir(QuiltLoader.getCacheDir().resolve(Constants.MOD_ID));
Expand All @@ -43,6 +32,12 @@ public boolean isDevelopmentEnvironment() {
return QuiltLoader.isDevelopmentEnvironment();
}

@Override
public Optional<String> getModVersion(String modId) {
Optional<ModContainer> optional = QuiltLoader.getModContainer(modId);
return optional.map(modContainer -> modContainer.metadata().version().toString());
}

@Override
public void registerStartTickEvent(StartTickEvent event) {
ClientTickEvents.START.register((minecraft) -> event.onStartTick());
Expand Down
7 changes: 0 additions & 7 deletions platforms/quilt/src/main/resources/quilt.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,6 @@
"versions": "*",
"optional": true
}
],
"breaks": [
{
"id": "fastload",
"versions": "<=3.4.0",
"reason": "Softlock in world loading screen, see https://github.com/BumbleSoftware/Fastload/issues/108"
}
]
},
"minecraft": {
Expand Down

0 comments on commit e314d2b

Please sign in to comment.