Skip to content

Commit

Permalink
Merge pull request #4 from LordEnder-Kitty/master
Browse files Browse the repository at this point in the history
1.2-1.21 pull
  • Loading branch information
LordEnder-Kitty authored Jul 2, 2024
2 parents 10b1697 + 751bcdb commit 92b9adf
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 28 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.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ yarn_mappings=1.21+build.4
loader_version=0.15.11

# Mod Properties
mod_version=1.1.1-1.21
mod_version=1.2-1.21
maven_group=net.enderkitty
archives_base_name=firehud

Expand Down
14 changes: 14 additions & 0 deletions src/main/java/net/enderkitty/EnchantTags.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net.enderkitty;

import net.minecraft.enchantment.Enchantment;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.util.Identifier;

public interface EnchantTags {
TagKey<Enchantment> FROST_WALKER = EnchantTags.of("prevents_fire_hearts");

private static TagKey<Enchantment> of(String id) {
return TagKey.of(RegistryKeys.ENCHANTMENT, Identifier.of(FireHud.MOD_ID, id));
}
}
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
17 changes: 11 additions & 6 deletions src/main/java/net/enderkitty/mixin/InGameHudMixin.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.enderkitty.mixin;

import com.mojang.blaze3d.systems.RenderSystem;
import net.enderkitty.EnchantTags;
import net.enderkitty.FireHud;
import net.enderkitty.SoulFireAccessor;
import net.enderkitty.config.FireHudConfig;
Expand All @@ -11,12 +12,14 @@
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.hud.InGameHud;
import net.minecraft.client.render.RenderTickCounter;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
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;
Expand All @@ -25,6 +28,7 @@
@Environment(EnvType.CLIENT)
@Mixin(InGameHud.class)
public abstract class InGameHudMixin {
@Shadow private ItemStack currentStack;
@Unique private static final Identifier FIRE_VIGNETTE = Identifier.of(FireHud.MOD_ID, "textures/fire/fire_vignette.png");
@Unique private static final Identifier SOUL_FIRE_VIGNETTE = Identifier.of(FireHud.MOD_ID, "textures/fire/soul_fire_vignette.png");

Expand Down Expand Up @@ -53,14 +57,15 @@ public abstract class InGameHudMixin {
private void drawHeart(DrawContext context, InGameHud.HeartType type, int x, int y, boolean hardcore, boolean blinking, boolean half, CallbackInfo ci) {
if (MinecraftClient.getInstance().cameraEntity instanceof PlayerEntity playerEntity && !(!config.renderWithFireResistance && playerEntity.hasStatusEffect(StatusEffects.FIRE_RESISTANCE))) {
if (config.renderFireHearts && type == InGameHud.HeartType.NORMAL) {
if (playerEntity.isOnFire() || ((playerEntity.getSteppingBlockState().getBlock() == Blocks.MAGMA_BLOCK && !playerEntity.bypassesSteppingEffects()) ||
playerEntity.getSteppingBlockState().getBlock() == Blocks.CAMPFIRE)) {

boolean hasFrostWalkerOnBoots = EnchantmentHelper.hasAnyEnchantmentsIn(playerEntity.getEquippedStack(EquipmentSlot.FEET), EnchantTags.FROST_WALKER);

if (playerEntity.isOnFire() || (!hasFrostWalkerOnBoots && ((playerEntity.getSteppingBlockState().getBlock() == Blocks.MAGMA_BLOCK && !playerEntity.bypassesSteppingEffects()) ||
playerEntity.getSteppingBlockState().getBlock() == Blocks.CAMPFIRE))) {
context.drawGuiTexture(getFireHeartTexture(hardcore, half, blinking), x, y, 9, 9);
ci.cancel();
}
if (config.renderSoulFire) {
if ((playerEntity.isOnFire() && ((SoulFireAccessor) playerEntity).isRenderSoulFire()) || playerEntity.getSteppingBlockState().getBlock() == Blocks.SOUL_CAMPFIRE) {
if ((playerEntity.isOnFire() && ((SoulFireAccessor) playerEntity).fireHud$isRenderSoulFire()) || (!hasFrostWalkerOnBoots && playerEntity.getSteppingBlockState().getBlock() == Blocks.SOUL_CAMPFIRE)) {
context.drawGuiTexture(getSoulFireHeartTexture(hardcore, half, blinking), x, y, 9, 9);
ci.cancel();
}
Expand All @@ -75,7 +80,7 @@ private void render(DrawContext context, RenderTickCounter tickCounter, Callback
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 && client.player != null && ((SoulFireAccessor) client.player).fireHud$isRenderSoulFire()) return SOUL_FIRE_1.getSprite();
return obj.getSprite();
}

Expand All @@ -74,7 +74,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 && client.player != null && ((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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"minecraft:frost_walker"
]
}
4 changes: 2 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"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": {
"curseforge": "https://www.curseforge.com/minecraft/mc-mods/firehud",
Expand All @@ -22,7 +22,7 @@
"depends": {
"fabricloader": ">=0.15.9",
"minecraft": "~1.21",
"java": ">=17",
"java": ">=21",
"fabric-api": "*",
"cloth-config2": "*"
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/firehud.accesswidener
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
accessWidener v1 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 92b9adf

Please sign in to comment.