コード例 #1
0
  private int firePeacefulRegenEventAndStoreEventBefore(
      MethodNode method, AbstractInsnNode injectPoint, LabelNode endLabel) {
    // create  variable
    LabelNode peacefulRegenEventStart = new LabelNode();
    LocalVariableNode peacefulRegenEvent =
        new LocalVariableNode(
            "peacefulRegenEvent",
            Type.getDescriptor(HealthRegenEvent.PeacefulRegen.class),
            null,
            peacefulRegenEventStart,
            endLabel,
            method.maxLocals);
    method.maxLocals += 1;
    method.localVariables.add(peacefulRegenEvent);

    InsnList toInject = new InsnList();

    // HealthRegenEvent.PeacefulRegen peacefulRegenEvent = Hooks.firePeacefulRegenEvent(this);
    toInject.add(new VarInsnNode(ALOAD, 0));
    toInject.add(
        new MethodInsnNode(
            INVOKESTATIC,
            Type.getInternalName(Hooks.class),
            "firePeacefulRegenEvent",
            "(Lnet/minecraft/entity/player/EntityPlayer;)Lsqueek/applecore/api/hunger/HealthRegenEvent$PeacefulRegen;",
            false));
    toInject.add(new VarInsnNode(ASTORE, peacefulRegenEvent.index));
    toInject.add(peacefulRegenEventStart);

    method.instructions.insertBefore(injectPoint, toInject);

    return peacefulRegenEvent.index;
  }