Skip to content

Commit 69141e0

Browse files
committed
random cache invalidation and formatting
1 parent feb0167 commit 69141e0

2 files changed

Lines changed: 77 additions & 64 deletions

File tree

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
2323
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
2424
import net.minecraft.block.Blocks;
25+
import net.minecraft.block.entity.SignBlockEntity;
2526
import net.minecraft.client.MinecraftClient;
2627
import net.minecraft.client.gui.screen.ChatScreen;
2728
import net.minecraft.client.gui.screen.GameMenuScreen;
@@ -30,6 +31,7 @@
3031
import net.minecraft.client.util.math.MatrixStack;
3132
import net.minecraft.network.listener.PacketListener;
3233
import net.minecraft.network.packet.Packet;
34+
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
3335
import net.minecraft.network.packet.s2c.play.CloseScreenS2CPacket;
3436
import net.minecraft.util.Identifier;
3537
import net.minecraft.util.math.BlockPos;
@@ -72,6 +74,13 @@ public static <T extends PacketListener> boolean handlePacket(Packet<T> packet)
7274

7375
String name = packet.getClass().getName().replace("net.minecraft.network.packet.s2c.play.", "");
7476
// if(!java.util.List.of("PlayerListS2CPacket","WorldTimeUpdateS2CPacket","GameMessageS2CPacket","KeepAliveS2CPacket", "ChunkDataS2CPacket", "UnloadChunkS2CPacket","TeamS2CPacket", "ChunkRenderDistanceCenterS2CPacket", "MessageHeaderS2CPacket", "LightUpdateS2CPacket", "OverlayMessageS2CPacket").contains(name)) LOGGER.info(name);
77+
78+
if (CodeClient.location instanceof Dev dev &&
79+
packet instanceof BlockEntityUpdateS2CPacket beu &&
80+
MC.world != null &&
81+
MC.world.getBlockEntity(beu.getPos()) instanceof SignBlockEntity) {
82+
dev.clearLineStarterCache();
83+
}
7584
return (MC.currentScreen instanceof GameMenuScreen || MC.currentScreen instanceof ChatScreen || MC.currentScreen instanceof StateSwitcher) && packet instanceof CloseScreenS2CPacket;
7685
}
7786

@@ -173,7 +182,7 @@ public static void reset() {
173182
}
174183

