Skip to content

Commit

Permalink
use forge gui offset to render faction level
Browse files Browse the repository at this point in the history
fix #1234
- add compatibility with changed config values
  • Loading branch information
Cheaterpaul committed Jul 17, 2023
1 parent 91d0a7d commit 664e2b8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void render(@NotNull ForgeGui gui, @NotNull PoseStack mStack, float parti

FactionPlayerHandler.getOpt(this.mc.player).ifPresent(handler -> {
IPlayableFaction<?> faction = handler.getCurrentFaction();
if (this.mc.gameMode.hasExperience() && faction != null) {
if (this.mc.gameMode != null && this.mc.gameMode.hasExperience() && faction != null) {
// boolean flag1 = false;
int color = faction.getColor();
int lord = handler.getLordLevel();
Expand All @@ -29,10 +29,10 @@ public void render(@NotNull ForgeGui gui, @NotNull PoseStack mStack, float parti
String title = handler.getLordTitle().getString();
text = title.substring(0, Math.min(3, title.length()));
} else {
text = "" + handler.getCurrentLevel();
text = String.valueOf(handler.getCurrentLevel());
}
int x = (this.mc.getWindow().getGuiScaledWidth() - this.mc.font.width(text)) / 2 + VampirismConfig.CLIENT.guiLevelOffsetX.get();
int y = this.mc.getWindow().getGuiScaledHeight() - VampirismConfig.CLIENT.guiLevelOffsetY.get();
int y = this.mc.getWindow().getGuiScaledHeight() - VampirismConfig.CLIENT.guiLevelOffsetY.get() - gui.rightHeight;
this.mc.font.draw(mStack, text, x + 1, y, 0);
this.mc.font.draw(mStack, text, x - 1, y, 0);
this.mc.font.draw(mStack, text, x, y + 1, 0);
Expand Down
17 changes: 15 additions & 2 deletions src/main/java/de/teamlapen/vampirism/config/VampirismConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import de.teamlapen.lib.lib.util.UtilLib;
import de.teamlapen.vampirism.REFERENCE;
import de.teamlapen.vampirism.VampirismMod;
import de.teamlapen.vampirism.api.ThreadSafeAPI;
import de.teamlapen.vampirism.api.VampirismAPI;
Expand All @@ -13,7 +14,12 @@
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.config.ModConfigEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.commons.compress.archivers.sevenz.CLI;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -111,7 +117,12 @@ public static void finalizeAndRegisterConfig() {
public static void onLoad(final ModConfigEvent.@NotNull Loading configEvent) {
if (configEvent.getConfig().getType() == ModConfig.Type.SERVER) {
((SundamageRegistry) VampirismAPI.sundamageRegistry()).reloadConfiguration();

}
if (configEvent.getConfig().getSpec() == clientSpec) {
if (CLIENT.guiLevelOffsetYOld.get() == 0) {
CLIENT.guiLevelOffsetYOld.set(CLIENT.guiLevelOffsetY.get());
CLIENT.guiLevelOffsetY.set(CLIENT.guiLevelOffsetY.get() - 49);
}
}
}

Expand Down Expand Up @@ -235,6 +246,7 @@ public static class Client {
public final ForgeConfigSpec.BooleanValue disableBloodVisionRendering;
public final ForgeConfigSpec.BooleanValue disableHudActionCooldownRendering;
public final ForgeConfigSpec.BooleanValue disableHudActionDurationRendering;
public final ForgeConfigSpec.IntValue guiLevelOffsetYOld;

Client(ForgeConfigSpec.@NotNull Builder builder) {
builder.comment("Client configuration settings")
Expand All @@ -252,7 +264,7 @@ public static class Client {

builder.comment("Configure GUI").push("gui");
guiLevelOffsetX = builder.comment("X-Offset of the level indicator from the center in pixels").defineInRange("levelOffsetX", 0, -250, 250);
guiLevelOffsetY = builder.comment("Y-Offset of the level indicator from the bottom in pixels").defineInRange("levelOffsetY", 47, 0, 270);
guiLevelOffsetY = builder.comment("Y-Offset of the level indicator from the bottom in pixels").defineInRange("levelOffsetY", 0, 0, 270);
guiSkillButton = builder.comment("Render skill menu button in inventory").define("skillButtonEnable", true);
overrideGuiSkillButtonX = builder.comment("Force the guiSkillButton to the following x position from the center of the inventory, default value is 125").defineInRange("overrideGuiSkillButtonX", 125, Integer.MIN_VALUE, Integer.MAX_VALUE);
overrideGuiSkillButtonY = builder.comment("Force the guiSkillButton to the following y position from the center of the inventory, default value is -22").defineInRange("overrideGuiSkillButtonY", -22, Integer.MIN_VALUE, Integer.MAX_VALUE);
Expand All @@ -263,6 +275,7 @@ public static class Client {
disableHudActionCooldownRendering = builder.comment("Disable the rendering of the action cooldowns in the HUD").define("disableHudActionCooldownRendering", false);
disableHudActionDurationRendering = builder.comment("Disable the rendering of the action durations in the HUD").define("disableHudActionDurationRendering", false);

guiLevelOffsetYOld = builder.comment("Old fixed Y offset of level overlay").defineInRange("levelOffsetYOld", 0, 0, 270);
builder.pop();

builder.pop();
Expand Down

0 comments on commit 664e2b8

Please sign in to comment.