CraftTweaker / CraftTweaker

Tweak your minecraft experience
MIT License
297 stars 122 forks source link

VerifyError: Bad operand type on stack #1345

Closed Foxite closed 3 years ago

Foxite commented 3 years ago

Let me preface this by saying that I have no idea if this code is even close to a valid piece of ZenScript, however I still think that the ZenScript compiler should have complained about it first, rather than successfully compiling ZS into invalid java bytecode.

import crafttweaker.api.events.CTEventManager;
import crafttweaker.api.entity.MCEntity;
import crafttweaker.api.event.entity.MCEntityJoinWorldEvent;

CTEventManager.register<MCEntityJoinWorldEvent>((event) => {
    if event.entity.type.registryName as string == "minecraft:zombie" {
        if event.getEntity().getData()."IsBaby" {
            event.cancel();
        }
    }
});
[16:42:57.049][DONE][CLIENT][ERROR] Bad type on operand stack
Exception Details:
  Location:
    lambda1.accept(Lnet/minecraftforge/event/entity/EntityJoinWorldEvent;)V @50: ifeq
  Reason:
    Type 'com/blamejared/crafttweaker/api/data/IData' (current frame, stack[0]) is not assignable to integer
  Current Frame:
    bci: @50
    flags: { }
    locals: { 'lambda1', 'net/minecraftforge/event/entity/EntityJoinWorldEvent' }
    stack: { 'com/blamejared/crafttweaker/api/data/IData' }
  Bytecode:
    0x0000000: 2bb8 0018 c000 1ab8 0020 c000 22b6 0026
    0x0000010: c000 28b8 002e 1230 b600 3699 0007 03a7
    0x0000020: 0004 0499 0016 2bb8 0018 b800 3a12 3cb6
    0x0000030: 0042 9900 072b b800 48b1               
  Stackmap Table:
    same_frame(@34)
    same_locals_1_stack_item_frame(@35,Integer)
    same_frame(@57)

