ExtraPlanets icon indicating copy to clipboard operation
ExtraPlanets copied to clipboard

add breathing underwater feature.

Open samuk190 opened this issue 4 years ago • 2 comments

As the mod author of galacticraft don't want to include this simple feature since 2013, I'm requesting here.
"with equipped gas mask and water gear. Simply consume oxygen and let stay underwater. "

This will also allow creation of aquactic planets.

samuk190 avatar Feb 10 '21 12:02 samuk190

Related: https://github.com/MJRLegends/ExtraPlanets/issues/525

LukeShortCloud avatar Apr 21 '23 05:04 LukeShortCloud

@MJRLegends Thanks for all of your incredibly hard work! ExtraPlanets really helps to make the Galacticraft experience new and exciting again.

Here are my initial thoughts about implementing underwater breathing. This could be implemented by checking every tick if (1) the player is underwater and (2) if valid oxygen equipment is equipped. Then drain the oxygen tank as if the player was on another planet (in the case of the Overworld) and apply the water breathing effect.

I'm no Java or Forge expert but, as a starting point, similar logic to this can be used to detect if a player is swimming in water.

public static boolean isPlayerUnderwater(EntityPlayer player) {
    BlockPos playerPos = new BlockPos(player.posX, player.posY + player.getEyeHeight(), player.posZ);
    IBlockState blockState = player.world.getBlockState(playerPos);
    Material material = blockState.getMaterial();
    return material.isLiquid() && player.isInsideOfMaterial(material);
}

Then apply the water breathing potion for a single tick as long as the oxygen equipment is valid and a tank still has oxygen in it.

public static void applyWaterBreathingEffect(EntityPlayer player) {
    Potion waterBreathingPotion = MobEffects.WATER_BREATHING;
    int waterBreathingDuration = 1;
    player.addPotionEffect(new PotionEffect(waterBreathingPotion, waterBreathingDuration));
}

Disclaimer: this code was generated by ChatGPT. I would advise not copying and pasting any of this but, instead, using it as inspiration for a starting point.

LukeShortCloud avatar Apr 21 '23 05:04 LukeShortCloud