Jump to content

Recommended Posts

Posted

I want to change player's eyeheight.

I think it's impossible without replacing a vanilla method.

So I used coremod, but my cord caused error.

I think this cause is that 0.5 is double, but I don't know to define float value on JavaScript.

How do I solve this?

 

I have bad English, so I apologize if I say something strange.

 

Vanilla Method:

public float getStandingEyeHeight(Pose poseIn, EntitySize sizeIn) {
      switch(poseIn) {
      case SWIMMING:
      case FALL_FLYING:
      case SPIN_ATTACK:
         return 0.4F;
      case CROUCHING:
         return 1.27F;
      default:
         return 1.62F;
      }
   }

 

Byte Code of Vanilla Method:

public getStandingEyeHeight(Lnet/minecraft/entity/Pose;Lnet/minecraft/entity/EntitySize;)F
   L0
    LINENUMBER 1771 L0
    GETSTATIC net/minecraft/entity/player/PlayerEntity$1.$SwitchMap$net$minecraft$entity$Pose : [I
    ALOAD 1
    INVOKEVIRTUAL net/minecraft/entity/Pose.ordinal ()I
    IALOAD
    TABLESWITCH
      1: L1
      2: L1
      3: L1
      4: L2
      default: L3
   L1
    LINENUMBER 1775 L1
   FRAME SAME
    LDC 0.4
    FRETURN
   L2
    LINENUMBER 1777 L2
   FRAME SAME
    LDC 1.27
    FRETURN
   L3
    LINENUMBER 1779 L3
   FRAME SAME
    LDC 1.62
    FRETURN
   L4
    LOCALVARIABLE this Lnet/minecraft/entity/player/PlayerEntity; L0 L4 0
    LOCALVARIABLE p_213348_1_ Lnet/minecraft/entity/Pose; L0 L4 1
    LOCALVARIABLE p_213348_2_ Lnet/minecraft/entity/EntitySize; L0 L4 2
    MAXSTACK = 2
    MAXLOCALS = 3

 

Transformer.js:

var ASMAPI = Java.type('net.minecraftforge.coremod.api.ASMAPI');
var Opcodes = Java.type('org.objectweb.asm.Opcodes');

var mappedMethodName = ASMAPI.mapMethod("func_213348_b");

function initializeCoreMod() {
    return {
        'coremodmethod': {
            'target': {
                'type': 'METHOD',
                'class': 'net.minecraft.entity.player.PlayerEntity',
                'methodName': mappedMethodName,
                'methodDesc': '(Lnet/minecraft/entity/Pose;Lnet/minecraft/entity/EntitySize;)F'
            },
            'transformer': function(method) {
                var arrayLength = method.instructions.size();
                for (var i = arrayLength - 1; i >= 0; --i) {
                     var instruction = method.instructions.get(i);
                     if (instruction.getOpcode() == Opcodes.LDC) {
                        var LdcInsnNode = Java.type('org.objectweb.asm.tree.LdcInsnNode');
                        var newInstruction = new LdcInsnNode(0.5);
                        method.instructions.insertBefore(instruction, newInstruction);
                        method.instructions.remove(instruction);
                        print("Transformed!");
                        break;
                     }
                }
                return method;
            }
        }
    }
}

 

Error:

[main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:644]: Caused by: java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    net/minecraft/entity/player/PlayerEntity.getStandingEyeHeight(Lnet/minecraft/entity/Pose;Lnet/minecraft/entity/EntitySize;)F @51: freturn
  Reason:
    Type double_2nd (current frame, stack[1]) is not assignable to float
  Current Frame:
    bci: @51
    flags: { }
    locals: { 'net/minecraft/entity/player/PlayerEntity', 'net/minecraft/entity/Pose', 'net/minecraft/entity/EntitySize' }
    stack: { double, double_2nd }

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.