Skip to content

Commit

Permalink
load custom injection point class using mixin plugin instead of ModIn…
Browse files Browse the repository at this point in the history
…itializer
  • Loading branch information
Hadron67 committed Aug 13, 2020
1 parent 1664dfe commit 0d373fe
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 19 deletions.
22 changes: 4 additions & 18 deletions src/main/java/com/hadroncfy/sreplay/SReplayMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,23 @@
import java.util.Collections;
import java.util.List;

import com.google.gson.JsonParseException;
import com.hadroncfy.sreplay.asm.MultipleOrdinalFieldInjectionPoint;
import com.hadroncfy.sreplay.command.SReplayCommand;
import com.hadroncfy.sreplay.config.Config;
import com.hadroncfy.sreplay.config.Formats;
import com.hadroncfy.sreplay.recording.Photographer;
import com.hadroncfy.sreplay.server.Server;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.mixin.injection.InjectionPoint;

public class SReplayMod implements ModInitializer {

private static final Logger LOGGER = LogManager.getLogger();
private static Config config;
private static final Server downloadServer = new Server();

public static final SReplayCommand SREPLAY_COMMAND = new SReplayCommand();

public static Photographer getFake(MinecraftServer server, String name) {
ServerPlayerEntity player = server.getPlayerManager().getPlayer(name);
if (player != null && player instanceof Photographer) {
if (player instanceof Photographer) {
return (Photographer) player;
}
return null;
Expand All @@ -55,7 +49,7 @@ public static List<File> listRecordings() {
return files;
}

public static void loadConfig() throws IOException, JsonParseException {
public static void loadConfig() throws IOException {
File dir = new File("config");
if (!dir.exists()) {
dir.mkdirs();
Expand Down Expand Up @@ -83,14 +77,13 @@ public static Formats getFormats() {

@Override
public void onInitialize() {
InjectionPoint.register(MultipleOrdinalFieldInjectionPoint.class);

try {
SReplayMod.loadConfig();
Lang.load("zh_cn");
LOGGER.info("SReplay: Initialzed");
} catch (Throwable e) {
LOGGER.error("Exception initializing mod: " + e);
} catch (Exception e) {
LOGGER.error("Exception initializing mod: {}", e);
e.printStackTrace();
}

Expand All @@ -101,13 +94,6 @@ public void onInitialize() {
if (!config.savePath.exists()) {
config.savePath.mkdirs();
}

try {
LOGGER.info("!!!! test: {}",
Class.forName("com.hadroncfy.sreplay.asm.MultipleOrdinalFieldInjectionPoint").getName());
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}

}
48 changes: 48 additions & 0 deletions src/main/java/com/hadroncfy/sreplay/asm/MixinConfigPlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.hadroncfy.sreplay.asm;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
import org.spongepowered.asm.mixin.injection.InjectionPoint;

public class MixinConfigPlugin implements IMixinConfigPlugin {

@Override
public void onLoad(String mixinPackage) {
InjectionPoint.register(MultipleOrdinalFieldInjectionPoint.class);
}

@Override
public String getRefMapperConfig() {
return null;
}

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
return true;
}

@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
// nop
}

@Override
public List<String> getMixins() {
return new ArrayList<>();
}

@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
// nop
}

@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
// nop
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.hadroncfy.sreplay.mixin;


import com.hadroncfy.sreplay.recording.Photographer;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.InjectionPoint;
import org.spongepowered.asm.mixin.injection.Redirect;

import net.minecraft.network.Packet;
Expand All @@ -15,6 +15,8 @@

import static com.hadroncfy.sreplay.recording.Photographer.getRealViewDistance;

import com.hadroncfy.sreplay.asm.MultipleOrdinalFieldInjectionPoint;

@Mixin(ThreadedAnvilChunkStorage.class)
public abstract class MixinThreadedAnvilChunkStorage {
@Shadow private int watchDistance;
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/sreplay.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
"injectors": {
"defaultRequire": 1
},
"plugin": "com.hadroncfy.sreplay.asm.MixinConfigPlugin",
"refmap": "sreplay-refmap.json"
}

0 comments on commit 0d373fe

Please sign in to comment.