#Creating custom items automatically from a config file
1 messages · Page 1 of 1 (latest)
I feel like I am just asking this over and over, but I just can't seem to figure this one out. Please feel free to point me to blogposts, videos, articles etc... I just want to get this done without being given code
Okay so I'm adding some rare versions of the different oretypes. The drop mechanism is already solved. They should have three properties:
Display name, oretype, drop chance.
I have a configuration setup but I'm not able to get to it right now. I'll post here once I'm back home. Thank you for your help so far.
Ores:
Gold:
Name: "Perfect Gold Ingot"
Material: "GOLD_ORE"
Chance: 50
So something like that
and it'll have multiple down at the same level as gold
say for every ore in the gme
Well that’s pretty easy i’d say
just get all the keys of “ores” then get each as a config section. then get the name, material to make the itemstack. and then maybe have a map or some way of looking up the % drop chance on the block break event
Also make sure to cache it on a field or something, so you don't need to getting the value directly on the config every successful chance in BlockBreakEvent.
Yeah it's the part about actually creating the itemstack that has me a little stuck. I want it to parse through the config and create each itemstack automatically but I haven't been able to set that up. I was given some code but I have no idea how to implement it so I'm just as far.
I was thinking of doing something similar to a for or foreach loop in JS, just going through each element and passing it to another function that does the work and uses the parameters it's given to fill in the blanks
Good point. I had forgotten about that when I worked on the blockbreak
So you want to create an object called OreItem or whatever.
public class OreItem{
private final String name;
private final String material;
private final int chance;
// constructor
// getter
}
And then you can load the items on the config using for loop FileConfiguration#getConfigurationSection, and then store it somewhere.
public class OreLoader{
private final List<OreItem> oreItems = new ArrayList<>();
public void loadOres(){
FileConfiguration config = ...;
for(String key : config.getConfigurationSection("Ores").getKeys(false)){
String name = ...;
String material = ...;
int chance = ...;
oreItems.add(new OreItem(...));
}
}
}
Something like that.
There is a better way for the OreItem object but that's what comes first on my mind.
record could be used here
Oh my god... Thank you. I should've realized sooner but putting it exactly like you did made me realize how overworked I must've been.
I knew all that I just didn't realize I knew it, thank you. I'm sure I can solve it now. I'll start back up Sunday or Monday, for now I want to enjoy my weekend. Thank you for your help, as with you olijeffersOn
I've about 5 hours of idle time today so I'm gonna see what I can do in that time
well