use of io.xol.chunkstories.api.entity.EntityDefinition in project chunkstories by Hugobros3.
the class SpawnEntityCommand method handleCommand.
@Override
public boolean handleCommand(CommandEmitter emitter, Command command, String[] arguments) {
if (!(emitter instanceof Player)) {
emitter.sendMessage("You need to be a player to use this command.");
return true;
}
Player player = (Player) emitter;
if (!emitter.hasPermission("world.spawnEntity")) {
emitter.sendMessage("You don't have the permission.");
return true;
}
if (arguments.length == 0) {
emitter.sendMessage("Syntax: /spawnEntity <entityId> [x y z]");
return false;
}
Location loc = player.getLocation();
if (arguments.length >= 4) {
loc = new Location(player.getWorld(), Double.parseDouble(arguments[1]), Double.parseDouble(arguments[2]), Double.parseDouble(arguments[3]));
}
EntityDefinition entityType;
String entityName = arguments[0];
entityType = server.getContent().entities().getEntityDefinition(entityName);
if (entityType == null) {
emitter.sendMessage("Entity type : " + arguments[0] + " not found in loaded content.");
return true;
}
Entity entity = entityType.create(loc);
entity.setLocation(loc);
loc.getWorld().addEntity(entity);
emitter.sendMessage("#00FFD0" + "Spawned " + entity.getClass().getSimpleName() + " at " + (arguments.length >= 4 ? loc.toString() : player.getName()));
return true;
}
use of io.xol.chunkstories.api.entity.EntityDefinition in project chunkstories by Hugobros3.
the class CulledEntitiesRenderer method renderEntities.
public int renderEntities(RenderingInterface renderer) {
((WorldImplementation) world).entitiesLock.readLock().lock();
// Sort them by type
Map<EntityDefinition, List<EntityRenderable>> renderableEntitiesTypes = new HashMap<EntityDefinition, List<EntityRenderable>>();
for (Entity entity : world.getAllLoadedEntities()) {
if (entity instanceof EntityRenderable) {
EntityRenderable entityRenderable = (EntityRenderable) entity;
List<EntityRenderable> entitiesOfThisType = renderableEntitiesTypes.get(entityRenderable.getDefinition());
if (entitiesOfThisType == null) {
renderableEntitiesTypes.put(entityRenderable.getDefinition(), new ArrayList<EntityRenderable>());
entitiesOfThisType = renderableEntitiesTypes.get(entityRenderable.getDefinition());
}
entitiesOfThisType.add(entityRenderable);
}
}
int entitiesRendered = 0;
for (Entry<EntityDefinition, List<EntityRenderable>> entry : renderableEntitiesTypes.entrySet()) {
List<EntityRenderable> entities = entry.getValue();
// Caches entity renderers until we f12
if (!entityRenderers.containsKey(entry.getKey()))
entityRenderers.put(entry.getKey(), entities.get(0).getEntityRenderer());
EntityRenderer<? extends EntityRenderable> entityRenderer = entityRenderers.get(entry.getKey());
if (entityRenderer == null)
continue;
try {
int e = entityRenderer.renderEntities(renderer, new EntitiesRendererIterator<>(renderer, entities));
entitiesRendered += e;
} catch (Throwable e) {
System.out.println("Exception rendering entities " + entities.get(0).getClass().getSimpleName() + " using " + entityRenderer.getClass().getSimpleName());
e.printStackTrace();
}
}
((WorldImplementation) world).entitiesLock.readLock().unlock();
return entitiesRendered;
}
Aggregations