Counts mobs in unloaded chunks better.

https://github.com/BentoBoxWorld/Greenhouses/issues/18
This commit is contained in:
tastybento 2019-09-14 18:09:26 -07:00
parent 49c0689e78
commit 0b10dadc2e
1 changed files with 17 additions and 14 deletions

View File

@ -6,6 +6,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
@ -104,21 +105,23 @@ public class EcoSystemManager {
} }
} }
} }
long sum = gh.getWorld().getEntities().stream() Bukkit.getScheduler().runTaskLater(addon.getPlugin(), () -> {
.filter(e -> gh.getBiomeRecipe().getMobTypes().contains(e.getType())) long sum = gh.getWorld().getEntities().stream()
.filter(e -> gh.contains(e.getLocation())).count(); .filter(e -> gh.getBiomeRecipe().getMobTypes().contains(e.getType()))
// Get the blocks in the greenhouse where spawning could occur .filter(e -> gh.contains(e.getLocation())).count();
Iterator<Block> it = getAvailableBlocks(gh).iterator(); // Get the blocks in the greenhouse where spawning could occur
// Check if the greenhouse is full Iterator<Block> it = getAvailableBlocks(gh).iterator();
while (it.hasNext() && (sum == 0 || gh.getArea() / sum >= gh.getBiomeRecipe().getMobLimit())) { // Check if the greenhouse is full
// Spawn something if chance says so while (it.hasNext() && (sum == 0 || gh.getArea() / sum >= gh.getBiomeRecipe().getMobLimit())) {
if (gh.getBiomeRecipe().spawnMob(it.next())) { // Spawn something if chance says so
// Add a mob to the sum in the greenhouse if (gh.getBiomeRecipe().spawnMob(it.next())) {
sum++; // Add a mob to the sum in the greenhouse
sum++;
}
} }
} // Unload chunks again
// Unload chunks again chunks.forEach(p -> gh.getWorld().unloadChunk(p.x, p.z));
chunks.forEach(p -> gh.getWorld().unloadChunk(p.x, p.z)); }, 20L);
} }
/** /**