diff --git a/build.gradle b/build.gradle index c29f44d..2db44c6 100644 --- a/build.gradle +++ b/build.gradle @@ -1,12 +1,17 @@ plugins { - id 'fabric-loom' version '1.11-SNAPSHOT' + id 'fabric-loom' version '1.14-SNAPSHOT' id 'maven-publish' + id 'java' } -sourceCompatibility = JavaVersion.VERSION_16 -targetCompatibility = JavaVersion.VERSION_16 +java { + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 +} -archivesBaseName = project.archives_base_name +base { + archivesName = project.archives_base_name +} version = project.mod_version group = project.maven_group @@ -78,7 +83,7 @@ java { jar { from("LICENSE") { - rename { "${it}_${project.archivesBaseName}"} + rename { "${it}_${project.base.archivesName.get()}"} } } diff --git a/gradle.properties b/gradle.properties index 65c1b03..eedcf27 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,16 +3,16 @@ org.gradle.jvmargs=-Xmx4G # Fabric Properties # check these on https://fabricmc.net/develop - minecraft_version=1.21.9 - yarn_mappings=1.21.9+build.1 - loader_version=0.17.3 + minecraft_version=1.21.11 + yarn_mappings=1.21.11+build.4 + loader_version=0.18.4 # Mod Properties - mod_version = 4.1.1+1.21.9 + mod_version = 4.1.1+1.21.11 maven_group = com.minenash archives_base_name = custom_hud # Dependencies #Fabric api - fabric_version=0.134.0+1.21.9 + fabric_version=0.141.1+1.21.11 modmenu_version=16.0.0-rc.1 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ff23a68..23449a2 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/src/main/java/com/minenash/customhud/CustomHud.java b/src/main/java/com/minenash/customhud/CustomHud.java index ea30c00..d7762d2 100644 --- a/src/main/java/com/minenash/customhud/CustomHud.java +++ b/src/main/java/com/minenash/customhud/CustomHud.java @@ -152,7 +152,11 @@ else if (saveDelay == 0) { ProfileManager.enabled = true; saveDelay = 100; } - for (Toggle t : p.toggles.values()) { + } + // Only check toggles for the active profile to avoid consuming key presses + Profile activeProfile = ProfileManager.getActive(); + if (activeProfile != null) { + for (Toggle t : activeProfile.toggles.values()) { boolean wasPressed = t.key.wasPressed(); if (isKeybindPressed(t.modifier) && wasPressed) t.toggle(); diff --git a/src/main/java/com/minenash/customhud/HudElements/SettingsElement.java b/src/main/java/com/minenash/customhud/HudElements/SettingsElement.java index 899f0db..3199b4d 100644 --- a/src/main/java/com/minenash/customhud/HudElements/SettingsElement.java +++ b/src/main/java/com/minenash/customhud/HudElements/SettingsElement.java @@ -14,7 +14,6 @@ import net.minecraft.sound.SoundCategory; import net.minecraft.util.Arm; import net.minecraft.util.Pair; -import net.minecraft.util.TranslatableOption; import java.util.HashMap; import java.util.Map; @@ -26,7 +25,7 @@ public class SettingsElement { public static boolean initialized = false; //Boolean, Integer, Double - private static final Map> simpleOptions = new HashMap<>(); + public static final Map> simpleOptions = new HashMap<>(); private static final Map staticIntOptions = new HashMap<>(); private static void init() { @@ -132,13 +131,23 @@ private static HudElement getSimpleOptionElement(SimpleOption option, Flags f return new NumberSupplierElement(NumberSupplierElement.of(() -> (Number) option.getValue(), option.getValue() instanceof Integer ? 0 : 1), flags); if (option.getValue() instanceof String) return new StringSupplierElement(() -> ((String)option.getValue()).isEmpty() ? "Default" : (String)option.getValue()); - if (option.getValue() instanceof TranslatableOption) { - final int falseValue = getFalseValue((TranslatableOption) option.getValue()); + if (option.getValue() instanceof ParticlesMode) { return new SpecialSupplierElement(SpecialSupplierElement.of( - () -> ((TranslatableOption)option.getValue()).getText().getString(), - ((TranslatableOption) option.getValue())::getId, - () -> ((TranslatableOption)option.getValue()).getId() != falseValue - )); + () -> ((ParticlesMode) option.getValue()).toString().toLowerCase(), + () -> ((ParticlesMode) option.getValue()).ordinal(), + () -> ((ParticlesMode) option.getValue()).ordinal() != 2)); + } + if (option.getValue() instanceof ChatVisibility) { + return new SpecialSupplierElement(SpecialSupplierElement.of( + () -> ((ChatVisibility) option.getValue()).toString().toLowerCase(), + () -> ((ChatVisibility) option.getValue()).ordinal(), + () -> ((ChatVisibility) option.getValue()).ordinal() != 2)); + } + if (option.getValue() instanceof Arm) { + return new SpecialSupplierElement(SpecialSupplierElement.of( + () -> ((Arm) option.getValue()).toString().toLowerCase(), + () -> ((Arm) option.getValue()).ordinal(), + () -> ((Arm) option.getValue()).ordinal() != 1)); } if (option.getValue() instanceof NarratorMode) return new SpecialSupplierElement(SpecialSupplierElement.of( @@ -149,13 +158,4 @@ private static HudElement getSimpleOptionElement(SimpleOption option, Flags f return null; } - private static int getFalseValue(TranslatableOption option) { - if (option instanceof ParticlesMode || option instanceof ChatVisibility) - return 2; - if (option instanceof Arm) - return 1; - return 0; // GraphicsMode, AoMode, ChunkBuilderMode, CloudRenderMode, AttackIndicator - - } - } diff --git a/src/main/java/com/minenash/customhud/HudElements/supplier/IntegerSuppliers.java b/src/main/java/com/minenash/customhud/HudElements/supplier/IntegerSuppliers.java index f89069f..fd7657d 100644 --- a/src/main/java/com/minenash/customhud/HudElements/supplier/IntegerSuppliers.java +++ b/src/main/java/com/minenash/customhud/HudElements/supplier/IntegerSuppliers.java @@ -170,7 +170,7 @@ private static double biome(DensityFunction function, MultiNoiseUtil.ParameterRa public static final Supplier WORLD_HEIGHT = () -> ComplexData.world.getHeight(); public static final Supplier WORLD_COORD_SCALE = () -> ComplexData.world.getDimension().coordinateScale();; - public static final Supplier MOON_PHASE = () -> ComplexData.clientChunk.isEmpty() ? null : client.world.getMoonPhase()+1; + public static final Supplier MOON_PHASE = () -> ComplexData.clientChunk.isEmpty() ? null : (int)(client.world.getTimeOfDay() / 24000L % 8L) + 1; public static final Supplier SPAWN_CHUNKS = () -> { SpawnHelper.Info info = ComplexData.serverWorld.getChunkManager().getSpawnInfo(); diff --git a/src/main/java/com/minenash/customhud/HudElements/supplier/SpecialSupplierElement.java b/src/main/java/com/minenash/customhud/HudElements/supplier/SpecialSupplierElement.java index 768ed32..9fa54f3 100644 --- a/src/main/java/com/minenash/customhud/HudElements/supplier/SpecialSupplierElement.java +++ b/src/main/java/com/minenash/customhud/HudElements/supplier/SpecialSupplierElement.java @@ -2,12 +2,15 @@ import com.minenash.customhud.complex.ComplexData; import com.minenash.customhud.HudElements.interfaces.HudElement; +import com.minenash.customhud.HudElements.SettingsElement; +import com.minenash.customhud.mixin.accessors.GameOptionsAccessor; import net.fabricmc.fabric.api.renderer.v1.Renderer; import net.minecraft.block.Block; import net.minecraft.client.MinecraftClient; import net.minecraft.client.option.CloudRenderMode; import net.minecraft.client.option.GameOptions; import net.minecraft.client.option.GraphicsMode; +import net.minecraft.client.option.SimpleOption; import net.minecraft.client.resource.language.I18n; import net.minecraft.fluid.Fluid; import net.minecraft.item.Item; @@ -76,13 +79,47 @@ private static boolean isFacingEastOrSouth() { () -> client.player.getOffHandStack().getName().getString().length(), () -> !client.player.getOffHandStack().isEmpty()); - public static final Entry GRAPHICS_MODE = of( () -> client.options.getGraphicsMode().getValue().toString(), - () -> client.options.getGraphicsMode().getValue() == GraphicsMode.FAST ? 0 : (client.options.getGraphicsMode().getValue() == GraphicsMode.FANCY ? 1 : 2), - () -> true); - - public static final Entry CLOUDS = of( () -> client.options.getCloudRenderMode().getValue() == CloudRenderMode.OFF ? "off" : (client.options.getCloudRenderMode().getValue() == CloudRenderMode.FAST ? "fast" : "fancy"), - () -> client.options.getCloudRenderMode().getValue() == CloudRenderMode.OFF ? 0 : (client.options.getCloudRenderMode().getValue() == CloudRenderMode.FAST ? 1 : 2), - () -> client.options.getCloudRenderMode().getValue() != CloudRenderMode.OFF); + public static final Entry GRAPHICS_MODE = of(() -> { + if (!SettingsElement.initialized) + return "fancy"; + var opt = SettingsElement.simpleOptions.get("graphicsmode"); + if (opt == null) + return "fancy"; + var value = opt.getValue(); + return value instanceof GraphicsMode ? value.toString().toLowerCase() : "fancy"; + }, + () -> { + if (!SettingsElement.initialized) + return 1; + var opt = SettingsElement.simpleOptions.get("graphicsmode"); + if (opt == null) + return 1; + var value = opt.getValue(); + if (value instanceof GraphicsMode) { + return ((GraphicsMode) value) == GraphicsMode.FAST ? 0 + : (((GraphicsMode) value) == GraphicsMode.FANCY ? 1 : 2); + } + return 1; + }, + () -> true); + + public static final Entry CLOUDS = of( + () -> { + @SuppressWarnings("unchecked") + var opt = (SimpleOption) ((GameOptionsAccessor) client.options).getCloudRenderMode(); + return opt.getValue() == CloudRenderMode.OFF ? "off" + : (opt.getValue() == CloudRenderMode.FAST ? "fast" : "fancy"); + }, + () -> { + @SuppressWarnings("unchecked") + var opt = (SimpleOption) ((GameOptionsAccessor) client.options).getCloudRenderMode(); + return opt.getValue() == CloudRenderMode.OFF ? 0 : (opt.getValue() == CloudRenderMode.FAST ? 1 : 2); + }, + () -> { + @SuppressWarnings("unchecked") + var opt = (SimpleOption) ((GameOptionsAccessor) client.options).getCloudRenderMode(); + return opt.getValue() != CloudRenderMode.OFF; + }); public static final Entry GAMEMODE = of ( () -> client.interactionManager.getCurrentGameMode().getId(), () -> client.interactionManager.getCurrentGameMode().getIndex(), diff --git a/src/main/java/com/minenash/customhud/HudElements/supplier/StringSupplierElement.java b/src/main/java/com/minenash/customhud/HudElements/supplier/StringSupplierElement.java index 2b82a6d..17d2fb2 100644 --- a/src/main/java/com/minenash/customhud/HudElements/supplier/StringSupplierElement.java +++ b/src/main/java/com/minenash/customhud/HudElements/supplier/StringSupplierElement.java @@ -47,7 +47,7 @@ public class StringSupplierElement implements HudElement { public static final Supplier BIOME = () -> I18n.translate("biome." + client.world.getBiome(blockPos()).getKey().get().getValue().toString().replace(':', '.')); private static final String[] moon_phases = new String[]{"full moon", "waning gibbous", "last quarter", "waning crescent", "new moon", "waxing crescent", "first quarter", "waxing gibbous"}; - public static final Supplier MOON_PHASE_WORD = () -> ComplexData.clientChunk.isEmpty() ? null : moon_phases[client.world.getMoonPhase()]; + public static final Supplier MOON_PHASE_WORD = () -> ComplexData.clientChunk.isEmpty() ? null : moon_phases[(int) (client.world.getTimeOfDay() / 24000L % 8L)]; public static final Supplier TIME_AM_PM = () -> ComplexData.timeOfDay < 12000 ? "am" : "pm"; diff --git a/src/main/java/com/minenash/customhud/complex/ComplexData.java b/src/main/java/com/minenash/customhud/complex/ComplexData.java index e45e550..5112789 100644 --- a/src/main/java/com/minenash/customhud/complex/ComplexData.java +++ b/src/main/java/com/minenash/customhud/complex/ComplexData.java @@ -200,7 +200,8 @@ public static void update(Profile profile) { if (profile.enabled.localDifficulty) { Profilers.get().push("localDifficulty"); - localDifficulty = new LocalDifficulty(world.getDifficulty(), world.getTimeOfDay(), serverChunk == null ? 0 : serverChunk.getInhabitedTime(), world.getMoonSize()); + localDifficulty = new LocalDifficulty(world.getDifficulty(), world.getTimeOfDay(), + serverChunk == null ? 0 : serverChunk.getInhabitedTime(), world.getTimeOfDay()); Profilers.get().pop(); } diff --git a/src/main/java/com/minenash/customhud/mixin/InGameHudMixin.java b/src/main/java/com/minenash/customhud/mixin/InGameHudMixin.java index 46b1cad..83815b3 100644 --- a/src/main/java/com/minenash/customhud/mixin/InGameHudMixin.java +++ b/src/main/java/com/minenash/customhud/mixin/InGameHudMixin.java @@ -29,9 +29,9 @@ private boolean getDebugCrosshairEnable(boolean original) { @WrapWithCondition(method = "renderCrosshair", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawGuiTexture(Lcom/mojang/blaze3d/pipeline/RenderPipeline;Lnet/minecraft/util/Identifier;IIII)V", ordinal = 0)) private boolean skipNormalCrosshairRendering0(DrawContext instance, RenderPipeline pipeline, Identifier sprite, int x, int y, int width, int height) { - return ProfileManager.getActive() != null && ProfileManager.getActive().crosshair == Crosshairs.NORMAL; + return ProfileManager.getActive() == null || ProfileManager.getActive().crosshair == Crosshairs.NORMAL; } - } + diff --git a/src/main/java/com/minenash/customhud/mixin/KeyBindingMixin.java b/src/main/java/com/minenash/customhud/mixin/KeyBindingMixin.java index 507740e..e3b7496 100644 --- a/src/main/java/com/minenash/customhud/mixin/KeyBindingMixin.java +++ b/src/main/java/com/minenash/customhud/mixin/KeyBindingMixin.java @@ -20,7 +20,10 @@ private static void checkKeybinds(InputUtil.Key key, CallbackInfo ci) { for (Profile p : ProfileManager.getProfiles()) { if (p.keyBinding.matchesKey(input)) ++p.keyBinding.timesPressed; - for (Toggle t : p.toggles.values()) { + } + Profile activeProfile = ProfileManager.getActive(); + if (activeProfile != null) { + for (Toggle t : activeProfile.toggles.values()) { if (t.key.matchesKey(input)) ++t.key.timesPressed; } diff --git a/src/main/java/com/minenash/customhud/mixin/PlayerEntityMixin.java b/src/main/java/com/minenash/customhud/mixin/PlayerEntityMixin.java index 059a804..5faed7e 100644 --- a/src/main/java/com/minenash/customhud/mixin/PlayerEntityMixin.java +++ b/src/main/java/com/minenash/customhud/mixin/PlayerEntityMixin.java @@ -13,7 +13,7 @@ @Mixin(PlayerEntity.class) public class PlayerEntityMixin { - @Inject(method = "attack", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;resetLastAttackedTicks()V")) + @Inject(method = "attack", at = @At("HEAD")) private void logAttack(Entity target, CallbackInfo ci) { if (((Object)this) == MinecraftClient.getInstance().player && ComplexData.targetEntityHitPos != null) { ComplexData.lastHitEntity = target; diff --git a/src/main/java/com/minenash/customhud/mixin/accessors/GameOptionsAccessor.java b/src/main/java/com/minenash/customhud/mixin/accessors/GameOptionsAccessor.java index d222cea..cf5f055 100644 --- a/src/main/java/com/minenash/customhud/mixin/accessors/GameOptionsAccessor.java +++ b/src/main/java/com/minenash/customhud/mixin/accessors/GameOptionsAccessor.java @@ -16,4 +16,7 @@ public interface GameOptionsAccessor { @Accessor Map> getSoundVolumeLevels(); + @Accessor("cloudRenderMode") + SimpleOption getCloudRenderMode(); + }