Fixed handling for Vanilla biome extensions, added crystals to the end and prevented our generation from spawning in the default world type
This commit is contained in:
parent
d51c6d1305
commit
38cd1655e1
14 changed files with 407 additions and 130 deletions
|
@ -72,6 +72,7 @@ public class BOPBiome extends BiomeGenBase implements IExtendedBiome
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(IConfigObj conf)
|
||||
{
|
||||
|
||||
|
@ -347,5 +348,9 @@ public class BOPBiome extends BiomeGenBase implements IExtendedBiome
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BiomeGenBase getBaseBiome()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@ import net.minecraft.world.biome.BiomeGenBase;
|
|||
|
||||
public class BOPBiomes
|
||||
{
|
||||
public static final IBiomeRegistry REG_INSTANCE = createRegistry();
|
||||
|
||||
// normal biomes which have weights
|
||||
public static Optional<BiomeGenBase> alps = Optional.absent();
|
||||
public static Optional<BiomeGenBase> arctic = Optional.absent();
|
||||
|
@ -63,4 +65,28 @@ public class BOPBiomes
|
|||
public static Optional<BiomeGenBase> mountain_foothills = Optional.absent();
|
||||
public static Optional<BiomeGenBase> canyon_ravine = Optional.absent();
|
||||
|
||||
//Biome extensions
|
||||
public static IExtendedBiome end_extension;
|
||||
|
||||
private static IBiomeRegistry createRegistry()
|
||||
{
|
||||
IBiomeRegistry instance = null;
|
||||
|
||||
try
|
||||
{
|
||||
instance = (IBiomeRegistry)Class.forName("biomesoplenty.common.init.ModBiomes").newInstance();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static interface IBiomeRegistry
|
||||
{
|
||||
public IExtendedBiome registerBiome(IExtendedBiome biome, String idName);
|
||||
public IExtendedBiome getExtendedBiome(BiomeGenBase biome);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
package biomesoplenty.api.biome;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import biomesoplenty.api.biome.generation.GenerationManager;
|
||||
import biomesoplenty.api.biome.generation.GeneratorStage;
|
||||
import biomesoplenty.api.biome.generation.IGenerator;
|
||||
import biomesoplenty.common.enums.BOPClimates;
|
||||
import biomesoplenty.common.util.config.BOPConfig.IConfigObj;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
|
||||
public class ExtendedBiomeWrapper implements IExtendedBiome
|
||||
{
|
||||
public final BiomeGenBase biome;
|
||||
private GenerationManager generationManager = new GenerationManager();
|
||||
private Map<BOPClimates, Integer> weightMap = new HashMap<BOPClimates, Integer>();
|
||||
|
||||
public ExtendedBiomeWrapper(BiomeGenBase biome)
|
||||
{
|
||||
this.biome = biome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(IConfigObj conf)
|
||||
{
|
||||
// Allow generators to be configured
|
||||
IConfigObj confGenerators = conf.getObject("generators");
|
||||
if (confGenerators != null)
|
||||
{
|
||||
for (String name : confGenerators.getKeys())
|
||||
{
|
||||
this.generationManager.configureWith(name, confGenerators.getObject(name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeOwner getBiomeOwner()
|
||||
{
|
||||
return BiomeOwner.OTHER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGenerator(String name, GeneratorStage stage, IGenerator generator)
|
||||
{
|
||||
this.generationManager.addGenerator(name, stage, generator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenerationManager getGenerationManager()
|
||||
{
|
||||
return this.generationManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<BOPClimates, Integer> getWeightMap()
|
||||
{
|
||||
return this.weightMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addWeight(BOPClimates climate, int weight)
|
||||
{
|
||||
this.weightMap.put(climate, weight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearWeights()
|
||||
{
|
||||
this.weightMap.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeGenBase getBaseBiome()
|
||||
{
|
||||
return this.biome;
|
||||
}
|
||||
}
|
|
@ -14,13 +14,20 @@ import biomesoplenty.api.biome.generation.GenerationManager;
|
|||
import biomesoplenty.api.biome.generation.GeneratorStage;
|
||||
import biomesoplenty.api.biome.generation.IGenerator;
|
||||
import biomesoplenty.common.enums.BOPClimates;
|
||||
import biomesoplenty.common.util.config.BOPConfig.IConfigObj;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
|
||||
public interface IExtendedBiome
|
||||
{
|
||||
public void configure(IConfigObj conf);
|
||||
|
||||
public BiomeOwner getBiomeOwner();
|
||||
public void addGenerator(String name, GeneratorStage stage, IGenerator generator);
|
||||
public GenerationManager getGenerationManager();
|
||||
public Map<BOPClimates, Integer> getWeightMap();
|
||||
public void clearWeights();
|
||||
public void addWeight(BOPClimates climate, int weight);
|
||||
|
||||
/**Get the base biome associated with this extension**/
|
||||
public BiomeGenBase getBaseBiome();
|
||||
}
|
||||
|
|
|
@ -49,7 +49,11 @@ public enum GeneratorStage
|
|||
@SerializedName("post")
|
||||
POST(null),
|
||||
@SerializedName("parent")
|
||||
PARENT(null);
|
||||
PARENT(null),
|
||||
@SerializedName("ore_pre")
|
||||
ORE_PRE(null),
|
||||
@SerializedName("ore_post")
|
||||
ORE_POST(null);
|
||||
|
||||
private Decorate.EventType decorateType;
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ public interface IGenerator
|
|||
public void setStage(GeneratorStage stage);
|
||||
public void setName(String name);
|
||||
|
||||
/**A unique name use to classify the purpose of a generator. For example, emeralds and ruby use the
|
||||
/**A unique name used to classify the purpose of a generator. For example, emeralds and ruby use the
|
||||
* same generator (and thus, have the same identifier) but have differing names.
|
||||
*/
|
||||
public String getName();
|
||||
|
|
|
@ -1,97 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 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.biome;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import biomesoplenty.api.biome.BiomeOwner;
|
||||
import biomesoplenty.api.biome.IExtendedBiome;
|
||||
import biomesoplenty.api.biome.generation.GenerationManager;
|
||||
import biomesoplenty.api.biome.generation.GeneratorStage;
|
||||
import biomesoplenty.api.biome.generation.IGenerator;
|
||||
import biomesoplenty.common.enums.BOPClimates;
|
||||
|
||||
public class ExtendedBiomeRegistry
|
||||
{
|
||||
private static Map<BiomeGenBase, BiomeExtension> externalExtensions = new HashMap();
|
||||
|
||||
public static boolean isRegistered(BiomeGenBase biome)
|
||||
{
|
||||
return biome.biomeID != -1;
|
||||
}
|
||||
|
||||
public static BiomeExtension createExtension(BiomeGenBase biome)
|
||||
{
|
||||
return externalExtensions.put(biome, new BiomeExtension(biome));
|
||||
}
|
||||
|
||||
public static IExtendedBiome getExtension(BiomeGenBase biome)
|
||||
{
|
||||
if (biome instanceof IExtendedBiome)
|
||||
{
|
||||
return (IExtendedBiome)biome;
|
||||
}
|
||||
else if (externalExtensions.containsKey(biome))
|
||||
{
|
||||
return externalExtensions.get(biome);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class BiomeExtension implements IExtendedBiome
|
||||
{
|
||||
public final BiomeGenBase biome;
|
||||
private GenerationManager generationManager = new GenerationManager();
|
||||
private Map<BOPClimates, Integer> weightMap = new HashMap<BOPClimates, Integer>();
|
||||
|
||||
private BiomeExtension(BiomeGenBase biome)
|
||||
{
|
||||
this.biome = biome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeOwner getBiomeOwner()
|
||||
{
|
||||
return BiomeOwner.OTHER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGenerator(String name, GeneratorStage stage, IGenerator generator)
|
||||
{
|
||||
this.generationManager.addGenerator(name, stage, generator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenerationManager getGenerationManager()
|
||||
{
|
||||
return this.generationManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<BOPClimates, Integer> getWeightMap()
|
||||
{
|
||||
return this.weightMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addWeight(BOPClimates climate, int weight)
|
||||
{
|
||||
this.weightMap.put(climate, weight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearWeights()
|
||||
{
|
||||
this.weightMap.clear();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package biomesoplenty.common.biome.vanilla;
|
||||
|
||||
import biomesoplenty.api.biome.ExtendedBiomeWrapper;
|
||||
import biomesoplenty.api.biome.generation.GeneratorStage;
|
||||
import biomesoplenty.api.block.BOPBlocks;
|
||||
import biomesoplenty.api.block.BlockQueries;
|
||||
import biomesoplenty.common.world.feature.GeneratorCrystals;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
|
||||
public class BiomeExtEnd extends ExtendedBiomeWrapper
|
||||
{
|
||||
public BiomeExtEnd()
|
||||
{
|
||||
super(BiomeGenBase.sky);
|
||||
|
||||
this.addGenerator("crystals", GeneratorStage.ORE_PRE, (new GeneratorCrystals.Builder()).amountPerChunk(6.0F).placeOn(BlockQueries.endish).with(BOPBlocks.crystal.getDefaultState()).create());
|
||||
}
|
||||
}
|
|
@ -17,8 +17,12 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.boss.EntityDragon;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
public class BlockBOPCrystal extends Block implements IBOPBlock
|
||||
{
|
||||
|
@ -44,6 +48,18 @@ public class BlockBOPCrystal extends Block implements IBOPBlock
|
|||
this.setStepSound(Block.soundTypeGlass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canEntityDestroy(IBlockAccess world, BlockPos pos, Entity entity)
|
||||
{
|
||||
//Prevent the ender dragon from destroying this block
|
||||
if (entity instanceof EntityDragon)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getItemDropped(IBlockState state, Random rand, int fortune)
|
||||
{
|
||||
|
|
|
@ -10,31 +10,39 @@ package biomesoplenty.common.handler.decoration;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraftforge.event.terraingen.DecorateBiomeEvent;
|
||||
import net.minecraftforge.event.terraingen.DecorateBiomeEvent.Decorate;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event.Result;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import biomesoplenty.api.biome.BOPBiomes;
|
||||
import biomesoplenty.api.biome.BiomeOwner;
|
||||
import biomesoplenty.api.biome.IExtendedBiome;
|
||||
import biomesoplenty.api.biome.generation.GenerationManager;
|
||||
import biomesoplenty.api.biome.generation.GeneratorStage;
|
||||
import biomesoplenty.api.biome.generation.IGenerator;
|
||||
import biomesoplenty.common.biome.ExtendedBiomeRegistry;
|
||||
import biomesoplenty.common.init.ModBiomes;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraftforge.event.terraingen.DecorateBiomeEvent;
|
||||
import net.minecraftforge.event.terraingen.DecorateBiomeEvent.Decorate;
|
||||
import net.minecraftforge.event.terraingen.OreGenEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event.Result;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
public class DecorateBiomeEventHandler
|
||||
{
|
||||
@SubscribeEvent
|
||||
public void onPreBiomeDecorate(DecorateBiomeEvent.Pre event)
|
||||
{
|
||||
if (event.world.getWorldType() != ModBiomes.worldTypeBOP)
|
||||
return;
|
||||
|
||||
runGeneratorStage(event.world, event.rand, event.pos, GeneratorStage.PRE);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onBiomeDecorate(DecorateBiomeEvent.Decorate event)
|
||||
{
|
||||
if (event.world.getWorldType() != ModBiomes.worldTypeBOP)
|
||||
return;
|
||||
|
||||
if (event.type != Decorate.EventType.CUSTOM)
|
||||
{
|
||||
boolean allow = runGeneratorStage(event.world, event.rand, event.pos, GeneratorStage.mapDecorateType(event.type));
|
||||
|
@ -46,13 +54,34 @@ public class DecorateBiomeEventHandler
|
|||
@SubscribeEvent
|
||||
public void onPostBiomeDecorate(DecorateBiomeEvent.Post event)
|
||||
{
|
||||
if (event.world.getWorldType() != ModBiomes.worldTypeBOP)
|
||||
return;
|
||||
|
||||
runGeneratorStage(event.world, event.rand, event.pos, GeneratorStage.POST);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPreGenerateOres(OreGenEvent.Pre event)
|
||||
{
|
||||
if (event.world.getWorldType() != ModBiomes.worldTypeBOP)
|
||||
return;
|
||||
|
||||
runGeneratorStage(event.world, event.rand, event.pos, GeneratorStage.ORE_PRE);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPostGenerateOres(OreGenEvent.Post event)
|
||||
{
|
||||
if (event.world.getWorldType() != ModBiomes.worldTypeBOP)
|
||||
return;
|
||||
|
||||
runGeneratorStage(event.world, event.rand, event.pos, GeneratorStage.ORE_POST);
|
||||
}
|
||||
|
||||
private static boolean runGeneratorStage(World world, Random random, BlockPos pos, GeneratorStage stage)
|
||||
{
|
||||
BiomeGenBase biome = world.getBiomeGenForCoords(pos.add(16, 0, 16));
|
||||
IExtendedBiome extendedBiome = ExtendedBiomeRegistry.getExtension(biome);
|
||||
IExtendedBiome extendedBiome = BOPBiomes.REG_INSTANCE.getExtendedBiome(biome);
|
||||
|
||||
if (extendedBiome != null)
|
||||
{
|
||||
|
|
|
@ -24,7 +24,9 @@ import com.google.common.base.Optional;
|
|||
|
||||
import biomesoplenty.api.biome.BOPBiome;
|
||||
import biomesoplenty.api.biome.BOPBiomes;
|
||||
import biomesoplenty.api.biome.ExtendedBiomeWrapper;
|
||||
import biomesoplenty.api.biome.IExtendedBiome;
|
||||
import biomesoplenty.api.biome.generation.GeneratorStage;
|
||||
import biomesoplenty.common.biome.overworld.BiomeGenAlps;
|
||||
import biomesoplenty.common.biome.overworld.BiomeGenArctic;
|
||||
import biomesoplenty.common.biome.overworld.BiomeGenBambooForest;
|
||||
|
@ -67,18 +69,21 @@ import biomesoplenty.common.biome.overworld.BiomeGenThicket;
|
|||
import biomesoplenty.common.biome.overworld.BiomeGenTundra;
|
||||
import biomesoplenty.common.biome.overworld.BiomeGenWoodland;
|
||||
import biomesoplenty.common.biome.overworld.BiomeGenXericShrubland;
|
||||
import biomesoplenty.common.biome.vanilla.BiomeExtEnd;
|
||||
import biomesoplenty.common.command.BOPCommand;
|
||||
import biomesoplenty.common.enums.BOPClimates;
|
||||
import biomesoplenty.common.util.biome.BiomeUtils;
|
||||
import biomesoplenty.common.util.config.BOPConfig;
|
||||
import biomesoplenty.common.world.WorldTypeBOP;
|
||||
import biomesoplenty.common.world.feature.GeneratorGrass;
|
||||
import biomesoplenty.core.BiomesOPlenty;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraftforge.common.BiomeDictionary;
|
||||
import net.minecraftforge.common.BiomeManager;
|
||||
import net.minecraftforge.common.BiomeDictionary.Type;
|
||||
import net.minecraftforge.common.BiomeManager;
|
||||
|
||||
public class ModBiomes
|
||||
public class ModBiomes implements BOPBiomes.IBiomeRegistry
|
||||
{
|
||||
public static WorldTypeBOP worldTypeBOP;
|
||||
|
||||
|
@ -87,6 +92,8 @@ public class ModBiomes
|
|||
private static BOPConfig.IConfigObj biomeIdMapConf;
|
||||
protected static Map<String, Integer> biomeIdMap;
|
||||
private static Set<Integer> idsReservedInConfig;
|
||||
private static Map<Integer, IExtendedBiome> biomeWrapperMap;
|
||||
|
||||
public static Map<Integer, List<Integer>> subBiomesMap;
|
||||
public static Map<Integer, List<Integer>> mutatedBiomesMap;
|
||||
|
||||
|
@ -126,6 +133,7 @@ public class ModBiomes
|
|||
|
||||
initSubBiomes();
|
||||
initMutatedBiomes();
|
||||
initExtendedBiomes();
|
||||
|
||||
registerBiomes();
|
||||
registerBiomeDictionaryTags();
|
||||
|
@ -196,6 +204,12 @@ public class ModBiomes
|
|||
setSubBiome(BiomeGenBase.megaTaigaHills, BiomeGenBase.getBiome(BiomeGenBase.megaTaigaHills.biomeID + 128));
|
||||
}
|
||||
|
||||
public static void initExtendedBiomes()
|
||||
{
|
||||
biomeWrapperMap = new HashMap<Integer, IExtendedBiome>();
|
||||
|
||||
end_extension = registerWrappedBiome(new BiomeExtEnd(), "end");
|
||||
}
|
||||
|
||||
private static void registerBiomes()
|
||||
{
|
||||
|
@ -310,6 +324,56 @@ public class ModBiomes
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public IExtendedBiome registerBiome(IExtendedBiome extendedBiome, String idName)
|
||||
{
|
||||
if (extendedBiome == null)
|
||||
throw new IllegalArgumentException("Extended biome to register cannot be null!");
|
||||
|
||||
configureBiome(extendedBiome, idName);
|
||||
|
||||
//Extra functionality builtin, such as with BOPBiome
|
||||
if (extendedBiome instanceof BiomeGenBase)
|
||||
{
|
||||
for (Entry<BOPClimates, Integer> entry : extendedBiome.getWeightMap().entrySet())
|
||||
{
|
||||
if (entry != null)
|
||||
{
|
||||
BOPClimates climate = entry.getKey();
|
||||
int weight = entry.getValue();
|
||||
climate.addLandBiome(weight, extendedBiome.getBaseBiome());
|
||||
}
|
||||
}
|
||||
}
|
||||
else //extendedBiome is a wrapper
|
||||
{
|
||||
biomeWrapperMap.put(extendedBiome.getBaseBiome().biomeID, extendedBiome);
|
||||
}
|
||||
|
||||
return extendedBiome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IExtendedBiome getExtendedBiome(BiomeGenBase biome)
|
||||
{
|
||||
//Extra functionality builtin, such as with BOPBiome
|
||||
if (biome instanceof IExtendedBiome)
|
||||
{
|
||||
return (IExtendedBiome)biome;
|
||||
}
|
||||
else
|
||||
{
|
||||
IExtendedBiome wrapper = biomeWrapperMap.get(biome.biomeID);
|
||||
|
||||
//This biome may not have a wrapper
|
||||
if (wrapper != null)
|
||||
{
|
||||
return wrapper;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void setSubBiome(Optional<BiomeGenBase> parent, Optional<BiomeGenBase>... subBiomes)
|
||||
{
|
||||
|
@ -349,6 +413,26 @@ public class ModBiomes
|
|||
}
|
||||
}
|
||||
|
||||
private static void configureBiome(IExtendedBiome biome, String idName)
|
||||
{
|
||||
File configFile = new File(new File(BiomesOPlenty.configDirectory, "biomes"), idName + ".json");
|
||||
BOPConfig.IConfigObj conf = new BOPConfig.ConfigFileObj(configFile);
|
||||
|
||||
// If there was a valid config file, then use it to configure the biome
|
||||
if (!conf.isEmpty()) {biome.configure(conf);}
|
||||
// log any warnings from parsing the config file
|
||||
for (String msg : conf.flushMessages()) {BiomesOPlenty.logger.warn(msg);}
|
||||
}
|
||||
|
||||
private static IExtendedBiome registerWrappedBiome(IExtendedBiome extendedBiome, String idName)
|
||||
{
|
||||
//Non-wrapped biomes should not be registered this way
|
||||
if (extendedBiome.getBaseBiome() instanceof IExtendedBiome)
|
||||
throw new IllegalArgumentException("Biome already implements IExtendedBiome, it should be registered appropriately");
|
||||
|
||||
return BOPBiomes.REG_INSTANCE.registerBiome(extendedBiome, idName);
|
||||
}
|
||||
|
||||
private static Optional<BiomeGenBase> registerBOPBiome(BOPBiome biome, String name)
|
||||
{
|
||||
|
||||
|
@ -360,29 +444,13 @@ public class ModBiomes
|
|||
biomeIdMap.put(idName, id);
|
||||
|
||||
if (id > -1) {
|
||||
|
||||
File configFile = new File(new File(BiomesOPlenty.configDirectory, "biomes"), idName + ".json");
|
||||
BOPConfig.IConfigObj conf = new BOPConfig.ConfigFileObj(configFile);
|
||||
|
||||
BOPCommand.biomeCount++;
|
||||
biome.biomeID = id;
|
||||
// If there was a valid config file, then use it to configure the biome
|
||||
if (!conf.isEmpty()) {biome.configure(conf);}
|
||||
// log any warnings from parsing the config file
|
||||
for (String msg : conf.flushMessages()) {BiomesOPlenty.logger.warn(msg);}
|
||||
|
||||
BOPBiomes.REG_INSTANCE.registerBiome(biome, idName);
|
||||
|
||||
BiomeGenBase.getBiomeGenArray()[id] = biome;
|
||||
|
||||
for (Entry<BOPClimates, Integer> entry : ((IExtendedBiome)biome).getWeightMap().entrySet())
|
||||
{
|
||||
if (entry != null)
|
||||
{
|
||||
BOPClimates climate = entry.getKey();
|
||||
int weight = entry.getValue();
|
||||
climate.addLandBiome(weight, biome);
|
||||
}
|
||||
}
|
||||
|
||||
//Enable spwning and village generation in the biome
|
||||
if (biome.canSpawnInBiome)
|
||||
BiomeManager.addSpawnBiome(biome);
|
||||
|
@ -428,5 +496,4 @@ public class ModBiomes
|
|||
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -43,5 +43,6 @@ public class ModGenerators
|
|||
registerGenerator("lakes", GeneratorLakes.class, new GeneratorLakes.Builder());
|
||||
registerGenerator("columns", GeneratorColumns.class, new GeneratorColumns.Builder());
|
||||
registerGenerator("mixed_lily", GeneratorMixedLily.class, new GeneratorMixedLily.Builder());
|
||||
registerGenerator("crystals", GeneratorCrystals.class, new GeneratorCrystals.Builder());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ public class ModHandlers
|
|||
DecorateBiomeEventHandler decorateBiomeHandler = new DecorateBiomeEventHandler();
|
||||
MinecraftForge.EVENT_BUS.register(decorateBiomeHandler);
|
||||
MinecraftForge.TERRAIN_GEN_BUS.register(decorateBiomeHandler);
|
||||
MinecraftForge.ORE_GEN_BUS.register(decorateBiomeHandler);
|
||||
MinecraftForge.EVENT_BUS.register(new DyeEventHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new FlippersEventHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new BucketEventHandler());
|
||||
|
|
|
@ -0,0 +1,121 @@
|
|||
package biomesoplenty.common.world.feature;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import biomesoplenty.api.block.BlockQueries;
|
||||
import biomesoplenty.common.util.biome.GeneratorUtils.ScatterYMethod;
|
||||
import biomesoplenty.common.util.block.BlockQuery.BlockQueryMaterial;
|
||||
import biomesoplenty.common.util.block.BlockQuery.IBlockPosQuery;
|
||||
import biomesoplenty.common.util.config.BOPConfig.IConfigObj;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class GeneratorCrystals extends GeneratorReplacing
|
||||
{
|
||||
public static class Builder extends GeneratorReplacing.InnerBuilder<Builder, GeneratorCrystals> implements IGeneratorBuilder<GeneratorCrystals>
|
||||
{
|
||||
protected int generationAttempts;
|
||||
protected int maxRadius;
|
||||
protected int maxDepth;
|
||||
|
||||
public Builder generationAttempts(int a) {this.generationAttempts = a; return this.self();}
|
||||
public Builder maxRadius(int a) {this.maxRadius = a; return this.self();}
|
||||
public Builder maxDepth(int a) {this.maxDepth = a; return this.self();}
|
||||
|
||||
public Builder()
|
||||
{
|
||||
// defaults
|
||||
this.amountPerChunk = 1.0F;
|
||||
this.placeOn = BlockQueries.hellish;
|
||||
this.replace = new BlockQueryMaterial(Material.air);
|
||||
this.with = Blocks.glowstone.getDefaultState();
|
||||
this.scatterYMethod = ScatterYMethod.BELOW_GROUND;
|
||||
this.generationAttempts = 1500;
|
||||
this.maxRadius = 7;
|
||||
this.maxDepth = 11;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneratorCrystals create()
|
||||
{
|
||||
return new GeneratorCrystals(this.amountPerChunk, this.placeOn, this.replace, this.with, this.scatterYMethod, this.generationAttempts, this.maxRadius, this.maxDepth);
|
||||
}
|
||||
}
|
||||
|
||||
protected int generationAttempts;
|
||||
protected int maxRadius;
|
||||
protected int maxDepth;
|
||||
|
||||
public GeneratorCrystals(float amountPerChunk, IBlockPosQuery placeOn, IBlockPosQuery replace, IBlockState with, ScatterYMethod scatterYMethod, int generationAttempts, int maxRadius, int maxDepth)
|
||||
{
|
||||
super(amountPerChunk, replace, replace, with, scatterYMethod);
|
||||
this.generationAttempts = generationAttempts;
|
||||
this.maxRadius = maxRadius;
|
||||
this.maxDepth = maxDepth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(World world, Random rand, BlockPos pos)
|
||||
{
|
||||
//Ensure the current position isn't occupied
|
||||
if (this.replace.matches(world, pos))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (this.placeOn.matches(world, pos.up())) //Crystals hang down, ensure the block above is suitable
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
world.setBlockState(pos, this.with, 2);
|
||||
|
||||
for (int i = 0; i < this.generationAttempts; ++i)
|
||||
{
|
||||
//Randomly choose a position within the max depth and radius. Subtracting random numbers adds a bias towards choosing positions closer to the origin
|
||||
BlockPos randPos = pos.add(rand.nextInt(this.maxRadius + 1) - rand.nextInt(this.maxRadius + 1), -rand.nextInt(this.maxDepth + 1), rand.nextInt(this.maxRadius + 1) - rand.nextInt(this.maxRadius + 1));
|
||||
|
||||
//Ensure the random position isn't occupied
|
||||
if (this.replace.matches(world, randPos))
|
||||
{
|
||||
boolean adjacentCrystals = false;
|
||||
|
||||
//Iterate through each side adjacent to the random position and check for existing crystal blocks
|
||||
for (EnumFacing face : EnumFacing.values())
|
||||
{
|
||||
if (world.getBlockState(randPos.offset(face)) == this.with)
|
||||
{
|
||||
adjacentCrystals = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (adjacentCrystals)
|
||||
{
|
||||
//Set random position to crystal block
|
||||
world.setBlockState(randPos, this.with, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(IConfigObj conf)
|
||||
{
|
||||
this.amountPerChunk = conf.getFloat("amountPerChunk", this.amountPerChunk);
|
||||
this.placeOn = conf.getBlockPosQuery("placeUnder", this.placeOn);
|
||||
this.replace = conf.getBlockPosQuery("replace", this.replace);
|
||||
this.with = conf.getBlockState("with", this.with);
|
||||
this.generationAttempts = conf.getInt("generationAttempts", this.generationAttempts);
|
||||
this.scatterYMethod = conf.getEnum("scatterYMethod", this.scatterYMethod, ScatterYMethod.class);
|
||||
this.maxRadius = conf.getInt("maxRadius", this.maxRadius);
|
||||
this.maxDepth = conf.getInt("maxDepth", this.maxDepth);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue