Search in sources :

Example 26 with EntityLiving

use of net.minecraft.entity.EntityLiving in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class RotationMatrices method applyTransform.

public static final void applyTransform(double[] wholeTransform, double[] rotationTransform, Entity ent) {
    Vector entityPos = new Vector(ent.posX, ent.posY, ent.posZ);
    Vector entityLook = new Vector(ent.getLook(1.0F));
    Vector entityMotion = new Vector(ent.motionX, ent.motionY, ent.motionZ);
    if (ent instanceof EntityFireball) {
        EntityFireball ball = (EntityFireball) ent;
        entityMotion.X = ball.accelerationX;
        entityMotion.Y = ball.accelerationY;
        entityMotion.Z = ball.accelerationZ;
    }
    applyTransform(wholeTransform, entityPos);
    doRotationOnly(rotationTransform, entityLook);
    doRotationOnly(rotationTransform, entityMotion);
    entityLook.normalize();
    // This is correct
    ent.rotationPitch = (float) MathHelper.wrapDegrees(BigBastardMath.getPitchFromVec3d(entityLook));
    ent.prevRotationPitch = ent.rotationPitch;
    ent.rotationYaw = (float) MathHelper.wrapDegrees(BigBastardMath.getYawFromVec3d(entityLook, ent.rotationPitch));
    ent.prevRotationYaw = ent.rotationYaw;
    if (ent instanceof EntityLiving) {
        EntityLiving living = (EntityLiving) ent;
        living.rotationYawHead = ent.rotationYaw;
        living.prevRotationYawHead = ent.rotationYaw;
    }
    if (ent instanceof EntityFireball) {
        EntityFireball ball = (EntityFireball) ent;
        ball.accelerationX = entityMotion.X;
        ball.accelerationY = entityMotion.Y;
        ball.accelerationZ = entityMotion.Z;
    }
    ent.motionX = entityMotion.X;
    ent.motionY = entityMotion.Y;
    ent.motionZ = entityMotion.Z;
    ent.setPosition(entityPos.X, entityPos.Y, entityPos.Z);
}
Also used : EntityLiving(net.minecraft.entity.EntityLiving) EntityFireball(net.minecraft.entity.projectile.EntityFireball)

Example 27 with EntityLiving

use of net.minecraft.entity.EntityLiving in project Realistic-Terrain-Generation by Team-RTG.

the class DisruptionSpawn method disrupt.

@Override
public void disrupt(World world, BlockPos pos, List<EntityPlayer> players) {
    if (!world.isRemote) {
        EntityLivingBase entityliving = null;
        try {
            entityliving = entity.getConstructor(World.class).newInstance(world);
        } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
            e.printStackTrace();
        }
        if (entityliving != null) {
            entityliving.setLocationAndAngles(pos.getX(), pos.getY() + 1, pos.getZ(), entityliving.rotationYaw, entityliving.rotationPitch);
            ((EntityLiving) entityliving).onInitialSpawn(world.getDifficultyForLocation(pos.up()), (IEntityLivingData) null);
            world.spawnEntity(entityliving);
        }
    }
}
Also used : EntityLiving(net.minecraft.entity.EntityLiving) EntityLivingBase(net.minecraft.entity.EntityLivingBase) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 28 with EntityLiving

use of net.minecraft.entity.EntityLiving in project ICBM-Classic by BuiltBrokenModding.

the class BlastRedmatter method affectEntity.

/**
     * Makes an entity get affected by Red Matter.
     *
     * @Return True if explosion happened
     */
