-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
95 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,14 @@ | ||
package wtf.zani.vanillamenu; | ||
|
||
import club.maxstats.weave.loader.api.HookManager; | ||
import club.maxstats.weave.loader.api.ModInitializer; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.jetbrains.annotations.NotNull; | ||
import wtf.zani.vanillamenu.hooks.MinecraftClientHook; | ||
|
||
public class VanillaMenu implements ModInitializer { | ||
public static final Logger logger = LogManager.getLogger(); | ||
|
||
@Override | ||
public void preInit(@NotNull HookManager hookManager) { | ||
logger.info("Adding Vanilla Menu's hook"); | ||
|
||
hookManager.register(new MinecraftClientHook()); | ||
public void init() { | ||
logger.info("Initializing VanillaMenu"); | ||
} | ||
} |
105 changes: 0 additions & 105 deletions
105
src/main/java/wtf/zani/vanillamenu/hooks/MinecraftClientHook.java
This file was deleted.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
src/main/java/wtf/zani/vanillamenu/hooks/VanillaMenuHook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package wtf.zani.vanillamenu.hooks; | ||
|
||
import club.maxstats.weave.loader.api.Hook; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.objectweb.asm.tree.ClassNode; | ||
import org.objectweb.asm.tree.InsnList; | ||
import org.objectweb.asm.tree.MethodInsnNode; | ||
import org.objectweb.asm.tree.MethodNode; | ||
|
||
import java.util.Arrays; | ||
|
||
@SuppressWarnings("unused") | ||
public class VanillaMenuHook extends Hook { | ||
public VanillaMenuHook() { | ||
super("net/minecraft/client/Minecraft"); | ||
} | ||
|
||
@Override | ||
public void transform(@NotNull ClassNode classNode, @NotNull AssemblerConfig assemblerConfig) { | ||
final MethodNode displayGuiScreen = classNode.methods | ||
.stream() | ||
.filter(methodNode -> methodNode.name.equals("displayGuiScreen")) | ||
.findFirst() | ||
.orElseThrow(); | ||
final InsnList filteredInstructions = new InsnList(); | ||
|
||
Arrays.stream(displayGuiScreen.instructions.toArray()) | ||
.filter(instruction -> { | ||
if (instruction instanceof final MethodInsnNode methodCall) { | ||
return !methodCall.name.endsWith("$impl$displayGuiScreen"); | ||
} | ||
|
||
return true; | ||
}) | ||
.forEach(filteredInstructions::add); | ||
|
||
assemblerConfig.computeFrames(); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/wtf/zani/vanillamenu/mixin/MinecraftMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package wtf.zani.vanillamenu.mixin; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.GuiMainMenu; | ||
import net.minecraft.client.gui.GuiScreen; | ||
import net.minecraft.client.multiplayer.WorldClient; | ||
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.ModifyVariable; | ||
import wtf.zani.vanillamenu.VanillaMenu; | ||
|
||
@Mixin(Minecraft.class) | ||
public class MinecraftMixin { | ||
@Shadow | ||
public WorldClient theWorld; | ||
|
||
private boolean isFirst = true; | ||
|
||
@ModifyVariable(at = @At(value = "HEAD"), method = "displayGuiScreen", argsOnly = true) | ||
public GuiScreen modifyScreen(GuiScreen screen) { | ||
if (this.theWorld == null && screen != null && !screen.getClass().getName().startsWith("net.minecraft") && isFirst) { | ||
isFirst = false; | ||
|
||
VanillaMenu.logger.info("Replaced Lunar's main menu!"); | ||
|
||
return new GuiMainMenu(); | ||
} | ||
|
||
return screen; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"compatibilityLevel": "JAVA_8", | ||
"package": "wtf.zani.vanillamenu.mixin", | ||
"mixins": [ | ||
"MinecraftMixin" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"mixinConfigs": [ | ||
"vanillamenu.mixins.json" | ||
], | ||
"hooks": [ | ||
"wtf.zani.vanillamenu.hooks.VanillaMenuHook" | ||
], | ||
"entrypoints": [ | ||
"wtf.zani.vanillamenu.VanillaMenu" | ||
] | ||
} |