use of com.builtbroken.mc.lib.world.map.data.ChunkData 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);
}
}
}
Aggregations