Skip to content

Commit

Permalink
Updated list type to use enum instead of boolean values
Browse files Browse the repository at this point in the history
  • Loading branch information
HyCraftHD committed Jul 10, 2019
1 parent 89b4d88 commit d0aab14
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 38 deletions.
36 changes: 30 additions & 6 deletions src/main/java/info/u_team/useful_ores/api/IGeneratable.java
Expand Up @@ -10,37 +10,37 @@ public interface IGeneratable {

boolean isEnabled();

boolean isBiomeCategoryBlackList();
ListType getBiomeCategoryListType();

List<Category> getBiomeCategories();

boolean isBiomeBlackList();
ListType getBiomeListType();

List<Biome> getBiomes();

int getVeinSize();

Type getType();
GenerationConfig getGenerationConfig();

CountRangeConfig getCountRangeConfig();

DepthAverageConfig getDepthAverageConfig();

public static enum Type {
public static enum GenerationConfig {
COUNT_RANGE("count_range"),
COUNT_DEPTH_AVERAGE("count_depth_average");

private final String name;

private Type(String name) {
private GenerationConfig(String name) {
this.name = name;
}

public String getName() {
return name;
}

public static Type byName(String name) {
public static GenerationConfig byName(String name) {
if ("count_range".equals(name)) {
return COUNT_RANGE;
}
Expand All @@ -51,4 +51,28 @@ public static Type byName(String name) {
}
}

public static enum ListType {
BLACKLIST("blacklist"),
WHITELIST("whitelist");

private final String name;

private ListType(String name) {
this.name = name;
}

public String getName() {
return name;
}

public static ListType byName(String name) {
if ("blacklist".equals(name)) {
return BLACKLIST;
}
if ("whitelist".equals(name)) {
return WHITELIST;
}
return null;
}
}
}
Expand Up @@ -11,6 +11,7 @@

import info.u_team.useful_ores.UsefulOresMod;
import info.u_team.useful_ores.api.IGeneratable;
import info.u_team.useful_ores.api.IGeneratable.ListType;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biome.Category;
import net.minecraft.world.gen.placement.*;
Expand Down Expand Up @@ -48,7 +49,7 @@ private CommonConfig(Builder builder) {
// CountRangeConfig(20, 0, 0, 64), null), new GeneratableConfig(true, false, new Category[] { Category.NETHER }, true,
// new Biome[] {}, 9, IGeneratable.Type.COUNT_RANGE, new CountRangeConfig(16, 10, 20, 128), null));

copper = createResourceConfig(builder, "copper", 3F, 3F, 3F, 3F, 3F, 6F, new GeneratableConfig(true, true, new Category[] { Category.NETHER, Category.THEEND }, true, new Biome[] {}, 9, IGeneratable.Type.COUNT_RANGE, new CountRangeConfig(20, 0, 0, 64), null), new GeneratableConfig(true, false, new Category[] { Category.NETHER }, true, new Biome[] {}, 9, IGeneratable.Type.COUNT_DEPTH_AVERAGE, null, new DepthAverageConfig(10, 32, 32)));
copper = createResourceConfig(builder, "copper", 3F, 3F, 3F, 3F, 3F, 6F, new GeneratableConfig(true, ListType.BLACKLIST, new Category[] { Category.NETHER, Category.THEEND }, ListType.BLACKLIST, new Biome[] {}, 9, IGeneratable.GenerationConfig.COUNT_RANGE, new CountRangeConfig(20, 0, 0, 64), null), new GeneratableConfig(true, ListType.WHITELIST, new Category[] { Category.NETHER }, ListType.BLACKLIST, new Biome[] {}, 9, IGeneratable.GenerationConfig.COUNT_DEPTH_AVERAGE, null, new DepthAverageConfig(10, 32, 32)));

builder.pop();
}
Expand Down
44 changes: 22 additions & 22 deletions src/main/java/info/u_team/useful_ores/config/GeneratableConfig.java
Expand Up @@ -18,25 +18,25 @@ public class GeneratableConfig implements IGeneratable {

private final boolean enabled;

private final boolean biomeCategoryBlackList;
private final ListType biomeCategoryListType;
private final List<Category> biomeCategories;
private final boolean biomeBlackList;
private final ListType biomeListType;
private final List<Biome> biomes;

private final int veinSize;
private final Type type;
private final GenerationConfig type;
private final CountRangeConfig countRangeConfig;
private final DepthAverageConfig depthAverageConfig;

public GeneratableConfig(boolean enabled, boolean biomeCategoryBlackList, Category[] biomeCategorys, boolean biomeBlackList, Biome[] biomes, int veinSize, Type type, CountRangeConfig countRangeConfig, DepthAverageConfig depthAverageConfig) {
this(enabled, biomeCategoryBlackList, Arrays.asList(biomeCategorys), biomeBlackList, Arrays.asList(biomes), veinSize, type, countRangeConfig, depthAverageConfig);
public GeneratableConfig(boolean enabled, ListType biomeCategoryListType, Category[] biomeCategorys, ListType biomeListType, Biome[] biomes, int veinSize, GenerationConfig type, CountRangeConfig countRangeConfig, DepthAverageConfig depthAverageConfig) {
this(enabled, biomeCategoryListType, Arrays.asList(biomeCategorys), biomeListType, Arrays.asList(biomes), veinSize, type, countRangeConfig, depthAverageConfig);
}

public GeneratableConfig(boolean enabled, boolean biomeCategoryBlackList, List<Category> biomeCategorys, boolean biomeBlackList, List<Biome> biomes, int veinSize, Type type, CountRangeConfig countRangeConfig, DepthAverageConfig depthAverageConfig) {
public GeneratableConfig(boolean enabled, ListType biomeCategoryListType, List<Category> biomeCategorys, ListType biomeListType, List<Biome> biomes, int veinSize, GenerationConfig type, CountRangeConfig countRangeConfig, DepthAverageConfig depthAverageConfig) {
this.enabled = enabled;
this.biomeCategoryBlackList = biomeCategoryBlackList;
this.biomeCategoryListType = biomeCategoryListType;
this.biomeCategories = biomeCategorys;
this.biomeBlackList = biomeBlackList;
this.biomeListType = biomeListType;
this.biomes = biomes;
this.veinSize = veinSize;
this.type = type;
Expand All @@ -50,8 +50,8 @@ public boolean isEnabled() {
}

@Override
public boolean isBiomeCategoryBlackList() {
return biomeCategoryBlackList;
public ListType getBiomeCategoryListType() {
return biomeCategoryListType;
}

@Override
Expand All @@ -60,8 +60,8 @@ public List<Category> getBiomeCategories() {
}

@Override
public boolean isBiomeBlackList() {
return biomeBlackList;
public ListType getBiomeListType() {
return biomeListType;
}

@Override
Expand All @@ -75,7 +75,7 @@ public int getVeinSize() {
}

@Override
public Type getType() {
public GenerationConfig getGenerationConfig() {
return type;
}

Expand All @@ -102,7 +102,7 @@ public JsonElement serialize(GeneratableConfig config, java.lang.reflect.Type ty

{
final JsonObject biomeCategoryObject = new JsonObject();
biomeCategoryObject.addProperty("black_list", config.isBiomeCategoryBlackList());
biomeCategoryObject.addProperty("list_type", config.getBiomeCategoryListType().getName());
final JsonArray biomeCategoryList = new JsonArray();
config.getBiomeCategories().stream().map(Biome.Category::getName).forEach(biomeCategoryList::add);
biomeCategoryObject.add("list", biomeCategoryList);
Expand All @@ -111,7 +111,7 @@ public JsonElement serialize(GeneratableConfig config, java.lang.reflect.Type ty

{
final JsonObject biomeObject = new JsonObject();
biomeObject.addProperty("black_list", config.isBiomeBlackList());
biomeObject.addProperty("list_type", config.getBiomeListType().getName());
final JsonArray biomeList = new JsonArray();
config.getBiomes().stream().map(Biome::getRegistryName).map(ResourceLocation::toString).forEach(biomeList::add);
biomeObject.add("list", biomeList);
Expand All @@ -122,8 +122,8 @@ public JsonElement serialize(GeneratableConfig config, java.lang.reflect.Type ty

{
final JsonObject placementObject = new JsonObject();
placementObject.addProperty("placement_type", config.getType().getName());
if (config.getType() == Type.COUNT_RANGE) {
placementObject.addProperty("placement_type", config.getGenerationConfig().getName());
if (config.getGenerationConfig() == GenerationConfig.COUNT_RANGE) {
placementObject.addProperty("count", config.getCountRangeConfig().count);
placementObject.addProperty("bottom_offset", config.getCountRangeConfig().bottomOffset);
placementObject.addProperty("top_offset", config.getCountRangeConfig().topOffset);
Expand All @@ -146,7 +146,7 @@ public GeneratableConfig deserialize(JsonElement json, java.lang.reflect.Type ty
final boolean enabled = object.get("enabled").getAsBoolean();

final JsonObject biomeCategoryObject = object.get("biome_category").getAsJsonObject();
final boolean biomeCategoryBlackList = biomeCategoryObject.get("black_list").getAsBoolean();
final ListType biomeCategoryListType = ListType.byName(biomeCategoryObject.get("list_type").getAsString());
final List<Biome.Category> biomeCategories = new ArrayList<>();
biomeCategoryObject.get("list").getAsJsonArray().forEach(element -> {
final Biome.Category category = NAMES_TO_CATEGORY.get(element.getAsString());
Expand All @@ -158,7 +158,7 @@ public GeneratableConfig deserialize(JsonElement json, java.lang.reflect.Type ty
});

final JsonObject biomeObject = object.get("biome").getAsJsonObject();
final boolean biomeBlackList = biomeObject.get("black_list").getAsBoolean();
final ListType biomeListType = ListType.byName(biomeObject.get("list_type").getAsString());
final List<Biome> biomes = new ArrayList<>();
biomeObject.get("list").getAsJsonArray().forEach(element -> {
final Biome biome = ForgeRegistries.BIOMES.getValue(new ResourceLocation(element.getAsString()));
Expand All @@ -172,22 +172,22 @@ public GeneratableConfig deserialize(JsonElement json, java.lang.reflect.Type ty
final int veinSize = object.get("vein_size").getAsInt();

final JsonObject placementObject = object.get("placement").getAsJsonObject();
Type type = Type.byName(placementObject.get("placement_type").getAsString());
GenerationConfig type = GenerationConfig.byName(placementObject.get("placement_type").getAsString());
if (type == null) {
throw new JsonParseException("Placement type can't be null. Undefined type for string " + placementObject.get("placement_type").getAsString());
}

final CountRangeConfig countRangeConfig;
final DepthAverageConfig depthAverageConfig;
if (type == Type.COUNT_RANGE) {
if (type == GenerationConfig.COUNT_RANGE) {
countRangeConfig = new CountRangeConfig(placementObject.get("count").getAsInt(), placementObject.get("bottom_offset").getAsInt(), placementObject.get("top_offset").getAsInt(), placementObject.get("maximum").getAsInt());
depthAverageConfig = null;
} else {
depthAverageConfig = new DepthAverageConfig(placementObject.get("count").getAsInt(), placementObject.get("baseline").getAsInt(), placementObject.get("spread").getAsInt());
countRangeConfig = null;
}

return new GeneratableConfig(enabled, biomeCategoryBlackList, biomeCategories, biomeBlackList, biomes, veinSize, type, countRangeConfig, depthAverageConfig);
return new GeneratableConfig(enabled, biomeCategoryListType, biomeCategories, biomeListType, biomes, veinSize, type, countRangeConfig, depthAverageConfig);
}

private static final Map<String, Biome.Category> NAMES_TO_CATEGORY = new HashMap<>();
Expand Down
Expand Up @@ -3,7 +3,7 @@
import java.util.List;

import info.u_team.useful_ores.api.*;
import info.u_team.useful_ores.api.IGeneratable.Type;
import info.u_team.useful_ores.api.IGeneratable.*;
import info.u_team.useful_ores.config.CommonConfig;
import net.minecraft.block.*;
import net.minecraft.world.biome.Biome;
Expand Down Expand Up @@ -35,23 +35,21 @@ private static void addGeneratable(Biome biome, BlockState state, FillerBlockTyp
if (!generatable.isEnabled()) {
return;
}
final boolean biomeCategoryBlacklist = generatable.isBiomeCategoryBlackList();
final ListType biomeCategoryListType = generatable.getBiomeCategoryListType();
final List<Category> biomeCategories = generatable.getBiomeCategories();
if (biomeCategoryBlacklist && biomeCategories.contains(biome.getCategory()) || !biomeCategoryBlacklist && !biomeCategories.contains(biome.getCategory())) {
if (biomeCategoryListType == ListType.BLACKLIST && biomeCategories.contains(biome.getCategory()) || biomeCategoryListType == ListType.WHITELIST && !biomeCategories.contains(biome.getCategory())) {
return;
}

final boolean biomeBlacklist = generatable.isBiomeBlackList();
final ListType biomeListType = generatable.getBiomeListType();
final List<Biome> biomes = generatable.getBiomes();
if (biomeBlacklist && biomes.contains(biome) || !biomeBlacklist && !biomes.contains(biome)) {
if (biomeListType == ListType.BLACKLIST && biomes.contains(biome) || biomeListType == ListType.WHITELIST && !biomes.contains(biome)) {
return;
}

System.out.println("ADD TO BIOMES" + biome);

if (generatable.getType() == Type.COUNT_RANGE) {
if (generatable.getGenerationConfig() == GenerationConfig.COUNT_RANGE) {
biome.addFeature(GenerationStage.Decoration.UNDERGROUND_ORES, Biome.createDecoratedFeature(Feature.ORE, new OreFeatureConfig(fillerType, state, generatable.getVeinSize()), Placement.COUNT_RANGE, generatable.getCountRangeConfig()));
} else if (generatable.getType() == Type.COUNT_DEPTH_AVERAGE) {
} else if (generatable.getGenerationConfig() == GenerationConfig.COUNT_DEPTH_AVERAGE) {
biome.addFeature(GenerationStage.Decoration.UNDERGROUND_ORES, Biome.createDecoratedFeature(Feature.ORE, new OreFeatureConfig(fillerType, state, generatable.getVeinSize()), Placement.COUNT_DEPTH_AVERAGE, generatable.getDepthAverageConfig()));
}
}
Expand Down

0 comments on commit d0aab14

Please sign in to comment.