From 9ad02a35c95f3b732749ad47ffb3597fcb720ffd Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Thu, 13 Mar 2025 14:58:41 +0700 Subject: [PATCH] ?: add debug lines to the chunk setblock to see more clearly about what is causing error --- build-number.txt | 2 +- .../chomens_bot/chunk/ChunkColumn.java | 33 +++++++++++++++---- .../chomens_bot/plugins/WorldPlugin.java | 6 +++- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/build-number.txt b/build-number.txt index 8542cbbf..a586f535 100644 --- a/build-number.txt +++ b/build-number.txt @@ -1 +1 @@ -1779 \ No newline at end of file +1780 \ No newline at end of file diff --git a/src/main/java/me/chayapak1/chomens_bot/chunk/ChunkColumn.java b/src/main/java/me/chayapak1/chomens_bot/chunk/ChunkColumn.java index 4bd3f756..1b7768b9 100644 --- a/src/main/java/me/chayapak1/chomens_bot/chunk/ChunkColumn.java +++ b/src/main/java/me/chayapak1/chomens_bot/chunk/ChunkColumn.java @@ -2,18 +2,23 @@ package me.chayapak1.chomens_bot.chunk; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; +import me.chayapak1.chomens_bot.Bot; import me.chayapak1.chomens_bot.data.chunk.ChunkPos; +import net.kyori.adventure.text.Component; import org.geysermc.mcprotocollib.protocol.codec.MinecraftTypes; import org.geysermc.mcprotocollib.protocol.data.game.chunk.ChunkSection; // Author: hhhzzzsss public class ChunkColumn { + private final Bot bot; + public final ChunkPos pos; public final ChunkSection[] chunks; private final int minY; - public ChunkColumn (ChunkPos chunkPos, byte[] data, int worldHeight, int minY) { + public ChunkColumn (Bot bot, ChunkPos chunkPos, byte[] data, int worldHeight, int minY) { + this.bot = bot; this.pos = chunkPos; this.minY = minY; @@ -45,11 +50,27 @@ public class ChunkColumn { if (yIndex >= chunks.length) return; - if (chunks[yIndex] == null) { - chunks[yIndex] = new ChunkSection(); - chunks[yIndex].setBlock(0, 0, 0, 0); - } + try { + if (chunks[yIndex] == null) { + chunks[yIndex] = new ChunkSection(); + chunks[yIndex].setBlock(0, 0, 0, 0); + } - chunks[yIndex].setBlock(x, y & 15, z, id); + chunks[yIndex].setBlock(x, y & 15, z, id); + } catch (Exception e) { + // passing bot just for debugging? really? + bot.logger.error( + Component.translatable( + "Failed to set block at %s %s %s with state %s!", + + Component.text(x), + Component.text(y), + Component.text(z), + + Component.text(id) + ) + ); + bot.logger.error(e); + } } } diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/WorldPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/WorldPlugin.java index 4a99ddfb..b2dec206 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/WorldPlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/WorldPlugin.java @@ -18,6 +18,8 @@ import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.level.*; import java.util.*; public class WorldPlugin extends Bot.Listener { + private final Bot bot; + public int minY = 0; public int maxY = 256; @@ -30,6 +32,8 @@ public class WorldPlugin extends Bot.Listener { private final List listeners = new ArrayList<>(); public WorldPlugin (Bot bot) { + this.bot = bot; + bot.addListener(this); } @@ -90,7 +94,7 @@ public class WorldPlugin extends Bot.Listener { private void packetReceived (ClientboundLevelChunkWithLightPacket packet) { final ChunkPos pos = new ChunkPos(packet.getX(), packet.getZ()); - final ChunkColumn column = new ChunkColumn(pos, packet.getChunkData(), maxY, minY); + final ChunkColumn column = new ChunkColumn(bot, pos, packet.getChunkData(), maxY, minY); chunks.put(pos, column); }