Search in sources :

Example 1 with ChunkProviderClient

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");
}
Also used : ChunkProviderClient(net.minecraft.client.multiplayer.ChunkProviderClient) Chunk(net.minecraft.world.chunk.Chunk)

Example 2 with ChunkProviderClient

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ChunkProviderClient(net.minecraft.client.multiplayer.ChunkProviderClient) ChunkProviderServer(net.minecraft.world.gen.ChunkProviderServer) Chunk(net.minecraft.world.chunk.Chunk) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 3 with ChunkProviderClient

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;
}
Also used : ChunkProviderClient(net.minecraft.client.multiplayer.ChunkProviderClient) IBlockState(net.minecraft.block.state.IBlockState) ChunkProviderServer(net.minecraft.world.gen.ChunkProviderServer) Chunk(net.minecraft.world.chunk.Chunk) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 4 with ChunkProviderClient

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);
                }
            }
        }
    }
}
Also used : ChunkProviderClient(net.minecraft.client.multiplayer.ChunkProviderClient) Minecraft(net.minecraft.client.Minecraft)

Example 5 with ChunkProviderClient

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);
            }
        }
    }
}
Also used : ChunkProviderClient(net.minecraft.client.multiplayer.ChunkProviderClient) Entity(net.minecraft.entity.Entity) Minecraft(net.minecraft.client.Minecraft)

Aggregations

ChunkProviderClient (net.minecraft.client.multiplayer.ChunkProviderClient)7 Chunk (net.minecraft.world.chunk.Chunk)3 ChunkProviderServer (net.minecraft.world.gen.ChunkProviderServer)3 Minecraft (net.minecraft.client.Minecraft)2 MinecraftServer (net.minecraft.server.MinecraftServer)2 StructureRenderer (mchorse.blockbuster_pack.morphs.structure.StructureRenderer)1 IBlockState (net.minecraft.block.state.IBlockState)1 Entity (net.minecraft.entity.Entity)1 Profiler (net.minecraft.profiler.Profiler)1 TileEntity (net.minecraft.tileentity.TileEntity)1 BlockPos (net.minecraft.util.math.BlockPos)1 ChunkPos (net.minecraft.util.math.ChunkPos)1 WorldProvider (net.minecraft.world.WorldProvider)1 WorldProviderSurface (net.minecraft.world.WorldProviderSurface)1 WorldSettings (net.minecraft.world.WorldSettings)1 PlacementSettings (net.minecraft.world.gen.structure.template.PlacementSettings)1 Template (net.minecraft.world.gen.structure.template.Template)1 WorldInfo (net.minecraft.world.storage.WorldInfo)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1