Skip to content

Some RemainingAirOverlay logic moved to an EventBusSubscriber #8723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: mc1.20.1/dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.mojang.blaze3d.vertex.PoseStack;
import com.simibubi.create.AllItems;

import com.simibubi.create.Create;

import net.createmod.catnip.gui.element.GuiGameElement;
import net.createmod.catnip.theme.Color;
import net.minecraft.client.Minecraft;
Expand All @@ -17,12 +19,19 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.block.Blocks;
import net.minecraftforge.api.distmarker.Dist;

import net.minecraftforge.client.gui.overlay.ForgeGui;
import net.minecraftforge.client.gui.overlay.IGuiOverlay;
import net.minecraftforge.event.entity.living.LivingBreatheEvent;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE, modid = Create.ID, value = Dist.CLIENT)
public class RemainingAirOverlay implements IGuiOverlay {
public static final RemainingAirOverlay INSTANCE = new RemainingAirOverlay();
private static boolean canBreathe = true;

@Override
public void render(ForgeGui gui, GuiGraphics graphics, float partialTick, int width, int height) {
Expand All @@ -38,9 +47,7 @@ public void render(ForgeGui gui, GuiGraphics graphics, float partialTick, int wi
if (!player.getPersistentData()
.contains("VisualBacktankAir"))
return;
boolean isAir = player.getEyeInFluidType().isAir() || player.level().getBlockState(BlockPos.containing(player.getX(), player.getEyeY(), player.getZ())).is(Blocks.BUBBLE_COLUMN);
boolean canBreathe = !player.canDrownInFluidType(player.getEyeInFluidType()) || MobEffectUtil.hasWaterBreathing(player) || player.getAbilities().invulnerable;
if ((isAir || canBreathe) && !player.isInLava())
if (canBreathe && !player.isInLava())
return;

int timeLeft = player.getPersistentData()
Expand Down Expand Up @@ -73,4 +80,9 @@ public static ItemStack getDisplayedBacktank(LocalPlayer player) {
}
return AllItems.COPPER_BACKTANK.asStack();
}

@SubscribeEvent(priority = EventPriority.LOWEST)
public static void onLivingBreathe(LivingBreatheEvent event) {
canBreathe = event.canBreathe() || event.canRefillAir();
}
}