From 730df42c620fd403e18d299cc099ad664dc04955 Mon Sep 17 00:00:00 2001 From: Taken Date: Thu, 15 Jan 2026 11:25:51 +0100 Subject: [PATCH 1/3] Made a version for 1.21.11 --- build.gradle | 15 +- gradle.properties | 20 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../HudElements/SettingsElement.java | 65 +- .../supplier/IntegerSuppliers.java | 582 +++++++++++------- .../supplier/SpecialSupplierElement.java | 192 ++++-- .../supplier/StringSupplierElement.java | 129 ++-- .../customhud/complex/ComplexData.java | 121 ++-- .../customhud/mixin/PlayerEntityMixin.java | 8 +- .../mixin/accessors/GameOptionsAccessor.java | 9 +- 10 files changed, 698 insertions(+), 445 deletions(-) diff --git a/build.gradle b/build.gradle index c29f44df..2db44c65 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 65c1b03e..20ccf379 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,17 +2,17 @@ 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 +# check these on https://fabricmc.net/develop +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 - maven_group = com.minenash - archives_base_name = custom_hud +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 - modmenu_version=16.0.0-rc.1 +#Fabric api +fabric_version=0.141.1+1.21.11 +modmenu_version=16.0.0-rc.1 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ff23a68d..23449a2b 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/HudElements/SettingsElement.java b/src/main/java/com/minenash/customhud/HudElements/SettingsElement.java index 899f0db5..8d142231 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; @@ -25,12 +24,12 @@ public class SettingsElement { private static final MinecraftClient client = MinecraftClient.getInstance(); public static boolean initialized = false; - //Boolean, Integer, Double - private static final Map> simpleOptions = new HashMap<>(); + // Boolean, Integer, Double + public static final Map> simpleOptions = new HashMap<>(); private static final Map staticIntOptions = new HashMap<>(); private static void init() { - ((GameOptionsAccessor)MinecraftClient.getInstance().options).invokeAccept(new GameOptions.Visitor() { + ((GameOptionsAccessor) MinecraftClient.getInstance().options).invokeAccept(new GameOptions.Visitor() { @Override public void accept(String key, SimpleOption option) { simpleOptions.put(key.toLowerCase(), option); @@ -38,7 +37,8 @@ public void accept(String key, SimpleOption option) { @Override public int visitInt(String key, int current) { - staticIntOptions.put(key.toLowerCase(), current); return current; + staticIntOptions.put(key.toLowerCase(), current); + return current; } @Override @@ -63,7 +63,7 @@ public T visitObject(String key, T current, Function decoder, Fun }); } - public static Pair> create(String setting, Flags flags) { + public static Pair> create(String setting, Flags flags) { if (!initialized) init(); initialized = true; @@ -76,7 +76,8 @@ public static Pair> create(String setting, Fla String code = client.getLanguageManager().getLanguage(); HudElement element = switch (setting.substring(4)) { case "" -> new StringSupplierElement(() -> client.getLanguageManager().getLanguage(code).name()); - case "_region" -> new StringSupplierElement(() -> client.getLanguageManager().getLanguage(code).region()); + case "_region" -> + new StringSupplierElement(() -> client.getLanguageManager().getLanguage(code).region()); case "_code" -> new StringSupplierElement(() -> code); default -> null; }; @@ -96,8 +97,7 @@ else if (setting.startsWith("sound_")) return new Pair<>(new SpecialSupplierElement(SpecialSupplierElement.of( () -> binding.getBoundKeyLocalizedText().getString(), () -> ((KeyBindingAccessor) binding).getBoundKey().getCode(), - () -> !binding.isUnbound() - )), null); + () -> !binding.isUnbound())), null); return new Pair<>(null, new Pair<>(ErrorType.UNKNOWN_KEYBIND, key)); } @@ -106,9 +106,10 @@ else if (setting.startsWith("sound_")) for (SoundCategory soundCategory : SoundCategory.values()) if (soundCategory.getName().equalsIgnoreCase(cat)) return new Pair<>(new NumberSupplierElement(NumberSupplierElement.of( - () -> ((GameOptionsAccessor)options).getSoundVolumeLevels().get(soundCategory).getValue() * 100, + () -> ((GameOptionsAccessor) options).getSoundVolumeLevels().get(soundCategory).getValue() + * 100, flags.precision != -1 ? flags.precision : 0), flags), null); - return new Pair<>(null,new Pair<>(ErrorType.UNKNOWN_SOUND_CATEGORY, cat)); + return new Pair<>(null, new Pair<>(ErrorType.UNKNOWN_SOUND_CATEGORY, cat)); } SimpleOption option = simpleOptions.get(setting); @@ -117,7 +118,7 @@ else if (setting.startsWith("sound_")) if (staticIntOptions.containsKey(setting)) { int value = staticIntOptions.get(setting); - return new Pair<>(new NumberSupplierElement(() -> value, flags),null); + return new Pair<>(new NumberSupplierElement(() -> value, flags), null); } return new Pair<>(null, new Pair<>(ErrorType.UNKNOWN_SETTING, setting)); @@ -129,33 +130,35 @@ private static HudElement getSimpleOptionElement(SimpleOption option, Flags f if (option.getValue() instanceof Boolean) return new BooleanSupplierElement(() -> (Boolean) option.getValue()); if (option.getValue() instanceof Number) - return new NumberSupplierElement(NumberSupplierElement.of(() -> (Number) option.getValue(), option.getValue() instanceof Integer ? 0 : 1), flags); + 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()); + return new StringSupplierElement( + () -> ((String) option.getValue()).isEmpty() ? "Default" : (String) option.getValue()); + if (option.getValue() instanceof ParticlesMode) { + return new SpecialSupplierElement(SpecialSupplierElement.of( + () -> ((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( - () -> ((TranslatableOption)option.getValue()).getText().getString(), - ((TranslatableOption) option.getValue())::getId, - () -> ((TranslatableOption)option.getValue()).getId() != falseValue - )); + () -> ((Arm) option.getValue()).toString().toLowerCase(), + () -> ((Arm) option.getValue()).ordinal(), + () -> ((Arm) option.getValue()).ordinal() != 1)); } if (option.getValue() instanceof NarratorMode) return new SpecialSupplierElement(SpecialSupplierElement.of( () -> ((NarratorMode) option.getValue()).getName().getString(), () -> ((NarratorMode) option.getValue()).getId(), - () -> ((NarratorMode) option.getValue()).getId() != 0 - )); + () -> ((NarratorMode) option.getValue()).getId() != 0)); 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 f89069f3..4ea44fa4 100644 --- a/src/main/java/com/minenash/customhud/HudElements/supplier/IntegerSuppliers.java +++ b/src/main/java/com/minenash/customhud/HudElements/supplier/IntegerSuppliers.java @@ -37,236 +37,356 @@ public class IntegerSuppliers { - private static final MinecraftClient client = MinecraftClient.getInstance(); - private static WorldRenderer worldRender() { - return client.worldRenderer; - } - private static ChunkBuilder chunkBuilder() { - return worldRender().getChunkBuilder(); - } - private static BlockPos blockPos() { return client.getCameraEntity().getBlockPos(); } - private static LightingProvider serverLighting() { return ComplexData.world.getChunkManager().getLightingProvider(); } - - private static Integer chunk(WorldChunk chunk, Heightmap.Type type) { - if (chunk == null) return null; - BlockPos pos = client.getCameraEntity().getBlockPos(); - return chunk.sampleHeightmap(type, pos.getX(), pos.getZ()); - } - - private static Integer spawnGroup(SpawnGroup group) { - SpawnHelper.Info info = ComplexData.serverWorld.getChunkManager().getSpawnInfo(); - return info == null ? null : info.getGroupToCount().getInt(group); - } - - private static double biome(DensityFunction function, MultiNoiseUtil.ParameterRange[] range) { - double d = (double)MultiNoiseUtil.toLong((float) EntryNumberSuppliers.sample(function)); - for(int i = 0; i < range.length; ++i) - if (d < (double)range[i].max()) - return i; - return Double.NaN; - } - - public static final Supplier PROFILE_ERRORS = () -> ProfileManager.getActive() == null ? 0 : Errors.getErrors(ProfileManager.getActive().name).size(); - - public static final Supplier FPS = client::getCurrentFps; - public static final Supplier BIOME_BLEND = () -> client.options.getBiomeBlendRadius().getValue(); - public static final Supplier SIMULATION_DISTANCE = () -> client.options.getSimulationDistance().getValue(); - - public static final Supplier PACKETS_SENT = () -> (int)client.getNetworkHandler().getConnection().getAveragePacketsSent(); - public static final Supplier PACKETS_RECEIVED = () -> (int)client.getNetworkHandler().getConnection().getAveragePacketsReceived(); - public static final Supplier CHUNKS_RENDERED = () -> worldRender().getCompletedChunkCount(); - public static final Supplier CHUNKS_LOADED = () -> worldRender().getChunkCount(); - @SuppressWarnings("Convert2MethodRef" ) - public static final Supplier RENDER_DISTANCE = () -> client.options.getClampedViewDistance(); - public static final Supplier QUEUED_TASKS = () -> chunkBuilder().getScheduledTaskCount(); - public static final Supplier UPLOAD_QUEUE = () -> chunkBuilder().getChunksToUpload(); - public static final Supplier BUFFER_COUNT = () -> chunkBuilder().getFreeBufferCount(); - public static final Supplier ENTITIES_RENDERED = () -> worldRender().worldRenderState.entityRenderStates.size(); - public static final Supplier ENTITIES_LOADED = () -> client.world.getRegularEntityCount(); - - public static final Supplier FORCED_LOADED_CHUNKS = () -> ComplexData.world instanceof ServerWorld ? ((ServerWorld)ComplexData.world).getForcedChunks().size() : null; - - public static final Supplier BLOCK_X = () -> blockPos().getX(); - public static final Supplier BLOCK_Y = () -> blockPos().getY(); - public static final Supplier BLOCK_Z = () -> blockPos().getZ(); - public static final Supplier TARGET_BLOCK_X = () -> targetBlockPos == null ? null : targetBlockPos.getX(); - public static final Supplier TARGET_BLOCK_Y = () -> targetBlockPos == null ? null : targetBlockPos.getY(); - public static final Supplier TARGET_BLOCK_Z = () -> targetBlockPos == null ? null : targetBlockPos.getZ(); - public static final Supplier TARGET_BLOCK_DISTANCE = () -> targetBlockPos == null ? null : targetBlockPos.getManhattanDistance(client.player.getBlockPos()); - public static final Supplier TARGET_BLOCK_COLOR = () -> targetBlock == null || targetBlock.isAir() ? null : targetBlock.getMapColor(client.world, targetBlockPos).color; - public static final Supplier TARGET_BLOCK_LUMINANCE = () -> targetBlock == null || targetBlock.isAir() ? null : ComplexData.world.getLuminance(targetBlockPos); - public static final Supplier TARGET_FLUID_X = () -> ComplexData.targetFluidPos == null ? null : ComplexData.targetFluidPos.getX(); - public static final Supplier TARGET_FLUID_Y = () -> ComplexData.targetFluidPos == null ? null : ComplexData.targetFluidPos.getY(); - public static final Supplier TARGET_FLUID_Z = () -> ComplexData.targetFluidPos == null ? null : ComplexData.targetFluidPos.getZ(); - public static final Supplier TARGET_FLUID_DISTANCE = () -> ComplexData.targetFluidPos == null ? null : ComplexData.targetFluidPos.getManhattanDistance(client.player.getBlockPos()); - public static final Supplier TARGET_FLUID_COLOR = () -> ComplexData.targetFluid == null || ComplexData.targetFluid.isEmpty()? null : ComplexData.targetFluid.getBlockState().getMapColor(client.world, ComplexData.targetFluidPos).color; - - public static final Supplier TARGET_BLOCK_POWERED = () -> targetBlockPos == null ? null : client.world.getReceivedRedstonePower(targetBlockPos); - public static final Supplier TARGET_BLOCK_POWERED_NORTH = () -> targetBlockPos == null ? null : client.world.getEmittedRedstonePower(targetBlockPos.offset(Direction.NORTH), Direction.NORTH); - public static final Supplier TARGET_BLOCK_POWERED_SOUTH = () -> targetBlockPos == null ? null : client.world.getEmittedRedstonePower(targetBlockPos.offset(Direction.SOUTH), Direction.SOUTH); - public static final Supplier TARGET_BLOCK_POWERED_EAST = () -> targetBlockPos == null ? null : client.world.getEmittedRedstonePower(targetBlockPos.offset(Direction.EAST), Direction.EAST); - public static final Supplier TARGET_BLOCK_POWERED_WEST = () -> targetBlockPos == null ? null : client.world.getEmittedRedstonePower(targetBlockPos.offset(Direction.WEST), Direction.WEST); - public static final Supplier TARGET_BLOCK_POWERED_UP = () -> targetBlockPos == null ? null : client.world.getEmittedRedstonePower(targetBlockPos.offset(Direction.UP), Direction.UP); - public static final Supplier TARGET_BLOCK_POWERED_DOWN = () -> targetBlockPos == null ? null : client.world.getEmittedRedstonePower(targetBlockPos.offset(Direction.DOWN), Direction.DOWN); - - public static final Supplier TARGET_BLOCK_STRONG_POWERED = () -> targetBlockPos == null ? null : client.world.getReceivedStrongRedstonePower(targetBlockPos); - public static final Supplier TARGET_BLOCK_STRONG_POWERED_NORTH = () -> targetBlockPos == null ? null : client.world.getStrongRedstonePower(targetBlockPos.offset(Direction.NORTH), Direction.NORTH); - public static final Supplier TARGET_BLOCK_STRONG_POWERED_SOUTH = () -> targetBlockPos == null ? null : client.world.getStrongRedstonePower(targetBlockPos.offset(Direction.SOUTH), Direction.SOUTH); - public static final Supplier TARGET_BLOCK_STRONG_POWERED_EAST = () -> targetBlockPos == null ? null : client.world.getStrongRedstonePower(targetBlockPos.offset(Direction.EAST), Direction.EAST); - public static final Supplier TARGET_BLOCK_STRONG_POWERED_WEST = () -> targetBlockPos == null ? null : client.world.getStrongRedstonePower(targetBlockPos.offset(Direction.WEST), Direction.WEST); - public static final Supplier TARGET_BLOCK_STRONG_POWERED_UP = () -> targetBlockPos == null ? null : client.world.getStrongRedstonePower(targetBlockPos.offset(Direction.UP), Direction.UP); - public static final Supplier TARGET_BLOCK_STRONG_POWERED_DOWN = () -> targetBlockPos == null ? null : client.world.getStrongRedstonePower(targetBlockPos.offset(Direction.DOWN), Direction.DOWN); - - public static final Supplier IN_CHUNK_X = () -> blockPos().getX() & 15; - public static final Supplier IN_CHUNK_Y = () -> blockPos().getY() & 15; - public static final Supplier IN_CHUNK_Z = () -> blockPos().getZ() & 15; - public static final Supplier CHUNK_X = () -> blockPos().getX() >> 4; - public static final Supplier CHUNK_Y = () -> blockPos().getY() >> 4; - public static final Supplier CHUNK_Z = () -> blockPos().getZ() >> 4; - public static final Supplier REGION_X = () -> blockPos().getX() >> 9; - public static final Supplier REGION_Z = () -> blockPos().getZ() >> 9; - public static final Supplier REGION_RELATIVE_X = () -> blockPos().getX() >> 4 & 0x1F; - public static final Supplier REGION_RELATIVE_Z = () -> blockPos().getZ() >> 4 & 0x1F; - - public static final Supplier CHUNK_CLIENT_CACHED = () -> client.world.getChunkManager().chunks.chunks.length(); - public static final Supplier CHUNK_CLIENT_LOADED = () -> client.world.getChunkManager().getLoadedChunkCount(); - public static final Supplier CHUNK_CLIENT_ENTITIES_LOADED = () -> client.world.getRegularEntityCount(); - public static final Supplier CHUNK_CLIENT_ENTITIES_CACHED_SECTIONS = () -> client.world.entityManager.cache.sectionCount(); - public static final Supplier CHUNK_CLIENT_ENTITIES_TICKING_CHUNKS = () -> client.world.entityManager.tickingChunkSections.size(); - - public static final Supplier CHUNK_SERVER_LOADED = () -> ComplexData.serverWorld == null ? null : ComplexData.serverWorld.getChunkManager().getLoadedChunkCount(); - public static final Supplier CHUNK_SERVER_ENTITIES_REGISTERED = () -> ComplexData.serverWorld == null ? null : ComplexData.serverWorld.entityManager.entityUuids.size(); - public static final Supplier CHUNK_SERVER_ENTITIES_LOADED = () -> ComplexData.serverWorld == null ? null : ComplexData.serverWorld.entityManager.index.size(); - public static final Supplier CHUNK_SERVER_ENTITIES_CACHED_SECTIONS = () -> ComplexData.serverWorld == null ? null : ComplexData.serverWorld.entityManager.cache.sectionCount(); - public static final Supplier CHUNK_SERVER_ENTITIES_MANAGED = () -> ComplexData.serverWorld == null ? null : ComplexData.serverWorld.entityManager.managedStatuses.size(); - public static final Supplier CHUNK_SERVER_ENTITIES_TRACKED = () -> ComplexData.serverWorld == null ? null : ComplexData.serverWorld.entityManager.trackingStatuses.size(); - public static final Supplier CHUNK_SERVER_ENTITIES_LOADING = () -> ComplexData.serverWorld == null ? null : ComplexData.serverWorld.entityManager.loadingQueue.size(); - public static final Supplier CHUNK_SERVER_ENTITIES_UNLOADING = () -> ComplexData.serverWorld == null ? null : ComplexData.serverWorld.entityManager.pendingUnloads.size(); - - public static final Supplier CLIENT_LIGHT = () -> { - if (ComplexData.clientChunk.isEmpty()) return null; - client.world.calculateAmbientDarkness(); - return Math.max(0, client.world.getChunkManager().getLightingProvider().getLight(blockPos(), client.world.getAmbientDarkness())); - }; - public static final Supplier CLIENT_LIGHT_SKY = () -> ComplexData.clientChunk.isEmpty() ? null : client.world.getLightLevel(LightType.SKY, blockPos()); - public static final Supplier CLIENT_LIGHT_SUN = () -> { - if (ComplexData.clientChunk.isEmpty()) return null; - client.world.calculateAmbientDarkness(); - return Math.max(0, client.world.getLightLevel(LightType.SKY, blockPos()) - client.world.getAmbientDarkness()); - }; - public static final Supplier CLIENT_LIGHT_BLOCK = () -> ComplexData.clientChunk.isEmpty() ? null : client.world.getLightLevel(LightType.BLOCK, blockPos()); - @Deprecated public static final Supplier SERVER_LIGHT_SKY = () -> ComplexData.serverChunk == null ? null : serverLighting().get(LightType.SKY).getLightLevel(blockPos()); - @Deprecated public static final Supplier SERVER_LIGHT_BLOCK = () -> ComplexData.serverChunk == null ? null : serverLighting().get(LightType.BLOCK).getLightLevel(blockPos()); - - public static final Supplier CLIENT_HEIGHT_MAP_SURFACE = () -> chunk(ComplexData.clientChunk, Heightmap.Type.WORLD_SURFACE); - public static final Supplier CLIENT_HEIGHT_MAP_MOTION_BLOCKING = () -> chunk(ComplexData.clientChunk, Heightmap.Type.MOTION_BLOCKING); - public static final Supplier SERVER_HEIGHT_MAP_SURFACE = () -> chunk(ComplexData.serverChunk, Heightmap.Type.WORLD_SURFACE); - public static final Supplier SERVER_HEIGHT_MAP_OCEAN_FLOOR = () -> chunk(ComplexData.serverChunk, Heightmap.Type.OCEAN_FLOOR); - public static final Supplier SERVER_HEIGHT_MAP_MOTION_BLOCKING = () -> chunk(ComplexData.serverChunk, Heightmap.Type.MOTION_BLOCKING); - public static final Supplier SERVER_HEIGHT_MAP_MOTION_BLOCKING_NO_LEAVES = () -> chunk(ComplexData.serverChunk, Heightmap.Type.MOTION_BLOCKING_NO_LEAVES); - - public static final Supplier WORLD_MIN_Y = () -> ComplexData.world.getBottomY(); - public static final Supplier WORLD_MAX_Y = () -> ComplexData.world.getTopYInclusive(); - 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 SPAWN_CHUNKS = () -> { - SpawnHelper.Info info = ComplexData.serverWorld.getChunkManager().getSpawnInfo(); - return info == null ? null : info.getSpawningChunkCount(); - }; - public static final Supplier MONSTERS = () -> spawnGroup(SpawnGroup.MONSTER); - public static final Supplier CREATURES = () -> spawnGroup(SpawnGroup.CREATURE); - public static final Supplier AMBIENT_MOBS = () -> spawnGroup(SpawnGroup.AMBIENT); - public static final Supplier WATER_CREATURES = () -> spawnGroup(SpawnGroup.WATER_CREATURE); - public static final Supplier WATER_AMBIENT_MOBS = () -> spawnGroup(SpawnGroup.WATER_AMBIENT); - public static final Supplier UNDERGROUND_WATER_CREATURE = () -> spawnGroup(SpawnGroup.UNDERGROUND_WATER_CREATURE); - public static final Supplier AXOLOTLS = () -> spawnGroup(SpawnGroup.AXOLOTLS); - public static final Supplier MISC_MOBS = () -> spawnGroup(SpawnGroup.MISC); - - public static final Supplier JAVA_BIT = () -> 64; - public static final Supplier CPU_CORES = () -> ComplexData.cpu == null ? null : ((CentralProcessor)ComplexData.cpu).getPhysicalProcessorCount(); - public static final Supplier CPU_THREADS = () -> ComplexData.cpu == null ? null : ((CentralProcessor)ComplexData.cpu).getLogicalProcessorCount(); - - public static final Supplier DISPLAY_WIDTH = () -> client.getWindow().getFramebufferWidth(); - public static final Supplier DISPLAY_HEIGHT = () -> client.getWindow().getFramebufferHeight(); - public static final Supplier DISPLAY_REFRESH_RATE = () -> GLX._getRefreshRate(client.getWindow()); - public static final Supplier PING = () -> Math.round(ComplexData.pingMetrics[0]); - public static final Supplier LATENCY = () -> client.player.networkHandler.getPlayerListEntry(client.player.getUuid()).getLatency(); - public static final Supplier SOLAR_TIME = () -> client.world.getTimeOfDay() % 24000; - public static final Supplier LUNAR_TIME = () -> client.world.getTimeOfDay(); - - public static final Supplier PARTICLES = () -> client.particleManager.particles.values().stream().mapToInt(ParticleRenderer::size).sum(); - public static final Supplier STREAMING_SOUNDS = () -> CLIENT.getSoundManager().soundSystem.soundEngine.streamingSources.getSourceCount(); - public static final Supplier MAX_STREAMING_SOUNDS = () -> CLIENT.getSoundManager().soundSystem.soundEngine.streamingSources.getMaxSourceCount(); - public static final Supplier STATIC_SOUNDS = () -> CLIENT.getSoundManager().soundSystem.soundEngine.staticSources.getSourceCount(); - public static final Supplier MAX_STATIC_SOUNDS = () -> CLIENT.getSoundManager().soundSystem.soundEngine.staticSources.getMaxSourceCount(); - - public static final Supplier SLOTS_USED = () -> ComplexData.slots_used; - public static final Supplier SLOTS_EMPTY = () -> ComplexData.slots_empty; - - public static final Supplier FOOD_LEVEL = () -> client.player.getHungerManager().getFoodLevel(); - public static final Supplier SATURATION_LEVEL = () -> client.player.getHungerManager().getSaturationLevel(); - public static final Supplier ARMOR_LEVEL = () -> client.player.getArmor(); - public static final Supplier AIR_LEVEL = () -> Math.round(20F * client.player.getAir() / client.player.getMaxAir()); - public static final Supplier SCORE = () -> client.player.getScore(); - public static final Supplier XP_LEVEL = () -> client.player.experienceLevel; - public static final Supplier XP_POINTS = () -> client.player.experienceProgress * client.player.getNextLevelExperience(); - public static final Supplier XP_POINTS_NEEDED = () -> client.player.getNextLevelExperience(); - public static final Supplier HEALTH = () -> client.player.getHealth() + client.player.getAbsorptionAmount(); - public static final Supplier HEALTH_MAX = () -> client.player.getMaxHealth(); - - public static final Supplier FOOD_LEVEL_PERCENTAGE = () -> client.player.getHungerManager().getFoodLevel() * 5; - public static final Supplier SATURATION_LEVEL_PERCENTAGE = () -> client.player.getHungerManager().getSaturationLevel() * 5; - public static final Supplier ARMOR_LEVEL_PERCENTAGE = () -> client.player.getArmor() * 5; - - public static final Supplier BIOME_BUILDER_EROSION = () -> isNoise() ? biome(sampler().erosion(), par.getErosionParameters()) : Double.NaN; - public static final Supplier BIOME_BUILDER_TEMPERATURE = () -> isNoise() ? biome(sampler().temperature(), par.getTemperatureParameters()) : Double.NaN; - public static final Supplier BIOME_BUILDER_VEGETATION = () -> isNoise() ? biome(sampler().vegetation(), par.getHumidityParameters()) : Double.NaN; - - public static final Supplier HOTBAR_SLOT = () -> client.player.getInventory().getSelectedSlot() + 1; - public static final Supplier HOTBAR_INDEX = () -> client.player.getInventory().getSelectedSlot(); - @Deprecated public static final Supplier ITEM_DURABILITY = () -> client.player.getMainHandStack().getMaxDamage() - client.player.getMainHandStack().getDamage(); - @Deprecated public static final Supplier ITEM_MAX_DURABILITY = () -> client.player.getMainHandStack().getMaxDamage(); - @Deprecated public static final Supplier OFFHAND_ITEM_DURABILITY = () -> client.player.getOffHandStack().getMaxDamage() - client.player.getOffHandStack().getDamage(); - @Deprecated public static final Supplier OFFHAND_ITEM_MAX_DURABILITY = () -> client.player.getOffHandStack().getMaxDamage(); - - public static final Supplier LCPS = () -> ComplexData.clicksPerSeconds[0]; - public static final Supplier RCPS = () -> ComplexData.clicksPerSeconds[1]; - - public static final Supplier TIME_HOUR_12 = () -> { - int hour = ComplexData.timeOfDay / 1000 % 12; - return hour == 0 ? 12 : hour; - }; - - public static final Supplier UNIX_TIME = System::currentTimeMillis; - public static final Supplier REAL_YEAR = () -> LocalDate.now().getYear(); - public static final Supplier REAL_MONTH = () -> LocalDate.now().getMonthValue(); - public static final Supplier REAL_DAY = () -> LocalDate.now().getDayOfMonth(); - public static final Supplier REAL_DAY_OF_WEEK = () -> LocalDate.now().getDayOfWeek().getValue(); - public static final Supplier REAL_DAY_OF_YEAR = () -> LocalDate.now().getDayOfYear(); - - public static final Supplier REAL_HOUR_24 = () -> LocalTime.now().getHour(); - public static final Supplier REAL_HOUR_12 = () -> { - int hour = LocalTime.now().getHour(); - return hour == 0 ? 12 : hour; - }; - public static final Supplier REAL_MINUTE = () -> LocalTime.now().getMinute(); - public static final Supplier REAL_SECOND = () -> LocalTime.now().getSecond(); - public static final Supplier REAL_MICROSECOND = () -> LocalTime.now().get(MICRO_OF_SECOND); - - - public static final Supplier RESOURCE_PACK_VERSION_MAJOR = () -> SharedConstants.getGameVersion().packVersion(ResourceType.CLIENT_RESOURCES).major(); - public static final Supplier RESOURCE_PACK_VERSION_MINOR = () -> SharedConstants.getGameVersion().packVersion(ResourceType.CLIENT_RESOURCES).minor(); - public static final Supplier DATA_PACK_VERSION_MAJOR = () -> SharedConstants.getGameVersion().packVersion(ResourceType.SERVER_DATA).major(); - public static final Supplier DATA_PACK_VERSION_MINOR = () -> SharedConstants.getGameVersion().packVersion(ResourceType.SERVER_DATA).minor(); - - public static final Supplier MAINHAND_SLOT = () -> CLIENT.player.getInventory().getSelectedSlot(); - - public static final Supplier VILLAGER_LEVEL = () -> ComplexData.targetEntity instanceof VillagerEntity ve ? ve.getVillagerData().level() : null; - public static final Supplier VILLAGER_XP = () -> ComplexData.targetEntity instanceof VillagerEntity ve ? ComplexData.villagerXP - VillagerData.getLowerLevelExperience(ve.getVillagerData().level()) : null; - public static final Supplier VILLAGER_XP_NEEDED = () -> ComplexData.targetEntity instanceof VillagerEntity ve ? VillagerData.getUpperLevelExperience(ve.getVillagerData().level()) : null; - + private static final MinecraftClient client = MinecraftClient.getInstance(); + + private static WorldRenderer worldRender() { + return client.worldRenderer; + } + + private static ChunkBuilder chunkBuilder() { + return worldRender().getChunkBuilder(); + } + + private static BlockPos blockPos() { + return client.getCameraEntity().getBlockPos(); + } + + private static LightingProvider serverLighting() { + return ComplexData.world.getChunkManager().getLightingProvider(); + } + + private static Integer chunk(WorldChunk chunk, Heightmap.Type type) { + if (chunk == null) + return null; + BlockPos pos = client.getCameraEntity().getBlockPos(); + return chunk.sampleHeightmap(type, pos.getX(), pos.getZ()); + } + + private static Integer spawnGroup(SpawnGroup group) { + SpawnHelper.Info info = ComplexData.serverWorld.getChunkManager().getSpawnInfo(); + return info == null ? null : info.getGroupToCount().getInt(group); + } + + private static double biome(DensityFunction function, MultiNoiseUtil.ParameterRange[] range) { + double d = (double) MultiNoiseUtil.toLong((float) EntryNumberSuppliers.sample(function)); + for (int i = 0; i < range.length; ++i) + if (d < (double) range[i].max()) + return i; + return Double.NaN; + } + + public static final Supplier PROFILE_ERRORS = () -> ProfileManager.getActive() == null ? 0 + : Errors.getErrors(ProfileManager.getActive().name).size(); + + public static final Supplier FPS = client::getCurrentFps; + public static final Supplier BIOME_BLEND = () -> client.options.getBiomeBlendRadius().getValue(); + public static final Supplier SIMULATION_DISTANCE = () -> client.options.getSimulationDistance() + .getValue(); + + public static final Supplier PACKETS_SENT = () -> (int) client.getNetworkHandler().getConnection() + .getAveragePacketsSent(); + public static final Supplier PACKETS_RECEIVED = () -> (int) client.getNetworkHandler().getConnection() + .getAveragePacketsReceived(); + public static final Supplier CHUNKS_RENDERED = () -> worldRender().getCompletedChunkCount(); + public static final Supplier CHUNKS_LOADED = () -> worldRender().getChunkCount(); + @SuppressWarnings("Convert2MethodRef") + public static final Supplier RENDER_DISTANCE = () -> client.options.getClampedViewDistance(); + public static final Supplier QUEUED_TASKS = () -> chunkBuilder().getScheduledTaskCount(); + public static final Supplier UPLOAD_QUEUE = () -> chunkBuilder().getChunksToUpload(); + public static final Supplier BUFFER_COUNT = () -> chunkBuilder().getFreeBufferCount(); + public static final Supplier ENTITIES_RENDERED = () -> worldRender().worldRenderState.entityRenderStates + .size(); + public static final Supplier ENTITIES_LOADED = () -> client.world.getRegularEntityCount(); + + public static final Supplier FORCED_LOADED_CHUNKS = () -> ComplexData.world instanceof ServerWorld + ? ((ServerWorld) ComplexData.world).getForcedChunks().size() + : null; + + public static final Supplier BLOCK_X = () -> blockPos().getX(); + public static final Supplier BLOCK_Y = () -> blockPos().getY(); + public static final Supplier BLOCK_Z = () -> blockPos().getZ(); + public static final Supplier TARGET_BLOCK_X = () -> targetBlockPos == null ? null + : targetBlockPos.getX(); + public static final Supplier TARGET_BLOCK_Y = () -> targetBlockPos == null ? null + : targetBlockPos.getY(); + public static final Supplier TARGET_BLOCK_Z = () -> targetBlockPos == null ? null + : targetBlockPos.getZ(); + public static final Supplier TARGET_BLOCK_DISTANCE = () -> targetBlockPos == null ? null + : targetBlockPos.getManhattanDistance(client.player.getBlockPos()); + public static final Supplier TARGET_BLOCK_COLOR = () -> targetBlock == null || targetBlock.isAir() + ? null + : targetBlock.getMapColor(client.world, targetBlockPos).color; + public static final Supplier TARGET_BLOCK_LUMINANCE = () -> targetBlock == null || targetBlock.isAir() + ? null + : ComplexData.world.getLuminance(targetBlockPos); + public static final Supplier TARGET_FLUID_X = () -> ComplexData.targetFluidPos == null ? null + : ComplexData.targetFluidPos.getX(); + public static final Supplier TARGET_FLUID_Y = () -> ComplexData.targetFluidPos == null ? null + : ComplexData.targetFluidPos.getY(); + public static final Supplier TARGET_FLUID_Z = () -> ComplexData.targetFluidPos == null ? null + : ComplexData.targetFluidPos.getZ(); + public static final Supplier TARGET_FLUID_DISTANCE = () -> ComplexData.targetFluidPos == null ? null + : ComplexData.targetFluidPos.getManhattanDistance(client.player.getBlockPos()); + public static final Supplier TARGET_FLUID_COLOR = () -> ComplexData.targetFluid == null + || ComplexData.targetFluid.isEmpty() ? null + : ComplexData.targetFluid.getBlockState().getMapColor(client.world, + ComplexData.targetFluidPos).color; + + public static final Supplier TARGET_BLOCK_POWERED = () -> targetBlockPos == null ? null + : client.world.getReceivedRedstonePower(targetBlockPos); + public static final Supplier TARGET_BLOCK_POWERED_NORTH = () -> targetBlockPos == null ? null + : client.world.getEmittedRedstonePower(targetBlockPos.offset(Direction.NORTH), Direction.NORTH); + public static final Supplier TARGET_BLOCK_POWERED_SOUTH = () -> targetBlockPos == null ? null + : client.world.getEmittedRedstonePower(targetBlockPos.offset(Direction.SOUTH), Direction.SOUTH); + public static final Supplier TARGET_BLOCK_POWERED_EAST = () -> targetBlockPos == null ? null + : client.world.getEmittedRedstonePower(targetBlockPos.offset(Direction.EAST), Direction.EAST); + public static final Supplier TARGET_BLOCK_POWERED_WEST = () -> targetBlockPos == null ? null + : client.world.getEmittedRedstonePower(targetBlockPos.offset(Direction.WEST), Direction.WEST); + public static final Supplier TARGET_BLOCK_POWERED_UP = () -> targetBlockPos == null ? null + : client.world.getEmittedRedstonePower(targetBlockPos.offset(Direction.UP), Direction.UP); + public static final Supplier TARGET_BLOCK_POWERED_DOWN = () -> targetBlockPos == null ? null + : client.world.getEmittedRedstonePower(targetBlockPos.offset(Direction.DOWN), Direction.DOWN); + + public static final Supplier TARGET_BLOCK_STRONG_POWERED = () -> targetBlockPos == null ? null + : client.world.getReceivedStrongRedstonePower(targetBlockPos); + public static final Supplier TARGET_BLOCK_STRONG_POWERED_NORTH = () -> targetBlockPos == null ? null + : client.world.getStrongRedstonePower(targetBlockPos.offset(Direction.NORTH), Direction.NORTH); + public static final Supplier TARGET_BLOCK_STRONG_POWERED_SOUTH = () -> targetBlockPos == null ? null + : client.world.getStrongRedstonePower(targetBlockPos.offset(Direction.SOUTH), Direction.SOUTH); + public static final Supplier TARGET_BLOCK_STRONG_POWERED_EAST = () -> targetBlockPos == null ? null + : client.world.getStrongRedstonePower(targetBlockPos.offset(Direction.EAST), Direction.EAST); + public static final Supplier TARGET_BLOCK_STRONG_POWERED_WEST = () -> targetBlockPos == null ? null + : client.world.getStrongRedstonePower(targetBlockPos.offset(Direction.WEST), Direction.WEST); + public static final Supplier TARGET_BLOCK_STRONG_POWERED_UP = () -> targetBlockPos == null ? null + : client.world.getStrongRedstonePower(targetBlockPos.offset(Direction.UP), Direction.UP); + public static final Supplier TARGET_BLOCK_STRONG_POWERED_DOWN = () -> targetBlockPos == null ? null + : client.world.getStrongRedstonePower(targetBlockPos.offset(Direction.DOWN), Direction.DOWN); + + public static final Supplier IN_CHUNK_X = () -> blockPos().getX() & 15; + public static final Supplier IN_CHUNK_Y = () -> blockPos().getY() & 15; + public static final Supplier IN_CHUNK_Z = () -> blockPos().getZ() & 15; + public static final Supplier CHUNK_X = () -> blockPos().getX() >> 4; + public static final Supplier CHUNK_Y = () -> blockPos().getY() >> 4; + public static final Supplier CHUNK_Z = () -> blockPos().getZ() >> 4; + public static final Supplier REGION_X = () -> blockPos().getX() >> 9; + public static final Supplier REGION_Z = () -> blockPos().getZ() >> 9; + public static final Supplier REGION_RELATIVE_X = () -> blockPos().getX() >> 4 & 0x1F; + public static final Supplier REGION_RELATIVE_Z = () -> blockPos().getZ() >> 4 & 0x1F; + + public static final Supplier CHUNK_CLIENT_CACHED = () -> client.world.getChunkManager().chunks.chunks + .length(); + public static final Supplier CHUNK_CLIENT_LOADED = () -> client.world.getChunkManager() + .getLoadedChunkCount(); + public static final Supplier CHUNK_CLIENT_ENTITIES_LOADED = () -> client.world.getRegularEntityCount(); + public static final Supplier CHUNK_CLIENT_ENTITIES_CACHED_SECTIONS = () -> client.world.entityManager.cache + .sectionCount(); + public static final Supplier CHUNK_CLIENT_ENTITIES_TICKING_CHUNKS = () -> client.world.entityManager.tickingChunkSections + .size(); + + public static final Supplier CHUNK_SERVER_LOADED = () -> ComplexData.serverWorld == null ? null + : ComplexData.serverWorld.getChunkManager().getLoadedChunkCount(); + public static final Supplier CHUNK_SERVER_ENTITIES_REGISTERED = () -> ComplexData.serverWorld == null + ? null + : ComplexData.serverWorld.entityManager.entityUuids.size(); + public static final Supplier CHUNK_SERVER_ENTITIES_LOADED = () -> ComplexData.serverWorld == null ? null + : ComplexData.serverWorld.entityManager.index.size(); + public static final Supplier CHUNK_SERVER_ENTITIES_CACHED_SECTIONS = () -> ComplexData.serverWorld == null + ? null + : ComplexData.serverWorld.entityManager.cache.sectionCount(); + public static final Supplier CHUNK_SERVER_ENTITIES_MANAGED = () -> ComplexData.serverWorld == null + ? null + : ComplexData.serverWorld.entityManager.managedStatuses.size(); + public static final Supplier CHUNK_SERVER_ENTITIES_TRACKED = () -> ComplexData.serverWorld == null + ? null + : ComplexData.serverWorld.entityManager.trackingStatuses.size(); + public static final Supplier CHUNK_SERVER_ENTITIES_LOADING = () -> ComplexData.serverWorld == null + ? null + : ComplexData.serverWorld.entityManager.loadingQueue.size(); + public static final Supplier CHUNK_SERVER_ENTITIES_UNLOADING = () -> ComplexData.serverWorld == null + ? null + : ComplexData.serverWorld.entityManager.pendingUnloads.size(); + + public static final Supplier CLIENT_LIGHT = () -> { + if (ComplexData.clientChunk.isEmpty()) + return null; + client.world.calculateAmbientDarkness(); + return Math.max(0, client.world.getChunkManager().getLightingProvider().getLight(blockPos(), + client.world.getAmbientDarkness())); + }; + public static final Supplier CLIENT_LIGHT_SKY = () -> ComplexData.clientChunk.isEmpty() ? null + : client.world.getLightLevel(LightType.SKY, blockPos()); + public static final Supplier CLIENT_LIGHT_SUN = () -> { + if (ComplexData.clientChunk.isEmpty()) + return null; + client.world.calculateAmbientDarkness(); + return Math.max(0, client.world.getLightLevel(LightType.SKY, blockPos()) + - client.world.getAmbientDarkness()); + }; + public static final Supplier CLIENT_LIGHT_BLOCK = () -> ComplexData.clientChunk.isEmpty() ? null + : client.world.getLightLevel(LightType.BLOCK, blockPos()); + @Deprecated + public static final Supplier SERVER_LIGHT_SKY = () -> ComplexData.serverChunk == null ? null + : serverLighting().get(LightType.SKY).getLightLevel(blockPos()); + @Deprecated + public static final Supplier SERVER_LIGHT_BLOCK = () -> ComplexData.serverChunk == null ? null + : serverLighting().get(LightType.BLOCK).getLightLevel(blockPos()); + + public static final Supplier CLIENT_HEIGHT_MAP_SURFACE = () -> chunk(ComplexData.clientChunk, + Heightmap.Type.WORLD_SURFACE); + public static final Supplier CLIENT_HEIGHT_MAP_MOTION_BLOCKING = () -> chunk(ComplexData.clientChunk, + Heightmap.Type.MOTION_BLOCKING); + public static final Supplier SERVER_HEIGHT_MAP_SURFACE = () -> chunk(ComplexData.serverChunk, + Heightmap.Type.WORLD_SURFACE); + public static final Supplier SERVER_HEIGHT_MAP_OCEAN_FLOOR = () -> chunk(ComplexData.serverChunk, + Heightmap.Type.OCEAN_FLOOR); + public static final Supplier SERVER_HEIGHT_MAP_MOTION_BLOCKING = () -> chunk(ComplexData.serverChunk, + Heightmap.Type.MOTION_BLOCKING); + public static final Supplier SERVER_HEIGHT_MAP_MOTION_BLOCKING_NO_LEAVES = () -> chunk( + ComplexData.serverChunk, Heightmap.Type.MOTION_BLOCKING_NO_LEAVES); + + public static final Supplier WORLD_MIN_Y = () -> ComplexData.world.getBottomY(); + public static final Supplier WORLD_MAX_Y = () -> ComplexData.world.getTopYInclusive(); + 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 + : (int) (client.world.getTimeOfDay() / 24000L % 8L) + 1; + + public static final Supplier SPAWN_CHUNKS = () -> { + SpawnHelper.Info info = ComplexData.serverWorld.getChunkManager().getSpawnInfo(); + return info == null ? null : info.getSpawningChunkCount(); + }; + public static final Supplier MONSTERS = () -> spawnGroup(SpawnGroup.MONSTER); + public static final Supplier CREATURES = () -> spawnGroup(SpawnGroup.CREATURE); + public static final Supplier AMBIENT_MOBS = () -> spawnGroup(SpawnGroup.AMBIENT); + public static final Supplier WATER_CREATURES = () -> spawnGroup(SpawnGroup.WATER_CREATURE); + public static final Supplier WATER_AMBIENT_MOBS = () -> spawnGroup(SpawnGroup.WATER_AMBIENT); + public static final Supplier UNDERGROUND_WATER_CREATURE = () -> spawnGroup( + SpawnGroup.UNDERGROUND_WATER_CREATURE); + public static final Supplier AXOLOTLS = () -> spawnGroup(SpawnGroup.AXOLOTLS); + public static final Supplier MISC_MOBS = () -> spawnGroup(SpawnGroup.MISC); + + public static final Supplier JAVA_BIT = () -> 64; + public static final Supplier CPU_CORES = () -> ComplexData.cpu == null ? null + : ((CentralProcessor) ComplexData.cpu).getPhysicalProcessorCount(); + public static final Supplier CPU_THREADS = () -> ComplexData.cpu == null ? null + : ((CentralProcessor) ComplexData.cpu).getLogicalProcessorCount(); + + public static final Supplier DISPLAY_WIDTH = () -> client.getWindow().getFramebufferWidth(); + public static final Supplier DISPLAY_HEIGHT = () -> client.getWindow().getFramebufferHeight(); + public static final Supplier DISPLAY_REFRESH_RATE = () -> GLX._getRefreshRate(client.getWindow()); + public static final Supplier PING = () -> Math.round(ComplexData.pingMetrics[0]); + public static final Supplier LATENCY = () -> client.player.networkHandler + .getPlayerListEntry(client.player.getUuid()).getLatency(); + public static final Supplier SOLAR_TIME = () -> client.world.getTimeOfDay() % 24000; + public static final Supplier LUNAR_TIME = () -> client.world.getTimeOfDay(); + + public static final Supplier PARTICLES = () -> client.particleManager.particles.values().stream() + .mapToInt(ParticleRenderer::size).sum(); + public static final Supplier STREAMING_SOUNDS = () -> CLIENT + .getSoundManager().soundSystem.soundEngine.streamingSources.getSourceCount(); + public static final Supplier MAX_STREAMING_SOUNDS = () -> CLIENT + .getSoundManager().soundSystem.soundEngine.streamingSources.getMaxSourceCount(); + public static final Supplier STATIC_SOUNDS = () -> CLIENT + .getSoundManager().soundSystem.soundEngine.staticSources.getSourceCount(); + public static final Supplier MAX_STATIC_SOUNDS = () -> CLIENT + .getSoundManager().soundSystem.soundEngine.staticSources.getMaxSourceCount(); + + public static final Supplier SLOTS_USED = () -> ComplexData.slots_used; + public static final Supplier SLOTS_EMPTY = () -> ComplexData.slots_empty; + + public static final Supplier FOOD_LEVEL = () -> client.player.getHungerManager().getFoodLevel(); + public static final Supplier SATURATION_LEVEL = () -> client.player.getHungerManager() + .getSaturationLevel(); + public static final Supplier ARMOR_LEVEL = () -> client.player.getArmor(); + public static final Supplier AIR_LEVEL = () -> Math + .round(20F * client.player.getAir() / client.player.getMaxAir()); + public static final Supplier SCORE = () -> client.player.getScore(); + public static final Supplier XP_LEVEL = () -> client.player.experienceLevel; + public static final Supplier XP_POINTS = () -> client.player.experienceProgress + * client.player.getNextLevelExperience(); + public static final Supplier XP_POINTS_NEEDED = () -> client.player.getNextLevelExperience(); + public static final Supplier HEALTH = () -> client.player.getHealth() + + client.player.getAbsorptionAmount(); + public static final Supplier HEALTH_MAX = () -> client.player.getMaxHealth(); + + public static final Supplier FOOD_LEVEL_PERCENTAGE = () -> client.player.getHungerManager() + .getFoodLevel() + * 5; + public static final Supplier SATURATION_LEVEL_PERCENTAGE = () -> client.player.getHungerManager() + .getSaturationLevel() * 5; + public static final Supplier ARMOR_LEVEL_PERCENTAGE = () -> client.player.getArmor() * 5; + + public static final Supplier BIOME_BUILDER_EROSION = () -> isNoise() + ? biome(sampler().erosion(), par.getErosionParameters()) + : Double.NaN; + public static final Supplier BIOME_BUILDER_TEMPERATURE = () -> isNoise() + ? biome(sampler().temperature(), par.getTemperatureParameters()) + : Double.NaN; + public static final Supplier BIOME_BUILDER_VEGETATION = () -> isNoise() + ? biome(sampler().vegetation(), par.getHumidityParameters()) + : Double.NaN; + + public static final Supplier HOTBAR_SLOT = () -> client.player.getInventory().getSelectedSlot() + 1; + public static final Supplier HOTBAR_INDEX = () -> client.player.getInventory().getSelectedSlot(); + @Deprecated + public static final Supplier ITEM_DURABILITY = () -> client.player.getMainHandStack().getMaxDamage() + - client.player.getMainHandStack().getDamage(); + @Deprecated + public static final Supplier ITEM_MAX_DURABILITY = () -> client.player.getMainHandStack() + .getMaxDamage(); + @Deprecated + public static final Supplier OFFHAND_ITEM_DURABILITY = () -> client.player.getOffHandStack() + .getMaxDamage() + - client.player.getOffHandStack().getDamage(); + @Deprecated + public static final Supplier OFFHAND_ITEM_MAX_DURABILITY = () -> client.player.getOffHandStack() + .getMaxDamage(); + + public static final Supplier LCPS = () -> ComplexData.clicksPerSeconds[0]; + public static final Supplier RCPS = () -> ComplexData.clicksPerSeconds[1]; + + public static final Supplier TIME_HOUR_12 = () -> { + int hour = ComplexData.timeOfDay / 1000 % 12; + return hour == 0 ? 12 : hour; + }; + + public static final Supplier UNIX_TIME = System::currentTimeMillis; + public static final Supplier REAL_YEAR = () -> LocalDate.now().getYear(); + public static final Supplier REAL_MONTH = () -> LocalDate.now().getMonthValue(); + public static final Supplier REAL_DAY = () -> LocalDate.now().getDayOfMonth(); + public static final Supplier REAL_DAY_OF_WEEK = () -> LocalDate.now().getDayOfWeek().getValue(); + public static final Supplier REAL_DAY_OF_YEAR = () -> LocalDate.now().getDayOfYear(); + + public static final Supplier REAL_HOUR_24 = () -> LocalTime.now().getHour(); + public static final Supplier REAL_HOUR_12 = () -> { + int hour = LocalTime.now().getHour(); + return hour == 0 ? 12 : hour; + }; + public static final Supplier REAL_MINUTE = () -> LocalTime.now().getMinute(); + public static final Supplier REAL_SECOND = () -> LocalTime.now().getSecond(); + public static final Supplier REAL_MICROSECOND = () -> LocalTime.now().get(MICRO_OF_SECOND); + + public static final Supplier RESOURCE_PACK_VERSION_MAJOR = () -> SharedConstants.getGameVersion() + .packVersion(ResourceType.CLIENT_RESOURCES).major(); + public static final Supplier RESOURCE_PACK_VERSION_MINOR = () -> SharedConstants.getGameVersion() + .packVersion(ResourceType.CLIENT_RESOURCES).minor(); + public static final Supplier DATA_PACK_VERSION_MAJOR = () -> SharedConstants.getGameVersion() + .packVersion(ResourceType.SERVER_DATA).major(); + public static final Supplier DATA_PACK_VERSION_MINOR = () -> SharedConstants.getGameVersion() + .packVersion(ResourceType.SERVER_DATA).minor(); + + public static final Supplier MAINHAND_SLOT = () -> CLIENT.player.getInventory().getSelectedSlot(); + + public static final Supplier VILLAGER_LEVEL = () -> ComplexData.targetEntity instanceof VillagerEntity ve + ? ve.getVillagerData().level() + : null; + public static final Supplier VILLAGER_XP = () -> ComplexData.targetEntity instanceof VillagerEntity ve + ? ComplexData.villagerXP - VillagerData.getLowerLevelExperience(ve.getVillagerData().level()) + : null; + public static final Supplier VILLAGER_XP_NEEDED = () -> ComplexData.targetEntity instanceof VillagerEntity ve + ? VillagerData.getUpperLevelExperience(ve.getVillagerData().level()) + : null; } 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 768ed32a..68a9c49a 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; @@ -22,99 +25,158 @@ public class SpecialSupplierElement implements HudElement { private static final MinecraftClient client = MinecraftClient.getInstance(); + private static boolean isFacingEastOrSouth() { Direction dir = client.getCameraEntity().getHorizontalFacing(); return dir == Direction.EAST || dir == Direction.SOUTH; } - public static final Entry DIFFICULTY = of( () -> client.world.getDifficulty().getName(), - () -> client.world.getDifficulty().getId(), - () -> client.world.getDifficulty().getId() != 0); - - public static final Entry MAX_FPS = of( () -> client.options.getMaxFps().getValue() == GameOptions.MAX_FPS_LIMIT ? null : client.options.getMaxFps().getValue().toString(), - () -> client.options.getMaxFps().getValue(), - () -> client.options.getMaxFps().getValue() == GameOptions.MAX_FPS_LIMIT); - - public static final Entry PROFILE_KEYBIND = of( () -> getActive() == null ? "" : getActive().keyBinding.getBoundKeyLocalizedText().getString(), - () -> getActive() == null ? 0 : getActive().keyBinding.boundKey.getCode(), - () -> getActive() != null && !getActive().keyBinding.isUnbound()); - - public static final Entry TIME_HOUR_24 = of( () -> String.format("%02d", ComplexData.timeOfDay / 1000), - () -> ComplexData.timeOfDay / 1000, - () -> ComplexData.timeOfDay / 1000 >= 12); - - public static final Entry TIME_MINUTES = of( () -> String.format("%02d",(int)((ComplexData.timeOfDay % 1000) / (1000/60F))), - () -> (int)((ComplexData.timeOfDay % 1000) / (1000/60F)), - () -> (int)((ComplexData.timeOfDay % 1000) / (1000/60F)) != 0); - - public static final Entry TIME_SECONDS = of( () -> String.format("%02d",(int)((ComplexData.timeOfDay % 1000) % (1000/60F) * 3.6F)), - () -> (int)((ComplexData.timeOfDay % 1000) % (1000/60F) * 3.6F), - () -> (int)((ComplexData.timeOfDay % 1000) % (1000/60F) * 3.6F) != 0); - - public static final Entry TARGET_BLOCK = of( () -> I18n.translate(ComplexData.targetBlock.getBlock().getTranslationKey()), - () -> Block.getRawIdFromState(ComplexData.targetBlock), - () -> !ComplexData.targetBlock.isAir()); - - public static final Entry TARGET_FLUID = of( () -> WordUtils.capitalize(Registries.FLUID.getId(ComplexData.targetFluid.getFluid()).getPath().replace('_',' ')), - () -> Fluid.STATE_IDS.getRawId(ComplexData.targetFluid), - () -> !ComplexData.targetFluid.isEmpty()); - - public static final Entry ITEM_OLD = of( () -> I18n.translate(client.player.getMainHandStack().getItem().getTranslationKey()), - () -> Item.getRawId(client.player.getMainHandStack().getItem()), - () -> !client.player.getMainHandStack().isEmpty()); + public static final Entry DIFFICULTY = of(() -> client.world.getDifficulty().getName(), + () -> client.world.getDifficulty().getId(), + () -> client.world.getDifficulty().getId() != 0); + + public static final Entry MAX_FPS = of( + () -> client.options.getMaxFps().getValue() == GameOptions.MAX_FPS_LIMIT ? null + : client.options.getMaxFps().getValue().toString(), + () -> client.options.getMaxFps().getValue(), + () -> client.options.getMaxFps().getValue() == GameOptions.MAX_FPS_LIMIT); + + public static final Entry PROFILE_KEYBIND = of( + () -> getActive() == null ? "" : getActive().keyBinding.getBoundKeyLocalizedText().getString(), + () -> getActive() == null ? 0 : getActive().keyBinding.boundKey.getCode(), + () -> getActive() != null && !getActive().keyBinding.isUnbound()); + + public static final Entry TIME_HOUR_24 = of(() -> String.format("%02d", ComplexData.timeOfDay / 1000), + () -> ComplexData.timeOfDay / 1000, + () -> ComplexData.timeOfDay / 1000 >= 12); + + public static final Entry TIME_MINUTES = of( + () -> String.format("%02d", (int) ((ComplexData.timeOfDay % 1000) / (1000 / 60F))), + () -> (int) ((ComplexData.timeOfDay % 1000) / (1000 / 60F)), + () -> (int) ((ComplexData.timeOfDay % 1000) / (1000 / 60F)) != 0); + + public static final Entry TIME_SECONDS = of( + () -> String.format("%02d", (int) ((ComplexData.timeOfDay % 1000) % (1000 / 60F) * 3.6F)), + () -> (int) ((ComplexData.timeOfDay % 1000) % (1000 / 60F) * 3.6F), + () -> (int) ((ComplexData.timeOfDay % 1000) % (1000 / 60F) * 3.6F) != 0); + + public static final Entry TARGET_BLOCK = of( + () -> I18n.translate(ComplexData.targetBlock.getBlock().getTranslationKey()), + () -> Block.getRawIdFromState(ComplexData.targetBlock), + () -> !ComplexData.targetBlock.isAir()); + + public static final Entry TARGET_FLUID = of( + () -> WordUtils + .capitalize(Registries.FLUID.getId(ComplexData.targetFluid.getFluid()).getPath().replace('_', ' ')), + () -> Fluid.STATE_IDS.getRawId(ComplexData.targetFluid), + () -> !ComplexData.targetFluid.isEmpty()); + + public static final Entry ITEM_OLD = of( + () -> I18n.translate(client.player.getMainHandStack().getItem().getTranslationKey()), + () -> Item.getRawId(client.player.getMainHandStack().getItem()), + () -> !client.player.getMainHandStack().isEmpty()); - public static final Entry ITEM_NAME = of( () -> client.player.getMainHandStack().getName().getString(), + public static final Entry ITEM_NAME = of(() -> client.player.getMainHandStack().getName().getString(), () -> client.player.getMainHandStack().getName().getString().length(), () -> !client.player.getMainHandStack().isEmpty()); @Deprecated - public static final Entry OFFHAND_ITEM = of( () -> I18n.translate(client.player.getOffHandStack().getItem().getTranslationKey()), - () -> Item.getRawId(client.player.getOffHandStack().getItem()), - () -> !client.player.getOffHandStack().isEmpty()); + public static final Entry OFFHAND_ITEM = of( + () -> I18n.translate(client.player.getOffHandStack().getItem().getTranslationKey()), + () -> Item.getRawId(client.player.getOffHandStack().getItem()), + () -> !client.player.getOffHandStack().isEmpty()); @Deprecated - public static final Entry OFFHAND_ITEM_NAME = of( () -> client.player.getOffHandStack().getName().getString(), - () -> 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 OFFHAND_ITEM_NAME = of(() -> client.player.getOffHandStack().getName().getString(), + () -> client.player.getOffHandStack().getName().getString().length(), + () -> !client.player.getOffHandStack().isEmpty()); + + 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(), - () -> true); + public static final Entry GAMEMODE = of(() -> client.interactionManager.getCurrentGameMode().getId(), + () -> client.interactionManager.getCurrentGameMode().getIndex(), + () -> true); - public static final Entry FACING_TOWARDS_PN_WORD = of( () -> isFacingEastOrSouth() ? "positive" : "negative", + public static final Entry FACING_TOWARDS_PN_WORD = of(() -> isFacingEastOrSouth() ? "positive" : "negative", () -> isFacingEastOrSouth() ? 1 : 0, SpecialSupplierElement::isFacingEastOrSouth); - public static final Entry FACING_TOWARDS_PN_SIGN = of( () -> isFacingEastOrSouth() ? "+" : "-", + public static final Entry FACING_TOWARDS_PN_SIGN = of(() -> isFacingEastOrSouth() ? "+" : "-", () -> isFacingEastOrSouth() ? 1 : 0, SpecialSupplierElement::isFacingEastOrSouth); - public static final Entry ACTIVE_RENDERER = of( () -> {var r = renderer(); return r != null ? r.getClass().getSimpleName() : "none (vanilla)";}, - () -> {var r = renderer(); return r != null ? r.getClass().getSimpleName().length() : 7;}, - () -> renderer() != null); - - public static Renderer renderer() { try {return Renderer.get();} catch (Exception e) { return null;}} + public static final Entry ACTIVE_RENDERER = of(() -> { + var r = renderer(); + return r != null ? r.getClass().getSimpleName() : "none (vanilla)"; + }, + () -> { + var r = renderer(); + return r != null ? r.getClass().getSimpleName().length() : 7; + }, + () -> renderer() != null); + + public static Renderer renderer() { + try { + return Renderer.get(); + } catch (Exception e) { + return null; + } + } - public static final Entry CAMERA_PERSPECTIVE = of ( + public static final Entry CAMERA_PERSPECTIVE = of( () -> switch (client.options.getPerspective()) { case FIRST_PERSON -> "First Person"; case THIRD_PERSON_BACK -> "Third Person (Back)"; case THIRD_PERSON_FRONT -> "Third Person (Front)"; }, () -> client.options.getPerspective().ordinal(), - () -> client.options.getPerspective().ordinal() != 0 - ); + () -> client.options.getPerspective().ordinal() != 0); + public record Entry(Supplier stringSupplier, Supplier numberSupplier, + Supplier booleanSupplier) { + } - public record Entry(Supplier stringSupplier, Supplier numberSupplier, Supplier booleanSupplier) {} - public static Entry of(Supplier stringSupplier, Supplier numberSupplier, Supplier booleanSupplier) { + public static Entry of(Supplier stringSupplier, Supplier numberSupplier, + Supplier booleanSupplier) { return new Entry(stringSupplier, numberSupplier, booleanSupplier); } 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 2b82a6d0..2543d3f4 100644 --- a/src/main/java/com/minenash/customhud/HudElements/supplier/StringSupplierElement.java +++ b/src/main/java/com/minenash/customhud/HudElements/supplier/StringSupplierElement.java @@ -27,76 +27,120 @@ public class StringSupplierElement implements HudElement { private static final MinecraftClient client = MinecraftClient.getInstance(); - private static Entity cameraEntity() { return client.getCameraEntity(); } - private static BlockPos blockPos() { return client.getCameraEntity().getBlockPos(); } - public static final Supplier PROFILE_NAME = () -> ProfileManager.getActive() == null ? null : ProfileManager.getActive().name; + private static Entity cameraEntity() { + return client.getCameraEntity(); + } + + private static BlockPos blockPos() { + return client.getCameraEntity().getBlockPos(); + } + + public static final Supplier PROFILE_NAME = () -> ProfileManager.getActive() == null ? null + : ProfileManager.getActive().name; public static final Supplier VERSION = () -> SharedConstants.getGameVersion().name(); public static final Supplier CLIENT_VERSION = client::getGameVersion; public static final Supplier MODDED_NAME = ClientBrandRetriever::getClientModName; - public static final Supplier USERNAME = () -> client.player.getGameProfile().name() == null ? null : client.player.getGameProfile().name(); + public static final Supplier USERNAME = () -> client.player.getGameProfile().name() == null ? null + : client.player.getGameProfile().name(); public static final Supplier UUID = () -> client.player.getGameProfile().id().toString(); public static final Supplier SERVER_BRAND = () -> client.player.networkHandler.getBrand(); public static final Supplier SERVER_NAME = () -> client.getCurrentServerEntry().name; public static final Supplier SERVER_ADDRESS = () -> client.getCurrentServerEntry().address; - public static final Supplier WORLD_NAME = () -> !client.isIntegratedServerRunning() ? null : client.getServer().getSaveProperties().getLevelName(); + public static final Supplier WORLD_NAME = () -> !client.isIntegratedServerRunning() ? null + : client.getServer().getSaveProperties().getLevelName(); - public static final Supplier DIMENSION = () -> WordUtils.capitalize(client.world.getRegistryKey().getValue().getPath().replace("_"," ")); - public static final Supplier BIOME = () -> I18n.translate("biome." + client.world.getBiome(blockPos()).getKey().get().getValue().toString().replace(':', '.')); + public static final Supplier DIMENSION = () -> WordUtils + .capitalize(client.world.getRegistryKey().getValue().getPath().replace("_", " ")); + 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()]; + 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[(int) (client.world.getTimeOfDay() / 24000L % 8L)]; public static final Supplier TIME_AM_PM = () -> ComplexData.timeOfDay < 12000 ? "am" : "pm"; public static final Supplier FACING4 = () -> cameraEntity().getHorizontalFacing().getId(); - public static final Supplier FACING4_SHORT = () -> cameraEntity().getHorizontalFacing().getId().substring(0, 1).toUpperCase(); - public static final Supplier FACING_TOWARDS_XZ = () -> - cameraEntity().getHorizontalFacing() == Direction.EAST || cameraEntity().getHorizontalFacing() == Direction.WEST ? "X" : "Z"; + public static final Supplier FACING4_SHORT = () -> cameraEntity().getHorizontalFacing().getId() + .substring(0, 1).toUpperCase(); + public static final Supplier FACING_TOWARDS_XZ = () -> cameraEntity() + .getHorizontalFacing() == Direction.EAST || cameraEntity().getHorizontalFacing() == Direction.WEST ? "X" + : "Z"; public static final Supplier FACING8 = () -> { float yaw = MathHelper.wrapDegrees(cameraEntity().getYaw()); - if (yaw > 157.5 || yaw < -157.5) return "north"; - if (yaw > 112.5) return "northwest"; - if (yaw > 67.5) return "west"; - if (yaw > 22.5) return "southwest"; - if (yaw < -112.5) return "northeast"; - if (yaw < -67.5) return "east"; - if (yaw < -22.5) return "southeast"; + if (yaw > 157.5 || yaw < -157.5) + return "north"; + if (yaw > 112.5) + return "northwest"; + if (yaw > 67.5) + return "west"; + if (yaw > 22.5) + return "southwest"; + if (yaw < -112.5) + return "northeast"; + if (yaw < -67.5) + return "east"; + if (yaw < -22.5) + return "southeast"; return "south"; }; public static final Supplier FACING8_SHORT = () -> { float yaw = MathHelper.wrapDegrees(cameraEntity().getYaw()); - if (yaw > 157.5 || yaw < -157.5) return "N"; - if (yaw > 112.5) return "NW"; - if (yaw > 67.5) return "W"; - if (yaw > 22.5) return "SW"; - if (yaw < -112.5) return "NE"; - if (yaw < -67.5) return "E"; - if (yaw < -22.5) return "SE"; + if (yaw > 157.5 || yaw < -157.5) + return "N"; + if (yaw > 112.5) + return "NW"; + if (yaw > 67.5) + return "W"; + if (yaw > 22.5) + return "SW"; + if (yaw < -112.5) + return "NE"; + if (yaw < -67.5) + return "E"; + if (yaw < -22.5) + return "SE"; return "S"; }; public static final Supplier JAVA_VERSION = () -> System.getProperty("java.version"); - public static final Supplier CPU_NAME = () -> ComplexData.cpu == null ? null : ((CentralProcessor)ComplexData.cpu).getProcessorIdentifier().getName().trim(); + public static final Supplier CPU_NAME = () -> ComplexData.cpu == null ? null + : ((CentralProcessor) ComplexData.cpu).getProcessorIdentifier().getName().trim(); public static final Supplier GPU_NAME = () -> RenderSystem.getDevice().getRenderer(); public static final Supplier GPU_VENDOR = () -> RenderSystem.getDevice().getVendor(); - public static final Supplier GL_VERSION = () -> RenderSystem.getDevice().getVersion().substring(0, RenderSystem.getDevice().getVersion().indexOf(' ')); - public static final Supplier GPU_DRIVER = () -> RenderSystem.getDevice().getVersion().substring(RenderSystem.getDevice().getVersion().indexOf(' ') + 1); - - public static final Supplier MUSIC_NAME = () -> MusicAndRecordTracker.isMusicPlaying ? MusicAndRecordTracker.musicName : null; - - public static final Supplier BIOME_BUILDER_PEAKS = () -> isNoise() ? VanillaBiomeParameters.getPeaksValleysDescription(DensityFunctions.getPeaksValleysNoise((float)sample(sampler().ridges()))) : null; - public static final Supplier BIOME_BUILDER_CONTINENTS = () -> isNoise() ? par.getContinentalnessDescription(sample(sampler().continents())) : null; - - public static final Supplier VILLAGER_BIOME = () -> ComplexData.targetEntity instanceof VillagerEntity ve ? WordUtils.capitalize(ve.getVillagerData().type().toString()) : null; - public static final Supplier VILLAGER_LEVEL_WORD = () -> ComplexData.targetEntity instanceof VillagerEntity ve ? I18n.translate("merchant.level." + ve.getVillagerData().level()) : null; - - - public static final Supplier RESOURCE_PACK_VERSION = () -> SharedConstants.getGameVersion().packVersion(ResourceType.CLIENT_RESOURCES).toString(); - public static final Supplier DATA_PACK_VERSION = () -> SharedConstants.getGameVersion().packVersion(ResourceType.SERVER_DATA).toString(); + public static final Supplier GL_VERSION = () -> RenderSystem.getDevice().getVersion().substring(0, + RenderSystem.getDevice().getVersion().indexOf(' ')); + public static final Supplier GPU_DRIVER = () -> RenderSystem.getDevice().getVersion() + .substring(RenderSystem.getDevice().getVersion().indexOf(' ') + 1); + + public static final Supplier MUSIC_NAME = () -> MusicAndRecordTracker.isMusicPlaying + ? MusicAndRecordTracker.musicName + : null; + + public static final Supplier BIOME_BUILDER_PEAKS = () -> isNoise() + ? VanillaBiomeParameters.getPeaksValleysDescription( + DensityFunctions.getPeaksValleysNoise((float) sample(sampler().ridges()))) + : null; + public static final Supplier BIOME_BUILDER_CONTINENTS = () -> isNoise() + ? par.getContinentalnessDescription(sample(sampler().continents())) + : null; + + public static final Supplier VILLAGER_BIOME = () -> ComplexData.targetEntity instanceof VillagerEntity ve + ? WordUtils.capitalize(ve.getVillagerData().type().toString()) + : null; + public static final Supplier VILLAGER_LEVEL_WORD = () -> ComplexData.targetEntity instanceof VillagerEntity ve + ? I18n.translate("merchant.level." + ve.getVillagerData().level()) + : null; + + public static final Supplier RESOURCE_PACK_VERSION = () -> SharedConstants.getGameVersion() + .packVersion(ResourceType.CLIENT_RESOURCES).toString(); + public static final Supplier DATA_PACK_VERSION = () -> SharedConstants.getGameVersion() + .packVersion(ResourceType.SERVER_DATA).toString(); private final Supplier supplier; @@ -113,8 +157,7 @@ public String getString() { public Number getNumber() { try { return supplier.get().length(); - } - catch (Exception e) { + } catch (Exception e) { return 0; } } diff --git a/src/main/java/com/minenash/customhud/complex/ComplexData.java b/src/main/java/com/minenash/customhud/complex/ComplexData.java index e45e550c..c1272d10 100644 --- a/src/main/java/com/minenash/customhud/complex/ComplexData.java +++ b/src/main/java/com/minenash/customhud/complex/ComplexData.java @@ -69,7 +69,7 @@ public class ComplexData { private static final MinecraftClient client = MinecraftClient.getInstance(); private static final BlockState AIR_BLOCK_STATE = Blocks.AIR.getDefaultState(); - //Chunk Data. + // Chunk Data. private static ChunkPos pos = null; private static CompletableFuture chunkFuture; @@ -78,8 +78,8 @@ public class ComplexData { public static double cpuLoad = 0; public static double gpuUsage = 0; - public static int[] clicksSoFar = new int[]{0,0}; - public static int[] clicksPerSeconds = new int[]{0,0}; + public static int[] clicksSoFar = new int[] { 0, 0 }; + public static int[] clicksPerSeconds = new int[] { 0, 0 }; public static ArrayDeque[] clicks = null; public static double[] frameTimeMetrics = new double[4]; @@ -102,9 +102,13 @@ public class ComplexData { public static long villagerLastRequested = Long.MAX_VALUE; public static boolean refreshTimings = false; - public record ProfilerTimingWithPath(String path, String name, double parent, double total, int color, List entries) {} + + public record ProfilerTimingWithPath(String path, String name, double parent, double total, int color, + List entries) { + } + public static List rootEntries = Collections.EMPTY_LIST; - public static Map allEntries = Collections.EMPTY_MAP; + public static Map allEntries = Collections.EMPTY_MAP; @SuppressWarnings("ConstantConditions") public static void update(Profile profile) { @@ -120,7 +124,7 @@ public static void update(Profile profile) { if (profile.enabled.clientChunk) { Profilers.get().push("clientChunk"); ChunkPos newPos = new ChunkPos(client.getCameraEntity().getBlockPos()); - if (!Objects.equals(ComplexData.pos,newPos)) { + if (!Objects.equals(ComplexData.pos, newPos)) { pos = newPos; chunkFuture = null; clientChunk = null; @@ -134,7 +138,9 @@ public static void update(Profile profile) { Profilers.get().push("serverChunk"); if (chunkFuture == null) { if (serverWorld != null) - chunkFuture = serverWorld.getChunkManager().getChunkFutureSyncOnMainThread(pos.x, pos.z, ChunkStatus.FULL, false).thenApply((either) -> (WorldChunk) either.orElse(null)); + chunkFuture = serverWorld.getChunkManager() + .getChunkFutureSyncOnMainThread(pos.x, pos.z, ChunkStatus.FULL, false) + .thenApply((either) -> (WorldChunk) either.orElse(null)); if (chunkFuture == null) chunkFuture = CompletableFuture.completedFuture(clientChunk); @@ -145,19 +151,22 @@ public static void update(Profile profile) { if (profile.enabled.world) { Profilers.get().push("world"); - world = DataFixUtils.orElse(Optional.ofNullable(client.getServer()).flatMap((integratedServer) -> Optional.ofNullable(integratedServer.getWorld(client.world.getRegistryKey()))), client.world); + world = DataFixUtils.orElse( + Optional.ofNullable(client.getServer()) + .flatMap((integratedServer) -> Optional + .ofNullable(integratedServer.getWorld(client.world.getRegistryKey()))), + client.world); Profilers.get().pop(); } if (profile.enabled.targetBlock) { Profilers.get().push("targetBlock"); - HitResult hit = client.getCameraEntity().raycast(profile.targetDistance, 0.0F, false); + HitResult hit = client.getCameraEntity().raycast(profile.targetDistance, 0.0F, false); if (hit.getType() == HitResult.Type.BLOCK) { - targetBlockPos = ((BlockHitResult)hit).getBlockPos(); + targetBlockPos = ((BlockHitResult) hit).getBlockPos(); targetBlock = world.getBlockState(targetBlockPos); - } - else { + } else { targetBlockPos = null; targetBlock = AIR_BLOCK_STATE; } @@ -166,13 +175,12 @@ public static void update(Profile profile) { if (profile.enabled.targetFluid) { Profilers.get().push("targetFluid"); - HitResult hit = client.getCameraEntity().raycast(profile.targetDistance, 0.0F, true); + HitResult hit = client.getCameraEntity().raycast(profile.targetDistance, 0.0F, true); if (hit.getType() == HitResult.Type.BLOCK) { - targetFluidPos = ((BlockHitResult)hit).getBlockPos(); + targetFluidPos = ((BlockHitResult) hit).getBlockPos(); targetFluid = world.getFluidState(targetFluidPos); - } - else { + } else { targetFluidPos = null; targetFluid = Fluids.EMPTY.getDefaultState(); } @@ -190,9 +198,10 @@ public static void update(Profile profile) { Box box = client.getCameraEntity().getBoundingBox().stretch(rot.multiply(dist)).expand(1.0, 1.0, 1.0); HitResult block = client.getCameraEntity().raycast(dist, 0, false); - double dist2 = block == null ? dist*dist : block.getPos().squaredDistanceTo(min); + double dist2 = block == null ? dist * dist : block.getPos().squaredDistanceTo(min); - EntityHitResult result = ProjectileUtil.raycast(client.getCameraEntity(), min, max, box, (en) -> !en.isSpectator(), dist2); + EntityHitResult result = ProjectileUtil.raycast(client.getCameraEntity(), min, max, box, + (en) -> !en.isSpectator(), dist2); targetEntity = result == null ? null : result.getEntity(); targetEntityHitPos = result == null ? null : result.getPos(); Profilers.get().pop(); @@ -200,7 +209,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(); } @@ -231,7 +241,7 @@ public static void update(Profile profile) { if (profile.enabled.cpuUsage) { Profilers.get().push("cpu"); var c = (CentralProcessor) cpu; - double load = c.getSystemCpuLoadBetweenTicks( prevTicks ) * 100; + double load = c.getSystemCpuLoadBetweenTicks(prevTicks) * 100; if (load > 0) cpuLoad = load; prevTicks = c.getSystemCpuLoadTicks(); @@ -241,17 +251,17 @@ public static void update(Profile profile) { if (profile.enabled.updateStats) { Profilers.get().push("updateStats"); if (System.currentTimeMillis() - lastStatUpdate >= 500) { - client.getNetworkHandler().sendPacket(new ClientStatusC2SPacket(ClientStatusC2SPacket.Mode.REQUEST_STATS)); + client.getNetworkHandler() + .sendPacket(new ClientStatusC2SPacket(ClientStatusC2SPacket.Mode.REQUEST_STATS)); lastStatUpdate = System.currentTimeMillis(); } Profilers.get().pop(); } - if (profile.enabled.clicksPerSeconds) { Profilers.get().push("clicksPerSeconds"); if (clicks == null) { - clicks = new ArrayDeque[]{new ArrayDeque(20), new ArrayDeque(20)}; + clicks = new ArrayDeque[] { new ArrayDeque(20), new ArrayDeque(20) }; for (int i = 0; i < 20; i++) { clicks[0].add(0); clicks[1].add(0); @@ -271,12 +281,14 @@ public static void update(Profile profile) { if (profile.enabled.frameMetrics) { Profilers.get().push("frameMetrics"); - processLog(((DebugHudAccessor)client.inGameHud.getDebugHud()).getFrameNanosLog(), 0.000001, 240, frameTimeMetrics); + processLog(((DebugHudAccessor) client.inGameHud.getDebugHud()).getFrameNanosLog(), 0.000001, 240, + frameTimeMetrics); Profilers.get().pop(); } if (profile.enabled.tickMetrics) { Profilers.get().push("tickMetrics"); - processLog(((DebugHudAccessor)client.inGameHud.getDebugHud()).getTickNanosLog(), 0.000001, 120, tickTimeMetrics); + processLog(((DebugHudAccessor) client.inGameHud.getDebugHud()).getTickNanosLog(), 0.000001, 120, + tickTimeMetrics); Profilers.get().pop(); } if (profile.enabled.pingMetrics) { @@ -286,12 +298,12 @@ public static void update(Profile profile) { } if (profile.enabled.packetMetrics) { Profilers.get().push("packetMetrics"); - processLog(client.inGameHud.getDebugHud().getPacketSizeLog(), 20/1024D, 120, packetSizeMetrics); + processLog(client.inGameHud.getDebugHud().getPacketSizeLog(), 20 / 1024D, 120, packetSizeMetrics); Profilers.get().pop(); } if (profile.enabled.tpsMetrics) { Profilers.get().push("tpsMetrics"); - processTPSLog(((DebugHudAccessor)client.inGameHud.getDebugHud()).getTickNanosLog(), tpsMetrics); + processTPSLog(((DebugHudAccessor) client.inGameHud.getDebugHud()).getTickNanosLog(), tpsMetrics); Profilers.get().pop(); } @@ -316,16 +328,17 @@ public static void update(Profile profile) { if (profile.enabled.targetVillager) { Profilers.get().push("targetVillager"); - if ( !(targetEntity instanceof VillagerEntity) && villagerUUID != null) { + if (!(targetEntity instanceof VillagerEntity) && villagerUUID != null) { villagerOffers.clear(); villagerUUID = null; villagerLastRequested = Long.MAX_VALUE; - } - else if (targetEntity instanceof VillagerEntity && (villagerUUID == null || - !targetEntity.getUuid().equals(villagerUUID) || System.currentTimeMillis() - villagerLastRequested > 30_000)) { + } else if (targetEntity instanceof VillagerEntity && (villagerUUID == null || + !targetEntity.getUuid().equals(villagerUUID) + || System.currentTimeMillis() - villagerLastRequested > 30_000)) { villagerUUID = targetEntity.getUuid(); fakeVillagerInteract = 2; - CLIENT.getNetworkHandler().sendPacket(PlayerInteractEntityC2SPacket.interact(targetEntity, false, Hand.OFF_HAND)); + CLIENT.getNetworkHandler() + .sendPacket(PlayerInteractEntityC2SPacket.interact(targetEntity, false, Hand.OFF_HAND)); villagerLastRequested = System.currentTimeMillis(); } Profilers.get().pop(); @@ -337,14 +350,13 @@ else if (targetEntity instanceof VillagerEntity && (villagerUUID == null || if (profileResult == null) { rootEntries = Collections.EMPTY_LIST; allEntries = Collections.EMPTY_MAP; - } - else { + } else { rootEntries = new ArrayList<>(); allEntries = new HashMap<>(); List timings = profileResult.getTimings("root"); timings.remove(0); for (var entry : timings) - rootEntries.add( getEntries(profileResult, entry, "root\u001e" + entry.name) ); + rootEntries.add(getEntries(profileResult, entry, "root\u001e" + entry.name)); } Profilers.get().pop(); } @@ -363,7 +375,8 @@ public static ProfilerTimingWithPath getEntries(ProfileResult profileResult, Pro for (var entry : timings) entries.add(getEntries(profileResult, entry, path + "\u001e" + entry.name)); - ProfilerTimingWithPath entry = new ProfilerTimingWithPath(path, timing.name, timing.parentSectionUsagePercentage, timing.totalUsagePercentage, timing.getColor(), entries); + ProfilerTimingWithPath entry = new ProfilerTimingWithPath(path, timing.name, + timing.parentSectionUsagePercentage, timing.totalUsagePercentage, timing.getColor(), entries); allEntries.put(path, entry); return entry; } @@ -374,13 +387,13 @@ public static void processLog(MultiValueDebugSampleLogImpl log, double multiplie return; } - metrics[0] = 0; //AVG - metrics[1] = Integer.MAX_VALUE; //MIN - metrics[2] = Integer.MIN_VALUE; //MAX - metrics[3] = Math.min(samples, log.getLength()-1); //SAMPLES + metrics[0] = 0; // AVG + metrics[1] = Integer.MAX_VALUE; // MIN + metrics[2] = Integer.MIN_VALUE; // MAX + metrics[3] = Math.min(samples, log.getLength() - 1); // SAMPLES double avg = 0L; - for (int r = 0; r < metrics[3]; ++r) { + for (int r = 0; r < metrics[3]; ++r) { double s = log.get(r) * multiplier; metrics[1] = Math.min(metrics[1], s); metrics[2] = Math.max(metrics[2], s); @@ -395,13 +408,13 @@ public static void processTPSLog(MultiValueDebugSampleLogImpl log, double[] metr return; } - metrics[0] = 0; //AVG - metrics[1] = Integer.MAX_VALUE; //MIN - metrics[2] = Integer.MIN_VALUE; //MAX - metrics[3] = Math.min(120, log.getLength()-1); //SAMPLES + metrics[0] = 0; // AVG + metrics[1] = Integer.MAX_VALUE; // MIN + metrics[2] = Integer.MIN_VALUE; // MAX + metrics[3] = Math.min(120, log.getLength() - 1); // SAMPLES double avg = 0L; - for (int r = 0; r < metrics[3]; ++r) { + for (int r = 0; r < metrics[3]; ++r) { double s = Math.min(20, 1000F / (log.get(r) * 0.000001)); metrics[1] = Math.min(metrics[1], s); metrics[2] = Math.max(metrics[2], s); @@ -431,7 +444,7 @@ public static void reset() { public static class Enabled { public static final Enabled DISABLED = new Enabled(); - public final Map custom = new HashMap<>(); + public final Map custom = new HashMap<>(); public final List velocityTrackers = new ArrayList<>(); @@ -466,27 +479,29 @@ public static class Enabled { public void merge(Enabled enabled) { for (Field field : this.getClass().getFields()) { - if (field.getType() != Boolean.TYPE) continue; - try { field.setBoolean(this, field.getBoolean(this) || field.getBoolean(enabled)); } - catch (Exception ignored) {} + if (field.getType() != Boolean.TYPE) + continue; + try { + field.setBoolean(this, field.getBoolean(this) || field.getBoolean(enabled)); + } catch (Exception ignored) { + } } this.custom.putAll(enabled.custom); - this.velocityTrackers.addAll(enabled.velocityTrackers); } public boolean get(String name) { return custom.getOrDefault(name, false); } + public void set(String name) { custom.put(name, true); } + public void set(String name, boolean value) { custom.put(name, value); } } - - } diff --git a/src/main/java/com/minenash/customhud/mixin/PlayerEntityMixin.java b/src/main/java/com/minenash/customhud/mixin/PlayerEntityMixin.java index 059a8040..0ee1fc6e 100644 --- a/src/main/java/com/minenash/customhud/mixin/PlayerEntityMixin.java +++ b/src/main/java/com/minenash/customhud/mixin/PlayerEntityMixin.java @@ -1,6 +1,5 @@ package com.minenash.customhud.mixin; - import com.minenash.customhud.complex.ComplexData; import net.minecraft.client.MinecraftClient; import net.minecraft.entity.Entity; @@ -13,11 +12,12 @@ @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) { + if (((Object) this) == MinecraftClient.getInstance().player && ComplexData.targetEntityHitPos != null) { ComplexData.lastHitEntity = target; - ComplexData.lastHitEntityDist = ComplexData.targetEntityHitPos.distanceTo(MinecraftClient.getInstance().getCameraEntity().getEntityPos()); + ComplexData.lastHitEntityDist = ComplexData.targetEntityHitPos + .distanceTo(MinecraftClient.getInstance().getCameraEntity().getEntityPos()); ComplexData.lastHitEntityTime = System.currentTimeMillis(); } } 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 d222ceab..6e820cd3 100644 --- a/src/main/java/com/minenash/customhud/mixin/accessors/GameOptionsAccessor.java +++ b/src/main/java/com/minenash/customhud/mixin/accessors/GameOptionsAccessor.java @@ -12,8 +12,13 @@ @Mixin(GameOptions.class) public interface GameOptionsAccessor { - @Invoker("accept") void invokeAccept(GameOptions.Visitor visitor); + @Invoker("accept") + void invokeAccept(GameOptions.Visitor visitor); - @Accessor Map> getSoundVolumeLevels(); + @Accessor + Map> getSoundVolumeLevels(); + + @Accessor("cloudRenderMode") + SimpleOption getCloudRenderMode(); } From 1063c10805845cdd1eeccdc406dcbb832895522d Mon Sep 17 00:00:00 2001 From: Taken Date: Thu, 29 Jan 2026 23:47:10 +0100 Subject: [PATCH 2/3] Fixed odd crosshair disapperance --- .../java/com/minenash/customhud/CustomHud.java | 6 +++++- .../customhud/mixin/InGameHudMixin.java | 17 +++++++---------- .../customhud/mixin/KeyBindingMixin.java | 6 +++++- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/minenash/customhud/CustomHud.java b/src/main/java/com/minenash/customhud/CustomHud.java index ea30c005..d7762d20 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/mixin/InGameHudMixin.java b/src/main/java/com/minenash/customhud/mixin/InGameHudMixin.java index 46b1cad6..1d4d1272 100644 --- a/src/main/java/com/minenash/customhud/mixin/InGameHudMixin.java +++ b/src/main/java/com/minenash/customhud/mixin/InGameHudMixin.java @@ -4,32 +4,29 @@ import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; import com.minenash.customhud.ProfileManager; import com.minenash.customhud.data.Crosshairs; +import com.minenash.customhud.data.Profile; import com.mojang.blaze3d.pipeline.RenderPipeline; -import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.hud.InGameHud; -import net.minecraft.client.option.AttackIndicator; -import net.minecraft.client.render.RenderTickCounter; import net.minecraft.util.Identifier; -import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(value = InGameHud.class, priority = 900) public abstract class InGameHudMixin { @ModifyExpressionValue(method = "renderCrosshair", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/debug/DebugHudProfile;isEntryVisible(Lnet/minecraft/util/Identifier;)Z")) private boolean getDebugCrosshairEnable(boolean original) { - return ProfileManager.getActive() != null && ProfileManager.getActive().crosshair == Crosshairs.NONE; + Profile active = ProfileManager.getActive(); + return active != null && active.crosshair == Crosshairs.NONE; } @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; + Profile active = ProfileManager.getActive(); + // When HUD is disabled (active == null), show normal crosshair (return true) + // When HUD is enabled, only show if crosshair is set to NORMAL + return active == null || active.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 507740e5..9fc2af19 100644 --- a/src/main/java/com/minenash/customhud/mixin/KeyBindingMixin.java +++ b/src/main/java/com/minenash/customhud/mixin/KeyBindingMixin.java @@ -20,7 +20,11 @@ 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()) { + } + // Only increment toggle keybinds for the active profile + Profile activeProfile = ProfileManager.getActive(); + if (activeProfile != null) { + for (Toggle t : activeProfile.toggles.values()) { if (t.key.matchesKey(input)) ++t.key.timesPressed; } From 11075ae825c1b70ae1b8928a9a585cb62af421cf Mon Sep 17 00:00:00 2001 From: Taken Date: Sat, 28 Feb 2026 02:04:40 +0100 Subject: [PATCH 3/3] Reverseing cosmetic changes --- gradle.properties | 20 +- .../HudElements/SettingsElement.java | 31 +- .../supplier/IntegerSuppliers.java | 582 +++++++----------- .../supplier/SpecialSupplierElement.java | 139 ++--- .../supplier/StringSupplierElement.java | 129 ++-- .../customhud/complex/ComplexData.java | 118 ++-- .../customhud/mixin/InGameHudMixin.java | 19 +- .../customhud/mixin/KeyBindingMixin.java | 1 - .../customhud/mixin/PlayerEntityMixin.java | 6 +- .../mixin/accessors/GameOptionsAccessor.java | 6 +- 10 files changed, 423 insertions(+), 628 deletions(-) diff --git a/gradle.properties b/gradle.properties index 20ccf379..eedcf271 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,17 +2,17 @@ org.gradle.jvmargs=-Xmx4G # Fabric Properties -# check these on https://fabricmc.net/develop -minecraft_version=1.21.11 -yarn_mappings=1.21.11+build.4 -loader_version=0.18.4 + # check these on https://fabricmc.net/develop + 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.11 -maven_group = com.minenash -archives_base_name = custom_hud + mod_version = 4.1.1+1.21.11 + maven_group = com.minenash + archives_base_name = custom_hud # Dependencies -#Fabric api -fabric_version=0.141.1+1.21.11 -modmenu_version=16.0.0-rc.1 \ No newline at end of file + #Fabric api + fabric_version=0.141.1+1.21.11 + modmenu_version=16.0.0-rc.1 diff --git a/src/main/java/com/minenash/customhud/HudElements/SettingsElement.java b/src/main/java/com/minenash/customhud/HudElements/SettingsElement.java index 8d142231..3199b4d4 100644 --- a/src/main/java/com/minenash/customhud/HudElements/SettingsElement.java +++ b/src/main/java/com/minenash/customhud/HudElements/SettingsElement.java @@ -24,12 +24,12 @@ public class SettingsElement { private static final MinecraftClient client = MinecraftClient.getInstance(); public static boolean initialized = false; - // Boolean, Integer, Double + //Boolean, Integer, Double public static final Map> simpleOptions = new HashMap<>(); private static final Map staticIntOptions = new HashMap<>(); private static void init() { - ((GameOptionsAccessor) MinecraftClient.getInstance().options).invokeAccept(new GameOptions.Visitor() { + ((GameOptionsAccessor)MinecraftClient.getInstance().options).invokeAccept(new GameOptions.Visitor() { @Override public void accept(String key, SimpleOption option) { simpleOptions.put(key.toLowerCase(), option); @@ -37,8 +37,7 @@ public void accept(String key, SimpleOption option) { @Override public int visitInt(String key, int current) { - staticIntOptions.put(key.toLowerCase(), current); - return current; + staticIntOptions.put(key.toLowerCase(), current); return current; } @Override @@ -63,7 +62,7 @@ public T visitObject(String key, T current, Function decoder, Fun }); } - public static Pair> create(String setting, Flags flags) { + public static Pair> create(String setting, Flags flags) { if (!initialized) init(); initialized = true; @@ -76,8 +75,7 @@ public static Pair> create(String setting, F String code = client.getLanguageManager().getLanguage(); HudElement element = switch (setting.substring(4)) { case "" -> new StringSupplierElement(() -> client.getLanguageManager().getLanguage(code).name()); - case "_region" -> - new StringSupplierElement(() -> client.getLanguageManager().getLanguage(code).region()); + case "_region" -> new StringSupplierElement(() -> client.getLanguageManager().getLanguage(code).region()); case "_code" -> new StringSupplierElement(() -> code); default -> null; }; @@ -97,7 +95,8 @@ else if (setting.startsWith("sound_")) return new Pair<>(new SpecialSupplierElement(SpecialSupplierElement.of( () -> binding.getBoundKeyLocalizedText().getString(), () -> ((KeyBindingAccessor) binding).getBoundKey().getCode(), - () -> !binding.isUnbound())), null); + () -> !binding.isUnbound() + )), null); return new Pair<>(null, new Pair<>(ErrorType.UNKNOWN_KEYBIND, key)); } @@ -106,10 +105,9 @@ else if (setting.startsWith("sound_")) for (SoundCategory soundCategory : SoundCategory.values()) if (soundCategory.getName().equalsIgnoreCase(cat)) return new Pair<>(new NumberSupplierElement(NumberSupplierElement.of( - () -> ((GameOptionsAccessor) options).getSoundVolumeLevels().get(soundCategory).getValue() - * 100, + () -> ((GameOptionsAccessor)options).getSoundVolumeLevels().get(soundCategory).getValue() * 100, flags.precision != -1 ? flags.precision : 0), flags), null); - return new Pair<>(null, new Pair<>(ErrorType.UNKNOWN_SOUND_CATEGORY, cat)); + return new Pair<>(null,new Pair<>(ErrorType.UNKNOWN_SOUND_CATEGORY, cat)); } SimpleOption option = simpleOptions.get(setting); @@ -118,7 +116,7 @@ else if (setting.startsWith("sound_")) if (staticIntOptions.containsKey(setting)) { int value = staticIntOptions.get(setting); - return new Pair<>(new NumberSupplierElement(() -> value, flags), null); + return new Pair<>(new NumberSupplierElement(() -> value, flags),null); } return new Pair<>(null, new Pair<>(ErrorType.UNKNOWN_SETTING, setting)); @@ -130,11 +128,9 @@ private static HudElement getSimpleOptionElement(SimpleOption option, Flags f if (option.getValue() instanceof Boolean) return new BooleanSupplierElement(() -> (Boolean) option.getValue()); if (option.getValue() instanceof Number) - return new NumberSupplierElement(NumberSupplierElement.of(() -> (Number) option.getValue(), - option.getValue() instanceof Integer ? 0 : 1), flags); + 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()); + return new StringSupplierElement(() -> ((String)option.getValue()).isEmpty() ? "Default" : (String)option.getValue()); if (option.getValue() instanceof ParticlesMode) { return new SpecialSupplierElement(SpecialSupplierElement.of( () -> ((ParticlesMode) option.getValue()).toString().toLowerCase(), @@ -157,7 +153,8 @@ private static HudElement getSimpleOptionElement(SimpleOption option, Flags f return new SpecialSupplierElement(SpecialSupplierElement.of( () -> ((NarratorMode) option.getValue()).getName().getString(), () -> ((NarratorMode) option.getValue()).getId(), - () -> ((NarratorMode) option.getValue()).getId() != 0)); + () -> ((NarratorMode) option.getValue()).getId() != 0 + )); return null; } 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 4ea44fa4..fd7657d7 100644 --- a/src/main/java/com/minenash/customhud/HudElements/supplier/IntegerSuppliers.java +++ b/src/main/java/com/minenash/customhud/HudElements/supplier/IntegerSuppliers.java @@ -37,356 +37,236 @@ public class IntegerSuppliers { - private static final MinecraftClient client = MinecraftClient.getInstance(); - - private static WorldRenderer worldRender() { - return client.worldRenderer; - } - - private static ChunkBuilder chunkBuilder() { - return worldRender().getChunkBuilder(); - } - - private static BlockPos blockPos() { - return client.getCameraEntity().getBlockPos(); - } - - private static LightingProvider serverLighting() { - return ComplexData.world.getChunkManager().getLightingProvider(); - } - - private static Integer chunk(WorldChunk chunk, Heightmap.Type type) { - if (chunk == null) - return null; - BlockPos pos = client.getCameraEntity().getBlockPos(); - return chunk.sampleHeightmap(type, pos.getX(), pos.getZ()); - } - - private static Integer spawnGroup(SpawnGroup group) { - SpawnHelper.Info info = ComplexData.serverWorld.getChunkManager().getSpawnInfo(); - return info == null ? null : info.getGroupToCount().getInt(group); - } - - private static double biome(DensityFunction function, MultiNoiseUtil.ParameterRange[] range) { - double d = (double) MultiNoiseUtil.toLong((float) EntryNumberSuppliers.sample(function)); - for (int i = 0; i < range.length; ++i) - if (d < (double) range[i].max()) - return i; - return Double.NaN; - } - - public static final Supplier PROFILE_ERRORS = () -> ProfileManager.getActive() == null ? 0 - : Errors.getErrors(ProfileManager.getActive().name).size(); - - public static final Supplier FPS = client::getCurrentFps; - public static final Supplier BIOME_BLEND = () -> client.options.getBiomeBlendRadius().getValue(); - public static final Supplier SIMULATION_DISTANCE = () -> client.options.getSimulationDistance() - .getValue(); - - public static final Supplier PACKETS_SENT = () -> (int) client.getNetworkHandler().getConnection() - .getAveragePacketsSent(); - public static final Supplier PACKETS_RECEIVED = () -> (int) client.getNetworkHandler().getConnection() - .getAveragePacketsReceived(); - public static final Supplier CHUNKS_RENDERED = () -> worldRender().getCompletedChunkCount(); - public static final Supplier CHUNKS_LOADED = () -> worldRender().getChunkCount(); - @SuppressWarnings("Convert2MethodRef") - public static final Supplier RENDER_DISTANCE = () -> client.options.getClampedViewDistance(); - public static final Supplier QUEUED_TASKS = () -> chunkBuilder().getScheduledTaskCount(); - public static final Supplier UPLOAD_QUEUE = () -> chunkBuilder().getChunksToUpload(); - public static final Supplier BUFFER_COUNT = () -> chunkBuilder().getFreeBufferCount(); - public static final Supplier ENTITIES_RENDERED = () -> worldRender().worldRenderState.entityRenderStates - .size(); - public static final Supplier ENTITIES_LOADED = () -> client.world.getRegularEntityCount(); - - public static final Supplier FORCED_LOADED_CHUNKS = () -> ComplexData.world instanceof ServerWorld - ? ((ServerWorld) ComplexData.world).getForcedChunks().size() - : null; - - public static final Supplier BLOCK_X = () -> blockPos().getX(); - public static final Supplier BLOCK_Y = () -> blockPos().getY(); - public static final Supplier BLOCK_Z = () -> blockPos().getZ(); - public static final Supplier TARGET_BLOCK_X = () -> targetBlockPos == null ? null - : targetBlockPos.getX(); - public static final Supplier TARGET_BLOCK_Y = () -> targetBlockPos == null ? null - : targetBlockPos.getY(); - public static final Supplier TARGET_BLOCK_Z = () -> targetBlockPos == null ? null - : targetBlockPos.getZ(); - public static final Supplier TARGET_BLOCK_DISTANCE = () -> targetBlockPos == null ? null - : targetBlockPos.getManhattanDistance(client.player.getBlockPos()); - public static final Supplier TARGET_BLOCK_COLOR = () -> targetBlock == null || targetBlock.isAir() - ? null - : targetBlock.getMapColor(client.world, targetBlockPos).color; - public static final Supplier TARGET_BLOCK_LUMINANCE = () -> targetBlock == null || targetBlock.isAir() - ? null - : ComplexData.world.getLuminance(targetBlockPos); - public static final Supplier TARGET_FLUID_X = () -> ComplexData.targetFluidPos == null ? null - : ComplexData.targetFluidPos.getX(); - public static final Supplier TARGET_FLUID_Y = () -> ComplexData.targetFluidPos == null ? null - : ComplexData.targetFluidPos.getY(); - public static final Supplier TARGET_FLUID_Z = () -> ComplexData.targetFluidPos == null ? null - : ComplexData.targetFluidPos.getZ(); - public static final Supplier TARGET_FLUID_DISTANCE = () -> ComplexData.targetFluidPos == null ? null - : ComplexData.targetFluidPos.getManhattanDistance(client.player.getBlockPos()); - public static final Supplier TARGET_FLUID_COLOR = () -> ComplexData.targetFluid == null - || ComplexData.targetFluid.isEmpty() ? null - : ComplexData.targetFluid.getBlockState().getMapColor(client.world, - ComplexData.targetFluidPos).color; - - public static final Supplier TARGET_BLOCK_POWERED = () -> targetBlockPos == null ? null - : client.world.getReceivedRedstonePower(targetBlockPos); - public static final Supplier TARGET_BLOCK_POWERED_NORTH = () -> targetBlockPos == null ? null - : client.world.getEmittedRedstonePower(targetBlockPos.offset(Direction.NORTH), Direction.NORTH); - public static final Supplier TARGET_BLOCK_POWERED_SOUTH = () -> targetBlockPos == null ? null - : client.world.getEmittedRedstonePower(targetBlockPos.offset(Direction.SOUTH), Direction.SOUTH); - public static final Supplier TARGET_BLOCK_POWERED_EAST = () -> targetBlockPos == null ? null - : client.world.getEmittedRedstonePower(targetBlockPos.offset(Direction.EAST), Direction.EAST); - public static final Supplier TARGET_BLOCK_POWERED_WEST = () -> targetBlockPos == null ? null - : client.world.getEmittedRedstonePower(targetBlockPos.offset(Direction.WEST), Direction.WEST); - public static final Supplier TARGET_BLOCK_POWERED_UP = () -> targetBlockPos == null ? null - : client.world.getEmittedRedstonePower(targetBlockPos.offset(Direction.UP), Direction.UP); - public static final Supplier TARGET_BLOCK_POWERED_DOWN = () -> targetBlockPos == null ? null - : client.world.getEmittedRedstonePower(targetBlockPos.offset(Direction.DOWN), Direction.DOWN); - - public static final Supplier TARGET_BLOCK_STRONG_POWERED = () -> targetBlockPos == null ? null - : client.world.getReceivedStrongRedstonePower(targetBlockPos); - public static final Supplier TARGET_BLOCK_STRONG_POWERED_NORTH = () -> targetBlockPos == null ? null - : client.world.getStrongRedstonePower(targetBlockPos.offset(Direction.NORTH), Direction.NORTH); - public static final Supplier TARGET_BLOCK_STRONG_POWERED_SOUTH = () -> targetBlockPos == null ? null - : client.world.getStrongRedstonePower(targetBlockPos.offset(Direction.SOUTH), Direction.SOUTH); - public static final Supplier TARGET_BLOCK_STRONG_POWERED_EAST = () -> targetBlockPos == null ? null - : client.world.getStrongRedstonePower(targetBlockPos.offset(Direction.EAST), Direction.EAST); - public static final Supplier TARGET_BLOCK_STRONG_POWERED_WEST = () -> targetBlockPos == null ? null - : client.world.getStrongRedstonePower(targetBlockPos.offset(Direction.WEST), Direction.WEST); - public static final Supplier TARGET_BLOCK_STRONG_POWERED_UP = () -> targetBlockPos == null ? null - : client.world.getStrongRedstonePower(targetBlockPos.offset(Direction.UP), Direction.UP); - public static final Supplier TARGET_BLOCK_STRONG_POWERED_DOWN = () -> targetBlockPos == null ? null - : client.world.getStrongRedstonePower(targetBlockPos.offset(Direction.DOWN), Direction.DOWN); - - public static final Supplier IN_CHUNK_X = () -> blockPos().getX() & 15; - public static final Supplier IN_CHUNK_Y = () -> blockPos().getY() & 15; - public static final Supplier IN_CHUNK_Z = () -> blockPos().getZ() & 15; - public static final Supplier CHUNK_X = () -> blockPos().getX() >> 4; - public static final Supplier CHUNK_Y = () -> blockPos().getY() >> 4; - public static final Supplier CHUNK_Z = () -> blockPos().getZ() >> 4; - public static final Supplier REGION_X = () -> blockPos().getX() >> 9; - public static final Supplier REGION_Z = () -> blockPos().getZ() >> 9; - public static final Supplier REGION_RELATIVE_X = () -> blockPos().getX() >> 4 & 0x1F; - public static final Supplier REGION_RELATIVE_Z = () -> blockPos().getZ() >> 4 & 0x1F; - - public static final Supplier CHUNK_CLIENT_CACHED = () -> client.world.getChunkManager().chunks.chunks - .length(); - public static final Supplier CHUNK_CLIENT_LOADED = () -> client.world.getChunkManager() - .getLoadedChunkCount(); - public static final Supplier CHUNK_CLIENT_ENTITIES_LOADED = () -> client.world.getRegularEntityCount(); - public static final Supplier CHUNK_CLIENT_ENTITIES_CACHED_SECTIONS = () -> client.world.entityManager.cache - .sectionCount(); - public static final Supplier CHUNK_CLIENT_ENTITIES_TICKING_CHUNKS = () -> client.world.entityManager.tickingChunkSections - .size(); - - public static final Supplier CHUNK_SERVER_LOADED = () -> ComplexData.serverWorld == null ? null - : ComplexData.serverWorld.getChunkManager().getLoadedChunkCount(); - public static final Supplier CHUNK_SERVER_ENTITIES_REGISTERED = () -> ComplexData.serverWorld == null - ? null - : ComplexData.serverWorld.entityManager.entityUuids.size(); - public static final Supplier CHUNK_SERVER_ENTITIES_LOADED = () -> ComplexData.serverWorld == null ? null - : ComplexData.serverWorld.entityManager.index.size(); - public static final Supplier CHUNK_SERVER_ENTITIES_CACHED_SECTIONS = () -> ComplexData.serverWorld == null - ? null - : ComplexData.serverWorld.entityManager.cache.sectionCount(); - public static final Supplier CHUNK_SERVER_ENTITIES_MANAGED = () -> ComplexData.serverWorld == null - ? null - : ComplexData.serverWorld.entityManager.managedStatuses.size(); - public static final Supplier CHUNK_SERVER_ENTITIES_TRACKED = () -> ComplexData.serverWorld == null - ? null - : ComplexData.serverWorld.entityManager.trackingStatuses.size(); - public static final Supplier CHUNK_SERVER_ENTITIES_LOADING = () -> ComplexData.serverWorld == null - ? null - : ComplexData.serverWorld.entityManager.loadingQueue.size(); - public static final Supplier CHUNK_SERVER_ENTITIES_UNLOADING = () -> ComplexData.serverWorld == null - ? null - : ComplexData.serverWorld.entityManager.pendingUnloads.size(); - - public static final Supplier CLIENT_LIGHT = () -> { - if (ComplexData.clientChunk.isEmpty()) - return null; - client.world.calculateAmbientDarkness(); - return Math.max(0, client.world.getChunkManager().getLightingProvider().getLight(blockPos(), - client.world.getAmbientDarkness())); - }; - public static final Supplier CLIENT_LIGHT_SKY = () -> ComplexData.clientChunk.isEmpty() ? null - : client.world.getLightLevel(LightType.SKY, blockPos()); - public static final Supplier CLIENT_LIGHT_SUN = () -> { - if (ComplexData.clientChunk.isEmpty()) - return null; - client.world.calculateAmbientDarkness(); - return Math.max(0, client.world.getLightLevel(LightType.SKY, blockPos()) - - client.world.getAmbientDarkness()); - }; - public static final Supplier CLIENT_LIGHT_BLOCK = () -> ComplexData.clientChunk.isEmpty() ? null - : client.world.getLightLevel(LightType.BLOCK, blockPos()); - @Deprecated - public static final Supplier SERVER_LIGHT_SKY = () -> ComplexData.serverChunk == null ? null - : serverLighting().get(LightType.SKY).getLightLevel(blockPos()); - @Deprecated - public static final Supplier SERVER_LIGHT_BLOCK = () -> ComplexData.serverChunk == null ? null - : serverLighting().get(LightType.BLOCK).getLightLevel(blockPos()); - - public static final Supplier CLIENT_HEIGHT_MAP_SURFACE = () -> chunk(ComplexData.clientChunk, - Heightmap.Type.WORLD_SURFACE); - public static final Supplier CLIENT_HEIGHT_MAP_MOTION_BLOCKING = () -> chunk(ComplexData.clientChunk, - Heightmap.Type.MOTION_BLOCKING); - public static final Supplier SERVER_HEIGHT_MAP_SURFACE = () -> chunk(ComplexData.serverChunk, - Heightmap.Type.WORLD_SURFACE); - public static final Supplier SERVER_HEIGHT_MAP_OCEAN_FLOOR = () -> chunk(ComplexData.serverChunk, - Heightmap.Type.OCEAN_FLOOR); - public static final Supplier SERVER_HEIGHT_MAP_MOTION_BLOCKING = () -> chunk(ComplexData.serverChunk, - Heightmap.Type.MOTION_BLOCKING); - public static final Supplier SERVER_HEIGHT_MAP_MOTION_BLOCKING_NO_LEAVES = () -> chunk( - ComplexData.serverChunk, Heightmap.Type.MOTION_BLOCKING_NO_LEAVES); - - public static final Supplier WORLD_MIN_Y = () -> ComplexData.world.getBottomY(); - public static final Supplier WORLD_MAX_Y = () -> ComplexData.world.getTopYInclusive(); - 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 - : (int) (client.world.getTimeOfDay() / 24000L % 8L) + 1; - - public static final Supplier SPAWN_CHUNKS = () -> { - SpawnHelper.Info info = ComplexData.serverWorld.getChunkManager().getSpawnInfo(); - return info == null ? null : info.getSpawningChunkCount(); - }; - public static final Supplier MONSTERS = () -> spawnGroup(SpawnGroup.MONSTER); - public static final Supplier CREATURES = () -> spawnGroup(SpawnGroup.CREATURE); - public static final Supplier AMBIENT_MOBS = () -> spawnGroup(SpawnGroup.AMBIENT); - public static final Supplier WATER_CREATURES = () -> spawnGroup(SpawnGroup.WATER_CREATURE); - public static final Supplier WATER_AMBIENT_MOBS = () -> spawnGroup(SpawnGroup.WATER_AMBIENT); - public static final Supplier UNDERGROUND_WATER_CREATURE = () -> spawnGroup( - SpawnGroup.UNDERGROUND_WATER_CREATURE); - public static final Supplier AXOLOTLS = () -> spawnGroup(SpawnGroup.AXOLOTLS); - public static final Supplier MISC_MOBS = () -> spawnGroup(SpawnGroup.MISC); - - public static final Supplier JAVA_BIT = () -> 64; - public static final Supplier CPU_CORES = () -> ComplexData.cpu == null ? null - : ((CentralProcessor) ComplexData.cpu).getPhysicalProcessorCount(); - public static final Supplier CPU_THREADS = () -> ComplexData.cpu == null ? null - : ((CentralProcessor) ComplexData.cpu).getLogicalProcessorCount(); - - public static final Supplier DISPLAY_WIDTH = () -> client.getWindow().getFramebufferWidth(); - public static final Supplier DISPLAY_HEIGHT = () -> client.getWindow().getFramebufferHeight(); - public static final Supplier DISPLAY_REFRESH_RATE = () -> GLX._getRefreshRate(client.getWindow()); - public static final Supplier PING = () -> Math.round(ComplexData.pingMetrics[0]); - public static final Supplier LATENCY = () -> client.player.networkHandler - .getPlayerListEntry(client.player.getUuid()).getLatency(); - public static final Supplier SOLAR_TIME = () -> client.world.getTimeOfDay() % 24000; - public static final Supplier LUNAR_TIME = () -> client.world.getTimeOfDay(); - - public static final Supplier PARTICLES = () -> client.particleManager.particles.values().stream() - .mapToInt(ParticleRenderer::size).sum(); - public static final Supplier STREAMING_SOUNDS = () -> CLIENT - .getSoundManager().soundSystem.soundEngine.streamingSources.getSourceCount(); - public static final Supplier MAX_STREAMING_SOUNDS = () -> CLIENT - .getSoundManager().soundSystem.soundEngine.streamingSources.getMaxSourceCount(); - public static final Supplier STATIC_SOUNDS = () -> CLIENT - .getSoundManager().soundSystem.soundEngine.staticSources.getSourceCount(); - public static final Supplier MAX_STATIC_SOUNDS = () -> CLIENT - .getSoundManager().soundSystem.soundEngine.staticSources.getMaxSourceCount(); - - public static final Supplier SLOTS_USED = () -> ComplexData.slots_used; - public static final Supplier SLOTS_EMPTY = () -> ComplexData.slots_empty; - - public static final Supplier FOOD_LEVEL = () -> client.player.getHungerManager().getFoodLevel(); - public static final Supplier SATURATION_LEVEL = () -> client.player.getHungerManager() - .getSaturationLevel(); - public static final Supplier ARMOR_LEVEL = () -> client.player.getArmor(); - public static final Supplier AIR_LEVEL = () -> Math - .round(20F * client.player.getAir() / client.player.getMaxAir()); - public static final Supplier SCORE = () -> client.player.getScore(); - public static final Supplier XP_LEVEL = () -> client.player.experienceLevel; - public static final Supplier XP_POINTS = () -> client.player.experienceProgress - * client.player.getNextLevelExperience(); - public static final Supplier XP_POINTS_NEEDED = () -> client.player.getNextLevelExperience(); - public static final Supplier HEALTH = () -> client.player.getHealth() - + client.player.getAbsorptionAmount(); - public static final Supplier HEALTH_MAX = () -> client.player.getMaxHealth(); - - public static final Supplier FOOD_LEVEL_PERCENTAGE = () -> client.player.getHungerManager() - .getFoodLevel() - * 5; - public static final Supplier SATURATION_LEVEL_PERCENTAGE = () -> client.player.getHungerManager() - .getSaturationLevel() * 5; - public static final Supplier ARMOR_LEVEL_PERCENTAGE = () -> client.player.getArmor() * 5; - - public static final Supplier BIOME_BUILDER_EROSION = () -> isNoise() - ? biome(sampler().erosion(), par.getErosionParameters()) - : Double.NaN; - public static final Supplier BIOME_BUILDER_TEMPERATURE = () -> isNoise() - ? biome(sampler().temperature(), par.getTemperatureParameters()) - : Double.NaN; - public static final Supplier BIOME_BUILDER_VEGETATION = () -> isNoise() - ? biome(sampler().vegetation(), par.getHumidityParameters()) - : Double.NaN; - - public static final Supplier HOTBAR_SLOT = () -> client.player.getInventory().getSelectedSlot() + 1; - public static final Supplier HOTBAR_INDEX = () -> client.player.getInventory().getSelectedSlot(); - @Deprecated - public static final Supplier ITEM_DURABILITY = () -> client.player.getMainHandStack().getMaxDamage() - - client.player.getMainHandStack().getDamage(); - @Deprecated - public static final Supplier ITEM_MAX_DURABILITY = () -> client.player.getMainHandStack() - .getMaxDamage(); - @Deprecated - public static final Supplier OFFHAND_ITEM_DURABILITY = () -> client.player.getOffHandStack() - .getMaxDamage() - - client.player.getOffHandStack().getDamage(); - @Deprecated - public static final Supplier OFFHAND_ITEM_MAX_DURABILITY = () -> client.player.getOffHandStack() - .getMaxDamage(); - - public static final Supplier LCPS = () -> ComplexData.clicksPerSeconds[0]; - public static final Supplier RCPS = () -> ComplexData.clicksPerSeconds[1]; - - public static final Supplier TIME_HOUR_12 = () -> { - int hour = ComplexData.timeOfDay / 1000 % 12; - return hour == 0 ? 12 : hour; - }; - - public static final Supplier UNIX_TIME = System::currentTimeMillis; - public static final Supplier REAL_YEAR = () -> LocalDate.now().getYear(); - public static final Supplier REAL_MONTH = () -> LocalDate.now().getMonthValue(); - public static final Supplier REAL_DAY = () -> LocalDate.now().getDayOfMonth(); - public static final Supplier REAL_DAY_OF_WEEK = () -> LocalDate.now().getDayOfWeek().getValue(); - public static final Supplier REAL_DAY_OF_YEAR = () -> LocalDate.now().getDayOfYear(); - - public static final Supplier REAL_HOUR_24 = () -> LocalTime.now().getHour(); - public static final Supplier REAL_HOUR_12 = () -> { - int hour = LocalTime.now().getHour(); - return hour == 0 ? 12 : hour; - }; - public static final Supplier REAL_MINUTE = () -> LocalTime.now().getMinute(); - public static final Supplier REAL_SECOND = () -> LocalTime.now().getSecond(); - public static final Supplier REAL_MICROSECOND = () -> LocalTime.now().get(MICRO_OF_SECOND); - - public static final Supplier RESOURCE_PACK_VERSION_MAJOR = () -> SharedConstants.getGameVersion() - .packVersion(ResourceType.CLIENT_RESOURCES).major(); - public static final Supplier RESOURCE_PACK_VERSION_MINOR = () -> SharedConstants.getGameVersion() - .packVersion(ResourceType.CLIENT_RESOURCES).minor(); - public static final Supplier DATA_PACK_VERSION_MAJOR = () -> SharedConstants.getGameVersion() - .packVersion(ResourceType.SERVER_DATA).major(); - public static final Supplier DATA_PACK_VERSION_MINOR = () -> SharedConstants.getGameVersion() - .packVersion(ResourceType.SERVER_DATA).minor(); - - public static final Supplier MAINHAND_SLOT = () -> CLIENT.player.getInventory().getSelectedSlot(); - - public static final Supplier VILLAGER_LEVEL = () -> ComplexData.targetEntity instanceof VillagerEntity ve - ? ve.getVillagerData().level() - : null; - public static final Supplier VILLAGER_XP = () -> ComplexData.targetEntity instanceof VillagerEntity ve - ? ComplexData.villagerXP - VillagerData.getLowerLevelExperience(ve.getVillagerData().level()) - : null; - public static final Supplier VILLAGER_XP_NEEDED = () -> ComplexData.targetEntity instanceof VillagerEntity ve - ? VillagerData.getUpperLevelExperience(ve.getVillagerData().level()) - : null; + private static final MinecraftClient client = MinecraftClient.getInstance(); + private static WorldRenderer worldRender() { + return client.worldRenderer; + } + private static ChunkBuilder chunkBuilder() { + return worldRender().getChunkBuilder(); + } + private static BlockPos blockPos() { return client.getCameraEntity().getBlockPos(); } + private static LightingProvider serverLighting() { return ComplexData.world.getChunkManager().getLightingProvider(); } + + private static Integer chunk(WorldChunk chunk, Heightmap.Type type) { + if (chunk == null) return null; + BlockPos pos = client.getCameraEntity().getBlockPos(); + return chunk.sampleHeightmap(type, pos.getX(), pos.getZ()); + } + + private static Integer spawnGroup(SpawnGroup group) { + SpawnHelper.Info info = ComplexData.serverWorld.getChunkManager().getSpawnInfo(); + return info == null ? null : info.getGroupToCount().getInt(group); + } + + private static double biome(DensityFunction function, MultiNoiseUtil.ParameterRange[] range) { + double d = (double)MultiNoiseUtil.toLong((float) EntryNumberSuppliers.sample(function)); + for(int i = 0; i < range.length; ++i) + if (d < (double)range[i].max()) + return i; + return Double.NaN; + } + + public static final Supplier PROFILE_ERRORS = () -> ProfileManager.getActive() == null ? 0 : Errors.getErrors(ProfileManager.getActive().name).size(); + + public static final Supplier FPS = client::getCurrentFps; + public static final Supplier BIOME_BLEND = () -> client.options.getBiomeBlendRadius().getValue(); + public static final Supplier SIMULATION_DISTANCE = () -> client.options.getSimulationDistance().getValue(); + + public static final Supplier PACKETS_SENT = () -> (int)client.getNetworkHandler().getConnection().getAveragePacketsSent(); + public static final Supplier PACKETS_RECEIVED = () -> (int)client.getNetworkHandler().getConnection().getAveragePacketsReceived(); + public static final Supplier CHUNKS_RENDERED = () -> worldRender().getCompletedChunkCount(); + public static final Supplier CHUNKS_LOADED = () -> worldRender().getChunkCount(); + @SuppressWarnings("Convert2MethodRef" ) + public static final Supplier RENDER_DISTANCE = () -> client.options.getClampedViewDistance(); + public static final Supplier QUEUED_TASKS = () -> chunkBuilder().getScheduledTaskCount(); + public static final Supplier UPLOAD_QUEUE = () -> chunkBuilder().getChunksToUpload(); + public static final Supplier BUFFER_COUNT = () -> chunkBuilder().getFreeBufferCount(); + public static final Supplier ENTITIES_RENDERED = () -> worldRender().worldRenderState.entityRenderStates.size(); + public static final Supplier ENTITIES_LOADED = () -> client.world.getRegularEntityCount(); + + public static final Supplier FORCED_LOADED_CHUNKS = () -> ComplexData.world instanceof ServerWorld ? ((ServerWorld)ComplexData.world).getForcedChunks().size() : null; + + public static final Supplier BLOCK_X = () -> blockPos().getX(); + public static final Supplier BLOCK_Y = () -> blockPos().getY(); + public static final Supplier BLOCK_Z = () -> blockPos().getZ(); + public static final Supplier TARGET_BLOCK_X = () -> targetBlockPos == null ? null : targetBlockPos.getX(); + public static final Supplier TARGET_BLOCK_Y = () -> targetBlockPos == null ? null : targetBlockPos.getY(); + public static final Supplier TARGET_BLOCK_Z = () -> targetBlockPos == null ? null : targetBlockPos.getZ(); + public static final Supplier TARGET_BLOCK_DISTANCE = () -> targetBlockPos == null ? null : targetBlockPos.getManhattanDistance(client.player.getBlockPos()); + public static final Supplier TARGET_BLOCK_COLOR = () -> targetBlock == null || targetBlock.isAir() ? null : targetBlock.getMapColor(client.world, targetBlockPos).color; + public static final Supplier TARGET_BLOCK_LUMINANCE = () -> targetBlock == null || targetBlock.isAir() ? null : ComplexData.world.getLuminance(targetBlockPos); + public static final Supplier TARGET_FLUID_X = () -> ComplexData.targetFluidPos == null ? null : ComplexData.targetFluidPos.getX(); + public static final Supplier TARGET_FLUID_Y = () -> ComplexData.targetFluidPos == null ? null : ComplexData.targetFluidPos.getY(); + public static final Supplier TARGET_FLUID_Z = () -> ComplexData.targetFluidPos == null ? null : ComplexData.targetFluidPos.getZ(); + public static final Supplier TARGET_FLUID_DISTANCE = () -> ComplexData.targetFluidPos == null ? null : ComplexData.targetFluidPos.getManhattanDistance(client.player.getBlockPos()); + public static final Supplier TARGET_FLUID_COLOR = () -> ComplexData.targetFluid == null || ComplexData.targetFluid.isEmpty()? null : ComplexData.targetFluid.getBlockState().getMapColor(client.world, ComplexData.targetFluidPos).color; + + public static final Supplier TARGET_BLOCK_POWERED = () -> targetBlockPos == null ? null : client.world.getReceivedRedstonePower(targetBlockPos); + public static final Supplier TARGET_BLOCK_POWERED_NORTH = () -> targetBlockPos == null ? null : client.world.getEmittedRedstonePower(targetBlockPos.offset(Direction.NORTH), Direction.NORTH); + public static final Supplier TARGET_BLOCK_POWERED_SOUTH = () -> targetBlockPos == null ? null : client.world.getEmittedRedstonePower(targetBlockPos.offset(Direction.SOUTH), Direction.SOUTH); + public static final Supplier TARGET_BLOCK_POWERED_EAST = () -> targetBlockPos == null ? null : client.world.getEmittedRedstonePower(targetBlockPos.offset(Direction.EAST), Direction.EAST); + public static final Supplier TARGET_BLOCK_POWERED_WEST = () -> targetBlockPos == null ? null : client.world.getEmittedRedstonePower(targetBlockPos.offset(Direction.WEST), Direction.WEST); + public static final Supplier TARGET_BLOCK_POWERED_UP = () -> targetBlockPos == null ? null : client.world.getEmittedRedstonePower(targetBlockPos.offset(Direction.UP), Direction.UP); + public static final Supplier TARGET_BLOCK_POWERED_DOWN = () -> targetBlockPos == null ? null : client.world.getEmittedRedstonePower(targetBlockPos.offset(Direction.DOWN), Direction.DOWN); + + public static final Supplier TARGET_BLOCK_STRONG_POWERED = () -> targetBlockPos == null ? null : client.world.getReceivedStrongRedstonePower(targetBlockPos); + public static final Supplier TARGET_BLOCK_STRONG_POWERED_NORTH = () -> targetBlockPos == null ? null : client.world.getStrongRedstonePower(targetBlockPos.offset(Direction.NORTH), Direction.NORTH); + public static final Supplier TARGET_BLOCK_STRONG_POWERED_SOUTH = () -> targetBlockPos == null ? null : client.world.getStrongRedstonePower(targetBlockPos.offset(Direction.SOUTH), Direction.SOUTH); + public static final Supplier TARGET_BLOCK_STRONG_POWERED_EAST = () -> targetBlockPos == null ? null : client.world.getStrongRedstonePower(targetBlockPos.offset(Direction.EAST), Direction.EAST); + public static final Supplier TARGET_BLOCK_STRONG_POWERED_WEST = () -> targetBlockPos == null ? null : client.world.getStrongRedstonePower(targetBlockPos.offset(Direction.WEST), Direction.WEST); + public static final Supplier TARGET_BLOCK_STRONG_POWERED_UP = () -> targetBlockPos == null ? null : client.world.getStrongRedstonePower(targetBlockPos.offset(Direction.UP), Direction.UP); + public static final Supplier TARGET_BLOCK_STRONG_POWERED_DOWN = () -> targetBlockPos == null ? null : client.world.getStrongRedstonePower(targetBlockPos.offset(Direction.DOWN), Direction.DOWN); + + public static final Supplier IN_CHUNK_X = () -> blockPos().getX() & 15; + public static final Supplier IN_CHUNK_Y = () -> blockPos().getY() & 15; + public static final Supplier IN_CHUNK_Z = () -> blockPos().getZ() & 15; + public static final Supplier CHUNK_X = () -> blockPos().getX() >> 4; + public static final Supplier CHUNK_Y = () -> blockPos().getY() >> 4; + public static final Supplier CHUNK_Z = () -> blockPos().getZ() >> 4; + public static final Supplier REGION_X = () -> blockPos().getX() >> 9; + public static final Supplier REGION_Z = () -> blockPos().getZ() >> 9; + public static final Supplier REGION_RELATIVE_X = () -> blockPos().getX() >> 4 & 0x1F; + public static final Supplier REGION_RELATIVE_Z = () -> blockPos().getZ() >> 4 & 0x1F; + + public static final Supplier CHUNK_CLIENT_CACHED = () -> client.world.getChunkManager().chunks.chunks.length(); + public static final Supplier CHUNK_CLIENT_LOADED = () -> client.world.getChunkManager().getLoadedChunkCount(); + public static final Supplier CHUNK_CLIENT_ENTITIES_LOADED = () -> client.world.getRegularEntityCount(); + public static final Supplier CHUNK_CLIENT_ENTITIES_CACHED_SECTIONS = () -> client.world.entityManager.cache.sectionCount(); + public static final Supplier CHUNK_CLIENT_ENTITIES_TICKING_CHUNKS = () -> client.world.entityManager.tickingChunkSections.size(); + + public static final Supplier CHUNK_SERVER_LOADED = () -> ComplexData.serverWorld == null ? null : ComplexData.serverWorld.getChunkManager().getLoadedChunkCount(); + public static final Supplier CHUNK_SERVER_ENTITIES_REGISTERED = () -> ComplexData.serverWorld == null ? null : ComplexData.serverWorld.entityManager.entityUuids.size(); + public static final Supplier CHUNK_SERVER_ENTITIES_LOADED = () -> ComplexData.serverWorld == null ? null : ComplexData.serverWorld.entityManager.index.size(); + public static final Supplier CHUNK_SERVER_ENTITIES_CACHED_SECTIONS = () -> ComplexData.serverWorld == null ? null : ComplexData.serverWorld.entityManager.cache.sectionCount(); + public static final Supplier CHUNK_SERVER_ENTITIES_MANAGED = () -> ComplexData.serverWorld == null ? null : ComplexData.serverWorld.entityManager.managedStatuses.size(); + public static final Supplier CHUNK_SERVER_ENTITIES_TRACKED = () -> ComplexData.serverWorld == null ? null : ComplexData.serverWorld.entityManager.trackingStatuses.size(); + public static final Supplier CHUNK_SERVER_ENTITIES_LOADING = () -> ComplexData.serverWorld == null ? null : ComplexData.serverWorld.entityManager.loadingQueue.size(); + public static final Supplier CHUNK_SERVER_ENTITIES_UNLOADING = () -> ComplexData.serverWorld == null ? null : ComplexData.serverWorld.entityManager.pendingUnloads.size(); + + public static final Supplier CLIENT_LIGHT = () -> { + if (ComplexData.clientChunk.isEmpty()) return null; + client.world.calculateAmbientDarkness(); + return Math.max(0, client.world.getChunkManager().getLightingProvider().getLight(blockPos(), client.world.getAmbientDarkness())); + }; + public static final Supplier CLIENT_LIGHT_SKY = () -> ComplexData.clientChunk.isEmpty() ? null : client.world.getLightLevel(LightType.SKY, blockPos()); + public static final Supplier CLIENT_LIGHT_SUN = () -> { + if (ComplexData.clientChunk.isEmpty()) return null; + client.world.calculateAmbientDarkness(); + return Math.max(0, client.world.getLightLevel(LightType.SKY, blockPos()) - client.world.getAmbientDarkness()); + }; + public static final Supplier CLIENT_LIGHT_BLOCK = () -> ComplexData.clientChunk.isEmpty() ? null : client.world.getLightLevel(LightType.BLOCK, blockPos()); + @Deprecated public static final Supplier SERVER_LIGHT_SKY = () -> ComplexData.serverChunk == null ? null : serverLighting().get(LightType.SKY).getLightLevel(blockPos()); + @Deprecated public static final Supplier SERVER_LIGHT_BLOCK = () -> ComplexData.serverChunk == null ? null : serverLighting().get(LightType.BLOCK).getLightLevel(blockPos()); + + public static final Supplier CLIENT_HEIGHT_MAP_SURFACE = () -> chunk(ComplexData.clientChunk, Heightmap.Type.WORLD_SURFACE); + public static final Supplier CLIENT_HEIGHT_MAP_MOTION_BLOCKING = () -> chunk(ComplexData.clientChunk, Heightmap.Type.MOTION_BLOCKING); + public static final Supplier SERVER_HEIGHT_MAP_SURFACE = () -> chunk(ComplexData.serverChunk, Heightmap.Type.WORLD_SURFACE); + public static final Supplier SERVER_HEIGHT_MAP_OCEAN_FLOOR = () -> chunk(ComplexData.serverChunk, Heightmap.Type.OCEAN_FLOOR); + public static final Supplier SERVER_HEIGHT_MAP_MOTION_BLOCKING = () -> chunk(ComplexData.serverChunk, Heightmap.Type.MOTION_BLOCKING); + public static final Supplier SERVER_HEIGHT_MAP_MOTION_BLOCKING_NO_LEAVES = () -> chunk(ComplexData.serverChunk, Heightmap.Type.MOTION_BLOCKING_NO_LEAVES); + + public static final Supplier WORLD_MIN_Y = () -> ComplexData.world.getBottomY(); + public static final Supplier WORLD_MAX_Y = () -> ComplexData.world.getTopYInclusive(); + 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 : (int)(client.world.getTimeOfDay() / 24000L % 8L) + 1; + + public static final Supplier SPAWN_CHUNKS = () -> { + SpawnHelper.Info info = ComplexData.serverWorld.getChunkManager().getSpawnInfo(); + return info == null ? null : info.getSpawningChunkCount(); + }; + public static final Supplier MONSTERS = () -> spawnGroup(SpawnGroup.MONSTER); + public static final Supplier CREATURES = () -> spawnGroup(SpawnGroup.CREATURE); + public static final Supplier AMBIENT_MOBS = () -> spawnGroup(SpawnGroup.AMBIENT); + public static final Supplier WATER_CREATURES = () -> spawnGroup(SpawnGroup.WATER_CREATURE); + public static final Supplier WATER_AMBIENT_MOBS = () -> spawnGroup(SpawnGroup.WATER_AMBIENT); + public static final Supplier UNDERGROUND_WATER_CREATURE = () -> spawnGroup(SpawnGroup.UNDERGROUND_WATER_CREATURE); + public static final Supplier AXOLOTLS = () -> spawnGroup(SpawnGroup.AXOLOTLS); + public static final Supplier MISC_MOBS = () -> spawnGroup(SpawnGroup.MISC); + + public static final Supplier JAVA_BIT = () -> 64; + public static final Supplier CPU_CORES = () -> ComplexData.cpu == null ? null : ((CentralProcessor)ComplexData.cpu).getPhysicalProcessorCount(); + public static final Supplier CPU_THREADS = () -> ComplexData.cpu == null ? null : ((CentralProcessor)ComplexData.cpu).getLogicalProcessorCount(); + + public static final Supplier DISPLAY_WIDTH = () -> client.getWindow().getFramebufferWidth(); + public static final Supplier DISPLAY_HEIGHT = () -> client.getWindow().getFramebufferHeight(); + public static final Supplier DISPLAY_REFRESH_RATE = () -> GLX._getRefreshRate(client.getWindow()); + public static final Supplier PING = () -> Math.round(ComplexData.pingMetrics[0]); + public static final Supplier LATENCY = () -> client.player.networkHandler.getPlayerListEntry(client.player.getUuid()).getLatency(); + public static final Supplier SOLAR_TIME = () -> client.world.getTimeOfDay() % 24000; + public static final Supplier LUNAR_TIME = () -> client.world.getTimeOfDay(); + + public static final Supplier PARTICLES = () -> client.particleManager.particles.values().stream().mapToInt(ParticleRenderer::size).sum(); + public static final Supplier STREAMING_SOUNDS = () -> CLIENT.getSoundManager().soundSystem.soundEngine.streamingSources.getSourceCount(); + public static final Supplier MAX_STREAMING_SOUNDS = () -> CLIENT.getSoundManager().soundSystem.soundEngine.streamingSources.getMaxSourceCount(); + public static final Supplier STATIC_SOUNDS = () -> CLIENT.getSoundManager().soundSystem.soundEngine.staticSources.getSourceCount(); + public static final Supplier MAX_STATIC_SOUNDS = () -> CLIENT.getSoundManager().soundSystem.soundEngine.staticSources.getMaxSourceCount(); + + public static final Supplier SLOTS_USED = () -> ComplexData.slots_used; + public static final Supplier SLOTS_EMPTY = () -> ComplexData.slots_empty; + + public static final Supplier FOOD_LEVEL = () -> client.player.getHungerManager().getFoodLevel(); + public static final Supplier SATURATION_LEVEL = () -> client.player.getHungerManager().getSaturationLevel(); + public static final Supplier ARMOR_LEVEL = () -> client.player.getArmor(); + public static final Supplier AIR_LEVEL = () -> Math.round(20F * client.player.getAir() / client.player.getMaxAir()); + public static final Supplier SCORE = () -> client.player.getScore(); + public static final Supplier XP_LEVEL = () -> client.player.experienceLevel; + public static final Supplier XP_POINTS = () -> client.player.experienceProgress * client.player.getNextLevelExperience(); + public static final Supplier XP_POINTS_NEEDED = () -> client.player.getNextLevelExperience(); + public static final Supplier HEALTH = () -> client.player.getHealth() + client.player.getAbsorptionAmount(); + public static final Supplier HEALTH_MAX = () -> client.player.getMaxHealth(); + + public static final Supplier FOOD_LEVEL_PERCENTAGE = () -> client.player.getHungerManager().getFoodLevel() * 5; + public static final Supplier SATURATION_LEVEL_PERCENTAGE = () -> client.player.getHungerManager().getSaturationLevel() * 5; + public static final Supplier ARMOR_LEVEL_PERCENTAGE = () -> client.player.getArmor() * 5; + + public static final Supplier BIOME_BUILDER_EROSION = () -> isNoise() ? biome(sampler().erosion(), par.getErosionParameters()) : Double.NaN; + public static final Supplier BIOME_BUILDER_TEMPERATURE = () -> isNoise() ? biome(sampler().temperature(), par.getTemperatureParameters()) : Double.NaN; + public static final Supplier BIOME_BUILDER_VEGETATION = () -> isNoise() ? biome(sampler().vegetation(), par.getHumidityParameters()) : Double.NaN; + + public static final Supplier HOTBAR_SLOT = () -> client.player.getInventory().getSelectedSlot() + 1; + public static final Supplier HOTBAR_INDEX = () -> client.player.getInventory().getSelectedSlot(); + @Deprecated public static final Supplier ITEM_DURABILITY = () -> client.player.getMainHandStack().getMaxDamage() - client.player.getMainHandStack().getDamage(); + @Deprecated public static final Supplier ITEM_MAX_DURABILITY = () -> client.player.getMainHandStack().getMaxDamage(); + @Deprecated public static final Supplier OFFHAND_ITEM_DURABILITY = () -> client.player.getOffHandStack().getMaxDamage() - client.player.getOffHandStack().getDamage(); + @Deprecated public static final Supplier OFFHAND_ITEM_MAX_DURABILITY = () -> client.player.getOffHandStack().getMaxDamage(); + + public static final Supplier LCPS = () -> ComplexData.clicksPerSeconds[0]; + public static final Supplier RCPS = () -> ComplexData.clicksPerSeconds[1]; + + public static final Supplier TIME_HOUR_12 = () -> { + int hour = ComplexData.timeOfDay / 1000 % 12; + return hour == 0 ? 12 : hour; + }; + + public static final Supplier UNIX_TIME = System::currentTimeMillis; + public static final Supplier REAL_YEAR = () -> LocalDate.now().getYear(); + public static final Supplier REAL_MONTH = () -> LocalDate.now().getMonthValue(); + public static final Supplier REAL_DAY = () -> LocalDate.now().getDayOfMonth(); + public static final Supplier REAL_DAY_OF_WEEK = () -> LocalDate.now().getDayOfWeek().getValue(); + public static final Supplier REAL_DAY_OF_YEAR = () -> LocalDate.now().getDayOfYear(); + + public static final Supplier REAL_HOUR_24 = () -> LocalTime.now().getHour(); + public static final Supplier REAL_HOUR_12 = () -> { + int hour = LocalTime.now().getHour(); + return hour == 0 ? 12 : hour; + }; + public static final Supplier REAL_MINUTE = () -> LocalTime.now().getMinute(); + public static final Supplier REAL_SECOND = () -> LocalTime.now().getSecond(); + public static final Supplier REAL_MICROSECOND = () -> LocalTime.now().get(MICRO_OF_SECOND); + + + public static final Supplier RESOURCE_PACK_VERSION_MAJOR = () -> SharedConstants.getGameVersion().packVersion(ResourceType.CLIENT_RESOURCES).major(); + public static final Supplier RESOURCE_PACK_VERSION_MINOR = () -> SharedConstants.getGameVersion().packVersion(ResourceType.CLIENT_RESOURCES).minor(); + public static final Supplier DATA_PACK_VERSION_MAJOR = () -> SharedConstants.getGameVersion().packVersion(ResourceType.SERVER_DATA).major(); + public static final Supplier DATA_PACK_VERSION_MINOR = () -> SharedConstants.getGameVersion().packVersion(ResourceType.SERVER_DATA).minor(); + + public static final Supplier MAINHAND_SLOT = () -> CLIENT.player.getInventory().getSelectedSlot(); + + public static final Supplier VILLAGER_LEVEL = () -> ComplexData.targetEntity instanceof VillagerEntity ve ? ve.getVillagerData().level() : null; + public static final Supplier VILLAGER_XP = () -> ComplexData.targetEntity instanceof VillagerEntity ve ? ComplexData.villagerXP - VillagerData.getLowerLevelExperience(ve.getVillagerData().level()) : null; + public static final Supplier VILLAGER_XP_NEEDED = () -> ComplexData.targetEntity instanceof VillagerEntity ve ? VillagerData.getUpperLevelExperience(ve.getVillagerData().level()) : null; + } 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 68a9c49a..9fa54f39 100644 --- a/src/main/java/com/minenash/customhud/HudElements/supplier/SpecialSupplierElement.java +++ b/src/main/java/com/minenash/customhud/HudElements/supplier/SpecialSupplierElement.java @@ -25,70 +25,59 @@ public class SpecialSupplierElement implements HudElement { private static final MinecraftClient client = MinecraftClient.getInstance(); - private static boolean isFacingEastOrSouth() { Direction dir = client.getCameraEntity().getHorizontalFacing(); return dir == Direction.EAST || dir == Direction.SOUTH; } - public static final Entry DIFFICULTY = of(() -> client.world.getDifficulty().getName(), - () -> client.world.getDifficulty().getId(), - () -> client.world.getDifficulty().getId() != 0); - - public static final Entry MAX_FPS = of( - () -> client.options.getMaxFps().getValue() == GameOptions.MAX_FPS_LIMIT ? null - : client.options.getMaxFps().getValue().toString(), - () -> client.options.getMaxFps().getValue(), - () -> client.options.getMaxFps().getValue() == GameOptions.MAX_FPS_LIMIT); - - public static final Entry PROFILE_KEYBIND = of( - () -> getActive() == null ? "" : getActive().keyBinding.getBoundKeyLocalizedText().getString(), - () -> getActive() == null ? 0 : getActive().keyBinding.boundKey.getCode(), - () -> getActive() != null && !getActive().keyBinding.isUnbound()); - - public static final Entry TIME_HOUR_24 = of(() -> String.format("%02d", ComplexData.timeOfDay / 1000), - () -> ComplexData.timeOfDay / 1000, - () -> ComplexData.timeOfDay / 1000 >= 12); - - public static final Entry TIME_MINUTES = of( - () -> String.format("%02d", (int) ((ComplexData.timeOfDay % 1000) / (1000 / 60F))), - () -> (int) ((ComplexData.timeOfDay % 1000) / (1000 / 60F)), - () -> (int) ((ComplexData.timeOfDay % 1000) / (1000 / 60F)) != 0); - - public static final Entry TIME_SECONDS = of( - () -> String.format("%02d", (int) ((ComplexData.timeOfDay % 1000) % (1000 / 60F) * 3.6F)), - () -> (int) ((ComplexData.timeOfDay % 1000) % (1000 / 60F) * 3.6F), - () -> (int) ((ComplexData.timeOfDay % 1000) % (1000 / 60F) * 3.6F) != 0); - - public static final Entry TARGET_BLOCK = of( - () -> I18n.translate(ComplexData.targetBlock.getBlock().getTranslationKey()), - () -> Block.getRawIdFromState(ComplexData.targetBlock), - () -> !ComplexData.targetBlock.isAir()); - - public static final Entry TARGET_FLUID = of( - () -> WordUtils - .capitalize(Registries.FLUID.getId(ComplexData.targetFluid.getFluid()).getPath().replace('_', ' ')), - () -> Fluid.STATE_IDS.getRawId(ComplexData.targetFluid), - () -> !ComplexData.targetFluid.isEmpty()); - - public static final Entry ITEM_OLD = of( - () -> I18n.translate(client.player.getMainHandStack().getItem().getTranslationKey()), - () -> Item.getRawId(client.player.getMainHandStack().getItem()), - () -> !client.player.getMainHandStack().isEmpty()); + public static final Entry DIFFICULTY = of( () -> client.world.getDifficulty().getName(), + () -> client.world.getDifficulty().getId(), + () -> client.world.getDifficulty().getId() != 0); + + public static final Entry MAX_FPS = of( () -> client.options.getMaxFps().getValue() == GameOptions.MAX_FPS_LIMIT ? null : client.options.getMaxFps().getValue().toString(), + () -> client.options.getMaxFps().getValue(), + () -> client.options.getMaxFps().getValue() == GameOptions.MAX_FPS_LIMIT); + + public static final Entry PROFILE_KEYBIND = of( () -> getActive() == null ? "" : getActive().keyBinding.getBoundKeyLocalizedText().getString(), + () -> getActive() == null ? 0 : getActive().keyBinding.boundKey.getCode(), + () -> getActive() != null && !getActive().keyBinding.isUnbound()); + + public static final Entry TIME_HOUR_24 = of( () -> String.format("%02d", ComplexData.timeOfDay / 1000), + () -> ComplexData.timeOfDay / 1000, + () -> ComplexData.timeOfDay / 1000 >= 12); + + public static final Entry TIME_MINUTES = of( () -> String.format("%02d",(int)((ComplexData.timeOfDay % 1000) / (1000/60F))), + () -> (int)((ComplexData.timeOfDay % 1000) / (1000/60F)), + () -> (int)((ComplexData.timeOfDay % 1000) / (1000/60F)) != 0); + + public static final Entry TIME_SECONDS = of( () -> String.format("%02d",(int)((ComplexData.timeOfDay % 1000) % (1000/60F) * 3.6F)), + () -> (int)((ComplexData.timeOfDay % 1000) % (1000/60F) * 3.6F), + () -> (int)((ComplexData.timeOfDay % 1000) % (1000/60F) * 3.6F) != 0); + + public static final Entry TARGET_BLOCK = of( () -> I18n.translate(ComplexData.targetBlock.getBlock().getTranslationKey()), + () -> Block.getRawIdFromState(ComplexData.targetBlock), + () -> !ComplexData.targetBlock.isAir()); + + public static final Entry TARGET_FLUID = of( () -> WordUtils.capitalize(Registries.FLUID.getId(ComplexData.targetFluid.getFluid()).getPath().replace('_',' ')), + () -> Fluid.STATE_IDS.getRawId(ComplexData.targetFluid), + () -> !ComplexData.targetFluid.isEmpty()); - public static final Entry ITEM_NAME = of(() -> client.player.getMainHandStack().getName().getString(), + public static final Entry ITEM_OLD = of( () -> I18n.translate(client.player.getMainHandStack().getItem().getTranslationKey()), + () -> Item.getRawId(client.player.getMainHandStack().getItem()), + () -> !client.player.getMainHandStack().isEmpty()); + + public static final Entry ITEM_NAME = of( () -> client.player.getMainHandStack().getName().getString(), () -> client.player.getMainHandStack().getName().getString().length(), () -> !client.player.getMainHandStack().isEmpty()); @Deprecated - public static final Entry OFFHAND_ITEM = of( - () -> I18n.translate(client.player.getOffHandStack().getItem().getTranslationKey()), - () -> Item.getRawId(client.player.getOffHandStack().getItem()), - () -> !client.player.getOffHandStack().isEmpty()); + public static final Entry OFFHAND_ITEM = of( () -> I18n.translate(client.player.getOffHandStack().getItem().getTranslationKey()), + () -> Item.getRawId(client.player.getOffHandStack().getItem()), + () -> !client.player.getOffHandStack().isEmpty()); @Deprecated - public static final Entry OFFHAND_ITEM_NAME = of(() -> client.player.getOffHandStack().getName().getString(), - () -> client.player.getOffHandStack().getName().getString().length(), - () -> !client.player.getOffHandStack().isEmpty()); + public static final Entry OFFHAND_ITEM_NAME = of( () -> client.player.getOffHandStack().getName().getString(), + () -> client.player.getOffHandStack().getName().getString().length(), + () -> !client.player.getOffHandStack().isEmpty()); public static final Entry GRAPHICS_MODE = of(() -> { if (!SettingsElement.initialized) @@ -132,51 +121,37 @@ private static boolean isFacingEastOrSouth() { return opt.getValue() != CloudRenderMode.OFF; }); - public static final Entry GAMEMODE = of(() -> client.interactionManager.getCurrentGameMode().getId(), - () -> client.interactionManager.getCurrentGameMode().getIndex(), - () -> true); + public static final Entry GAMEMODE = of ( () -> client.interactionManager.getCurrentGameMode().getId(), + () -> client.interactionManager.getCurrentGameMode().getIndex(), + () -> true); - public static final Entry FACING_TOWARDS_PN_WORD = of(() -> isFacingEastOrSouth() ? "positive" : "negative", + public static final Entry FACING_TOWARDS_PN_WORD = of( () -> isFacingEastOrSouth() ? "positive" : "negative", () -> isFacingEastOrSouth() ? 1 : 0, SpecialSupplierElement::isFacingEastOrSouth); - public static final Entry FACING_TOWARDS_PN_SIGN = of(() -> isFacingEastOrSouth() ? "+" : "-", + public static final Entry FACING_TOWARDS_PN_SIGN = of( () -> isFacingEastOrSouth() ? "+" : "-", () -> isFacingEastOrSouth() ? 1 : 0, SpecialSupplierElement::isFacingEastOrSouth); - public static final Entry ACTIVE_RENDERER = of(() -> { - var r = renderer(); - return r != null ? r.getClass().getSimpleName() : "none (vanilla)"; - }, - () -> { - var r = renderer(); - return r != null ? r.getClass().getSimpleName().length() : 7; - }, - () -> renderer() != null); - - public static Renderer renderer() { - try { - return Renderer.get(); - } catch (Exception e) { - return null; - } - } + public static final Entry ACTIVE_RENDERER = of( () -> {var r = renderer(); return r != null ? r.getClass().getSimpleName() : "none (vanilla)";}, + () -> {var r = renderer(); return r != null ? r.getClass().getSimpleName().length() : 7;}, + () -> renderer() != null); - public static final Entry CAMERA_PERSPECTIVE = of( + public static Renderer renderer() { try {return Renderer.get();} catch (Exception e) { return null;}} + + public static final Entry CAMERA_PERSPECTIVE = of ( () -> switch (client.options.getPerspective()) { case FIRST_PERSON -> "First Person"; case THIRD_PERSON_BACK -> "Third Person (Back)"; case THIRD_PERSON_FRONT -> "Third Person (Front)"; }, () -> client.options.getPerspective().ordinal(), - () -> client.options.getPerspective().ordinal() != 0); + () -> client.options.getPerspective().ordinal() != 0 + ); - public record Entry(Supplier stringSupplier, Supplier numberSupplier, - Supplier booleanSupplier) { - } - public static Entry of(Supplier stringSupplier, Supplier numberSupplier, - Supplier booleanSupplier) { + public record Entry(Supplier stringSupplier, Supplier numberSupplier, Supplier booleanSupplier) {} + public static Entry of(Supplier stringSupplier, Supplier numberSupplier, Supplier booleanSupplier) { return new Entry(stringSupplier, numberSupplier, booleanSupplier); } 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 2543d3f4..17d2fb27 100644 --- a/src/main/java/com/minenash/customhud/HudElements/supplier/StringSupplierElement.java +++ b/src/main/java/com/minenash/customhud/HudElements/supplier/StringSupplierElement.java @@ -27,120 +27,76 @@ public class StringSupplierElement implements HudElement { private static final MinecraftClient client = MinecraftClient.getInstance(); + private static Entity cameraEntity() { return client.getCameraEntity(); } + private static BlockPos blockPos() { return client.getCameraEntity().getBlockPos(); } - private static Entity cameraEntity() { - return client.getCameraEntity(); - } - - private static BlockPos blockPos() { - return client.getCameraEntity().getBlockPos(); - } - - public static final Supplier PROFILE_NAME = () -> ProfileManager.getActive() == null ? null - : ProfileManager.getActive().name; + public static final Supplier PROFILE_NAME = () -> ProfileManager.getActive() == null ? null : ProfileManager.getActive().name; public static final Supplier VERSION = () -> SharedConstants.getGameVersion().name(); public static final Supplier CLIENT_VERSION = client::getGameVersion; public static final Supplier MODDED_NAME = ClientBrandRetriever::getClientModName; - public static final Supplier USERNAME = () -> client.player.getGameProfile().name() == null ? null - : client.player.getGameProfile().name(); + public static final Supplier USERNAME = () -> client.player.getGameProfile().name() == null ? null : client.player.getGameProfile().name(); public static final Supplier UUID = () -> client.player.getGameProfile().id().toString(); public static final Supplier SERVER_BRAND = () -> client.player.networkHandler.getBrand(); public static final Supplier SERVER_NAME = () -> client.getCurrentServerEntry().name; public static final Supplier SERVER_ADDRESS = () -> client.getCurrentServerEntry().address; - public static final Supplier WORLD_NAME = () -> !client.isIntegratedServerRunning() ? null - : client.getServer().getSaveProperties().getLevelName(); + public static final Supplier WORLD_NAME = () -> !client.isIntegratedServerRunning() ? null : client.getServer().getSaveProperties().getLevelName(); - public static final Supplier DIMENSION = () -> WordUtils - .capitalize(client.world.getRegistryKey().getValue().getPath().replace("_", " ")); - public static final Supplier BIOME = () -> I18n.translate( - "biome." + client.world.getBiome(blockPos()).getKey().get().getValue().toString().replace(':', '.')); + public static final Supplier DIMENSION = () -> WordUtils.capitalize(client.world.getRegistryKey().getValue().getPath().replace("_"," ")); + 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[(int) (client.world.getTimeOfDay() / 24000L % 8L)]; + 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[(int) (client.world.getTimeOfDay() / 24000L % 8L)]; public static final Supplier TIME_AM_PM = () -> ComplexData.timeOfDay < 12000 ? "am" : "pm"; public static final Supplier FACING4 = () -> cameraEntity().getHorizontalFacing().getId(); - public static final Supplier FACING4_SHORT = () -> cameraEntity().getHorizontalFacing().getId() - .substring(0, 1).toUpperCase(); - public static final Supplier FACING_TOWARDS_XZ = () -> cameraEntity() - .getHorizontalFacing() == Direction.EAST || cameraEntity().getHorizontalFacing() == Direction.WEST ? "X" - : "Z"; + public static final Supplier FACING4_SHORT = () -> cameraEntity().getHorizontalFacing().getId().substring(0, 1).toUpperCase(); + public static final Supplier FACING_TOWARDS_XZ = () -> + cameraEntity().getHorizontalFacing() == Direction.EAST || cameraEntity().getHorizontalFacing() == Direction.WEST ? "X" : "Z"; public static final Supplier FACING8 = () -> { float yaw = MathHelper.wrapDegrees(cameraEntity().getYaw()); - if (yaw > 157.5 || yaw < -157.5) - return "north"; - if (yaw > 112.5) - return "northwest"; - if (yaw > 67.5) - return "west"; - if (yaw > 22.5) - return "southwest"; - if (yaw < -112.5) - return "northeast"; - if (yaw < -67.5) - return "east"; - if (yaw < -22.5) - return "southeast"; + if (yaw > 157.5 || yaw < -157.5) return "north"; + if (yaw > 112.5) return "northwest"; + if (yaw > 67.5) return "west"; + if (yaw > 22.5) return "southwest"; + if (yaw < -112.5) return "northeast"; + if (yaw < -67.5) return "east"; + if (yaw < -22.5) return "southeast"; return "south"; }; public static final Supplier FACING8_SHORT = () -> { float yaw = MathHelper.wrapDegrees(cameraEntity().getYaw()); - if (yaw > 157.5 || yaw < -157.5) - return "N"; - if (yaw > 112.5) - return "NW"; - if (yaw > 67.5) - return "W"; - if (yaw > 22.5) - return "SW"; - if (yaw < -112.5) - return "NE"; - if (yaw < -67.5) - return "E"; - if (yaw < -22.5) - return "SE"; + if (yaw > 157.5 || yaw < -157.5) return "N"; + if (yaw > 112.5) return "NW"; + if (yaw > 67.5) return "W"; + if (yaw > 22.5) return "SW"; + if (yaw < -112.5) return "NE"; + if (yaw < -67.5) return "E"; + if (yaw < -22.5) return "SE"; return "S"; }; public static final Supplier JAVA_VERSION = () -> System.getProperty("java.version"); - public static final Supplier CPU_NAME = () -> ComplexData.cpu == null ? null - : ((CentralProcessor) ComplexData.cpu).getProcessorIdentifier().getName().trim(); + public static final Supplier CPU_NAME = () -> ComplexData.cpu == null ? null : ((CentralProcessor)ComplexData.cpu).getProcessorIdentifier().getName().trim(); public static final Supplier GPU_NAME = () -> RenderSystem.getDevice().getRenderer(); public static final Supplier GPU_VENDOR = () -> RenderSystem.getDevice().getVendor(); - public static final Supplier GL_VERSION = () -> RenderSystem.getDevice().getVersion().substring(0, - RenderSystem.getDevice().getVersion().indexOf(' ')); - public static final Supplier GPU_DRIVER = () -> RenderSystem.getDevice().getVersion() - .substring(RenderSystem.getDevice().getVersion().indexOf(' ') + 1); - - public static final Supplier MUSIC_NAME = () -> MusicAndRecordTracker.isMusicPlaying - ? MusicAndRecordTracker.musicName - : null; - - public static final Supplier BIOME_BUILDER_PEAKS = () -> isNoise() - ? VanillaBiomeParameters.getPeaksValleysDescription( - DensityFunctions.getPeaksValleysNoise((float) sample(sampler().ridges()))) - : null; - public static final Supplier BIOME_BUILDER_CONTINENTS = () -> isNoise() - ? par.getContinentalnessDescription(sample(sampler().continents())) - : null; - - public static final Supplier VILLAGER_BIOME = () -> ComplexData.targetEntity instanceof VillagerEntity ve - ? WordUtils.capitalize(ve.getVillagerData().type().toString()) - : null; - public static final Supplier VILLAGER_LEVEL_WORD = () -> ComplexData.targetEntity instanceof VillagerEntity ve - ? I18n.translate("merchant.level." + ve.getVillagerData().level()) - : null; - - public static final Supplier RESOURCE_PACK_VERSION = () -> SharedConstants.getGameVersion() - .packVersion(ResourceType.CLIENT_RESOURCES).toString(); - public static final Supplier DATA_PACK_VERSION = () -> SharedConstants.getGameVersion() - .packVersion(ResourceType.SERVER_DATA).toString(); + public static final Supplier GL_VERSION = () -> RenderSystem.getDevice().getVersion().substring(0, RenderSystem.getDevice().getVersion().indexOf(' ')); + public static final Supplier GPU_DRIVER = () -> RenderSystem.getDevice().getVersion().substring(RenderSystem.getDevice().getVersion().indexOf(' ') + 1); + + public static final Supplier MUSIC_NAME = () -> MusicAndRecordTracker.isMusicPlaying ? MusicAndRecordTracker.musicName : null; + + public static final Supplier BIOME_BUILDER_PEAKS = () -> isNoise() ? VanillaBiomeParameters.getPeaksValleysDescription(DensityFunctions.getPeaksValleysNoise((float)sample(sampler().ridges()))) : null; + public static final Supplier BIOME_BUILDER_CONTINENTS = () -> isNoise() ? par.getContinentalnessDescription(sample(sampler().continents())) : null; + + public static final Supplier VILLAGER_BIOME = () -> ComplexData.targetEntity instanceof VillagerEntity ve ? WordUtils.capitalize(ve.getVillagerData().type().toString()) : null; + public static final Supplier VILLAGER_LEVEL_WORD = () -> ComplexData.targetEntity instanceof VillagerEntity ve ? I18n.translate("merchant.level." + ve.getVillagerData().level()) : null; + + + public static final Supplier RESOURCE_PACK_VERSION = () -> SharedConstants.getGameVersion().packVersion(ResourceType.CLIENT_RESOURCES).toString(); + public static final Supplier DATA_PACK_VERSION = () -> SharedConstants.getGameVersion().packVersion(ResourceType.SERVER_DATA).toString(); private final Supplier supplier; @@ -157,7 +113,8 @@ public String getString() { public Number getNumber() { try { return supplier.get().length(); - } catch (Exception e) { + } + catch (Exception e) { return 0; } } diff --git a/src/main/java/com/minenash/customhud/complex/ComplexData.java b/src/main/java/com/minenash/customhud/complex/ComplexData.java index c1272d10..51127899 100644 --- a/src/main/java/com/minenash/customhud/complex/ComplexData.java +++ b/src/main/java/com/minenash/customhud/complex/ComplexData.java @@ -69,7 +69,7 @@ public class ComplexData { private static final MinecraftClient client = MinecraftClient.getInstance(); private static final BlockState AIR_BLOCK_STATE = Blocks.AIR.getDefaultState(); - // Chunk Data. + //Chunk Data. private static ChunkPos pos = null; private static CompletableFuture chunkFuture; @@ -78,8 +78,8 @@ public class ComplexData { public static double cpuLoad = 0; public static double gpuUsage = 0; - public static int[] clicksSoFar = new int[] { 0, 0 }; - public static int[] clicksPerSeconds = new int[] { 0, 0 }; + public static int[] clicksSoFar = new int[]{0,0}; + public static int[] clicksPerSeconds = new int[]{0,0}; public static ArrayDeque[] clicks = null; public static double[] frameTimeMetrics = new double[4]; @@ -102,13 +102,9 @@ public class ComplexData { public static long villagerLastRequested = Long.MAX_VALUE; public static boolean refreshTimings = false; - - public record ProfilerTimingWithPath(String path, String name, double parent, double total, int color, - List entries) { - } - + public record ProfilerTimingWithPath(String path, String name, double parent, double total, int color, List entries) {} public static List rootEntries = Collections.EMPTY_LIST; - public static Map allEntries = Collections.EMPTY_MAP; + public static Map allEntries = Collections.EMPTY_MAP; @SuppressWarnings("ConstantConditions") public static void update(Profile profile) { @@ -124,7 +120,7 @@ public static void update(Profile profile) { if (profile.enabled.clientChunk) { Profilers.get().push("clientChunk"); ChunkPos newPos = new ChunkPos(client.getCameraEntity().getBlockPos()); - if (!Objects.equals(ComplexData.pos, newPos)) { + if (!Objects.equals(ComplexData.pos,newPos)) { pos = newPos; chunkFuture = null; clientChunk = null; @@ -138,9 +134,7 @@ public static void update(Profile profile) { Profilers.get().push("serverChunk"); if (chunkFuture == null) { if (serverWorld != null) - chunkFuture = serverWorld.getChunkManager() - .getChunkFutureSyncOnMainThread(pos.x, pos.z, ChunkStatus.FULL, false) - .thenApply((either) -> (WorldChunk) either.orElse(null)); + chunkFuture = serverWorld.getChunkManager().getChunkFutureSyncOnMainThread(pos.x, pos.z, ChunkStatus.FULL, false).thenApply((either) -> (WorldChunk) either.orElse(null)); if (chunkFuture == null) chunkFuture = CompletableFuture.completedFuture(clientChunk); @@ -151,22 +145,19 @@ public static void update(Profile profile) { if (profile.enabled.world) { Profilers.get().push("world"); - world = DataFixUtils.orElse( - Optional.ofNullable(client.getServer()) - .flatMap((integratedServer) -> Optional - .ofNullable(integratedServer.getWorld(client.world.getRegistryKey()))), - client.world); + world = DataFixUtils.orElse(Optional.ofNullable(client.getServer()).flatMap((integratedServer) -> Optional.ofNullable(integratedServer.getWorld(client.world.getRegistryKey()))), client.world); Profilers.get().pop(); } if (profile.enabled.targetBlock) { Profilers.get().push("targetBlock"); - HitResult hit = client.getCameraEntity().raycast(profile.targetDistance, 0.0F, false); + HitResult hit = client.getCameraEntity().raycast(profile.targetDistance, 0.0F, false); if (hit.getType() == HitResult.Type.BLOCK) { - targetBlockPos = ((BlockHitResult) hit).getBlockPos(); + targetBlockPos = ((BlockHitResult)hit).getBlockPos(); targetBlock = world.getBlockState(targetBlockPos); - } else { + } + else { targetBlockPos = null; targetBlock = AIR_BLOCK_STATE; } @@ -175,12 +166,13 @@ public static void update(Profile profile) { if (profile.enabled.targetFluid) { Profilers.get().push("targetFluid"); - HitResult hit = client.getCameraEntity().raycast(profile.targetDistance, 0.0F, true); + HitResult hit = client.getCameraEntity().raycast(profile.targetDistance, 0.0F, true); if (hit.getType() == HitResult.Type.BLOCK) { - targetFluidPos = ((BlockHitResult) hit).getBlockPos(); + targetFluidPos = ((BlockHitResult)hit).getBlockPos(); targetFluid = world.getFluidState(targetFluidPos); - } else { + } + else { targetFluidPos = null; targetFluid = Fluids.EMPTY.getDefaultState(); } @@ -198,10 +190,9 @@ public static void update(Profile profile) { Box box = client.getCameraEntity().getBoundingBox().stretch(rot.multiply(dist)).expand(1.0, 1.0, 1.0); HitResult block = client.getCameraEntity().raycast(dist, 0, false); - double dist2 = block == null ? dist * dist : block.getPos().squaredDistanceTo(min); + double dist2 = block == null ? dist*dist : block.getPos().squaredDistanceTo(min); - EntityHitResult result = ProjectileUtil.raycast(client.getCameraEntity(), min, max, box, - (en) -> !en.isSpectator(), dist2); + EntityHitResult result = ProjectileUtil.raycast(client.getCameraEntity(), min, max, box, (en) -> !en.isSpectator(), dist2); targetEntity = result == null ? null : result.getEntity(); targetEntityHitPos = result == null ? null : result.getPos(); Profilers.get().pop(); @@ -241,7 +232,7 @@ public static void update(Profile profile) { if (profile.enabled.cpuUsage) { Profilers.get().push("cpu"); var c = (CentralProcessor) cpu; - double load = c.getSystemCpuLoadBetweenTicks(prevTicks) * 100; + double load = c.getSystemCpuLoadBetweenTicks( prevTicks ) * 100; if (load > 0) cpuLoad = load; prevTicks = c.getSystemCpuLoadTicks(); @@ -251,17 +242,17 @@ public static void update(Profile profile) { if (profile.enabled.updateStats) { Profilers.get().push("updateStats"); if (System.currentTimeMillis() - lastStatUpdate >= 500) { - client.getNetworkHandler() - .sendPacket(new ClientStatusC2SPacket(ClientStatusC2SPacket.Mode.REQUEST_STATS)); + client.getNetworkHandler().sendPacket(new ClientStatusC2SPacket(ClientStatusC2SPacket.Mode.REQUEST_STATS)); lastStatUpdate = System.currentTimeMillis(); } Profilers.get().pop(); } + if (profile.enabled.clicksPerSeconds) { Profilers.get().push("clicksPerSeconds"); if (clicks == null) { - clicks = new ArrayDeque[] { new ArrayDeque(20), new ArrayDeque(20) }; + clicks = new ArrayDeque[]{new ArrayDeque(20), new ArrayDeque(20)}; for (int i = 0; i < 20; i++) { clicks[0].add(0); clicks[1].add(0); @@ -281,14 +272,12 @@ public static void update(Profile profile) { if (profile.enabled.frameMetrics) { Profilers.get().push("frameMetrics"); - processLog(((DebugHudAccessor) client.inGameHud.getDebugHud()).getFrameNanosLog(), 0.000001, 240, - frameTimeMetrics); + processLog(((DebugHudAccessor)client.inGameHud.getDebugHud()).getFrameNanosLog(), 0.000001, 240, frameTimeMetrics); Profilers.get().pop(); } if (profile.enabled.tickMetrics) { Profilers.get().push("tickMetrics"); - processLog(((DebugHudAccessor) client.inGameHud.getDebugHud()).getTickNanosLog(), 0.000001, 120, - tickTimeMetrics); + processLog(((DebugHudAccessor)client.inGameHud.getDebugHud()).getTickNanosLog(), 0.000001, 120, tickTimeMetrics); Profilers.get().pop(); } if (profile.enabled.pingMetrics) { @@ -298,12 +287,12 @@ public static void update(Profile profile) { } if (profile.enabled.packetMetrics) { Profilers.get().push("packetMetrics"); - processLog(client.inGameHud.getDebugHud().getPacketSizeLog(), 20 / 1024D, 120, packetSizeMetrics); + processLog(client.inGameHud.getDebugHud().getPacketSizeLog(), 20/1024D, 120, packetSizeMetrics); Profilers.get().pop(); } if (profile.enabled.tpsMetrics) { Profilers.get().push("tpsMetrics"); - processTPSLog(((DebugHudAccessor) client.inGameHud.getDebugHud()).getTickNanosLog(), tpsMetrics); + processTPSLog(((DebugHudAccessor)client.inGameHud.getDebugHud()).getTickNanosLog(), tpsMetrics); Profilers.get().pop(); } @@ -328,17 +317,16 @@ public static void update(Profile profile) { if (profile.enabled.targetVillager) { Profilers.get().push("targetVillager"); - if (!(targetEntity instanceof VillagerEntity) && villagerUUID != null) { + if ( !(targetEntity instanceof VillagerEntity) && villagerUUID != null) { villagerOffers.clear(); villagerUUID = null; villagerLastRequested = Long.MAX_VALUE; - } else if (targetEntity instanceof VillagerEntity && (villagerUUID == null || - !targetEntity.getUuid().equals(villagerUUID) - || System.currentTimeMillis() - villagerLastRequested > 30_000)) { + } + else if (targetEntity instanceof VillagerEntity && (villagerUUID == null || + !targetEntity.getUuid().equals(villagerUUID) || System.currentTimeMillis() - villagerLastRequested > 30_000)) { villagerUUID = targetEntity.getUuid(); fakeVillagerInteract = 2; - CLIENT.getNetworkHandler() - .sendPacket(PlayerInteractEntityC2SPacket.interact(targetEntity, false, Hand.OFF_HAND)); + CLIENT.getNetworkHandler().sendPacket(PlayerInteractEntityC2SPacket.interact(targetEntity, false, Hand.OFF_HAND)); villagerLastRequested = System.currentTimeMillis(); } Profilers.get().pop(); @@ -350,13 +338,14 @@ public static void update(Profile profile) { if (profileResult == null) { rootEntries = Collections.EMPTY_LIST; allEntries = Collections.EMPTY_MAP; - } else { + } + else { rootEntries = new ArrayList<>(); allEntries = new HashMap<>(); List timings = profileResult.getTimings("root"); timings.remove(0); for (var entry : timings) - rootEntries.add(getEntries(profileResult, entry, "root\u001e" + entry.name)); + rootEntries.add( getEntries(profileResult, entry, "root\u001e" + entry.name) ); } Profilers.get().pop(); } @@ -375,8 +364,7 @@ public static ProfilerTimingWithPath getEntries(ProfileResult profileResult, Pro for (var entry : timings) entries.add(getEntries(profileResult, entry, path + "\u001e" + entry.name)); - ProfilerTimingWithPath entry = new ProfilerTimingWithPath(path, timing.name, - timing.parentSectionUsagePercentage, timing.totalUsagePercentage, timing.getColor(), entries); + ProfilerTimingWithPath entry = new ProfilerTimingWithPath(path, timing.name, timing.parentSectionUsagePercentage, timing.totalUsagePercentage, timing.getColor(), entries); allEntries.put(path, entry); return entry; } @@ -387,13 +375,13 @@ public static void processLog(MultiValueDebugSampleLogImpl log, double multiplie return; } - metrics[0] = 0; // AVG - metrics[1] = Integer.MAX_VALUE; // MIN - metrics[2] = Integer.MIN_VALUE; // MAX - metrics[3] = Math.min(samples, log.getLength() - 1); // SAMPLES + metrics[0] = 0; //AVG + metrics[1] = Integer.MAX_VALUE; //MIN + metrics[2] = Integer.MIN_VALUE; //MAX + metrics[3] = Math.min(samples, log.getLength()-1); //SAMPLES double avg = 0L; - for (int r = 0; r < metrics[3]; ++r) { + for (int r = 0; r < metrics[3]; ++r) { double s = log.get(r) * multiplier; metrics[1] = Math.min(metrics[1], s); metrics[2] = Math.max(metrics[2], s); @@ -408,13 +396,13 @@ public static void processTPSLog(MultiValueDebugSampleLogImpl log, double[] metr return; } - metrics[0] = 0; // AVG - metrics[1] = Integer.MAX_VALUE; // MIN - metrics[2] = Integer.MIN_VALUE; // MAX - metrics[3] = Math.min(120, log.getLength() - 1); // SAMPLES + metrics[0] = 0; //AVG + metrics[1] = Integer.MAX_VALUE; //MIN + metrics[2] = Integer.MIN_VALUE; //MAX + metrics[3] = Math.min(120, log.getLength()-1); //SAMPLES double avg = 0L; - for (int r = 0; r < metrics[3]; ++r) { + for (int r = 0; r < metrics[3]; ++r) { double s = Math.min(20, 1000F / (log.get(r) * 0.000001)); metrics[1] = Math.min(metrics[1], s); metrics[2] = Math.max(metrics[2], s); @@ -444,7 +432,7 @@ public static void reset() { public static class Enabled { public static final Enabled DISABLED = new Enabled(); - public final Map custom = new HashMap<>(); + public final Map custom = new HashMap<>(); public final List velocityTrackers = new ArrayList<>(); @@ -479,29 +467,27 @@ public static class Enabled { public void merge(Enabled enabled) { for (Field field : this.getClass().getFields()) { - if (field.getType() != Boolean.TYPE) - continue; - try { - field.setBoolean(this, field.getBoolean(this) || field.getBoolean(enabled)); - } catch (Exception ignored) { - } + if (field.getType() != Boolean.TYPE) continue; + try { field.setBoolean(this, field.getBoolean(this) || field.getBoolean(enabled)); } + catch (Exception ignored) {} } this.custom.putAll(enabled.custom); + this.velocityTrackers.addAll(enabled.velocityTrackers); } public boolean get(String name) { return custom.getOrDefault(name, false); } - public void set(String name) { custom.put(name, true); } - public void set(String name, boolean value) { custom.put(name, value); } } + + } diff --git a/src/main/java/com/minenash/customhud/mixin/InGameHudMixin.java b/src/main/java/com/minenash/customhud/mixin/InGameHudMixin.java index 1d4d1272..83815b34 100644 --- a/src/main/java/com/minenash/customhud/mixin/InGameHudMixin.java +++ b/src/main/java/com/minenash/customhud/mixin/InGameHudMixin.java @@ -4,31 +4,34 @@ import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; import com.minenash.customhud.ProfileManager; import com.minenash.customhud.data.Crosshairs; -import com.minenash.customhud.data.Profile; import com.mojang.blaze3d.pipeline.RenderPipeline; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.hud.InGameHud; +import net.minecraft.client.option.AttackIndicator; +import net.minecraft.client.render.RenderTickCounter; import net.minecraft.util.Identifier; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(value = InGameHud.class, priority = 900) public abstract class InGameHudMixin { @ModifyExpressionValue(method = "renderCrosshair", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/debug/DebugHudProfile;isEntryVisible(Lnet/minecraft/util/Identifier;)Z")) private boolean getDebugCrosshairEnable(boolean original) { - Profile active = ProfileManager.getActive(); - return active != null && active.crosshair == Crosshairs.NONE; + return ProfileManager.getActive() != null && ProfileManager.getActive().crosshair == Crosshairs.NONE; } @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) { - Profile active = ProfileManager.getActive(); - // When HUD is disabled (active == null), show normal crosshair (return true) - // When HUD is enabled, only show if crosshair is set to NORMAL - return active == null || active.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 9fc2af19..e3b74966 100644 --- a/src/main/java/com/minenash/customhud/mixin/KeyBindingMixin.java +++ b/src/main/java/com/minenash/customhud/mixin/KeyBindingMixin.java @@ -21,7 +21,6 @@ private static void checkKeybinds(InputUtil.Key key, CallbackInfo ci) { if (p.keyBinding.matchesKey(input)) ++p.keyBinding.timesPressed; } - // Only increment toggle keybinds for the active profile Profile activeProfile = ProfileManager.getActive(); if (activeProfile != null) { for (Toggle t : activeProfile.toggles.values()) { diff --git a/src/main/java/com/minenash/customhud/mixin/PlayerEntityMixin.java b/src/main/java/com/minenash/customhud/mixin/PlayerEntityMixin.java index 0ee1fc6e..5faed7e1 100644 --- a/src/main/java/com/minenash/customhud/mixin/PlayerEntityMixin.java +++ b/src/main/java/com/minenash/customhud/mixin/PlayerEntityMixin.java @@ -1,5 +1,6 @@ package com.minenash.customhud.mixin; + import com.minenash.customhud.complex.ComplexData; import net.minecraft.client.MinecraftClient; import net.minecraft.entity.Entity; @@ -14,10 +15,9 @@ public class PlayerEntityMixin { @Inject(method = "attack", at = @At("HEAD")) private void logAttack(Entity target, CallbackInfo ci) { - if (((Object) this) == MinecraftClient.getInstance().player && ComplexData.targetEntityHitPos != null) { + if (((Object)this) == MinecraftClient.getInstance().player && ComplexData.targetEntityHitPos != null) { ComplexData.lastHitEntity = target; - ComplexData.lastHitEntityDist = ComplexData.targetEntityHitPos - .distanceTo(MinecraftClient.getInstance().getCameraEntity().getEntityPos()); + ComplexData.lastHitEntityDist = ComplexData.targetEntityHitPos.distanceTo(MinecraftClient.getInstance().getCameraEntity().getEntityPos()); ComplexData.lastHitEntityTime = System.currentTimeMillis(); } } 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 6e820cd3..cf5f055a 100644 --- a/src/main/java/com/minenash/customhud/mixin/accessors/GameOptionsAccessor.java +++ b/src/main/java/com/minenash/customhud/mixin/accessors/GameOptionsAccessor.java @@ -12,11 +12,9 @@ @Mixin(GameOptions.class) public interface GameOptionsAccessor { - @Invoker("accept") - void invokeAccept(GameOptions.Visitor visitor); + @Invoker("accept") void invokeAccept(GameOptions.Visitor visitor); - @Accessor - Map> getSoundVolumeLevels(); + @Accessor Map> getSoundVolumeLevels(); @Accessor("cloudRenderMode") SimpleOption getCloudRenderMode();