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

This commit is contained in:
embeddedt 2023-05-14 19:26:03 -04:00
commit 33d7b6f67b
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
3 changed files with 46 additions and 0 deletions

View File

@ -35,6 +35,7 @@ dependencies {
modIncludeImplementation(fabricApi.module("fabric-command-api-v2", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' }
modIncludeImplementation(fabricApi.module("fabric-models-v0", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' }
modImplementation(fabricApi.module("fabric-resource-loader-v0", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' }
modImplementation(fabricApi.module("fabric-data-generation-api-v1", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' }
modCompileOnly("com.terraformersmc:modmenu:${rootProject.modmenu_version}") { transitive false }
// Remove the next line if you don't want to depend on the API
// modApi "me.shedaniel:architectury-fabric:${rootProject.architectury_version}"

View File

@ -4,7 +4,9 @@ import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.Minecraft;
import org.embeddedt.modernfix.fabric.datagen.RuntimeDatagen;
import java.util.concurrent.atomic.AtomicBoolean;
@ -29,5 +31,8 @@ public class ModernFixClientFabric implements ClientModInitializer {
ServerLifecycleEvents.SERVER_STARTED.register(server -> {
commonMod.onServerStarted(server);
});
if(FabricLoader.getInstance().isModLoaded("fabric-data-generation-api-v1")) {
RuntimeDatagen.init();
}
}
}

View File

@ -0,0 +1,40 @@
package org.embeddedt.modernfix.fabric.datagen;
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
import net.fabricmc.fabric.impl.datagen.FabricDataGenHelper;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.TitleScreen;
import net.minecraft.network.chat.TextComponent;
import org.embeddedt.modernfix.ModernFix;
import java.lang.reflect.Method;
public class RuntimeDatagen {
private static final boolean SHOULD_RUNTIME_DATAGEN = System.getProperty("fabric-api.datagen.output-dir") != null;
private static void runRuntimeDatagen() {
// call runInternal directly to avoid exiting immediately
try {
System.setProperty("fabric-api.datagen", "true");
Method method = FabricDataGenHelper.class.getDeclaredMethod("runInternal");
method.setAccessible(true);
method.invoke(null);
} catch(Throwable e) {
ModernFix.LOGGER.error("Error running datagen", e);
} finally {
System.clearProperty("fabric-api.datagen");
}
}
public static void init() {
if(!SHOULD_RUNTIME_DATAGEN)
return;
ScreenEvents.AFTER_INIT.register(((client, s, scaledWidth, scaledHeight) -> {
if(s instanceof TitleScreen screen) {
screen.addRenderableWidget(new Button(screen.width / 2 - 100 - 50, screen.height / 4 + 48, 50, 20, new TextComponent("DG"), (arg) -> {
runRuntimeDatagen();
}));
}
}));
}
}