Search in sources :

Example 1 with GCCoreOxygenSuffocationEvent

use of micdoodle8.mods.galacticraft.api.event.oxygen.GCCoreOxygenSuffocationEvent in project Galacticraft by micdoodle8.

the class EventHandlerGC method entityLivingEvent.

@SubscribeEvent
public void entityLivingEvent(LivingUpdateEvent event) {
    final EntityLivingBase entityLiving = event.entityLiving;
    if (entityLiving instanceof EntityPlayerMP) {
        GalacticraftCore.handler.onPlayerUpdate((EntityPlayerMP) entityLiving);
        if (GalacticraftCore.isPlanetsLoaded) {
            AsteroidsModule.playerHandler.onPlayerUpdate((EntityPlayerMP) entityLiving);
        }
        return;
    }
    if (entityLiving.ticksExisted % ConfigManagerCore.suffocationCooldown == 0) {
        if (entityLiving.worldObj.provider instanceof IGalacticraftWorldProvider) {
            if (!(entityLiving instanceof EntityPlayer) && (!(entityLiving instanceof IEntityBreathable) || !((IEntityBreathable) entityLiving).canBreath()) && !((IGalacticraftWorldProvider) entityLiving.worldObj.provider).hasBreathableAtmosphere()) {
                if (!OxygenUtil.isAABBInBreathableAirBlock(entityLiving)) {
                    GCCoreOxygenSuffocationEvent suffocationEvent = new GCCoreOxygenSuffocationEvent.Pre(entityLiving);
                    MinecraftForge.EVENT_BUS.post(suffocationEvent);
                    if (suffocationEvent.isCanceled()) {
                        return;
                    }
                    entityLiving.attackEntityFrom(DamageSourceGC.oxygenSuffocation, Math.max(ConfigManagerCore.suffocationDamage / 2, 1));
                    GCCoreOxygenSuffocationEvent suffocationEventPost = new GCCoreOxygenSuffocationEvent.Post(entityLiving);
                    MinecraftForge.EVENT_BUS.post(suffocationEventPost);
                }
            }
        }
    }
}
Also used : IEntityBreathable(micdoodle8.mods.galacticraft.api.entity.IEntityBreathable) IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) GCCoreOxygenSuffocationEvent(micdoodle8.mods.galacticraft.api.event.oxygen.GCCoreOxygenSuffocationEvent) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with GCCoreOxygenSuffocationEvent

use of micdoodle8.mods.galacticraft.api.event.oxygen.GCCoreOxygenSuffocationEvent in project Galacticraft by micdoodle8.

the class GCPlayerHandler method checkOxygen.

