Added a breathing grace period after exiting breathable area or dying

This commit is contained in:
Unknown 2019-08-24 16:20:58 +02:00 committed by unknown
parent 610bc4ddff
commit 50cb3117f4
2 changed files with 29 additions and 8 deletions

View file

@ -112,9 +112,8 @@ public class BreathingManager {
}
final boolean notInVacuum = vAirBlock != null;
Integer air;
Integer air = entity_airBlock.get(uuidEntity);
if (notInVacuum) {// no atmosphere with air blocks
air = entity_airBlock.get(uuidEntity);
if (air == null) {
entity_airBlock.put(uuidEntity, AIR_BLOCK_TICKS);
} else if (air <= 1) {// time elapsed => consume air block
@ -124,15 +123,23 @@ public class BreathingManager {
}
} else {// no atmosphere without air blocks
// finish air from blocks
air = entity_airBlock.get(uuidEntity);
if (air != null && air > 0) {
entity_airBlock.put(uuidEntity, air - 1);
return;
} else if (air == null) {
// add grace period on first breath
if (air == null) {
entity_airBlock.put(uuidEntity, AIR_FIRST_BREATH_TICKS);
return;
}
// players have a grace period when exiting breathable area
// others just finish air from blocks
if (air > 0) {
if (entityLivingBase instanceof EntityPlayerMP) {
entity_airBlock.put(uuidEntity, 0);
player_airTank.put(uuidEntity, AIR_FIRST_BREATH_TICKS);
return;
} else {
entity_airBlock.put(uuidEntity, air - 1);
return;
}
}
// damage entity if in vacuum without protection
final boolean hasValidSetup = hasValidSetup(entityLivingBase);
@ -460,4 +467,8 @@ public class BreathingManager {
// first air breath is free
return airCanister.getAirTicksPerConsumption(itemStackAirCanister);
}
public static void onEntityLivingDeath(@Nonnull final EntityLivingBase entityLivingBase) {
entity_airBlock.remove(entityLivingBase.getUniqueID());
}
}

View file

@ -34,8 +34,10 @@ import net.minecraft.world.WorldServer;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.event.entity.living.EnderTeleportEvent;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
import net.minecraftforge.event.entity.living.LivingFallEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class LivingHandler {
@ -348,4 +350,12 @@ public class LivingHandler {
}
}
}
@SubscribeEvent(priority = EventPriority.LOWEST)
void onLivingDeath(@Nonnull final LivingDeathEvent event) {
final EntityLivingBase entityLivingBase = event.getEntityLiving();
if (entityLivingBase != null) {
BreathingManager.onEntityLivingDeath(entityLivingBase);
}
}
}