[1.14] Fix NPE in FullBrightness

Turns out fabric's init runs earlier than forge so mc.options is still
null.
Instead we just store mc and access the options when needed (thanks to
the preprocessor that's even shorter than before).
This commit is contained in:
Jonas Herzig
2019-06-14 19:37:27 +02:00
parent a76268138a
commit 8112c852ef

View File

@@ -10,7 +10,7 @@ import de.johni0702.minecraft.gui.element.GuiImage;
import de.johni0702.minecraft.gui.element.IGuiImage; import de.johni0702.minecraft.gui.element.IGuiImage;
import de.johni0702.minecraft.gui.layout.HorizontalLayout; import de.johni0702.minecraft.gui.layout.HorizontalLayout;
import de.johni0702.minecraft.gui.utils.EventRegistrations; import de.johni0702.minecraft.gui.utils.EventRegistrations;
import net.minecraft.client.options.GameOptions; import net.minecraft.client.MinecraftClient;
//#if MC>=11400 //#if MC>=11400
import com.replaymod.core.events.PreRenderCallback; import com.replaymod.core.events.PreRenderCallback;
@@ -25,7 +25,7 @@ public class FullBrightness extends EventRegistrations implements Extra {
private final IGuiImage indicator = new GuiImage().setTexture(ReplayMod.TEXTURE, 90, 20, 19, 13).setSize(19, 13); private final IGuiImage indicator = new GuiImage().setTexture(ReplayMod.TEXTURE, 90, 20, 19, 13).setSize(19, 13);
private GameOptions gameSettings; private MinecraftClient mc;
private boolean active; private boolean active;
//#if MC>=11300 //#if MC>=11300
private double originalGamma; private double originalGamma;
@@ -36,7 +36,7 @@ public class FullBrightness extends EventRegistrations implements Extra {
@Override @Override
public void register(final ReplayMod mod) throws Exception { public void register(final ReplayMod mod) throws Exception {
this.module = ReplayModReplay.instance; this.module = ReplayModReplay.instance;
this.gameSettings = mod.getMinecraft().options; this.mc = mod.getMinecraft();
mod.getKeyBindingRegistry().registerKeyBinding("replaymod.input.lighting", Keyboard.KEY_Z, new Runnable() { mod.getKeyBindingRegistry().registerKeyBinding("replaymod.input.lighting", Keyboard.KEY_Z, new Runnable() {
@Override @Override
@@ -67,8 +67,8 @@ public class FullBrightness extends EventRegistrations implements Extra {
//$$ if (event.phase != TickEvent.Phase.START) return; //$$ if (event.phase != TickEvent.Phase.START) return;
//#endif //#endif
if (active && module.getReplayHandler() != null) { if (active && module.getReplayHandler() != null) {
originalGamma = gameSettings.gamma; originalGamma = mc.options.gamma;
gameSettings.gamma = 1000; mc.options.gamma = 1000;
} }
} }
@@ -81,7 +81,7 @@ public class FullBrightness extends EventRegistrations implements Extra {
//$$ if (event.phase != TickEvent.Phase.END) return; //$$ if (event.phase != TickEvent.Phase.END) return;
//#endif //#endif
if (active && module.getReplayHandler() != null) { if (active && module.getReplayHandler() != null) {
gameSettings.gamma = originalGamma; mc.options.gamma = originalGamma;
} }
} }