Skip to content

Commit

Permalink
fix: turtle helmet wearing
Browse files Browse the repository at this point in the history
  • Loading branch information
sakura-ryoko committed Sep 13, 2024
1 parent 51615eb commit a881371
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ author = masa
mod_file_name = malilib-fabric

# Current mod version
mod_version = 0.20.3-sakura.1
mod_version = 0.20.3-sakura.2

# Minecraft, Fabric Loader and API and mappings versions
minecraft_version_out = 1.21
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/fi/dy/masa/malilib/render/RenderUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ public static int getHudOffsetForPotions(HudAlignment alignment, double scale, P
}

Collection<StatusEffectInstance> effects = player.getStatusEffects();
boolean hasTurtleHelmet = EntityUtils.hasTurtleHelmetEquipped(player);
// Turtle Helmets only add their status effects when in water

if (effects.isEmpty() == false)
{
Expand All @@ -493,8 +495,17 @@ public static int getHudOffsetForPotions(HudAlignment alignment, double scale, P
}
}

if (hasTurtleHelmet && y1 == 0)
{
y1 = 26;
}

return (int) (Math.max(y1, y2) / scale);
}
else if (hasTurtleHelmet)
{
return (int) ((int) 26 / scale);
}
}

return 0;
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/fi/dy/masa/malilib/util/EntityUtils.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package fi.dy.masa.malilib.util;

import javax.annotation.Nullable;

import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;

public class EntityUtils
{
Expand All @@ -23,4 +28,21 @@ public static Entity getCameraEntity()

return entity;
}

/**
* Returns weather or not the Entity has a Turtle Helmet equipped
* @param player (The Player)
* @return (True/False)
*/
public static boolean hasTurtleHelmetEquipped(PlayerEntity player)
{
if (player == null)
{
return false;
}

ItemStack stack = player.getEquippedStack(EquipmentSlot.HEAD);

return !stack.isEmpty() && stack.isOf(Items.TURTLE_HELMET);
}
}

0 comments on commit a881371

Please sign in to comment.