2016-05-18 17:04:27 +00:00
|
|
|
package me.mrCookieSlime.Slimefun.GEO;
|
|
|
|
|
2016-05-18 20:31:49 +00:00
|
|
|
import java.util.Collection;
|
2019-09-26 13:22:42 +00:00
|
|
|
import java.util.concurrent.ThreadLocalRandom;
|
2019-08-31 15:52:20 +00:00
|
|
|
import java.util.logging.Level;
|
2016-05-18 17:04:27 +00:00
|
|
|
|
|
|
|
import org.bukkit.Chunk;
|
|
|
|
import org.bukkit.block.Biome;
|
|
|
|
|
|
|
|
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
|
2019-08-31 09:36:45 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
|
2016-05-18 17:04:27 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
2019-08-31 15:52:20 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
2016-05-18 17:04:27 +00:00
|
|
|
|
2019-08-27 12:08:09 +00:00
|
|
|
public final class OreGenSystem {
|
|
|
|
|
|
|
|
private OreGenSystem() {}
|
2016-05-18 17:04:27 +00:00
|
|
|
|
2016-05-18 20:31:49 +00:00
|
|
|
public static Collection<OreGenResource> listResources() {
|
2019-08-31 09:36:45 +00:00
|
|
|
return SlimefunPlugin.getUtilities().resources.values();
|
2016-05-18 20:31:49 +00:00
|
|
|
}
|
|
|
|
|
2016-05-18 17:04:27 +00:00
|
|
|
public static void registerResource(OreGenResource resource) {
|
2019-09-23 15:50:35 +00:00
|
|
|
Config cfg = new Config("plugins/Slimefun/generators/" + resource.getName() + ".yml");
|
|
|
|
cfg.setDefaultValue("enabled", true);
|
2016-05-18 17:04:27 +00:00
|
|
|
for (Biome biome: Biome.values()) {
|
2019-09-23 15:50:35 +00:00
|
|
|
cfg.setDefaultValue("spawn-rates." + biome.toString(), resource.getDefaultSupply(biome));
|
2016-05-18 17:04:27 +00:00
|
|
|
}
|
|
|
|
cfg.save();
|
2019-09-23 15:50:35 +00:00
|
|
|
|
|
|
|
if (cfg.getBoolean("enabled")) {
|
|
|
|
Slimefun.getLogger().log(Level.INFO, "Registering Ore Gen: " + resource.getName());
|
|
|
|
SlimefunPlugin.getUtilities().resources.put(resource.getName(), resource);
|
|
|
|
SlimefunPlugin.getUtilities().resource_configs.put(resource.getName(), cfg);
|
|
|
|
}
|
2016-05-18 17:04:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static OreGenResource getResource(String name) {
|
2019-08-31 09:36:45 +00:00
|
|
|
return SlimefunPlugin.getUtilities().resources.get(name);
|
2016-05-18 17:04:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static int getDefault(OreGenResource resource, Biome biome) {
|
2019-09-23 15:50:35 +00:00
|
|
|
if (resource == null) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else {
|
2019-09-26 13:22:42 +00:00
|
|
|
int supply = SlimefunPlugin.getUtilities().resource_configs.get(resource.getName()).getInt("spawn-rates." + biome.toString());
|
|
|
|
return supply > 0 ? (supply + ThreadLocalRandom.current().nextInt(3)): 0;
|
2019-09-23 15:50:35 +00:00
|
|
|
}
|
2016-05-18 17:04:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void setSupplies(OreGenResource resource, Chunk chunk, int amount) {
|
2019-09-23 15:50:35 +00:00
|
|
|
if (resource != null) {
|
|
|
|
BlockStorage.setChunkInfo(chunk, "resources_" + resource.getName().toUpperCase(), String.valueOf(amount));
|
|
|
|
}
|
2016-05-18 17:04:27 +00:00
|
|
|
}
|
|
|
|
|
2016-11-26 19:25:36 +00:00
|
|
|
public static int generateSupplies(OreGenResource resource, Chunk chunk) {
|
|
|
|
if (resource == null) return 0;
|
2019-09-23 15:50:35 +00:00
|
|
|
|
|
|
|
int supplies = getDefault(resource, chunk.getBlock(7, 60, 7).getBiome());
|
2016-05-18 17:04:27 +00:00
|
|
|
BlockStorage.setChunkInfo(chunk, "resources_" + resource.getName().toUpperCase(), String.valueOf(supplies));
|
|
|
|
return supplies;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getSupplies(OreGenResource resource, Chunk chunk, boolean generate) {
|
2016-11-26 19:25:36 +00:00
|
|
|
if (resource == null) return 0;
|
2019-09-23 15:50:35 +00:00
|
|
|
|
2019-10-27 19:07:12 +00:00
|
|
|
String supply = BlockStorage.getChunkInfo(chunk, "resources_" + resource.getName().toUpperCase());
|
|
|
|
if (supply != null) {
|
|
|
|
return Integer.parseInt(supply);
|
2016-05-18 17:04:27 +00:00
|
|
|
}
|
|
|
|
else if (!generate) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return generateSupplies(resource, chunk);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean wasResourceGenerated(OreGenResource resource, Chunk chunk) {
|
2016-11-26 19:25:36 +00:00
|
|
|
if (resource == null) return false;
|
2016-05-18 17:04:27 +00:00
|
|
|
return BlockStorage.hasChunkInfo(chunk, "resources_" + resource.getName().toUpperCase());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|