Java Code Examples for net.minecraft.entity.Entity#getDistanceSq()

The following examples show how to use net.minecraft.entity.Entity#getDistanceSq() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModuleEffectTimeSlow.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@ModuleOverride("shape_zone_run")
public boolean onRunZone(World world, SpellData data, SpellRing ring, @ContextRing SpellRing childRing) {
	double aoe = ring.getAttributeValue(world, AttributeRegistry.AREA, data);
	double range = ring.getAttributeValue(world, AttributeRegistry.RANGE, data);

	Vec3d targetPos = data.getTarget(world);

	if (targetPos == null) return false;

	Vec3d min = targetPos.subtract(aoe, range, aoe);
	Vec3d max = targetPos.add(aoe, range, aoe);

	List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(min, max));
	for (Entity entity : entities) {
		if (entity instanceof EntityLivingBase) {
			if (!((EntityLivingBase) entity).isPotionActive(ModPotions.TIME_SLOW) && entity.getDistanceSq(targetPos.x, targetPos.y, targetPos.z) <= aoe * aoe) {
				data.processEntity(entity, false);
				runOnStart(world, data, childRing);
			}
		}
	}
	return true;
}
 
Example 2
Source File: ModuleEffectVanish.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@ModuleOverride("shape_zone_run")
public boolean onRunZone(World world, SpellData data, SpellRing ring, @ContextRing SpellRing childRing) {
	double aoe = ring.getAttributeValue(world, AttributeRegistry.AREA, data);
	double range = ring.getAttributeValue(world, AttributeRegistry.RANGE, data);

	Vec3d targetPos = data.getTarget(world);

	if (targetPos == null) return false;

	Vec3d min = targetPos.subtract(aoe, range, aoe);
	Vec3d max = targetPos.add(aoe, range, aoe);

	List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(min, max));
	for (Entity entity : entities) {
		if (entity instanceof EntityLivingBase) {
			if (!VanishTracker.isVanished(entity) && entity.getDistanceSq(targetPos.x, targetPos.y, targetPos.z) <= aoe * aoe) {
				data.processEntity(entity, false);
				run(world, (ModuleInstanceEffect) childRing.getModule(), data, childRing);
			}
		}
	}
	return true;
}
 
Example 3
Source File: ModuleEffectLowGravity.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@ModuleOverride("shape_zone_run")
public boolean onRunZone(World world, SpellData data, SpellRing ring, @ContextRing SpellRing childRing) {
	double aoe = ring.getAttributeValue(world, AttributeRegistry.AREA, data);
	double range = ring.getAttributeValue(world, AttributeRegistry.RANGE, data);

	Vec3d targetPos = data.getTarget(world);

	if (targetPos == null) return false;

	Vec3d min = targetPos.subtract(aoe, range, aoe);
	Vec3d max = targetPos.add(aoe, range, aoe);

	List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(min, max));
	for (Entity entity : entities) {
		if (entity instanceof EntityLivingBase) {
			if (!((EntityLivingBase) entity).isPotionActive(ModPotions.LOW_GRAVITY) && entity.getDistanceSq(targetPos.x, targetPos.y, targetPos.z) <= aoe * aoe) {
				data.processEntity(entity, false);
				run(world, (ModuleInstanceEffect) childRing.getModule(), data, childRing);
			}
		}
	}
	return true;
}
 
Example 4
Source File: MoCEntityHorse.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
protected MoCEntityHorse getClosestMommy(Entity entity, double d)
{
    double d1 = -1D;
    MoCEntityHorse entityliving = null;
    List list = worldObj.getEntitiesWithinAABBExcludingEntity(entity, entity.boundingBox.expand(d, d, d));
    for (int i = 0; i < list.size(); i++)
    {
        Entity entity1 = (Entity) list.get(i);
        if ((!(entity1 instanceof MoCEntityHorse)) || ((entity1 instanceof MoCEntityHorse) && !((MoCEntityHorse) entity1).getHasBred()))
        {
            continue;
        }

        double d2 = entity1.getDistanceSq(entity.posX, entity.posY, entity.posZ);
        if (((d < 0.0D) || (d2 < (d * d))) && ((d1 == -1D) || (d2 < d1)))
        {
            d1 = d2;
            entityliving = (MoCEntityHorse) entity1;
        }
    }

    return entityliving;
}
 
