From 9965c6a389b3bfd7e18848bf75d09b7c1b98c16d Mon Sep 17 00:00:00 2001 From: EOT3000 <43685885+EOT3000@users.noreply.github.com> Date: Sat, 12 Oct 2019 19:07:55 -0400 Subject: [PATCH] Decrease cpu load to 30%. --- .../java/world/JavaChunkDataTranslator.java | 6 ++- .../geysermc/connector/utils/ChunkUtils.java | 42 ++++++++++++------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java index bab7ceebdc1..309138b34f2 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java @@ -62,7 +62,11 @@ public void translate(ServerChunkDataPacket packet, GeyserSession session) { levelChunkPacket.setChunkX(packet.getColumn().getX()); levelChunkPacket.setChunkZ(packet.getColumn().getZ()); levelChunkPacket.setData(payload); - session.getUpstream().sendPacket(levelChunkPacket); + try { + session.getUpstream().sendPacket(levelChunkPacket); + } catch (Exception e) { + //Usually a connection has been closed. + } session.getChunkCache().addToCache(packet.getColumn()); } catch (Exception ex) { ex.printStackTrace(); diff --git a/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java b/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java index 77f703338c9..afac9e5f206 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java @@ -20,31 +20,41 @@ public static ChunkData translateToBedrock(Column column) { chunkData.sections[i] = new ChunkSection(); } - for (int chunkY = 0; chunkY < chunkSectionCount; chunkY++) { - Chunk chunk = chunks[chunkY]; + try { + for (int chunkY = 0; chunkY < chunkSectionCount; chunkY++) { + Chunk chunk = chunks[chunkY]; - if (chunk == null || chunk.isEmpty()) - continue; + if (chunk == null || chunk.isEmpty()) + continue; - BlockStorage storage = chunk.getBlocks(); - ChunkSection section = chunkData.sections[chunkY]; + BlockStorage storage = chunk.getBlocks(); + ChunkSection section = chunkData.sections[chunkY]; - for (int x = 0; x < 16; x++) { - for (int y = 0; y < 16; y++) { - for (int z = 0; z < 16; z++) { - BlockState blockState = storage.get(x, y, z); - BlockEntry block = TranslatorsInit.getBlockTranslator().getBedrockBlock(blockState); + for (int x = 0; x < 16; x++) { + for (int y = 0; y < 16; y++) { + for (int z = 0; z < 16; z++) { + BlockState blockState = storage.get(x, y, z); + BlockEntry block = TranslatorsInit.getBlockTranslator().getBedrockBlock(blockState); - section.getBlockStorageArray()[0].setFullBlock(ChunkSection.blockPosition(x, y, z), - block.getBedrockId() << 4 | block.getBedrockData()); + section.getBlockStorageArray()[0].setFullBlock(ChunkSection.blockPosition(x, y, z), + block.getBedrockId() << 4 | block.getBedrockData()); - if (block.getJavaIdentifier().contains("waterlogged=true")) { - section.getBlockStorageArray()[1].setFullBlock(ChunkSection.blockPosition(x, y, z), - 9 << 4); // water id + if (block.getJavaIdentifier().contains("waterlogged=true")) { + section.getBlockStorageArray()[1].setFullBlock(ChunkSection.blockPosition(x, y, z), + 9 << 4); // water id + } } + + Thread.sleep(0, 3000); } + + Thread.sleep(0, 15000); } + + Thread.sleep(0, 30000); } + } catch (InterruptedException e) { + //Shouldn't happen } return chunkData; }