Skip to content

Commit

Permalink
Update and fix mixins with examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
Crystal-Spider committed Mar 7, 2024
1 parent 61af2fa commit 8737dd4
Show file tree
Hide file tree
Showing 14 changed files with 169 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package crystalnest.cobweb_mod_template;

import crystalnest.cobweb_mod_template.platform.Services;
import crystalnest.cobweb_mod_template.platform.services.PlatformHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -18,4 +20,9 @@ private Constants() {}
* Mod logger.
*/
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

/**
* Provides information about what platform the mod is running on.
*/
public static final PlatformHelper PLATFORM = Services.load(PlatformHelper.class);
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package crystalnest.cobweb_mod_template.mixin;

import crystalnest.cobweb_mod_template.Constants;
import net.minecraft.client.gui.components.LogoRenderer;
import net.minecraft.client.gui.screens.TitleScreen;
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;

/**
* Example mixin class.
*/
@Mixin(TitleScreen.class)
public class TitleScreenMixin {
/**
* Injects at the end of the base constructor to print an example message.
*
* @param fading
* @param logoRenderer
* @param ci
*/
@Inject(method = "<init>(ZLnet/minecraft/client/gui/components/LogoRenderer;)V", at = @At(value = "TAIL"))
private void onInit(boolean fading, LogoRenderer logoRenderer, CallbackInfo ci) {
Constants.LOGGER.info("Example mixin from " + Constants.PLATFORM.getPlatformName());
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package crystalnest.cobweb_mod_template.platform;

import crystalnest.cobweb_mod_template.Constants;
import crystalnest.cobweb_mod_template.platform.services.PlatformHelper;

import java.util.ServiceLoader;

Expand All @@ -10,11 +9,6 @@
* 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 final class Services {
/**
* Provides information about what platform the mod is running on.
*/
public static final PlatformHelper PLATFORM = load(PlatformHelper.class);

private Services() {}

/**
Expand Down
4 changes: 3 additions & 1 deletion common/src/main/resources/cobweb_mod_template.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"package": "${group}.${mod_id}.mixin",
"refmap": "${mod_id}.refmap.json",
"compatibilityLevel": "JAVA_17",
"mixins": [],
"mixins": [
"TitleScreenMixin"
],
"client": [],
"server": [],
"injectors": {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package crystalnest.cobweb_mod_template.mixin;

import com.mojang.datafixers.DataFixer;
import crystalnest.cobweb_mod_template.Constants;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.Services;
import net.minecraft.server.WorldStem;
import net.minecraft.server.level.progress.ChunkProgressListenerFactory;
import net.minecraft.server.packs.repository.PackRepository;
import net.minecraft.world.level.storage.LevelStorageSource;
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;

import java.net.Proxy;

/**
* Example mixin class.
*/
@Mixin(MinecraftServer.class)
public class MinecraftServerMixin {
/**
* Injects at the end of the base constructor to print an example message.
*
* @param thread
* @param levelStorageAccess
* @param packRepository
* @param worldStem
* @param proxy
* @param dataFixer
* @param services
* @param chunkProgressListenerFactory
* @param ci
*/
@Inject(method = "<init>", at = @At(value = "TAIL"))
private void onInit(Thread thread, LevelStorageSource.LevelStorageAccess levelStorageAccess, PackRepository packRepository, WorldStem worldStem, Proxy proxy, DataFixer dataFixer, Services services, ChunkProgressListenerFactory chunkProgressListenerFactory, CallbackInfo ci) {
Constants.LOGGER.info("Example mixin from Fabric");
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"required": true,
"minVersion": "0.8",
"package": "${group}.mixin",
"package": "${group}.${mod_id}.mixin",
"refmap": "${mod_id}.refmap.json",
"compatibilityLevel": "JAVA_17",
"mixins": [],
"mixins": [
"MinecraftServerMixin"
],
"client": [],
"server": [],
"injectors": {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package crystalnest.cobweb_mod_template.mixin;

import com.mojang.datafixers.DataFixer;
import crystalnest.cobweb_mod_template.Constants;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.Services;
import net.minecraft.server.WorldStem;
import net.minecraft.server.level.progress.ChunkProgressListenerFactory;
import net.minecraft.server.packs.repository.PackRepository;
import net.minecraft.world.level.storage.LevelStorageSource;
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;

import java.net.Proxy;

/**
* Example mixin class.
*/
@Mixin(MinecraftServer.class)
public class MinecraftServerMixin {
/**
* Injects at the end of the base constructor to print an example message.
*
* @param thread
* @param levelStorageAccess
* @param packRepository
* @param worldStem
* @param proxy
* @param dataFixer
* @param services
* @param chunkProgressListenerFactory
* @param ci
*/
@Inject(method = "<init>", at = @At(value = "TAIL"))
private void onInit(Thread thread, LevelStorageSource.LevelStorageAccess levelStorageAccess, PackRepository packRepository, WorldStem worldStem, Proxy proxy, DataFixer dataFixer, Services services, ChunkProgressListenerFactory chunkProgressListenerFactory, CallbackInfo ci) {
Constants.LOGGER.info("Example mixin from Forge");
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"required": true,
"minVersion": "0.8",
"package": "${group}.mixin",
"package": "${group}.${mod_id}.mixin",
"refmap": "${mod_id}.refmap.json",
"compatibilityLevel": "JAVA_17",
"mixins": [],
"mixins": [
"MinecraftServerMixin"
],
"client": [],
"server": [],
"injectors": {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package crystalnest.cobweb_mod_template.mixin;

import com.mojang.datafixers.DataFixer;
import crystalnest.cobweb_mod_template.Constants;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.Services;
import net.minecraft.server.WorldStem;
import net.minecraft.server.level.progress.ChunkProgressListenerFactory;
import net.minecraft.server.packs.repository.PackRepository;
import net.minecraft.world.level.storage.LevelStorageSource;
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;

import java.net.Proxy;

/**
* Example mixin class.
*/
@Mixin(MinecraftServer.class)
public class MinecraftServerMixin {
/**
* Injects at the end of the base constructor to print an example message.
*
* @param thread
* @param levelStorageAccess
* @param packRepository
* @param worldStem
* @param proxy
* @param dataFixer
* @param services
* @param chunkProgressListenerFactory
* @param ci
*/
@Inject(method = "<init>", at = @At(value = "TAIL"))
private void onInit(Thread thread, LevelStorageSource.LevelStorageAccess levelStorageAccess, PackRepository packRepository, WorldStem worldStem, Proxy proxy, DataFixer dataFixer, Services services, ChunkProgressListenerFactory chunkProgressListenerFactory, CallbackInfo ci) {
Constants.LOGGER.info("Example mixin from NeoForge");
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"required": true,
"minVersion": "0.8",
"package": "${group}.mixin",
"package": "${group}.${mod_id}.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [],
"mixins": [
"MinecraftServerMixin"
],
"client": [],
"server": [],
"injectors": {
Expand Down

0 comments on commit 8737dd4

Please sign in to comment.