Created
January 29, 2014 20:06
-
-
Save aikar/8695871 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static boolean attemptSpawn(Entity entity) { | |
Location loc = entity.getLocation(); | |
long now = System.currentTimeMillis(); | |
if (now - lastSpawnAttempt >= 200) { | |
lastSpawnAttempt = now; | |
final MetaApi.MetaMap worldMetaMap = MetaApi.getWorldMetaMap(entity.getWorld()); | |
for (CustomMob customMob : spawnableList) { | |
String metaKey = "survivalRespawn_" + customMob.customType; | |
final Object o = worldMetaMap.get(metaKey); | |
Long nextSpawn = o instanceof Long ? (Long) o : now; | |
if (customMob.spawnRate == 0 || nextSpawn > now) { | |
continue; | |
} | |
if (!customMob.canSpawn(loc)) { | |
continue; | |
} | |
float randChance = Util.RANDOM.nextFloat() * 100; | |
if (randChance > customMob.spawnRate) { | |
continue; | |
} | |
boolean tooClose = false; | |
for (Entity playerCheck : entity.getNearbyEntities(customMob.minPlayerSpawn, | |
256, | |
customMob.minPlayerSpawn)) { | |
if (playerCheck instanceof Player) { | |
tooClose = true; | |
break; | |
} | |
if (playerCheck.getType() == customMob.baseType) { | |
if (getType(playerCheck) == customMob) { | |
tooClose = true; | |
break; | |
} | |
} | |
} | |
if (tooClose) { | |
continue; | |
} | |
if (Wastelands.isWastelands(entity.getWorld())) { | |
if (Wastelands.isSpawnVicinity(entity.getLocation(), 64)) { | |
continue; | |
} | |
} | |
// Finally can spawn | |
nextSpawn = now + Util.rand((int) (customMob.respawnRate * 0.9), (int) (customMob.respawnRate * 1.1)); | |
worldMetaMap.put(metaKey, nextSpawn); | |
customMob.spawn(loc); | |
return true; | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment