Skip to content

Commit

Permalink
fix deprecated DivingSuitOverlay use
Browse files Browse the repository at this point in the history
  • Loading branch information
ktpatient committed Dec 7, 2024
1 parent 876881d commit b095308
Showing 1 changed file with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mojang.blaze3d.systems.RenderSystem;
import com.portingdeadmods.nautec.Nautec;
import com.portingdeadmods.nautec.data.NTDataComponentsUtils;
import com.portingdeadmods.nautec.registries.NTFluidTypes;
import com.portingdeadmods.nautec.registries.NTItems;
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.Minecraft;
Expand All @@ -13,23 +14,28 @@
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.material.Fluids;
import net.neoforged.neoforge.fluids.FluidType;
import org.jetbrains.annotations.NotNull;


public final class DivingSuitOverlay {
private static final ResourceLocation OXYGEN_SPRITE = ResourceLocation.fromNamespaceAndPath(Nautec.MODID,"hud/oxygen");
private static final ResourceLocation OXYGEN_BURSTING_SPRITE = ResourceLocation.fromNamespaceAndPath(Nautec.MODID,"hud/oxygen_bursting");
private static final ResourceLocation OXYGEN_EMPTY_SPRITE = ResourceLocation.fromNamespaceAndPath(Nautec.MODID,"hud/oxygen_empty");

private static int burstingTicks = 0;

private static boolean isWearingFullDivingSuit(Player player) {
private static boolean isWearingFullDivingSuit(@NotNull Player player) {
return player.getItemBySlot(EquipmentSlot.HEAD).is(NTItems.DIVING_HELMET) &&
player.getItemBySlot(EquipmentSlot.CHEST).is(NTItems.DIVING_CHESTPLATE) &&
player.getItemBySlot(EquipmentSlot.LEGS).is(NTItems.DIVING_LEGGINGS) &&
player.getItemBySlot(EquipmentSlot.FEET).is(NTItems.DIVING_BOOTS);
}

public static void render(GuiGraphics guiGraphics, DeltaTracker deltaTracker) {
int rightHeight = 59;
int rightOffset = 59;
int maxOxygen = 600;
int spriteSize = 9;

Player player = Minecraft.getInstance().player;
if (player == null) return;

Expand All @@ -38,26 +44,22 @@ public static void render(GuiGraphics guiGraphics, DeltaTracker deltaTracker) {
return;
}

int i1 = guiGraphics.guiWidth() / 2 + 91;
int xBase = guiGraphics.guiWidth() / 2 + 91;
int yBase = guiGraphics.guiHeight() - rightOffset;
int visibleOxygen = Math.min(oxygenLevels, maxOxygen);
int fullBubbles = Mth.ceil((double)(visibleOxygen - 2) * 10.0 / maxOxygen);
int burstingBubbles = Mth.ceil((double)visibleOxygen * 10.0 / maxOxygen) - fullBubbles;

int i3 = 600;
int j3 = Math.min(oxygenLevels, i3);
if (player.isEyeInFluid(FluidTags.WATER) || j3 < i3) {
int j2 = guiGraphics.guiHeight() - rightHeight;
int l3 = Mth.ceil((double)(j3 - 2) * 10.0 / (double)i3);
int i4 = Mth.ceil((double)j3 * 10.0 / (double)i3) - l3;
RenderSystem.enableBlend();

for (int j4 = 0; j4 < l3 + i4; j4++) {
if (j4 < l3) {
guiGraphics.blitSprite(OXYGEN_SPRITE, i1 - j4 * 8 - 9, j2, 9, 9);
} else {
guiGraphics.blitSprite(OXYGEN_BURSTING_SPRITE, i1 - j4 * 8 - 9, j2, 9, 9);
}
if (player.isEyeInFluidType(Fluids.WATER.getFluidType()) || visibleOxygen < maxOxygen) {
RenderSystem.enableBlend();
for (int i = 0; i < fullBubbles + burstingBubbles; i++) {
boolean isBursting = i >= fullBubbles;
guiGraphics.blitSprite(isBursting ? OXYGEN_BURSTING_SPRITE : OXYGEN_SPRITE,
xBase - i * spriteSize - spriteSize,
yBase, spriteSize, spriteSize);
}

RenderSystem.disableBlend();
rightHeight += 10;
}

}
Expand Down

0 comments on commit b095308

Please sign in to comment.