1414import meteordevelopment .meteorclient .commands .arguments .RegistryEntryReferenceArgumentType ;
1515import meteordevelopment .meteorclient .utils .misc .EnchantmentOptimizer ;
1616import meteordevelopment .meteorclient .utils .player .ChatUtils ;
17- import net .minecraft .command .CommandSource ;
18- import net .minecraft .command .argument .ItemStackArgumentType ;
19- import net .minecraft .enchantment .Enchantment ;
20- import net .minecraft .item .Item ;
21- import net .minecraft .registry .RegistryKeys ;
22- import net .minecraft .registry .entry .RegistryEntry ;
23- import net .minecraft .text .MutableText ;
24- import net .minecraft .text .Text ;
25- import net .minecraft .util .Formatting ;
17+ import net .minecraft .ChatFormatting ;
18+ import net .minecraft .client .multiplayer .ClientSuggestionProvider ;
19+ import net .minecraft .commands .arguments .item .ItemArgument ;
20+ import net .minecraft .core .Holder ;
21+ import net .minecraft .core .component .DataComponents ;
22+ import net .minecraft .core .registries .Registries ;
23+ import net .minecraft .network .chat .Component ;
24+ import net .minecraft .network .chat .MutableComponent ;
25+ import net .minecraft .world .item .Item ;
26+ import net .minecraft .world .item .enchantment .Enchantment ;
27+
2628
2729import java .util .ArrayList ;
2830import java .util .List ;
@@ -33,14 +35,14 @@ public OptimizeEnchantsCommand() {
3335 }
3436
3537 @ Override
36- public void build (LiteralArgumentBuilder <CommandSource > builder ) {
38+ public void build (LiteralArgumentBuilder <ClientSuggestionProvider > builder ) {
3739 // TODO: The optimizer supports book-only mode (item=null) for combining enchanted books,
3840 // but this command currently requires an item argument, so item will never be null.
3941 // Should we add an item-less version of the command for book-only optimization?
4042
4143 // TODO: should we restrict the available items to only those that can be enchanted?
4244 // e.g. armors, weapons, tools, books, etc.
43- builder .then (argument ("item" , ItemStackArgumentType . itemStack (REGISTRY_ACCESS ))
45+ builder .then (argument ("item" , ItemArgument . item (REGISTRY_ACCESS ))
4446 .then (buildEnchantmentChain (1 , 20 ))
4547 // TODO: what should the max depth be? Idk how many enchantments on a single item MC supports.
4648 );
@@ -50,7 +52,7 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
5052 * Recursively builds a chain of enchantment arguments.
5153 * Each enchantment requires a name and level, and can optionally chain to the next.
5254 */
53- private RequiredArgumentBuilder <CommandSource , ?> buildEnchantmentChain (int index , int maxDepth ) {
55+ private RequiredArgumentBuilder <ClientSuggestionProvider , ?> buildEnchantmentChain (int index , int maxDepth ) {
5456 String enchantArg = "enchantment" + index ;
5557 String levelArg = "level" + index ;
5658
@@ -71,7 +73,7 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
7173 /**
7274 * Extracts all enchantments from context and runs optimization.
7375 */
74- private void executeOptimization (CommandContext <CommandSource > context , int enchantmentCount ) {
76+ private void executeOptimization (CommandContext <ClientSuggestionProvider > context , int enchantmentCount ) {
7577 try {
7678 Item item = getItem (context );
7779 List <EnchantmentOptimizer .EnchantmentEntry > enchants = new ArrayList <>();
@@ -81,7 +83,7 @@ private void executeOptimization(CommandContext<CommandSource> context, int ench
8183 String levelArg = "level" + i ;
8284
8385 try {
84- RegistryEntry .Reference <Enchantment > enchantment =
86+ Holder .Reference <Enchantment > enchantment =
8587 RegistryEntryReferenceArgumentType .getEnchantment (context , enchantArg );
8688 int level = IntegerArgumentType .getInteger (context , levelArg );
8789
@@ -96,7 +98,7 @@ private void executeOptimization(CommandContext<CommandSource> context, int ench
9698 }
9799
98100 enchants .add (new EnchantmentOptimizer .EnchantmentEntry (enchantment , level ));
99- } catch (IllegalArgumentException e ) {
101+ } catch (IllegalArgumentException _ ) {
100102 // Argument doesn't exist, we've reached the end
101103 break ;
102104 }
@@ -113,23 +115,23 @@ private void executeOptimization(CommandContext<CommandSource> context, int ench
113115 }
114116 }
115117
116- private Item getItem (CommandContext <CommandSource > context ) {
118+ private Item getItem (CommandContext <ClientSuggestionProvider > context ) {
117119 try {
118- var itemArg = ItemStackArgumentType . getItemStackArgument (context , "item" );
119- return itemArg .getItem ();
120- } catch (Exception e ) {
120+ var itemArg = ItemArgument . getItem (context , "item" );
121+ return itemArg .item (). value ();
122+ } catch (Exception _ ) {
121123 return null ;
122124 }
123125 }
124126
125127 private void optimize (Item item , List <EnchantmentOptimizer .EnchantmentEntry > enchants ) {
126128 try {
127129 // Create optimizer from current registry
128- var registry = mc .getNetworkHandler ().getRegistryManager ().getOrThrow ( RegistryKeys .ENCHANTMENT );
130+ var registry = mc .getConnection ().registryAccess ().lookupOrThrow ( Registries .ENCHANTMENT );
129131 EnchantmentOptimizer .OptimizationResult result = EnchantmentOptimizer .create (registry ).optimize (item , enchants );
130132
131133 // Display header
132- String itemName = item != null ? item .getName ( ).getString () : "Book" ;
134+ String itemName = item != null ? item .components (). get ( DataComponents . ITEM_NAME ).getString () : "Book" ;
133135 ChatUtils .info ("=== Enchantment Optimization for %s ===" , itemName );
134136 ChatUtils .info ("Total Cost: (highlight)%d levels(default) (%d XP)" , result .totalLevels (), result .totalXp ());
135137
@@ -144,11 +146,11 @@ private void optimize(Item item, List<EnchantmentOptimizer.EnchantmentEntry> enc
144146 for (int i = 0 ; i < result .instructions ().size (); i ++) {
145147 EnchantmentOptimizer .Instruction instr = result .instructions ().get (i );
146148
147- MutableText stepText = Text .literal (String .format (" %d. " , i + 1 )).formatted ( Formatting .GRAY );
148- stepText .append (Text .literal ("Combine " ).formatted ( Formatting .GRAY ));
149- stepText .append (formatItem (instr .left ()).copy ().formatted ( Formatting .YELLOW ));
150- stepText .append (Text .literal (" with " ).formatted ( Formatting .GRAY ));
151- stepText .append (formatItem (instr .right ()).copy ().formatted ( Formatting .AQUA ));
149+ MutableComponent stepText = Component .literal (String .format (" %d. " , i + 1 )).withStyle ( ChatFormatting .GRAY );
150+ stepText .append (Component .literal ("Combine " ).withStyle ( ChatFormatting .GRAY ));
151+ stepText .append (formatItem (instr .left ()).copy ().withStyle ( ChatFormatting .YELLOW ));
152+ stepText .append (Component .literal (" with " ).withStyle ( ChatFormatting .GRAY ));
153+ stepText .append (formatItem (instr .right ()).copy ().withStyle ( ChatFormatting .AQUA ));
152154
153155 ChatUtils .sendMsg (stepText );
154156
@@ -164,18 +166,18 @@ private void optimize(Item item, List<EnchantmentOptimizer.EnchantmentEntry> enc
164166 }
165167 }
166168
167- private Text formatItem (EnchantmentOptimizer .Combination comb ) {
169+ private Component formatItem (EnchantmentOptimizer .Combination comb ) {
168170 String baseName = comb .baseItem != null
169- ? comb .baseItem .getName ( ).getString ()
171+ ? comb .baseItem .components (). get ( DataComponents . ITEM_NAME ).getString ()
170172 : "Book" ;
171173
172174 List <String > enchantments = new ArrayList <>();
173175 collectEnchantments (comb , enchantments );
174176
175- if (enchantments .isEmpty ()) return Text .literal (baseName );
177+ if (enchantments .isEmpty ()) return Component .literal (baseName );
176178
177179 // Format: "ItemName (ench1, ench2, ench3)"
178- return Text .literal (baseName + " (" + String .join (", " , enchantments ) + ")" );
180+ return Component .literal (baseName + " (" + String .join (", " , enchantments ) + ")" );
179181 }
180182
181183 private void collectEnchantments (EnchantmentOptimizer .Combination comb , List <String > out ) {
0 commit comments