Merge remote-tracking branch 'origin/1.16' into 1.18

This commit is contained in:
embeddedt 2023-07-27 16:35:06 -04:00
commit f3f66e1873
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
18 changed files with 137 additions and 101 deletions

View File

@ -28,6 +28,10 @@ allprojects {
}
}
architectury {
compileOnly()
}
group = 'org.embeddedt'
// extract base version from tag, generate other metadata ourselves
def details = versionDetails()
@ -189,6 +193,15 @@ configure(subprojects.findAll {it.name == "forge" || it.name == "fabric"}) {
apply plugin: 'com.matthewprenger.cursegradle'
apply plugin: 'com.modrinth.minotaur'
loom {
mods {
main { // to match the default mod generated for Forge
sourceSet project.sourceSets.main
sourceSet project(':common').sourceSets.main
}
}
}
def copyJarNameConsistent = tasks.register('copyJarNameConsistent', Copy) {
from remapJar // shortcut for createJar.outputs.files
into project.file("build/libs")

View File

@ -50,15 +50,15 @@ public class ModernFix {
INSTANCE = this;
if(ModernFixMixinPlugin.instance.isOptionEnabled("feature.snapshot_easter_egg.NameChange") && !SharedConstants.getCurrentVersion().isStable())
NAME = "PreemptiveFix";
ModernFixPlatformHooks.onServerCommandRegister(ModernFixCommands::register);
ModernFixPlatformHooks.INSTANCE.onServerCommandRegister(ModernFixCommands::register);
}
public void onServerStarted() {
if(ModernFixPlatformHooks.isDedicatedServer()) {
if(ModernFixPlatformHooks.INSTANCE.isDedicatedServer()) {
float gameStartTime = ManagementFactory.getRuntimeMXBean().getUptime() / 1000f;
if(ModernFixMixinPlugin.instance.isOptionEnabled("feature.measure_time.ServerLoad"))
ModernFix.LOGGER.warn("Dedicated server took " + gameStartTime + " seconds to load");
ModernFixPlatformHooks.onLaunchComplete();
ModernFixPlatformHooks.INSTANCE.onLaunchComplete();
}
ClassInfoManager.clear();
}

View File

@ -46,11 +46,11 @@ public class ModernFixClient {
// clear reserve as it's not needed
MemoryReserve.release();
if(ModernFixMixinPlugin.instance.isOptionEnabled("feature.branding.F3Screen")) {
brandingString = ModernFix.NAME + " " + ModernFixPlatformHooks.getVersionString();
brandingString = ModernFix.NAME + " " + ModernFixPlatformHooks.INSTANCE.getVersionString();
}
SearchTreeProviderRegistry.register(JEIBackedSearchTree.PROVIDER);
SearchTreeProviderRegistry.register(REIBackedSearchTree.PROVIDER);
for(String className : ModernFixPlatformHooks.getCustomModOptions().get(IntegrationConstants.CLIENT_INTEGRATION_CLASS)) {
for(String className : ModernFixPlatformHooks.INSTANCE.getCustomModOptions().get(IntegrationConstants.CLIENT_INTEGRATION_CLASS)) {
try {
CLIENT_INTEGRATIONS.add((ModernFixClientIntegration)Class.forName(className).getDeclaredConstructor().newInstance());
} catch(ReflectiveOperationException | ClassCastException e) {
@ -73,7 +73,7 @@ public class ModernFixClient {
gameStartTimeSeconds = ManagementFactory.getRuntimeMXBean().getUptime() / 1000f;
if(ModernFixMixinPlugin.instance.isOptionEnabled("feature.measure_time.GameLoad"))
ModernFix.LOGGER.warn("Game took " + gameStartTimeSeconds + " seconds to start");
ModernFixPlatformHooks.onLaunchComplete();
ModernFixPlatformHooks.INSTANCE.onLaunchComplete();
ClassInfoManager.clear();
}
}

View File

@ -41,7 +41,7 @@ public abstract class TextureAtlasMixin {
*/
@Inject(method = "getBasicSpriteInfos", at = @At("HEAD"))
private void loadImages(ResourceManager manager, Set<ResourceLocation> imageLocations, CallbackInfoReturnable<Collection<TextureAtlasSprite.Info>> cir) {
usingFasterLoad = ModernFixPlatformHooks.isLoadingNormally();
usingFasterLoad = ModernFixPlatformHooks.INSTANCE.isLoadingNormally();
}
@Redirect(method = "getBasicSpriteInfos", at = @At(value = "INVOKE", target = "Ljava/util/Set;iterator()Ljava/util/Iterator;", ordinal = 0))
@ -107,7 +107,7 @@ public abstract class TextureAtlasMixin {
} else {
TextureAtlasSprite sprite = null;
try {
sprite = ModernFixPlatformHooks.loadTextureAtlasSprite((TextureAtlas)(Object)this, resourceManager, spriteInfo, pair.getFirst(), storageX, storageY, x, y, mipLevel, pair.getSecond());
sprite = ModernFixPlatformHooks.INSTANCE.loadTextureAtlasSprite((TextureAtlas)(Object)this, resourceManager, spriteInfo, pair.getFirst(), storageX, storageY, x, y, mipLevel, pair.getSecond());
} catch(RuntimeException e) {
ModernFix.LOGGER.error("Error loading texture {}: {}", spriteInfo.name(), e);
} finally {

View File

@ -36,7 +36,7 @@ public class StitcherMixin {
*/
@Inject(method = "stitch", at = @At("HEAD"), cancellable = true)
private void stitchFast(CallbackInfo ci) {
if(!ModernFixPlatformHooks.isLoadingNormally()) {
if(!ModernFixPlatformHooks.INSTANCE.isLoadingNormally()) {
ModernFix.LOGGER.error("Using vanilla stitcher implementation due to invalid loading state");
return;
}
@ -57,7 +57,7 @@ public class StitcherMixin {
*/
@Inject(method = "gatherSprites", at = @At("HEAD"), cancellable = true)
private void gatherSpritesFast(Stitcher.SpriteLoader spriteLoader, CallbackInfo ci) {
if(!ModernFixPlatformHooks.isLoadingNormally())
if(!ModernFixPlatformHooks.INSTANCE.isLoadingNormally())
return;
ci.cancel();
for(StbStitcher.LoadableSpriteInfo info : loadableSpriteInfos) {

View File

@ -22,7 +22,7 @@ public class ModernFixMixinPlugin implements IMixinConfigPlugin {
public ModernFixMixinPlugin() {
/* invoke early to ensure it gets read on one thread */
ModernFixPlatformHooks.getCustomModOptions();
ModernFixPlatformHooks.INSTANCE.getCustomModOptions();
boolean firstConfig = instance == null;
if(firstConfig) {
instance = this;
@ -33,7 +33,7 @@ public class ModernFixMixinPlugin implements IMixinConfigPlugin {
}
this.logger.info("Loaded configuration file for ModernFix {}: {} options available, {} override(s) found",
ModernFixPlatformHooks.getVersionString(), config.getOptionCount(), config.getOptionOverrideCount());
ModernFixPlatformHooks.INSTANCE.getVersionString(), config.getOptionCount(), config.getOptionOverrideCount());
config.getOptionMap().values().forEach(option -> {
if (option.isOverridden()) {
@ -41,7 +41,7 @@ public class ModernFixMixinPlugin implements IMixinConfigPlugin {
if (option.isUserDefined()) {
source = "user configuration";
} else if (!ModernFixPlatformHooks.isEarlyLoadingNormally()) {
} else if (!ModernFixPlatformHooks.INSTANCE.isEarlyLoadingNormally()) {
source = "load error";
} else if (option.isModDefined()) {
source = "mods [" + String.join(", ", option.getDefiningMods()) + "]";
@ -64,7 +64,7 @@ public class ModernFixMixinPlugin implements IMixinConfigPlugin {
}
/* We abuse the constructor of a mixin plugin as a safe location to start modifying the classloader */
ModernFixPlatformHooks.injectPlatformSpecificHacks();
ModernFixPlatformHooks.INSTANCE.injectPlatformSpecificHacks();
if(ModernFixMixinPlugin.instance.isOptionEnabled("feature.spam_thread_dump.ThreadDumper")) {
// run once to trigger classloading
@ -119,7 +119,7 @@ public class ModernFixMixinPlugin implements IMixinConfigPlugin {
if (option == null) {
String msg = "No rules matched mixin '{}', treating as foreign and disabling!";
if(ModernFixPlatformHooks.isDevEnv())
if(ModernFixPlatformHooks.INSTANCE.isDevEnv())
this.logger.error(msg, mixin);
else
this.logger.debug(msg, mixin);
@ -146,6 +146,6 @@ public class ModernFixMixinPlugin implements IMixinConfigPlugin {
@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
ModernFixPlatformHooks.applyASMTransformers(mixinClassName, targetClass);
ModernFixPlatformHooks.INSTANCE.applyASMTransformers(mixinClassName, targetClass);
}
}

View File

@ -51,7 +51,7 @@ public class ModernFixEarlyConfig {
if(modId.equals("optifine"))
return OPTIFINE_PRESENT;
else
return ModernFixPlatformHooks.modPresent(modId);
return ModernFixPlatformHooks.INSTANCE.modPresent(modId);
}
private static final String MIXIN_DESC = Type.getDescriptor(Mixin.class);
@ -122,11 +122,11 @@ public class ModernFixEarlyConfig {
isDevOnly = true;
}
}
if(isMixin && (!isDevOnly || ModernFixPlatformHooks.isDevEnv())) {
if(isMixin && (!isDevOnly || ModernFixPlatformHooks.INSTANCE.isDevEnv())) {
String mixinClassName = sanitize(node.name.replace('/', '.')).replace("org.embeddedt.modernfix.mixin.", "");
if(!requiredModPresent)
mixinsMissingMods.put(mixinClassName, requiredModId);
else if(isClientOnly && !ModernFixPlatformHooks.isClient())
else if(isClientOnly && !ModernFixPlatformHooks.INSTANCE.isClient())
mixinsMissingMods.put(mixinClassName, "[not client]");
List<String> mixinOptionNames = dotSplitter.splitToList(mixinClassName);
StringBuilder optionBuilder = new StringBuilder(mixinClassName.length());
@ -150,7 +150,7 @@ public class ModernFixEarlyConfig {
}
}
private static final boolean isDevEnv = ModernFixPlatformHooks.isDevEnv();
private static final boolean isDevEnv = ModernFixPlatformHooks.INSTANCE.isDevEnv();
private static class DefaultSettingMapBuilder extends ImmutableMap.Builder<String, Boolean> {
public DefaultSettingMapBuilder putConditionally(BooleanSupplier condition, String k, Boolean v) {
@ -169,7 +169,7 @@ public class ModernFixEarlyConfig {
private static final ImmutableMap<String, Boolean> DEFAULT_SETTING_OVERRIDES = new DefaultSettingMapBuilder()
.put("mixin.perf.dynamic_resources", false)
.put("mixin.feature.direct_stack_trace", false)
.putConditionally(ModernFixPlatformHooks::isDevEnv, "mixin.perf.rewrite_registry", false)
.putConditionally(ModernFixPlatformHooks.INSTANCE::isDevEnv, "mixin.perf.rewrite_registry", false)
.put("mixin.perf.clear_mixin_classinfo", false)
.put("mixin.perf.deduplicate_climate_parameters", false)
.put("mixin.bugfix.packet_leak", false)
@ -242,7 +242,7 @@ public class ModernFixEarlyConfig {
private void disableIfModPresent(String configName, String... ids) {
for(String id : ids) {
if(!ModernFixPlatformHooks.isEarlyLoadingNormally() || modPresent(id)) {
if(!ModernFixPlatformHooks.INSTANCE.isEarlyLoadingNormally() || modPresent(id)) {
Option option = this.options.get(configName);
if(option != null)
option.addModOverride(false, id);

View File

@ -117,7 +117,7 @@ public class ModelBakeryHelpers {
Set<ResourceLocation> modelFiles, UnbakedModel missingModel,
Function<JsonElement, BlockModel> modelDeserializer,
Function<ResourceLocation, UnbakedModel> bakeryModelGetter) {
if(!ModernFixPlatformHooks.isLoadingNormally())
if(!ModernFixPlatformHooks.INSTANCE.isLoadingNormally())
return;
Stopwatch stopwatch = Stopwatch.createStarted();
final Object2IntOpenHashMap<String> blockstateErrors = new Object2IntOpenHashMap<>();

View File

@ -51,7 +51,7 @@ public class EntityDataIDSyncHandler {
}
EntityIDSyncPacket packet = new EntityIDSyncPacket(fieldsToSyncMap);
ModernFix.LOGGER.debug("Sending ID correction packet to client with " + fieldsToSyncMap.size() + " classes");
ModernFixPlatformHooks.sendPacket(targetPlayer, packet);
ModernFixPlatformHooks.INSTANCE.sendPacket(targetPlayer, packet);
}
}
}

View File

@ -3,7 +3,6 @@ package org.embeddedt.modernfix.platform;
import com.google.common.collect.Multimap;
import com.mojang.blaze3d.platform.NativeImage;
import com.mojang.brigadier.CommandDispatcher;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.commands.CommandSourceStack;
@ -16,59 +15,60 @@ import org.objectweb.asm.tree.ClassNode;
import java.nio.file.Path;
import java.util.function.Consumer;
public class ModernFixPlatformHooks {
@ExpectPlatform
public static boolean isClient() {
public interface ModernFixPlatformHooks {
ModernFixPlatformHooks INSTANCE = PlatformHookLoader.findInstance();
default boolean isClient() {
throw new AssertionError();
}
@ExpectPlatform
public static boolean isDedicatedServer() {
default boolean isDedicatedServer() {
throw new AssertionError();
}
@ExpectPlatform
public static String getVersionString() {
default String getVersionString() {
throw new AssertionError();
}
@ExpectPlatform
public static boolean modPresent(String modId) {
default boolean modPresent(String modId) {
throw new AssertionError();
}
@ExpectPlatform
public static boolean isDevEnv() {
default boolean isDevEnv() {
throw new AssertionError();
}
@ExpectPlatform
public static void injectPlatformSpecificHacks() {
default void injectPlatformSpecificHacks() {
throw new AssertionError();
}
@ExpectPlatform
public static void applyASMTransformers(String mixinClassName, ClassNode targetClass) {
default void applyASMTransformers(String mixinClassName, ClassNode targetClass) {
throw new AssertionError();
}
@ExpectPlatform
public static MinecraftServer getCurrentServer() {
default MinecraftServer getCurrentServer() {
throw new AssertionError();
}
@ExpectPlatform
public static boolean isEarlyLoadingNormally() {
default boolean isEarlyLoadingNormally() {
throw new AssertionError();
}
@ExpectPlatform
public static boolean isLoadingNormally() {
default boolean isLoadingNormally() {
throw new AssertionError();
}
@ExpectPlatform
public static TextureAtlasSprite loadTextureAtlasSprite(TextureAtlas atlasTexture,
default TextureAtlasSprite loadTextureAtlasSprite(TextureAtlas atlasTexture,
ResourceManager resourceManager, TextureAtlasSprite.Info textureInfo,
Resource resource,
int atlasWidth, int atlasHeight,
@ -77,33 +77,33 @@ public class ModernFixPlatformHooks {
throw new AssertionError();
}
@ExpectPlatform
public static Path getGameDirectory() {
default Path getGameDirectory() {
throw new AssertionError();
}
@ExpectPlatform
public static void sendPacket(ServerPlayer player, Object packet) {
default void sendPacket(ServerPlayer player, Object packet) {
throw new AssertionError();
}
@ExpectPlatform
public static void onServerCommandRegister(Consumer<CommandDispatcher<CommandSourceStack>> handler) {
default void onServerCommandRegister(Consumer<CommandDispatcher<CommandSourceStack>> handler) {
throw new AssertionError();
}
@ExpectPlatform
public static Multimap<String, String> getCustomModOptions() {
default Multimap<String, String> getCustomModOptions() {
throw new AssertionError();
}
@ExpectPlatform
public static void onLaunchComplete() {
default void onLaunchComplete() {
}
@ExpectPlatform
public static String getPlatformName() {
default String getPlatformName() {
throw new AssertionError();
}
}

View File

@ -0,0 +1,23 @@
package org.embeddedt.modernfix.platform;
import java.lang.reflect.Constructor;
class PlatformHookLoader {
static ModernFixPlatformHooks findInstance() {
String[] locations = new String[] { "forge", "fabric" };
for(String location : locations) {
try {
Class<?> clz = Class.forName("org.embeddedt.modernfix.platform." + location + ".ModernFixPlatformHooksImpl");
Constructor<?> constructor = clz.getConstructor();
constructor.setAccessible(true);
return (ModernFixPlatformHooks)constructor.newInstance();
} catch(ClassNotFoundException ignored) {
} catch(ReflectiveOperationException | ClassCastException e) {
e.printStackTrace();
}
}
System.err.println("ModernFix has failed to load platform hooks. It cannot function, the game will now close");
Runtime.getRuntime().exit(1);
throw new AssertionError("Somehow couldn't exit");
}
}

View File

@ -172,7 +172,7 @@ public class PackResourcesCacheEngine {
}
public static void invalidate() {
if(!ModernFixPlatformHooks.isDevEnv())
if(!ModernFixPlatformHooks.INSTANCE.isDevEnv())
return;
synchronized (cachingPacks) {
cachingPacks.keySet().forEach(pack -> {

View File

@ -153,7 +153,7 @@ public class OptionList extends ContainerObjectSelectionList<OptionList.Entry> {
});
if(!I18n.exists("modernfix.option." + optionName)) {
this.helpButton.active = false;
if(ModernFixPlatformHooks.isDevEnv() && OPTIONS_MISSING_HELP.add(optionName))
if(ModernFixPlatformHooks.INSTANCE.isDevEnv() && OPTIONS_MISSING_HELP.add(optionName))
ModernFix.LOGGER.warn("Missing help for {}", optionName);
}
}

View File

@ -26,7 +26,7 @@ public class CachingStructureManager {
throw new RuntimeException(e);
}
});
private static final File STRUCTURE_CACHE_FOLDER = FileUtil.childFile(ModernFixPlatformHooks.getGameDirectory().resolve("modernfix").resolve("structureCacheV1").toFile());
private static final File STRUCTURE_CACHE_FOLDER = FileUtil.childFile(ModernFixPlatformHooks.INSTANCE.getGameDirectory().resolve("modernfix").resolve("structureCacheV1").toFile());
static {
STRUCTURE_CACHE_FOLDER.mkdirs();

View File

@ -17,7 +17,6 @@ configurations {
shadowCommon // Don't use shadow from the shadow plugin since it *excludes* files.
compileClasspath.extendsFrom common
runtimeClasspath.extendsFrom common
developmentFabric.extendsFrom common
modIncludeImplementation

View File

@ -20,6 +20,7 @@ import net.minecraft.server.packs.resources.ResourceManager;
import org.embeddedt.modernfix.ModernFixFabric;
import org.embeddedt.modernfix.api.constants.IntegrationConstants;
import org.embeddedt.modernfix.core.ModernFixMixinPlugin;
import org.embeddedt.modernfix.platform.ModernFixPlatformHooks;
import org.embeddedt.modernfix.spark.SparkLaunchProfiler;
import org.embeddedt.modernfix.util.CommonModUtil;
import org.objectweb.asm.tree.*;
@ -28,18 +29,18 @@ import java.nio.file.Path;
import java.util.*;
import java.util.function.Consumer;
public class ModernFixPlatformHooksImpl {
public static boolean isClient() {
public class ModernFixPlatformHooksImpl implements ModernFixPlatformHooks {
public boolean isClient() {
return FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT;
}
public static boolean isDedicatedServer() {
public boolean isDedicatedServer() {
return FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER;
}
private static String verString;
public static String getVersionString() {
public String getVersionString() {
if(verString == null) {
ModContainer mfModContainer = FabricLoader.getInstance().getModContainer("modernfix").get();
verString = mfModContainer.getMetadata().getVersion().getFriendlyString();
@ -47,27 +48,27 @@ public class ModernFixPlatformHooksImpl {
return verString;
}
public static boolean modPresent(String modId) {
public boolean modPresent(String modId) {
return FabricLoader.getInstance().getModContainer(modId).isPresent();
}
public static boolean isDevEnv() {
public boolean isDevEnv() {
return FabricLoader.getInstance().isDevelopmentEnvironment();
}
public static MinecraftServer getCurrentServer() {
public MinecraftServer getCurrentServer() {
return ModernFixFabric.theServer.get();
}
public static boolean isEarlyLoadingNormally() {
public boolean isEarlyLoadingNormally() {
return true;
}
public static boolean isLoadingNormally() {
public boolean isLoadingNormally() {
return true;
}
public static TextureAtlasSprite loadTextureAtlasSprite(TextureAtlas atlasTexture,
public TextureAtlasSprite loadTextureAtlasSprite(TextureAtlas atlasTexture,
ResourceManager resourceManager, TextureAtlasSprite.Info textureInfo,
Resource resource,
int atlasWidth, int atlasHeight,
@ -76,27 +77,27 @@ public class ModernFixPlatformHooksImpl {
return new TextureAtlasSprite(atlasTexture, textureInfo, mipmapLevel, atlasWidth, atlasHeight, spriteX, spriteY, image);
}
public static Path getGameDirectory() {
public Path getGameDirectory() {
return FabricLoader.getInstance().getGameDir();
}
public static void sendPacket(ServerPlayer player, Object packet) {
public void sendPacket(ServerPlayer player, Object packet) {
//PacketHandler.INSTANCE.send(PacketDistributor.PLAYER.with(() -> player), packet);
}
public static void injectPlatformSpecificHacks() {
public void injectPlatformSpecificHacks() {
}
public static void applyASMTransformers(String mixinClassName, ClassNode targetClass) {
public void applyASMTransformers(String mixinClassName, ClassNode targetClass) {
}
public static void onServerCommandRegister(Consumer<CommandDispatcher<CommandSourceStack>> handler) {
public void onServerCommandRegister(Consumer<CommandDispatcher<CommandSourceStack>> handler) {
CommandRegistrationCallback.EVENT.register((dispatcher, arg) -> handler.accept(dispatcher));
}
private static Multimap<String, String> modOptions;
public static Multimap<String, String> getCustomModOptions() {
public Multimap<String, String> getCustomModOptions() {
if(modOptions == null) {
modOptions = ArrayListMultimap.create();
for (ModContainer container : FabricLoader.getInstance().getAllMods()) {
@ -117,13 +118,13 @@ public class ModernFixPlatformHooksImpl {
return modOptions;
}
public static void onLaunchComplete() {
public void onLaunchComplete() {
if(ModernFixMixinPlugin.instance.isOptionEnabled("feature.spark_profile_launch.OnFabric")) {
CommonModUtil.runWithoutCrash(() -> SparkLaunchProfiler.stop("launch"), "Failed to stop profiler");
}
}
public static String getPlatformName() {
public String getPlatformName() {
return "Fabric";
}
}

View File

@ -25,7 +25,6 @@ configurations {
shadowCommon // Don't use shadow from the shadow plugin since it *excludes* files.
compileClasspath.extendsFrom common
runtimeClasspath.extendsFrom common
developmentForge.extendsFrom common
}
dependencies {

View File

@ -27,6 +27,7 @@ import org.embeddedt.modernfix.api.constants.IntegrationConstants;
import org.embeddedt.modernfix.forge.classloading.FastAccessTransformerList;
import org.embeddedt.modernfix.forge.config.NightConfigFixer;
import org.embeddedt.modernfix.forge.packet.PacketHandler;
import org.embeddedt.modernfix.platform.ModernFixPlatformHooks;
import org.embeddedt.modernfix.spark.SparkLaunchProfiler;
import org.embeddedt.modernfix.util.CommonModUtil;
import org.embeddedt.modernfix.util.DummyList;
@ -42,18 +43,18 @@ import java.util.Map;
import java.util.Objects;
import java.util.function.Consumer;
public class ModernFixPlatformHooksImpl {
public static boolean isClient() {
public class ModernFixPlatformHooksImpl implements ModernFixPlatformHooks {
public boolean isClient() {
return FMLLoader.getDist() == Dist.CLIENT;
}
public static boolean isDedicatedServer() {
public boolean isDedicatedServer() {
return FMLLoader.getDist().isDedicatedServer();
}
private static String verString;
public static String getVersionString() {
public String getVersionString() {
if(verString == null) {
try {
verString = ModernFixMixinPlugin.class.getPackage().getImplementationVersion();
@ -65,28 +66,28 @@ public class ModernFixPlatformHooksImpl {
return verString;
}
public static boolean modPresent(String modId) {
public boolean modPresent(String modId) {
return FMLLoader.getLoadingModList().getModFileById(modId) != null;
}
public static boolean isDevEnv() {
public boolean isDevEnv() {
return !FMLLoader.isProduction();
}
public static MinecraftServer getCurrentServer() {
public MinecraftServer getCurrentServer() {
return ServerLifecycleHooks.getCurrentServer();
}
public static boolean isEarlyLoadingNormally() {
public boolean isEarlyLoadingNormally() {
return LoadingModList.get().getErrors().isEmpty();
}
public static boolean isLoadingNormally() {
public boolean isLoadingNormally() {
return isEarlyLoadingNormally() && ModLoader.isLoadingStateValid();
}
public static TextureAtlasSprite loadTextureAtlasSprite(TextureAtlas atlasTexture,
public TextureAtlasSprite loadTextureAtlasSprite(TextureAtlas atlasTexture,
ResourceManager resourceManager, TextureAtlasSprite.Info textureInfo,
Resource resource,
int atlasWidth, int atlasHeight,
@ -128,15 +129,15 @@ public class ModernFixPlatformHooksImpl {
}
}
public static Path getGameDirectory() {
public Path getGameDirectory() {
return FMLPaths.GAMEDIR.get();
}
public static void sendPacket(ServerPlayer player, Object packet) {
public void sendPacket(ServerPlayer player, Object packet) {
PacketHandler.INSTANCE.send(PacketDistributor.PLAYER.with(() -> player), packet);
}
public static void injectPlatformSpecificHacks() {
public void injectPlatformSpecificHacks() {
FastAccessTransformerList.attemptReplace();
/* https://github.com/FabricMC/Mixin/pull/99 */
@ -158,18 +159,18 @@ public class ModernFixPlatformHooksImpl {
NightConfigFixer.monitorFileWatcher();
}
public static void applyASMTransformers(String mixinClassName, ClassNode targetClass) {
public void applyASMTransformers(String mixinClassName, ClassNode targetClass) {
}
public static void onServerCommandRegister(Consumer<CommandDispatcher<CommandSourceStack>> handler) {
public void onServerCommandRegister(Consumer<CommandDispatcher<CommandSourceStack>> handler) {
MinecraftForge.EVENT_BUS.addListener((RegisterCommandsEvent event) -> {
handler.accept(event.getDispatcher());
});
}
private static Multimap<String, String> modOptions;
public static Multimap<String, String> getCustomModOptions() {
public Multimap<String, String> getCustomModOptions() {
if(modOptions == null) {
modOptions = ArrayListMultimap.create();
for (ModInfo meta : LoadingModList.get().getMods()) {
@ -188,13 +189,13 @@ public class ModernFixPlatformHooksImpl {
return modOptions;
}
public static void onLaunchComplete() {
public void onLaunchComplete() {
if(ModernFixMixinPlugin.instance.isOptionEnabled("feature.spark_profile_launch.OnForge")) {
CommonModUtil.runWithoutCrash(() -> SparkLaunchProfiler.stop("launch"), "Failed to stop profiler");
}
}
public static String getPlatformName() {
public String getPlatformName() {
return "Forge";
}
}