Search in sources :

Example 1 with IEntityBreathable

use of micdoodle8.mods.galacticraft.api.entity.IEntityBreathable 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 IEntityBreathable

use of micdoodle8.mods.galacticraft.api.entity.IEntityBreathable in project Galacticraft by micdoodle8.

the class TileEntityEmergencyBox method scareMobs.

private void scareMobs() {
    List<Entity> moblist = this.worldObj.getEntitiesInAABBexcluding(null, mobsAABB, IMob.mobSelector);
    if (!moblist.isEmpty()) {
        for (Entity entry : moblist) {
            if (!(entry instanceof EntityCreature && entry instanceof IEntityBreathable)) {
                continue;
            }
            EntityCreature mob = (EntityCreature) entry;
            PathNavigate nav = mob.getNavigator();
            if (nav == null) {
                continue;
            }
            Vec3 vecNewTarget = RandomPositionGenerator.findRandomTargetBlockAwayFrom(mob, 12, 5, vec3Centre);
            if (vecNewTarget == null) {
                vecNewTarget = RandomPositionGenerator.findRandomTargetBlockAwayFrom(mob, 14, 7, vec3Centre);
                if (vecNewTarget == null)
                    continue;
            }
            double distanceNew = vecNewTarget.squareDistanceTo(thisVec3);
            double distanceCurrent = thisVec3.squareDistanceTo(new Vec3(mob.posX, mob.posY, mob.posZ));
            if (distanceNew > distanceCurrent) {
                Vec3 vecOldTarget = null;
                if (nav.getPath() != null && !nav.getPath().isFinished()) {
                    vecOldTarget = nav.getPath().getPosition(mob);
                }
                if (vecOldTarget == null || distanceCurrent > vecOldTarget.squareDistanceTo(thisVec3)) {
                    nav.tryMoveToXYZ(vecNewTarget.xCoord, vecNewTarget.yCoord, vecNewTarget.zCoord, 1.3D);
                }
            }
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) IEntityBreathable(micdoodle8.mods.galacticraft.api.entity.IEntityBreathable) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3) Vec3(net.minecraft.util.Vec3) PathNavigate(net.minecraft.pathfinding.PathNavigate) EntityCreature(net.minecraft.entity.EntityCreature)

Aggregations

IEntityBreathable (micdoodle8.mods.galacticraft.api.entity.IEntityBreathable)2 GCCoreOxygenSuffocationEvent (micdoodle8.mods.galacticraft.api.event.oxygen.GCCoreOxygenSuffocationEvent)1 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)1 IGalacticraftWorldProvider (micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider)1 Entity (net.minecraft.entity.Entity)1 EntityCreature (net.minecraft.entity.EntityCreature)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 PathNavigate (net.minecraft.pathfinding.PathNavigate)1 TileEntity (net.minecraft.tileentity.TileEntity)1 Vec3 (net.minecraft.util.Vec3)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1