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 ItemType
s and int
s.
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 ConfigurationNode
s. 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 ConfigurationNode
s.
1 Like
As away ok nite I understand. Thank you!