Dropt

Dropt

3M Downloads

Setting rules via zen script associative array/key, value loops causes crash

hanleybrand opened this issue ยท 3 comments

commented

Issue Description

I am trying to replace block drops based on an associative array and a key/value loop but the loop causes the client to crash while loading. I put #debug at the top of my script

I know how to program in other languages, and know a little java but have very little zen script experience (sorry I'm pretty certain the issue is going to be something that should be obvious)

What Happens

The client fails to launch, the error is:

net.minecraftforge.fml.common.LoaderExceptionModCrash: Caught exception from Dropt (dropt)
Caused by: java.lang.NullPointerException
	at com.codetaylor.mc.dropt.modules.dropt.rule.parse.ParserRuleMatchBlocks.parse(ParserRuleMatchBlocks.java:42)
	at com.codetaylor.mc.dropt.modules.dropt.rule.RuleLoader.parseRuleLists(RuleLoader.java:153)
	at com.codetaylor.mc.dropt.modules.dropt.ModuleDropt.onLoadCompleteEvent(ModuleDropt.java
... java java java
... stack trace stack trace stack trace

What You Expect to Happen

I expected it to not crash and for all of my code to work beautifully

Ha ha, no I was just hoping that the associative array loop would work, similar to the examples in the Zscript docs:

https://docs.blamejared.com/1.12/en/#AdvancedFunctions/Associative_Arrays/

except I'm basically trying to get like 8 or 9 fruit bush blocks that only drop themselves to also drop the fruits that one would expect if you break the blocks normally, but to drop themselves if broken by a shovel.

Script

Here is the script snippet that causes the crash (removing the loop fixes the crash), so it's not the associative array in itself -- I guess I should mention that /ct syntax reports no errors, but I know that's no guarantee something will actually work:

// change break rules for conquest berry bushes so that if the player breaks them 
// a) without a shovel they get berries, but 
// b) with a shovel they get the bush

val crBerryBushes = {
	<conquest:hollyberry_food> : <conquest:leaves_hollyberry>,
	<conquest:hawthorn_food> : <conquest:bush_hawthorn>,
// ... 
	<conquest:blackberry_food> : <conquest:bush_blackberry>
} as IItemStack[IItemStack];

for key, value in crBerryBushes {
	//no shovel
	Dropt.list("conquest_drops")
	  .add(Dropt.rule()
		  .matchBlocks([ crBerryBushes[value] ])
		  .addDrop(Dropt.drop()
			  .items([ crBerryBushes[key] ])
		  )
	  );	
	  // shovel
	  Dropt.list("conquest_drops")
	  .add(Dropt.rule()
	  .matchBlocks([ crBerryBushes[value] ])
	  .matchHarvester(Dropt.harvester()
		  .type("PLAYER")
		  .mainHand("BLACKLIST", [], "shovel;0;-1")
	  )
	  .addDrop(Dropt.drop().items([ crBerryBushes[value] ]))
	);
}

I also tried just key and value instead of crBerryBushes[key] and/or crBerryBushes[value]

full script at
https://gist.github.com/hanleybrand/0cd9248bdf9d0f2064b7d31a9c66a3ac#file-dropt-zs

Crash Log

https://gist.githubusercontent.com/hanleybrand/0cd9248bdf9d0f2064b7d31a9c66a3ac/raw/3c63d7408125cd0d60af11940c11e947a6bf2ecf/debug.log

Affected Versions

  • Minecraft:1.12.2
  • Forge: 14.23.5.2847
  • CraftTweaker:2-1.12-4.1.20
  • Dropt: 1.12.2-1.16.1
  • Athenaeum:1.12.2-1.17.4
commented

I notice you are passing an array of IItemStack to matchBlocks(string[]). Broken blocks are matched against block strings which describe an in-world blockstate.

More info here: https://dropt.readthedocs.io/en/latest/blockstrings/
Discord: http://discord.codetaylor.com

commented

Can you recommend a good strategy for something like this? I realize a lot of my issue is not being super familiar with zen script, but the types are pretty confusing, and there don't seem to be standardized methods for any of them (like .asBlock() or .toString()).

Should I make the array from <bracket.items> or build from stings? Or am I being dumb and should I just make a JSON file or a super long non-DRY redundant script file that does each block in a row?

commented

If it were me, I'd just change your values to the appropriate strings.

CraftTweaker has a Discord with a lot of knowledgeable people over there, I recommend checking it out: https://discord.blamejared.com