made a better working multiloader build process
This commit is contained in:
@@ -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.");
|
||||
}
|
||||
}
|
11
common/src/main/java/com/vaporvee/loadsupport/Constants.java
Normal file
11
common/src/main/java/com/vaporvee/loadsupport/Constants.java
Normal 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);
|
||||
}
|
@@ -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());
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -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";
|
||||
}
|
||||
}
|
16
common/src/main/resources/loadsupport.mixins.json
Normal file
16
common/src/main/resources/loadsupport.mixins.json
Normal 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
|
||||
}
|
||||
}
|
||||
|
6
common/src/main/resources/pack.mcmeta
Normal file
6
common/src/main/resources/pack.mcmeta
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"pack": {
|
||||
"description": "${mod_name}",
|
||||
"pack_format": 8
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user