Added the basis for configurable biomes along with files for all the Vanilla biomes (Note: This may or may not stay for the full release, BoP biomes will certainly be configurable however Vanilla biomes have limitations)

This commit is contained in:
Adubbz 2014-12-01 08:49:47 +11:00
parent 9786bfe200
commit 8af3d66c95
21 changed files with 434 additions and 37 deletions

View file

@ -11,7 +11,6 @@ package biomesoplenty.api.block;
import java.util.Collection;
import java.util.List;
import biomesoplenty.api.IConfigurable;
import biomesoplenty.common.util.inventory.CreativeTabBOP;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
@ -23,7 +22,7 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public abstract class BOPBlock extends Block implements IConfigurable
public abstract class BOPBlock extends Block
{
private final PropertyEnum variantProperty;
@ -77,20 +76,6 @@ public abstract class BOPBlock extends Block implements IConfigurable
{
return this.getMetaFromState(state);
}
@Override
//TODO: Account for configurations (which are provided by Forge and thus, cannot be done at this time)
public boolean isEnabled(Object... args)
{
if (args[0] instanceof IBlockState)
{
IBlockState blockState = (IBlockState)args[0];
return true;
}
return false;
}
public final boolean hasVariants()
{

View file

@ -14,7 +14,6 @@ import java.util.HashMap;
import com.google.common.collect.Lists;
import biomesoplenty.api.block.BOPBlock;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BlockModelShapes;

View file

@ -34,7 +34,6 @@ import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import biomesoplenty.api.block.BOPBlock;
import biomesoplenty.api.block.BOPPlant;
import biomesoplenty.api.block.IBOPVariant;
import biomesoplenty.common.util.inventory.CreativeTabBOP;

View file

@ -8,6 +8,8 @@
package biomesoplenty.common.block;
import biomesoplenty.api.block.BOPPlant;
import biomesoplenty.api.block.IBOPVariant;
import net.minecraft.block.Block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
@ -17,8 +19,6 @@ import net.minecraft.init.Blocks;
import net.minecraft.util.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import biomesoplenty.api.block.BOPPlant;
import biomesoplenty.api.block.IBOPVariant;
public class BlockBOPFlower2 extends BOPPlant
{

View file

@ -8,8 +8,8 @@
package biomesoplenty.common.block;
import net.minecraft.block.material.Material;
import biomesoplenty.api.block.BOPBlock;
import net.minecraft.block.material.Material;
public abstract class BlockBOPLeavesBase extends BOPBlock
{

View file

@ -14,7 +14,7 @@ import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumFacing;
import biomesoplenty.api.block.IBOPVariant;
import biomesoplenty.common.block.BOPBlockPlanks.PlankType;
import biomesoplenty.common.block.BlockBOPPlanks.PlankType;
public class BlockBOPLog extends BlockBOPLogBase
{

View file

@ -8,12 +8,12 @@
package biomesoplenty.common.block;
import biomesoplenty.api.block.IBOPVariant;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumFacing;
import biomesoplenty.api.block.IBOPVariant;
public class BlockBOPLog2 extends BlockBOPLogBase
{

View file

@ -8,12 +8,12 @@
package biomesoplenty.common.block;
import biomesoplenty.api.block.IBOPVariant;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumFacing;
import biomesoplenty.api.block.IBOPVariant;
public class BlockBOPLog3 extends BlockBOPLogBase
{

View file

@ -8,12 +8,12 @@
package biomesoplenty.common.block;
import biomesoplenty.api.block.IBOPVariant;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumFacing;
import biomesoplenty.api.block.IBOPVariant;
public class BlockBOPLog4 extends BlockBOPLogBase
{

View file

@ -8,6 +8,8 @@
package biomesoplenty.common.block;
import biomesoplenty.api.block.BOPPlant;
import biomesoplenty.api.block.IBOPVariant;
import net.minecraft.block.Block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
@ -17,8 +19,6 @@ import net.minecraft.init.Blocks;
import net.minecraft.util.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import biomesoplenty.api.block.BOPPlant;
import biomesoplenty.api.block.IBOPVariant;
public class BlockBOPMushroom extends BOPPlant
{

View file

@ -20,11 +20,11 @@ import biomesoplenty.api.block.IBOPVariant;
import biomesoplenty.common.util.inventory.CreativeTabBOP;
//TODO: Commented methods and calls
public class BOPBlockPlanks extends BOPBlock
public class BlockBOPPlanks extends BOPBlock
{
public static PropertyEnum VARIANT_PROP = PropertyEnum.create("variant", PlankType.class);
public BOPBlockPlanks()
public BlockBOPPlanks()
{
super(Material.wood, VARIANT_PROP);

View file

@ -8,6 +8,7 @@
package biomesoplenty.common.block;
import biomesoplenty.api.block.BOPPlant;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
@ -16,7 +17,6 @@ import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import biomesoplenty.api.block.BOPPlant;
//TODO: Reimplement IPlantable interface (Requires Forge)
public class BlockBamboo extends BOPPlant

View file

@ -0,0 +1,136 @@
/*******************************************************************************
* 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.config;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map.Entry;
import org.apache.commons.io.FileUtils;
import com.google.gson.JsonSyntaxException;
import biomesoplenty.common.util.config.JsonBiome;
import biomesoplenty.common.util.config.JsonEntitySpawn;
import net.minecraft.world.biome.BiomeGenBase;
public class BiomeConfigurationHandler
{
private static HashMap<BiomeGenBase, String> configFileMap = new HashMap();
public static void init(File configDirectory)
{
registerConfigurableBiomes();
load(configDirectory);
}
private static void registerConfigurableBiomes()
{
registerConfigurableBiome(BiomeGenBase.ocean, "ocean");
registerConfigurableBiome(BiomeGenBase.plains, "plains");
registerConfigurableBiome(BiomeGenBase.desert, "desert");
registerConfigurableBiome(BiomeGenBase.extremeHills, "extremeHills");
registerConfigurableBiome(BiomeGenBase.forest, "forest");
registerConfigurableBiome(BiomeGenBase.taiga, "taiga");
registerConfigurableBiome(BiomeGenBase.swampland, "swampland");
registerConfigurableBiome(BiomeGenBase.river, "river");
registerConfigurableBiome(BiomeGenBase.hell, "hell");
registerConfigurableBiome(BiomeGenBase.sky, "sky");
registerConfigurableBiome(BiomeGenBase.frozenOcean, "frozenOcean");
registerConfigurableBiome(BiomeGenBase.frozenRiver, "frozenRiver");
registerConfigurableBiome(BiomeGenBase.icePlains, "icePlains");
registerConfigurableBiome(BiomeGenBase.iceMountains, "iceMountains");
registerConfigurableBiome(BiomeGenBase.mushroomIsland, "mushroomIsland");
registerConfigurableBiome(BiomeGenBase.mushroomIslandShore, "mushroomIslandShore");
registerConfigurableBiome(BiomeGenBase.beach, "beach");
registerConfigurableBiome(BiomeGenBase.desertHills, "beachHills");
registerConfigurableBiome(BiomeGenBase.forestHills, "forestHills");
registerConfigurableBiome(BiomeGenBase.taigaHills, "taigaHills");
registerConfigurableBiome(BiomeGenBase.extremeHillsEdge, "extremeHillsEdge");
registerConfigurableBiome(BiomeGenBase.jungle, "jungle");
registerConfigurableBiome(BiomeGenBase.jungleHills, "jungleHills");
registerConfigurableBiome(BiomeGenBase.jungleEdge, "jungleEdge");
registerConfigurableBiome(BiomeGenBase.deepOcean, "deepOcean");
registerConfigurableBiome(BiomeGenBase.stoneBeach, "stoneBeach");
registerConfigurableBiome(BiomeGenBase.coldBeach, "coldBeach");
registerConfigurableBiome(BiomeGenBase.birchForest, "birchForest");
registerConfigurableBiome(BiomeGenBase.birchForestHills, "birchForestHills");
registerConfigurableBiome(BiomeGenBase.roofedForest, "roofedForest");
registerConfigurableBiome(BiomeGenBase.coldTaiga, "coldTaiga");
registerConfigurableBiome(BiomeGenBase.coldTaigaHills, "coldTaigaHills");
registerConfigurableBiome(BiomeGenBase.megaTaiga, "megaTaiga");
registerConfigurableBiome(BiomeGenBase.megaTaigaHills, "megaTaigaHills");
registerConfigurableBiome(BiomeGenBase.extremeHillsPlus, "extremeHillsPlus");
registerConfigurableBiome(BiomeGenBase.savanna, "savanna");
registerConfigurableBiome(BiomeGenBase.savannaPlateau, "savannaPlateau");
registerConfigurableBiome(BiomeGenBase.mesa, "mesa");
registerConfigurableBiome(BiomeGenBase.mesaPlateau_F, "mesaPlatea_F");
registerConfigurableBiome(BiomeGenBase.mesaPlateau, "mesaPlateau");
}
private static void load(File configDirectory)
{
for (Entry<BiomeGenBase, String> entry : configFileMap.entrySet())
{
BiomeGenBase biome = entry.getKey();
String configFileName = entry.getValue();
File configFile = new File(configDirectory, configFileName + ".json");
if (configFile.exists())
{
try
{
JsonBiome jsonBiome = JsonBiome.serializer.fromJson(FileUtils.readFileToString(configFile), JsonBiome.class);
configureBiomeWithJson(biome, jsonBiome);
}
catch (JsonSyntaxException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
else
{
try
{
FileUtils.write(configFile, JsonBiome.serializer.toJson(JsonBiome.createFromBiomeGenBase(biome), JsonBiome.class));
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}
public static void registerConfigurableBiome(BiomeGenBase biome, String configFileName)
{
configFileMap.put(biome, configFileName);
}
private static void configureBiomeWithJson(BiomeGenBase biome, JsonBiome jsonBiome)
{
//TODO: Reflect and modify biome id biome.biomeId = jsonBiome.biomeID;
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);
}
}

View file

@ -15,7 +15,6 @@ import net.minecraft.item.Item;
import net.minecraftforge.fml.common.registry.GameRegistry;
import biomesoplenty.api.block.BOPBlock;
import biomesoplenty.api.block.IBOPVariant;
import biomesoplenty.common.block.BOPBlockPlanks;
import biomesoplenty.common.block.BlockAsh;
import biomesoplenty.common.block.BlockBOPFlower;
import biomesoplenty.common.block.BlockBOPFlower2;
@ -24,6 +23,7 @@ import biomesoplenty.common.block.BlockBOPLog2;
import biomesoplenty.common.block.BlockBOPLog3;
import biomesoplenty.common.block.BlockBOPLog4;
import biomesoplenty.common.block.BlockBOPMushroom;
import biomesoplenty.common.block.BlockBOPPlanks;
import biomesoplenty.common.block.BlockBamboo;
import biomesoplenty.common.item.ItemBlockWithVariants;
import biomesoplenty.core.BiomesOPlenty;
@ -41,7 +41,7 @@ public class ModBlocks
log3 = registerBlock(new BlockBOPLog3(), "log3");
log4 = registerBlock(new BlockBOPLog4(), "log4");
mushroom = registerBlock(new BlockBOPMushroom(), "mushroom");
planks = registerBlock(new BOPBlockPlanks(), "planks");
planks = registerBlock(new BlockBOPPlanks(), "planks");
}
private static Block registerBlock(BOPBlock block, String name)

View file

@ -6,9 +6,16 @@
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
******************************************************************************/
package biomesoplenty.api;
package biomesoplenty.common.init;
public interface IConfigurable
import java.io.File;
import biomesoplenty.common.config.BiomeConfigurationHandler;
public class ModConfiguration
{
boolean isEnabled(Object... args);
public static void init(File configDirectory)
{
BiomeConfigurationHandler.init(new File(configDirectory, "biomes"));
}
}

View file

@ -8,10 +8,10 @@
package biomesoplenty.common.item;
import biomesoplenty.api.block.BOPBlock;
import net.minecraft.block.Block;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import biomesoplenty.api.block.BOPBlock;
public class ItemBlockWithVariants extends ItemBlock
{

View file

@ -0,0 +1,42 @@
/*******************************************************************************
* 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.block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
import com.google.common.collect.ImmutableSet;
public class BlockStateUtils
{
public static IProperty getPropertyByName(IBlockState blockState, String propertyName)
{
for (IProperty property : (ImmutableSet<IProperty>)blockState.getProperties().keySet())
{
if (property.getName().equals(propertyName)) return property;
}
return null;
}
public static boolean isValidPropertyName(IBlockState blockState, String propertyName)
{
return getPropertyByName(blockState, propertyName) != null;
}
public static Comparable getPropertyValueByName(IBlockState blockState, IProperty property, String valueName)
{
for (Comparable value : (ImmutableSet<Comparable>)property.getAllowedValues())
{
if (value.toString().equals(valueName)) return value;
}
return null;
}
}

View file

@ -0,0 +1,53 @@
/*******************************************************************************
* 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 net.minecraft.block.state.IBlockState;
import net.minecraft.world.biome.BiomeGenBase;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public class JsonBiome
{
public static final Gson serializer = new GsonBuilder().setPrettyPrinting().registerTypeAdapter(IBlockState.class, new JsonBlockState()).create();
public String biomeName;
public int biomeId;
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 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);
return biome;
}
}

View file

@ -0,0 +1,102 @@
/*******************************************************************************
* 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.Gson;
import com.google.gson.GsonBuilder;
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 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());
}
}

View file

@ -0,0 +1,73 @@
/*******************************************************************************
* 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)
{
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();
}
}
}
}

View file

@ -18,6 +18,7 @@ import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import biomesoplenty.common.init.ModBlocks;
import biomesoplenty.common.init.ModConfiguration;
import biomesoplenty.common.init.ModItems;
@Mod(modid = BiomesOPlenty.MOD_ID, name = BiomesOPlenty.MOD_NAME)
@ -39,7 +40,7 @@ public class BiomesOPlenty
{
configDirectory = new File(event.getModConfigurationDirectory(), "biomesoplenty");
//TODO: ModConfiguration.load();
ModConfiguration.init(configDirectory);
ModItems.init();
ModBlocks.init();
}