CraftTweaker

CraftTweaker

151M Downloads

[1.16] Unable to cast MCItemDefinition to IItemStack

CharlieQiu2017 opened this issue ยท 3 comments

commented

Issue description

I have a script that provides players with extra crafting output when they use a certain recipe. It goes like this:

CTEventManager.register<MCItemCraftedEvent>((event) => {
  if(event.player == null) { return; }
  if (...) {
    var sz = someTag.elements.length as int;
    var idx = event.player.getWorld().random.nextInt(sz) as usize;
    var elem = someTag.elements[idx] as IItemStack;
    event.player.give(elem);

The extra output is randomly selected from the element list of a tag. This script works fine when using CraftTweaker-1.16.5-7.1.2.507, but breaks when using CraftTweaker-1.16.5-7.1.2.508. The error message is:

Bad type on operand stack
Exception Details:
Location:
j_util_function_Consumer_3.accept(Lnet/minecraftforge/event/entity/player/PlayerEvent$ItemCraftedEvent;)V @88: invokestatic
Reason:
Type 'java/lang/Object' (current frame, stack[0]) is not assignable to 'net/minecraft/item/Item'
Current Frame:
bci: @88
flags: { }
locals: { 'j_util_function_Consumer_3', 'net/minecraftforge/event/entity/player/PlayerEvent$ItemCraftedEvent', top, integer, top, integer, top, 'java/lang/Object' }
stack: { 'java/lang/Object' }
Bytecode: (omitted)

Further experimenting shows that this error occurs whenever I attempt to cast MCItemDefinition to IItemStack. Using getDefaultInstance() does not resolve this issue.

Steps to reproduce

  1. Install CraftTweaker 1.16.5-7.1.2.508
  2. Put the attached script into ~/.minecraft/scripts
  3. Run Minecraft. Load any world.

Script used

https://gist.github.com/CharlieQiu2017/5ce855efe85bb2cb50347db0fb69d2b4

The crafttweaker.log file

https://gist.github.com/CharlieQiu2017/05fc56eee49928b969e7e6386067c2ff

Minecraft version

1.16

Modloader

Forge

Modloader version

36.2.29

CraftTweaker version

1.16.5-7.1.2.508

Other relevant information

No response

The latest.log file

https://pastebin.com/MLASUr8Y

commented

This has been fixed by ZenCodeLang/ZenCode@55e9a43 and will be in the next version.

commented

please add #debug to the top of the script and then reload it, a new folder should generate called classes, zip that folder up and upload it here please.