Search in sources :

Example 31 with EntityLiving

use of net.minecraft.entity.EntityLiving in project ArsMagica2 by Mithion.

the class TileEntitySummoner method summonCreature.

private void summonCreature() {
    if (worldObj.isRemote || this.summonEntityID != -1)
        return;
    if (dummyCaster == null) {
        dummyCaster = new DummyEntityPlayer(worldObj);
    }
    EntityLiving summon = ((Summon) SkillManager.instance.getSkill("Summon")).summonCreature(inventory[SUMMON_SLOT], dummyCaster, dummyCaster, worldObj, xCoord, yCoord, zCoord);
    if (summon != null) {
        if (summon instanceof EntityCreature)
            EntityUtilities.setGuardSpawnLocation((EntityCreature) summon, xCoord, yCoord, zCoord);
        this.summonEntityID = summon.getEntityId();
        PowerNodeRegistry.For(this.worldObj).consumePower(this, PowerNodeRegistry.For(this.worldObj).getHighestPowerType(this), summonCost);
        this.summonCooldown = this.maxSummonCooldown;
        EntityUtilities.setTileSpawned(summon, this);
        worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
    }
}
Also used : DummyEntityPlayer(am2.utility.DummyEntityPlayer) EntityLiving(net.minecraft.entity.EntityLiving) Summon(am2.spell.components.Summon) EntityCreature(net.minecraft.entity.EntityCreature)

Example 32 with EntityLiving

use of net.minecraft.entity.EntityLiving in project ArsMagica2 by Mithion.

the class TileEntitySummoner method updateEntity.

@Override
public void updateEntity() {
    super.updateEntity();
    prevSummonCooldown = summonCooldown;
    summonCooldown--;
    if (summonCooldown < 0)
        summonCooldown = 0;
    if (!worldObj.isRemote && summonCooldown == 0 && prevSummonCooldown > 0) {
        worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
    }
    if (!worldObj.isRemote) {
        EntityLiving ent = getSummonedCreature();
        if (ent == null) {
            summonEntityID = -1;
        }
        if (isRedstonePowered() && inventory[SUMMON_SLOT] != null) {
            if (PowerNodeRegistry.For(this.worldObj).checkPower(this, maintainCost)) {
                if (ent == null && canSummon()) {
                    summonCreature();
                } else {
                    if (ent != null) {
                        PowerNodeRegistry.For(this.worldObj).consumePower(this, PowerNodeRegistry.For(this.worldObj).getHighestPowerType(this), maintainCost);
                    }
                }
            } else {
                unsummonCreature();
            }
        } else {
            if (ent != null) {
                unsummonCreature();
                PowerNodeRegistry.For(this.worldObj).insertPower(this, PowerTypes.NEUTRAL, summonCost / 2);
            }
        }
    }
}
Also used : EntityLiving(net.minecraft.entity.EntityLiving)

Example 33 with EntityLiving

use of net.minecraft.entity.EntityLiving in project ArsMagica2 by Mithion.

the class TileEntitySummoner method unsummonCreature.

private void unsummonCreature() {
    if (worldObj.isRemote)
        return;
    EntityLiving ent = getSummonedCreature();
    if (ent == null)
        return;
    ent.attackEntityFrom(DamageSources.unsummon, 1000000);
    this.summonEntityID = -1;
    worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
Also used : EntityLiving(net.minecraft.entity.EntityLiving)

Example 34 with EntityLiving

use of net.minecraft.entity.EntityLiving in project MinecraftForge by MinecraftForge.

the class EntitySpawnHandler method spawnEntity.

private void spawnEntity(FMLMessage.EntitySpawnMessage spawnMsg) {
    ModContainer mc = Loader.instance().getIndexedModList().get(spawnMsg.modId);
    EntityRegistration er = EntityRegistry.instance().lookupModSpawn(mc, spawnMsg.modEntityTypeId);
    if (er == null) {
        throw new RuntimeException("Could not spawn mod entity ModID: " + spawnMsg.modId + " EntityID: " + spawnMsg.modEntityTypeId + " at ( " + spawnMsg.rawX + "," + spawnMsg.rawY + ", " + spawnMsg.rawZ + ") Please contact mod author or server admin.");
    }
    WorldClient wc = FMLClientHandler.instance().getWorldClient();
    Class<? extends Entity> cls = er.getEntityClass();
    try {
        Entity entity;
        if (er.hasCustomSpawning()) {
            entity = er.doCustomSpawning(spawnMsg);
        } else {
            entity = cls.getConstructor(World.class).newInstance(wc);
            int offset = spawnMsg.entityId - entity.getEntityId();
            entity.setEntityId(spawnMsg.entityId);
            entity.setUniqueId(spawnMsg.entityUUID);
            entity.setLocationAndAngles(spawnMsg.rawX, spawnMsg.rawY, spawnMsg.rawZ, spawnMsg.scaledYaw, spawnMsg.scaledPitch);
            if (entity instanceof EntityLiving) {
                ((EntityLiving) entity).rotationYawHead = spawnMsg.scaledHeadYaw;
            }
            Entity[] parts = entity.getParts();
            if (parts != null) {
                for (int j = 0; j < parts.length; j++) {
                    parts[j].setEntityId(parts[j].getEntityId() + offset);
                }
            }
        }
        EntityTracker.updateServerPosition(entity, spawnMsg.rawX, spawnMsg.rawY, spawnMsg.rawZ);
        EntityPlayerSP clientPlayer = FMLClientHandler.instance().getClientPlayerEntity();
        if (entity instanceof IThrowableEntity) {
            Entity thrower = clientPlayer.getEntityId() == spawnMsg.throwerId ? clientPlayer : wc.getEntityByID(spawnMsg.throwerId);
            ((IThrowableEntity) entity).setThrower(thrower);
        }
        if (spawnMsg.dataWatcherList != null) {
            entity.getDataManager().setEntryValues(spawnMsg.dataWatcherList);
        }
        if (spawnMsg.throwerId > 0) {
            entity.setVelocity(spawnMsg.speedScaledX, spawnMsg.speedScaledY, spawnMsg.speedScaledZ);
        }
        if (entity instanceof IEntityAdditionalSpawnData) {
            ((IEntityAdditionalSpawnData) entity).readSpawnData(spawnMsg.dataStream);
        }
        wc.addEntityToWorld(spawnMsg.entityId, entity);
    } catch (Exception e) {
        FMLLog.log(Level.ERROR, e, "A severe problem occurred during the spawning of an entity at ( " + spawnMsg.rawX + "," + spawnMsg.rawY + ", " + spawnMsg.rawZ + ")");
        throw Throwables.propagate(e);
    }
}
Also used : IEntityAdditionalSpawnData(net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData) Entity(net.minecraft.entity.Entity) IThrowableEntity(net.minecraftforge.fml.common.registry.IThrowableEntity) ModContainer(net.minecraftforge.fml.common.ModContainer) EntityLiving(net.minecraft.entity.EntityLiving) IThrowableEntity(net.minecraftforge.fml.common.registry.IThrowableEntity) WorldClient(net.minecraft.client.multiplayer.WorldClient) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) EntityRegistration(net.minecraftforge.fml.common.registry.EntityRegistry.EntityRegistration)

