Skip to content

Commit

Permalink
Fixed bugs, cleaned up code, general improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
LordEnder-Kitty committed Jul 2, 2024
1 parent 99658c5 commit 14cd115
Show file tree
Hide file tree
Showing 17 changed files with 78 additions and 33 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# FireHud

This is a client only mod which provides more settings than you'll ever need to customize the onscreen effect when on fire.

**Everything is on vanilla settings by default**

The config, made using [Cloth Config](https://modrinth.com/mod/cloth-config), is accessable through either [ModMenu](https://modrinth.com/mod/modmenu) or, I have added a button in the game options beside the videos settings button. This button is toggleable and you may move it around as well.

This mod was made as a passion project after I went netherite mining and remembered how annoying fire was.

You may also adjust the volume and pitch of fire blocks in the config.

Believe me when I say I have really gone overkill on customization. Chances are that I'll also add more features in the future. If you have any good ideas for additions to this mod, don't hesitate to go to the issues page on the github and make a suggestion. I will most likely read it and consider it.

Some features of note:
- Adjusting the position of vanilla fire.
- Adjusting the opactity of vanilla fire.
- Disabling vanilla fire entirely.
- Enabling other customizable redesigns of the hud.
- Adjusting the in-lava fog. Making it easier to see under lava.
- Player ignites on soul fire rather than normal, orange fire when in soul fire.
- And many other useful, but completely optional features.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'fabric-loom' version '1.7-SNAPSHOT'
id 'maven-publish'
}

Expand Down Expand Up @@ -40,14 +40,14 @@ processResources {
}

tasks.withType(JavaCompile).configureEach {
it.options.release = 17
it.options.release = 21
}

java {
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}

jar {
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ org.gradle.parallel=true
# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.6
yarn_mappings=1.20.6+build.1
yarn_mappings=1.20.6+build.3
loader_version=0.15.11

# Mod Properties
mod_version=1.1.0-1.20.5-6
mod_version=1.2-1.20.5-6
maven_group=net.enderkitty
archives_base_name=firehud

# Dependencies
fabric_version=0.98.0+1.20.6
fabric_version=0.100.4+1.20.6
cloth_config_version=14.0.126
modmenu_version=10.0.0-beta.1
modmenu_version=10.0.0
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Empty file modified gradlew
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions src/main/java/net/enderkitty/FireHud.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/enderkitty/SoulFireAccessor.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.enderkitty;

public interface SoulFireAccessor {
boolean isRenderSoulFire();
void setRenderSoulFire(boolean renderSoulFire);
boolean fireHud$isRenderSoulFire();
void fireHud$setRenderSoulFire(boolean renderSoulFire);
}
3 changes: 3 additions & 0 deletions src/main/java/net/enderkitty/config/FireHudConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/net/enderkitty/mixin/BackgroundRendererMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/enderkitty/mixin/ClientEntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 (FireHud.getConfig().renderSoulFire && world != null) {
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);
}
}
}
Expand All @@ -55,17 +55,17 @@ 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) {
for (int k = blockPos.getZ(); k <= blockPos2.getZ(); ++k) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.screen.PlayerScreenHandler;
import net.minecraft.util.Identifier;
Expand Down Expand Up @@ -44,15 +43,15 @@ 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();
}

@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();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/enderkitty/mixin/InGameHudMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/firehud/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 6 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions src/main/resources/firehud.accesswidener
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
accessWidener v1 named
accessWidener v2 named

accessible class net/minecraft/client/gui/hud/InGameHud$HeartType
accessible class net/minecraft/client/gui/hud/InGameHud$HeartType
accessible class net/minecraft/client/render/BackgroundRenderer$FogData

0 comments on commit 14cd115

Please sign in to comment.