33import net .just_s .sds .config .Config ;
44import net .minecraft .block .Block ;
55import net .minecraft .block .BlockState ;
6- import net .minecraft .component .DataComponentTypes ;
7- import net .minecraft .component .type .DebugStickStateComponent ;
86import net .minecraft .entity .player .PlayerEntity ;
97import net .minecraft .item .DebugStickItem ;
108import net .minecraft .item .Item ;
119import net .minecraft .item .ItemStack ;
12- import net .minecraft .registry .entry .RegistryEntry ;
10+ import net .minecraft .nbt .NbtCompound ;
11+ import net .minecraft .registry .Registries ;
1312import net .minecraft .state .StateManager ;
1413import net .minecraft .state .property .Property ;
1514import net .minecraft .text .Text ;
@@ -53,28 +52,27 @@ private void onUSE(PlayerEntity player, BlockState state, WorldAccess world, Blo
5352 if (player .isCreativeLevelTwoOp ()) {return ;}
5453
5554 Block block = state .getBlock ();
56- RegistryEntry < Block > registryEntry = state . getRegistryEntry ();
57- StateManager <Block , BlockState > stateManager = ( registryEntry . value ()) .getStateManager ();
55+ String blockIdAsString = Registries . BLOCK . getId ( block ). toString ();
56+ StateManager <Block , BlockState > stateManager = block .getStateManager ();
5857 Collection <Property <?>> collection = stateManager .getProperties ();
5958
6059 // check if block is modifiable by the config
6160 if (!isBlockAllowedToModify (block ) || collection .isEmpty ()) {
62- sendMessage (player , Text .translatable (this .getTranslationKey () + ".empty" , new Object []{registryEntry . getIdAsString () }));
61+ sendMessage (player , Text .translatable (this .getTranslationKey () + ".empty" , new Object []{blockIdAsString }));
6362 cir .setReturnValue (false );
6463 return ;
6564 }
6665
67- // https://minecraft.wiki/w/ Debug_Stick
66+ // https://minecraft.fandom.com/ wiki/Debug_Stick#Item_data
6867 // to remember the data of which property for which block is chosen,
69- // Minecraft Devs decided to use Component for Debug Stick.
70- // Who am I to disagree? (btw thx to @MrBretze for example code)
71- DebugStickStateComponent stateComponent = stack .get ( DataComponentTypes . DEBUG_STICK_STATE );
68+ // Minecraft Devs decided to use NBT data for Debug Stick.
69+ // Who am I to disagree?
70+ NbtCompound nbtCompound = stack .getOrCreateSubNbt ( "DebugProperty" );
7271
73- if (stateComponent == null ) {
74- return ;
75- }
72+ String blockName = Registries .BLOCK .getId (block ).toString ();
73+ String propertyName = nbtCompound .getString (blockName );
7674
77- Property <?> property = stateComponent . properties (). get ( registryEntry );
75+ Property <?> property = stateManager . getProperty ( propertyName );
7876
7977 if (update ) {
8078 // change value of property
@@ -83,7 +81,7 @@ private void onUSE(PlayerEntity player, BlockState state, WorldAccess world, Blo
8381 }
8482 // check if given property is allowed
8583 if (!isPropertyModifiable (property , block )) {
86- sendMessage (player , Text .translatable (this .getTranslationKey () + ".empty" , new Object []{registryEntry . getIdAsString () }));
84+ sendMessage (player , Text .translatable (this .getTranslationKey () + ".empty" , new Object []{blockIdAsString }));
8785 cir .setReturnValue (false );
8886 return ;
8987 }
@@ -105,12 +103,12 @@ private void onUSE(PlayerEntity player, BlockState state, WorldAccess world, Blo
105103 property = getNextProperty (collection , property , block , player .shouldCancelInteraction ());
106104 // check if given property is allowed
107105 if (!isPropertyModifiable (property , block )) {
108- sendMessage (player , Text .translatable (this .getTranslationKey () + ".empty" , new Object []{registryEntry . getIdAsString () }));
106+ sendMessage (player , Text .translatable (this .getTranslationKey () + ".empty" , new Object []{blockIdAsString }));
109107 cir .setReturnValue (false );
110108 return ;
111109 }
112110 // save chosen property in the NBT data of Debug Stick
113- stack . set ( DataComponentTypes . DEBUG_STICK_STATE , stateComponent . with ( registryEntry , property ));
111+ nbtCompound . putString ( blockName , property . getName ( ));
114112
115113 // send the player a message of successful selecting
116114 sendMessage (
0 commit comments