question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CraftTweaker fails to use arrays properly in some cases

See original GitHub issue

Issue Description:

When attempting to check if a string is in an array, CraftTweaker fails with an error message.

What happens:

In the script below I am trying to make Hoppers unplaceable. The script works fine until I include the has check for blacklisted blocks, at which point the script fails with an error message.

Note that using a direct string comparison like if ("minecraft:hopper" == blockID) works fine. My assumption is that the inline function cannot see the outside blacklist definition, while it should.

What you expected to happen:

That the script would actually work.

Script used (Please Pastebin or gist your script, posting an unpasted or ungist’d script will automatically close this issue):

val blacklistedBlocks as string[] = [
  "minecraft:hopper"
] as string[];

events.onBlockPlace(function(event as crafttweaker.event.BlockPlaceEvent) {
  val blockID as string = (event.current.block.definition.id + (event.current.block.meta == 0? "" : ":"+event.current.block.meta)) as string;
  if (blacklistedBlocks has blockID) {
    event.cancel();
    event.player.sendChat("This block cannot be placed.");
  }
});

crafttweaker.log file (Please Pastebin or gist your file, posting an unpasted or ungist’d file will automatically close this issue):

[INITIALIZATION][CLIENT][INFO] [crafttweaker | SIDE_CLIENT]: Loading Script: {[0:crafttweaker]: 02_rules\Unplaceables.zs}
[INITIALIZATION][CLIENT][ERROR] [crafttweaker]: Error executing {[0:crafttweaker]: 02_rules\Unplaceables.zs}: Bad local variable type
Exception Details:
  Location:
    ZenClassCrafttweaker02_rules\Unplaceables5.handle(Lcrafttweaker/api/event/BlockPlaceEvent;)V @109: aload
  Reason:
    Type top (current frame, locals[5]) is not assignable to reference type
  Current Frame:
    bci: @109
    flags: { }
    locals: { 'ZenClassCrafttweaker02_rules\Unplaceables5', 'crafttweaker/api/event/BlockPlaceEvent', top, 'java/lang/String' }
    stack: { }
  Bytecode:
    0x0000000: bb00 0f59 b700 102b b900 1601 00b9 001c
    0x0000010: 0100 b900 2201 00b9 0028 0100 b600 2c2b
    0x0000020: b900 1601 00b9 001c 0100 b900 3001 0012
    0x0000030: 319f 0007 03a7 0004 0499 0008 1233 a700
    0x0000040: 28bb 000f 59b7 0010 1235 b600 2c2b b900
    0x0000050: 1601 00b9 001c 0100 b900 3001 00b8 003b
    0x0000060: b600 2cb6 003d b600 2cb6 003d 4e19 052d
    0x0000070: b800 4399 0016 2bb9 0048 0100 2bb9 004c
    0x0000080: 0100 124e b900 5402 00b1               
  Stackmap Table:
    same_locals_1_stack_item_frame(@56,Object[#15])
    full_frame(@57,{Object[#2],Object[#18]},{Object[#15],Integer})
    same_locals_1_stack_item_frame(@65,Object[#15])
    full_frame(@102,{Object[#2],Object[#18]},{Object[#15],Object[#86]})
    append_frame(@137,Top,Object[#86])

java.lang.VerifyError: Bad local variable type
Exception Details:
  Location:
    ZenClassCrafttweaker02_rules\Unplaceables5.handle(Lcrafttweaker/api/event/BlockPlaceEvent;)V @109: aload
  Reason:
    Type top (current frame, locals[5]) is not assignable to reference type
  Current Frame:
    bci: @109
    flags: { }
    locals: { 'ZenClassCrafttweaker02_rules\Unplaceables5', 'crafttweaker/api/event/BlockPlaceEvent', top, 'java/lang/String' }
    stack: { }
  Bytecode:
    0x0000000: bb00 0f59 b700 102b b900 1601 00b9 001c
    0x0000010: 0100 b900 2201 00b9 0028 0100 b600 2c2b
    0x0000020: b900 1601 00b9 001c 0100 b900 3001 0012
    0x0000030: 319f 0007 03a7 0004 0499 0008 1233 a700
    0x0000040: 28bb 000f 59b7 0010 1235 b600 2c2b b900
    0x0000050: 1601 00b9 001c 0100 b900 3001 00b8 003b
    0x0000060: b600 2cb6 003d b600 2cb6 003d 4e19 052d
    0x0000070: b800 4399 0016 2bb9 0048 0100 2bb9 004c
    0x0000080: 0100 124e b900 5402 00b1               
  Stackmap Table:
    same_locals_1_stack_item_frame(@56,Object[#15])
    full_frame(@57,{Object[#2],Object[#18]},{Object[#15],Integer})
    same_locals_1_stack_item_frame(@65,Object[#15])
    full_frame(@102,{Object[#2],Object[#18]},{Object[#15],Object[#86]})
    append_frame(@137,Top,Object[#86])

	at 02_rules\Unplaceables.__script__(02_rules\Unplaceables.zs:6)
	at __ZenMain__.run(02_rules\Unplaceables)
	at crafttweaker.runtime.CrTTweaker.loadScript(CrTTweaker.java:225)
	at crafttweaker.runtime.CrTTweaker.loadScript(CrTTweaker.java:105)
	at crafttweaker.mc1120.events.CommonEventHandler.registerRecipes(CommonEventHandler.java:73)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_376_CommonEventHandler_registerRecipes_Register.invoke(.dynamic)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
	at net.minecraftforge.fml.common.eventhandler.EventBus$1.invoke(EventBus.java:144)
	at com.github.terminatornl.laggoggles.tickcentral.EventBusTransformer.redirectEvent(EventBusTransformer.java:67)
	at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182)
	at net.minecraftforge.registries.GameData.fireRegistryEvents(GameData.java:857)
	at net.minecraftforge.common.crafting.CraftingHelper.loadRecipes(CraftingHelper.java:636)
	at net.minecraftforge.fml.common.Loader.initializeMods(Loader.java:747)
	at net.minecraftforge.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:336)
	at net.minecraft.client.Minecraft.func_71384_a(Minecraft.java:535)
	at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:378)
	at net.minecraft.client.main.Main.main(SourceFile:123)
	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:497)
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

Affected Versions (Do not use “latest”):

  • Minecraft: 1.12
  • Forge: 2854
  • Crafttweaker: 4.1.20.570
  • Using a server: no
  • If yes, does the client have the exact same scripts?

Your most recent log file where the issue was present:

crafttweaker.log

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kindlichcommented, May 16, 2020

Eh… I maybe should’ve pushed this to the correct branches lol

Capturing was added a while back as the errors it threw were well… that.

0reactions
twothecommented, May 16, 2020

Thank you for the quick fix. =)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Array / Loops not working · Issue #350 · CraftTweaker ...
Issue Description: Arrays / Loops don't work and produce severe errors. What happens: Array / Loop with items, strings or integers results ...
Read more >
Arrays and Lists - CraftTweaker Documentation
So if a List's size can be changed but an Array's cannot, why not always use Lists? That comes from the ways that...
Read more >
Arrays and Loops - CraftTweaker Documentation
An array is a List containing several items of the same kind. ... but upon reloading your game, you will get an error...
Read more >
Arrays and Loops - CraftTweaker Documentation
It is declared using [ and ] . Imortant: you must initialize arrays to something, even if it's an empty array. var floatArray...
Read more >
Associative Arrays - CraftTweaker Documentation
as valuetype[keytpe] : Casts the array to it's type. This is required or else CraftTweaker will throw an error. The required types depend...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found