BiomesOPlenty/common/biomesoplenty/worldgen/structure/BOPMapGenVillage.java

102 lines
2.5 KiB
Java
Raw Normal View History

2013-05-03 13:00:44 +00:00
package biomesoplenty.worldgen.structure;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
2013-05-03 13:00:44 +00:00
import net.minecraft.util.MathHelper;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.gen.structure.MapGenStructure;
import net.minecraft.world.gen.structure.MapGenVillage;
import net.minecraft.world.gen.structure.StructureStart;
2013-09-14 10:16:39 +00:00
import biomesoplenty.configuration.configfile.BOPConfigurationTerrainGen;
2013-05-03 13:00:44 +00:00
public class BOPMapGenVillage extends MapGenStructure
{
2013-05-31 10:34:02 +00:00
/** A list of all the biomes villages can spawn in. */
public static List villageSpawnBiomes = Arrays.asList(new BiomeGenBase[] {BiomeGenBase.plains, BiomeGenBase.desert});
/** World terrain type, 0 for normal, 1 for flat map */
private int terrainType;
private int maxDistance;
private int minDistance;
public BOPMapGenVillage()
{
terrainType = 0;
2013-09-14 10:16:39 +00:00
maxDistance = BOPConfigurationTerrainGen.villageDistance;
minDistance = BOPConfigurationTerrainGen.villageDistance / 4;
2013-05-31 10:34:02 +00:00
villageSpawnBiomes = MapGenVillage.villageSpawnBiomes;
}
public BOPMapGenVillage(Map par1Map)
{
this();
Iterator iterator = par1Map.entrySet().iterator();
while (iterator.hasNext())
{
Entry entry = (Entry)iterator.next();
if (((String)entry.getKey()).equals("size"))
{
terrainType = MathHelper.parseIntWithDefaultAndMax((String)entry.getValue(), terrainType, 0);
}
else if (((String)entry.getKey()).equals("distance"))
{
maxDistance = MathHelper.parseIntWithDefaultAndMax((String)entry.getValue(), maxDistance, minDistance + 1);
}
}
}
@Override
public String func_143025_a()
{
2013-09-21 07:04:41 +00:00
return "Village";
}
2013-05-31 10:34:02 +00:00
@Override
protected boolean canSpawnStructureAtCoords(int par1, int par2)
{
int k = par1;
int l = par2;
if (par1 < 0)
{
par1 -= maxDistance - 1;
}
if (par2 < 0)
{
par2 -= maxDistance - 1;
}
int i1 = par1 / maxDistance;
int j1 = par2 / maxDistance;
Random random = worldObj.setRandomSeed(i1, j1, 10387312);
i1 *= maxDistance;
j1 *= maxDistance;
i1 += random.nextInt(maxDistance - minDistance);
j1 += random.nextInt(maxDistance - minDistance);
if (k == i1 && l == j1)
{
boolean flag = worldObj.getWorldChunkManager().areBiomesViable(k * 16 + 8, l * 16 + 8, 0, villageSpawnBiomes);
if (flag)
return true;
}
return false;
}
@Override
protected StructureStart getStructureStart(int par1, int par2)
{
return new BOPStructureVillageStart(worldObj, rand, par1, par2, terrainType);
}
2013-05-03 13:00:44 +00:00
}