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;
|
package biomesoplenty.api.biome.generation;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
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.ImmutableCollection;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Table;
|
|
||||||
|
|
||||||
public class GenerationManager
|
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)
|
public void addGenerator(String name, GeneratorStage stage, IGenerator generator)
|
||||||
{
|
{
|
||||||
if (!this.generatorTable.containsColumn(name))
|
if (this.generators.containsKey(name))
|
||||||
{
|
|
||||||
generator.setName(name);
|
|
||||||
generator.setStage(stage);
|
|
||||||
|
|
||||||
this.generatorTable.put(stage, name, generator);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
throw new RuntimeException("A generator with name " + name + " already exists!");
|
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)
|
public ImmutableCollection<IGenerator> getGeneratorsForStage(GeneratorStage stage)
|
||||||
{
|
{
|
||||||
Map<String, IGenerator> columnMap = this.generatorTable.rowMap().get(stage);
|
ArrayList<IGenerator> out = new ArrayList<IGenerator>();
|
||||||
Collection<IGenerator> result = columnMap == null ? null : columnMap.values();
|
for (IGenerator generator : this.generators.values())
|
||||||
|
{
|
||||||
return result == null ? ImmutableList.<IGenerator>of() : ImmutableList.<IGenerator>copyOf(result);
|
if (generator.getStage() == stage)
|
||||||
|
{
|
||||||
|
out.add(generator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ImmutableList.<IGenerator>copyOf(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, IGenerator> createGeneratorMap()
|
public void removeGenerator(String name)
|
||||||
{
|
{
|
||||||
Map<String, IGenerator> result = new HashMap<String, IGenerator>();
|
this.generators.remove(name);
|
||||||
|
}
|
||||||
|
|
||||||
for (IGenerator generator : this.generatorTable.values())
|
public IGenerator getGenerator(String name)
|
||||||
|
{
|
||||||
|
return this.generators.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void configureWith(String name, WrappedJsonObject conf)
|
||||||
|
{
|
||||||
|
if (this.generators.containsKey(name))
|
||||||
{
|
{
|
||||||
result.put(generator.getName(), generator);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
public IGenerator create()
|
||||||
}
|
|
||||||
|
|
||||||
public void createGeneratorTable(Map<String, IGenerator> generators)
|
|
||||||
{
|
|
||||||
Table<GeneratorStage, String, IGenerator> result = HashBasedTable.create();
|
|
||||||
|
|
||||||
for (Entry<String, IGenerator> entry : generators.entrySet())
|
|
||||||
{
|
{
|
||||||
String name = entry.getKey();
|
switch (this)
|
||||||
IGenerator generator = entry.getValue();
|
{
|
||||||
|
case FLORA:
|
||||||
generator.setName(name);
|
return new GeneratorFlora();
|
||||||
result.put(generator.getStage(), generator.getName(), generator);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.generatorTable = result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -8,6 +8,8 @@
|
||||||
|
|
||||||
package biomesoplenty.api.biome.generation;
|
package biomesoplenty.api.biome.generation;
|
||||||
|
|
||||||
|
import biomesoplenty.common.util.config.ConfigHelper.WrappedJsonObject;
|
||||||
|
|
||||||
public abstract class GeneratorCustomizable implements IGenerator
|
public abstract class GeneratorCustomizable implements IGenerator
|
||||||
{
|
{
|
||||||
private final String identifier;
|
private final String identifier;
|
||||||
|
@ -53,4 +55,10 @@ public abstract class GeneratorCustomizable implements IGenerator
|
||||||
{
|
{
|
||||||
return this.identifier;
|
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.BlockPos;
|
||||||
import net.minecraft.util.WeightedRandom;
|
import net.minecraft.util.WeightedRandom;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import biomesoplenty.common.util.config.ConfigHelper.WrappedJsonObject;
|
||||||
|
|
||||||
import com.google.gson.JsonDeserializationContext;
|
// TODO implement so that we don't rely on minecraft WeightedRandom class and GeneratorWeightedEntry class - can be much simpler
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonSerializationContext;
|
|
||||||
import com.google.gson.reflect.TypeToken;
|
|
||||||
|
|
||||||
public class GeneratorWeighted extends GeneratorCustomizable
|
public class GeneratorWeighted extends GeneratorCustomizable
|
||||||
{
|
{
|
||||||
private int amountPerChunk;
|
private int amountPerChunk;
|
||||||
|
@ -59,16 +56,26 @@ public class GeneratorWeighted extends GeneratorCustomizable
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToJson(JsonObject json, JsonSerializationContext context)
|
public void configure(WrappedJsonObject conf)
|
||||||
{
|
{
|
||||||
json.addProperty("amount_per_chunk", this.amountPerChunk);
|
this.amountPerChunk = conf.getInt("amountPerChunk", this.amountPerChunk);
|
||||||
json.add("entries", context.serialize(this.weightedEntries));
|
ArrayList<WrappedJsonObject> weightedEntriesConf = conf.getObjectArray("weightedEntries");
|
||||||
}
|
if (!weightedEntriesConf.isEmpty())
|
||||||
|
{
|
||||||
@Override
|
this.weightedEntries.clear();
|
||||||
public void readFromJson(JsonObject json, JsonDeserializationContext context)
|
for (WrappedJsonObject weightedEntryConf : weightedEntriesConf)
|
||||||
{
|
{
|
||||||
this.amountPerChunk = json.get("amount_per_chunk").getAsInt();
|
Integer weight = weightedEntryConf.getInt("weight", null);
|
||||||
this.weightedEntries = context.deserialize(json.get("entries"), new TypeToken<List<GeneratorWeightedEntry>>() {}.getType());
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 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.BlockPos;
|
||||||
import net.minecraft.util.WeightedRandom;
|
import net.minecraft.util.WeightedRandom;
|
||||||
import net.minecraft.world.World;
|
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;
|
|
||||||
|
|
||||||
public final class GeneratorWeightedEntry extends WeightedRandom.Item implements IGenerator
|
public final class GeneratorWeightedEntry extends WeightedRandom.Item implements IGenerator
|
||||||
{
|
{
|
||||||
|
@ -56,18 +53,12 @@ public final class GeneratorWeightedEntry extends WeightedRandom.Item implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToJson(JsonObject json, JsonSerializationContext context)
|
public void configure(WrappedJsonObject conf)
|
||||||
{
|
{
|
||||||
json.addProperty("weight", this.itemWeight);
|
// this should never be used directly
|
||||||
json.add("wrapped_generator", context.serialize(this.wrappedGenerator));
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
@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
|
@Override
|
||||||
public void setStage(GeneratorStage stage)
|
public void setStage(GeneratorStage stage)
|
||||||
|
@ -96,4 +87,5 @@ public final class GeneratorWeightedEntry extends WeightedRandom.Item implements
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,10 +12,7 @@ import java.util.Random;
|
||||||
|
|
||||||
import net.minecraft.util.BlockPos;
|
import net.minecraft.util.BlockPos;
|
||||||
import net.minecraft.world.World;
|
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;
|
|
||||||
|
|
||||||
public interface IGenerator
|
public interface IGenerator
|
||||||
{
|
{
|
||||||
|
@ -33,6 +30,5 @@ public interface IGenerator
|
||||||
public String getIdentifier();
|
public String getIdentifier();
|
||||||
public GeneratorStage getStage();
|
public GeneratorStage getStage();
|
||||||
|
|
||||||
public void writeToJson(JsonObject json, JsonSerializationContext context);
|
public void configure(WrappedJsonObject conf);
|
||||||
public void readFromJson(JsonObject json, JsonDeserializationContext context);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,6 @@
|
||||||
|
|
||||||
package biomesoplenty.common.biome.overworld;
|
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.BlockFlower.EnumFlowerType;
|
||||||
import net.minecraft.block.BlockTallGrass;
|
import net.minecraft.block.BlockTallGrass;
|
||||||
import net.minecraft.entity.passive.EntityHorse;
|
import net.minecraft.entity.passive.EntityHorse;
|
||||||
|
@ -21,7 +19,6 @@ import biomesoplenty.api.biome.generation.GeneratorWeighted;
|
||||||
import biomesoplenty.api.block.BOPBlocks;
|
import biomesoplenty.api.block.BOPBlocks;
|
||||||
import biomesoplenty.common.block.BlockBOPDoublePlant;
|
import biomesoplenty.common.block.BlockBOPDoublePlant;
|
||||||
import biomesoplenty.common.block.BlockBOPPlant;
|
import biomesoplenty.common.block.BlockBOPPlant;
|
||||||
import biomesoplenty.common.block.BlockDoubleDecoration.Half;
|
|
||||||
import biomesoplenty.common.block.BlockGem;
|
import biomesoplenty.common.block.BlockGem;
|
||||||
import biomesoplenty.common.enums.BOPGems;
|
import biomesoplenty.common.enums.BOPGems;
|
||||||
import biomesoplenty.common.enums.BOPPlants;
|
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("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("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("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("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()));
|
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 com.google.gson.JsonParser;
|
||||||
|
|
||||||
import biomesoplenty.common.util.block.BlockStateUtils;
|
import biomesoplenty.common.util.block.BlockStateUtils;
|
||||||
import biomesoplenty.common.util.config.JsonBlockState;
|
|
||||||
import biomesoplenty.core.BiomesOPlenty;
|
import biomesoplenty.core.BiomesOPlenty;
|
||||||
|
|
||||||
public class ConfigHelper
|
public class ConfigHelper
|
||||||
|
@ -35,7 +34,6 @@ public class ConfigHelper
|
||||||
|
|
||||||
public static Gson serializer = new GsonBuilder().setPrettyPrinting().create();
|
public static Gson serializer = new GsonBuilder().setPrettyPrinting().create();
|
||||||
public static JsonParser parser = new JsonParser();
|
public static JsonParser parser = new JsonParser();
|
||||||
public JsonBlockState blockStateParser = new JsonBlockState();
|
|
||||||
public WrappedJsonObject root = null;
|
public WrappedJsonObject root = null;
|
||||||
public ArrayList<String> messages = new ArrayList<String>();
|
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);
|
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)
|
public Boolean getBool(String name, Boolean defaultVal)
|
||||||
{
|
{
|
||||||
return this.root == null ? defaultVal : this.root.getBool(name, 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)
|
public String getString(String name, String defaultVal)
|
||||||
{
|
{
|
||||||
return this.root == null ? defaultVal : this.root.getString(name, 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)
|
public Integer getInt(String name, Integer defaultVal)
|
||||||
{
|
{
|
||||||
return this.root == null ? defaultVal : this.root.getInt(name, 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)
|
public Float getFloat(String name, Float defaultVal)
|
||||||
{
|
{
|
||||||
return this.root == null ? defaultVal : this.root.getFloat(name, 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)
|
public IBlockState getBlockState(String name, IBlockState defaultVal)
|
||||||
{
|
{
|
||||||
|
@ -174,6 +172,16 @@ public class ConfigHelper
|
||||||
this.conf = conf;
|
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)
|
public WrappedJsonObject getObject(String name)
|
||||||
{
|
{
|
||||||
if (this.obj == null || !this.obj.has(name)) {return null;}
|
if (this.obj == null || !this.obj.has(name)) {return null;}
|
||||||
|
@ -214,19 +222,40 @@ public class ConfigHelper
|
||||||
return list;
|
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 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 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 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 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 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)
|
private <T> T get(String name, T defaultVal, Types type)
|
||||||
{
|
{
|
||||||
|
@ -235,21 +264,20 @@ public class ConfigHelper
|
||||||
return out == null ? defaultVal : out;
|
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>();
|
ArrayList<T> list = new ArrayList<T>();
|
||||||
if (this.obj != null && this.obj.has(name)) {
|
try
|
||||||
try
|
{
|
||||||
|
JsonArray arr = this.obj.getAsJsonArray(name);
|
||||||
|
for (int i = 0; i < arr.size(); i++)
|
||||||
{
|
{
|
||||||
JsonArray arr = this.obj.getAsJsonArray(name);
|
T ele = this.<T>as(arr.get(i), type);
|
||||||
for (int i = 0; i < arr.size(); i++)
|
if (ele != null) {list.add(ele);}
|
||||||
{
|
|
||||||
T ele = this.<T>as(arr.get(i), type);
|
|
||||||
if (ele != null) {list.add(ele);}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
this.conf.addMessage("Error fetching " + type.toString().toLowerCase() + " array: " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
this.conf.addMessage("Error fetching " + type.toString().toLowerCase() + " array: " + e.getMessage());
|
||||||
}
|
}
|
||||||
return list;
|
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)
|
public Boolean asBool(JsonElement ele)
|
||||||
{
|
{
|
||||||
try
|
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 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.biome.generation.GeneratorCustomizable;
|
||||||
|
import biomesoplenty.api.block.BOPBlocks;
|
||||||
|
import biomesoplenty.common.block.BlockBOPDoublePlant;
|
||||||
import biomesoplenty.common.block.BlockDecoration;
|
import biomesoplenty.common.block.BlockDecoration;
|
||||||
|
import biomesoplenty.common.block.BlockDoubleDecoration;
|
||||||
import biomesoplenty.common.util.biome.GeneratorUtils;
|
import biomesoplenty.common.util.biome.GeneratorUtils;
|
||||||
|
import biomesoplenty.common.util.config.ConfigHelper.WrappedJsonObject;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.util.BlockPos;
|
import net.minecraft.util.BlockPos;
|
||||||
|
@ -29,7 +29,17 @@ public class GeneratorDoubleFlora extends GeneratorCustomizable
|
||||||
private IBlockState topState;
|
private IBlockState topState;
|
||||||
private int generationAttempts;
|
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)
|
public GeneratorDoubleFlora(int amountPerChunk, IBlockState bottomState, IBlockState topState, int generationAttempts)
|
||||||
{
|
{
|
||||||
|
@ -81,20 +91,11 @@ public class GeneratorDoubleFlora extends GeneratorCustomizable
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToJson(JsonObject json, JsonSerializationContext context)
|
public void configure(WrappedJsonObject conf)
|
||||||
{
|
{
|
||||||
json.addProperty("amount_per_chunk", this.amountPerChunk);
|
this.amountPerChunk = conf.getInt("amountPerChunk", this.amountPerChunk);
|
||||||
json.add("bottom_state", context.serialize(this.bottomState));
|
this.bottomState = conf.getBlockState("bottomState", this.bottomState);
|
||||||
json.add("top_state", context.serialize(this.topState));
|
this.topState = conf.getBlockState("topState", this.topState);
|
||||||
json.addProperty("generation_attempts", this.generationAttempts);
|
this.generationAttempts = conf.getInt("generationAttempts", 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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,17 +10,15 @@ package biomesoplenty.common.world.feature;
|
||||||
|
|
||||||
import java.util.Random;
|
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.Block;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.util.BlockPos;
|
import net.minecraft.util.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import biomesoplenty.api.biome.generation.GeneratorCustomizable;
|
import biomesoplenty.api.biome.generation.GeneratorCustomizable;
|
||||||
import biomesoplenty.common.block.BlockDecoration;
|
import biomesoplenty.common.block.BlockDecoration;
|
||||||
import biomesoplenty.common.util.biome.GeneratorUtils;
|
import biomesoplenty.common.util.biome.GeneratorUtils;
|
||||||
|
import biomesoplenty.common.util.config.ConfigHelper.WrappedJsonObject;
|
||||||
|
|
||||||
public class GeneratorFlora extends GeneratorCustomizable
|
public class GeneratorFlora extends GeneratorCustomizable
|
||||||
{
|
{
|
||||||
|
@ -28,7 +26,11 @@ public class GeneratorFlora extends GeneratorCustomizable
|
||||||
protected IBlockState state;
|
protected IBlockState state;
|
||||||
protected int generationAttempts;
|
protected int generationAttempts;
|
||||||
|
|
||||||
public GeneratorFlora() {}
|
public GeneratorFlora()
|
||||||
|
{
|
||||||
|
// default
|
||||||
|
this(1, Blocks.red_flower.getDefaultState(), 64);
|
||||||
|
}
|
||||||
|
|
||||||
public GeneratorFlora(int amountPerChunk, IBlockState state, int generationAttempts)
|
public GeneratorFlora(int amountPerChunk, IBlockState state, int generationAttempts)
|
||||||
{
|
{
|
||||||
|
@ -78,18 +80,11 @@ public class GeneratorFlora extends GeneratorCustomizable
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToJson(JsonObject json, JsonSerializationContext context)
|
public void configure(WrappedJsonObject conf)
|
||||||
{
|
{
|
||||||
json.addProperty("amount_per_chunk", this.amountPerChunk);
|
this.amountPerChunk = conf.getInt("amountPerChunk", this.amountPerChunk);
|
||||||
json.add("state", context.serialize(this.state));
|
this.state = conf.getBlockState("state", this.state);
|
||||||
json.addProperty("generation_attempts", this.generationAttempts);
|
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.Block;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.util.BlockPos;
|
import net.minecraft.util.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import biomesoplenty.common.block.BlockDecoration;
|
import biomesoplenty.common.block.BlockDecoration;
|
||||||
|
@ -19,7 +20,11 @@ import biomesoplenty.common.util.biome.GeneratorUtils;
|
||||||
|
|
||||||
public class GeneratorGrass extends GeneratorFlora
|
public class GeneratorGrass extends GeneratorFlora
|
||||||
{
|
{
|
||||||
public GeneratorGrass() {}
|
public GeneratorGrass()
|
||||||
|
{
|
||||||
|
// default
|
||||||
|
this(1, Blocks.tallgrass.getDefaultState(), 128);
|
||||||
|
}
|
||||||
|
|
||||||
public GeneratorGrass(int amountPerChunk, IBlockState state, int generationAttempts)
|
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.api.biome.generation.GeneratorCustomizable;
|
||||||
import biomesoplenty.common.util.biome.GeneratorUtils;
|
import biomesoplenty.common.util.biome.GeneratorUtils;
|
||||||
|
import biomesoplenty.common.util.config.ConfigHelper.WrappedJsonObject;
|
||||||
import com.google.gson.JsonDeserializationContext;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonSerializationContext;
|
|
||||||
|
|
||||||
public abstract class GeneratorOreBase extends GeneratorCustomizable
|
public abstract class GeneratorOreBase extends GeneratorCustomizable
|
||||||
{
|
{
|
||||||
|
@ -28,8 +25,6 @@ public abstract class GeneratorOreBase extends GeneratorCustomizable
|
||||||
protected int minHeight;
|
protected int minHeight;
|
||||||
protected int maxHeight;
|
protected int maxHeight;
|
||||||
|
|
||||||
protected GeneratorOreBase() {}
|
|
||||||
|
|
||||||
protected GeneratorOreBase(int amountPerChunk, int minHeight, int maxHeight)
|
protected GeneratorOreBase(int amountPerChunk, int minHeight, int maxHeight)
|
||||||
{
|
{
|
||||||
this.amountPerChunk = amountPerChunk;
|
this.amountPerChunk = amountPerChunk;
|
||||||
|
@ -51,22 +46,15 @@ public abstract class GeneratorOreBase extends GeneratorCustomizable
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToJson(JsonObject json, JsonSerializationContext context)
|
public void configure(WrappedJsonObject conf)
|
||||||
{
|
{
|
||||||
json.addProperty("amount_per_chunk", this.amountPerChunk);
|
this.amountPerChunk = conf.getInt("amountPerChunk", this.amountPerChunk);
|
||||||
json.addProperty("min_height", this.minHeight);
|
int minHeight = conf.getInt("minHeight", this.minHeight).intValue();
|
||||||
json.addProperty("max_height", this.maxHeight);
|
int maxHeight = conf.getInt("maxHeight", this.maxHeight).intValue();
|
||||||
}
|
|
||||||
|
|
||||||
@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();
|
|
||||||
|
|
||||||
Pair<Integer, Integer> heights = GeneratorUtils.validateMinMaxHeight(minHeight, maxHeight);
|
Pair<Integer, Integer> heights = GeneratorUtils.validateMinMaxHeight(minHeight, maxHeight);
|
||||||
this.minHeight = heights.getLeft();
|
this.minHeight = heights.getLeft();
|
||||||
this.maxHeight = heights.getRight();
|
this.maxHeight = heights.getRight();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,19 +11,21 @@ package biomesoplenty.common.world.feature;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.util.BlockPos;
|
import net.minecraft.util.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.gen.feature.WorldGenMinable;
|
import net.minecraft.world.gen.feature.WorldGenMinable;
|
||||||
|
import biomesoplenty.common.util.config.ConfigHelper.WrappedJsonObject;
|
||||||
import com.google.gson.JsonDeserializationContext;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonSerializationContext;
|
|
||||||
|
|
||||||
public class GeneratorOreCluster extends GeneratorOreBase
|
public class GeneratorOreCluster extends GeneratorOreBase
|
||||||
{
|
{
|
||||||
private WorldGenMinable generator;
|
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)
|
public GeneratorOreCluster(IBlockState state, int amountPerChunk, int clusterSize, int minHeight, int maxHeight)
|
||||||
{
|
{
|
||||||
|
@ -39,22 +41,12 @@ public class GeneratorOreCluster extends GeneratorOreBase
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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));
|
this.generator.oreBlock = conf.getBlockState("state", this.generator.oreBlock);
|
||||||
json.addProperty("cluster_size", this.generator.numberOfBlocks);
|
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.init.Blocks;
|
||||||
import net.minecraft.util.BlockPos;
|
import net.minecraft.util.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import biomesoplenty.common.util.config.ConfigHelper.WrappedJsonObject;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
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
|
public class GeneratorOreSingle extends GeneratorOreBase
|
||||||
{
|
{
|
||||||
private IBlockState state;
|
private IBlockState state;
|
||||||
private Predicate replace;
|
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)
|
public GeneratorOreSingle(IBlockState state, int amountPerChunk, int minHeight, int maxHeight)
|
||||||
{
|
{
|
||||||
|
@ -48,19 +50,12 @@ public class GeneratorOreSingle extends GeneratorOreBase
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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));
|
this.state = conf.getBlockState("state", this.state);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readFromJson(JsonObject json, JsonDeserializationContext context)
|
|
||||||
{
|
|
||||||
super.readFromJson(json, context);
|
|
||||||
|
|
||||||
this.state = context.deserialize(json.get("state"), IBlockState.class);
|
|
||||||
this.replace = BlockHelper.forBlock(Blocks.stone);
|
this.replace = BlockHelper.forBlock(Blocks.stone);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
package biomesoplenty.common.world.feature;
|
package biomesoplenty.common.world.feature;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
@ -18,11 +19,7 @@ import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.util.BlockPos;
|
import net.minecraft.util.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import biomesoplenty.api.biome.generation.GeneratorCustomizable;
|
import biomesoplenty.api.biome.generation.GeneratorCustomizable;
|
||||||
import biomesoplenty.common.util.biome.GeneratorUtils;
|
import biomesoplenty.common.util.config.ConfigHelper.WrappedJsonObject;
|
||||||
|
|
||||||
import com.google.gson.JsonDeserializationContext;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonSerializationContext;
|
|
||||||
|
|
||||||
public class GeneratorWaterside extends GeneratorCustomizable
|
public class GeneratorWaterside extends GeneratorCustomizable
|
||||||
{
|
{
|
||||||
|
@ -31,7 +28,11 @@ public class GeneratorWaterside extends GeneratorCustomizable
|
||||||
private IBlockState state;
|
private IBlockState state;
|
||||||
private List<IBlockState> replacedStates;
|
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)
|
public GeneratorWaterside(int amountPerChunk, int maxRadius, IBlockState state, IBlockState... replacedStates)
|
||||||
{
|
{
|
||||||
|
@ -105,20 +106,12 @@ public class GeneratorWaterside extends GeneratorCustomizable
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToJson(JsonObject json, JsonSerializationContext context)
|
public void configure(WrappedJsonObject conf)
|
||||||
{
|
{
|
||||||
json.addProperty("amount_per_chunk", this.amountPerChunk);
|
this.amountPerChunk = conf.getInt("amountPerChunk", this.amountPerChunk);
|
||||||
json.addProperty("max_radius", this.maxRadius);
|
this.maxRadius = conf.getInt("maxRadius", this.maxRadius);
|
||||||
json.add("state", context.serialize(this.state));
|
this.state = conf.getBlockState("state", this.state);
|
||||||
json.add("replaced_states", context.serialize(this.replacedStates));
|
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.api.biome.generation.GeneratorCustomizable;
|
||||||
import biomesoplenty.common.util.biome.GeneratorUtils;
|
import biomesoplenty.common.util.biome.GeneratorUtils;
|
||||||
|
import biomesoplenty.common.util.config.ConfigHelper.WrappedJsonObject;
|
||||||
import com.google.gson.JsonDeserializationContext;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonSerializationContext;
|
|
||||||
|
|
||||||
public class GeneratorBasicTree extends GeneratorCustomizable
|
public class GeneratorBasicTree extends GeneratorCustomizable
|
||||||
{
|
{
|
||||||
|
@ -39,7 +36,11 @@ public class GeneratorBasicTree extends GeneratorCustomizable
|
||||||
private IBlockState leaves;
|
private IBlockState leaves;
|
||||||
private IBlockState vine;
|
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)
|
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
|
@Override
|
||||||
public void writeToJson(JsonObject json, JsonSerializationContext context)
|
public void configure(WrappedJsonObject conf)
|
||||||
{
|
{
|
||||||
json.addProperty("amount_per_chunk", this.amountPerChunk);
|
this.amountPerChunk = conf.getInt("amountPerChunk", this.amountPerChunk);
|
||||||
json.addProperty("update_neighbours", this.updateNeighbours);
|
this.updateNeighbours = conf.getBool("updateNeighbours", this.updateNeighbours);
|
||||||
json.addProperty("min_height", this.minHeight);
|
int minHeight = conf.getInt("minHeight", this.minHeight);
|
||||||
json.addProperty("max_height", this.maxHeight);
|
int maxHeight = conf.getInt("maxHeight", 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();
|
|
||||||
|
|
||||||
Pair<Integer, Integer> heights = GeneratorUtils.validateMinMaxHeight(minHeight, maxHeight);
|
Pair<Integer, Integer> heights = GeneratorUtils.validateMinMaxHeight(minHeight, maxHeight);
|
||||||
this.minHeight = heights.getLeft();
|
this.minHeight = heights.getLeft();
|
||||||
this.maxHeight = heights.getRight();
|
this.maxHeight = heights.getRight();
|
||||||
|
|
||||||
this.log = context.deserialize(json.get("log_state"), IBlockState.class);
|
this.log = conf.getBlockState("logState", this.log);
|
||||||
this.leaves = context.deserialize(json.get("leaves_state"), IBlockState.class);
|
this.leaves = conf.getBlockState("leavesState", this.leaves);
|
||||||
this.vine = context.deserialize(json.get("vine_state"), IBlockState.class);
|
this.vine = conf.getBlockState("vineState", this.vine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,11 +23,9 @@ import net.minecraft.util.MathHelper;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import biomesoplenty.api.biome.generation.GeneratorCustomizable;
|
import biomesoplenty.api.biome.generation.GeneratorCustomizable;
|
||||||
import biomesoplenty.common.util.biome.GeneratorUtils;
|
import biomesoplenty.common.util.biome.GeneratorUtils;
|
||||||
|
import biomesoplenty.common.util.config.ConfigHelper.WrappedJsonObject;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
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
|
/*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
|
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;
|
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)
|
public GeneratorBigTree(int amountPerChunk, boolean updateNeighbours, int minHeight, int maxHeight, IBlockState log, IBlockState leaves)
|
||||||
{
|
{
|
||||||
|
@ -533,29 +535,19 @@ public class GeneratorBigTree extends GeneratorCustomizable
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToJson(JsonObject json, JsonSerializationContext context)
|
public void configure(WrappedJsonObject conf)
|
||||||
{
|
{
|
||||||
json.addProperty("amount_per_chunk", this.amountPerChunk);
|
this.amountPerChunk = conf.getInt("amountPerChunk", this.amountPerChunk);
|
||||||
json.addProperty("update_neighbours", this.updateNeighbours);
|
this.updateNeighbours = conf.getBool("updateNeighbours", this.updateNeighbours);
|
||||||
json.addProperty("min_height", this.minHeight);
|
int minHeight = conf.getInt("minHeight", this.minHeight);
|
||||||
json.addProperty("max_height", this.maxHeight);
|
int maxHeight = conf.getInt("maxHeight", 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();
|
|
||||||
|
|
||||||
Pair<Integer, Integer> heights = GeneratorUtils.validateMinMaxHeight(minHeight, maxHeight);
|
Pair<Integer, Integer> heights = GeneratorUtils.validateMinMaxHeight(minHeight, maxHeight);
|
||||||
this.minHeight = heights.getLeft();
|
this.minHeight = heights.getLeft();
|
||||||
this.maxHeight = heights.getRight();
|
this.maxHeight = heights.getRight();
|
||||||
|
|
||||||
this.log = context.deserialize(json.get("log_state"), IBlockState.class);
|
this.log = conf.getBlockState("logState", this.log);
|
||||||
this.leaves = context.deserialize(json.get("leaves_state"), IBlockState.class);
|
this.leaves = conf.getBlockState("leavesState", this.leaves);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,12 +18,8 @@ import net.minecraft.util.BlockPos;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.world.World;
|
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.api.biome.generation.GeneratorCustomizable;
|
||||||
import biomesoplenty.common.util.biome.GeneratorUtils;
|
import biomesoplenty.common.util.config.ConfigHelper.WrappedJsonObject;
|
||||||
|
|
||||||
public class GeneratorBush extends GeneratorCustomizable
|
public class GeneratorBush extends GeneratorCustomizable
|
||||||
{
|
{
|
||||||
|
@ -31,7 +27,11 @@ public class GeneratorBush extends GeneratorCustomizable
|
||||||
private IBlockState log;
|
private IBlockState log;
|
||||||
private IBlockState leaves;
|
private IBlockState leaves;
|
||||||
|
|
||||||
public GeneratorBush() {}
|
public GeneratorBush()
|
||||||
|
{
|
||||||
|
// default
|
||||||
|
this(1, Blocks.log.getDefaultState(), Blocks.leaves.getDefaultState());
|
||||||
|
}
|
||||||
|
|
||||||
public GeneratorBush(int amountPerChunk, IBlockState log, IBlockState leaves)
|
public GeneratorBush(int amountPerChunk, IBlockState log, IBlockState leaves)
|
||||||
{
|
{
|
||||||
|
@ -110,18 +110,11 @@ public class GeneratorBush extends GeneratorCustomizable
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToJson(JsonObject json, JsonSerializationContext context)
|
public void configure(WrappedJsonObject conf)
|
||||||
{
|
{
|
||||||
json.addProperty("amount_per_chunk", this.amountPerChunk);
|
this.amountPerChunk = conf.getInt("amountPerChunk", this.amountPerChunk);
|
||||||
json.add("log_state", context.serialize(this.log));
|
this.log = conf.getBlockState("logState", this.log);
|
||||||
json.add("leaves_state", context.serialize(this.leaves));
|
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