Began work on a system for configurable biome decoration

This commit is contained in:
Adubbz 2015-01-14 21:34:24 +11:00
parent 6363c1c642
commit 1847f46548
7 changed files with 205 additions and 31 deletions

View file

@ -0,0 +1,15 @@
/*******************************************************************************
* 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.api.biome;
public enum BiomeOwner
{
BIOMESOPLENTY,
OTHER;
}

View file

@ -0,0 +1,34 @@
/*******************************************************************************
* 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.api.biome;
public enum BiomeProperty
{
GRASS_PER_CHUNK(1),
FLOWERS_PER_CHUNK(2);
private Object defaultValue;
private BiomeProperty() {}
private BiomeProperty(Object defaultValue)
{
this.defaultValue = defaultValue;
}
public String getName()
{
return this.name().toLowerCase();
}
public Object getDefaultValue()
{
return this.defaultValue;
}
}

View file

@ -0,0 +1,19 @@
/*******************************************************************************
* 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.api.biome;
import java.util.Map;
public interface IExtendedBiome
{
public BiomeOwner getBiomeOwner();
public void setProperty(BiomeProperty property, Object value);
public Object getProperty(BiomeProperty property);
public Map<BiomeProperty, Object> getPropertyMap();
}

View file

@ -13,13 +13,17 @@ import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map.Entry; import java.util.Map.Entry;
import net.minecraft.world.biome.BiomeGenBase;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import com.google.gson.JsonSyntaxException; import biomesoplenty.api.biome.BiomeOwner;
import biomesoplenty.api.biome.BiomeProperty;
import biomesoplenty.api.biome.IExtendedBiome;
import biomesoplenty.common.util.config.JsonBiome; import biomesoplenty.common.util.config.JsonBiome;
import biomesoplenty.common.util.config.JsonEntitySpawn; import biomesoplenty.common.util.config.JsonEntitySpawn;
import net.minecraft.world.biome.BiomeGenBase;
import com.google.gson.JsonSyntaxException;
public class BiomeConfigurationHandler public class BiomeConfigurationHandler
{ {
@ -36,43 +40,43 @@ public class BiomeConfigurationHandler
registerConfigurableBiome(BiomeGenBase.ocean, "ocean"); registerConfigurableBiome(BiomeGenBase.ocean, "ocean");
registerConfigurableBiome(BiomeGenBase.plains, "plains"); registerConfigurableBiome(BiomeGenBase.plains, "plains");
registerConfigurableBiome(BiomeGenBase.desert, "desert"); registerConfigurableBiome(BiomeGenBase.desert, "desert");
registerConfigurableBiome(BiomeGenBase.extremeHills, "extremeHills"); registerConfigurableBiome(BiomeGenBase.extremeHills, "extreme_hills");
registerConfigurableBiome(BiomeGenBase.forest, "forest"); registerConfigurableBiome(BiomeGenBase.forest, "forest");
registerConfigurableBiome(BiomeGenBase.taiga, "taiga"); registerConfigurableBiome(BiomeGenBase.taiga, "taiga");
registerConfigurableBiome(BiomeGenBase.swampland, "swampland"); registerConfigurableBiome(BiomeGenBase.swampland, "swampland");
registerConfigurableBiome(BiomeGenBase.river, "river"); registerConfigurableBiome(BiomeGenBase.river, "river");
registerConfigurableBiome(BiomeGenBase.hell, "hell"); registerConfigurableBiome(BiomeGenBase.hell, "hell");
registerConfigurableBiome(BiomeGenBase.sky, "sky"); registerConfigurableBiome(BiomeGenBase.sky, "sky");
registerConfigurableBiome(BiomeGenBase.frozenOcean, "frozenOcean"); registerConfigurableBiome(BiomeGenBase.frozenOcean, "frozen_ocean");
registerConfigurableBiome(BiomeGenBase.frozenRiver, "frozenRiver"); registerConfigurableBiome(BiomeGenBase.frozenRiver, "frozen_river");
registerConfigurableBiome(BiomeGenBase.icePlains, "icePlains"); registerConfigurableBiome(BiomeGenBase.icePlains, "ice_plains");
registerConfigurableBiome(BiomeGenBase.iceMountains, "iceMountains"); registerConfigurableBiome(BiomeGenBase.iceMountains, "ice_mountains");
registerConfigurableBiome(BiomeGenBase.mushroomIsland, "mushroomIsland"); registerConfigurableBiome(BiomeGenBase.mushroomIsland, "mushroom_island");
registerConfigurableBiome(BiomeGenBase.mushroomIslandShore, "mushroomIslandShore"); registerConfigurableBiome(BiomeGenBase.mushroomIslandShore, "mushroom_island_shore");
registerConfigurableBiome(BiomeGenBase.beach, "beach"); registerConfigurableBiome(BiomeGenBase.beach, "beach");
registerConfigurableBiome(BiomeGenBase.desertHills, "beachHills"); registerConfigurableBiome(BiomeGenBase.desertHills, "beach_hills");
registerConfigurableBiome(BiomeGenBase.forestHills, "forestHills"); registerConfigurableBiome(BiomeGenBase.forestHills, "forest_hills");
registerConfigurableBiome(BiomeGenBase.taigaHills, "taigaHills"); registerConfigurableBiome(BiomeGenBase.taigaHills, "taiga_hills");
registerConfigurableBiome(BiomeGenBase.extremeHillsEdge, "extremeHillsEdge"); registerConfigurableBiome(BiomeGenBase.extremeHillsEdge, "extreme_hills_edge");
registerConfigurableBiome(BiomeGenBase.jungle, "jungle"); registerConfigurableBiome(BiomeGenBase.jungle, "jungle");
registerConfigurableBiome(BiomeGenBase.jungleHills, "jungleHills"); registerConfigurableBiome(BiomeGenBase.jungleHills, "jungle_hills");
registerConfigurableBiome(BiomeGenBase.jungleEdge, "jungleEdge"); registerConfigurableBiome(BiomeGenBase.jungleEdge, "jungle_edge");
registerConfigurableBiome(BiomeGenBase.deepOcean, "deepOcean"); registerConfigurableBiome(BiomeGenBase.deepOcean, "deep_ocean");
registerConfigurableBiome(BiomeGenBase.stoneBeach, "stoneBeach"); registerConfigurableBiome(BiomeGenBase.stoneBeach, "stone_beach");
registerConfigurableBiome(BiomeGenBase.coldBeach, "coldBeach"); registerConfigurableBiome(BiomeGenBase.coldBeach, "cold_beach");
registerConfigurableBiome(BiomeGenBase.birchForest, "birchForest"); registerConfigurableBiome(BiomeGenBase.birchForest, "birch_forest");
registerConfigurableBiome(BiomeGenBase.birchForestHills, "birchForestHills"); registerConfigurableBiome(BiomeGenBase.birchForestHills, "birch_forest_hills");
registerConfigurableBiome(BiomeGenBase.roofedForest, "roofedForest"); registerConfigurableBiome(BiomeGenBase.roofedForest, "roofed_forest");
registerConfigurableBiome(BiomeGenBase.coldTaiga, "coldTaiga"); registerConfigurableBiome(BiomeGenBase.coldTaiga, "cold_taiga");
registerConfigurableBiome(BiomeGenBase.coldTaigaHills, "coldTaigaHills"); registerConfigurableBiome(BiomeGenBase.coldTaigaHills, "cold_taiga_hills");
registerConfigurableBiome(BiomeGenBase.megaTaiga, "megaTaiga"); registerConfigurableBiome(BiomeGenBase.megaTaiga, "mega_taiga");
registerConfigurableBiome(BiomeGenBase.megaTaigaHills, "megaTaigaHills"); registerConfigurableBiome(BiomeGenBase.megaTaigaHills, "mega_taiga_hills");
registerConfigurableBiome(BiomeGenBase.extremeHillsPlus, "extremeHillsPlus"); registerConfigurableBiome(BiomeGenBase.extremeHillsPlus, "extreme_hills_plus");
registerConfigurableBiome(BiomeGenBase.savanna, "savanna"); registerConfigurableBiome(BiomeGenBase.savanna, "savanna");
registerConfigurableBiome(BiomeGenBase.savannaPlateau, "savannaPlateau"); registerConfigurableBiome(BiomeGenBase.savannaPlateau, "savanna_plateau");
registerConfigurableBiome(BiomeGenBase.mesa, "mesa"); registerConfigurableBiome(BiomeGenBase.mesa, "mesa");
registerConfigurableBiome(BiomeGenBase.mesaPlateau_F, "mesaPlatea_F"); registerConfigurableBiome(BiomeGenBase.mesaPlateau_F, "mesa_plateau_f");
registerConfigurableBiome(BiomeGenBase.mesaPlateau, "mesaPlateau"); registerConfigurableBiome(BiomeGenBase.mesaPlateau, "mesa_plateau");
} }
private static void load(File configDirectory) private static void load(File configDirectory)
@ -116,9 +120,24 @@ public class BiomeConfigurationHandler
public static void registerConfigurableBiome(BiomeGenBase biome, String configFileName) public static void registerConfigurableBiome(BiomeGenBase biome, String configFileName)
{ {
translateVanillaValues(biome);
configFileMap.put(biome, configFileName); configFileMap.put(biome, configFileName);
} }
private static void translateVanillaValues(BiomeGenBase biome)
{
IExtendedBiome extendedBiome = (IExtendedBiome)biome;
if (extendedBiome.getBiomeOwner() == BiomeOwner.OTHER)
{
extendedBiome.setProperty(BiomeProperty.GRASS_PER_CHUNK, biome.theBiomeDecorator.grassPerChunk);
//TODO: Create our own implementations
//biome.theBiomeDecorator.grassPerChunk = 0;
extendedBiome.setProperty(BiomeProperty.FLOWERS_PER_CHUNK, biome.theBiomeDecorator.flowersPerChunk);
//biome.theBiomeDecorator.flowersPerChunk = 0;
}
}
private static void configureBiomeWithJson(BiomeGenBase biome, JsonBiome jsonBiome) private static void configureBiomeWithJson(BiomeGenBase biome, JsonBiome jsonBiome)
{ {
//TODO: Reflect and modify biome id biome.biomeId = jsonBiome.biomeID; //TODO: Reflect and modify biome id biome.biomeId = jsonBiome.biomeID;
@ -132,5 +151,21 @@ public class BiomeConfigurationHandler
biome.color = jsonBiome.color; biome.color = jsonBiome.color;
biome.waterColorMultiplier = jsonBiome.waterColorMultiplier; biome.waterColorMultiplier = jsonBiome.waterColorMultiplier;
JsonEntitySpawn.addBiomeEntitySpawns(biome, jsonBiome); JsonEntitySpawn.addBiomeEntitySpawns(biome, jsonBiome);
IExtendedBiome extendedBiome = (IExtendedBiome)biome;
if (!jsonBiome.decorationProperties.isEmpty())
{
for (Entry<BiomeProperty, Object> entry : jsonBiome.decorationProperties.entrySet())
{
BiomeProperty property = entry.getKey();
Object value = entry.getValue();
if (property != null)
{
extendedBiome.setProperty(property, value);
}
}
}
} }
} }

View file

@ -0,0 +1,62 @@
/*******************************************************************************
* 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.mixin.biome;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.world.biome.BiomeGenBase;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import biomesoplenty.api.biome.BiomeOwner;
import biomesoplenty.api.biome.BiomeProperty;
import biomesoplenty.api.biome.IExtendedBiome;
@Mixin(BiomeGenBase.class)
public abstract class MixinBiomeGenBase implements IExtendedBiome
{
private BiomeOwner biomeOwner;
private HashMap<BiomeProperty, Object> properties;
@Inject(method = "<init>(IZ)V", at = @At("RETURN"))
private void onConstructed(int biomeId, boolean register, CallbackInfo callbackInfo)
{
this.biomeOwner = BiomeOwner.OTHER;
this.properties = new HashMap();
}
@Override
public BiomeOwner getBiomeOwner()
{
return biomeOwner;
}
@Override
public void setProperty(BiomeProperty property, Object value)
{
if (property.getDefaultValue() != value)
this.properties.put(property, value);
}
@Override
public Object getProperty(BiomeProperty property)
{
return this.properties.get(property);
}
@Override
public Map<BiomeProperty, Object> getPropertyMap()
{
return properties;
}
}

View file

@ -9,16 +9,22 @@
package biomesoplenty.common.util.config; package biomesoplenty.common.util.config;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Map;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.world.biome.BiomeGenBase; import net.minecraft.world.biome.BiomeGenBase;
import biomesoplenty.api.biome.BiomeProperty;
import biomesoplenty.api.biome.IExtendedBiome;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
public class JsonBiome public class JsonBiome
{ {
public static final Gson serializer = new GsonBuilder().setPrettyPrinting().registerTypeAdapter(IBlockState.class, new JsonBlockState()).create(); public static final Gson serializer = new GsonBuilder()
.setPrettyPrinting().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.registerTypeAdapter(IBlockState.class, new JsonBlockState()).create();
public String biomeName; public String biomeName;
public int biomeId; public int biomeId;
@ -31,6 +37,7 @@ public class JsonBiome
public int color; public int color;
public int waterColorMultiplier; public int waterColorMultiplier;
public ArrayList<JsonEntitySpawn> entities; public ArrayList<JsonEntitySpawn> entities;
public Map<BiomeProperty, Object> decorationProperties;
public static JsonBiome createFromBiomeGenBase(BiomeGenBase baseBiome) public static JsonBiome createFromBiomeGenBase(BiomeGenBase baseBiome)
{ {
@ -47,6 +54,7 @@ public class JsonBiome
biome.color = baseBiome.color; biome.color = baseBiome.color;
biome.waterColorMultiplier = baseBiome.waterColorMultiplier; biome.waterColorMultiplier = baseBiome.waterColorMultiplier;
biome.entities = JsonEntitySpawn.getBiomeEntitySpawns(baseBiome); biome.entities = JsonEntitySpawn.getBiomeEntitySpawns(baseBiome);
biome.decorationProperties = ((IExtendedBiome)baseBiome).getPropertyMap();
return biome; return biome;
} }

View file

@ -1,6 +1,7 @@
{ {
"package": "biomesoplenty.common.mixin", "package": "biomesoplenty.common.mixin",
"mixins": [ "mixins": [
"biome.MixinBiomeGenBase",
"renderer.MixinBlockModelShapes" "renderer.MixinBlockModelShapes"
] ]
} }