Integrated Dynamics

Integrated Dynamics

63M Downloads

Cannot create operator to extract NBT data

PaulMurrayCbr opened this issue Ā· 7 comments

commented

Issue type:

question: Question

Short description:

I am attempting to create an operator that will read the Item.tag.astralsorcery.crystalProperties.size and .collectiveCapability property of an entity variable. The goal is to farm maxed-out celestial crystals.

I'm finding that I cannot build an operator that does what NBT.tag() does.

Without this, I cannot use item exporters with predicate to sort the crystals into bins according to their NBT properties.

Steps to reproduce the problem:

I dropped an astral sorcery celestial crystal in front of an entity reader.
I created a variable c_entity from the entity aspect.
Putting this in a display confirmed that the entity was being read ok.

I created an Entity Entity NBT operator variable 'op_NBT' using the Operator entry in the portable programmer.
I created a variable c_nbt by applying variable c_entity to operator op_NBT.
Putting this in a display confirmed that the NBT of the crystal was being extracted.

I created a string variable s_opname containing 'NBT.tag()', which is what appears in the list of operators visible in the portable programmer.
I created a string 'Item'
I created an operator 'op_tag' using 'operator by name' with s_opname.
I applied the two arguments c_nbt and 'Item' to the operator op_tag.
I placed this in a display. It didn't work. The error was 'could not find the operator with the name NBT.tag()'

I altered the variable s_opname to 'NBT.tag', 'tag()', and 'tag'. None of which worked, all giving the same error in the display with the operator name being correctly changed each time.

I tried creating an operator named 'Item', and applied that operator to c_nbt, with the thought that perhaps the entries of the NBT object might be treated as methods. This also didn't work: 'could not find the operator with the name Item'.

I attempted to use the pipe operator directly with the string 'Item', but pipe requires an operator as its second argument and won't take a string.

Briefly

So, the question is: how to create operator that reads an given entry from an NBT variable?

After doing this, I can hopefully use the pipe operator to navigate down the whole chain, and wind up with an operator that I can use to build item export predicates and so on.

The somewhat broader question is: is there a manual that I should have read which describes how to do this?

commented

I'm not seeing NBT operators inside an item exporter (this is in Integrated tunnels). I'm seeing export all items (boolean), export item amount (int), export item slot (int), export item ā€¦ which takes an item- to-match, and maybe that will do the job, export items (taking a list?), and export items predicate. It's export items predicate that takes a predicate.

Export Item has an NBT yes/no check, but I need to make finer distinctions than that. Crystals that have a size of 900 and a cutting of 100 go to the output chest, crystals with a size of less than 900 go to the crystal growth chamber, and crystals with a maxed-out size that are not cut perfectly go to the grindstone to be cut.

That is, I want to make export decisions based on specific parts of the NBT data, involving numeric comparisons. Now, I can do it just by building NBT variables using an entity reader, and this seems to work ok. But each place where I need a decision I have to build a chain of NBT.tag() objects. Creating a lambda to do the job is more the right way to go about it.

commented

Try updating to the latest version of IT for the NBT operators inside the tunnels.

Regarding the operators, you'll have to play around with partially applied operators. (see 'apply' operator)

commented

Ok. I'm using the FTB "New Horizons III" pack, and I'm not going to fool about with it. If it has an older version of IT and the newer version would do what I want, well, as far as I'm concerned I have explored the modpack to my satisfaction.

Partially applied operators would be useful (presumably it gives you back an operator with one of the free variables bound), but it doesn't address the issue of not being able to pull out NBT map values using an operator at all. If there was such a primitive, then yes creating a single-argument operator to pull out some particular key by binding the second argument would be very nice.

I suppose we can mark my question as answered. The version I am using won't do it, newer versions might or might not.

commented

Oh - looking through the source. Also tried
operators.operator.integrateddynamics.nbt.valueTag
integrateddynamics.nbt.valueTag
nbt.valueTag

As operator names. No luck. I might need to attach a debugger and find out what keys wind up in the operator uniquename map.

commented

Did you already have a look at the NBT-based operators inside the importers/exporters? Those might be able to help you accomplish the same thing in an easier way.

commented

@dalgrim I hadn't realised that his was still open - sorry peoples. That page there is actually mine, after I worked out how to do it. The key was using the 'operator' tab rather than 'operator by name'.

commented

read: https://paulmurray.wordpress.com/2018/03/04/more-minecraft/
step by step building of the exact operator you want.

Paul Murray's Blog
This is going to get very freaky, very weird. Oh, maybe not for people who already have a particular kink ā€“ people with lisps, Haskel programmers. But everyone not already an FP weenie will nā€¦