Skip to content

Commit 2357119

Browse files
committed
make line starter cache not regenerate by doing anything
1 parent 1d07962 commit 2357119

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

src/main/java/dev/dfonline/codeclient/CodeClient.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import net.fabricmc.loader.api.ModContainer;
4848
import net.minecraft.block.Blocks;
4949
import net.minecraft.block.entity.BlockEntityType;
50+
import net.minecraft.block.entity.SignText;
5051
import net.minecraft.client.MinecraftClient;
5152
import net.minecraft.client.gui.DrawContext;
5253
import net.minecraft.client.gui.screen.ChatScreen;
@@ -57,10 +58,13 @@
5758
import net.minecraft.client.render.VertexConsumerProvider;
5859
import net.minecraft.client.util.math.MatrixStack;
5960
import net.minecraft.item.ItemStack;
61+
import net.minecraft.nbt.NbtCompound;
62+
import net.minecraft.nbt.NbtOps;
6063
import net.minecraft.network.listener.PacketListener;
6164
import net.minecraft.network.packet.Packet;
6265
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
6366
import net.minecraft.network.packet.s2c.play.BundleS2CPacket;
67+
import net.minecraft.network.packet.s2c.play.ChunkDeltaUpdateS2CPacket;
6468
import net.minecraft.network.packet.s2c.play.CloseScreenS2CPacket;
6569
import net.minecraft.screen.slot.Slot;
6670
import net.minecraft.screen.slot.SlotActionType;
@@ -276,18 +280,32 @@ public static <T extends PacketListener> boolean handlePacket(Packet<T> packet)
276280

277281
//noinspection unused
278282
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);
280284

281285
if (CodeClient.location instanceof Dev dev) {
282286
try {
283287
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+
}
285297
}
286298
} catch (ConcurrentModificationException exception) {
287299
// Not sure how this comes to happen. My guess it's the getBlockEntity call.
288300
// Unfortunately, I don't know what state the game has to be in to make it fail, maybe an unloaded chunk?
289301
// It's hard to check for that, apparently.
290302
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));
291309
}
292310
}
293311
return (MC.currentScreen instanceof GameMenuScreen || MC.currentScreen instanceof ChatScreen || MC.currentScreen instanceof StateSwitcher) && packet instanceof CloseScreenS2CPacket;
@@ -465,6 +483,9 @@ public static void reset() {
465483
}
466484

467485
public static void onModeChange(Location location) {
486+
if (location instanceof Dev dev) {
487+
dev.clearLineStarterCache();
488+
}
468489
if (Config.getConfig().DevForBuild && (currentAction instanceof None || currentAction instanceof DevForBuild) && location instanceof Build) {
469490
currentAction = new DevForBuild(() -> currentAction = new None());
470491
currentAction.init();

src/main/java/dev/dfonline/codeclient/dev/InteractionManager.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,27 +87,30 @@ public static BlockPos targetedBlockPos(BlockPos pos) {
8787

8888
public static boolean onBreakBlock(BlockPos pos) {
8989
if (CodeClient.location instanceof Dev dev) {
90-
dev.clearLineStarterCache();
9190
if (!dev.isInDev(pos)) return false;
9291
BlockPos breakPos = isBlockBreakable(pos);
9392
CodeClient.onBreakBlock(dev,pos,breakPos);
94-
if (Config.getConfig().CustomBlockInteractions) {
95-
if (breakPos != null) {
96-
breakCodeBlock(breakPos);
97-
}
93+
if (breakPos != null) {
94+
breakCodeBlock(breakPos);
9895
}
9996
return true;
10097
}
10198
return false;
10299
}
103100

104101
private static void breakCodeBlock(BlockPos pos) {
105-
ClientWorld world = CodeClient.MC.world;
106-
CodeClient.MC.getSoundManager().play(new PositionedSoundInstance(SoundEvents.BLOCK_STONE_BREAK, SoundCategory.BLOCKS, 2, 0.8F, Random.create(), pos));
107-
world.setBlockState(pos, Blocks.AIR.getDefaultState());
108-
world.setBlockState(pos.add(0, 1, 0), Blocks.AIR.getDefaultState());
109-
world.setBlockState(pos.add(-1, 0, 0), Blocks.AIR.getDefaultState());
110-
world.setBlockState(pos.add(0, 0, 1), Blocks.AIR.getDefaultState());
102+
if (CodeClient.location instanceof Dev dev) {
103+
dev.getLineStartCache().remove(pos.west());
104+
}
105+
106+
if (Config.getConfig().CustomBlockInteractions) {
107+
ClientWorld world = CodeClient.MC.world;
108+
CodeClient.MC.getSoundManager().play(new PositionedSoundInstance(SoundEvents.BLOCK_STONE_BREAK, SoundCategory.BLOCKS, 2, 0.8F, Random.create(), pos));
109+
world.setBlockState(pos, Blocks.AIR.getDefaultState());
110+
world.setBlockState(pos.add(0, 1, 0), Blocks.AIR.getDefaultState());
111+
world.setBlockState(pos.add(-1, 0, 0), Blocks.AIR.getDefaultState());
112+
world.setBlockState(pos.add(0, 0, 1), Blocks.AIR.getDefaultState());
113+
}
111114
}
112115

113116
public static boolean onClickSlot(Slot slot, int button, SlotActionType actionType, int syncId, int revision) {

src/main/java/dev/dfonline/codeclient/location/Plot.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
import java.util.regex.Pattern;
1616

1717
public abstract class Plot extends Location {
18+
19+
public static Pattern lineStarterPattern = Pattern.compile("(PLAYER|ENTITY) EVENT|FUNCTION|PROCESS");
20+
1821
/**
1922
* The position the player was at before they were teleported, in any scenario but plot borders.
2023
*/
@@ -168,7 +171,7 @@ public HashMap<BlockPos, SignText> scanForSigns(Pattern name, Pattern scan) {
168171
* Returns null if the plot origin is unknown.
169172
*/
170173
public HashMap<BlockPos, SignText> scanForSigns(Pattern scan) {
171-
return scanForSigns(Pattern.compile("(PLAYER|ENTITY) EVENT|FUNCTION|PROCESS"), scan);
174+
return scanForSigns(lineStarterPattern, scan);
172175
}
173176

174177
/**

0 commit comments

Comments
 (0)