How to use the transformer in HOCON inside the getList()

0
down vote
favorite
So what I have is the below for a config.

"minecraft:blaze" {
"HOB Night" {
    # This Feature has not been Implemented yet
    "============Custom Drops============" {
        # True = Custom Drops, False = Vanilla
        "Enable Custom Drops: "=false
        # List out the Minecraft ID(ie. minecraft:Iron_sword) and the Number of them
        "List of Items and Amount"=
         "minecraft:dirt 5",
         "minecraft:stone 15"
    }
}

So what I have so far is this

ConfigurationManager.getInstance().getSpawnControl().getNode(“minecraft:blaze”, “HOB Night”, “============Custom Drops============”, “List of Items and Amount” ).getList(transformer)

however…i can’t figure out how to get a ‘transformer’ into that portion of the getList feature…Help? I know this is a HOCON question…however no one on Stack overflow has stepped forward to answer it.

Why do you need a transformer? Do you even know what it does?
I think you perhaps have missed that the method is overloaded many times, and doesn’t need a transformer. It also accepts a TypeToken, and if you’re just pulling strings out of it, TypeToken.of(String.class) works just fine.

That said, I highly urge you to reconsider the format of your config. It is recommended for you to use dashed-lowercase for all of your keys, or barring that, at least something easily repeatable. But you’re putting a high value on what the config looks like to someone who doesn’t understand HOCON (especially the key ============Custom Drops============). Fancy formatting, explanations of what things do, etc. is what comments are for, not keys.
What’s more, those ‘items and amounts’ values have to be manually parsed, and it would make much more sense to let the existing libraries do the work for you. I would probably structure it as

items-list {
    "minecraft:dirt" = 5
    "minecraft:stone" = 15
}

or, even better,

items-list = [
    {
        id = "minecraft:dirt"
        count = 5
    }
    {
        id = "minecraft:stone"
        count = 15
    }
]

and let Configurate parse out the ItemTypes and ints.

1 Like

No I don’t know what a transformer is but that’s what it was pointing too.
The first one you’re showing would probably be my best bet. As I want it to be simple enough for a player to add or remove items and amounts through the config. So I’ll do some more research on using the TypeToken instead of a transformer.
Now when you say parsed in this method do you mean like .getList(TypeToken.of(string.class), int)? Or am I missing something obvious? I’m trying to learn and I was thinking of trying to put the strings in a collection then doing a while loop for each Entity in it…but I can’t figure that out quite yet lol

Also thank you for your patience in answering this. I know it’s not directly linked with sponge as its HOCON so thank you. A ton

With your current config schema, you would call getList(TypeToken.of(String.class)). What’s going on here is that the default method would be getChildrenList, which would return a list of ConfigurationNodes. For it to return a list of anything else, it has to understand what to extract each ConfigurationNode into. In this case, you want to just get the string values, so you tell it to get a list of strings (TypeToken is similar to Class, but supporting generics). Transformer would be for if you wanted to use your own method of converting ConfigurationNodes.

1 Like

As away ok nite I understand. Thank you!