|
47 | 47 | import net.fabricmc.loader.api.ModContainer; |
48 | 48 | import net.minecraft.block.Blocks; |
49 | 49 | import net.minecraft.block.entity.BlockEntityType; |
| 50 | +import net.minecraft.block.entity.SignText; |
50 | 51 | import net.minecraft.client.MinecraftClient; |
51 | 52 | import net.minecraft.client.gui.DrawContext; |
52 | 53 | import net.minecraft.client.gui.screen.ChatScreen; |
|
57 | 58 | import net.minecraft.client.render.VertexConsumerProvider; |
58 | 59 | import net.minecraft.client.util.math.MatrixStack; |
59 | 60 | import net.minecraft.item.ItemStack; |
| 61 | +import net.minecraft.nbt.NbtCompound; |
| 62 | +import net.minecraft.nbt.NbtOps; |
60 | 63 | import net.minecraft.network.listener.PacketListener; |
61 | 64 | import net.minecraft.network.packet.Packet; |
62 | 65 | import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket; |
63 | 66 | import net.minecraft.network.packet.s2c.play.BundleS2CPacket; |
| 67 | +import net.minecraft.network.packet.s2c.play.ChunkDeltaUpdateS2CPacket; |
64 | 68 | import net.minecraft.network.packet.s2c.play.CloseScreenS2CPacket; |
65 | 69 | import net.minecraft.screen.slot.Slot; |
66 | 70 | import net.minecraft.screen.slot.SlotActionType; |
@@ -276,18 +280,32 @@ public static <T extends PacketListener> boolean handlePacket(Packet<T> packet) |
276 | 280 |
|
277 | 281 | //noinspection unused |
278 | 282 | String name = packet.getClass().getName().replace("net.minecraft.network.packet.s2c.play.", ""); |
279 | | -// if(!java.util.List.of("PlayerListS2CPacket","WorldTimeUpdateS2CPacket","GameMessageS2CPacket","KeepAliveS2CPacket", "ChunkDataS2CPacket", "UnloadChunkS2CPacket","TeamS2CPacket", "ChunkRenderDistanceCenterS2CPacket", "MessageHeaderS2CPacket", "LightUpdateS2CPacket", "OverlayMessageS2CPacket").contains(name)) LOGGER.info(name); |
| 283 | +// if(!java.util.List.of("PlayerListS2CPacket","WorldTimeUpdateS2CPacket","GameMessageS2CPacket","KeepAliveS2CPacket", "ChunkDataS2CPacket", "UnloadChunkS2CPacket","TeamS2CPacket", "ChunkRenderDistanceCenterS2CPacket", "MessageHeaderS2CPacket", "LightUpdateS2CPacket", "OverlayMessageS2CPacket", "DebugSampleS2CPacket").contains(name)) LOGGER.info(name); |
280 | 284 |
|
281 | 285 | if (CodeClient.location instanceof Dev dev) { |
282 | 286 | try { |
283 | 287 | if (packet instanceof BlockEntityUpdateS2CPacket beu && dev.isInDev(beu.getPos()) && beu.getBlockEntityType() == BlockEntityType.SIGN) { |
284 | | - dev.clearLineStarterCache(); |
| 288 | + NbtCompound compound = beu.getNbt(); |
| 289 | + if(compound.contains("front_text")) { |
| 290 | + SignText text = SignText.CODEC.decode(NbtOps.INSTANCE, beu.getNbt().get("front_text")).getOrThrow().getFirst(); |
| 291 | + if (Plot.lineStarterPattern.matcher(text.getMessage(0, false).getString()).matches()) { |
| 292 | + dev.getLineStartCache().put(beu.getPos(), text); |
| 293 | + } |
| 294 | + } else { |
| 295 | + dev.clearLineStarterCache(); |
| 296 | + } |
285 | 297 | } |
286 | 298 | } catch (ConcurrentModificationException exception) { |
287 | 299 | // Not sure how this comes to happen. My guess it's the getBlockEntity call. |
288 | 300 | // Unfortunately, I don't know what state the game has to be in to make it fail, maybe an unloaded chunk? |
289 | 301 | // It's hard to check for that, apparently. |
290 | 302 | dev.clearLineStarterCache(); |
| 303 | + } catch (IllegalStateException exception) { |
| 304 | + dev.clearLineStarterCache(); |
| 305 | + } |
| 306 | + |
| 307 | + if (packet instanceof ChunkDeltaUpdateS2CPacket update) { |
| 308 | + update.visitUpdates((blockPos, blockState) -> dev.getLineStartCache().remove(blockPos)); |
291 | 309 | } |
292 | 310 | } |
293 | 311 | return (MC.currentScreen instanceof GameMenuScreen || MC.currentScreen instanceof ChatScreen || MC.currentScreen instanceof StateSwitcher) && packet instanceof CloseScreenS2CPacket; |
@@ -465,6 +483,9 @@ public static void reset() { |
465 | 483 | } |
466 | 484 |
|
467 | 485 | public static void onModeChange(Location location) { |
| 486 | + if (location instanceof Dev dev) { |
| 487 | + dev.clearLineStarterCache(); |
| 488 | + } |
468 | 489 | if (Config.getConfig().DevForBuild && (currentAction instanceof None || currentAction instanceof DevForBuild) && location instanceof Build) { |
469 | 490 | currentAction = new DevForBuild(() -> currentAction = new None()); |
470 | 491 | currentAction.init(); |
|
0 commit comments