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 c08699a commit 6981b54
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 27 deletions.
2 changes: 1 addition & 1 deletion 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
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 (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);
}
}
}
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 @@ -43,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
10 changes: 7 additions & 3 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 All @@ -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": [
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 6981b54

Please sign in to comment.