diff --git a/src/main/java/micdoodle8/mods/galacticraft/core/entities/player/GCPlayerHandler.java b/src/main/java/micdoodle8/mods/galacticraft/core/entities/player/GCPlayerHandler.java index fa963bee51..49ba54d3b3 100644 --- a/src/main/java/micdoodle8/mods/galacticraft/core/entities/player/GCPlayerHandler.java +++ b/src/main/java/micdoodle8/mods/galacticraft/core/entities/player/GCPlayerHandler.java @@ -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) { diff --git a/src/main/java/micdoodle8/mods/galacticraft/core/util/OxygenUtil.java b/src/main/java/micdoodle8/mods/galacticraft/core/util/OxygenUtil.java index 55343f5e33..3df89801c9 100644 --- a/src/main/java/micdoodle8/mods/galacticraft/core/util/OxygenUtil.java +++ b/src/main/java/micdoodle8/mods/galacticraft/core/util/OxygenUtil.java @@ -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; @@ -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); + } + } + } + } }