use of net.minecraft.world.gen.ChunkProviderServer in project GIRSignals by German-Immersive-Railroading-Community.
the class IChunkloadable method loadChunkAndGetTile.
default boolean loadChunkAndGetTile(World world, BlockPos pos, BiConsumer<T, Chunk> consumer) {
if (pos == null)
return false;
try {
@SuppressWarnings("unchecked") final Callable<Boolean> call = () -> {
TileEntity entity = null;
Chunk chunk = world.getChunkFromBlockCoords(pos);
final boolean flag = !chunk.isLoaded();
if (flag) {
if (world.isRemote) {
ChunkProviderClient client = (ChunkProviderClient) world.getChunkProvider();
chunk = client.loadChunk(chunk.x, chunk.z);
} else {
ChunkProviderServer server = (ChunkProviderServer) world.getChunkProvider();
chunk = server.loadChunk(chunk.x, chunk.z);
}
}
if (chunk == null)
return false;
entity = chunk.getTileEntity(pos, EnumCreateEntityType.IMMEDIATE);
final boolean flag2 = entity != null;
if (flag2) {
consumer.accept((T) entity, chunk);
}
if (flag) {
if (world.isRemote) {
ChunkProviderClient client = (ChunkProviderClient) world.getChunkProvider();
client.unloadChunk(chunk.x, chunk.z);
} else {
ChunkProviderServer server = (ChunkProviderServer) world.getChunkProvider();
server.queueUnload(chunk);
}
}
return flag2;
};
final MinecraftServer mcserver = world.getMinecraftServer();
if (mcserver == null)
return Minecraft.getMinecraft().addScheduledTask(call).get();
return mcserver.callFromMainThread(call).get();
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
use of net.minecraft.world.gen.ChunkProviderServer in project GIRSignals by German-Immersive-Railroading-Community.
the class IChunkloadable method loadChunkAndGetBlock.
default boolean loadChunkAndGetBlock(World world, BlockPos pos, BiConsumer<IBlockState, Chunk> consumer) {
if (pos == null)
return false;
try {
final Callable<Boolean> call = () -> {
IBlockState entity = null;
Chunk chunk = world.getChunkFromBlockCoords(pos);
final boolean flag = !chunk.isLoaded();
if (flag) {
if (world.isRemote) {
ChunkProviderClient client = (ChunkProviderClient) world.getChunkProvider();
chunk = client.loadChunk(chunk.x, chunk.z);
} else {
ChunkProviderServer server = (ChunkProviderServer) world.getChunkProvider();
chunk = server.loadChunk(chunk.x, chunk.z);
}
}
if (chunk == null)
return false;
entity = chunk.getBlockState(pos);
final boolean flag2 = entity != null;
if (flag2) {
consumer.accept(entity, chunk);
}
if (flag) {
if (world.isRemote) {
ChunkProviderClient client = (ChunkProviderClient) world.getChunkProvider();
client.unloadChunk(chunk.x, chunk.z);
} else {
ChunkProviderServer server = (ChunkProviderServer) world.getChunkProvider();
server.queueUnload(chunk);
}
}
return flag2;
};
final MinecraftServer mcserver = world.getMinecraftServer();
if (mcserver == null)
return Minecraft.getMinecraft().addScheduledTask(call).get();
return mcserver.callFromMainThread(call).get();
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
use of net.minecraft.world.gen.ChunkProviderServer in project Crossroads by Crossroads-Development.
the class MultiPistonBase method getEntitiesMultiChunk.
/**
* An alternate version of World#getEntitiesWithinAABBExcludingEntity that checks a 3x3x3 cube of mini chunks (16x16x16 cubes within chunks) for entities.
* This is less efficient than the standard method, but necessary to fix a bug.
*/
private static ArrayList<Entity> getEntitiesMultiChunk(AxisAlignedBB checkBox, World worldIn) {
ArrayList<Entity> found = new ArrayList<Entity>();
int i = MathHelper.floor((checkBox.minX - World.MAX_ENTITY_RADIUS) / 16.0D) - 1;
int j = MathHelper.floor((checkBox.maxX + World.MAX_ENTITY_RADIUS) / 16.0D) + 1;
int k = MathHelper.floor((checkBox.minZ - World.MAX_ENTITY_RADIUS) / 16.0D) - 1;
int l = MathHelper.floor((checkBox.maxZ + World.MAX_ENTITY_RADIUS) / 16.0D) + 1;
int yMin = MathHelper.clamp(MathHelper.floor((checkBox.minY - World.MAX_ENTITY_RADIUS) / 16.0D) - 1, 0, 15);
int yMax = MathHelper.clamp(MathHelper.floor((checkBox.maxY + World.MAX_ENTITY_RADIUS) / 16.0D) + 1, 0, 15);
for (int iLoop = i; iLoop <= j; ++iLoop) {
for (int kLoop = k; kLoop <= l; ++kLoop) {
if (((ChunkProviderServer) worldIn.getChunkProvider()).chunkExists(iLoop, kLoop)) {
Chunk chunk = worldIn.getChunkFromChunkCoords(iLoop, kLoop);
for (int yLoop = yMin; yLoop <= yMax; ++yLoop) {
if (!chunk.getEntityLists()[yLoop].isEmpty()) {
for (Entity entity : chunk.getEntityLists()[yLoop]) {
if (entity.getEntityBoundingBox().intersectsWith(checkBox)) {
found.add(entity);
}
}
}
}
}
}
}
return found;
}
use of net.minecraft.world.gen.ChunkProviderServer in project Engine by VoltzEngine-Project.
the class MassRegistry method getMass.
@Override
public double getMass(World world, int x, int y, int z) {
double mass;
if (world != null) {
//Checks if the chunk is loaded
if (world instanceof WorldServer) {
ChunkProviderServer providerServer = ((WorldServer) world).theChunkProviderServer;
if (!providerServer.chunkExists(x >> 4, z >> 4)) {
return -1;
}
}
Block block = world.getBlock(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof IHasMass) {
mass = ((IHasMass) tile).getMass();
if (mass >= 0) {
return mass;
}
}
mass = getMass(block, meta);
return mass >= 0 ? mass : getMass(block);
}
return -1;
}
use of net.minecraft.world.gen.ChunkProviderServer in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class WorldServerShipManager method loadAndUnloadShips.
private void loadAndUnloadShips() {
QueryableShipData queryableShipData = QueryableShipData.get(world);
// Load the ships that are required immediately.
for (final UUID toLoadID : loadQueue) {
Optional<ShipData> toLoadOptional = queryableShipData.getShip(toLoadID);
if (!toLoadOptional.isPresent()) {
throw new IllegalStateException("No ship found for ID:\n" + toLoadID);
}
ShipData toLoad = toLoadOptional.get();
if (loadedShips.containsKey(toLoadID)) {
throw new IllegalStateException("Tried loading a ShipData that was already loaded?\n" + toLoad);
}
// Remove this ship from the background loading set, if it is in it.
loadingInBackground.remove(toLoadID);
// Finally, load the ship.
if (VSConfig.showAnnoyingDebugOutput) {
System.out.println("Attempting to load ship " + toLoad);
}
PhysicsObject physicsObject = new PhysicsObject(world, toLoad);
PhysicsObject old = loadedShips.put(toLoad.getUuid(), physicsObject);
if (old != null) {
throw new IllegalStateException("How did we already have a ship loaded for " + toLoad);
}
}
loadQueue.clear();
// Load ships that aren't required immediately in the background.
for (final UUID toLoadID : backgroundLoadQueue) {
// Skip if this ship is already being loaded in the background,.
if (loadingInBackground.contains(toLoadID)) {
// Already loading this ship in the background
continue;
}
// Make sure there isn't an already loaded ship with this UUID.
if (loadedShips.containsKey(toLoadID)) {
// continue; // temp, need to fix WorldShipLoadingController.determineLoadAndUnload()
throw new IllegalStateException("Tried loading a ShipData that was already loaded? Ship ID is\n" + toLoadID);
}
// Then try getting the ShipData for this UUID.
Optional<ShipData> toLoadOptional = queryableShipData.getShip(toLoadID);
if (!toLoadOptional.isPresent()) {
throw new IllegalStateException("No ship found for ID:\n" + toLoadID);
}
ShipData toLoad = toLoadOptional.get();
loadingInBackground.add(toLoadID);
if (VSConfig.showAnnoyingDebugOutput) {
System.out.println("Attempting to load " + toLoad + " in the background.");
}
ChunkProviderServer chunkProviderServer = world.getChunkProvider();
for (ChunkPos chunkPos : toLoad.getChunkClaim()) {
@Nonnull Runnable returnTask = () -> {
if (VSConfig.showAnnoyingDebugOutput) {
System.out.println("Loaded ship chunk " + chunkPos);
}
};
chunkProviderServer.loadChunk(chunkPos.x, chunkPos.z, returnTask);
}
}
backgroundLoadQueue.clear();
// Unload far away ships immediately.
for (final UUID toUnloadID : unloadQueue) {
// Make sure we have a ship with this ID that can be unloaded
if (!loadedShips.containsKey(toUnloadID)) {
throw new IllegalStateException("Tried unloading a ShipData that isn't loaded? Ship ID is\n" + toUnloadID);
}
PhysicsObject physicsObject = getPhysObjectFromUUID(toUnloadID);
if (VSConfig.showAnnoyingDebugOutput) {
System.out.println("Attempting to unload " + physicsObject);
}
physicsObject.unload();
boolean success = loadedShips.remove(toUnloadID, physicsObject);
if (!success) {
throw new IllegalStateException("How did we fail to unload " + physicsObject.getShipData());
}
}
unloadQueue.clear();
}
Aggregations