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);
}
}
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);
}
}
}
}
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);
}
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);
}
}
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;
}
Aggregations