Error executing {[0:crafttweaker]: dungeonloot.zs}: java.util.Optional
DMBuce opened this issue ยท 2 comments
I'm getting Error executing {[0:crafttweaker]: dungeonloot.zs}: java.util.Optional
with this:
rare.addItemEntryJson( <minecraft:enchanted_book> * 1, 10,
0,
[
{"levels": 30.0, "treasure": true, "function": "minecraft:enchant_with_levels"}
],
[]
);
I put the full script I'm using plus the stack trace from crafttweaker.log
at the bottom of this ticket.
If I comment out the above lines, the script doesn't error.
I also don't get the error if I downgrade to LootTweaker-1.12.2-0.0.10.jar
.
Is this a bug or am I doing something wrong?
Here's the full script:
# LootTweaker imports
import loottweaker.vanilla.loot.LootTables;
import loottweaker.vanilla.loot.LootTable;
import loottweaker.vanilla.loot.LootPool;
# set up loot table
val table = LootTables.getTable("dimdoors:dungeon_chest");
val main = table.addPool("main", 6, 10, 0, 0);
val rare = table.addPool("treasure", 1, 2, 0, 0);
table.removePool("default");
table.removePool("ench_book");
##############
# rare items #
##############
# low-tier rewards
rare.addItemEntry( <thaumcraft:loot_bag:0> * 1, 10 );
rare.addItemEntry( <thaumcraft:loot_bag:1> * 1, 5 );
rare.addItemEntry( <thaumcraft:loot_bag:2> * 1, 2 );
rare.addItemEntry( <minecraft:mycelium> * 16, 10 );
rare.addItemEntry( <minecraft:grass> * 16, 10 );
rare.addItemEntry( <minecraft:packed_ice> * 16, 10 );
rare.addItemEntry( <minecraft:sea_lantern> * 16, 10 );
rare.addItemEntry( <minecraft:web> * 8, 10 );
rare.addItemEntry( <minecraft:sponge> * 8, 10 );
rare.addItemEntry( <minecraft:name_tag> * 1, 10 );
rare.addItemEntry( <minecraft:saddle> * 1, 10 );
rare.addItemEntry( <minecraft:blaze_rod> * 1, 10 );
rare.addItemEntry( <minecraft:ghast_tear> * 1, 10 );
rare.addItemEntry( <minecraft:ender_pearl> * 2, 10 );
# mid-tier rewards
rare.addItemEntry( <thaumcraft:levitator> * 1, 10 );
rare.addItemEntry( <thaumcraft:golem>.withTag({props: 0 as long}) * 1, 10 );
rare.addItemEntry( <minecraft:anvil> * 1, 10 );
rare.addItemEntry( <minecraft:enchanting_table> * 1, 10 );
rare.addItemEntryJson( <minecraft:enchanted_book> * 1, 10,
0,
[
{"levels": 30.0, "treasure": true, "function": "minecraft:enchant_with_levels"}
],
[]
);
# high-tier rewards
rare.addItemEntry( <thaumcraft:creative_flux_sponge> * 1, 10 );
rare.addItemEntry( <minecraft:skull:1> * 2, 10 );
#rare.addItemEntry( <minecraft:nether_star> * 1, 10 );
#rare.addItemEntry( <minecraft:end_portal_frame> * 1, 10 );
rare.addItemEntry( <minecraft:ender_chest> * 1, 10 );
#rare.addItemEntry( <minecraft:beacon> * 1, 10 );
rare.addItemEntry( <minecraft:elytra> * 1, 10 );
rare.addItemEntry( <minecraft:black_shulker_box> * 1, 10 );
rare.addItemEntry( <minecraft:cyan_shulker_box> * 1, 10 );
rare.addItemEntry( <minecraft:brown_shulker_box> * 1, 10 );
rare.addItemEntry( <minecraft:blue_shulker_box> * 1, 10 );
rare.addItemEntry( <minecraft:gray_shulker_box> * 1, 10 );
rare.addItemEntry( <minecraft:green_shulker_box> * 1, 10 );
rare.addItemEntry( <minecraft:light_blue_shulker_box> * 1, 10 );
rare.addItemEntry( <minecraft:lime_shulker_box> * 1, 10 );
rare.addItemEntry( <minecraft:magenta_shulker_box> * 1, 10 );
rare.addItemEntry( <minecraft:orange_shulker_box> * 1, 10 );
rare.addItemEntry( <minecraft:pink_shulker_box> * 1, 10 );
rare.addItemEntry( <minecraft:purple_shulker_box> * 1, 10 );
rare.addItemEntry( <minecraft:red_shulker_box> * 1, 10 );
rare.addItemEntry( <minecraft:silver_shulker_box> * 1, 10 );
rare.addItemEntry( <minecraft:white_shulker_box> * 1, 10 );
rare.addItemEntry( <minecraft:yellow_shulker_box> * 1, 10 );
################
# common items #
################
# ores
main.addItemEntry( <minecraft:coal_ore> * 16, 10 );
main.addItemEntry( <minecraft:iron_ore> * 8, 10 );
main.addItemEntry( <minecraft:gold_ore> * 4, 10 );
main.addItemEntry( <minecraft:redstone_ore> * 4, 10 );
main.addItemEntry( <minecraft:quartz_ore> * 4, 10 );
main.addItemEntry( <minecraft:lapis_ore> * 2, 10 );
main.addItemEntry( <minecraft:diamond_ore> * 2, 10 );
main.addItemEntry( <minecraft:emerald_ore> * 1, 10 );
#main.addItemEntry( <thaumcraft:amber> * 1, 10 );
#main.addItemEntry( <thaumcraft:ore_amber> * 1, 10 );
main.addItemEntry( <thaumcraft:ore_cinnabar> * 1, 10 );
main.addItemEntry( <thaumcraft:quicksilver> * 4, 10 );
#main.addItemEntry( <thaumcraft:ore_quartz> * 1, 10 );
#main.addItemEntry( <thaumcraft:ingot:0> * 1, 10 );
#main.addItemEntry( <thaumcraft:ingot:2> * 1, 10 );
# saplings
main.addItemEntry( <thaumcraft:sapling_greatwood> * 8, 10 );
main.addItemEntry( <thaumcraft:sapling_silverwood> * 2, 10 );
main.addItemEntry( <minecraft:sapling:0> * 2, 10 ); # oak
main.addItemEntry( <minecraft:sapling:1> * 4, 10 ); # spruce
main.addItemEntry( <minecraft:sapling:2> * 2, 10 ); # birch
main.addItemEntry( <minecraft:sapling:3> * 4, 10 ); # jungle
main.addItemEntry( <minecraft:sapling:4> * 2, 10 ); # acacia
main.addItemEntry( <minecraft:sapling:5> * 8, 10 ); # dark oak
# blocks
main.addItemEntry( <minecraft:dirt> * 32, 10 );
main.addItemEntry( <minecraft:stone> * 32, 10 );
main.addItemEntry( <minecraft:cobblestone> * 32, 10 );
main.addItemEntry( <minecraft:gravel> * 32, 10 );
main.addItemEntry( <minecraft:sand> * 32, 10 );
main.addItemEntry( <minecraft:snow> * 16, 10 );
main.addItemEntry( <minecraft:ice> * 16, 10 );
#main.addItemEntry( <minecraft:prismarine> * 16, 10 );
main.addItemEntry( <minecraft:clay> * 16, 10 );
main.addItemEntry( <minecraft:obsidian> * 16, 10 );
main.addItemEntry( <thaumcraft:log_greatwood> * 8, 10 );
main.addItemEntry( <thaumcraft:log_silverwood> * 8, 10 );
main.addItemEntry( <minecraft:log> * 8, 10 );
main.addItemEntry( <minecraft:log2> * 8, 10 );
main.addItemEntry( <minecraft:piston> * 8, 10 );
# crops
#main.addItemEntry( <thaumcraft:vishroom> * 2, 10 );
#main.addItemEntry( <thaumcraft:shimmerleaf> * 2, 10 );
main.addItemEntry( <minecraft:egg> * 12, 10 );
main.addItemEntry( <minecraft:carrot> * 2, 10 );
main.addItemEntry( <minecraft:potato> * 2, 10 );
main.addItemEntry( <minecraft:wheat_seeds> * 4, 10 );
main.addItemEntry( <minecraft:beetroot_seeds> * 4, 10 );
main.addItemEntry( <minecraft:brown_mushroom> * 8, 10 );
main.addItemEntry( <minecraft:red_mushroom> * 8, 10 );
main.addItemEntry( <minecraft:reeds> * 2, 10 );
main.addItemEntry( <minecraft:cactus> * 2, 10 );
main.addItemEntry( <minecraft:pumpkin> * 1, 10 );
main.addItemEntry( <minecraft:melon_block> * 1, 10 );
main.addItemEntry( <minecraft:vine> * 4, 10 );
main.addItemEntry( <minecraft:waterlily> * 16, 10 );
# drops
#main.addItemEntry( <minecraft:bone> * 1, 10 );
#main.addItemEntry( <minecraft:bone_block> * 1, 10 );
# nether
main.addItemEntry( <minecraft:lava_bucket> * 1, 10 );
main.addItemEntry( <minecraft:blaze_powder> * 4, 10 );
# end
#main.addItemEntry( <minecraft:chorus_flower> * 1, 10 );
# other resources
main.addItemEntry( <thaumcraft:mechanism_simple> * 2, 10 );
main.addItemEntry( <dimdoors:world_thread> * 4, 10 );
main.addItemEntry( <minecraft:paper> * 8, 10 );
main.addItemEntry( <minecraft:book> * 8, 10 );
main.addItemEntry( <minecraft:bookshelf> * 8, 10 );
main.addItemEntry( <minecraft:prismarine_crystals> * 32, 10 );
main.addItemEntry( <minecraft:prismarine_shard> * 32, 10 );
And the stack trace from crafttweaker.log:
[INITIALIZATION][CLIENT][INFO] Queued item entry 'loottweaker#17' for addition to pool treasure of table dimdoors:dungeon_chest
[INITIALIZATION][CLIENT][INFO] Queued item entry 'loottweaker#18' for addition to pool treasure of table dimdoors:dungeon_chest
[INITIALIZATION][CLIENT][ERROR] [crafttweaker]: Error executing {[0:crafttweaker]: dungeonloot.zs}: java.util.Optional
java.lang.ArrayStoreException: java.util.Optional
at java.util.stream.Nodes$FixedNodeBuilder.accept(Nodes.java:1222)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:546)
at java.util.stream.AbstractPipeline.evaluateToArrayNode(AbstractPipeline.java:260)
at java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:505)
at leviathan143.loottweaker.common.zenscript.wrapper.ZenLootPoolWrapper.addItemEntryJson(ZenLootPoolWrapper.java:138)
at Dungeonloot.__script__(dungeonloot.zs:39)
at __ZenMain__.run(Dungeonloot)
at crafttweaker.runtime.CrTTweaker.loadScript(CrTTweaker.java:225)
at crafttweaker.runtime.CrTTweaker.loadScript(CrTTweaker.java:105)
at crafttweaker.mc1120.events.CommonEventHandler.registerRecipes(CommonEventHandler.java:69)
at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_147_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 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:629)
at net.minecraftforge.fml.common.Loader.initializeMods(Loader.java:742)
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:498)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
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.multimc.onesix.OneSixLauncher.launchWithMainClass(OneSixLauncher.java:196)
at org.multimc.onesix.OneSixLauncher.launch(OneSixLauncher.java:231)
at org.multimc.EntryPoint.listen(EntryPoint.java:143)
at org.multimc.EntryPoint.main(EntryPoint.java:34)
[INITIALIZATION][CLIENT][INFO] [crafttweaker | SIDE_CLIENT]: Loading Script: {[0:crafttweaker]: events.zs}
[INITIALIZATION][CLIENT][INFO] [crafttweaker | SIDE_CLIENT]: Loading Script: {[0:crafttweaker]: flint.zs}
[INITIALIZATION][CLIENT][INFO] Translating item.pickaxe_flint.name to Sharpened Flint
Is this a bug or am I doing something wrong?
LootTweaker gives MUCH friendlier errors than that if you do something wrong. It's a bug, I bungled some of the parsed function and condition processing code for that method.
For now you can workaround the issue by using LootPool#addItemEntryHelper() instead of LootPool#addItemEntryJson(). Either use the appropriate convenience method of loottweaker.vanilla.loot.Functions, or Functions#parse().
Since the documentation for LootPool#addItemEntryJson() is not great, here's some examples
...
import loottweaker.vanilla.loot.Functions;
somePool.addItemEntryHelper(<minecraft:apple>, 10, 1,
[
Functions.enchantWithLevels(30, 30, true)
], []);
...
import loottweaker.vanilla.loot.Functions;
somePool.addItemEntryHelper(<minecraft:apple>, 10, 1,
[
Functions.parse({"levels": 30.0, "treasure": true, "function": "minecraft:enchant_with_levels"})
], []);