public boolean affectEntity(float radius, Entity entity, boolean doExplosion) {
    //Ignore players that are in creative mode or can't be harmed
    if (entity instanceof EntityPlayer && (((EntityPlayer) entity).capabilities.isCreativeMode || ((EntityPlayer) entity).capabilities.disableDamage)) {
        return false;
    }
    //Ignore self
    if (entity == this.controller) {
        return false;
    }
    //Ignore entities that mark themselves are ignorable
    if (entity instanceof IExplosiveIgnore) {
        if (((IExplosiveIgnore) entity).canIgnore(this)) {
            return false;
        }
    }
    //Calculate different from center
    double xDifference = entity.posX - position.xi() + 0.5;
    double yDifference = entity.posY - position.yi() + 0.5;
    double zDifference = entity.posZ - position.zi() + 0.5;
    /** The percentage of the closeness of the entity. */
    double xPercentage = 1 - (xDifference / radius);
    double yPercentage = 1 - (yDifference / radius);
    double zPercentage = 1 - (zDifference / radius);
    double distancePercentage = this.position.distance(entity) / radius;
    Pos entityPosition = new Pos(entity);
    Pos centeredPosition = entityPosition.subtract(this.position);
    centeredPosition = (Pos) centeredPosition.transform(new EulerAngle(1.5 * distancePercentage * Math.random(), 1.5 * distancePercentage * Math.random(), 1.5 * distancePercentage * Math.random()));
    Location newPosition = this.position.add(centeredPosition);
    // Orbit Velocity
    entity.addVelocity(newPosition.x() - entityPosition.x(), 0, newPosition.z() - entityPosition.z());
    // Gravity Velocity (0.015 is barely enough to overcome y gravity so do not lower)
    entity.addVelocity(-xDifference * 0.015 * xPercentage, -yDifference * 0.015 * yPercentage, -zDifference * 0.015 * zPercentage);
    boolean explosionCreated = false;
    if (new Pos(entity.posX, entity.posY, entity.posZ).distance(position) < (ENTITY_DESTROY_RADIUS * (getRadius() / NORMAL_RADIUS))) {
        if (entity instanceof EntityExplosion) {
            if (((EntityExplosion) entity).getBlast() instanceof BlastAntimatter) {
                if (doAudio) {
                    this.world().playSoundEffect(position.x(), position.y(), position.z(), ICBMClassic.PREFIX + "explosion", 7.0F, (1.0F + (this.world().rand.nextFloat() - this.world().rand.nextFloat()) * 0.2F) * 0.7F);
                }
                if (this.world().rand.nextFloat() > 0.85 && !this.world().isRemote) {
                    entity.setDead();
                    return explosionCreated;
                }
            } else if (((EntityExplosion) entity).getBlast() instanceof BlastRedmatter) {
                //https://www.wolframalpha.com/input/?i=(4%2F3)pi+*+r%5E3+%3D+(4%2F3)pi+*+a%5E3+%2B+(4%2F3)pi+*+b%5E3
                //We are going to merge both blasts together
                double sizeA = this.getRadius();
                sizeA = sizeA * sizeA * sizeA;
                double sizeB = ((EntityExplosion) entity).getBlast().getRadius();
                sizeB = sizeB * sizeB * sizeB;
                float radiusNew = (float) Math.cbrt(sizeA + sizeB);
                //Average out timer
                this.callCount = (callCount + ((EntityExplosion) entity).getBlast().callCount) / 2;
                //Destroy current instance
                this.isAlive = false;
                this.controller.setDead();
                //Create new to avoid doing packet syncing
                new BlastRedmatter(world(), entity, position.x(), position.y(), position.z(), radiusNew).explode();
            }
            //Kill explosion entity
            ((EntityExplosion) entity).getBlast().isAlive = false;
            //Kill entity in the center of the ball
            entity.setDead();
        } else if (entity instanceof EntityExplosive) {
            ((EntityExplosive) entity).explode();
        } else if (entity instanceof EntityLiving) {
            ((EntityLiving) entity).attackEntityFrom(DamageSource.outOfWorld, 99999999);
        } else {
            //Kill entity in the center of the ball
            entity.setDead();
        }
    }
    return explosionCreated;
}
Also used : EntityLiving(net.minecraft.entity.EntityLiving) Pos(com.builtbroken.mc.imp.transform.vector.Pos) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityExplosion(icbm.classic.content.entity.EntityExplosion) EntityExplosive(icbm.classic.content.entity.EntityExplosive) EulerAngle(com.builtbroken.mc.imp.transform.rotation.EulerAngle) IExplosiveIgnore(resonant.api.explosion.IExplosiveIgnore) Location(com.builtbroken.mc.imp.transform.vector.Location)

Example 29 with EntityLiving

use of net.minecraft.entity.EntityLiving in project ICBM-Classic by BuiltBrokenModding.

the class BlastMutation method doExplode.

