Skip to content

Commit

Permalink
fix: crash with OptiFine (#1809)
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiAF committed Oct 13, 2023
1 parent f82ba45 commit 8931676
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
53 changes: 53 additions & 0 deletions src/main/java/com/aetherteam/aether/mixin/AetherMixinPlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.aetherteam.aether.mixin;

import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;

import java.util.List;
import java.util.Set;

public class AetherMixinPlugin implements IMixinConfigPlugin {
private boolean isOptiFineInstalled = false;

@Override
public void onLoad(String mixinPackage) {
try {
Class.forName("optifine.Installer", false, getClass().getClassLoader());
isOptiFineInstalled = true;
} catch (ClassNotFoundException e) {
}
}

@Override
public String getRefMapperConfig() {
return null;
}

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
if (this.isOptiFineInstalled) {
if (mixinClassName.equals("com.aetherteam.aether.mixin.mixins.client.BossHealthOverlayMixin")) return false;
if (mixinClassName.equals("com.aetherteam.aether.mixin.mixins.client.optifine.BossHealthOverlayMixin")) return true;
}

return !mixinClassName.equals("com.aetherteam.aether.mixin.mixins.client.optifine.BossHealthOverlayMixin");
}

@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
}

@Override
public List<String> getMixins() {
return null;
}

@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
}

@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.aetherteam.aether.mixin.mixins.client.optifine;

import com.aetherteam.aether.client.event.hooks.GuiHooks;
import net.minecraft.client.gui.components.BossHealthOverlay;
import net.minecraftforge.client.event.CustomizeGuiOverlayEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;

@Mixin(BossHealthOverlay.class)
public class BossHealthOverlayMixin {
/**
* Cancels the {@link CustomizeGuiOverlayEvent.BossEventProgress} GUI event after the event hook has been called for it.
* Made as a workaround for Jade's boss bar pushdown.<br>
* This modifies the assignment of the {@link CustomizeGuiOverlayEvent.BossEventProgress} event variable.
* @param event The original {@link CustomizeGuiOverlayEvent.BossEventProgress} parameter value.
* @return The modified {@link CustomizeGuiOverlayEvent.BossEventProgress} parameter value.
*/
@ModifyVariable(at = @At(value = "STORE"), method = "render(Lnet/minecraft/client/gui/GuiGraphics;)V", index = 9)
@SuppressWarnings({"MixinAnnotationTarget", "InvalidInjectorMethodSignature"})
private Object event(Object event) {
CustomizeGuiOverlayEvent.BossEventProgress e = (CustomizeGuiOverlayEvent.BossEventProgress)event;
e.setCanceled(GuiHooks.BOSS_EVENTS.containsKey(e.getBossEvent().getId()));
return event;
}
}
4 changes: 3 additions & 1 deletion src/main/resources/aether.mixins.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"required": true,
"package": "com.aetherteam.aether.mixin.mixins",
"plugin": "com.aetherteam.aether.mixin.AetherMixinPlugin",
"minVersion": "0.8",
"compatibilityLevel": "JAVA_17",
"refmap": "aether.refmap.json",
Expand Down Expand Up @@ -65,7 +66,8 @@
"client.accessor.PlayerModelAccessor",
"client.accessor.QuadrupedModelAccessor",
"client.accessor.ScreenAccessor",
"client.accessor.TitleScreenAccessor"
"client.accessor.TitleScreenAccessor",
"client.optifine.BossHealthOverlayMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 8931676

Please sign in to comment.