@Override public void unloadChunk(int x, int y, int z, boolean save) { SpoutRegion r = this.getRegionFromChunk(x, y, z, LoadOption.NO_LOAD); if (r != null) { r.unloadChunk(x, y, z, save); } }
protected SpoutColumn getColumn(int x, int z, LoadOption loadopt, boolean sync) { long key = IntPairHashed.key(x, z); SpoutColumn column = columns.get(key); if (column != null || !loadopt.loadIfNeeded()) { return column; } column = loadColumn(x, z); if (column != null || !loadopt.generateIfNeeded()) { return column; } int[][] height = this.getGenerator().getSurfaceHeight(this, x, z); int h = (height[7][7] >> Chunk.BLOCKS.BITS); SpoutRegion r = getRegionFromChunk(x, h, z, loadopt); if (r == null) { throw new IllegalStateException( "Unable to generate region for new column and load option " + loadopt); } r.getRegionGenerator().generateColumn(x, z, sync, true); column = getColumn(x, z, LoadOption.LOAD_ONLY); if (column == null) { throw new IllegalStateException("Unable to generate column " + x + ", " + z); } return column; }
@Override public void saveChunk(int x, int y, int z) { SpoutRegion r = this.getRegionFromChunk(x, y, z, LoadOption.NO_LOAD); if (r != null) { r.saveChunk(x, y, z); } }
/** Spawns an entity into the world. Fires off a cancellable EntitySpawnEvent */ @Override public void spawnEntity(Entity e) { if (e.isSpawned()) { throw new IllegalArgumentException("Cannot spawn an entity that is already spawned!"); } SpoutRegion region = (SpoutRegion) e.getRegion(); region.addEntity(e); }
@Override public SpoutChunk getChunk(int x, int y, int z, LoadOption loadopt) { SpoutRegion region = getRegionFromChunk(x, y, z, loadopt); if (region != null) { return region.getChunk(x, y, z, loadopt); } else if (loadopt.loadIfNeeded() && loadopt.generateIfNeeded()) { getEngine() .getLogger() .info("Warning unable to load region: " + x + ", " + y + ", " + z + ":" + loadopt); } return null; }
/** Spawns an entity into the world. Fires off a cancellable EntitySpawnEvent */ public void spawnEntity(Entity e, int entityID) { if (e.isSpawned()) { throw new IllegalArgumentException("Cannot spawn an entity that is already spawned!"); } SpoutRegion region = (SpoutRegion) e.getRegion(); if (region == null) { throw new IllegalStateException("Cannot spawn an entity that has a null region!"); } if (region.getEntityManager().isSpawnable((SpoutEntity) e)) { if (entityID > -1) { if (getEngine().getPlatform() == Platform.CLIENT) { ((SpoutEntity) e).setId(entityID); } else { throw new IllegalArgumentException("Can not set entity id's manually"); } } EntitySpawnEvent event = getEngine() .getEventManager() .callEvent(new EntitySpawnEvent(e, e.getScene().getPosition())); if (event.isCancelled()) { return; } region.getEntityManager().addEntity((SpoutEntity) e); // Alert world components that an entity entered for (Component component : values()) { if (component instanceof WorldComponent) { ((WorldComponent) component).onSpawn(event); } } // Alert entity components that their owner spawned for (Component component : e.values()) { if (component instanceof EntityComponent) { ((EntityComponent) component).onSpawned(event); } } } else { throw new IllegalStateException("Cannot spawn an entity that already has an id!"); } }
@Override public void queueChunkForGeneration(final Vector3 chunk) { final int rx = (chunk.getFloorX() >> Region.CHUNKS.BITS); final int ry = (chunk.getFloorY() >> Region.CHUNKS.BITS); final int rz = (chunk.getFloorZ() >> Region.CHUNKS.BITS); SpoutRegion region = getRegion(rx, ry, rz, LoadOption.NO_LOAD); if (region != null) { region.queueChunkForGeneration(chunk); } else { Spout.getScheduler() .scheduleSyncDelayedTask( this, new Runnable() { @Override public void run() { SpoutRegion region = getRegion(rx, ry, rz, LoadOption.LOAD_GEN); region.queueChunkForGeneration(chunk); } }); } }