diff --git a/src/main/java/io/github/gaming32/worldhost/WorldHost.java b/src/main/java/io/github/gaming32/worldhost/WorldHost.java index a0ca5aa..38c24c8 100644 --- a/src/main/java/io/github/gaming32/worldhost/WorldHost.java +++ b/src/main/java/io/github/gaming32/worldhost/WorldHost.java @@ -211,8 +211,7 @@ public class WorldHost private static int delayIndex = 0; private static Future connectingFuture; - public static boolean shareWorldOnLoadUi; - public static boolean shareWorldOnLoadReal; + public static boolean shareWorldOnLoad; //#if FABRIC @Override diff --git a/src/main/java/io/github/gaming32/worldhost/WorldHostComponents.java b/src/main/java/io/github/gaming32/worldhost/WorldHostComponents.java index 541cd24..8aa2780 100644 --- a/src/main/java/io/github/gaming32/worldhost/WorldHostComponents.java +++ b/src/main/java/io/github/gaming32/worldhost/WorldHostComponents.java @@ -6,4 +6,5 @@ public class WorldHostComponents { public static final Component FRIENDS = Components.translatable("world-host.friends"); public static final Component SERVERS = Components.translatable("world-host.servers"); + public static final Component PLAY_TEXT = Component.translatable("world-host.play_world"); } diff --git a/src/main/java/io/github/gaming32/worldhost/ext/SelectWorldScreenExt.java b/src/main/java/io/github/gaming32/worldhost/ext/SelectWorldScreenExt.java new file mode 100644 index 0000000..5b0fa23 --- /dev/null +++ b/src/main/java/io/github/gaming32/worldhost/ext/SelectWorldScreenExt.java @@ -0,0 +1,5 @@ +package io.github.gaming32.worldhost.ext; + +public interface SelectWorldScreenExt { + boolean wh$shareButtonPressed(); +} diff --git a/src/main/java/io/github/gaming32/worldhost/mixin/MixinIntegratedServer.java b/src/main/java/io/github/gaming32/worldhost/mixin/MixinIntegratedServer.java index 332a240..0e9eaff 100644 --- a/src/main/java/io/github/gaming32/worldhost/mixin/MixinIntegratedServer.java +++ b/src/main/java/io/github/gaming32/worldhost/mixin/MixinIntegratedServer.java @@ -113,8 +113,8 @@ private void serverIsClosed(boolean waitForServer, CallbackInfo ci) { @Inject(method = "setUUID", at = @At("TAIL")) private void shareWorldOnLoad(UUID uuid, CallbackInfo ci) { - if (!WorldHost.shareWorldOnLoadReal) return; - WorldHost.shareWorldOnLoadReal = false; + if (!WorldHost.shareWorldOnLoad) return; + WorldHost.shareWorldOnLoad = false; final Component message; if (publishServer(worldData.getGameType(), worldData.getAllowCommands(), HttpUtil.getAvailablePort())) { message = wh$getOpenedMessage(); diff --git a/src/main/java/io/github/gaming32/worldhost/mixin/MixinLevelSummary.java b/src/main/java/io/github/gaming32/worldhost/mixin/MixinLevelSummary.java new file mode 100644 index 0000000..9264d5d --- /dev/null +++ b/src/main/java/io/github/gaming32/worldhost/mixin/MixinLevelSummary.java @@ -0,0 +1,22 @@ +package io.github.gaming32.worldhost.mixin; + +import io.github.gaming32.worldhost.WorldHost; +import io.github.gaming32.worldhost.WorldHostComponents; +import net.minecraft.network.chat.Component; +import net.minecraft.world.level.storage.LevelSummary; +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.CallbackInfoReturnable; + +@Mixin(LevelSummary.class) +public class MixinLevelSummary { + //#if MC >= 1.20.3 + @Inject(method = "primaryActionMessage", at = @At("HEAD"), cancellable = true) + private void shareButton(CallbackInfoReturnable cir) { + if (WorldHost.CONFIG.isShareButton()) { + cir.setReturnValue(WorldHostComponents.PLAY_TEXT); + } + } + //#endif +} diff --git a/src/main/java/io/github/gaming32/worldhost/mixin/MixinSelectWorldScreen.java b/src/main/java/io/github/gaming32/worldhost/mixin/MixinSelectWorldScreen.java index c08c5fd..59ca711 100644 --- a/src/main/java/io/github/gaming32/worldhost/mixin/MixinSelectWorldScreen.java +++ b/src/main/java/io/github/gaming32/worldhost/mixin/MixinSelectWorldScreen.java @@ -1,6 +1,8 @@ package io.github.gaming32.worldhost.mixin; import io.github.gaming32.worldhost.WorldHost; +import io.github.gaming32.worldhost.WorldHostComponents; +import io.github.gaming32.worldhost.ext.SelectWorldScreenExt; import io.github.gaming32.worldhost.gui.screen.WorldHostScreen; import io.github.gaming32.worldhost.versions.Components; import net.minecraft.client.gui.components.Button; @@ -8,30 +10,45 @@ import net.minecraft.client.gui.screens.worldselection.SelectWorldScreen; import net.minecraft.client.gui.screens.worldselection.WorldSelectionList; import net.minecraft.network.chat.Component; +import net.minecraft.world.level.storage.LevelSummary; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Constant; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyConstant; +import org.spongepowered.asm.mixin.injection.*; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(SelectWorldScreen.class) -public class MixinSelectWorldScreen extends Screen { +public class MixinSelectWorldScreen extends Screen implements SelectWorldScreenExt { @Shadow private WorldSelectionList list; @Unique private Button wh$shareButton; + @Unique + private boolean wh$shareButtonPressed; + protected MixinSelectWorldScreen(Component component) { super(component); } - @ModifyConstant(method = "init()V", constant = @Constant(stringValue = "selectWorld.select")) - private String changePlayButtonText(String constant) { - return WorldHost.CONFIG.isShareButton() ? "world-host.play_world" : constant; + //#if MC >= 1.20.3 + @ModifyArg( + method = "init()V", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/gui/components/Button;builder(Lnet/minecraft/network/chat/Component;Lnet/minecraft/client/gui/components/Button$OnPress;)Lnet/minecraft/client/gui/components/Button$Builder;", + ordinal = 0 + ) + ) + private Component changePlayButtonText(Component original) { + return WorldHost.CONFIG.isShareButton() ? WorldHostComponents.PLAY_TEXT : original; } + //#else + //$$ @ModifyConstant(method = "init()V", constant = @Constant(stringValue = "selectWorld.select")) + //$$ private String changePlayButtonText(String constant) { + //$$ return WorldHost.CONFIG.isShareButton() ? "world-host.play_world" : constant; + //$$ } + //#endif @ModifyConstant(method = "init()V", constant = @Constant(intValue = 150, ordinal = 0)) private int shrinkPlayButton(int constant) { @@ -62,8 +79,10 @@ private void addShareWorldButton(CallbackInfo ci) { //$$ wh$shareButton = addButton( //#endif WorldHostScreen.button(Components.translatable("world-host.share_world"), b -> { - WorldHost.shareWorldOnLoadUi = true; - list.getSelectedOpt().ifPresent(WorldSelectionList.WorldListEntry::joinWorld); + list.getSelectedOpt().ifPresent(worldListEntry -> { + wh$shareButtonPressed = true; + worldListEntry.joinWorld(); + }); }).pos(width / 2 - 50, height - 52) .width(100) .build() @@ -85,16 +104,43 @@ private String changeCreateButtonText(String constant) { return WorldHost.CONFIG.isShareButton() ? "world-host.create_world" : constant; } + //#if MC >= 1.20.3 + @ModifyArg( + method = "updateButtonStatus", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/gui/components/Button;setMessage(Lnet/minecraft/network/chat/Component;)V", + ordinal = 0 + ) + ) + private Component changePlayButtonTextOnUpdate(Component original) { + return WorldHost.CONFIG.isShareButton() ? WorldHostComponents.PLAY_TEXT : original; + } + //#endif + @Inject(method = "updateButtonStatus", at = @At("TAIL")) - private void updateShareButtonStatus( - boolean active, - //#if MC > 1.19.2 - boolean bl2, - //#endif - CallbackInfo ci - ) { + //#if MC >= 1.20.3 + private void updateShareButtonStatus(LevelSummary levelSummary, CallbackInfo ci) { if (wh$shareButton != null) { - wh$shareButton.active = active; + wh$shareButton.active = levelSummary != null && levelSummary.primaryActionActive(); } } + //#else + //$$ private void updateShareButtonStatus( + //$$ boolean active, + //$$ //#if MC > 1.19.2 + //$$ boolean bl2, + //$$ //#endif + //$$ CallbackInfo ci + //$$ ) { + //$$ if (wh$shareButton != null) { + //$$ wh$shareButton.active = active; + //$$ } + //$$ } + //#endif + + @Override + public boolean wh$shareButtonPressed() { + return wh$shareButtonPressed; + } } diff --git a/src/main/java/io/github/gaming32/worldhost/mixin/MixinWorldSelectionList_WorldListEntry.java b/src/main/java/io/github/gaming32/worldhost/mixin/MixinWorldSelectionList_WorldListEntry.java index 9156940..5e9183d 100644 --- a/src/main/java/io/github/gaming32/worldhost/mixin/MixinWorldSelectionList_WorldListEntry.java +++ b/src/main/java/io/github/gaming32/worldhost/mixin/MixinWorldSelectionList_WorldListEntry.java @@ -2,6 +2,7 @@ import com.mojang.blaze3d.platform.InputConstants; import io.github.gaming32.worldhost.WorldHost; +import io.github.gaming32.worldhost.ext.SelectWorldScreenExt; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.worldselection.WorldSelectionList; import org.spongepowered.asm.mixin.Final; @@ -19,26 +20,25 @@ public class MixinWorldSelectionList_WorldListEntry { @Shadow @Final private Minecraft minecraft; + @Shadow @Final WorldSelectionList this$0; + @Inject(method = "joinWorld", at = @At("HEAD")) private void shareWorldOnShift(CallbackInfo ci) { - if ( - !WorldHost.CONFIG.isShareButton() || - WorldHost.shareWorldOnLoadUi || - !InputConstants.isKeyDown( + if (WorldHost.CONFIG.isShareButton()) { + if (((SelectWorldScreenExt)this$0.getScreen()).wh$shareButtonPressed()) { + WorldHost.shareWorldOnLoad = true; + } else { + WorldHost.shareWorldOnLoad = InputConstants.isKeyDown( minecraft.getWindow().getWindow(), //#if MC > 1.16.5 InputConstants.KEY_LSHIFT //#else //$$ GLFW.GLFW_KEY_LEFT_SHIFT //#endif - ) - ) return; - WorldHost.shareWorldOnLoadUi = true; - } - - @Inject(method = "loadWorld", at = @At("HEAD")) - private void setupShareWorld(CallbackInfo ci) { - WorldHost.shareWorldOnLoadReal = WorldHost.shareWorldOnLoadUi; - WorldHost.shareWorldOnLoadUi = false; + ); + } + } else { + WorldHost.shareWorldOnLoad = false; + } } } diff --git a/src/main/resources/world-host.mixins.json b/src/main/resources/world-host.mixins.json index ac8c4f0..562a2cf 100644 --- a/src/main/resources/world-host.mixins.json +++ b/src/main/resources/world-host.mixins.json @@ -5,6 +5,7 @@ "compatibilityLevel": "$java_version", "mixins": [ "MixinCommands", + "MixinLevelSummary", "MixinPublishCommand", "ServerConnectionListenerAccessor" ], @@ -23,9 +24,9 @@ "MixinTitleScreen", "MixinWorldSelectionList_WorldListEntry", "PlainTextButtonAccessor", - "ServerStatusPingerAccessor" + "ServerStatusPingerAccessor", //#if FABRIC && MC > 1.16.1 - , "modmenu.MixinModMenuEventHandler" + "modmenu.MixinModMenuEventHandler" //#endif ], "injectors": { diff --git a/version.gradle.kts b/version.gradle.kts index 190f30a..22664b6 100644 --- a/version.gradle.kts +++ b/version.gradle.kts @@ -240,7 +240,10 @@ dependencies { } } - modRuntimeOnly("me.djtheredstoner:DevAuth-${if (isFabric) "fabric" else "forge-latest"}:1.1.2") + // TODO: Remove this if when DevAuth gets Neo support on Maven + if (!isNeoForge) { + modRuntimeOnly("me.djtheredstoner:DevAuth-${if (isFabric) "fabric" else "forge-latest"}:1.1.2") + } if (isFabric) { when (mcVersion) {