55import dev .dfonline .codeclient .action .None ;
66import dev .dfonline .codeclient .action .impl .DevForBuild ;
77import dev .dfonline .codeclient .command .CommandManager ;
8+ import dev .dfonline .codeclient .command .CommandSender ;
89import dev .dfonline .codeclient .config .Config ;
910import dev .dfonline .codeclient .config .KeyBinds ;
11+ import dev .dfonline .codeclient .data .DFItem ;
12+ import dev .dfonline .codeclient .data .ItemData ;
13+ import dev .dfonline .codeclient .data .PublicBukkitValues ;
14+ import dev .dfonline .codeclient .data .value .DataValue ;
15+ import dev .dfonline .codeclient .data .value .NumberDataValue ;
16+ import dev .dfonline .codeclient .data .value .StringDataValue ;
1017import dev .dfonline .codeclient .dev .*;
1118import dev .dfonline .codeclient .dev .debug .Debug ;
1219import dev .dfonline .codeclient .dev .highlighter .ExpressionHighlighter ;
4249import net .minecraft .client .render .VertexConsumerProvider ;
4350import net .minecraft .client .util .math .MatrixStack ;
4451import net .minecraft .item .ItemStack ;
45- import net .minecraft .nbt .AbstractNbtNumber ;
46- import net .minecraft .nbt .NbtCompound ;
47- import net .minecraft .nbt .NbtElement ;
48- import net .minecraft .nbt .NbtString ;
4952import net .minecraft .network .listener .PacketListener ;
5053import net .minecraft .network .packet .Packet ;
5154import net .minecraft .network .packet .s2c .play .BlockEntityUpdateS2CPacket ;
55+ import net .minecraft .network .packet .s2c .play .BundleS2CPacket ;
5256import net .minecraft .network .packet .s2c .play .CloseScreenS2CPacket ;
5357import net .minecraft .screen .slot .Slot ;
5458import net .minecraft .screen .slot .SlotActionType ;
55- import net .minecraft .text .MutableText ;
5659import net .minecraft .text .Text ;
5760import net .minecraft .util .Formatting ;
5861import net .minecraft .util .Identifier ;
@@ -82,7 +85,7 @@ public class CodeClient implements ClientModInitializer {
8285 public static Action confirmingAction = null ;
8386 public static Location lastLocation = null ;
8487 public static Location location = null ;
85- /***
88+ /**
8689 * Used to open a screen on the next tick.
8790 */
8891 public static Screen screenToOpen = null ;
@@ -112,7 +115,9 @@ public void onInitializeClient() {
112115 BlockRenderLayerMap .INSTANCE .putBlock (Blocks .STRUCTURE_VOID , RenderLayer .getTranslucent ());
113116 BlockRenderLayerMap .INSTANCE .putBlock (Blocks .LIGHT , RenderLayer .getTranslucent ());
114117
115- ClientLifecycleEvents .CLIENT_STOPPING .register (new Identifier (MOD_ID , "close" ), client -> API .stop ());
118+ ClientLifecycleEvents .CLIENT_STOPPING .register (Identifier .of (MOD_ID , "close" ), client -> API .stop ());
119+
120+ ClientTickEvents .END_CLIENT_TICK .register (client -> CommandSender .tick ());
116121
117122 if (Config .getConfig ().CodeClientAPI ) {
118123 try {
@@ -129,29 +134,33 @@ public void onInitializeClient() {
129134
130135 ClientCommandRegistrationCallback .EVENT .register ((dispatcher , registryAccess ) -> CommandManager .init (dispatcher , registryAccess ));
131136
132- ItemTooltipCallback .EVENT .register ((stack , context , lines ) -> {
137+ ItemTooltipCallback .EVENT .register ((stack , context , type , lines ) -> {
133138 if (isPreviewingItemTags ) {
134- if (!stack .hasNbt ()) return ;
135- NbtCompound nbt = stack .getNbt ();
136- if (nbt == null ) return ;
137- if (!nbt .contains ("PublicBukkitValues" )) return ;
138- NbtCompound publicBukkit = nbt .getCompound ("PublicBukkitValues" );
139- for (var key : publicBukkit .getKeys ()) {
140- if (key .startsWith ("hypercube:" )) {
141- NbtElement element = publicBukkit .get (key );
142-
143- // Any type = yellow, number = red, string = aqua.
144- MutableText value = Text .literal (publicBukkit .get (key ).toString ()).formatted (Formatting .GREEN );
145- if (element instanceof NbtString ) value .formatted (Formatting .AQUA );
146- if (element instanceof AbstractNbtNumber ) value .formatted (Formatting .RED );
147-
148- lines .add (
149- Text .literal (key .replace ("hypercube:" , "" ))
150- .withColor (0xAAFF55 )
151- .append (Text .literal (" = " ).formatted (Formatting .DARK_GRAY ))
152- .append (value )
153- );
139+ DFItem item = DFItem .of (stack );
140+ ItemData itemData = item .getItemData ();
141+ if (itemData == null ) return ;
142+ PublicBukkitValues publicBukkit = itemData .getPublicBukkitValues ();
143+ if (publicBukkit == null ) return ;
144+ for (var key : publicBukkit .getHypercubeKeys ()) {
145+ DataValue element = publicBukkit .getHypercubeValue (key );
146+
147+ // Any type = yellow, number = red, string = aqua.
148+ Formatting formatting = Formatting .GREEN ;
149+ String stringElement = element .getValue () == null ? "?" : element .getValue ().toString ();
150+ if (element instanceof StringDataValue ) {
151+ formatting = Formatting .AQUA ;
154152 }
153+ if (element instanceof NumberDataValue numberDataValue ) {
154+ formatting = Formatting .RED ;
155+ stringElement = String .valueOf (numberDataValue .getValue ());
156+ }
157+
158+ lines .add (
159+ Text .literal (key )
160+ .withColor (0xAAFF55 )
161+ .append (Text .literal (" = " ).formatted (Formatting .DARK_GRAY ))
162+ .append (Text .literal (stringElement ).formatted (formatting ))
163+ );
155164 }
156165 }
157166 });
@@ -189,6 +198,7 @@ private static void loadFeatures() {
189198 feat (new CPUDisplay ());
190199 feat (new MessageHiding ());
191200 feat (new ExpressionHighlighter ());
201+ feat (new PreviewSoundChest ());
192202 }
193203
194204 /**
@@ -205,6 +215,16 @@ private static Stream<ChestFeature> chestFeatures() {
205215 return features ().map (Feature ::getChest ).filter (Optional ::isPresent ).map (Optional ::get );
206216 }
207217
218+ /**
219+ * Get an identifier using the mod id as the namespace.
220+ *
221+ * @param path The path to the resource.
222+ * @return Identifier under the mod id's namespace and the provided path as the path.
223+ */
224+ public static Identifier getId (String path ) {
225+ return Identifier .of (MOD_ID , path );
226+ }
227+
208228 public static void isCodeChest () {
209229 isCodeChest = true ;
210230 }
@@ -216,6 +236,12 @@ public static <T extends Feature> Optional<T> getFeature(Class<T> clazz) {
216236 }
217237
218238 public static <T extends PacketListener > boolean handlePacket (Packet <T > packet ) {
239+ if (packet instanceof BundleS2CPacket bundle ) {
240+ bundle .getPackets ().forEach (CodeClient ::handlePacket );
241+ return false ;
242+ }
243+
244+
219245 if (currentAction .onReceivePacket (packet )) return true ;
220246 for (var feature : features ().toList ()) {
221247 if (feature .onReceivePacket (packet )) return true ;
@@ -263,6 +289,8 @@ public static void onTick() {
263289 features ().forEach (Feature ::tick );
264290 KeyBinds .tick ();
265291
292+ // System.out.println(location.name());
293+
266294 if (!(location instanceof Dev ) || !(MC .currentScreen instanceof HandledScreen <?>)) {
267295 isCodeChest = false ;
268296 features ().forEach (Feature ::closeChest );
@@ -455,7 +483,7 @@ private boolean registerResourcePack(String id, Text name) throws NullPointerExc
455483 private boolean registerResourcePack (String id , Text name , ResourcePackActivationType type ) throws NullPointerException {
456484 var prefix = String .format ("[%s] " , MOD_NAME );
457485 return ResourceManagerHelper .registerBuiltinResourcePack (
458- new Identifier ( CodeClient . MOD_ID , id ),
486+ getId ( id ),
459487 getModContainer (),
460488 Text .literal (prefix ).formatted (Formatting .GRAY ).append (name ),
461489 type
0 commit comments