Make generator configurable via ConfigHelper
This commit is contained in:
parent
d9cf50efa9
commit
e269c43e54
22 changed files with 352 additions and 717 deletions
|
@ -70,6 +70,16 @@ public class BOPBiome extends BiomeGenBase implements IExtendedBiome
|
|||
}
|
||||
}
|
||||
|
||||
// Allow generators to be configured
|
||||
WrappedJsonObject confGenerators = conf.getObject("generators");
|
||||
if (confGenerators != null)
|
||||
{
|
||||
for (String name : confGenerators.getKeys())
|
||||
{
|
||||
this.generationManager.configureWith(name, confGenerators.getObject(name));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -8,68 +8,124 @@
|
|||
|
||||
package biomesoplenty.api.biome.generation;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.google.common.collect.HashBasedTable;
|
||||
import biomesoplenty.common.util.config.ConfigHelper.WrappedJsonObject;
|
||||
import biomesoplenty.common.world.feature.*;
|
||||
import biomesoplenty.common.world.feature.tree.*;
|
||||
|
||||
import com.google.common.collect.ImmutableCollection;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Table;
|
||||
|
||||
public class GenerationManager
|
||||
{
|
||||
private Table<GeneratorStage, String, IGenerator> generatorTable = HashBasedTable.create();
|
||||
private Map<String, IGenerator> generators = new HashMap<String, IGenerator>();
|
||||
|
||||
public void addGenerator(String name, GeneratorStage stage, IGenerator generator)
|
||||
{
|
||||
if (!this.generatorTable.containsColumn(name))
|
||||
{
|
||||
generator.setName(name);
|
||||
generator.setStage(stage);
|
||||
|
||||
this.generatorTable.put(stage, name, generator);
|
||||
}
|
||||
else
|
||||
if (this.generators.containsKey(name))
|
||||
{
|
||||
throw new RuntimeException("A generator with name " + name + " already exists!");
|
||||
}
|
||||
generator.setName(name);
|
||||
generator.setStage(stage);
|
||||
this.generators.put(name, generator);
|
||||
}
|
||||
|
||||
public ImmutableCollection<IGenerator> getGeneratorsForStage(GeneratorStage stage)
|
||||
{
|
||||
Map<String, IGenerator> columnMap = this.generatorTable.rowMap().get(stage);
|
||||
Collection<IGenerator> result = columnMap == null ? null : columnMap.values();
|
||||
|
||||
return result == null ? ImmutableList.<IGenerator>of() : ImmutableList.<IGenerator>copyOf(result);
|
||||
}
|
||||
|
||||
public Map<String, IGenerator> createGeneratorMap()
|
||||
ArrayList<IGenerator> out = new ArrayList<IGenerator>();
|
||||
for (IGenerator generator : this.generators.values())
|
||||
{
|
||||
Map<String, IGenerator> result = new HashMap<String, IGenerator>();
|
||||
|
||||
for (IGenerator generator : this.generatorTable.values())
|
||||
if (generator.getStage() == stage)
|
||||
{
|
||||
result.put(generator.getName(), generator);
|
||||
out.add(generator);
|
||||
}
|
||||
}
|
||||
return ImmutableList.<IGenerator>copyOf(out);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void createGeneratorTable(Map<String, IGenerator> generators)
|
||||
public void removeGenerator(String name)
|
||||
{
|
||||
Table<GeneratorStage, String, IGenerator> result = HashBasedTable.create();
|
||||
this.generators.remove(name);
|
||||
}
|
||||
|
||||
for (Entry<String, IGenerator> entry : generators.entrySet())
|
||||
public IGenerator getGenerator(String name)
|
||||
{
|
||||
String name = entry.getKey();
|
||||
IGenerator generator = entry.getValue();
|
||||
|
||||
generator.setName(name);
|
||||
result.put(generator.getStage(), generator.getName(), generator);
|
||||
return this.generators.get(name);
|
||||
}
|
||||
|
||||
this.generatorTable = result;
|
||||
public void configureWith(String name, WrappedJsonObject conf)
|
||||
{
|
||||
if (this.generators.containsKey(name))
|
||||
{
|
||||
if (conf.getBool("enable", true))
|
||||
{
|
||||
// configure the existing generator
|
||||
this.generators.get(name).configure(conf);
|
||||
}
|
||||
else
|
||||
{
|
||||
// remove this generator
|
||||
this.generators.remove(name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// there was previously no generator of this name - attempt to add it
|
||||
IGenerator generator = GeneratorFactory.create(conf);
|
||||
if (generator != null)
|
||||
{
|
||||
this.generators.put(name, generator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: use GeneratorRegistry instead?
|
||||
public enum GeneratorFactory
|
||||
{
|
||||
FLORA, DOUBLE_FLORA, GRASS, ORE_CLUSTER, ORE_SINGLE, WATERSIDE, BASIC_TREE, BIG_TREE, BUSH;
|
||||
|
||||
public static IGenerator create(WrappedJsonObject conf)
|
||||
{
|
||||
GeneratorStage stage = conf.getEnum("stage", null, GeneratorStage.class);
|
||||
GeneratorFactory factory = conf.getEnum("type", null, GeneratorFactory.class);
|
||||
if (stage == null || factory == null) {return null;}
|
||||
IGenerator generator = factory.create();
|
||||
generator.setStage(stage);
|
||||
generator.configure(conf);
|
||||
return generator;
|
||||
}
|
||||
|
||||
public IGenerator create()
|
||||
{
|
||||
switch (this)
|
||||
{
|
||||
case FLORA:
|
||||
return new GeneratorFlora();
|
||||
case DOUBLE_FLORA:
|
||||
return new GeneratorDoubleFlora();
|
||||
case GRASS:
|
||||
return new GeneratorGrass();
|
||||
case ORE_CLUSTER:
|
||||
return new GeneratorOreCluster();
|
||||
case ORE_SINGLE:
|
||||
return new GeneratorOreSingle();
|
||||
case WATERSIDE:
|
||||
return new GeneratorWaterside();
|
||||
case BASIC_TREE:
|
||||
return new GeneratorBasicTree();
|
||||
case BIG_TREE:
|
||||
return new GeneratorBigTree();
|
||||
case BUSH:
|
||||
return new GeneratorBush();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -8,6 +8,8 @@
|
|||
|
||||
package biomesoplenty.api.biome.generation;
|
||||
|
||||
import biomesoplenty.common.util.config.ConfigHelper.WrappedJsonObject;
|
||||
|
||||
public abstract class GeneratorCustomizable implements IGenerator
|
||||
{
|
||||
private final String identifier;
|
||||
|
@ -53,4 +55,10 @@ public abstract class GeneratorCustomizable implements IGenerator
|
|||
{
|
||||
return this.identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(WrappedJsonObject conf)
|
||||
{
|
||||
;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,12 +15,9 @@ import java.util.Random;
|
|||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.WeightedRandom;
|
||||
import net.minecraft.world.World;
|
||||
import biomesoplenty.common.util.config.ConfigHelper.WrappedJsonObject;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
// TODO implement so that we don't rely on minecraft WeightedRandom class and GeneratorWeightedEntry class - can be much simpler
|
||||
public class GeneratorWeighted extends GeneratorCustomizable
|
||||
{
|
||||
private int amountPerChunk;
|
||||
|
@ -59,16 +56,26 @@ public class GeneratorWeighted extends GeneratorCustomizable
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeToJson(JsonObject json, JsonSerializationContext context)
|
||||
public void configure(WrappedJsonObject conf)
|
||||
{
|
||||
json.addProperty("amount_per_chunk", this.amountPerChunk);
|
||||
json.add("entries", context.serialize(this.weightedEntries));
|
||||
this.amountPerChunk = conf.getInt("amountPerChunk", this.amountPerChunk);
|
||||
ArrayList<WrappedJsonObject> weightedEntriesConf = conf.getObjectArray("weightedEntries");
|
||||
if (!weightedEntriesConf.isEmpty())
|
||||
{
|
||||
this.weightedEntries.clear();
|
||||
for (WrappedJsonObject weightedEntryConf : weightedEntriesConf)
|
||||
{
|
||||
Integer weight = weightedEntryConf.getInt("weight", null);
|
||||
if (weight == null || weight.intValue() < 1) {continue;}
|
||||
WrappedJsonObject generatorConf = weightedEntryConf.getObject("generator");
|
||||
if (generatorConf == null) {continue;}
|
||||
IGenerator generator = GenerationManager.GeneratorFactory.create(generatorConf);
|
||||
if (generator == null) {continue;}
|
||||
this.add(weight, generator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromJson(JsonObject json, JsonDeserializationContext context)
|
||||
{
|
||||
this.amountPerChunk = json.get("amount_per_chunk").getAsInt();
|
||||
this.weightedEntries = context.deserialize(json.get("entries"), new TypeToken<List<GeneratorWeightedEntry>>() {}.getType());
|
||||
}
|
||||
// TODO: at the moment, because the weighted entries aren't named, there's no way to just adjust one part of one of them
|
||||
// The only thing you can do is replace the whole array. Perhaps should use named entries in a Map<String,Generator> kind of arrangement
|
||||
// Then they could be individually altered
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,10 +13,7 @@ import java.util.Random;
|
|||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.WeightedRandom;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import biomesoplenty.common.util.config.ConfigHelper.WrappedJsonObject;
|
||||
|
||||
public final class GeneratorWeightedEntry extends WeightedRandom.Item implements IGenerator
|
||||
{
|
||||
|
@ -56,18 +53,12 @@ public final class GeneratorWeightedEntry extends WeightedRandom.Item implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeToJson(JsonObject json, JsonSerializationContext context)
|
||||
public void configure(WrappedJsonObject conf)
|
||||
{
|
||||
json.addProperty("weight", this.itemWeight);
|
||||
json.add("wrapped_generator", context.serialize(this.wrappedGenerator));
|
||||
// this should never be used directly
|
||||
;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromJson(JsonObject json, JsonDeserializationContext context)
|
||||
{
|
||||
this.itemWeight = json.get("weight").getAsInt();
|
||||
this.wrappedGenerator = context.deserialize(json.get("wrapped_generator"), IGenerator.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStage(GeneratorStage stage)
|
||||
|
@ -96,4 +87,5 @@ public final class GeneratorWeightedEntry extends WeightedRandom.Item implements
|
|||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,10 +12,7 @@ import java.util.Random;
|
|||
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import biomesoplenty.common.util.config.ConfigHelper.WrappedJsonObject;
|
||||
|
||||
public interface IGenerator
|
||||
{
|
||||
|
@ -33,6 +30,5 @@ public interface IGenerator
|
|||
public String getIdentifier();
|
||||
public GeneratorStage getStage();
|
||||
|
||||
public void writeToJson(JsonObject json, JsonSerializationContext context);
|
||||
public void readFromJson(JsonObject json, JsonDeserializationContext context);
|
||||
public void configure(WrappedJsonObject conf);
|
||||
}
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
|
||||
package biomesoplenty.common.biome.overworld;
|
||||
|
||||
import static biomesoplenty.common.block.BlockBOPDoublePlant.VARIANT;
|
||||
import static biomesoplenty.common.block.BlockDoubleDecoration.HALF;
|
||||
import net.minecraft.block.BlockFlower.EnumFlowerType;
|
||||
import net.minecraft.block.BlockTallGrass;
|
||||
import net.minecraft.entity.passive.EntityHorse;
|
||||
|
@ -21,7 +19,6 @@ import biomesoplenty.api.biome.generation.GeneratorWeighted;
|
|||
import biomesoplenty.api.block.BOPBlocks;
|
||||
import biomesoplenty.common.block.BlockBOPDoublePlant;
|
||||
import biomesoplenty.common.block.BlockBOPPlant;
|
||||
import biomesoplenty.common.block.BlockDoubleDecoration.Half;
|
||||
import biomesoplenty.common.block.BlockGem;
|
||||
import biomesoplenty.common.enums.BOPGems;
|
||||
import biomesoplenty.common.enums.BOPPlants;
|
||||
|
@ -49,7 +46,7 @@ public class BiomeGenShrubland extends BOPBiome
|
|||
this.addGenerator("gravel", GeneratorStage.SAND_PASS2, new GeneratorWaterside(4, 7, Blocks.gravel.getDefaultState()));
|
||||
this.addGenerator("bushes", GeneratorStage.FLOWERS, new GeneratorFlora(7, BlockBOPPlant.paging.getVariantState(BOPPlants.BUSH)));
|
||||
this.addGenerator("shrubs", GeneratorStage.FLOWERS, new GeneratorFlora(5, BlockBOPPlant.paging.getVariantState(BOPPlants.SHRUB)));
|
||||
this.addGenerator("flax", GeneratorStage.FLOWERS, new GeneratorDoubleFlora(1, BOPBlocks.double_plant.getDefaultState().withProperty(VARIANT, BlockBOPDoublePlant.DoublePlantType.FLAX).withProperty(HALF, Half.LOWER), BOPBlocks.double_plant.getDefaultState().withProperty(VARIANT, BlockBOPDoublePlant.DoublePlantType.FLAX).withProperty(HALF, Half.UPPER), 24));
|
||||
this.addGenerator("flax", GeneratorStage.FLOWERS, new GeneratorDoubleFlora(1, BlockBOPDoublePlant.DoublePlantType.FLAX, 24));
|
||||
this.addGenerator("water_reeds", GeneratorStage.LILYPAD, new GeneratorFlora(3, BlockBOPPlant.paging.getVariantState(BOPPlants.REED), 128));
|
||||
|
||||
this.addGenerator("trees", GeneratorStage.TREE, new GeneratorBush(1, Blocks.log.getDefaultState(), Blocks.leaves.getDefaultState()));
|
||||
|
|
|
@ -27,7 +27,6 @@ import com.google.gson.JsonObject;
|
|||
import com.google.gson.JsonParser;
|
||||
|
||||
import biomesoplenty.common.util.block.BlockStateUtils;
|
||||
import biomesoplenty.common.util.config.JsonBlockState;
|
||||
import biomesoplenty.core.BiomesOPlenty;
|
||||
|
||||
public class ConfigHelper
|
||||
|
@ -35,7 +34,6 @@ public class ConfigHelper
|
|||
|
||||
public static Gson serializer = new GsonBuilder().setPrettyPrinting().create();
|
||||
public static JsonParser parser = new JsonParser();
|
||||
public JsonBlockState blockStateParser = new JsonBlockState();
|
||||
public WrappedJsonObject root = null;
|
||||
public ArrayList<String> messages = new ArrayList<String>();
|
||||
|
||||
|
@ -115,41 +113,41 @@ public class ConfigHelper
|
|||
{
|
||||
return this.root == null ? new ArrayList<WrappedJsonObject>() : this.root.getObjectArray(name);
|
||||
}
|
||||
public ArrayList<Boolean> getBoolArray(String name)
|
||||
public ArrayList<Boolean> getBoolArray(String name, ArrayList<Boolean> defaultVal)
|
||||
{
|
||||
return this.root == null ? new ArrayList<Boolean>() : this.root.getBoolArray(name);
|
||||
return this.root == null ? new ArrayList<Boolean>() : this.root.getBoolArray(name, defaultVal);
|
||||
}
|
||||
public Boolean getBool(String name, Boolean defaultVal)
|
||||
{
|
||||
return this.root == null ? defaultVal : this.root.getBool(name, defaultVal);
|
||||
}
|
||||
public ArrayList<String> getStringArray(String name)
|
||||
public ArrayList<String> getStringArray(String name, ArrayList<String> defaultVal)
|
||||
{
|
||||
return this.root == null ? new ArrayList<String>() : this.root.getStringArray(name);
|
||||
return this.root == null ? new ArrayList<String>() : this.root.getStringArray(name, defaultVal);
|
||||
}
|
||||
public String getString(String name, String defaultVal)
|
||||
{
|
||||
return this.root == null ? defaultVal : this.root.getString(name, defaultVal);
|
||||
}
|
||||
public ArrayList<Integer> getIntArray(String name)
|
||||
public ArrayList<Integer> getIntArray(String name, ArrayList<Integer> defaultVal)
|
||||
{
|
||||
return this.root == null ? new ArrayList<Integer>() : this.root.getIntArray(name);
|
||||
return this.root == null ? new ArrayList<Integer>() : this.root.getIntArray(name, defaultVal);
|
||||
}
|
||||
public Integer getInt(String name, Integer defaultVal)
|
||||
{
|
||||
return this.root == null ? defaultVal : this.root.getInt(name, defaultVal);
|
||||
}
|
||||
public ArrayList<Float> getFloatArray(String name)
|
||||
public ArrayList<Float> getFloatArray(String name, ArrayList<Float> defaultVal)
|
||||
{
|
||||
return this.root == null ? new ArrayList<Float>() : this.root.getFloatArray(name);
|
||||
return this.root == null ? new ArrayList<Float>() : this.root.getFloatArray(name, defaultVal);
|
||||
}
|
||||
public Float getFloat(String name, Float defaultVal)
|
||||
{
|
||||
return this.root == null ? defaultVal : this.root.getFloat(name, defaultVal);
|
||||
}
|
||||
public ArrayList<IBlockState> getBlockStateArray(String name)
|
||||
public ArrayList<IBlockState> getBlockStateArray(String name, ArrayList<IBlockState> defaultVal)
|
||||
{
|
||||
return this.root == null ? new ArrayList<IBlockState>() : this.root.getBlockStateArray(name);
|
||||
return this.root == null ? new ArrayList<IBlockState>() : this.root.getBlockStateArray(name, defaultVal);
|
||||
}
|
||||
public IBlockState getBlockState(String name, IBlockState defaultVal)
|
||||
{
|
||||
|
@ -174,6 +172,16 @@ public class ConfigHelper
|
|||
this.conf = conf;
|
||||
}
|
||||
|
||||
public ArrayList<String> getKeys()
|
||||
{
|
||||
ArrayList<String> out = new ArrayList<String>();
|
||||
for (Entry<String, JsonElement> entry : this.obj.entrySet())
|
||||
{
|
||||
out.add(entry.getKey());
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
public WrappedJsonObject getObject(String name)
|
||||
{
|
||||
if (this.obj == null || !this.obj.has(name)) {return null;}
|
||||
|
@ -214,19 +222,40 @@ public class ConfigHelper
|
|||
return list;
|
||||
}
|
||||
|
||||
public ArrayList<Boolean> getBoolArray(String name) {return this.<Boolean>getArray(name, Types.BOOLEAN);}
|
||||
public ArrayList<Boolean> getBoolArray(String name, ArrayList<Boolean> defaultVal) {return this.<Boolean>getArray(name, defaultVal, Types.BOOLEAN);}
|
||||
public Boolean getBool(String name, Boolean defaultVal) {return this.<Boolean>get(name, defaultVal, Types.BOOLEAN);}
|
||||
public ArrayList<String> getStringArray(String name) {return this.<String>getArray(name, Types.STRING);}
|
||||
public ArrayList<String> getStringArray(String name, ArrayList<String> defaultVal) {return this.<String>getArray(name, defaultVal, Types.STRING);}
|
||||
public String getString(String name, String defaultVal) {return this.<String>get(name, defaultVal, Types.STRING);}
|
||||
public ArrayList<Integer> getIntArray(String name) {return this.<Integer>getArray(name, Types.INTEGER);}
|
||||
public ArrayList<Integer> getIntArray(String name, ArrayList<Integer> defaultVal) {return this.<Integer>getArray(name, defaultVal, Types.INTEGER);}
|
||||
public Integer getInt(String name, Integer defaultVal) {return this.<Integer>get(name, defaultVal, Types.INTEGER);}
|
||||
public ArrayList<Float> getFloatArray(String name) {return this.<Float>getArray(name, Types.FLOAT);}
|
||||
public ArrayList<Float> getFloatArray(String name, ArrayList<Float> defaultVal) {return this.<Float>getArray(name, defaultVal, Types.FLOAT);}
|
||||
public Float getFloat(String name, Float defaultVal) {return this.<Float>get(name, defaultVal, Types.FLOAT);}
|
||||
public ArrayList<IBlockState> getBlockStateArray(String name) {return this.<IBlockState>getArray(name, Types.BLOCKSTATE);}
|
||||
public ArrayList<IBlockState> getBlockStateArray(String name, ArrayList<IBlockState> defaultVal) {return this.<IBlockState>getArray(name, defaultVal, Types.BLOCKSTATE);}
|
||||
public IBlockState getBlockState(String name, IBlockState defaultVal) {return this.<IBlockState>get(name, defaultVal, Types.BLOCKSTATE);}
|
||||
|
||||
|
||||
|
||||
public <E extends Enum> ArrayList<E> getEnumArray(String name, ArrayList<E> defaultVal, Class<E> clazz)
|
||||
{
|
||||
if (this.obj == null || !this.obj.has(name)) {return defaultVal;}
|
||||
ArrayList<E> list = new ArrayList<E>();
|
||||
try
|
||||
{
|
||||
JsonArray arr = this.obj.getAsJsonArray(name);
|
||||
for (int i = 0; i < arr.size(); i++)
|
||||
{
|
||||
E ele = this.<E>asEnum(arr.get(i), clazz);
|
||||
if (ele != null) {list.add(ele);}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
this.conf.addMessage("Error fetching " + clazz.getName() + " array: " + e.getMessage());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
public <E extends Enum> E getEnum(String name, E defaultVal, Class<E> clazz)
|
||||
{
|
||||
if (this.obj == null || !this.obj.has(name)) {return defaultVal;}
|
||||
E out = this.<E>asEnum(this.obj.get(name), clazz);
|
||||
return out == null ? defaultVal : out;
|
||||
}
|
||||
|
||||
private <T> T get(String name, T defaultVal, Types type)
|
||||
{
|
||||
|
@ -235,10 +264,10 @@ public class ConfigHelper
|
|||
return out == null ? defaultVal : out;
|
||||
}
|
||||
|
||||
private <T> ArrayList<T> getArray(String name, Types type)
|
||||
private <T> ArrayList<T> getArray(String name, ArrayList<T> defaultVal, Types type)
|
||||
{
|
||||
if (this.obj == null || !this.obj.has(name)) {return defaultVal;}
|
||||
ArrayList<T> list = new ArrayList<T>();
|
||||
if (this.obj != null && this.obj.has(name)) {
|
||||
try
|
||||
{
|
||||
JsonArray arr = this.obj.getAsJsonArray(name);
|
||||
|
@ -250,7 +279,6 @@ public class ConfigHelper
|
|||
} catch (Exception e) {
|
||||
this.conf.addMessage("Error fetching " + type.toString().toLowerCase() + " array: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
@ -272,6 +300,32 @@ public class ConfigHelper
|
|||
}
|
||||
}
|
||||
|
||||
public <E extends Enum> E asEnum(JsonElement ele, Class<E>clazz)
|
||||
{
|
||||
try
|
||||
{
|
||||
String val = ele.getAsString();
|
||||
E[] enums = clazz.getEnumConstants();
|
||||
if (enums == null)
|
||||
{
|
||||
this.conf.addMessage("Class " + clazz.getName() + " contains no enum constants");
|
||||
return null;
|
||||
}
|
||||
for (E enumVal : enums)
|
||||
{
|
||||
if (enumVal.name().equalsIgnoreCase(val))
|
||||
{
|
||||
return enumVal;
|
||||
}
|
||||
}
|
||||
this.conf.addMessage("Value " + val + " does not exist in enum " + clazz);
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
this.conf.addMessage("Error fetching string: " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean asBool(JsonElement ele)
|
||||
{
|
||||
try
|
||||
|
|
|
@ -1,95 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 2014-2015, the Biomes O' Plenty Team
|
||||
*
|
||||
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
|
||||
*
|
||||
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
|
||||
******************************************************************************/
|
||||
|
||||
package biomesoplenty.common.util.config;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import biomesoplenty.api.biome.generation.GeneratorRegistry;
|
||||
import biomesoplenty.api.biome.generation.GeneratorStage;
|
||||
import biomesoplenty.api.biome.generation.IGenerator;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
|
||||
public class GeneratorTypeAdaptor implements JsonSerializer<IGenerator>, JsonDeserializer<IGenerator>
|
||||
{
|
||||
@Override
|
||||
public JsonElement serialize(IGenerator src, Type typeOfSrc, JsonSerializationContext context)
|
||||
{
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
src.writeToJson(jsonObject, context);
|
||||
|
||||
jsonObject.addProperty("generator", src.getIdentifier());
|
||||
jsonObject.add("stage", context.serialize(src.getStage()));
|
||||
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGenerator deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
JsonObject jsonObject = json.getAsJsonObject();
|
||||
|
||||
if (jsonObject.has("generator"))
|
||||
{
|
||||
String generatorIdentifier = jsonObject.get("generator").getAsString();
|
||||
Class<? extends IGenerator> generatorClass = GeneratorRegistry.getGeneratorClass(generatorIdentifier);
|
||||
|
||||
if (generatorClass == null)
|
||||
{
|
||||
throw new JsonSyntaxException("Generator " + generatorIdentifier + " doesn't exist");
|
||||
}
|
||||
else
|
||||
{
|
||||
IGenerator generator;
|
||||
try
|
||||
{
|
||||
generator = (IGenerator)generatorClass.newInstance();
|
||||
|
||||
Type generatorStageType = new TypeToken<GeneratorStage>() {}.getType();
|
||||
GeneratorStage generatorStage = (GeneratorStage)context.deserialize(jsonObject.get("stage"), generatorStageType);
|
||||
String generatorStageName = jsonObject.get("stage") != null ? jsonObject.get("stage").getAsString() : null;
|
||||
|
||||
if (generatorStage == null)
|
||||
{
|
||||
throw new JsonSyntaxException("Generator stage " + generatorStageName + " is invalid");
|
||||
}
|
||||
else
|
||||
{
|
||||
generator.setStage((GeneratorStage)context.deserialize(jsonObject.get("stage"), generatorStageType));
|
||||
generator.readFromJson(jsonObject, context);
|
||||
|
||||
return generator;
|
||||
}
|
||||
}
|
||||
catch (InstantiationException e)
|
||||
{
|
||||
throw new RuntimeException("Generators must have a no-args constructor", e);
|
||||
}
|
||||
catch (IllegalAccessException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new JsonSyntaxException("Entry missing generator property");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,158 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 2014, the Biomes O' Plenty Team
|
||||
*
|
||||
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
|
||||
*
|
||||
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
|
||||
******************************************************************************/
|
||||
|
||||
package biomesoplenty.common.util.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraftforge.common.BiomeManager.BiomeEntry;
|
||||
import net.minecraftforge.common.BiomeManager.BiomeType;
|
||||
import biomesoplenty.api.biome.BiomeOwner;
|
||||
import biomesoplenty.api.biome.IExtendedBiome;
|
||||
import biomesoplenty.api.biome.generation.GenerationManager;
|
||||
import biomesoplenty.api.biome.generation.IGenerator;
|
||||
import biomesoplenty.common.biome.BOPBiomeManager;
|
||||
import biomesoplenty.common.biome.ExtendedBiomeRegistry;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.gson.FieldNamingPolicy;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
public class JsonBiome
|
||||
{
|
||||
public static final Gson serializer = new GsonBuilder().setPrettyPrinting().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).registerTypeHierarchyAdapter(IBlockState.class, new JsonBlockState()).registerTypeHierarchyAdapter(IGenerator.class, new GeneratorTypeAdaptor()).create();
|
||||
|
||||
public String biomeName;
|
||||
public int biomeId;
|
||||
public Map<BiomeType, Integer> weights;
|
||||
public IBlockState topBlock;
|
||||
public IBlockState fillerBlock;
|
||||
public float rootHeight;
|
||||
public float rootVariation;
|
||||
public float temperature;
|
||||
public float rainfall;
|
||||
public int color;
|
||||
public int waterColorMultiplier;
|
||||
public ArrayList<JsonEntitySpawn> entities;
|
||||
public Map<String, IGenerator> decoration;
|
||||
|
||||
public static JsonBiome createFromBiomeGenBase(BiomeGenBase baseBiome)
|
||||
{
|
||||
JsonBiome biome = new JsonBiome();
|
||||
|
||||
biome.biomeId = baseBiome.biomeID;
|
||||
biome.biomeName = baseBiome.biomeName;
|
||||
biome.topBlock = baseBiome.topBlock;
|
||||
biome.fillerBlock = baseBiome.fillerBlock;
|
||||
biome.rootHeight = baseBiome.minHeight;
|
||||
biome.rootVariation = baseBiome.maxHeight;
|
||||
biome.temperature = baseBiome.temperature;
|
||||
biome.rainfall = baseBiome.rainfall;
|
||||
biome.color = baseBiome.color;
|
||||
biome.waterColorMultiplier = baseBiome.waterColorMultiplier;
|
||||
biome.entities = JsonEntitySpawn.getBiomeEntitySpawns(baseBiome);
|
||||
|
||||
IExtendedBiome extendedBiome = ExtendedBiomeRegistry.getExtension(baseBiome);
|
||||
|
||||
if (extendedBiome != null)
|
||||
{
|
||||
GenerationManager generationManager = extendedBiome.getGenerationManager();
|
||||
|
||||
biome.weights = extendedBiome.getWeightMap();
|
||||
biome.decoration = generationManager.createGeneratorMap();
|
||||
|
||||
if (extendedBiome.getBiomeOwner() == BiomeOwner.BIOMESOPLENTY)
|
||||
{
|
||||
//Add the biome to the array if it is ours because the registration in configureBiomeWithJson is
|
||||
//not called on the first run
|
||||
BiomeGenBase.getBiomeGenArray()[baseBiome.biomeID] = baseBiome;
|
||||
}
|
||||
|
||||
//TODO: Add a system for making Vanilla biome weights configurable. This won't necessarily be in this class, however it's worth noting.
|
||||
for (Entry<BiomeType, Integer> entry : extendedBiome.getWeightMap().entrySet())
|
||||
{
|
||||
if (entry != null)
|
||||
{
|
||||
BiomeType biomeType = entry.getKey();
|
||||
int weight = entry.getValue();
|
||||
|
||||
BOPBiomeManager.addBiome(biomeType, new BiomeEntry(baseBiome, weight));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return biome;
|
||||
}
|
||||
|
||||
public static Optional<BiomeGenBase> configureBiomeWithJson(BiomeGenBase biome, JsonBiome jsonBiome)
|
||||
{
|
||||
IExtendedBiome extendedBiome = ExtendedBiomeRegistry.getExtension(biome);
|
||||
|
||||
if (extendedBiome != null)
|
||||
{
|
||||
if (extendedBiome.getBiomeOwner() == BiomeOwner.BIOMESOPLENTY)
|
||||
{
|
||||
if (jsonBiome.biomeId != -1)
|
||||
{
|
||||
biome.biomeID = jsonBiome.biomeId;
|
||||
BiomeGenBase.getBiomeGenArray()[jsonBiome.biomeId] = biome;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Optional.absent();
|
||||
}
|
||||
}
|
||||
|
||||
Map<BiomeType, Integer> weightMap = jsonBiome.weights;
|
||||
|
||||
//Removes the default weights set by us as they are about to be set from the config file
|
||||
extendedBiome.clearWeights();
|
||||
|
||||
//TODO: Add a system for making Vanilla biome weights configurable. This won't necessarily be in this class, however it's worth noting.
|
||||
if (biome.biomeID != -1)
|
||||
{
|
||||
for (Entry<BiomeType, Integer> entry : weightMap.entrySet())
|
||||
{
|
||||
if (entry != null)
|
||||
{
|
||||
BiomeType biomeType = entry.getKey();
|
||||
int weight = entry.getValue();
|
||||
|
||||
//Updates the biome's weights to be in line with the config file
|
||||
extendedBiome.addWeight(biomeType, weight);
|
||||
BOPBiomeManager.addBiome(biomeType, new BiomeEntry(biome, weight));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
biome.biomeName = jsonBiome.biomeName;
|
||||
biome.topBlock = jsonBiome.topBlock;
|
||||
biome.fillerBlock = jsonBiome.fillerBlock;
|
||||
biome.setHeight(new BiomeGenBase.Height(jsonBiome.rootHeight, jsonBiome.rootVariation));
|
||||
biome.temperature = jsonBiome.temperature;
|
||||
biome.rainfall = jsonBiome.rainfall;
|
||||
// TODO: Reflect and modify enableRain and enableSnow
|
||||
biome.color = jsonBiome.color;
|
||||
biome.waterColorMultiplier = jsonBiome.waterColorMultiplier;
|
||||
JsonEntitySpawn.addBiomeEntitySpawns(biome, jsonBiome);
|
||||
|
||||
GenerationManager generationManager = extendedBiome.getGenerationManager();
|
||||
|
||||
generationManager.createGeneratorTable(jsonBiome.decoration);
|
||||
|
||||
return Optional.of(biome);
|
||||
}
|
||||
|
||||
return Optional.absent();
|
||||
}
|
||||
}
|
|
@ -1,99 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 2014, the Biomes O' Plenty Team
|
||||
*
|
||||
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
|
||||
*
|
||||
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
|
||||
******************************************************************************/
|
||||
|
||||
package biomesoplenty.common.util.config;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import biomesoplenty.common.util.block.BlockStateUtils;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
|
||||
public class JsonBlockState implements JsonDeserializer<IBlockState>, JsonSerializer<IBlockState>
|
||||
{
|
||||
@Override
|
||||
public JsonElement serialize(IBlockState blockState, Type typeOfSrc, JsonSerializationContext context)
|
||||
{
|
||||
JsonObject jsonBlockState = new JsonObject();
|
||||
JsonObject jsonStateProperties = new JsonObject();
|
||||
|
||||
jsonBlockState.addProperty("block", GameRegistry.findUniqueIdentifierFor(blockState.getBlock()).toString());
|
||||
|
||||
for (Entry<IProperty, Comparable> entry : (ImmutableSet<Entry<IProperty, Comparable>>) blockState.getProperties().entrySet())
|
||||
{
|
||||
IProperty property = entry.getKey();
|
||||
Comparable value = entry.getValue();
|
||||
|
||||
jsonStateProperties.addProperty(property.getName(), value.toString());
|
||||
}
|
||||
|
||||
jsonBlockState.add("properties", jsonStateProperties);
|
||||
|
||||
return jsonBlockState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
JsonObject jsonBlockState = json.getAsJsonObject();
|
||||
|
||||
if (jsonBlockState.has("block"))
|
||||
{
|
||||
Block block = Block.getBlockFromName(jsonBlockState.get("block").getAsString());
|
||||
|
||||
if (block != null)
|
||||
{
|
||||
IBlockState blockState = block.getDefaultState();
|
||||
|
||||
if (jsonBlockState.has("properties"))
|
||||
{
|
||||
JsonObject jsonProperties = jsonBlockState.getAsJsonObject("properties");
|
||||
|
||||
for (Entry<String, JsonElement> entry : jsonProperties.entrySet())
|
||||
{
|
||||
IProperty property = BlockStateUtils.getPropertyByName(blockState, entry.getKey());
|
||||
|
||||
if (property != null)
|
||||
{
|
||||
Comparable propertyValue = BlockStateUtils.getPropertyValueByName(blockState, property, entry.getValue().getAsString());
|
||||
|
||||
if (propertyValue != null)
|
||||
{
|
||||
blockState = blockState.withProperty(property, propertyValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new JsonParseException("Invalid value " + entry.getValue().getAsString() + " for property " + entry.getKey());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new JsonParseException("Invalid property name: " + entry.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return blockState;
|
||||
}
|
||||
}
|
||||
|
||||
throw new JsonParseException("Invalid block state: " + json.toString());
|
||||
}
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 2014, the Biomes O' Plenty Team
|
||||
*
|
||||
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
|
||||
*
|
||||
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
|
||||
******************************************************************************/
|
||||
|
||||
package biomesoplenty.common.util.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.EnumCreatureType;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraft.world.biome.BiomeGenBase.SpawnListEntry;
|
||||
|
||||
public class JsonEntitySpawn
|
||||
{
|
||||
public String entityType;
|
||||
public String entityClass;
|
||||
public int weight;
|
||||
public int minGroupCount;
|
||||
public int maxGroupCount;
|
||||
|
||||
public static ArrayList<JsonEntitySpawn> getBiomeEntitySpawns(BiomeGenBase biome)
|
||||
{
|
||||
ArrayList<JsonEntitySpawn> entitySpawns = new ArrayList();
|
||||
|
||||
for (EnumCreatureType creatureType : EnumCreatureType.values())
|
||||
{
|
||||
List<SpawnListEntry> spawnableList = biome.getSpawnableList(creatureType);
|
||||
|
||||
for (SpawnListEntry spawnListEntry : spawnableList)
|
||||
{
|
||||
JsonEntitySpawn entitySpawn = new JsonEntitySpawn();
|
||||
|
||||
entitySpawn.entityType = creatureType.toString().toLowerCase();
|
||||
entitySpawn.entityClass = spawnListEntry.entityClass.getCanonicalName();
|
||||
entitySpawn.weight = spawnListEntry.itemWeight;
|
||||
entitySpawn.minGroupCount = spawnListEntry.minGroupCount;
|
||||
entitySpawn.maxGroupCount = spawnListEntry.maxGroupCount;
|
||||
|
||||
entitySpawns.add(entitySpawn);
|
||||
}
|
||||
}
|
||||
|
||||
return entitySpawns;
|
||||
}
|
||||
|
||||
public static void addBiomeEntitySpawns(BiomeGenBase biome, JsonBiome jsonBiome)
|
||||
{
|
||||
for (EnumCreatureType creatureType : EnumCreatureType.values())
|
||||
{
|
||||
biome.getSpawnableList(creatureType).clear();
|
||||
}
|
||||
|
||||
for (JsonEntitySpawn entitySpawn : jsonBiome.entities)
|
||||
{
|
||||
if (entitySpawn != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnumCreatureType creatureType = EnumCreatureType.valueOf(entitySpawn.entityType.toUpperCase());
|
||||
Class entityClass = Class.forName(entitySpawn.entityClass);
|
||||
|
||||
biome.getSpawnableList(creatureType).add(new BiomeGenBase.SpawnListEntry(entityClass, entitySpawn.weight, entitySpawn.minGroupCount, entitySpawn.maxGroupCount));
|
||||
}
|
||||
catch (ClassNotFoundException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,13 +10,13 @@ package biomesoplenty.common.world.feature;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
|
||||
import biomesoplenty.api.biome.generation.GeneratorCustomizable;
|
||||
import biomesoplenty.api.block.BOPBlocks;
|
||||
import biomesoplenty.common.block.BlockBOPDoublePlant;
|
||||
import biomesoplenty.common.block.BlockDecoration;
|
||||
import biomesoplenty.common.block.BlockDoubleDecoration;
|
||||
import biomesoplenty.common.util.biome.GeneratorUtils;
|
||||
import biomesoplenty.common.util.config.ConfigHelper.WrappedJsonObject;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.BlockPos;
|
||||
|
@ -29,7 +29,17 @@ public class GeneratorDoubleFlora extends GeneratorCustomizable
|
|||
private IBlockState topState;
|
||||
private int generationAttempts;
|
||||
|
||||
public GeneratorDoubleFlora() {}
|
||||
public GeneratorDoubleFlora()
|
||||
{
|
||||
// default
|
||||
this(1, BlockBOPDoublePlant.DoublePlantType.FLAX, 64);
|
||||
}
|
||||
|
||||
// convenient shortcut constructor for use with a BlockBOPDoublePlant variant
|
||||
public GeneratorDoubleFlora(int amountPerChunk, BlockBOPDoublePlant.DoublePlantType type, int generationAttempts)
|
||||
{
|
||||
this(amountPerChunk, BOPBlocks.double_plant.getDefaultState().withProperty(BlockBOPDoublePlant.VARIANT, type).withProperty(BlockBOPDoublePlant.HALF, BlockDoubleDecoration.Half.LOWER), BOPBlocks.double_plant.getDefaultState().withProperty(BlockBOPDoublePlant.VARIANT, type).withProperty(BlockBOPDoublePlant.HALF, BlockDoubleDecoration.Half.UPPER), generationAttempts);
|
||||
}
|
||||
|
||||
public GeneratorDoubleFlora(int amountPerChunk, IBlockState bottomState, IBlockState topState, int generationAttempts)
|
||||
{
|
||||
|
@ -81,20 +91,11 @@ public class GeneratorDoubleFlora extends GeneratorCustomizable
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeToJson(JsonObject json, JsonSerializationContext context)
|
||||
public void configure(WrappedJsonObject conf)
|
||||
{
|
||||
json.addProperty("amount_per_chunk", this.amountPerChunk);
|
||||
json.add("bottom_state", context.serialize(this.bottomState));
|
||||
json.add("top_state", context.serialize(this.topState));
|
||||
json.addProperty("generation_attempts", this.generationAttempts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromJson(JsonObject json, JsonDeserializationContext context)
|
||||
{
|
||||
this.amountPerChunk = json.get("amount_per_chunk").getAsInt();
|
||||
this.bottomState = GeneratorUtils.deserializeStateNonNull(json, "bottom_state", context);
|
||||
this.topState = GeneratorUtils.deserializeStateNonNull(json, "top_state", context);
|
||||
this.generationAttempts = json.get("generation_attempts").getAsInt();
|
||||
this.amountPerChunk = conf.getInt("amountPerChunk", this.amountPerChunk);
|
||||
this.bottomState = conf.getBlockState("bottomState", this.bottomState);
|
||||
this.topState = conf.getBlockState("topState", this.topState);
|
||||
this.generationAttempts = conf.getInt("generationAttempts", this.generationAttempts);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,17 +10,15 @@ package biomesoplenty.common.world.feature;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import biomesoplenty.api.biome.generation.GeneratorCustomizable;
|
||||
import biomesoplenty.common.block.BlockDecoration;
|
||||
import biomesoplenty.common.util.biome.GeneratorUtils;
|
||||
import biomesoplenty.common.util.config.ConfigHelper.WrappedJsonObject;
|
||||
|
||||
public class GeneratorFlora extends GeneratorCustomizable
|
||||
{
|
||||
|
@ -28,7 +26,11 @@ public class GeneratorFlora extends GeneratorCustomizable
|
|||
protected IBlockState state;
|
||||
protected int generationAttempts;
|
||||
|
||||
public GeneratorFlora() {}
|
||||
public GeneratorFlora()
|
||||
{
|
||||
// default
|
||||
this(1, Blocks.red_flower.getDefaultState(), 64);
|
||||
}
|
||||
|
||||
public GeneratorFlora(int amountPerChunk, IBlockState state, int generationAttempts)
|
||||
{
|
||||
|
@ -78,18 +80,11 @@ public class GeneratorFlora extends GeneratorCustomizable
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeToJson(JsonObject json, JsonSerializationContext context)
|
||||
public void configure(WrappedJsonObject conf)
|
||||
{
|
||||
json.addProperty("amount_per_chunk", this.amountPerChunk);
|
||||
json.add("state", context.serialize(this.state));
|
||||
json.addProperty("generation_attempts", this.generationAttempts);
|
||||
this.amountPerChunk = conf.getInt("amountPerChunk", this.amountPerChunk);
|
||||
this.state = conf.getBlockState("state", this.state);
|
||||
this.generationAttempts = conf.getInt("generationAttempts", this.generationAttempts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromJson(JsonObject json, JsonDeserializationContext context)
|
||||
{
|
||||
this.amountPerChunk = json.get("amount_per_chunk").getAsInt();
|
||||
this.state = GeneratorUtils.deserializeStateNonNull(json, "state", context);
|
||||
this.generationAttempts = json.get("generation_attempts").getAsInt();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import java.util.Random;
|
|||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import biomesoplenty.common.block.BlockDecoration;
|
||||
|
@ -19,7 +20,11 @@ import biomesoplenty.common.util.biome.GeneratorUtils;
|
|||
|
||||
public class GeneratorGrass extends GeneratorFlora
|
||||
{
|
||||
public GeneratorGrass() {}
|
||||
public GeneratorGrass()
|
||||
{
|
||||
// default
|
||||
this(1, Blocks.tallgrass.getDefaultState(), 128);
|
||||
}
|
||||
|
||||
public GeneratorGrass(int amountPerChunk, IBlockState state, int generationAttempts)
|
||||
{
|
||||
|
|
|
@ -17,10 +17,7 @@ import org.apache.commons.lang3.tuple.Pair;
|
|||
|
||||
import biomesoplenty.api.biome.generation.GeneratorCustomizable;
|
||||
import biomesoplenty.common.util.biome.GeneratorUtils;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import biomesoplenty.common.util.config.ConfigHelper.WrappedJsonObject;
|
||||
|
||||
public abstract class GeneratorOreBase extends GeneratorCustomizable
|
||||
{
|
||||
|
@ -28,8 +25,6 @@ public abstract class GeneratorOreBase extends GeneratorCustomizable
|
|||
protected int minHeight;
|
||||
protected int maxHeight;
|
||||
|
||||
protected GeneratorOreBase() {}
|
||||
|
||||
protected GeneratorOreBase(int amountPerChunk, int minHeight, int maxHeight)
|
||||
{
|
||||
this.amountPerChunk = amountPerChunk;
|
||||
|
@ -51,22 +46,15 @@ public abstract class GeneratorOreBase extends GeneratorCustomizable
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeToJson(JsonObject json, JsonSerializationContext context)
|
||||
public void configure(WrappedJsonObject conf)
|
||||
{
|
||||
json.addProperty("amount_per_chunk", this.amountPerChunk);
|
||||
json.addProperty("min_height", this.minHeight);
|
||||
json.addProperty("max_height", this.maxHeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromJson(JsonObject json, JsonDeserializationContext context)
|
||||
{
|
||||
this.amountPerChunk = json.get("amount_per_chunk").getAsInt();
|
||||
int minHeight = json.get("min_height").getAsInt();
|
||||
int maxHeight = json.get("max_height").getAsInt();
|
||||
this.amountPerChunk = conf.getInt("amountPerChunk", this.amountPerChunk);
|
||||
int minHeight = conf.getInt("minHeight", this.minHeight).intValue();
|
||||
int maxHeight = conf.getInt("maxHeight", this.maxHeight).intValue();
|
||||
|
||||
Pair<Integer, Integer> heights = GeneratorUtils.validateMinMaxHeight(minHeight, maxHeight);
|
||||
this.minHeight = heights.getLeft();
|
||||
this.maxHeight = heights.getRight();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,19 +11,21 @@ package biomesoplenty.common.world.feature;
|
|||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.gen.feature.WorldGenMinable;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import biomesoplenty.common.util.config.ConfigHelper.WrappedJsonObject;
|
||||
|
||||
public class GeneratorOreCluster extends GeneratorOreBase
|
||||
{
|
||||
private WorldGenMinable generator;
|
||||
|
||||
public GeneratorOreCluster() {}
|
||||
public GeneratorOreCluster()
|
||||
{
|
||||
// default
|
||||
this(Blocks.emerald_ore.getDefaultState(), 12, 4, 4, 32);
|
||||
}
|
||||
|
||||
public GeneratorOreCluster(IBlockState state, int amountPerChunk, int clusterSize, int minHeight, int maxHeight)
|
||||
{
|
||||
|
@ -39,22 +41,12 @@ public class GeneratorOreCluster extends GeneratorOreBase
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeToJson(JsonObject json, JsonSerializationContext context)
|
||||
public void configure(WrappedJsonObject conf)
|
||||
{
|
||||
super.writeToJson(json, context);
|
||||
super.configure(conf);
|
||||
|
||||
json.add("state", context.serialize(this.generator.oreBlock));
|
||||
json.addProperty("cluster_size", this.generator.numberOfBlocks);
|
||||
this.generator.oreBlock = conf.getBlockState("state", this.generator.oreBlock);
|
||||
this.generator.numberOfBlocks = conf.getInt("clusterSize", this.generator.numberOfBlocks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromJson(JsonObject json, JsonDeserializationContext context)
|
||||
{
|
||||
super.readFromJson(json, context);
|
||||
|
||||
IBlockState state = context.deserialize(json.get("state"), IBlockState.class);
|
||||
int clusterSize = json.get("cluster_size").getAsInt();
|
||||
|
||||
this.generator = new WorldGenMinable(state, clusterSize);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,18 +15,20 @@ import net.minecraft.block.state.pattern.BlockHelper;
|
|||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import biomesoplenty.common.util.config.ConfigHelper.WrappedJsonObject;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
|
||||
public class GeneratorOreSingle extends GeneratorOreBase
|
||||
{
|
||||
private IBlockState state;
|
||||
private Predicate replace;
|
||||
|
||||
public GeneratorOreSingle() {}
|
||||
public GeneratorOreSingle()
|
||||
{
|
||||
// default
|
||||
this(Blocks.emerald_ore.getDefaultState(), 12, 4, 32);
|
||||
}
|
||||
|
||||
public GeneratorOreSingle(IBlockState state, int amountPerChunk, int minHeight, int maxHeight)
|
||||
{
|
||||
|
@ -48,19 +50,12 @@ public class GeneratorOreSingle extends GeneratorOreBase
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeToJson(JsonObject json, JsonSerializationContext context)
|
||||
public void configure(WrappedJsonObject conf)
|
||||
{
|
||||
super.writeToJson(json, context);
|
||||
super.configure(conf);
|
||||
|
||||
json.add("state", context.serialize(this.state));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromJson(JsonObject json, JsonDeserializationContext context)
|
||||
{
|
||||
super.readFromJson(json, context);
|
||||
|
||||
this.state = context.deserialize(json.get("state"), IBlockState.class);
|
||||
this.state = conf.getBlockState("state", this.state);
|
||||
this.replace = BlockHelper.forBlock(Blocks.stone);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
package biomesoplenty.common.world.feature;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
@ -18,11 +19,7 @@ import net.minecraft.init.Blocks;
|
|||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import biomesoplenty.api.biome.generation.GeneratorCustomizable;
|
||||
import biomesoplenty.common.util.biome.GeneratorUtils;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import biomesoplenty.common.util.config.ConfigHelper.WrappedJsonObject;
|
||||
|
||||
public class GeneratorWaterside extends GeneratorCustomizable
|
||||
{
|
||||
|
@ -31,7 +28,11 @@ public class GeneratorWaterside extends GeneratorCustomizable
|
|||
private IBlockState state;
|
||||
private List<IBlockState> replacedStates;
|
||||
|
||||
public GeneratorWaterside() {}
|
||||
public GeneratorWaterside()
|
||||
{
|
||||
// default
|
||||
this(4, 7, Blocks.gravel.getDefaultState());
|
||||
}
|
||||
|
||||
public GeneratorWaterside(int amountPerChunk, int maxRadius, IBlockState state, IBlockState... replacedStates)
|
||||
{
|
||||
|
@ -105,20 +106,12 @@ public class GeneratorWaterside extends GeneratorCustomizable
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeToJson(JsonObject json, JsonSerializationContext context)
|
||||
public void configure(WrappedJsonObject conf)
|
||||
{
|
||||
json.addProperty("amount_per_chunk", this.amountPerChunk);
|
||||
json.addProperty("max_radius", this.maxRadius);
|
||||
json.add("state", context.serialize(this.state));
|
||||
json.add("replaced_states", context.serialize(this.replacedStates));
|
||||
this.amountPerChunk = conf.getInt("amountPerChunk", this.amountPerChunk);
|
||||
this.maxRadius = conf.getInt("maxRadius", this.maxRadius);
|
||||
this.state = conf.getBlockState("state", this.state);
|
||||
this.replacedStates = conf.getBlockStateArray("replacedStates", new ArrayList(this.replacedStates) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromJson(JsonObject json, JsonDeserializationContext context)
|
||||
{
|
||||
this.amountPerChunk = json.get("amount_per_chunk").getAsInt();
|
||||
this.maxRadius = json.get("max_radius").getAsInt();
|
||||
this.state = GeneratorUtils.deserializeStateNonNull(json, "state", context);
|
||||
this.replacedStates = context.deserialize(json.get("replaced_states"), List.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,10 +24,7 @@ import org.apache.commons.lang3.tuple.Pair;
|
|||
|
||||
import biomesoplenty.api.biome.generation.GeneratorCustomizable;
|
||||
import biomesoplenty.common.util.biome.GeneratorUtils;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import biomesoplenty.common.util.config.ConfigHelper.WrappedJsonObject;
|
||||
|
||||
public class GeneratorBasicTree extends GeneratorCustomizable
|
||||
{
|
||||
|
@ -39,7 +36,11 @@ public class GeneratorBasicTree extends GeneratorCustomizable
|
|||
private IBlockState leaves;
|
||||
private IBlockState vine;
|
||||
|
||||
public GeneratorBasicTree() {}
|
||||
public GeneratorBasicTree()
|
||||
{
|
||||
// default
|
||||
this(1, false, 4, 7, Blocks.log.getDefaultState(), Blocks.leaves.getDefaultState());
|
||||
}
|
||||
|
||||
public GeneratorBasicTree(int amountPerChunk, boolean updateNeighbours, int minHeight, int maxHeight, IBlockState log, IBlockState leaves, IBlockState vine)
|
||||
{
|
||||
|
@ -301,31 +302,19 @@ public class GeneratorBasicTree extends GeneratorCustomizable
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeToJson(JsonObject json, JsonSerializationContext context)
|
||||
public void configure(WrappedJsonObject conf)
|
||||
{
|
||||
json.addProperty("amount_per_chunk", this.amountPerChunk);
|
||||
json.addProperty("update_neighbours", this.updateNeighbours);
|
||||
json.addProperty("min_height", this.minHeight);
|
||||
json.addProperty("max_height", this.maxHeight);
|
||||
json.add("log_state", context.serialize(this.log));
|
||||
json.add("leaves_state", context.serialize(this.leaves));
|
||||
json.add("vine_state", context.serialize(this.vine));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromJson(JsonObject json, JsonDeserializationContext context)
|
||||
{
|
||||
this.amountPerChunk = json.get("amount_per_chunk").getAsInt();
|
||||
this.updateNeighbours = json.get("update_neighbours").getAsBoolean();
|
||||
int minHeight = json.get("min_height").getAsInt();
|
||||
int maxHeight = json.get("max_height").getAsInt();
|
||||
this.amountPerChunk = conf.getInt("amountPerChunk", this.amountPerChunk);
|
||||
this.updateNeighbours = conf.getBool("updateNeighbours", this.updateNeighbours);
|
||||
int minHeight = conf.getInt("minHeight", this.minHeight);
|
||||
int maxHeight = conf.getInt("maxHeight", this.maxHeight);
|
||||
|
||||
Pair<Integer, Integer> heights = GeneratorUtils.validateMinMaxHeight(minHeight, maxHeight);
|
||||
this.minHeight = heights.getLeft();
|
||||
this.maxHeight = heights.getRight();
|
||||
|
||||
this.log = context.deserialize(json.get("log_state"), IBlockState.class);
|
||||
this.leaves = context.deserialize(json.get("leaves_state"), IBlockState.class);
|
||||
this.vine = context.deserialize(json.get("vine_state"), IBlockState.class);
|
||||
this.log = conf.getBlockState("logState", this.log);
|
||||
this.leaves = conf.getBlockState("leavesState", this.leaves);
|
||||
this.vine = conf.getBlockState("vineState", this.vine);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,11 +23,9 @@ import net.minecraft.util.MathHelper;
|
|||
import net.minecraft.world.World;
|
||||
import biomesoplenty.api.biome.generation.GeneratorCustomizable;
|
||||
import biomesoplenty.common.util.biome.GeneratorUtils;
|
||||
import biomesoplenty.common.util.config.ConfigHelper.WrappedJsonObject;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
|
||||
/*This class is heavily based on https://gist.github.com/grum/62cfdec0537e8db24eb3#file-bigtreefeature-java
|
||||
additional information has been added from http://pastebin.com/XBLdGqXQ. This class has been cross-checked
|
||||
|
@ -58,7 +56,11 @@ public class GeneratorBigTree extends GeneratorCustomizable
|
|||
|
||||
private List<FoliageCoords> foliageCoords;
|
||||
|
||||
public GeneratorBigTree() {}
|
||||
public GeneratorBigTree()
|
||||
{
|
||||
// default
|
||||
this(1, false, 4, 7, Blocks.log.getDefaultState(), Blocks.leaves.getDefaultState());
|
||||
}
|
||||
|
||||
public GeneratorBigTree(int amountPerChunk, boolean updateNeighbours, int minHeight, int maxHeight, IBlockState log, IBlockState leaves)
|
||||
{
|
||||
|
@ -533,29 +535,19 @@ public class GeneratorBigTree extends GeneratorCustomizable
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeToJson(JsonObject json, JsonSerializationContext context)
|
||||
public void configure(WrappedJsonObject conf)
|
||||
{
|
||||
json.addProperty("amount_per_chunk", this.amountPerChunk);
|
||||
json.addProperty("update_neighbours", this.updateNeighbours);
|
||||
json.addProperty("min_height", this.minHeight);
|
||||
json.addProperty("max_height", this.maxHeight);
|
||||
json.add("log_state", context.serialize(this.log));
|
||||
json.add("leaves_state", context.serialize(this.leaves));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromJson(JsonObject json, JsonDeserializationContext context)
|
||||
{
|
||||
this.amountPerChunk = json.get("amount_per_chunk").getAsInt();
|
||||
this.updateNeighbours = json.get("update_neighbours").getAsBoolean();
|
||||
int minHeight = json.get("min_height").getAsInt();
|
||||
int maxHeight = json.get("max_height").getAsInt();
|
||||
this.amountPerChunk = conf.getInt("amountPerChunk", this.amountPerChunk);
|
||||
this.updateNeighbours = conf.getBool("updateNeighbours", this.updateNeighbours);
|
||||
int minHeight = conf.getInt("minHeight", this.minHeight);
|
||||
int maxHeight = conf.getInt("maxHeight", this.maxHeight);
|
||||
|
||||
Pair<Integer, Integer> heights = GeneratorUtils.validateMinMaxHeight(minHeight, maxHeight);
|
||||
this.minHeight = heights.getLeft();
|
||||
this.maxHeight = heights.getRight();
|
||||
|
||||
this.log = context.deserialize(json.get("log_state"), IBlockState.class);
|
||||
this.leaves = context.deserialize(json.get("leaves_state"), IBlockState.class);
|
||||
this.log = conf.getBlockState("logState", this.log);
|
||||
this.leaves = conf.getBlockState("leavesState", this.leaves);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,12 +18,8 @@ import net.minecraft.util.BlockPos;
|
|||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
|
||||
import biomesoplenty.api.biome.generation.GeneratorCustomizable;
|
||||
import biomesoplenty.common.util.biome.GeneratorUtils;
|
||||
import biomesoplenty.common.util.config.ConfigHelper.WrappedJsonObject;
|
||||
|
||||
public class GeneratorBush extends GeneratorCustomizable
|
||||
{
|
||||
|
@ -31,7 +27,11 @@ public class GeneratorBush extends GeneratorCustomizable
|
|||
private IBlockState log;
|
||||
private IBlockState leaves;
|
||||
|
||||
public GeneratorBush() {}
|
||||
public GeneratorBush()
|
||||
{
|
||||
// default
|
||||
this(1, Blocks.log.getDefaultState(), Blocks.leaves.getDefaultState());
|
||||
}
|
||||
|
||||
public GeneratorBush(int amountPerChunk, IBlockState log, IBlockState leaves)
|
||||
{
|
||||
|
@ -110,18 +110,11 @@ public class GeneratorBush extends GeneratorCustomizable
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeToJson(JsonObject json, JsonSerializationContext context)
|
||||
public void configure(WrappedJsonObject conf)
|
||||
{
|
||||
json.addProperty("amount_per_chunk", this.amountPerChunk);
|
||||
json.add("log_state", context.serialize(this.log));
|
||||
json.add("leaves_state", context.serialize(this.leaves));
|
||||
this.amountPerChunk = conf.getInt("amountPerChunk", this.amountPerChunk);
|
||||
this.log = conf.getBlockState("logState", this.log);
|
||||
this.leaves = conf.getBlockState("leavesState", this.leaves);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromJson(JsonObject json, JsonDeserializationContext context)
|
||||
{
|
||||
this.amountPerChunk = json.get("amount_per_chunk").getAsInt();
|
||||
this.log = GeneratorUtils.deserializeStateNonNull(json, "log_state", context);
|
||||
this.leaves = GeneratorUtils.deserializeStateNonNull(json, "leaves_state", context);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue