Modify monster spawning algorithm. Allow all players to have a fair

share of mobs. Number of mobs allowed increases with the number of
nearby players in the area. One player won't hog the entire mob spawn
cap anymore.
dev
sigonasr2 9 years ago
parent aae4497d18
commit 5caa9a237f
  1. BIN
      TwosideKeeper.jar
  2. 15
      src/sig/plugin/TwosideKeeper/MonsterController.java
  3. 1
      src/sig/plugin/TwosideKeeper/TwosideKeeper.java

Binary file not shown.

@ -19,6 +19,7 @@ import org.bukkit.entity.Guardian;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Monster;
import org.bukkit.entity.PigZombie;
import org.bukkit.entity.Player;
import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Zombie;
import org.bukkit.entity.Skeleton.SkeletonType;
@ -58,6 +59,9 @@ public class MonsterController {
return false;
}
}
if (!meetsConditionsToSpawn(ent)) {
return false;
}
if (isZombieLeader(ent)) {
//Zombie leaders have faster movement.
ent.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,Integer.MAX_VALUE,1));
@ -140,6 +144,17 @@ public class MonsterController {
}
}
private static boolean meetsConditionsToSpawn(LivingEntity ent) {
double dist = 999999999;
int nearbyplayers=0;
for (Player p : Bukkit.getOnlinePlayers()) {
double temp = ent.getLocation().distanceSquared(p.getLocation());
if (temp<262144) {nearbyplayers++;}
dist = (temp<dist)?temp:dist;
}
return (dist<262144 && ent.getNearbyEntities(16, 16, 16).size()<nearbyplayers*3);
}
private static boolean meetsConditionsToBeElite(LivingEntity ent) {
if (Math.random()<=TwosideKeeper.ELITE_MONSTER_CHANCE && TwosideKeeper.LAST_ELITE_SPAWN+(72000*4)<TwosideKeeper.getServerTickTime() &&
((ent instanceof Zombie) || ((ent instanceof Skeleton) && ((Skeleton)ent).getSkeletonType()==SkeletonType.WITHER))

@ -934,7 +934,6 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
filesave=getDataFolder(); //Store the location of where our data folder is.
log("Data folder at "+filesave+".",3);
Bukkit.getServer().setSpawnRadius(1);
//log("Spawn Radius is "+Bukkit.getServer().getSpawnRadius(),0);
time_passed+=-Bukkit.getWorld("world").getFullTime();

Loading…
Cancel
Save