Example 5
Source File: MoCEntityOstrich.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
protected MoCEntityOstrich getClosestMaleOstrich(Entity entity, double d)
{
    double d1 = -1D;
    MoCEntityOstrich entityliving = null;
    List list = worldObj.getEntitiesWithinAABBExcludingEntity(entity, entity.boundingBox.expand(d, d, d));
    for (int i = 0; i < list.size(); i++)
    {
        Entity entity1 = (Entity) list.get(i);
        if (!(entity1 instanceof MoCEntityOstrich) || ((entity1 instanceof MoCEntityOstrich) && ((MoCEntityOstrich) entity1).getType() < 3))
        {
            continue;
        }

        double d2 = entity1.getDistanceSq(entity.posX, entity.posY, entity.posZ);
        if (((d < 0.0D) || (d2 < (d * d))) && ((d1 == -1D) || (d2 < d1)))// && ((EntityLiving) entity1).canEntityBeSeen(entity))
        {
            d1 = d2;
            entityliving = (MoCEntityOstrich) entity1;
        }
    }

    return entityliving;
}
 
Example 6
Source File: ModuleEffectFrost.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@ModuleOverride("shape_zone_run")
public boolean onRunZone(World world, SpellData data, SpellRing ring, @ContextRing SpellRing childRing) {
	if(!world.isRemote) return false;

	double aoe = ring.getAttributeValue(world, AttributeRegistry.AREA, data);
	double range = ring.getAttributeValue(world, AttributeRegistry.RANGE, data);

	Vec3d targetPos = data.getTarget(world);

	if (targetPos == null) return false;

	Vec3d min = targetPos.subtract(aoe, range, aoe);
	Vec3d max = targetPos.add(aoe, range, aoe);

	List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(min, max));
	for (Entity entity : entities) {
		entity.extinguish();
		if (entity instanceof EntityLivingBase) {
			if (!((EntityLivingBase) entity).isPotionActive(ModPotions.SLIPPERY) && entity.getDistanceSq(targetPos.x, targetPos.y, targetPos.z) <= aoe * aoe) {

				double time = childRing.getAttributeValue(world, AttributeRegistry.DURATION, data) * 10;
				world.playSound(null, entity.getPosition(), ModSounds.FROST_FORM, SoundCategory.NEUTRAL, 1, 1);
				((EntityLivingBase) entity).addPotionEffect(new PotionEffect(ModPotions.SLIPPERY, (int) time, 0, true, false));
			}
		}
	}
	return false;
}
 
Example 7
Source File: WEntity.java    From ForgeWurst with GNU General Public License v3.0 4 votes vote down vote up
public static double getDistanceSq(Entity e1, Entity e2)
{
	return e1.getDistanceSq(e2);
}
 
Example 8
Source File: MoCEntityKitty.java    From mocreaturesdev with GNU General Public License v3.0 4 votes vote down vote up
public EntityLiving getKittyStuff(Entity entity, double d, boolean flag)
{
    double d1 = -1D;
    Object obj = null;
    List list = worldObj.getEntitiesWithinAABBExcludingEntity(entity, boundingBox.expand(d, d, d));
    for (int i = 0; i < list.size(); i++)
    {
        Entity entity1 = (Entity) list.get(i);
        if (flag)
        {
            if (!(entity1 instanceof MoCEntityLitterBox))
            {
                continue;
            }
            MoCEntityLitterBox entitylitterbox = (MoCEntityLitterBox) entity1;
            if (entitylitterbox.getUsedLitter())
            {
                continue;
            }
            double d2 = entity1.getDistanceSq(entity.posX, entity.posY, entity.posZ);
            if (((d < 0.0D) || (d2 < (d * d))) && ((d1 == -1.0D) || (d2 < d1)) && entitylitterbox.canEntityBeSeen(entity))
            {
                d1 = d2;
                obj = entitylitterbox;
            }
            continue;
        }
        if (!(entity1 instanceof MoCEntityKittyBed))
        {
            continue;
        }
        MoCEntityKittyBed entitykittybed = (MoCEntityKittyBed) entity1;
        double d3 = entity1.getDistanceSq(entity.posX, entity.posY, entity.posZ);
        if (((d < 0.0D) || (d3 < (d * d))) && ((d1 == -1.0D) || (d3 < d1)) && entitykittybed.canEntityBeSeen(entity))
        {
            d1 = d3;
            obj = entitykittybed;
        }
    }

    return ((EntityLiving) (obj));
}