Skip to content

Commit

Permalink
MineTogether Integration
Browse files Browse the repository at this point in the history
  • Loading branch information
MORIMORI0317 committed Aug 16, 2022
1 parent 164aa40 commit 3cf1c84
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 17 deletions.
12 changes: 12 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,16 @@ buildscript {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true
classpath group: 'org.spongepowered', name: 'mixingradle', version: '0.7-SNAPSHOT'
}
}
repositories {
maven {
url "https://cursemaven.com"
}
maven {
url "https://maven.architectury.dev/"
}
}
dependencies {
compileOnly fg.deobf("curse.maven:ctm-267172:3805535");//MineTogether
compileOnly fg.deobf("dev.architectury:architectury-forge:4.9.83")
}
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fg_version=1.18-38.0.12
#-----------------------------
mod_name=GameMenuModOption
mod_id=gamemenumodoption
mod_version=1.14
mod_version=1.14.1
mod_group=net.morimori0317
mod_vendor=MORIMORI0317
mod_implevendor=MORIMORI0317
Expand All @@ -21,7 +21,7 @@ curesforge_id=353051
modrinth_id=7V0nY9Tu
release_type=release
loader_type=Forge
support_versions=1.18
support_versions=1.18,1.18.1,1.18.2
required_mods=
optional_mods=catalogue
embedded_mods=
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/net/morimori0317/gamemenumodoption/ClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.config.ModConfig;
import org.apache.commons.lang3.tuple.Pair;

public class ClientConfig {
public static ForgeConfigSpec.ConfigValue<Boolean> ShowNotificationModUpdate;
public static ForgeConfigSpec.ConfigValue<Boolean> RenderModListBackground;
public static ForgeConfigSpec.ConfigValue<Boolean> SlideUpGameMenuButtons;
public static ForgeConfigSpec.ConfigValue<Boolean> MineTogetherCompatibility;

public static void init() {
Pair<ConfigLoder, ForgeConfigSpec> client_config = new ForgeConfigSpec.Builder().configure(ConfigLoder::new);
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, client_config.getRight());
var config = buildConfig(new ForgeConfigSpec.Builder()).build();
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, config);
}

public static class ConfigLoder {
public ConfigLoder(ForgeConfigSpec.Builder builder) {
builder.push("General");
ShowNotificationModUpdate = builder.define("Show notification mod update", true);
RenderModListBackground = builder.define("Render mod list background", true);
SlideUpGameMenuButtons = builder.define("Slide up game menu buttons", true);
builder.pop();
}
private static ForgeConfigSpec.Builder buildConfig(ForgeConfigSpec.Builder builder) {
builder.push("General");
ShowNotificationModUpdate = builder.define("Show notification mod update", true);
RenderModListBackground = builder.define("Render mod list background", true);
SlideUpGameMenuButtons = builder.define("Slide up game menu buttons", true);
MineTogetherCompatibility = builder.define("MineTogether Compatibility", true);
builder.pop();
return builder;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package net.morimori0317.gamemenumodoption.integration;

import net.minecraft.client.Minecraft;
import net.minecraftforge.fml.ModList;
import net.morimori0317.gamemenumodoption.ClientConfig;

public class MineTogetherIntegration {
public static boolean isCompat() {
return ModList.get().isLoaded("minetogether") && ClientConfig.MineTogetherCompatibility.get();
}

public static boolean isFixButtons() {
return isCompat() && Minecraft.getInstance().getSingleplayerServer() != null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package net.morimori0317.gamemenumodoption.mixin;

import dev.architectury.hooks.client.screen.ScreenAccess;
import net.creeperhost.minetogether.module.connect.ConnectModule;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.server.IntegratedServer;
import net.morimori0317.gamemenumodoption.ClientConfig;
import net.morimori0317.gamemenumodoption.integration.MineTogetherIntegration;
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 org.spongepowered.asm.mixin.injection.callback.LocalCapture;

@Mixin(ConnectModule.class)
public class ConnectModuleMixin {
@Inject(method = "onScreenOpen", at = @At(value = "INVOKE", target = "Ldev/architectury/hooks/client/screen/ScreenHooks;addRenderableWidget(Lnet/minecraft/client/gui/screens/Screen;Lnet/minecraft/client/gui/components/AbstractWidget;)Lnet/minecraft/client/gui/components/AbstractWidget;", ordinal = 0), remap = false, locals = LocalCapture.CAPTURE_FAILHARD)
private static void onScreenOpen(Screen screen, ScreenAccess screenAccess, CallbackInfo ci, IntegratedServer integratedServer, AbstractWidget feedBack, AbstractWidget bugs, AbstractWidget openToLan, AbstractWidget options, Button guiButton) {
if (MineTogetherIntegration.isCompat() && ClientConfig.SlideUpGameMenuButtons.get())
guiButton.y -= 16;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraftforge.fml.ModList;
import net.morimori0317.gamemenumodoption.ClientConfig;
import net.morimori0317.gamemenumodoption.GameMenuModOptionAPI;
import net.morimori0317.gamemenumodoption.integration.MineTogetherIntegration;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -39,18 +40,22 @@ private void init(CallbackInfo ci) {
if (ModList.get().isLoaded("bettergamemenu")) return;

if (this.showPauseMenu) {
boolean minetFlg = MineTogetherIntegration.isFixButtons();

boolean gmrmflag = ModList.get().isLoaded("gamemenuremovegfarb");
Button options = (Button) this.renderables.get(gmrmflag ? 3 : 5);
Button returnToMenu = (Button) this.renderables.get(gmrmflag ? 5 : 7);
Button shareToLan = (Button) this.renderables.get(6);
if (shareToLan != null) {
shareToLan.x = width / 2 - 102;
shareToLan.setWidth(204);
if (!minetFlg) {
shareToLan.x = width / 2 - 102;
shareToLan.setWidth(204);
}
if (gmrmflag)
shareToLan.y -= 24;
}

Button button = new Button(this.width / 2 + 4, this.height / 4 + (gmrmflag ? 96 : 120) - 16, 98, 20, new TranslatableComponent("menu.modoption"), (n) -> {
Button button = new Button(minetFlg ? width / 2 - 102 : this.width / 2 + 4, this.height / 4 + ((gmrmflag || minetFlg) ? 96 : 120) - 16, minetFlg ? 204 : 98, 20, new TranslatableComponent("menu.modoption"), (n) -> {
var openGui = GameMenuModOptionAPI.getOpenModOptions(this);
if (openGui != null)
Minecraft.getInstance().setScreen(openGui);
Expand All @@ -59,7 +64,7 @@ private void init(CallbackInfo ci) {
if (showUpdate)
modUpdateNotification = init((PauseScreen) (Object) this, button);

if (!gmrmflag) {
if (!gmrmflag || minetFlg) {
if (options != null)
options.y += 24;
if (returnToMenu != null)
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/gamemenumodoption.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"package": "net.morimori0317.gamemenumodoption.mixin",
"compatibilityLevel": "JAVA_17",
"client": [
"ConnectModuleMixin",
"PauseScreenMixin",
"ScreenMixin"
],
Expand Down

0 comments on commit 3cf1c84

Please sign in to comment.