Skip to content

Commit

Permalink
prevent_optifine_guiscale_crash (#123)
Browse files Browse the repository at this point in the history
* Prevents the chunk loading option from changing while changing the gui scale in the video options, since it can cause crashes

* will crash on spongemixins 0.7, forces the chunk loading option to default and changes the tooltip in the options

* forces the chunk loading setting to default upon starting the game

* remove optifine from targeted mods

* I love spotless

* spotlessApply (#124)

Co-authored-by: Alexdoru <[email protected]>
Co-authored-by: GitHub GTNH Actions <>

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
Alexdoru and github-actions[bot] authored Sep 20, 2022
1 parent 60fa234 commit c329c66
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public class LoadingConfig {
public boolean optimizeASMDataTable;
public boolean squashBedErrorMessage;
public boolean throttleItemPickupEvent;
public boolean fixOptifineChunkLoadingCrash;
public boolean hideCrosshairInThirdPerson;
public boolean fixOptifineGuiScaleCrash;

public boolean enableDefaultLanPort;

Expand Down Expand Up @@ -343,11 +343,11 @@ public LoadingConfig(File file) {
1,
config.get(Category.FIXES.toString(), "itemStacksPickedUpPerTick", 36, "Stacks picked up per tick")
.getInt());
fixOptifineGuiScaleCrash = config.get(
fixOptifineChunkLoadingCrash = config.get(
Category.FIXES.toString(),
"fixOptifineGuiScaleCrash",
"fixOptifineChunkLoadingCrash",
true,
"Prevents the chunk loading option from changing while changing the gui scale in the video options, since it can cause crashes")
"Forces the chunk loading option from optifine to default since other values can crash the game")
.getBoolean();

increaseParticleLimit = config.get(
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,13 @@ public enum Mixins {
Side.CLIENT,
() -> Common.config.fixUnfocusedFullscreen,
TargetedMod.VANILLA),
FIX_OPTIFINE_GUISCALE_CRASH(
"minecraft.MixinGameSettings",
FIX_OPTIFINE_CHUNKLOADING_CRASH(
() -> Common.config.fixOptifineChunkLoadingCrash,
Side.CLIENT,
() -> Common.config.fixOptifineGuiScaleCrash,
TargetedMod.VANILLA),
TargetedMod.VANILLA, // TargetedMod.OPTIFINE,
"minecraft.MixinGameSettings" /*,
TODO this mixins crashes with mixins 7.0, enable it once we update to 8.0
"minecraft.MixinGuiVideoSettings"*/),
ADD_TOGGLE_DEBUG_MESSAGE(
"minecraft.MixinMinecraft_ToggleDebugMessage",
Side.CLIENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public enum TargetedMod {
// Temporary solution to force load it early
GTNHLIB("GTNHLib", "gtnhlib"),
JOURNEYMAP("journeymap", "journeymap");
// OPTIFINE("OptiFine", "OptiFine");

public final String modName;
public final String jarName;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mitchej123.hodgepodge.mixins.minecraft;

import net.minecraft.client.settings.GameSettings;
import org.spongepowered.asm.mixin.Dynamic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -9,9 +10,17 @@
@Mixin(GameSettings.class)
public class MixinGameSettings {

@Dynamic("Field is added by optifine's ASM")
public int ofChunkLoading;

@Inject(method = "loadOptions", at = @At("TAIL"))
public void hodgepodge$forceChunkLoadingToDefault(CallbackInfo ci) {
ofChunkLoading = 0;
}

@Inject(method = "setOptionValue", at = @At("HEAD"), cancellable = true)
public void hodgepodge$fixOptifineChunkLoadingCrash(GameSettings.Options option, int p_74306_2_, CallbackInfo ci) {
if (option.name().equals("CHUNK_LOADING")) {
if (option != null && option.name().equals("CHUNK_LOADING")) {
ci.cancel();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.mitchej123.hodgepodge.mixins.minecraft;

import net.minecraft.client.gui.GuiVideoSettings;
import org.spongepowered.asm.mixin.Dynamic;
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(GuiVideoSettings.class)
public class MixinGuiVideoSettings {

/*
* This mixins is disabled for now as it will crash with Mixins v7.0
* https://github.com/SpongePowered/Mixin/issues/358
* TODO enable it once we change to 8.0
*/

@Dynamic("Method is added by optifine's ASM")
@Inject(method = "getTooltipLines", at = @At("HEAD"), remap = false, cancellable = true)
public void hodgepodge$ChangeChunkLoadingTooltip(String btnName, CallbackInfoReturnable<String[]> cir) {
if (btnName.equals("Chunk Loading")) {
cir.setReturnValue(new String[] {
"Chunk Loading is forced to default in GTNH",
" Any other value can cause your game to crash",
" If you want to re-enable this setting you",
" have to open the Hodgepodge config and change",
"\"fixOptifineChunkLoadingCrash\" to false"
});
cir.cancel();
}
}
}

0 comments on commit c329c66

Please sign in to comment.