Fixed crash when using the F3 + F4 menu in <= 1.8

This commit is contained in:
FlorianMichael 2023-11-28 00:00:54 +01:00
parent 9d33bd9431
commit ebf1075155
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
2 changed files with 13 additions and 9 deletions

View File

@ -50,8 +50,12 @@ public class MixinGameModeSelectionScreen extends Screen {
if (ProtocolHack.getTargetVersion().isOlderThan(VersionEnum.r1_8)) { if (ProtocolHack.getTargetVersion().isOlderThan(VersionEnum.r1_8)) {
final List<GameModeSelectionScreen.GameModeSelection> gameModeSelections = new ArrayList<>(Arrays.stream(GameModeSelectionScreen.GameModeSelection.values()).toList()); final List<GameModeSelectionScreen.GameModeSelection> gameModeSelections = new ArrayList<>(Arrays.stream(GameModeSelectionScreen.GameModeSelection.values()).toList());
if (ProtocolHack.getTargetVersion().isOlderThan(VersionEnum.r1_3_1tor1_3_2)) gameModeSelections.remove(GameModeSelectionScreen.GameModeSelection.ADVENTURE); if (ProtocolHack.getTargetVersion().isOlderThan(VersionEnum.r1_3_1tor1_3_2)) {
if (ProtocolHack.getTargetVersion().isOlderThan(VersionEnum.r1_8)) gameModeSelections.remove(GameModeSelectionScreen.GameModeSelection.SPECTATOR); gameModeSelections.remove(GameModeSelectionScreen.GameModeSelection.ADVENTURE);
}
if (ProtocolHack.getTargetVersion().isOlderThan(VersionEnum.r1_8)) {
gameModeSelections.remove(GameModeSelectionScreen.GameModeSelection.SPECTATOR);
}
viafabricplus_unwrappedGameModes = gameModeSelections.toArray(GameModeSelectionScreen.GameModeSelection[]::new); viafabricplus_unwrappedGameModes = gameModeSelections.toArray(GameModeSelectionScreen.GameModeSelection[]::new);
UI_WIDTH = viafabricplus_unwrappedGameModes.length * 31 - 5; UI_WIDTH = viafabricplus_unwrappedGameModes.length * 31 - 5;

View File

@ -52,18 +52,18 @@ public class MixinGameModeSelectionScreen_GameModeSelection {
} }
@Inject(method = "next", at = @At("HEAD"), cancellable = true) @Inject(method = "next", at = @At("HEAD"), cancellable = true)
public void unwrapGameModes(CallbackInfoReturnable<Optional<GameModeSelectionScreen.GameModeSelection>> cir) { private void unwrapGameModes(CallbackInfoReturnable<GameModeSelectionScreen.GameModeSelection> cir) {
if (ProtocolHack.getTargetVersion().isOlderThan(VersionEnum.r1_8)) { if (ProtocolHack.getTargetVersion().isOlderThan(VersionEnum.r1_8)) {
switch ((GameModeSelectionScreen.GameModeSelection) (Object) this) { switch ((GameModeSelectionScreen.GameModeSelection) (Object) this) {
case CREATIVE -> cir.setReturnValue(Optional.of(SURVIVAL)); case CREATIVE -> cir.setReturnValue(SURVIVAL);
case SURVIVAL -> { case SURVIVAL -> {
if (ProtocolHack.getTargetVersion().isOlderThan(VersionEnum.r1_2_4tor1_2_5)) { if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_2_4tor1_2_5)) {
cir.setReturnValue(Optional.of(CREATIVE)); cir.setReturnValue(CREATIVE);
} else { } else {
cir.setReturnValue(Optional.of(GameModeSelectionScreen.GameModeSelection.ADVENTURE)); cir.setReturnValue(GameModeSelectionScreen.GameModeSelection.ADVENTURE);
} }
} }
case ADVENTURE -> cir.setReturnValue(Optional.of(CREATIVE)); case ADVENTURE -> cir.setReturnValue(CREATIVE);
} }
} }
} }