Search in sources :

Example 1 with PacketRequestData

use of com.builtbroken.mc.core.network.packet.callback.chunk.PacketRequestData in project Engine by VoltzEngine-Project.

the class ClientProxy method clientUpdate.

@SubscribeEvent
public void clientUpdate(TickEvent.WorldTickEvent event) {
    if (///TODO reduce check to every 10 ticks
    Engine.enableExtendedMetaPacketSync) {
        try {
            if (event.side == Side.CLIENT) {
                Minecraft mc = Minecraft.getMinecraft();
                if (mc != null) {
                    EntityPlayer player = mc.thePlayer;
                    World world = mc.theWorld;
                    if (player != null && world != null) {
                        if (ExtendedBlockDataManager.CLIENT.dimID != world.provider.dimensionId) {
                            ExtendedBlockDataManager.CLIENT.clear();
                            ExtendedBlockDataManager.CLIENT.dimID = world.provider.dimensionId;
                        }
                        int renderDistance = mc.gameSettings.renderDistanceChunks + 2;
                        int centerX = ((int) Math.floor(player.posX)) >> 4;
                        int centerZ = ((int) Math.floor(player.posZ)) >> 4;
                        //Clear out chunks outside of render distance
                        List<ChunkData> chunksToRemove = new ArrayList();
                        for (ChunkData data : ExtendedBlockDataManager.CLIENT.chunks.values()) {
                            if (Math.abs(data.position.chunkXPos - centerX) > renderDistance || Math.abs(data.position.chunkZPos - centerZ) > renderDistance) {
                                chunksToRemove.add(data);
                            }
                        }
                        for (ChunkData data : chunksToRemove) {
                            ExtendedBlockDataManager.CLIENT.chunks.remove(data.position);
                        }
                        renderDistance = mc.gameSettings.renderDistanceChunks;
                        for (int x = centerX - renderDistance; x < centerX + renderDistance; x++) {
                            for (int z = centerZ - renderDistance; z < centerZ + renderDistance; z++) {
                                ChunkData chunkData = ExtendedBlockDataManager.CLIENT.getChunk(x, z);
                                if (chunkData == null) {
                                    Engine.instance.packetHandler.sendToServer(new PacketRequestData(world.provider.dimensionId, x, z, 0));
                                }
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            Engine.logger().error("Unexpected error while updating client chunk data state", e);
        }
    }
}
Also used : ChunkData(com.builtbroken.mc.lib.world.map.data.ChunkData) PacketRequestData(com.builtbroken.mc.core.network.packet.callback.chunk.PacketRequestData) ArrayList(java.util.ArrayList) EntityPlayer(net.minecraft.entity.player.EntityPlayer) World(net.minecraft.world.World) Minecraft(net.minecraft.client.Minecraft) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Aggregations

PacketRequestData (com.builtbroken.mc.core.network.packet.callback.chunk.PacketRequestData)1 ChunkData (com.builtbroken.mc.lib.world.map.data.ChunkData)1 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)1 ArrayList (java.util.ArrayList)1 Minecraft (net.minecraft.client.Minecraft)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 World (net.minecraft.world.World)1