175184
public static void onModeChange(Location location) {
176-
if(Config.getConfig().DevForBuild && (currentAction instanceof None || currentAction instanceof DevForBuild) && location instanceof Build) {
185+
if (Config.getConfig().DevForBuild && (currentAction instanceof None || currentAction instanceof DevForBuild) && location instanceof Build) {
177186
currentAction = new DevForBuild(() -> currentAction = new None());
178187
currentAction.init();
179188
}

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

Lines changed: 67 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public static BlockPos targetedBlockPos(BlockPos pos) {
9494

9595
public static boolean onBreakBlock(BlockPos pos) {
9696
if (CodeClient.location instanceof Dev plot) {
97+
plot.clearLineStarterCache();
9798
if (!plot.isInCodeSpace(pos.getX(), pos.getZ())) return false;
9899
if (CodeClient.MC.world.getBlockState(pos).getBlock() == Blocks.CHEST) {
99100
ChestPeeker.invalidate();
@@ -129,79 +130,81 @@ private static void breakCodeBlock(BlockPos pos) {
129130
}
130131

131132
public static boolean onClickSlot(Slot slot, int button, SlotActionType actionType, int syncId, int revision) {
132-
if (!slot.hasStack()) return false;
133-
ItemStack item = slot.getStack();
134-
if (!item.hasNbt()) return false;
135-
NbtCompound nbt = item.getNbt();
136-
if (nbt != null && !nbt.contains("PublicBukkitValues")) return false;
137-
if (nbt != null && nbt.get("PublicBukkitValues") instanceof NbtCompound bukkitValues) {
138-
if (!bukkitValues.contains("hypercube:varitem")) return false;
139-
try {
140-
if (bukkitValues.get("hypercube:varitem") instanceof NbtString varItem) {
141-
if (!Config.getConfig().CustomTagInteraction) return false;
142-
if (actionType == SlotActionType.PICKUP_ALL) return false;
143-
JsonElement varElement = JsonParser.parseString(varItem.asString());
144-
if (!varElement.isJsonObject()) return false;
145-
JsonObject varObject = (JsonObject) varElement;
146-
if (!(Objects.equals(varObject.get("id").getAsString(), "bl_tag"))) return false;
133+
if (CodeClient.location instanceof Dev) {
134+
if (!slot.hasStack()) return false;
135+
ItemStack item = slot.getStack();
136+
if (!item.hasNbt()) return false;
137+
NbtCompound nbt = item.getNbt();
138+
if (nbt != null && !nbt.contains("PublicBukkitValues")) return false;
139+
if (nbt != null && nbt.get("PublicBukkitValues") instanceof NbtCompound bukkitValues) {
140+
if (!bukkitValues.contains("hypercube:varitem")) return false;
141+
try {
142+
if (bukkitValues.get("hypercube:varitem") instanceof NbtString varItem) {
143+
if (!Config.getConfig().CustomTagInteraction) return false;
144+
if (actionType == SlotActionType.PICKUP_ALL) return false;
145+
JsonElement varElement = JsonParser.parseString(varItem.asString());
146+
if (!varElement.isJsonObject()) return false;
147+
JsonObject varObject = (JsonObject) varElement;
148+
if (!(Objects.equals(varObject.get("id").getAsString(), "bl_tag"))) return false;
147149

148-
Int2ObjectMap<ItemStack> int2ObjectMap = new Int2ObjectOpenHashMap<>();
149-
CodeClient.MC.getNetworkHandler().sendPacket(new ClickSlotC2SPacket(syncId, revision, slot.getIndex(), button, SlotActionType.PICKUP, item, int2ObjectMap));
150+
Int2ObjectMap<ItemStack> int2ObjectMap = new Int2ObjectOpenHashMap<>();
151+
CodeClient.MC.getNetworkHandler().sendPacket(new ClickSlotC2SPacket(syncId, revision, slot.getIndex(), button, SlotActionType.PICKUP, item, int2ObjectMap));
150152

151-
String selected = varObject.get("data").getAsJsonObject().get("option").getAsString();
152-
NbtCompound display = nbt.getCompound("display");
153-
NbtList lore = (NbtList) display.get("Lore");
154-
if (lore == null) return true;
153+
String selected = varObject.get("data").getAsJsonObject().get("option").getAsString();
154+
NbtCompound display = nbt.getCompound("display");
155+
NbtList lore = (NbtList) display.get("Lore");
156+
if (lore == null) return true;
155157

156-
int i = 0;
157-
Integer tagStartIndex = null;
158-
Integer selectedIndex = null;
159-
List<String> options = new ArrayList<>();
158+
int i = 0;
159+
Integer tagStartIndex = null;
160+
Integer selectedIndex = null;
161+
List<String> options = new ArrayList<>();
160162

161-
// TODO: Utility.getBlockTagLines
162-
for (NbtElement element : lore) {
163-
Text text = Text.Serialization.fromJson(element.asString());
164-
if (text == null) return false;
165-
TextColor color = text.getStyle().getColor();
166-
if (color == null) {
167-
List<Text> siblings = text.getSiblings();
168-
if (siblings.size() == 2)
169-
if (text.getSiblings().get(0).getStyle().getColor().equals(TextColor.fromFormatting(Formatting.DARK_AQUA))) {
170-
if (tagStartIndex == null) tagStartIndex = i;
171-
options.add(text.getSiblings().get(1).getString());
172-
selectedIndex = i;
173-
}
174-
} else if (color.equals(TextColor.fromRgb(0x808080))) {
175-
if (tagStartIndex == null) tagStartIndex = i;
176-
options.add(text.getString());
163+
// TODO: Utility.getBlockTagLines
164+
for (NbtElement element : lore) {
165+
Text text = Text.Serialization.fromJson(element.asString());
166+
if (text == null) return false;
167+
TextColor color = text.getStyle().getColor();
168+
if (color == null) {
169+
List<Text> siblings = text.getSiblings();
170+
if (siblings.size() == 2)
171+
if (text.getSiblings().get(0).getStyle().getColor().equals(TextColor.fromFormatting(Formatting.DARK_AQUA))) {
172+
if (tagStartIndex == null) tagStartIndex = i;
173+
options.add(text.getSiblings().get(1).getString());
174+
selectedIndex = i;
175+
}
176+
} else if (color.equals(TextColor.fromRgb(0x808080))) {
177+
if (tagStartIndex == null) tagStartIndex = i;
178+
options.add(text.getString());
179+
}
180+
i++;
177181
}
178-
i++;
179-
}
180182

181-
if (selectedIndex == null) return true;
183+
if (selectedIndex == null) return true;
182184

183-
int shift = button == 0 ? 1 : -1;
184-
int selectionIndex = selectedIndex - tagStartIndex;
185-
int newSelection = (selectionIndex + shift) % (options.size());
186-
if (newSelection < 0) newSelection = options.size() + newSelection;
185+
int shift = button == 0 ? 1 : -1;
186+
int selectionIndex = selectedIndex - tagStartIndex;
187+
int newSelection = (selectionIndex + shift) % (options.size());
188+
if (newSelection < 0) newSelection = options.size() + newSelection;
187189

188-
int optionIndex = 0;
189-
for (String option : options) {
190-
MutableText text = Text.empty();
191-
if (optionIndex == newSelection) {
192-
text.append(Text.literal("» ").formatted(Formatting.DARK_AQUA)).append(Text.literal(option).formatted(Formatting.AQUA));
193-
} else
194-
text = Text.literal(option).setStyle(Text.empty().getStyle().withColor(TextColor.fromRgb(0x808080)));
195-
lore.set(tagStartIndex + optionIndex, Utility.nbtify(text));
196-
optionIndex++;
190+
int optionIndex = 0;
191+
for (String option : options) {
192+
MutableText text = Text.empty();
193+
if (optionIndex == newSelection) {
194+
text.append(Text.literal("» ").formatted(Formatting.DARK_AQUA)).append(Text.literal(option).formatted(Formatting.AQUA));
195+
} else
196+
text = Text.literal(option).setStyle(Text.empty().getStyle().withColor(TextColor.fromRgb(0x808080)));
197+
lore.set(tagStartIndex + optionIndex, Utility.nbtify(text));
198+
optionIndex++;
199+
}
200+
display.put("Lore", lore);
201+
item.setSubNbt("display", display);
202+
slot.setStack(item);
203+
return true;
197204
}
198-
display.put("Lore", lore);
199-
item.setSubNbt("display", display);
200-
slot.setStack(item);
201-
return true;
205+
} catch (Exception e) {
206+
e.printStackTrace();
202207
}
203-
} catch (Exception e) {
204-
e.printStackTrace();
205208
}
206209
}
207210
return false;
@@ -237,6 +240,7 @@ public static BlockPos getPlacePos(BlockHitResult hitResult) {
237240

238241
public static BlockHitResult onBlockInteract(BlockHitResult hitResult) {
239242
if (CodeClient.location instanceof Dev plot) {
243+
plot.getLineStartCache();
240244
ChestPeeker.invalidate();
241245
BlockPos pos = hitResult.getBlockPos();
242246
if (plot.isInDev(pos)) {

0 commit comments

Comments
 (0)