Skip to content

Commit

Permalink
Merge to update to 1.21, fixing #44
Browse files Browse the repository at this point in the history
Updated to 1.21 and refactored some things
  • Loading branch information
legoraft authored Jun 23, 2024
2 parents a8c37eb + 43fa4df commit 5fee70d
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 42 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repositories {
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
maven { url = "https://maven.terraformersmc.com/" }
maven { url = "https://maven.gegy.dev" }
// maven { url = "https://maven.gegy.dev" }
}

loom {
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.6
yarn_mappings=1.20.6+build.3
minecraft_version=1.21
yarn_mappings=1.21+build.2
loader_version=0.15.11

# Mod Properties
mod_version=1.4.3
mod_version=1.4.4
maven_group=com.armorhud
archives_base_name=simple-armor-hud

# Dependency properties
fabric_version=0.99.0+1.20.6
modmenu_version=10.0.0-beta.1
fabric_version=0.100.3+1.21
modmenu_version=11.0.1
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.armorhud.config;

import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.option.GameOptionsScreen;
import net.minecraft.client.gui.widget.*;
import net.minecraft.text.Text;

public class fabricScreen extends GameOptionsScreen {
public class configScreen extends GameOptionsScreen {
public Screen parent;

public fabricScreen(Screen parent) {
public configScreen(Screen parent) {
super(parent, null, Text.translatable("config.title"));

this.parent = parent;
Expand All @@ -18,13 +19,12 @@ public fabricScreen(Screen parent) {
public CyclingButtonWidget betterMountHudToggle;
public CyclingButtonWidget armorHudToggle;
public CyclingButtonWidget rightToLeftToggle;

public CyclingButtonWidget disableArmorBar;

public ButtonWidget doneButton;

@Override
protected void init() {
OptionListWidget optionListWidget = this.addDrawableChild(new OptionListWidget(this.client, this.width, this.height, this));

doubleHotbarToggle = CyclingButtonWidget.onOffBuilder(config.DOUBLE_HOTBAR)
.build(Text.translatable("config.doublehotbar"), ((button, value) -> config.DOUBLE_HOTBAR = !config.DOUBLE_HOTBAR));

Expand All @@ -38,11 +38,30 @@ protected void init() {
.build(Text.translatable("config.righttoleft"), (button, value) -> config.RTL = !config.RTL);

disableArmorBar = CyclingButtonWidget.onOffBuilder(config.DISABLE_ARMOR_BAR)
.build(Text.translatable("config.disablearmorbar"), ((button, value) -> config.DISABLE_ARMOR_BAR = !config.DISABLE_ARMOR_BAR));
.build(Text.translatable("config.disablearmorbar"), ((button, value) -> config.DISABLE_ARMOR_BAR = !config.DISABLE_ARMOR_BAR));

OptionListWidget optionListWidget = this.addDrawableChild(new OptionListWidget(this.client, this.width, this));

optionListWidget.addWidgetEntry(doubleHotbarToggle, betterMountHudToggle);
optionListWidget.addWidgetEntry(armorHudToggle, rightToLeftToggle);
optionListWidget.addWidgetEntry(disableArmorBar, null);

doneButton = ButtonWidget
.builder(Text.translatable("config.done"), button -> close())
.dimensions(width / 2 - 100, height - 25, 200, 20)
.build();

addDrawableChild(doneButton);
}

@Override
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
super.render(context, mouseX, mouseY, delta);
context.drawCenteredTextWithShadow(textRenderer, super.title, width / 2, 12, 0xffffff);
}

@Override
protected void addOptions() {
super.init();
}

Expand Down
26 changes: 8 additions & 18 deletions src/client/java/com/armorhud/mixin/client/armorHudMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.hud.InGameHud;
import net.minecraft.client.render.RenderTickCounter;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
Expand All @@ -16,27 +17,28 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(InGameHud.class)

public abstract class armorHudMixin {

@Shadow @Final private MinecraftClient client;

@Shadow protected abstract LivingEntity getRiddenEntity();

@Shadow public abstract void tick(boolean paused);

@Unique int armorHeight;

@Inject(at = @At("TAIL"), method = "renderHotbar")
private void renderHud(DrawContext context, float tickDelta, CallbackInfo ci) {
private void renderHud(DrawContext context, RenderTickCounter tickCounter, CallbackInfo ci) {
if(!config.ARMOR_HUD) { return; }

assert client.player != null;

renderArmor(context, tickDelta);
renderArmor(context, tickCounter);
moveArmor(context);
}

@Unique
private void renderArmor(DrawContext context, float tickDelta) {
private void renderArmor(DrawContext context, RenderTickCounter tickCounter) {
int scaledWidth = context.getScaledWindowWidth();

assert client.player != null;
Expand All @@ -58,31 +60,19 @@ private void renderArmor(DrawContext context, float tickDelta) {
armorPiece = j;
}

renderArmorPiece(context, x, armorHeight, tickDelta, client.player, client.player.getInventory().getArmorStack(armorPiece));
renderArmorPiece(context, x, armorHeight, tickCounter, client.player, client.player.getInventory().getArmorStack(armorPiece));
}
}

// Pretty much the same as renderHotbarItem but with x and y as float parameters.
@Unique
private void renderArmorPiece(DrawContext context, float x, float y, float tickDelta, PlayerEntity player, ItemStack stack) {
private void renderArmorPiece(DrawContext context, float x, float y, RenderTickCounter tickCounter, PlayerEntity player, ItemStack stack) {
if (stack.isEmpty()) return;

// Magic
float f = (float)stack.getBobbingAnimationTime() - tickDelta;
context.getMatrices().push();
context.getMatrices().translate(x, y, 0);

if (f > 0) {
float g = 1 + f / 5;
context.getMatrices().push();
context.getMatrices().translate(8, 12, 0);
context.getMatrices().scale(1 / g, (g + 1) / 2, 1);
context.getMatrices().translate(-8, -12, 0);
}
context.drawItem(player, stack, 0, 0, 1);
if (f > 0) {
context.getMatrices().pop();
}

context.drawItemInSlot(this.client.textRenderer, stack, 0,0);
context.getMatrices().pop();
Expand Down
16 changes: 6 additions & 10 deletions src/client/java/com/armorhud/mixin/client/inGameHudMixin.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
package com.armorhud.mixin.client;

import com.armorhud.config.config;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.hud.InGameHud;
import net.minecraft.entity.player.PlayerEntity;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(InGameHud.class)

public abstract class inGameHudMixin {

@Shadow @Nullable protected abstract PlayerEntity getCameraPlayer();

@ModifyVariable(method = "renderStatusBars", at = @At("STORE"), ordinal = 11)
public int renderStatusBars(int u) {
PlayerEntity playerEntity = this.getCameraPlayer();
assert playerEntity != null;

@Inject(method = "renderArmor", at=@At("HEAD"), cancellable = true)
private static void checkArmor(DrawContext context, PlayerEntity player, int i, int j, int k, int x, CallbackInfo ci) {
if (config.DISABLE_ARMOR_BAR) {
return 0;
} else {
return playerEntity.getArmor();
ci.cancel();
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/client/java/com/armorhud/util/armorHudModMenu.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.armorhud.util;

import com.armorhud.config.configScreen;
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
import com.armorhud.config.fabricScreen;
import net.minecraft.client.gui.screen.Screen;

public class armorHudModMenu implements ModMenuApi {
Expand All @@ -13,7 +13,7 @@ public ConfigScreenFactory<?> getModConfigScreenFactory() {
}

private Screen createConfigScreen(Screen parent) {
return new fabricScreen(parent);
return new configScreen(parent);
}

}

0 comments on commit 5fee70d

Please sign in to comment.