Switch to compile-only Arch Transformer
This commit is contained in:
parent
2663f5e3f4
commit
13cc103be2
13
build.gradle
13
build.gradle
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,9 +42,9 @@ public class ModernFixClient {
|
|||
// clear reserve as it's not needed
|
||||
Minecraft.reserve = new byte[0];
|
||||
if(ModernFixMixinPlugin.instance.isOptionEnabled("feature.branding.F3Screen")) {
|
||||
brandingString = ModernFix.NAME + " " + ModernFixPlatformHooks.getVersionString();
|
||||
brandingString = ModernFix.NAME + " " + ModernFixPlatformHooks.INSTANCE.getVersionString();
|
||||
}
|
||||
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) {
|
||||
|
|
@ -67,7 +67,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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ public class ChunkGeneratorMixin {
|
|||
}
|
||||
|
||||
private ServerLevel searchLevel() {
|
||||
MinecraftServer server = ModernFixPlatformHooks.getCurrentServer();
|
||||
MinecraftServer server = ModernFixPlatformHooks.INSTANCE.getCurrentServer();
|
||||
if(server != null) {
|
||||
ServerLevel ourLevel = null;
|
||||
for (ServerLevel level : server.getAllLevels()) {
|
||||
|
|
|
|||
|
|
@ -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(), width, height, originX, originY, mipmapLevel, pair.getSecond());
|
||||
sprite = ModernFixPlatformHooks.INSTANCE.loadTextureAtlasSprite((TextureAtlas)(Object)this, resourceManager, spriteInfo, pair.getFirst(), width, height, originX, originY, mipmapLevel, pair.getSecond());
|
||||
} catch(RuntimeException e) {
|
||||
ModernFix.LOGGER.error("Error loading texture {}: {}", spriteInfo.name(), e);
|
||||
} finally {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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());
|
||||
|
|
@ -151,7 +151,7 @@ public class ModernFixEarlyConfig {
|
|||
}
|
||||
|
||||
private static final boolean shouldReplaceSearchTrees;
|
||||
private static final boolean isDevEnv = ModernFixPlatformHooks.isDevEnv();
|
||||
private static final boolean isDevEnv = ModernFixPlatformHooks.INSTANCE.isDevEnv();
|
||||
|
||||
static {
|
||||
shouldReplaceSearchTrees = modPresent("jei");
|
||||
|
|
@ -174,7 +174,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.bugfix.packet_leak", false)
|
||||
.put("mixin.perf.deduplicate_location", false)
|
||||
|
|
@ -245,7 +245,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);
|
||||
|
|
|
|||
|
|
@ -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<>();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
@ -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 -> {
|
||||
|
|
|
|||
|
|
@ -147,7 +147,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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import org.embeddedt.modernfix.ModernFixFabric;
|
|||
import org.embeddedt.modernfix.api.constants.IntegrationConstants;
|
||||
import org.embeddedt.modernfix.core.ModernFixMixinPlugin;
|
||||
import org.embeddedt.modernfix.fabric.spark.SparkLaunchProfiler;
|
||||
import org.embeddedt.modernfix.platform.ModernFixPlatformHooks;
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import org.embeddedt.modernfix.forge.classloading.ModernFixResourceFinder;
|
|||
import org.embeddedt.modernfix.forge.config.NightConfigFixer;
|
||||
import org.embeddedt.modernfix.forge.packet.PacketHandler;
|
||||
import org.embeddedt.modernfix.forge.spark.SparkLaunchProfiler;
|
||||
import org.embeddedt.modernfix.platform.ModernFixPlatformHooks;
|
||||
import org.embeddedt.modernfix.util.CommonModUtil;
|
||||
import org.embeddedt.modernfix.util.DummyList;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
|
@ -56,18 +57,18 @@ import java.util.Optional;
|
|||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
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();
|
||||
|
|
@ -79,28 +80,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,
|
||||
|
|
@ -142,15 +143,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() {
|
||||
/* We abuse the constructor of a mixin plugin as a safe location to start modifying the classloader */
|
||||
/* Swap the transformer for ours */
|
||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||
|
|
@ -227,7 +228,7 @@ public class ModernFixPlatformHooksImpl {
|
|||
return resourceEnumeratorLocator;
|
||||
}
|
||||
|
||||
public static void applyASMTransformers(String mixinClassName, ClassNode targetClass) {
|
||||
public void applyASMTransformers(String mixinClassName, ClassNode targetClass) {
|
||||
if(mixinClassName.equals("org.embeddedt.modernfix.forge.mixin.bugfix.chunk_deadlock.valhesia.BlockStateBaseMixin")) {
|
||||
// We need to destroy Valhelsia's callback so it can never run getBlockState
|
||||
for(MethodNode m : targetClass.methods) {
|
||||
|
|
@ -239,14 +240,14 @@ public class ModernFixPlatformHooksImpl {
|
|||
}
|
||||
}
|
||||
|
||||
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()) {
|
||||
|
|
@ -265,13 +266,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";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user