Advertisement
spacechase0

EnchantmentListSubInterceptor

Jan 12th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. package com.spacechase0.minecraft.spelunkerdim.asm;
  2.  
  3. import org.objectweb.asm.MethodVisitor;
  4. import static org.objectweb.asm.Opcodes.*;
  5.  
  6. public class EnchantmentListSubInterceptor extends MethodVisitor
  7. {
  8.     public EnchantmentListSubInterceptor( MethodVisitor mv )
  9.     {
  10.         super( ASM4, mv );
  11.     }
  12.    
  13.     @Override
  14.     public void visitInsn( int opcode )
  15.     {
  16.         if ( should && opcode == ARETURN )
  17.         {
  18.             visitVarInsn( ALOAD, 0 );
  19.             visitMethodInsn( INVOKESTATIC, "com/spacechase0/minecraft/spelunkerdim/EnchantmentListInterceptor", "intercept", "(" + typeA + "L" + typeB + ";)V" );
  20.             visitInsn( POP );
  21.             visitVarInsn( ALOAD, 0 );
  22.             should = false;
  23.             did = true;
  24.         }
  25.        
  26.         mv.visitInsn( opcode );
  27.     }
  28.    
  29.     @Override
  30.     public void visitLdcInsn( Object obj )
  31.     {
  32.         if ( obj instanceof String )
  33.         {
  34.             String str = ( String ) obj;
  35.             if ( str.equals( "ench" ) )
  36.             {
  37.                 should = true;
  38.             }
  39.         }
  40.        
  41.         mv.visitLdcInsn( obj );
  42.     }
  43.    
  44.     public static boolean didChangeSomething()
  45.     {
  46.         return did;
  47.     }
  48.    
  49.     public static void reset()
  50.     {
  51.         did = false;
  52.     }
  53.    
  54.     private boolean should = false;
  55.     public static String typeA;
  56.     public static String typeB;
  57.     private static boolean did = false;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement