@@ -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