use of net.minecraft.client.multiplayer.ChunkProviderClient in project LiquidBouncePlus by WYSI-Foundation.
the class WDL method saveChunks.
/**
* Calls saveChunk for all currently loaded chunks
*
* @throws IllegalAccessException
* @throws IllegalArgumentException
*/
public static void saveChunks(GuiWDLSaveProgress progressScreen) throws IllegalArgumentException, IllegalAccessException {
if (!WDLPluginChannels.canDownloadAtAll()) {
return;
}
WDLMessages.chatMessageTranslated(WDLMessageTypes.SAVING, "wdl.messages.saving.savingChunks");
// Get the ChunkProviderClient from WorldClient
ChunkProviderClient chunkProvider = (ChunkProviderClient) worldClient.getChunkProvider();
// Get the list of loaded chunks
List<?> chunks = ReflectionUtils.stealAndGetField(chunkProvider, List.class);
progressScreen.startMajorTask(I18n.format("wdl.saveProgress.chunk.title"), chunks.size());
for (int currentChunk = 0; currentChunk < chunks.size(); currentChunk++) {
Chunk c = (Chunk) chunks.get(currentChunk);
if (c != null) {
// Serverside restrictions check
if (!WDLPluginChannels.canSaveChunk(c)) {
continue;
}
progressScreen.setMinorTaskProgress(I18n.format("wdl.saveProgress.chunk.saving", c.xPosition, c.zPosition), currentChunk);
saveChunk(c);
}
}
WDLMessages.chatMessageTranslated(WDLMessageTypes.SAVING, "wdl.messages.saving.chunksSaved");
}
use of net.minecraft.client.multiplayer.ChunkProviderClient 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.client.multiplayer.ChunkProviderClient 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.client.multiplayer.ChunkProviderClient in project tweakeroo by maruohon.
the class CameraUtils method markChunksForRebuild.
public static void markChunksForRebuild(ViewFrustum storage, int chunkX, int chunkZ, int lastChunkX, int lastChunkZ) {
if (chunkX == lastChunkX && chunkZ == lastChunkZ) {
return;
}
Minecraft mc = GameUtils.getClient();
ChunkProviderClient provider = mc.world.getChunkProvider();
final int viewDistance = GameUtils.getRenderDistanceChunks();
if (chunkX != lastChunkX) {
final int minCX = chunkX > lastChunkX ? lastChunkX + viewDistance : chunkX - viewDistance;
final int maxCX = chunkX > lastChunkX ? chunkX + viewDistance : lastChunkX - viewDistance;
for (int cx = minCX; cx <= maxCX; ++cx) {
for (int cz = chunkZ - viewDistance; cz <= chunkZ + viewDistance; ++cz) {
if (provider.isChunkGeneratedAt(cx, cz)) {
int x = cx << 4;
int z = cz << 4;
storage.markBlocksForUpdate(x, 0, z, x, 255, z, false);
}
}
}
}
if (chunkZ != lastChunkZ) {
final int minCZ = chunkZ > lastChunkZ ? lastChunkZ + viewDistance : chunkZ - viewDistance;
final int maxCZ = chunkZ > lastChunkZ ? chunkZ + viewDistance : lastChunkZ - viewDistance;
for (int cz = minCZ; cz <= maxCZ; ++cz) {
for (int cx = chunkX - viewDistance; cx <= chunkX + viewDistance; ++cx) {
if (provider.isChunkGeneratedAt(cx, cz)) {
int x = cx << 4;
int z = cz << 4;
storage.markBlocksForUpdate(x, 0, z, x, 255, z, false);
}
}
}
}
}
use of net.minecraft.client.multiplayer.ChunkProviderClient in project tweakeroo by maruohon.
the class CameraUtils method markChunksForRebuildOnDeactivation.
public static void markChunksForRebuildOnDeactivation(int lastChunkX, int lastChunkZ) {
Minecraft mc = GameUtils.getClient();
Entity entity = EntityUtils.getCameraEntity();
ChunkProviderClient provider = mc.world.getChunkProvider();
final int viewDistance = GameUtils.getRenderDistanceChunks();
final int chunkX = entity.chunkCoordX;
final int chunkZ = entity.chunkCoordZ;
final int minCameraCX = lastChunkX - viewDistance;
final int maxCameraCX = lastChunkX + viewDistance;
final int minCameraCZ = lastChunkZ - viewDistance;
final int maxCameraCZ = lastChunkZ + viewDistance;
final int minCX = chunkX - viewDistance;
final int maxCX = chunkX + viewDistance;
final int minCZ = chunkZ - viewDistance;
final int maxCZ = chunkZ + viewDistance;
for (int cz = minCZ; cz <= maxCZ; ++cz) {
for (int cx = minCX; cx <= maxCX; ++cx) {
// Mark all chunks that were not in free camera range
if ((cx < minCameraCX || cx > maxCameraCX || cz < minCameraCZ || cz > maxCameraCZ) && provider.isChunkGeneratedAt(cx, cz)) {
int x = cx << 4;
int z = cz << 4;
mc.world.markBlockRangeForRenderUpdate(x, 0, z, x, 255, z);
}
}
}
}
Aggregations