use of com.bergerkiller.generated.net.minecraft.world.level.biome.BiomeSettingsMobsHandle.SpawnRateHandle in project BKCommonLib by bergerhealer.
the class CreaturePreSpawnHandler_Spigot method handleMobsFor.
private static List<Object> handleMobsFor(World world, Object blockposition, List<Object> mobs) {
try {
// There is no use wasting CPU time when no one handles the event!
if (LogicUtil.nullOrEmpty(mobs) || !CommonUtil.hasHandlers(CreaturePreSpawnEvent.getHandlerList())) {
return mobs;
}
// Wrap the parameters and send the event along
BlockPositionHandle pos = BlockPositionHandle.createHandle(blockposition);
// Check all instances of SpawnRateHandle if they need to be cancelled
// If they're cancelled, initialize a new List with those entries omitted
CommonEventFactory eventFactory = CommonPlugin.getInstance().getEventFactory();
List<Object> result = mobs;
int numMobs = mobs.size();
for (int n = 0; n < numMobs; n++) {
SpawnRateHandle handle = SpawnRateHandle.createHandle(mobs.get(n));
EntityType entityType = CommonEntityType.byNMSEntityClass(handle.getEntityClass()).entityType;
if (eventFactory.handleCreaturePreSpawn(world, pos.getX(), pos.getY(), pos.getZ(), entityType)) {
// add this entry to the list.
if (result != mobs) {
result.add(handle.getRaw());
}
} else if (result == mobs) {
// Create a new List of stuff, omit the entry that was cancelled
result = new ArrayList<Object>();
result.addAll(mobs.subList(0, n));
}
}
return result;
} catch (Throwable t) {
Logging.LOGGER.log(Level.SEVERE, "Failed to handle mob pre-spawn event", t);
return mobs;
}
}
Aggregations