protected void checkOxygen(EntityPlayerMP player, GCPlayerStats stats) {
    if ((player.dimension == 0 || player.worldObj.provider instanceof IGalacticraftWorldProvider) && (!(player.dimension == 0 || ((IGalacticraftWorldProvider) player.worldObj.provider).hasBreathableAtmosphere()) || player.posY > GCPlayerHandler.OXYGENHEIGHTLIMIT) && !player.capabilities.isCreativeMode && !(player.ridingEntity instanceof EntityLanderBase) && !(player.ridingEntity instanceof EntityAutoRocket) && !(player.ridingEntity instanceof EntityCelestialFake) && !CompatibilityManager.isAndroid(player)) {
        final ItemStack tankInSlot = stats.getExtendedInventory().getStackInSlot(2);
        final ItemStack tankInSlot2 = stats.getExtendedInventory().getStackInSlot(3);
        final int drainSpacing = OxygenUtil.getDrainSpacing(tankInSlot, tankInSlot2);
        if (tankInSlot == null) {
            stats.setAirRemaining(0);
        } else {
            stats.setAirRemaining(tankInSlot.getMaxDamage() - tankInSlot.getItemDamage());
        }
        if (tankInSlot2 == null) {
            stats.setAirRemaining2(0);
        } else {
            stats.setAirRemaining2(tankInSlot2.getMaxDamage() - tankInSlot2.getItemDamage());
        }
        if (drainSpacing > 0) {
            if ((player.ticksExisted - 1) % drainSpacing == 0 && !OxygenUtil.isAABBInBreathableAirBlock(player) && !stats.isUsingPlanetSelectionGui()) {
                int toTake = 1;
                // Take 1 oxygen from Tank 1
                if (stats.getAirRemaining() > 0) {
                    tankInSlot.damageItem(1, player);
                    stats.setAirRemaining(stats.getAirRemaining() - 1);
                    toTake = 0;
                }
                // Alternatively, take 1 oxygen from Tank 2
                if (toTake > 0 && stats.getAirRemaining2() > 0) {
                    tankInSlot2.damageItem(1, player);
                    stats.setAirRemaining2(stats.getAirRemaining2() - 1);
                    toTake = 0;
                }
            }
        } else {
            if ((player.ticksExisted - 1) % 60 == 0) {
                if (OxygenUtil.isAABBInBreathableAirBlock(player)) {
                    if (stats.getAirRemaining() < 90 && tankInSlot != null) {
                        stats.setAirRemaining(Math.min(stats.getAirRemaining() + 1, tankInSlot.getMaxDamage() - tankInSlot.getItemDamage()));
                    }
                    if (stats.getAirRemaining2() < 90 && tankInSlot2 != null) {
                        stats.setAirRemaining2(Math.min(stats.getAirRemaining2() + 1, tankInSlot2.getMaxDamage() - tankInSlot2.getItemDamage()));
                    }
                } else {
                    if (stats.getAirRemaining() > 0) {
                        stats.setAirRemaining(stats.getAirRemaining() - 1);
                    }
                    if (stats.getAirRemaining2() > 0) {
                        stats.setAirRemaining2(stats.getAirRemaining2() - 1);
                    }
                }
            }
        }
        final boolean airEmpty = stats.getAirRemaining() <= 0 && stats.getAirRemaining2() <= 0;
        if (player.isOnLadder()) {
            stats.setOxygenSetupValid(stats.isLastOxygenSetupValid());
        } else {
            stats.setOxygenSetupValid(!((!OxygenUtil.hasValidOxygenSetup(player) || airEmpty) && !OxygenUtil.isAABBInBreathableAirBlock(player)));
        }
        if (!player.worldObj.isRemote && player.isEntityAlive()) {
            if (!stats.isOxygenSetupValid()) {
                GCCoreOxygenSuffocationEvent suffocationEvent = new GCCoreOxygenSuffocationEvent.Pre(player);
                MinecraftForge.EVENT_BUS.post(suffocationEvent);
                if (!suffocationEvent.isCanceled()) {
                    if (stats.getDamageCounter() == 0) {
                        stats.setDamageCounter(ConfigManagerCore.suffocationCooldown);
                        player.attackEntityFrom(DamageSourceGC.oxygenSuffocation, ConfigManagerCore.suffocationDamage * (2 + stats.getIncrementalDamage()) / 2);
                        if (ConfigManagerCore.hardMode)
                            stats.setIncrementalDamage(stats.getIncrementalDamage() + 1);
                        GCCoreOxygenSuffocationEvent suffocationEventPost = new GCCoreOxygenSuffocationEvent.Post(player);
                        MinecraftForge.EVENT_BUS.post(suffocationEventPost);
                    }
                } else
                    stats.setOxygenSetupValid(true);
            } else
                stats.setIncrementalDamage(0);
        }
    } else if ((player.ticksExisted - 1) % 20 == 0 && !player.capabilities.isCreativeMode && stats.getAirRemaining() < 90) {
        stats.setAirRemaining(stats.getAirRemaining() + 1);
        stats.setAirRemaining2(stats.getAirRemaining2() + 1);
    } else if (player.capabilities.isCreativeMode) {
        stats.setAirRemaining(90);
        stats.setAirRemaining2(90);
    } else {
        stats.setOxygenSetupValid(true);
    }
}
Also used : EntityLanderBase(micdoodle8.mods.galacticraft.core.entities.EntityLanderBase) IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) EntityCelestialFake(micdoodle8.mods.galacticraft.core.entities.EntityCelestialFake) GCCoreOxygenSuffocationEvent(micdoodle8.mods.galacticraft.api.event.oxygen.GCCoreOxygenSuffocationEvent) EntityAutoRocket(micdoodle8.mods.galacticraft.api.prefab.entity.EntityAutoRocket) ItemStack(net.minecraft.item.ItemStack) TargetPoint(net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint) Footprint(micdoodle8.mods.galacticraft.core.wrappers.Footprint)

Aggregations

GCCoreOxygenSuffocationEvent (micdoodle8.mods.galacticraft.api.event.oxygen.GCCoreOxygenSuffocationEvent)2 IGalacticraftWorldProvider (micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider)2 IEntityBreathable (micdoodle8.mods.galacticraft.api.entity.IEntityBreathable)1 EntityAutoRocket (micdoodle8.mods.galacticraft.api.prefab.entity.EntityAutoRocket)1 EntityCelestialFake (micdoodle8.mods.galacticraft.core.entities.EntityCelestialFake)1 EntityLanderBase (micdoodle8.mods.galacticraft.core.entities.EntityLanderBase)1 Footprint (micdoodle8.mods.galacticraft.core.wrappers.Footprint)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 ItemStack (net.minecraft.item.ItemStack)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 TargetPoint (net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint)1