Skip to content
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

Breathing underwater #101

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
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 @@ -998,6 +998,7 @@ public void onPlayerUpdate(EntityPlayerMP player) {

// This will speed things up a little
final GCPlayerStats GCPlayer = GCPlayerStats.get(player);
OxygenUtil.applyWaterBreathingEffect(player);

if (ConfigManagerCore.challengeSpawnHandling && GCPlayer.unlockedSchematics.size() == 0) {
if (GCPlayer.startDimension.length() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
Expand Down Expand Up @@ -423,4 +425,34 @@ public static boolean inOxygenBubble(World worldObj, double avgX, double avgY, d

return false;
}

/**
* Applies the water breathing effect to the player if they are in water and have the oxygen gear. Consumes oxygen
* from the player's oxygen tanks.
*
* @param player The player to check and apply the effect to.
*/
public static void applyWaterBreathingEffect(EntityPlayerMP player) {
// Check if the player is in water
if (player.isInWater()) {
// Check if the player has valid oxygen gear setup
if (hasValidOxygenSetup(player)) {
// Apply the water breathing effect
player.addPotionEffect(new PotionEffect(Potion.waterBreathing.id, 220, 0, true));

// Consume oxygen
GCPlayerStats stats = GCPlayerStats.get(player);
ItemStack tankInSlot1 = stats.extendedInventory.getStackInSlot(2);
ItemStack tankInSlot2 = stats.extendedInventory.getStackInSlot(3);

if (tankInSlot1 != null && tankInSlot1.getItem() instanceof ItemOxygenTank
&& tankInSlot1.getMaxDamage() - tankInSlot1.getItemDamage() > 0) {
tankInSlot1.damageItem(1, player);
} else if (tankInSlot2 != null && tankInSlot2.getItem() instanceof ItemOxygenTank
&& tankInSlot2.getMaxDamage() - tankInSlot2.getItemDamage() > 0) {
tankInSlot2.damageItem(1, player);
}
}
}
}
}