@Override
public void doExplode() {
    if (!this.world().isRemote) {
        AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(position.x() - this.getRadius(), position.y() - this.getRadius(), position.z() - this.getRadius(), position.x() + this.getRadius(), position.y() + this.getRadius(), position.z() + this.getRadius());
        List<EntityLiving> entitiesNearby = world().getEntitiesWithinAABB(EntityLiving.class, bounds);
        for (EntityLiving entity : entitiesNearby) {
            if (entity instanceof EntityPig) {
                EntityPigZombie newEntity = new EntityPigZombie(world());
                newEntity.preventEntitySpawning = true;
                newEntity.setPosition(entity.posX, entity.posY, entity.posZ);
                entity.setDead();
            } else if (entity instanceof EntityVillager) {
                EntityZombie newEntity = new EntityZombie(world());
                newEntity.preventEntitySpawning = true;
                newEntity.setPosition(entity.posX, entity.posY, entity.posZ);
                entity.setDead();
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) EntityLiving(net.minecraft.entity.EntityLiving) EntityZombie(net.minecraft.entity.monster.EntityZombie) EntityPig(net.minecraft.entity.passive.EntityPig) EntityPigZombie(net.minecraft.entity.monster.EntityPigZombie) EntityVillager(net.minecraft.entity.passive.EntityVillager)

Example 30 with EntityLiving

use of net.minecraft.entity.EntityLiving in project BetterWithAddons by DaedalusGame.

the class TileEntityLureTree method attractAnimals.

public boolean attractAnimals(int amt) {
    Random random = world.rand;
    Biome biome = world.getBiome(pos);
    int spawned = 0;
    if (biome != null) {
        List<Biome.SpawnListEntry> spawnable = biome.getSpawnableList(EnumCreatureType.CREATURE);
        if (!spawnable.isEmpty())
            for (int i = 0; i < amt; i++) {
                Biome.SpawnListEntry entry = WeightedRandom.getRandomItem(random, spawnable);
                int x = pos.getX() + random.nextInt(InteractionBWA.RADIUS * 2 + 1) - InteractionBWA.RADIUS;
                int z = pos.getZ() + random.nextInt(InteractionBWA.RADIUS * 2 + 1) - InteractionBWA.RADIUS;
                if (!BLACKLIST.contains(entry.entityClass)) {
                    for (int y = pos.getY(); y > pos.getY() - 4; y--) {
                        BlockPos pos = new BlockPos(x, y, z);
                        if (world.isAirBlock(pos) && WorldEntitySpawner.canCreatureTypeSpawnAtLocation(EntityLiving.SpawnPlacementType.ON_GROUND, world, pos)) {
                            EntityLiving entityliving;
                            try {
                                entityliving = entry.entityClass.getConstructor(new Class[] { World.class }).newInstance(new Object[] { world });
                            } catch (Exception exception) {
                                exception.printStackTrace();
                                continue;
                            }
                            entityliving.setLocationAndAngles(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, random.nextFloat() * 360.0F, 0.0F);
                            world.spawnEntity(entityliving);
                            if (entityliving != null) {
                                entityliving.spawnExplosionParticle();
                                spawned++;
                            }
                            break;
                        } else if (world.isSideSolid(pos, EnumFacing.UP)) {
                            break;
                        }
                    }
                }
            }
    }
    return spawned > 0;
}
Also used : Biome(net.minecraft.world.biome.Biome) Random(java.util.Random) EntityLiving(net.minecraft.entity.EntityLiving) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World)

Aggregations

EntityLiving (net.minecraft.entity.EntityLiving)44 Entity (net.minecraft.entity.Entity)14 EntityPlayer (net.minecraft.entity.player.EntityPlayer)14 ItemStack (net.minecraft.item.ItemStack)11 EntityLivingBase (net.minecraft.entity.EntityLivingBase)7 World (net.minecraft.world.World)6 Block (net.minecraft.block.Block)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 PotionEffect (net.minecraft.potion.PotionEffect)4 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 EntityCreature (net.minecraft.entity.EntityCreature)3 BlockPos (net.minecraft.util.math.BlockPos)3 Pos (com.builtbroken.mc.imp.transform.vector.Pos)2 ArrayList (java.util.ArrayList)2 Random (java.util.Random)2 EntityItem (net.minecraft.entity.item.EntityItem)2 EntityXPOrb (net.minecraft.entity.item.EntityXPOrb)2 EntityMob (net.minecraft.entity.monster.EntityMob)2 EntityZombie (net.minecraft.entity.monster.EntityZombie)2