Skip to content

Commit

Permalink
Merge branch '1.20.4' into 1.20.6
Browse files Browse the repository at this point in the history
  • Loading branch information
rfresh2 committed Jul 3, 2024
2 parents 49f4ba4 + 6742d39 commit d3f1447
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 22 deletions.
2 changes: 1 addition & 1 deletion common/src/main/java/xaeroplus/XaeroPlus.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import net.lenni0451.lambdaevents.generator.LambdaMetaFactoryGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import xaero.common.platform.Services;
import xaero.map.platform.Services;

import java.io.File;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down
29 changes: 17 additions & 12 deletions fabric/src/main/java/xaeroplus/fabric/XaeroPlusFabric.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,42 @@
import xaeroplus.XaeroPlus;
import xaeroplus.fabric.util.FabricWaystonesHelperInit;
import xaeroplus.fabric.util.compat.IncompatibleMinimapWarningScreen;
import xaeroplus.fabric.util.compat.MinimapBaseVersionCheck;
import xaeroplus.fabric.util.compat.XaeroPlusMinimapCompatibilityChecker;
import xaeroplus.module.ModuleManager;
import xaeroplus.settings.XaeroPlusSettingRegistry;
import xaeroplus.settings.XaeroPlusSettingsReflectionHax;
import xaeroplus.util.DataFolderResolveUtil;

import java.util.List;

import static xaeroplus.fabric.util.compat.XaeroPlusMinimapCompatibilityChecker.versionCheckResult;

public class XaeroPlusFabric implements ClientModInitializer {
public static void initialize() {
if (XaeroPlus.initialized.compareAndSet(false, true)) {
XaeroPlus.LOGGER.info("Initializing XaeroPlus");
ModuleManager.init();
boolean a = Globals.FOLLOW; // force static instances to init
XaeroPlusSettingRegistry.fastMapSetting.getValue(); // force static instances to init
List<KeyMapping> keybinds = XaeroPlusSettingsReflectionHax.keybindsSupplier.get();
keybinds.forEach(KeyBindingHelper::registerKeyBinding);
FabricWaystonesHelperInit.doInit();
}
if (!versionCheckResult.minimapCompatible()) {
XaeroPlus.LOGGER.error("Incompatible Xaero Minimap version detected! Expected: {} Actual: {}",
versionCheckResult.expectedVersion().getFriendlyString(),
versionCheckResult.anyPresentMinimapVersion().map(Version::getFriendlyString).orElse("None!"));
return;
}
ModuleManager.init();
boolean a = Globals.FOLLOW; // force static instances to init
XaeroPlusSettingRegistry.fastMapSetting.getValue(); // force static instances to init
List<KeyMapping> keybinds = XaeroPlusSettingsReflectionHax.keybindsSupplier.get();
keybinds.forEach(KeyBindingHelper::registerKeyBinding);
FabricWaystonesHelperInit.doInit();
}
}

@Override
public void onInitializeClient() {
initialize();
ClientLifecycleEvents.CLIENT_STARTED.register(client -> {
// needed as we can either accept Xaero's Minimap or BetterPVP but can't describe this in the fabric.mod.json
var versionCheckResult = MinimapBaseVersionCheck.versionCheck();
var versionCheckResult = XaeroPlusMinimapCompatibilityChecker.versionCheckResult;
if (versionCheckResult.minimapCompatible()) return;
XaeroPlus.LOGGER.error("Incompatible Xaero Minimap version detected! Expected: {} Actual: {}",
versionCheckResult.expectedVersion().getFriendlyString(),
versionCheckResult.anyPresentMinimapVersion().map(Version::getFriendlyString).orElse("None!"));
var anyPresentVersion = versionCheckResult.minimapVersion().or(versionCheckResult::betterPvpVersion);
Minecraft.getInstance().setScreen(
new IncompatibleMinimapWarningScreen(anyPresentVersion, versionCheckResult.expectedVersion()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
import java.util.List;
import java.util.Set;

import static xaeroplus.fabric.util.compat.XaeroPlusMinimapCompatibilityChecker.versionCheckResult;

/**
* Avoids applying XP mixins if Minimap is not present or not at a compatible version
*
* We want to either accept BetterPVP or Minimap at a specific version. But we can't make fabric.json enforce this so we have to do it ourselves
*/
public class XaeroPlusCompatibleMinimapMixinPlugin implements IMixinConfigPlugin {
private VersionCheckResult versionCheckResult;

@Override
public void onLoad(final String mixinPackage) {
if (FabricLoader.getInstance().getEnvironmentType() != EnvType.CLIENT) return;
versionCheckResult = MinimapBaseVersionCheck.versionCheck();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@

import java.util.Optional;

public class MinimapBaseVersionCheck {
public class XaeroPlusMinimapCompatibilityChecker {

public static VersionCheckResult versionCheck() {
public static VersionCheckResult versionCheckResult = XaeroPlusMinimapCompatibilityChecker.versionCheck();

private static VersionCheckResult versionCheck() {
try {
var compatibleMinimapVersion = SemanticVersion.parse(MinimapBaseVersionCheck.getCompatibleMinimapVersion());
var minimapVersion = MinimapBaseVersionCheck.getVersion("xaerominimap");
var betterPvpVersion = MinimapBaseVersionCheck.getVersion("xaerobetterpvp");
var compatibleMinimapVersion = SemanticVersion.parse(XaeroPlusMinimapCompatibilityChecker.getCompatibleMinimapVersion());
var minimapVersion = XaeroPlusMinimapCompatibilityChecker.getVersion("xaerominimap");
var betterPvpVersion = XaeroPlusMinimapCompatibilityChecker.getVersion("xaerobetterpvp");
return new VersionCheckResult(minimapVersion, betterPvpVersion, compatibleMinimapVersion);
} catch (VersionParsingException e) {
throw new RuntimeException(e);
}
}

static Optional<Version> getVersion(final String modId) {
private static Optional<Version> getVersion(final String modId) {
try {
return FabricLoader.getInstance().getAllMods().stream()
.filter(modContainer -> modContainer.getMetadata().getId().equals(modId))
Expand All @@ -40,7 +42,7 @@ static Optional<Version> getVersion(final String modId) {
}
}

static String getCompatibleMinimapVersion() {
private static String getCompatibleMinimapVersion() {
return FabricLoader.getInstance().getModContainer("xaeroplus").get().getMetadata().getCustomValue("minimap_version").getAsString();
}
}

0 comments on commit d3f1447

Please sign in to comment.