made a better working multiloader build process

This commit is contained in:
2025-06-19 22:35:40 +02:00
parent b1b02afd46
commit 2effc8a6eb
59 changed files with 749 additions and 1367 deletions

41
common/build.gradle Normal file
View File

@@ -0,0 +1,41 @@
plugins {
id 'multiloader-common'
id 'net.neoforged.moddev'
}
neoForge {
neoFormVersion = neo_form_version
// Automatically enable AccessTransformers if the file exists
def at = file('src/main/resources/META-INF/accesstransformer.cfg')
if (at.exists()) {
accessTransformers.from(at.absolutePath)
}
parchment {
minecraftVersion = parchment_minecraft
mappingsVersion = parchment_version
}
}
dependencies {
compileOnly group: 'org.spongepowered', name: 'mixin', version: '0.8.5'
// fabric and neoforge both bundle mixinextras, so it is safe to use it in common
compileOnly group: 'io.github.llamalad7', name: 'mixinextras-common', version: '0.3.5'
annotationProcessor group: 'io.github.llamalad7', name: 'mixinextras-common', version: '0.3.5'
}
configurations {
commonJava {
canBeResolved = false
canBeConsumed = true
}
commonResources {
canBeResolved = false
canBeConsumed = true
}
}
artifacts {
commonJava sourceSets.main.java.sourceDirectories.singleFile
commonResources sourceSets.main.resources.sourceDirectories.singleFile
}

View File

@@ -0,0 +1,18 @@
package com.vaporvee.loadsupport;
import com.vaporvee.loadsupport.platform.Services;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.item.Items;
public class CommonClass {
public static void init() {
// Constants.LOG.info("Hello from Common init on {}! we are currently in a {} environment!", Services.PLATFORM.getPlatformName(), Services.PLATFORM.getEnvironmentName());
// Constants.LOG.info("The ID for diamonds is {}", BuiltInRegistries.ITEM.getKey(Items.DIAMOND));
// if (Services.PLATFORM.isModLoaded("loadsupport"))
if (Services.PLATFORM.isEnvServer()) {
Constants.LOG.info(Constants.MOD_ID + " is a client mod only!");
return;
}
Constants.LOG.info("Loading Load Support mod.");
}
}

View File

@@ -0,0 +1,11 @@
package com.vaporvee.loadsupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Constants {
public static final String MOD_ID = "loadsupport";
public static final String MOD_NAME = "LoadSupport";
public static final Logger LOG = LoggerFactory.getLogger(MOD_NAME);
}

View File

@@ -0,0 +1,19 @@
package com.vaporvee.loadsupport.mixin;
import com.vaporvee.loadsupport.Constants;
import net.minecraft.client.Minecraft;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(Minecraft.class)
public class MixinMinecraft {
@Inject(at = @At("TAIL"), method = "<init>")
private void init(CallbackInfo info) {
Constants.LOG.info("This line is printed by an example mod common mixin!");
Constants.LOG.info("MC Version: {}", Minecraft.getInstance().getVersionType());
}
}

View File

@@ -0,0 +1,30 @@
package com.vaporvee.loadsupport.platform;
import com.vaporvee.loadsupport.Constants;
import com.vaporvee.loadsupport.platform.services.IPlatformHelper;
import java.util.ServiceLoader;
// Service loaders are a built-in Java feature that allow us to locate implementations of an interface that vary from one
// environment to another. In the context of MultiLoader we use this feature to access a mock API in the common code that
// is swapped out for the platform specific implementation at runtime.
public class Services {
// In this example we provide a platform helper which provides information about what platform the mod is running on.
// For example this can be used to check if the code is running on Forge vs Fabric, or to ask the modloader if another
// mod is loaded.
public static final IPlatformHelper PLATFORM = load(IPlatformHelper.class);
// This code is used to load a service for the current environment. Your implementation of the service must be defined
// manually by including a text file in META-INF/services named with the fully qualified class name of the service.
// Inside the file you should write the fully qualified class name of the implementation to load for the platform. For
// example our file on Forge points to ForgePlatformHelper while Fabric points to FabricPlatformHelper.
public static <T> T load(Class<T> clazz) {
final T loadedService = ServiceLoader.load(clazz)
.findFirst()
.orElseThrow(() -> new NullPointerException("Failed to load service for " + clazz.getName()));
Constants.LOG.debug("Loaded {} for service {}", loadedService, clazz);
return loadedService;
}
}

View File

@@ -0,0 +1,43 @@
package com.vaporvee.loadsupport.platform.services;
public interface IPlatformHelper {
/**
* Gets the name of the current platform
*
* @return The name of the current platform.
*/
String getPlatformName();
/**
* Checks if a mod with the given id is loaded.
*
* @param modId The mod to check if it is loaded.
* @return True if the mod is loaded, false otherwise.
*/
boolean isModLoaded(String modId);
/**
* Check if the game is currently in a client environment.
*
* @return True if in a client environment, false otherwise.
*/
boolean isEnvServer();
/**
* Check if the game is currently in a development environment.
*
* @return True if in a development environment, false otherwise.
*/
boolean isDevelopmentEnvironment();
/**
* Gets the name of the environment type as a string.
*
* @return The name of the environment type.
*/
default String getEnvironmentName() {
return isDevelopmentEnvironment() ? "development" : "production";
}
}

View File

@@ -0,0 +1,16 @@
{
"required": true,
"minVersion": "0.8",
"package": "com.vaporvee.loadsupport.mixin",
"refmap": "${mod_id}.refmap.json",
"compatibilityLevel": "JAVA_18",
"mixins": [],
"client": [
"MixinMinecraft"
],
"server": [],
"injectors": {
"defaultRequire": 1
}
}

View File

@@ -0,0 +1,6 @@
{
"pack": {
"description": "${mod_name}",
"pack_format": 8
}
}