Initial code #2

This commit is contained in:
2026-02-07 20:40:45 +00:00
parent 005cad843f
commit e5226b3901

View File

@@ -0,0 +1,46 @@
package net.ardakaz.simpleMobSpawningOptimizer;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.Random;
import java.lang.Math;
import static org.bukkit.Bukkit.getSimulationDistance;
public class SimpleMobSpawningOptimizer extends JavaPlugin implements Listener {
Random random = new Random();
int mobsSpawned = 0;
int mobsNotSpawned = 0;
@Override
public void onEnable() {
// Plugin startup logic
getServer().getPluginManager().registerEvents(this, this);
}
@Override
public void onDisable() {
// Plugin shutdown logic
getLogger().info(mobsSpawned + " mobs have been spawned, " + mobsNotSpawned + " mob spawns have been cancelled.");
}
@EventHandler
public void onCreatureSpawn(CreatureSpawnEvent event) {
int currentSimulationDistance = getSimulationDistance();
int normalSimulationDistance = 10;
double mobPercentage = (Math.PI * Math.pow(currentSimulationDistance, 2)) / (Math.PI * Math.pow(normalSimulationDistance, 2));
if (random.nextDouble() > mobPercentage) {
event.setCancelled(true);
mobsNotSpawned += 1;
}
else {
mobsSpawned += 1;
}
}
}