| 1 | package net.minecraft.world.gen.structure;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import com.google.common.collect.Sets;
|
| 5 | import java.util.Arrays;
|
| 6 | import java.util.List;
|
| 7 | import java.util.Map;
|
| 8 | import java.util.Random;
|
| 9 | import java.util.Set;
|
| 10 | import java.util.Map.Entry;
|
| 11 | import net.minecraft.entity.monster.EntityGuardian;
|
| 12 | import net.minecraft.nbt.NBTTagCompound;
|
| 13 | import net.minecraft.nbt.NBTTagList;
|
| 14 | import net.minecraft.util.BlockPos;
|
| 15 | import net.minecraft.util.EnumFacing;
|
| 16 | import net.minecraft.util.MathHelper;
|
| 17 | import net.minecraft.world.ChunkCoordIntPair;
|
| 18 | import net.minecraft.world.World;
|
| 19 | import net.minecraft.world.biome.BiomeGenBase;
|
| 20 |
|
| 21 | public class StructureOceanMonument extends MapGenStructure
|
| 22 | {
|
| 23 | private int field_175800_f;
|
| 24 | private int field_175801_g;
|
| 25 | public static final List<BiomeGenBase> field_175802_d = Arrays.<BiomeGenBase>asList(new BiomeGenBase[] {BiomeGenBase.ocean, BiomeGenBase.deepOcean, BiomeGenBase.river, BiomeGenBase.frozenOcean, BiomeGenBase.frozenRiver});
|
| 26 | private static final List<BiomeGenBase.SpawnListEntry> field_175803_h = Lists.<BiomeGenBase.SpawnListEntry>newArrayList();
|
| 27 |
|
| 28 | public StructureOceanMonument()
|
| 29 | {
|
| 30 | this.field_175800_f = 32;
|
| 31 | this.field_175801_g = 5;
|
| 32 | }
|
| 33 |
|
| 34 | public StructureOceanMonument(Map<String, String> p_i45608_1_)
|
| 35 | {
|
| 36 | this();
|
| 37 |
|
| 38 | for (Entry<String, String> entry : p_i45608_1_.entrySet())
|
| 39 | {
|
| 40 | if (((String)entry.getKey()).equals("spacing"))
|
| 41 | {
|
| 42 | this.field_175800_f = MathHelper.parseIntWithDefaultAndMax((String)entry.getValue(), this.field_175800_f, 1);
|
| 43 | }
|
| 44 | else if (((String)entry.getKey()).equals("separation"))
|
| 45 | {
|
| 46 | this.field_175801_g = MathHelper.parseIntWithDefaultAndMax((String)entry.getValue(), this.field_175801_g, 1);
|
| 47 | }
|
| 48 | }
|
| 49 | }
|
| 50 |
|
| 51 | public String getStructureName()
|
| 52 | {
|
| 53 | return "Monument";
|
| 54 | }
|
| 55 |
|
| 56 | protected boolean canSpawnStructureAtCoords(int chunkX, int chunkZ)
|
| 57 | {
|
| 58 | int i = chunkX;
|
| 59 | int j = chunkZ;
|
| 60 |
|
| 61 | if (chunkX < 0)
|
| 62 | {
|
| 63 | chunkX -= this.field_175800_f - 1;
|
| 64 | }
|
| 65 |
|
| 66 | if (chunkZ < 0)
|
| 67 | {
|
| 68 | chunkZ -= this.field_175800_f - 1;
|
| 69 | }
|
| 70 |
|
| 71 | int k = chunkX / this.field_175800_f;
|
| 72 | int l = chunkZ / this.field_175800_f;
|
| 73 | Random random = this.worldObj.setRandomSeed(k, l, 10387313);
|
| 74 | k = k * this.field_175800_f;
|
| 75 | l = l * this.field_175800_f;
|
| 76 | k = k + (random.nextInt(this.field_175800_f - this.field_175801_g) + random.nextInt(this.field_175800_f - this.field_175801_g)) / 2;
|
| 77 | l = l + (random.nextInt(this.field_175800_f - this.field_175801_g) + random.nextInt(this.field_175800_f - this.field_175801_g)) / 2;
|
| 78 |
|
| 79 | if (i == k && j == l)
|
| 80 | {
|
| 81 | if (this.worldObj.getWorldChunkManager().getBiomeGenerator(new BlockPos(i * 16 + 8, 64, j * 16 + 8), (BiomeGenBase)null) != BiomeGenBase.deepOcean)
|
| 82 | {
|
| 83 | return false;
|
| 84 | }
|
| 85 |
|
| 86 | boolean flag = this.worldObj.getWorldChunkManager().areBiomesViable(i * 16 + 8, j * 16 + 8, 29, field_175802_d);
|
| 87 |
|
| 88 | if (flag)
|
| 89 | {
|
| 90 | return true;
|
| 91 | }
|
| 92 | }
|
| 93 |
|
| 94 | return false;
|
| 95 | }
|
| 96 |
|
| 97 | protected StructureStart getStructureStart(int chunkX, int chunkZ)
|
| 98 | {
|
| 99 | return new StructureOceanMonument.StartMonument(this.worldObj, this.rand, chunkX, chunkZ);
|
| 100 | }
|
| 101 |
|
| 102 | public List<BiomeGenBase.SpawnListEntry> getScatteredFeatureSpawnList()
|
| 103 | {
|
| 104 | return field_175803_h;
|
| 105 | }
|
| 106 |
|
| 107 | static
|
| 108 | {
|
| 109 | field_175803_h.add(new BiomeGenBase.SpawnListEntry(EntityGuardian.class, 1, 2, 4));
|
| 110 | }
|
| 111 |
|
| 112 | public static class StartMonument extends StructureStart
|
| 113 | {
|
| 114 | private Set<ChunkCoordIntPair> field_175791_c = Sets.<ChunkCoordIntPair>newHashSet();
|
| 115 | private boolean field_175790_d;
|
| 116 |
|
| 117 | public StartMonument()
|
| 118 | {
|
| 119 | }
|
| 120 |
|
| 121 | public StartMonument(World worldIn, Random p_i45607_2_, int p_i45607_3_, int p_i45607_4_)
|
| 122 | {
|
| 123 | super(p_i45607_3_, p_i45607_4_);
|
| 124 | this.func_175789_b(worldIn, p_i45607_2_, p_i45607_3_, p_i45607_4_);
|
| 125 | }
|
| 126 |
|
| 127 | private void func_175789_b(World worldIn, Random p_175789_2_, int p_175789_3_, int p_175789_4_)
|
| 128 | {
|
| 129 | p_175789_2_.setSeed(worldIn.getSeed());
|
| 130 | long i = p_175789_2_.nextLong();
|
| 131 | long j = p_175789_2_.nextLong();
|
| 132 | long k = (long)p_175789_3_ * i;
|
| 133 | long l = (long)p_175789_4_ * j;
|
| 134 | p_175789_2_.setSeed(k ^ l ^ worldIn.getSeed());
|
| 135 | int i1 = p_175789_3_ * 16 + 8 - 29;
|
| 136 | int j1 = p_175789_4_ * 16 + 8 - 29;
|
| 137 | EnumFacing enumfacing = EnumFacing.Plane.HORIZONTAL.random(p_175789_2_);
|
| 138 | this.components.add(new StructureOceanMonumentPieces.MonumentBuilding(p_175789_2_, i1, j1, enumfacing));
|
| 139 | this.updateBoundingBox();
|
| 140 | this.field_175790_d = true;
|
| 141 | }
|
| 142 |
|
| 143 | public void generateStructure(World worldIn, Random rand, StructureBoundingBox structurebb)
|
| 144 | {
|
| 145 | if (!this.field_175790_d)
|
| 146 | {
|
| 147 | this.components.clear();
|
| 148 | this.func_175789_b(worldIn, rand, this.getChunkPosX(), this.getChunkPosZ());
|
| 149 | }
|
| 150 |
|
| 151 | super.generateStructure(worldIn, rand, structurebb);
|
| 152 | }
|
| 153 |
|
| 154 | public boolean func_175788_a(ChunkCoordIntPair pair)
|
| 155 | {
|
| 156 | return this.field_175791_c.contains(pair) ? false : super.func_175788_a(pair);
|
| 157 | }
|
| 158 |
|
| 159 | public void func_175787_b(ChunkCoordIntPair pair)
|
| 160 | {
|
| 161 | super.func_175787_b(pair);
|
| 162 | this.field_175791_c.add(pair);
|
| 163 | }
|
| 164 |
|
| 165 | public void writeToNBT(NBTTagCompound tagCompound)
|
| 166 | {
|
| 167 | super.writeToNBT(tagCompound);
|
| 168 | NBTTagList nbttaglist = new NBTTagList();
|
| 169 |
|
| 170 | for (ChunkCoordIntPair chunkcoordintpair : this.field_175791_c)
|
| 171 | {
|
| 172 | NBTTagCompound nbttagcompound = new NBTTagCompound();
|
| 173 | nbttagcompound.setInteger("X", chunkcoordintpair.chunkXPos);
|
| 174 | nbttagcompound.setInteger("Z", chunkcoordintpair.chunkZPos);
|
| 175 | nbttaglist.appendTag(nbttagcompound);
|
| 176 | }
|
| 177 |
|
| 178 | tagCompound.setTag("Processed", nbttaglist);
|
| 179 | }
|
| 180 |
|
| 181 | public void readFromNBT(NBTTagCompound tagCompound)
|
| 182 | {
|
| 183 | super.readFromNBT(tagCompound);
|
| 184 |
|
| 185 | if (tagCompound.hasKey("Processed", 9))
|
| 186 | {
|
| 187 | NBTTagList nbttaglist = tagCompound.getTagList("Processed", 10);
|
| 188 |
|
| 189 | for (int i = 0; i < nbttaglist.tagCount(); ++i)
|
| 190 | {
|
| 191 | NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
|
| 192 | this.field_175791_c.add(new ChunkCoordIntPair(nbttagcompound.getInteger("X"), nbttagcompound.getInteger("Z")));
|
| 193 | }
|
| 194 | }
|
| 195 | }
|
| 196 | }
|
| 197 | }
|
| 198 |
|