Automatically close GameMode selection screen in <= c0.28-c0.30

This commit is contained in:
FlorianMichael 2023-08-28 17:44:55 +02:00
parent 51538b6fc7
commit 54f8ad9619
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
2 changed files with 15 additions and 10 deletions

View File

@ -17,12 +17,11 @@
*/ */
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.screen; package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.screen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;
import net.raphimc.vialoader.util.VersionEnum; import net.raphimc.vialoader.util.VersionEnum;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack; import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import net.minecraft.client.gui.screen.GameModeSelectionScreen; import net.minecraft.client.gui.screen.GameModeSelectionScreen;
import net.raphimc.vialoader.util.VersionEnum;
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
import org.spongepowered.asm.mixin.*; import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
@ -34,7 +33,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
@Mixin(GameModeSelectionScreen.class) @Mixin(GameModeSelectionScreen.class)
public class MixinGameModeSelectionScreen { public class MixinGameModeSelectionScreen extends Screen {
@Mutable @Mutable
@Shadow @Final private static int UI_WIDTH; @Shadow @Final private static int UI_WIDTH;
@ -42,6 +41,10 @@ public class MixinGameModeSelectionScreen {
@Unique @Unique
private GameModeSelectionScreen.GameModeSelection[] viafabricplus_unwrappedGameModes; private GameModeSelectionScreen.GameModeSelection[] viafabricplus_unwrappedGameModes;
public MixinGameModeSelectionScreen(Text title) {
super(title);
}
@Inject(method = "<init>", at = @At("RETURN")) @Inject(method = "<init>", at = @At("RETURN"))
public void fixUIWidth(CallbackInfo ci) { public void fixUIWidth(CallbackInfo ci) {
if (ProtocolHack.getTargetVersion().isOlderThan(VersionEnum.r1_8)) { if (ProtocolHack.getTargetVersion().isOlderThan(VersionEnum.r1_8)) {
@ -55,6 +58,13 @@ public class MixinGameModeSelectionScreen {
} }
} }
@Inject(method = "init", at = @At("HEAD"))
public void disableInClassic(CallbackInfo ci) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.c0_28toc0_30)) { // survival mode was added in a1.0.15
this.close();
}
}
@Redirect(method = "init", at = @At(value = "FIELD", target = "Lnet/minecraft/client/gui/screen/GameModeSelectionScreen$GameModeSelection;VALUES:[Lnet/minecraft/client/gui/screen/GameModeSelectionScreen$GameModeSelection;")) @Redirect(method = "init", at = @At(value = "FIELD", target = "Lnet/minecraft/client/gui/screen/GameModeSelectionScreen$GameModeSelection;VALUES:[Lnet/minecraft/client/gui/screen/GameModeSelectionScreen$GameModeSelection;"))
public GameModeSelectionScreen.GameModeSelection[] removeNewerGameModes() { public GameModeSelectionScreen.GameModeSelection[] removeNewerGameModes() {
if (ProtocolHack.getTargetVersion().isOlderThan(VersionEnum.r1_8)) { if (ProtocolHack.getTargetVersion().isOlderThan(VersionEnum.r1_8)) {

View File

@ -18,12 +18,9 @@
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.screen; package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.screen;
import net.raphimc.vialoader.util.VersionEnum; import net.raphimc.vialoader.util.VersionEnum;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack; import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.GameModeSelectionScreen; import net.minecraft.client.gui.screen.GameModeSelectionScreen;
import net.raphimc.vialoader.util.VersionEnum;
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
@ -66,9 +63,7 @@ public class MixinGameModeSelectionScreen_GameModeSelection {
cir.setReturnValue(Optional.of(GameModeSelectionScreen.GameModeSelection.ADVENTURE)); cir.setReturnValue(Optional.of(GameModeSelectionScreen.GameModeSelection.ADVENTURE));
} }
} }
case ADVENTURE -> { case ADVENTURE -> cir.setReturnValue(Optional.of(CREATIVE));
cir.setReturnValue(Optional.of(CREATIVE));
}
} }
} }
} }