LootTweaker

LootTweaker

17M Downloads

Adding a pool with addPool() and then retrieving it with getPool() causes all actions performed on that pool to be performed twice

MisterObvious25 opened this issue ยท 6 comments

commented

Description:

Trying to use a script to remove all the loot pools in the loot table simple dungeons, then add the pool main back and try to add iron ingot. when using game shows error cannot be executed

The item is in "pool1", but if i remove the pool, i still cant add the item to another pool, is this intended behavior??

Removing the item from pool1, before adding it to my pool "test" works, but i was trying to remove the whole to so that i don't need to remove every single item from the pool.

Also tried adding simpleDungeon.clear();(with the script below) but that is not working at all.

Steps to reproduce:
Add script to script directory.
Start the game.
Create new world.
World wont load.

Script Used
import loottweaker.vanilla.loot.LootTables;
import loottweaker.vanilla.loot.LootTable;
import loottweaker.vanilla.loot.LootPool;
import loottweaker.vanilla.loot.Conditions;
import loottweaker.vanilla.loot.Functions;

val simpleDungeon = LootTables.getTable("minecraft:chests/simple_dungeon");

simpleDungeon.removePool("main");
simpleDungeon.removePool("pool1");
simpleDungeon.removePool("pool2");
//simpleDungeon.removePool("ic2");
//simpleDungeon.removePool("forestry_apiculture_bees");
//simpleDungeon.removePool("randomthings:lavaCharm");
//simpleDungeon.removePool("randomthings:summoningPendulum");
//simpleDungeon.removePool("randomthings:magicHood");
//simpleDungeon.removePool("randomthings:slimeCube");
//simpleDungeon.removePool("randomthings:biomeCrystal");
//simpleDungeon.removePool("botania_inject_pool");
//simpleDungeon.removePool("xreliquary_inject_pool");

simpleDungeon.addPool("test", 3, 7, 0, 0);

val test = simpleDungeon.getPool("test");

test.addItemEntry(<minecraft:iron_ingot>, 1, 1);

Version Info(Exact versions only):
LootTweaker-1.11.2-0.0.6.2.jar
CraftTweaker-1.11.2-3.0.26.jar
forge:1.11.2-13.20.0.2315
Minecraft:1.11.2

Logs and other useful information:
https://pastebin.com/ubVXbAFB

commented

Your script is not valid ZenScript.
This line is not valid:
test.addItemEntry(minecraft:iron_ingot, 1, 1);
It should be
test.addItemEntry(<minecraft:iron_ingot>, 1, 1);

commented

Yes, thank you, was a typo, but unfortunately i still get the error

commented

The script you have linked is still invalid ZenScript.

commented

Could you be a little more specific because using this script

import loottweaker.vanilla.loot.LootTables;
import loottweaker.vanilla.loot.LootTable;
import loottweaker.vanilla.loot.LootPool;
import loottweaker.vanilla.loot.Conditions;
import loottweaker.vanilla.loot.Functions;

val simpleDungeon = LootTables.getTable("minecraft:chests/simple_dungeon");

simpleDungeon.removePool("main");
simpleDungeon.removePool("pool1");
simpleDungeon.removePool("pool2");
//simpleDungeon.removePool("ic2");
//simpleDungeon.removePool("forestry_apiculture_bees");
//simpleDungeon.removePool("randomthings:lavaCharm");
//simpleDungeon.removePool("randomthings:summoningPendulum");
//simpleDungeon.removePool("randomthings:magicHood");
//simpleDungeon.removePool("randomthings:slimeCube");
//simpleDungeon.removePool("randomthings:biomeCrystal");
//simpleDungeon.removePool("botania_inject_pool");
//simpleDungeon.removePool("xreliquary_inject_pool");

simpleDungeon.addPool("test", 3, 7, 0, 0);

val test = simpleDungeon.getPool("test");

Seems to work fine. running "/mt loottables all" shows that all pools from the loot table simple_dungeon are removed and test is added with the min/max rolls. Its when i add " test.addItemEntry(<minecraft:iron_ingot>, 1, 1); " and use "/mt reload" that the error occurs.

commented

Yes, same error occurs when relaunching minecraft with the full script

commented

I think I've found the cause, but the fix is going to be complex. The issue is that getPool() and addPool() "mark" the pools as added and pre-existing respectively. If a pool gets both marks LootTweaker tries to do everything twice, which doesn't work.

addPool() actually returns the pool it creates (I forgot to document this, it's documented now), which means that you can avoid the call to getPool() and the pool won't get both marks.
This issue doesn't occur with preexisting pools, it only occurs if a pool is added with addPool() and then retrieved with getPool().