@@ -368,6 +368,62 @@ private static void findBlockTypes(StatementBlock block, SourceSet src, Map<Stri
368
368
}
369
369
}
370
370
371
+ private static void register_enchantments (MethodMatchEntry match , MergeEngine set ) {
372
+ if (match .getOldMethod ().getInstructions () == null || match .getNewMethod ().getInstructions () == null ) {
373
+ return ;
374
+ }
375
+ Map <String , TypeEntry > old_types = new HashMap <>();
376
+ Map <String , TypeEntry > new_types = new HashMap <>();
377
+ findEnchantments (match .getOldMethod ().getInstructions (), set .getOldSourceSet (), old_types );
378
+ findEnchantments (match .getNewMethod ().getInstructions (), set .getNewSourceSet (), new_types );
379
+ for (Map .Entry <String , TypeEntry > e : new_types .entrySet ()) {
380
+ TypeEntry old = old_types .get (e .getKey ());
381
+ if (old != null ) {
382
+ set .vote (old , e .getValue ());
383
+ }
384
+ }
385
+ }
386
+
387
+ private static void findEnchantments (StatementBlock block , SourceSet src , Map <String , TypeEntry > types ) {
388
+ for (Statement stmt : block ) {
389
+ if (stmt instanceof InvokeStatement ) {
390
+ Instruction inner = ((InvokeStatement ) stmt ).getInstruction ();
391
+ if (inner instanceof InstanceMethodInvoke ) {
392
+ InstanceMethodInvoke reg = (InstanceMethodInvoke ) inner ;
393
+ if (reg .getParameters ().length != 3 ) {
394
+ continue ;
395
+ }
396
+ Instruction key_val = reg .getParameters ()[1 ];
397
+ String key = null ;
398
+ if (key_val instanceof New ) {
399
+ New n = (New ) key_val ;
400
+ if (n .getParameters ().length == 1 && n .getParameters ()[0 ] instanceof StringConstant ) {
401
+ key = ((StringConstant ) n .getParameters ()[0 ]).getConstant ();
402
+ }
403
+ }
404
+ if (key == null ) {
405
+ continue ;
406
+ }
407
+ Instruction val = reg .getParameters ()[2 ];
408
+ if (val instanceof Cast ) {
409
+ val = ((Cast ) val ).getValue ();
410
+ }
411
+ while (val instanceof InstanceMethodInvoke ) {
412
+ val = ((InstanceMethodInvoke ) val ).getCallee ();
413
+ }
414
+ if (!(val instanceof New )) {
415
+ continue ;
416
+ }
417
+ String type = TypeHelper .descToType (((New ) val ).getType ().getDescriptor ());
418
+ TypeEntry block_type = src .get (type );
419
+ if (block_type != null ) {
420
+ types .put (key , block_type );
421
+ }
422
+ }
423
+ }
424
+ }
425
+ }
426
+
371
427
static {
372
428
custom_mergers .put ("Lnet/minecraft/init/SoundEvents;<clinit>()V" , CustomMethodMergers ::bootstrap_handler );
373
429
custom_mergers .put ("Lnet/minecraft/init/Blocks;<clinit>()V" , CustomMethodMergers ::bootstrap_handler );
@@ -388,6 +444,7 @@ private static void findBlockTypes(StatementBlock block, SourceSet src, Map<Stri
388
444
custom_mergers .put ("Lnet/minecraft/block/Block;func_149671_p()V" , CustomMethodMergers ::register_blocks );
389
445
custom_mergers .put ("Lnet/minecraft/item/Item;func_150900_l()V" , CustomMethodMergers ::register_items );
390
446
custom_mergers .put ("Lnet/minecraft/world/biome/Biome;func_185358_q()V" , CustomMethodMergers ::register_blocks );
447
+ custom_mergers .put ("Lnet/minecraft/enchantment/Enchantment;func_185257_f()V" , CustomMethodMergers ::register_enchantments );
391
448
}
392
449
393
450
}
0 commit comments