use of com.bergerkiller.generated.net.minecraft.server.BiomeBaseHandle.BiomeMetaHandle in project BKCommonLib by bergerhealer.
the class CommonEventFactory method handleCreaturePreSpawn.
/**
* Handles the spawning of creatures on the server
*
* @param world
* @param x
* @param y
* @param z
* @param inputTypes to process and fire events for
* @return a list of mobs to spawn
*/
public List<BiomeMetaHandle> handleCreaturePreSpawn(World world, int x, int y, int z, List<BiomeMetaHandle> inputTypes) {
// Shortcuts
if (LogicUtil.nullOrEmpty(inputTypes) || !CommonUtil.hasHandlers(CreaturePreSpawnEvent.getHandlerList())) {
return inputTypes;
}
// Start processing the elements
creaturePreSpawnMobs.clear();
for (BiomeMetaHandle inputMeta : inputTypes) {
final EntityType oldEntityType = CommonEntityType.byNMSEntityClass(inputMeta.getEntityClass()).entityType;
// Set up the event
creaturePreSpawnEvent.cancelled = false;
creaturePreSpawnEvent.spawnLocation.setWorld(world);
creaturePreSpawnEvent.spawnLocation.setX(x);
creaturePreSpawnEvent.spawnLocation.setY(y);
creaturePreSpawnEvent.spawnLocation.setZ(z);
creaturePreSpawnEvent.spawnLocation.setYaw(0.0f);
creaturePreSpawnEvent.spawnLocation.setPitch(0.0f);
creaturePreSpawnEvent.entityType = oldEntityType;
creaturePreSpawnEvent.minSpawnCount = inputMeta.getMinSpawnCount();
creaturePreSpawnEvent.maxSpawnCount = inputMeta.getMaxSpawnCount();
// Raise it and handle spawn cancel
if (CommonUtil.callEvent(creaturePreSpawnEvent).isCancelled() || (creaturePreSpawnEvent.minSpawnCount == 0 && creaturePreSpawnEvent.maxSpawnCount == 0)) {
continue;
}
// Handle a possibly changed entity type
final Class<?> entityClass;
if (oldEntityType == creaturePreSpawnEvent.entityType) {
entityClass = inputMeta.getEntityClass();
} else {
entityClass = CommonEntityType.byEntityType(creaturePreSpawnEvent.entityType).nmsType.getType();
}
// Unknown or unsupported Entity Type - ignore spawning
if (entityClass == null) {
continue;
}
// Add element to buffer
final BiomeMetaHandle outputMeta = creaturePreSpawnMobs.add();
outputMeta.setEntityClass(entityClass);
outputMeta.setMinSpawnCount(creaturePreSpawnEvent.minSpawnCount);
outputMeta.setMaxSpawnCount(creaturePreSpawnEvent.maxSpawnCount);
outputMeta.setChance(inputMeta.getChance());
}
return creaturePreSpawnMobs;
}
use of com.bergerkiller.generated.net.minecraft.server.BiomeBaseHandle.BiomeMetaHandle in project BKCommonLib by bergerhealer.
the class ChunkProviderServerHook method getMobsFor.
@HookMethod("public List<BiomeBase.BiomeMeta> getBiomeSpawnInfo:???(EnumCreatureType enumcreaturetype, BlockPosition blockposition)")
public List<?> getMobsFor(Object enumcreaturetype, Object blockposition) {
List<?> mobs = base.getMobsFor(enumcreaturetype, blockposition);
if (CommonPlugin.hasInstance()) {
// 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);
org.bukkit.World world = getWorld();
List<BiomeMetaHandle> mobsHandles = new ConvertingList<BiomeMetaHandle>(mobs, BiomeMetaHandle.T.getHandleConverter());
mobsHandles = CommonPlugin.getInstance().getEventFactory().handleCreaturePreSpawn(world, pos.getX(), pos.getY(), pos.getZ(), mobsHandles);
return new ConvertingList<Object>(mobsHandles, BiomeMetaHandle.T.getHandleConverter().reverse());
} else {
return mobs;
}
}
Aggregations