| 1 | package net.minecraft.world.gen.structure;
|
| 2 |
|
| 3 | import java.util.Arrays;
|
| 4 | import java.util.List;
|
| 5 | import java.util.Map;
|
| 6 | import java.util.Random;
|
| 7 | import java.util.Map.Entry;
|
| 8 | import net.minecraft.nbt.NBTTagCompound;
|
| 9 | import net.minecraft.util.MathHelper;
|
| 10 | import net.minecraft.world.World;
|
| 11 | import net.minecraft.world.biome.BiomeGenBase;
|
| 12 |
|
| 13 | public class MapGenVillage extends MapGenStructure
|
| 14 | {
|
| 15 | public static final List<BiomeGenBase> villageSpawnBiomes = Arrays.<BiomeGenBase>asList(new BiomeGenBase[] {BiomeGenBase.plains, BiomeGenBase.desert, BiomeGenBase.savanna});
|
| 16 |
|
| 17 | /** World terrain type, 0 for normal, 1 for flat map */
|
| 18 | private int terrainType;
|
| 19 | private int field_82665_g;
|
| 20 | private int field_82666_h;
|
| 21 |
|
| 22 | public MapGenVillage()
|
| 23 | {
|
| 24 | this.field_82665_g = 32;
|
| 25 | this.field_82666_h = 8;
|
| 26 | }
|
| 27 |
|
| 28 | public MapGenVillage(Map<String, String> p_i2093_1_)
|
| 29 | {
|
| 30 | this();
|
| 31 |
|
| 32 | for (Entry<String, String> entry : p_i2093_1_.entrySet())
|
| 33 | {
|
| 34 | if (((String)entry.getKey()).equals("size"))
|
| 35 | {
|
| 36 | this.terrainType = MathHelper.parseIntWithDefaultAndMax((String)entry.getValue(), this.terrainType, 0);
|
| 37 | }
|
| 38 | else if (((String)entry.getKey()).equals("distance"))
|
| 39 | {
|
| 40 | this.field_82665_g = MathHelper.parseIntWithDefaultAndMax((String)entry.getValue(), this.field_82665_g, this.field_82666_h + 1);
|
| 41 | }
|
| 42 | }
|
| 43 | }
|
| 44 |
|
| 45 | public String getStructureName()
|
| 46 | {
|
| 47 | return "Village";
|
| 48 | }
|
| 49 |
|
| 50 | protected boolean canSpawnStructureAtCoords(int chunkX, int chunkZ)
|
| 51 | {
|
| 52 | int i = chunkX;
|
| 53 | int j = chunkZ;
|
| 54 |
|
| 55 | if (chunkX < 0)
|
| 56 | {
|
| 57 | chunkX -= this.field_82665_g - 1;
|
| 58 | }
|
| 59 |
|
| 60 | if (chunkZ < 0)
|
| 61 | {
|
| 62 | chunkZ -= this.field_82665_g - 1;
|
| 63 | }
|
| 64 |
|
| 65 | int k = chunkX / this.field_82665_g;
|
| 66 | int l = chunkZ / this.field_82665_g;
|
| 67 | Random random = this.worldObj.setRandomSeed(k, l, 10387312);
|
| 68 | k = k * this.field_82665_g;
|
| 69 | l = l * this.field_82665_g;
|
| 70 | k = k + random.nextInt(this.field_82665_g - this.field_82666_h);
|
| 71 | l = l + random.nextInt(this.field_82665_g - this.field_82666_h);
|
| 72 |
|
| 73 | if (i == k && j == l)
|
| 74 | {
|
| 75 | boolean flag = this.worldObj.getWorldChunkManager().areBiomesViable(i * 16 + 8, j * 16 + 8, 0, villageSpawnBiomes);
|
| 76 |
|
| 77 | if (flag)
|
| 78 | {
|
| 79 | return true;
|
| 80 | }
|
| 81 | }
|
| 82 |
|
| 83 | return false;
|
| 84 | }
|
| 85 |
|
| 86 | protected StructureStart getStructureStart(int chunkX, int chunkZ)
|
| 87 | {
|
| 88 | return new MapGenVillage.Start(this.worldObj, this.rand, chunkX, chunkZ, this.terrainType);
|
| 89 | }
|
| 90 |
|
| 91 | public static class Start extends StructureStart
|
| 92 | {
|
| 93 | private boolean hasMoreThanTwoComponents;
|
| 94 |
|
| 95 | public Start()
|
| 96 | {
|
| 97 | }
|
| 98 |
|
| 99 | public Start(World worldIn, Random rand, int x, int z, int size)
|
| 100 | {
|
| 101 | super(x, z);
|
| 102 | List<StructureVillagePieces.PieceWeight> list = StructureVillagePieces.getStructureVillageWeightedPieceList(rand, size);
|
| 103 | StructureVillagePieces.Start structurevillagepieces$start = new StructureVillagePieces.Start(worldIn.getWorldChunkManager(), 0, rand, (x << 4) + 2, (z << 4) + 2, list, size);
|
| 104 | this.components.add(structurevillagepieces$start);
|
| 105 | structurevillagepieces$start.buildComponent(structurevillagepieces$start, this.components, rand);
|
| 106 | List<StructureComponent> list1 = structurevillagepieces$start.field_74930_j;
|
| 107 | List<StructureComponent> list2 = structurevillagepieces$start.field_74932_i;
|
| 108 |
|
| 109 | while (!list1.isEmpty() || !list2.isEmpty())
|
| 110 | {
|
| 111 | if (list1.isEmpty())
|
| 112 | {
|
| 113 | int i = rand.nextInt(list2.size());
|
| 114 | StructureComponent structurecomponent = (StructureComponent)list2.remove(i);
|
| 115 | structurecomponent.buildComponent(structurevillagepieces$start, this.components, rand);
|
| 116 | }
|
| 117 | else
|
| 118 | {
|
| 119 | int j = rand.nextInt(list1.size());
|
| 120 | StructureComponent structurecomponent2 = (StructureComponent)list1.remove(j);
|
| 121 | structurecomponent2.buildComponent(structurevillagepieces$start, this.components, rand);
|
| 122 | }
|
| 123 | }
|
| 124 |
|
| 125 | this.updateBoundingBox();
|
| 126 | int k = 0;
|
| 127 |
|
| 128 | for (StructureComponent structurecomponent1 : this.components)
|
| 129 | {
|
| 130 | if (!(structurecomponent1 instanceof StructureVillagePieces.Road))
|
| 131 | {
|
| 132 | ++k;
|
| 133 | }
|
| 134 | }
|
| 135 |
|
| 136 | this.hasMoreThanTwoComponents = k > 2;
|
| 137 | }
|
| 138 |
|
| 139 | public boolean isSizeableStructure()
|
| 140 | {
|
| 141 | return this.hasMoreThanTwoComponents;
|
| 142 | }
|
| 143 |
|
| 144 | public void writeToNBT(NBTTagCompound tagCompound)
|
| 145 | {
|
| 146 | super.writeToNBT(tagCompound);
|
| 147 | tagCompound.setBoolean("Valid", this.hasMoreThanTwoComponents);
|
| 148 | }
|
| 149 |
|
| 150 | public void readFromNBT(NBTTagCompound tagCompound)
|
| 151 | {
|
| 152 | super.readFromNBT(tagCompound);
|
| 153 | this.hasMoreThanTwoComponents = tagCompound.getBoolean("Valid");
|
| 154 | }
|
| 155 | }
|
| 156 | }
|
| 157 |
|