From 6981b5460056d27963a08435400d288da79c8311 Mon Sep 17 00:00:00 2001 From: LordEnder_Kitty Date: Mon, 1 Jul 2024 23:46:25 -0500 Subject: [PATCH] Fixed bugs, cleaned up code, general improvements --- build.gradle | 2 +- gradle.properties | 4 ++-- gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew | 0 src/main/java/net/enderkitty/FireHud.java | 4 ++-- src/main/java/net/enderkitty/SoulFireAccessor.java | 4 ++-- .../java/net/enderkitty/config/FireHudConfig.java | 3 +++ .../enderkitty/mixin/BackgroundRendererMixin.java | 14 ++++++++++++++ .../net/enderkitty/mixin/ClientEntityMixin.java | 4 ++-- .../mixin/ClientPlayNetworkHandlerMixin.java | 14 +++++++------- .../mixin/EntityRendererDispatcherMixin.java | 4 ++-- .../java/net/enderkitty/mixin/InGameHudMixin.java | 4 ++-- .../mixin/InGameOverlayRendererMixin.java | 4 ++-- src/main/resources/assets/firehud/lang/en_us.json | 2 ++ src/main/resources/fabric.mod.json | 10 +++++++--- src/main/resources/firehud.accesswidener | 3 ++- 16 files changed, 51 insertions(+), 27 deletions(-) mode change 100644 => 100755 gradlew diff --git a/build.gradle b/build.gradle index d0c08a7..6149fd6 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.6-SNAPSHOT' + id 'fabric-loom' version '1.7-SNAPSHOT' id 'maven-publish' } diff --git a/gradle.properties b/gradle.properties index 04b7621..94c0bea 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,11 +9,11 @@ yarn_mappings=1.20.4+build.3 loader_version=0.15.11 # Mod Properties -mod_version=1.1.0-1.20.3-4 +mod_version=1.2-1.20.3-4 maven_group=net.enderkitty archives_base_name=firehud # Dependencies -fabric_version=0.97.0+1.20.4 +fabric_version=0.97.1+1.20.4 cloth_config_version=13.0.121 modmenu_version=9.0.0 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b82aa23..a441313 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.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/src/main/java/net/enderkitty/FireHud.java b/src/main/java/net/enderkitty/FireHud.java index a84ee3f..1bb56b8 100644 --- a/src/main/java/net/enderkitty/FireHud.java +++ b/src/main/java/net/enderkitty/FireHud.java @@ -37,10 +37,10 @@ public void onInitializeClient() { if (player != null && player.isOnFire() && client.options.getPerspective().isFirstPerson() && !(!config.renderFireInLava && player.isInLava()) && !(!config.renderWithFireResistance && player.hasStatusEffect(StatusEffects.FIRE_RESISTANCE))) { - if (config.fireScreenTint && !((SoulFireAccessor) player).isRenderSoulFire()) { + if (config.fireScreenTint && !((SoulFireAccessor) player).fireHud$isRenderSoulFire()) { context.fillGradient(0, 0, width, height, config.fireStartColor, config.fireEndColor); } - if (config.fireScreenTint && config.renderSoulFire && ((SoulFireAccessor) player).isRenderSoulFire()) { + if (config.fireScreenTint && config.renderSoulFire && ((SoulFireAccessor) player).fireHud$isRenderSoulFire()) { context.fillGradient(0, 0, width, height, config.soulFireStartColor, config.soulFireEndColor); } } diff --git a/src/main/java/net/enderkitty/SoulFireAccessor.java b/src/main/java/net/enderkitty/SoulFireAccessor.java index ef32a7d..b740ea3 100644 --- a/src/main/java/net/enderkitty/SoulFireAccessor.java +++ b/src/main/java/net/enderkitty/SoulFireAccessor.java @@ -1,6 +1,6 @@ package net.enderkitty; public interface SoulFireAccessor { - boolean isRenderSoulFire(); - void setRenderSoulFire(boolean renderSoulFire); + boolean fireHud$isRenderSoulFire(); + void fireHud$setRenderSoulFire(boolean renderSoulFire); } diff --git a/src/main/java/net/enderkitty/config/FireHudConfig.java b/src/main/java/net/enderkitty/config/FireHudConfig.java index b7dbcc8..3187da3 100644 --- a/src/main/java/net/enderkitty/config/FireHudConfig.java +++ b/src/main/java/net/enderkitty/config/FireHudConfig.java @@ -60,6 +60,9 @@ public class FireHudConfig implements ConfigData { @ConfigEntry.Gui.Tooltip @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) public LavaFogOptions renderLavaFog = LavaFogOptions.VANILLA; + @ConfigEntry.Gui.Tooltip + @ConfigEntry.BoundedDiscrete(max = 100) + public int lightFogDist = 50; @ConfigEntry.Gui.PrefixText @ConfigEntry.Gui.Tooltip diff --git a/src/main/java/net/enderkitty/mixin/BackgroundRendererMixin.java b/src/main/java/net/enderkitty/mixin/BackgroundRendererMixin.java index fe47337..a09973f 100644 --- a/src/main/java/net/enderkitty/mixin/BackgroundRendererMixin.java +++ b/src/main/java/net/enderkitty/mixin/BackgroundRendererMixin.java @@ -7,6 +7,7 @@ import net.minecraft.client.render.BackgroundRenderer; import net.minecraft.client.render.Camera; import net.minecraft.entity.Entity; +import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -24,6 +25,19 @@ private static boolean applyFog(Entity entity) { return config.renderLavaFog == FireHudConfig.LavaFogOptions.LIGHT_FOG; } + @Redirect(method = "applyFog", at = @At(value = "FIELD", target = "Lnet/minecraft/client/render/BackgroundRenderer$FogData;fogEnd:F", ordinal = 0, opcode = Opcodes.PUTFIELD)) + private static void viewDistFogEndFix(BackgroundRenderer.FogData fogData, float value) { + if (config.renderLavaFog == FireHudConfig.LavaFogOptions.LIGHT_FOG) { + fogData.fogEnd = config.lightFogDist; + } + } + @Redirect(method = "applyFog", at = @At(value = "FIELD", target = "Lnet/minecraft/client/render/BackgroundRenderer$FogData;fogStart:F", ordinal = 0, opcode = Opcodes.PUTFIELD)) + private static void viewDistFogStartFix(BackgroundRenderer.FogData fogData, float value) { + if (config.renderLavaFog == FireHudConfig.LavaFogOptions.LIGHT_FOG) { + fogData.fogStart = 0; + } + } + @Inject(method = "applyFog", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;isSpectator()Z", ordinal = 0, shift = At.Shift.BEFORE), cancellable = true) private static void applyFog(Camera camera, BackgroundRenderer.FogType fogType, float viewDistance, boolean thickFog, float tickDelta, CallbackInfo ci) { diff --git a/src/main/java/net/enderkitty/mixin/ClientEntityMixin.java b/src/main/java/net/enderkitty/mixin/ClientEntityMixin.java index f9efd06..71ec74e 100644 --- a/src/main/java/net/enderkitty/mixin/ClientEntityMixin.java +++ b/src/main/java/net/enderkitty/mixin/ClientEntityMixin.java @@ -13,12 +13,12 @@ public class ClientEntityMixin implements SoulFireAccessor { @Unique private boolean renderSoulFire; @Override - public boolean isRenderSoulFire() { + public boolean fireHud$isRenderSoulFire() { return renderSoulFire; } @Override - public void setRenderSoulFire(boolean renderSoulFire) { + public void fireHud$setRenderSoulFire(boolean renderSoulFire) { this.renderSoulFire = renderSoulFire; } } diff --git a/src/main/java/net/enderkitty/mixin/ClientPlayNetworkHandlerMixin.java b/src/main/java/net/enderkitty/mixin/ClientPlayNetworkHandlerMixin.java index 22e00b4..0361525 100644 --- a/src/main/java/net/enderkitty/mixin/ClientPlayNetworkHandlerMixin.java +++ b/src/main/java/net/enderkitty/mixin/ClientPlayNetworkHandlerMixin.java @@ -32,17 +32,17 @@ public class ClientPlayNetworkHandlerMixin { @Inject(method = "onEntityDamage", at = @At("HEAD")) public void entitySetsOnSoulFire(EntityDamageS2CPacket packet, CallbackInfo ci) { - if (FireHud.getConfig().renderSoulFire) { + if (world != null && FireHud.getConfig().renderSoulFire) { Entity targetEntity = world.getEntityById(packet.entityId()); Entity sourceEntity = world.getEntityById(packet.sourceDirectId()); if (targetEntity != null && sourceEntity != null) { if ((sourceEntity instanceof ZombieEntity || sourceEntity instanceof ArrowEntity) && sourceEntity.doesRenderOnFire()) { - ((SoulFireAccessor) targetEntity).setRenderSoulFire(((SoulFireAccessor) sourceEntity).isRenderSoulFire()); + ((SoulFireAccessor) targetEntity).fireHud$setRenderSoulFire(((SoulFireAccessor) sourceEntity).fireHud$isRenderSoulFire()); } } if (targetEntity != null) { if (packet.createDamageSource(world).isOf(DamageTypes.LIGHTNING_BOLT)) { - ((SoulFireAccessor) targetEntity).setRenderSoulFire(false); + ((SoulFireAccessor) targetEntity).fireHud$setRenderSoulFire(false); } } } @@ -55,7 +55,7 @@ public void clientTickEvents(CallbackInfo ci) { Box box = entity.getBoundingBox(); BlockPos blockPos = new BlockPos(MathHelper.floor(box.minX + 0.001), MathHelper.floor(box.minY + 0.001), MathHelper.floor(box.minZ + 0.001)); BlockPos blockPos2 = new BlockPos(MathHelper.floor(box.maxX - 0.001), MathHelper.floor(box.maxY - 0.001), MathHelper.floor(box.maxZ - 0.001)); - if (entity.getWorld().isRegionLoaded(blockPos, blockPos2)) { + if (entity.getWorld() != null && entity.getWorld().isRegionLoaded(blockPos, blockPos2)) { BlockPos.Mutable mutable = new BlockPos.Mutable(); for (int i = blockPos.getX(); i <= blockPos2.getX(); ++i) { for (int j = blockPos.getY(); j <= blockPos2.getY(); ++j) { @@ -63,9 +63,9 @@ public void clientTickEvents(CallbackInfo ci) { mutable.set(i, j, k); try { Block block = entity.getWorld().getBlockState(mutable).getBlock(); - if (block instanceof SoulFireBlock) ((SoulFireAccessor)entity).setRenderSoulFire(true); - if (block instanceof FireBlock) ((SoulFireAccessor)entity).setRenderSoulFire(false); - if (entity.isInLava()) ((SoulFireAccessor)entity).setRenderSoulFire(false); + if (block instanceof SoulFireBlock) ((SoulFireAccessor)entity).fireHud$setRenderSoulFire(true); + if (block instanceof FireBlock) ((SoulFireAccessor)entity).fireHud$setRenderSoulFire(false); + if (entity.isInLava()) ((SoulFireAccessor)entity).fireHud$setRenderSoulFire(false); } catch (Throwable throwable) { CrashReport crashReport = CrashReport.create(throwable, "Colliding entity with block"); throw new CrashException(crashReport); diff --git a/src/main/java/net/enderkitty/mixin/EntityRendererDispatcherMixin.java b/src/main/java/net/enderkitty/mixin/EntityRendererDispatcherMixin.java index 352059f..d51803d 100644 --- a/src/main/java/net/enderkitty/mixin/EntityRendererDispatcherMixin.java +++ b/src/main/java/net/enderkitty/mixin/EntityRendererDispatcherMixin.java @@ -43,7 +43,7 @@ private void renderThirdPersonFire(MatrixStack matrices, VertexConsumerProvider @Redirect(method = "renderFire", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/SpriteIdentifier;getSprite()Lnet/minecraft/client/texture/Sprite;", ordinal = 0)) private Sprite getSprite0(SpriteIdentifier obj, MatrixStack matrices, VertexConsumerProvider vertexConsumers, Entity entity) { - if (config.renderSoulFire && ((SoulFireAccessor) entity).isRenderSoulFire()) { + if (config.renderSoulFire && ((SoulFireAccessor) entity).fireHud$isRenderSoulFire()) { return SOUL_FIRE_0.getSprite(); } return obj.getSprite(); @@ -51,7 +51,7 @@ private Sprite getSprite0(SpriteIdentifier obj, MatrixStack matrices, VertexCons @Redirect(method = "renderFire", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/SpriteIdentifier;getSprite()Lnet/minecraft/client/texture/Sprite;", ordinal = 1)) private Sprite getSprite1(SpriteIdentifier obj, MatrixStack matrices, VertexConsumerProvider vertexConsumers, Entity entity) { - if (config.renderSoulFire && ((SoulFireAccessor) entity).isRenderSoulFire()) { + if (config.renderSoulFire && ((SoulFireAccessor) entity).fireHud$isRenderSoulFire()) { return SOUL_FIRE_1.getSprite(); } return obj.getSprite(); diff --git a/src/main/java/net/enderkitty/mixin/InGameHudMixin.java b/src/main/java/net/enderkitty/mixin/InGameHudMixin.java index 2c256ee..bac3f1a 100644 --- a/src/main/java/net/enderkitty/mixin/InGameHudMixin.java +++ b/src/main/java/net/enderkitty/mixin/InGameHudMixin.java @@ -59,7 +59,7 @@ private void drawHeart(DrawContext context, InGameHud.HeartType type, int x, int ci.cancel(); } if (config.renderSoulFire) { - if ((playerEntity.isOnFire() && ((SoulFireAccessor) playerEntity).isRenderSoulFire()) || + if ((playerEntity.isOnFire() && ((SoulFireAccessor) playerEntity).fireHud$isRenderSoulFire()) || (!EnchantmentHelper.hasFrostWalker(playerEntity) && playerEntity.getSteppingBlockState().getBlock() == Blocks.SOUL_CAMPFIRE)) { context.drawGuiTexture(getSoulFireHeartTexture(hardcore, half, blinking), x, y, 9, 9); @@ -76,7 +76,7 @@ private void render(DrawContext context, float tickDelta, CallbackInfo ci) { MinecraftClient client = MinecraftClient.getInstance(); PlayerEntity player = client.player; - Identifier texture = player != null && ((SoulFireAccessor) player).isRenderSoulFire() ? SOUL_FIRE_VIGNETTE : FIRE_VIGNETTE; + Identifier texture = player != null && ((SoulFireAccessor) player).fireHud$isRenderSoulFire() ? SOUL_FIRE_VIGNETTE : FIRE_VIGNETTE; int hudScale = config.vignetteScale; int width = context.getScaledWindowWidth(); int height = context.getScaledWindowHeight(); diff --git a/src/main/java/net/enderkitty/mixin/InGameOverlayRendererMixin.java b/src/main/java/net/enderkitty/mixin/InGameOverlayRendererMixin.java index acf7b84..8093c69 100644 --- a/src/main/java/net/enderkitty/mixin/InGameOverlayRendererMixin.java +++ b/src/main/java/net/enderkitty/mixin/InGameOverlayRendererMixin.java @@ -63,7 +63,7 @@ private static float firePos(float y) { @Redirect(method = "renderFireOverlay", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/SpriteIdentifier;getSprite()Lnet/minecraft/client/texture/Sprite;")) private static Sprite getSprite(SpriteIdentifier obj, MinecraftClient client) { - if (config.renderSoulFire && ((SoulFireAccessor) client.player).isRenderSoulFire()) return SOUL_FIRE_1.getSprite(); + if (config.renderSoulFire && ((SoulFireAccessor) client.player).fireHud$isRenderSoulFire()) return SOUL_FIRE_1.getSprite(); return obj.getSprite(); } @@ -75,7 +75,7 @@ private static void renderSideFireOverlay(MinecraftClient client, MatrixStack ma RenderSystem.depthFunc(519); RenderSystem.depthMask(false); RenderSystem.enableBlend(); - Sprite sprite = (config.renderSoulFire && ((SoulFireAccessor) client.player).isRenderSoulFire() ? SOUL_FIRE_1.getSprite() : ModelLoader.FIRE_1.getSprite()); + Sprite sprite = (config.renderSoulFire && ((SoulFireAccessor) client.player).fireHud$isRenderSoulFire() ? SOUL_FIRE_1.getSprite() : ModelLoader.FIRE_1.getSprite()); RenderSystem.setShaderTexture(0, sprite.getAtlasId()); float f = sprite.getMinU(); float g = sprite.getMaxU(); diff --git a/src/main/resources/assets/firehud/lang/en_us.json b/src/main/resources/assets/firehud/lang/en_us.json index 130bc61..f68c6ab 100644 --- a/src/main/resources/assets/firehud/lang/en_us.json +++ b/src/main/resources/assets/firehud/lang/en_us.json @@ -48,6 +48,8 @@ "text.autoconfig.firehud.option.renderThirdPersonFireInLava": "Third Person Fire In Lava", "text.autoconfig.firehud.option.renderLavaFog.@Tooltip": "Toggles rendering the fog effect when in lava, making it easier to see", "text.autoconfig.firehud.option.renderLavaFog": "Render Lava Fog", + "text.autoconfig.firehud.option.lightFogDist.@Tooltip": "The view distance when in lava with Render Lava Fog set to LIGHT_FOG", + "text.autoconfig.firehud.option.lightFogDist": "Light Fog Distance", "text.autoconfig.firehud.option.renderWithFireResistance.@PrefixText": "Fire Resistance", "text.autoconfig.firehud.option.renderWithFireResistance.@Tooltip": "Toggles rendering the hud when under the Fire Resistance status effect", diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 183caa4..6acff03 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -3,9 +3,13 @@ "id": "firehud", "version": "${version}", "name": "Fire Hud", - "description": "Redesigns the visuals of being set on fire to be less intrusive", + "description": "Redesigns the visuals of being set on fire to be highly configurable and less intrusive", "authors": [ "LordEnder_Kitty" ], - "contact": {}, + "contact": { + "curseforge": "https://www.curseforge.com/minecraft/mc-mods/firehud", + "modrinth": "https://modrinth.com/mod/firehud", + "github": "https://github.com/LordEnder-Kitty/FireHud" + }, "license": "MIT", "icon": "assets/firehud/icon.png", "environment": "client", @@ -14,7 +18,7 @@ "modmenu": [ "net.enderkitty.config.ModMenuImpl" ] }, "mixins": [ "firehud.mixins.json" ], - "accessWidener" : "firehud.accesswidener", + "accessWidener": "firehud.accesswidener", "depends": { "fabricloader": ">=0.15.9", "minecraft": [ diff --git a/src/main/resources/firehud.accesswidener b/src/main/resources/firehud.accesswidener index 90d2ce4..f7b47d0 100644 --- a/src/main/resources/firehud.accesswidener +++ b/src/main/resources/firehud.accesswidener @@ -1,3 +1,4 @@ accessWidener v1 named -accessible class net/minecraft/client/gui/hud/InGameHud$HeartType \ No newline at end of file +accessible class net/minecraft/client/gui/hud/InGameHud$HeartType +accessible class net/minecraft/client/render/BackgroundRenderer$FogData