java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    lambda1.accept(Lnet/minecraftforge/event/entity/EntityJoinWorldEvent;)V @50: ifeq
  Reason:
    Type 'com/blamejared/crafttweaker/api/data/IData' (current frame, stack[0]) is not assignable to integer
  Current Frame:
    bci: @50
    flags: { }
    locals: { 'lambda1', 'net/minecraftforge/event/entity/EntityJoinWorldEvent' }
    stack: { 'com/blamejared/crafttweaker/api/data/IData' }
  Bytecode:
    0x0000000: 2bb8 0018 c000 1ab8 0020 c000 22b6 0026
    0x0000010: c000 28b8 002e 1230 b600 3699 0007 03a7
    0x0000020: 0004 0499 0016 2bb8 0018 b800 3a12 3cb6
    0x0000030: 0042 9900 072b b800 48b1               
  Stackmap Table:
    same_frame(@34)
    same_locals_1_stack_item_frame(@35,Integer)
    same_frame(@57)

    at scripts.ik_ihe.disable-baby-zombies.run(ik_ihe/disable-baby-zombies.zs:5)
    at Scripts.run(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.openzen.zenscript.javabytecode.JavaBytecodeRunUnit.run(JavaBytecodeRunUnit.java:127)
    at org.openzen.zencode.java.ScriptingEngine.run(ScriptingEngine.java:165)
    at com.blamejared.crafttweaker.api.zencode.impl.loaders.ScriptRun.readAndExecuteScripts(ScriptRun.java:124)
    at com.blamejared.crafttweaker.api.zencode.impl.loaders.ScriptRun.run(ScriptRun.java:94)
    at com.blamejared.crafttweaker.api.CraftTweakerAPI.loadScripts(CraftTweakerAPI.java:134)
    at com.blamejared.crafttweaker.api.CraftTweakerAPI.loadScripts(CraftTweakerAPI.java:117)
    at com.blamejared.crafttweaker.CraftTweaker$1.apply(CraftTweaker.java:251)
    at com.blamejared.crafttweaker.CraftTweaker$1.func_212853_a_(CraftTweaker.java:230)
    at net.minecraft.client.resources.ReloadListener.func_215269_a(SourceFile:13)
    at java.util.concurrent.CompletableFuture.uniAccept(CompletableFuture.java:656)
    at java.util.concurrent.CompletableFuture$UniAccept.tryFire(CompletableFuture.java:632)
    at java.util.concurrent.CompletableFuture$Completion.run(CompletableFuture.java:442)
    at net.minecraft.resources.AsyncReloader.func_219557_a(SourceFile:71)
    at net.minecraft.util.concurrent.ThreadTaskExecutor.func_213166_h(SourceFile:144)
    at net.minecraft.util.concurrent.RecursiveEventLoop.func_213166_h(SourceFile:23)
    at net.minecraft.util.concurrent.ThreadTaskExecutor.func_213168_p(SourceFile:118)
    at net.minecraft.util.concurrent.ThreadTaskExecutor.func_213161_c(SourceFile:127)
    at net.minecraft.client.Minecraft.func_238189_a_(Minecraft.java:1863)
    at net.minecraft.client.Minecraft.loadWorld(Minecraft.java:1712)
    at net.minecraft.client.Minecraft.func_238191_a_(Minecraft.java:1681)
    at net.minecraft.client.gui.screen.WorldSelectionList$Entry.func_214443_e(SourceFile:407)
    at net.minecraft.client.gui.screen.WorldSelectionList$Entry.func_214438_a(SourceFile:317)
    at net.minecraft.client.gui.screen.WorldSelectionList$Entry.func_231044_a_(SourceFile:259)
    at net.minecraft.client.gui.widget.list.AbstractList.func_231044_a_(AbstractList.java:309)
    at net.minecraft.client.gui.INestedGuiEventHandler.func_231044_a_(SourceFile:27)
    at net.minecraft.client.MouseHelper.func_198033_b(MouseHelper.java:87)
    at net.minecraft.client.gui.screen.Screen.func_231153_a_(Screen.java:427)
    at net.minecraft.client.MouseHelper.func_198023_a(MouseHelper.java:85)
    at net.minecraft.client.MouseHelper.func_228030_c_(MouseHelper.java:181)
    at net.minecraft.util.concurrent.ThreadTaskExecutor.execute(SourceFile:94)
    at net.minecraft.client.MouseHelper.func_228028_b_(MouseHelper.java:180)
    at org.lwjgl.glfw.GLFWMouseButtonCallbackI.callback(GLFWMouseButtonCallbackI.java:36)
    at org.lwjgl.system.JNI.invokeV(Native Method)
    at org.lwjgl.glfw.GLFW.glfwWaitEventsTimeout(GLFW.java:3174)
    at com.mojang.blaze3d.systems.RenderSystem.limitDisplayFPS(SourceFile:127)
    at net.minecraft.client.Minecraft.func_195542_b(Minecraft.java:999)
    at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:607)
    at net.minecraft.client.main.Main.main(Main.java:184)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at net.minecraftforge.fml.loading.FMLClientLaunchProvider.lambda$launchService$0(FMLClientLaunchProvider.java:51)
    at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37)
    at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54)
    at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72)
    at cpw.mods.modlauncher.Launcher.run(Launcher.java:82)
    at cpw.mods.modlauncher.Launcher.main(Launcher.java:66)
jaredlll08 commented 3 years ago

Transfered to the right repo as that one is for 1.12 zenscript.

Can you please add #debug Somewhere in the script, when you run it, it will generate a folder called "classes", zip that folder up and attach it here please

Foxite commented 3 years ago

classes-before-loading-world.zip

classes-after-loading-world.zip

The error is logged to chat and crafttweaker.log when I load the world.

Foxite commented 3 years ago

crafttweaker.log

The full log file if it helps

jaredlll08 commented 3 years ago

So your script is fine, like it is "valid" zenscript in terms of how everything is structured.

The issue was that IData (which is what IsBaby returns) could not be casted to a boolean.

I have fixed that in 2cce4411fbe586f0240c60d0b18f4f793e4b344f and changing your code to be:

import crafttweaker.api.events.CTEventManager;
import crafttweaker.api.entity.MCEntity;
import crafttweaker.api.event.entity.MCEntityJoinWorldEvent;

CTEventManager.register<MCEntityJoinWorldEvent>((event) => {
    if event.entity.type.registryName as string == "minecraft:zombie" {
        if event.getEntity().getData()."IsBaby" as bool {
            event.cancel();
        }
    }
});

will now work.

As for:

however I still think that the ZenScript compiler should have complained about it first, rather than successfully compiling ZS into invalid java bytecode.

While I do agree with you, unfortunately I don't know how feasible that is to do right now.