#Creating custom items automatically from a config file

1 messages · Page 1 of 1 (latest)

brisk tundra
#

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

dawn violet
#

Right

#

So

#

What do you want them to be able to set in config?

#

@brisk tundra

chrome quarry
#

Can you explain more, what is custom items?

#

What is the goal for all of this?

brisk tundra
#

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.

brisk tundra
#
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

dawn violet
#

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

chrome quarry
#

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.

brisk tundra
#

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

brisk tundra
chrome quarry
#

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.

brisk tundra
#

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

brisk tundra
#

I've about 5 hours of idle time today so I'm gonna see what I can do in that time

dawn violet
#

well