public void SpawnAnimal(int X, int Y, int Z) { MobType type = MobType.Giant; switch (Server.Rand.Next(4)) { case 0: type = MobType.Cow; break; case 1: type = MobType.Hen; break; case 2: type = MobType.Pig; break; case 3: type = MobType.Sheep; break; } Mob mob = new Mob(Server, Server.AllocateEntity(), type); switch (type) // Assign type specific stats { case MobType.Cow: mob.Health = 10; break; case MobType.Hen: mob.Health = 5; break; case MobType.Pig: mob.Health = 10; break; case MobType.Sheep: mob.Health = 10; break; case MobType.PigZombie: mob.Health = 10; break; case MobType.Squid: mob.Health = 10; break; case MobType.Wolf: mob.Health = 10; break; } mob.Position = new World.Vector3(X + 0.5, Y, Z + 0.5); mob.World = this; mob.Hunter = true; mob.Hunting = false; mob.AttackRange = 10; //Event EntitySpawnEventArgs e = new EntitySpawnEventArgs(mob, mob.Position); Server.PluginManager.CallEvent(Plugins.Events.Event.ENTITY_SPAWN, e); if (e.EventCanceled) return; mob.Position = e.Location; //End Event //mob.Data // Set accessor is inaccebile? Server.AddEntity(mob); }
public void SpawnMob(int X, int Y, int Z, MobType type = MobType.Pig) { if (type == MobType.Pig) // Type has not been forced. { switch (Server.Rand.Next(4)) { case 0: type = MobType.Zombie; break; case 1: type = MobType.Skeleton; break; case 2: type = MobType.Creeper; break; case 3: type = MobType.Spider; break; // TODO: Check space is larger than 1x2 } } Mob mob = new Mob(Server, Server.AllocateEntity(), type); switch (type) // Assign type specific stats { case MobType.Zombie: mob.Health = 10; break; case MobType.Skeleton: mob.Health = 10; break; case MobType.Creeper: mob.Health = 10; break; case MobType.Spider: mob.Health = 10; break; case MobType.Ghast: mob.Health = 10; break; case MobType.Giant: mob.Health = 10; break; case MobType.Slime: mob.Health = 10; break; } mob.Position = new World.Vector3(X + 0.5, Y, Z + 0.5); mob.World = this; mob.Hunter = true; mob.Hunting = false; mob.AttackRange = 10; //Event EntitySpawnEventArgs e = new EntitySpawnEventArgs(mob, mob.Position); Server.PluginManager.CallEvent(Plugins.Events.Event.ENTITY_SPAWN, e); if (e.EventCanceled) return; mob.Position = e.Location; //End Event //mob.Data // Set accessor is inaccebile? Server.AddEntity(mob); // TODO: Limit this in some way. }
public void SpawnMob(UniversalCoords coords, MobType type = MobType.Pig) { if (type == MobType.Pig) // Type has not been forced. { switch (Server.Rand.Next(4)) { case 0: type = MobType.Zombie; break; case 1: type = MobType.Skeleton; break; case 2: type = MobType.Creeper; break; case 3: type = MobType.Spider; break; // TODO: Check space is larger than 1x2 } } Mob mob = MobFactory.CreateMob(this, this.Server.AllocateEntity(), type); mob.Position = new Location(new Vector3(coords.WorldX + 0.5, coords.WorldY, coords.WorldZ + 0.5)); mob.World = this; mob.Hunter = true; mob.Hunting = false; //Event EntitySpawnEventArgs e = new EntitySpawnEventArgs(mob, mob.Position.Vector); Server.PluginManager.CallEvent(Plugins.Events.Event.ENTITY_SPAWN, e); if (e.EventCanceled) return; mob.Position.Vector = e.Location; //End Event //mob.Data // Set accessor is inaccebile? Server.AddEntity(mob); // TODO: Limit this in some way. }
public void SpawnAnimal(UniversalCoords coords) { MobType type = MobType.Giant; switch (Server.Rand.Next(4)) { case 0: type = MobType.Cow; break; case 1: type = MobType.Hen; break; case 2: type = MobType.Pig; break; case 3: type = MobType.Sheep; break; } Mob mob = MobFactory.CreateMob(this, this.Server.AllocateEntity(), type); mob.Position = new Location(new Vector3(coords.WorldX + 0.5, coords.WorldY, coords.WorldZ + 0.5)); mob.World = this; mob.Hunter = true; mob.Hunting = false; //Event EntitySpawnEventArgs e = new EntitySpawnEventArgs(mob, mob.Position.Vector); Server.PluginManager.CallEvent(Plugins.Events.Event.ENTITY_SPAWN, e); if (e.EventCanceled) return; mob.Position.Vector = e.Location; //End Event //mob.Data // Set accessor is inaccebile? Server.AddEntity(mob); }
public virtual void OnSpawn(EntitySpawnEventArgs e) { }
private static void DoSpawn(WorldManager world, HashSet<int> chunksToSpawnIn, Mob[] mobEntities, List<WeightedValue<MobType>> mobGroup, int maximumMobs, bool inWater = false) { // Based on original server spawn logic and minecraft wiki (http://www.minecraftwiki.net/wiki/Spawn) // Check that we haven't already reached the maximum number of this type of mob if (mobGroup.Count > 0 && (mobEntities.Where(e => mobGroup.Where(mob => mob.Value == e.Type).Any()).Count() <= maximumMobs * chunksToSpawnIn.Count / 256)) { foreach (var packedChunk in chunksToSpawnIn) { MobType mobType = mobGroup.SelectRandom(world.Server.Rand); UniversalCoords packSpawnPosition = GetRandomPointInChunk(world, UniversalCoords.FromPackedChunkToX(packedChunk), UniversalCoords.FromPackedChunkToZ(packedChunk)); byte? blockId = world.GetBlockId(packSpawnPosition); if (blockId == null) continue; BlockBase blockClass = BlockHelper.Instance((byte)blockId); if (!blockClass.IsOpaque && ((!inWater && blockClass.Type == BlockData.Blocks.Air) || (inWater && blockClass.IsLiquid))) // Lava is Opaque, so IsLiquid is safe to use here for water & still water { int spawnedCount = 0; int x = packSpawnPosition.WorldX; int y = packSpawnPosition.WorldY; int z = packSpawnPosition.WorldZ; for (int i = 0; i < 21; i++) { // Every 4th attempt reset the coordinates to the centre of the pack spawn if (i % 4 == 0) { x = packSpawnPosition.WorldX; y = packSpawnPosition.WorldY; z = packSpawnPosition.WorldZ; } const int distance = 6; x += world.Server.Rand.Next(distance) - world.Server.Rand.Next(distance); y += world.Server.Rand.Next(1) - world.Server.Rand.Next(1); z += world.Server.Rand.Next(distance) - world.Server.Rand.Next(distance); if (CanMobTypeSpawnAtLocation(mobType, world, x, y, z)) { AbsWorldCoords spawnPosition = new AbsWorldCoords(x + 0.5, y, z + 0.5); // Check that no player is within a radius of 24 blocks of the spawnPosition if (world.GetClosestPlayer(spawnPosition, 24.0) == null) { // Check that the squared distance is more than 576 from spawn (24 blocks) if (spawnPosition.ToVector().DistanceSquared(new AbsWorldCoords(world.Spawn).ToVector()) > 576.0) { Mob newMob = MobFactory.CreateMob(world, world.Server.AllocateEntity(), mobType); if (newMob == null) break; newMob.Position = spawnPosition; newMob.Yaw = world.Server.Rand.NextDouble()*360.0; // Finally apply any mob specific rules about spawning here if (newMob.CanSpawnHere()) { //Event EntitySpawnEventArgs e = new EntitySpawnEventArgs(newMob, newMob.Position); world.Server.PluginManager.CallEvent(Plugins.Events.Event.EntitySpawn, e); if (e.EventCanceled) continue; newMob.Position = e.Location; //End Event ++spawnedCount; MobSpecificInitialisation(newMob, world, spawnPosition); world.Server.AddEntity(newMob); if (spawnedCount >= newMob.MaxSpawnedPerGroup) { // This chunk is full - move to the next break; } } } } } } } } } }
private void OnSpawn(EntitySpawnEventArgs e) { foreach (EventListener el in Plugins) { if (el.Event == Event.ENTITY_SPAWN) { EntityListener l = el.Listener as EntityListener; l.OnSpawn(e); } } }