Skip to content

Commit

Permalink
Breathing underwater (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
mak8427 authored Jan 21, 2025
1 parent c6b2f37 commit b0fd67b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
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);
}
}
}
}
}

0 comments on commit b0fd67b

Please sign in to comment.