Search in sources :

Example 1 with EntityFlying

use of net.minecraft.entity.EntityFlying in project Galacticraft by micdoodle8.

the class FreefallHandler method tickFreefallEntity.

/**
 * Call this on every freefalling non-player entity in a dimension
 * either at the end of the world tick (ideal) or else during the
 * start of the next world tick (e.g. during updateWeather())
 *
 * May require iteration through the world's loadedEntityList
 * See SpinManager.updateSpin() for an example
 * @param e
 */
public static void tickFreefallEntity(Entity e) {
    if (e.worldObj.provider instanceof IZeroGDimension)
        ((IZeroGDimension) e.worldObj.provider).setInFreefall(e);
    // Undo deceleration applied at the end of the previous tick
    boolean warnLog = false;
    if (e instanceof EntityLivingBase) {
        ZeroGravityEvent zeroGEvent = new ZeroGravityEvent.InFreefall((EntityLivingBase) e);
        MinecraftForge.EVENT_BUS.post(zeroGEvent);
        if (!zeroGEvent.isCanceled()) {
            // 0.91F;
            e.motionX /= (double) 0.91F;
            // 0.91F;
            e.motionZ /= (double) 0.91F;
            e.motionY /= (e instanceof EntityFlying) ? 0.91F : 0.9800000190734863D;
            if (e.motionX > 10D) {
                warnLog = true;
                e.motionX = 10D;
            } else if (e.motionX < -10D) {
                warnLog = true;
                e.motionX = -10D;
            }
            if (e.motionY > 10D) {
                warnLog = true;
                e.motionY = 10D;
            } else if (e.motionY < -10D) {
                warnLog = true;
                e.motionY = -10D;
            }
            if (e.motionZ > 10D) {
                warnLog = true;
                e.motionZ = 10D;
            } else if (e.motionZ < -10D) {
                warnLog = true;
                e.motionZ = -10D;
            }
        }
    } else if (e instanceof EntityFallingBlock) {
        e.motionY /= 0.9800000190734863D;
        // e.lastTickPosY += 0.03999999910593033D;
        if (e.motionY > 10D) {
            warnLog = true;
            e.motionY = 10D;
        } else if (e.motionY < -10D) {
            warnLog = true;
            e.motionY = -10D;
        }
    } else {
        e.motionX /= 0.9800000190734863D;
        e.motionY /= 0.9800000190734863D;
        e.motionZ /= 0.9800000190734863D;
        if (e.motionX > 10D) {
            warnLog = true;
            e.motionX = 10D;
        } else if (e.motionX < -10D) {
            warnLog = true;
            e.motionX = -10D;
        }
        if (e.motionY > 10D) {
            warnLog = true;
            e.motionY = 10D;
        } else if (e.motionY < -10D) {
            warnLog = true;
            e.motionY = -10D;
        }
        if (e.motionZ > 10D) {
            warnLog = true;
            e.motionZ = 10D;
        } else if (e.motionZ < -10D) {
            warnLog = true;
            e.motionZ = -10D;
        }
    }
    if (warnLog)
        GCLog.debug(e.getName() + " moving too fast");
}
Also used : ZeroGravityEvent(micdoodle8.mods.galacticraft.api.event.ZeroGravityEvent) EntityFallingBlock(net.minecraft.entity.item.EntityFallingBlock) EntityFlying(net.minecraft.entity.EntityFlying) EntityLivingBase(net.minecraft.entity.EntityLivingBase) IZeroGDimension(micdoodle8.mods.galacticraft.api.world.IZeroGDimension)

Aggregations

ZeroGravityEvent (micdoodle8.mods.galacticraft.api.event.ZeroGravityEvent)1 IZeroGDimension (micdoodle8.mods.galacticraft.api.world.IZeroGDimension)1 EntityFlying (net.minecraft.entity.EntityFlying)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityFallingBlock (net.minecraft.entity.item.EntityFallingBlock)1