77import net .minecraft .component .type .DebugStickStateComponent ;
88import net .minecraft .entity .player .PlayerEntity ;
99import net .minecraft .item .DebugStickItem ;
10+ import net .minecraft .item .Item ;
1011import net .minecraft .item .ItemStack ;
1112import net .minecraft .registry .entry .RegistryEntry ;
1213import net .minecraft .state .StateManager ;
2425import java .util .Collection ;
2526
2627@ Mixin (DebugStickItem .class )
27- public class DebugStickMixin {
28+ public class DebugStickMixin extends Item {
29+ public DebugStickMixin (Settings settings ) {
30+ super (settings );
31+ }
32+
2833 @ Shadow
2934 private static void sendMessage (PlayerEntity player , Text message ) {}
3035
@@ -52,8 +57,8 @@ private void onUSE(PlayerEntity player, BlockState state, WorldAccess world, Blo
5257 Collection <Property <?>> collection = stateManager .getProperties ();
5358
5459 // check if block is modifiable by the config
55- if (!isBlockAllowedToModify (state . getBlock () ) || collection .isEmpty ()) {
56- sendMessage (player , Text .of ( Config . MESSAGE_nomodify ));
60+ if (!isBlockAllowedToModify (block ) || collection .isEmpty ()) {
61+ sendMessage (player , Text .translatable ( this . getTranslationKey () + ".empty" , new Object []{ registryEntry . getIdAsString ()} ));
5762 cir .setReturnValue (false );
5863 return ;
5964 }
@@ -70,22 +75,7 @@ private void onUSE(PlayerEntity player, BlockState state, WorldAccess world, Blo
7075
7176 Property <?> property = stateComponent .properties ().get (registryEntry );
7277
73- if (player .isSneaking ()) {
74- // select next property
75- property = getNextProperty (collection , property , block );
76- // save chosen property in the NBT data of Debug Stick
77- stack .set (DataComponentTypes .DEBUG_STICK_STATE , stateComponent .with (registryEntry , property ));
78-
79- // send the player a message of successful selecting
80- sendMessage (player , Text .of (
81- String .format (
82- Config .MESSAGE_select ,
83- property .getName (),
84- getValueString (state , property )
85- )
86- )
87- );
88- } else {
78+ if (update ) {
8979 // change value of property
9080 if (property == null ) {
9181 property = getNextProperty (collection , null , block );
@@ -96,12 +86,25 @@ private void onUSE(PlayerEntity player, BlockState state, WorldAccess world, Blo
9686 // update chosen block with its new state
9787 world .setBlockState (pos , newState , 18 );
9888 // send the player a message of successful modifying
99- sendMessage (player , Text .of (
100- String .format (
101- Config .MESSAGE_change ,
102- property .getName (),
103- getValueString (newState , property )
104- )
89+ sendMessage (
90+ player ,
91+ Text .translatable (
92+ this .getTranslationKey () + ".update" ,
93+ new Object []{property .getName (), getValueString (newState , property )}
94+ )
95+ );
96+ } else {
97+ // select next property
98+ property = getNextProperty (collection , property , block );
99+ // save chosen property in the NBT data of Debug Stick
100+ stack .set (DataComponentTypes .DEBUG_STICK_STATE , stateComponent .with (registryEntry , property ));
101+
102+ // send the player a message of successful selecting
103+ sendMessage (
104+ player ,
105+ Text .translatable (
106+ this .getTranslationKey () + ".select" ,
107+ new Object []{property .getName (), getValueString (state , property )}
105108 )
106109 );
107110 }
0 commit comments