Example 35 with EntityLiving

use of net.minecraft.entity.EntityLiving in project MineFactoryReloaded by powercrystals.

the class ItemSafariNet method spawnCreature.

private static Entity spawnCreature(World world, NBTTagCompound mobTag, double x, double y, double z, int side) {
    Entity e;
    if (mobTag.getBoolean("hide")) {
        List<RandomMob> mobs = new ArrayList<RandomMob>();
        for (IRandomMobProvider p : MFRRegistry.getRandomMobProviders()) {
            System.out.println("Adding mobs from " + p.getClass().getName());
            mobs.addAll(p.getRandomMobs(world));
        }
        e = ((RandomMob) WeightedRandom.getRandomItem(world.rand, mobs)).getMob();
    } else {
        NBTTagList pos = mobTag.getTagList("Pos");
        ((NBTTagDouble) pos.tagAt(0)).data = x;
        ((NBTTagDouble) pos.tagAt(1)).data = y;
        ((NBTTagDouble) pos.tagAt(2)).data = z;
        e = EntityList.createEntityFromNBT(mobTag, world);
        if (e != null) {
            if (e instanceof EntityLiving) {
                ((EntityLiving) e).initCreature();
            }
            e.readFromNBT(mobTag);
        }
    }
    if (e != null) {
        int offsetX = Facing.offsetsXForSide[side];
        int offsetY = side == 0 ? -1 : 0;
        int offsetZ = Facing.offsetsZForSide[side];
        AxisAlignedBB bb = e.boundingBox;
        e.setLocationAndAngles(x + (bb.maxX - bb.minX) * 0.5 * offsetX, y + (bb.maxY - bb.minY) * 0.5 * offsetY, z + (bb.maxZ - bb.minZ) * 0.5 * offsetZ, world.rand.nextFloat() * 360.0F, 0.0F);
        world.spawnEntityInWorld(e);
        if (e instanceof EntityLiving) {
            ((EntityLiving) e).playLivingSound();
        }
        Entity riddenByEntity = e.riddenByEntity;
        while (riddenByEntity != null) {
            riddenByEntity.setLocationAndAngles(x, y, z, world.rand.nextFloat() * 360.0F, 0.0F);
            world.spawnEntityInWorld(riddenByEntity);
            if (riddenByEntity instanceof EntityLiving) {
                ((EntityLiving) riddenByEntity).playLivingSound();
            }
            riddenByEntity = riddenByEntity.riddenByEntity;
        }
    }
    return e;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) AxisAlignedBB(net.minecraft.util.AxisAlignedBB) Entity(net.minecraft.entity.Entity) RandomMob(powercrystals.minefactoryreloaded.api.RandomMob) EntityLiving(net.minecraft.entity.EntityLiving) ArrayList(java.util.ArrayList) IRandomMobProvider(powercrystals.minefactoryreloaded.api.IRandomMobProvider)

Aggregations

EntityLiving (net.minecraft.entity.EntityLiving)45 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)5 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 IBlockState (net.minecraft.block.state.IBlockState)2 EntityItem (net.minecraft.entity.item.EntityItem)2 EntityXPOrb (net.minecraft.entity.item.EntityXPOrb)2 EntityMob (net.minecraft.entity.monster.EntityMob)2