Skip to content

Commit

Permalink
Fix standard HUD not moving up on Forge
Browse files Browse the repository at this point in the history
  • Loading branch information
DenWav committed Jan 8, 2018
1 parent 823eb4e commit ef76e96
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 48 deletions.
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
modVersion=1.1.5
# suppress inspection "UnusedProperty" for whole file
modVersion=1.2.0
modGroup=com.demonwav
modBaseName=extendedhotbar
mcVersion=1.12.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public String getName() {

@Override
public String getVersion() {
return "1.1.5";
return "1.2.0";
}

@Override
Expand Down
51 changes: 51 additions & 0 deletions src/main/java/com/demonwav/extendedhotbar/Util.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.demonwav.extendedhotbar;

import static com.mumfrey.liteloader.gl.GL.glPopMatrix;
import static com.mumfrey.liteloader.gl.GL.glPushMatrix;
import static com.mumfrey.liteloader.gl.GL.glTranslated;

import com.mumfrey.liteloader.core.LiteLoader;

public final class Util {

private static LiteModExtendedHotbar mod = null;

public static final int DISTANCE = -22;

private Util() {}

/*
* This likely doesn't need to be thread-safe.
*/
public static LiteModExtendedHotbar getMod() {
LiteModExtendedHotbar m = Util.mod;
if (m != null) {
return m;
}

synchronized (Util.class) {
m = Util.mod;
if (m != null) {
return m;
}

m = LiteLoader.getInstance().getMod(LiteModExtendedHotbar.class);
Util.mod = m;
}

return m;
}

public static void moveUp() {
if (getMod().isEnabled()) {
glPushMatrix();
glTranslated(0, DISTANCE, 0);
}
}

public static void reset() {
if (getMod().isEnabled()) {
glPopMatrix();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.demonwav.extendedhotbar.mixin;

import static com.demonwav.extendedhotbar.Util.moveUp;
import static com.demonwav.extendedhotbar.Util.reset;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiIngame;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Pseudo
@Mixin(targets = "net.minecraftforge.client.GuiIngameForge")
public abstract class MixinGuiInGameForge extends GuiIngame {

public MixinGuiInGameForge(final Minecraft mcIn) {
super(mcIn);
}

@Inject(
method = "Lnet/minecraftforge/client/GuiIngameForge;renderGameOverlay(F)V",
at = {
@At(value = "INVOKE", target = "Lnet/minecraftforge/client/GuiIngameForge;renderBossHealth()V", shift = At.Shift.BY, by = 2),
@At(value = "INVOKE", target = "Lnet/minecraftforge/client/GuiIngameForge;renderSleepFade(II)V", shift = At.Shift.AFTER)
}
)
private void moveGuiUp(float partialTicks, final CallbackInfo info) {
moveUp();
}

@Inject(
method = "Lnet/minecraftforge/client/GuiIngameForge;renderGameOverlay(F)V", at = {
@At(value = "INVOKE", target = "Lnet/minecraftforge/client/GuiIngameForge;renderSleepFade(II)V"),
@At(value = "INVOKE", target = "Lnet/minecraftforge/client/GuiIngameForge;renderFPSGraph()V")
}
)
private void moveGuiDown(float partialTicks, final CallbackInfo info) {
reset();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.demonwav.extendedhotbar.mixin;

import static com.demonwav.extendedhotbar.Util.DISTANCE;
import static com.demonwav.extendedhotbar.Util.getMod;
import static com.demonwav.extendedhotbar.Util.moveUp;
import static com.demonwav.extendedhotbar.Util.reset;
import static com.mumfrey.liteloader.gl.GL.*;

import com.demonwav.extendedhotbar.LiteModExtendedHotbar;
import com.mumfrey.liteloader.core.LiteLoader;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiIngame;
Expand All @@ -21,39 +23,13 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(GuiIngame.class)
public abstract class MixinGuiInGame extends Gui {

private static final int DISTANCE = -22;

private LiteModExtendedHotbar mod = null;
public abstract class MixinGuiIngame extends Gui {

@Shadow @Final private static ResourceLocation WIDGETS_TEX_PATH;

@Shadow @Final private Minecraft mc;
@Shadow protected abstract void renderHotbarItem(int p_184044_1_, int p_184044_2_, float p_184044_3_, EntityPlayer player, ItemStack stack);

/*
* This likely doesn't need to be thread-safe.
*/
private LiteModExtendedHotbar getMod() {
LiteModExtendedHotbar m = this.mod;
if (m != null) {
return m;
}

synchronized (this) {
m = this.mod;
if (m != null) {
return m;
}

m = LiteLoader.getInstance().getMod(LiteModExtendedHotbar.class);
this.mod = m;
}

return m;
}

@Inject(method = "renderHotbar", at = @At("RETURN"))
private void drawTopHotbar(final ScaledResolution sr, final float partialTicks, final CallbackInfo info) {
if (!getMod().isEnabled()) {
Expand Down Expand Up @@ -88,19 +64,6 @@ private void drawTopHotbar(final ScaledResolution sr, final float partialTicks,
glDisableBlend();
}

private void moveUp() {
if (getMod().isEnabled()) {
glPushMatrix();
glTranslated(0, DISTANCE, 0);
}
}

private void reset() {
if (getMod().isEnabled()) {
glPopMatrix();
}
}

@Inject(
id = "move",
method = {
Expand Down
10 changes: 6 additions & 4 deletions src/main/resources/mixins.extendedhotbar.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
"minVersion": "0.7.1",
"package": "com.demonwav.extendedhotbar.mixin",
"refmap": "mixins.extendedhotbar.refmap.json",
"mixins": [
"MixinGuiInGame",
"MixinGuiContainerCreative"
"client": [
"MixinGuiIngame",
"MixinGuiContainerCreative",
"MixinGuiInGameForge"
],
"injectors": {
"defaultRequire": 1
"defaultRequire": 1,
"maxShiftBy": 2
}
}

0 comments on commit ef76e96

Please sign in to comment.