001 package net.minecraft.village;
002
003 import java.util.Iterator;
004 import java.util.List;
005 import net.minecraft.entity.EnumCreatureType;
006 import net.minecraft.entity.monster.EntityZombie;
007 import net.minecraft.entity.player.EntityPlayer;
008 import net.minecraft.util.ChunkCoordinates;
009 import net.minecraft.util.MathHelper;
010 import net.minecraft.util.Vec3;
011 import net.minecraft.world.SpawnerAnimals;
012 import net.minecraft.world.World;
013
014 public class VillageSiege
015 {
016 private World worldObj;
017 private boolean field_75535_b = false;
018 private int field_75536_c = -1;
019 private int field_75533_d;
020 private int field_75534_e;
021
022 /** Instance of Village. */
023 private Village theVillage;
024 private int field_75532_g;
025 private int field_75538_h;
026 private int field_75539_i;
027
028 public VillageSiege(World par1World)
029 {
030 this.worldObj = par1World;
031 }
032
033 /**
034 * Runs a single tick for the village siege
035 */
036 public void tick()
037 {
038 boolean var1 = false;
039
040 if (var1)
041 {
042 if (this.field_75536_c == 2)
043 {
044 this.field_75533_d = 100;
045 return;
046 }
047 }
048 else
049 {
050 if (this.worldObj.isDaytime())
051 {
052 this.field_75536_c = 0;
053 return;
054 }
055
056 if (this.field_75536_c == 2)
057 {
058 return;
059 }
060
061 if (this.field_75536_c == 0)
062 {
063 float var2 = this.worldObj.getCelestialAngle(0.0F);
064
065 if ((double)var2 < 0.5D || (double)var2 > 0.501D)
066 {
067 return;
068 }
069
070 this.field_75536_c = this.worldObj.rand.nextInt(10) == 0 ? 1 : 2;
071 this.field_75535_b = false;
072
073 if (this.field_75536_c == 2)
074 {
075 return;
076 }
077 }
078 }
079
080 if (!this.field_75535_b)
081 {
082 if (!this.func_75529_b())
083 {
084 return;
085 }
086
087 this.field_75535_b = true;
088 }
089
090 if (this.field_75534_e > 0)
091 {
092 --this.field_75534_e;
093 }
094 else
095 {
096 this.field_75534_e = 2;
097
098 if (this.field_75533_d > 0)
099 {
100 this.spawnZombie();
101 --this.field_75533_d;
102 }
103 else
104 {
105 this.field_75536_c = 2;
106 }
107 }
108 }
109
110 private boolean func_75529_b()
111 {
112 List var1 = this.worldObj.playerEntities;
113 Iterator var2 = var1.iterator();
114
115 while (var2.hasNext())
116 {
117 EntityPlayer var3 = (EntityPlayer)var2.next();
118 this.theVillage = this.worldObj.villageCollectionObj.findNearestVillage((int)var3.posX, (int)var3.posY, (int)var3.posZ, 1);
119
120 if (this.theVillage != null && this.theVillage.getNumVillageDoors() >= 10 && this.theVillage.getTicksSinceLastDoorAdding() >= 20 && this.theVillage.getNumVillagers() >= 20)
121 {
122 ChunkCoordinates var4 = this.theVillage.getCenter();
123 float var5 = (float)this.theVillage.getVillageRadius();
124 boolean var6 = false;
125 int var7 = 0;
126
127 while (true)
128 {
129 if (var7 < 10)
130 {
131 this.field_75532_g = var4.posX + (int)((double)(MathHelper.cos(this.worldObj.rand.nextFloat() * (float)Math.PI * 2.0F) * var5) * 0.9D);
132 this.field_75538_h = var4.posY;
133 this.field_75539_i = var4.posZ + (int)((double)(MathHelper.sin(this.worldObj.rand.nextFloat() * (float)Math.PI * 2.0F) * var5) * 0.9D);
134 var6 = false;
135 Iterator var8 = this.worldObj.villageCollectionObj.getVillageList().iterator();
136
137 while (var8.hasNext())
138 {
139 Village var9 = (Village)var8.next();
140
141 if (var9 != this.theVillage && var9.isInRange(this.field_75532_g, this.field_75538_h, this.field_75539_i))
142 {
143 var6 = true;
144 break;
145 }
146 }
147
148 if (var6)
149 {
150 ++var7;
151 continue;
152 }
153 }
154
155 if (var6)
156 {
157 return false;
158 }
159
160 Vec3 var10 = this.func_75527_a(this.field_75532_g, this.field_75538_h, this.field_75539_i);
161
162 if (var10 != null)
163 {
164 this.field_75534_e = 0;
165 this.field_75533_d = 20;
166 return true;
167 }
168
169 break;
170 }
171 }
172 }
173
174 return false;
175 }
176
177 private boolean spawnZombie()
178 {
179 Vec3 var1 = this.func_75527_a(this.field_75532_g, this.field_75538_h, this.field_75539_i);
180
181 if (var1 == null)
182 {
183 return false;
184 }
185 else
186 {
187 EntityZombie var2;
188
189 try
190 {
191 var2 = new EntityZombie(this.worldObj);
192 var2.initCreature();
193 var2.setVillager(false);
194 }
195 catch (Exception var4)
196 {
197 var4.printStackTrace();
198 return false;
199 }
200
201 var2.setLocationAndAngles(var1.xCoord, var1.yCoord, var1.zCoord, this.worldObj.rand.nextFloat() * 360.0F, 0.0F);
202 this.worldObj.spawnEntityInWorld(var2);
203 ChunkCoordinates var3 = this.theVillage.getCenter();
204 var2.setHomeArea(var3.posX, var3.posY, var3.posZ, this.theVillage.getVillageRadius());
205 return true;
206 }
207 }
208
209 private Vec3 func_75527_a(int par1, int par2, int par3)
210 {
211 for (int var4 = 0; var4 < 10; ++var4)
212 {
213 int var5 = par1 + this.worldObj.rand.nextInt(16) - 8;
214 int var6 = par2 + this.worldObj.rand.nextInt(6) - 3;
215 int var7 = par3 + this.worldObj.rand.nextInt(16) - 8;
216
217 if (this.theVillage.isInRange(var5, var6, var7) && SpawnerAnimals.canCreatureTypeSpawnAtLocation(EnumCreatureType.monster, this.worldObj, var5, var6, var7))
218 {
219 this.worldObj.getWorldVec3Pool().getVecFromPool((double)var5, (double)var6, (double)var7);
220 }
221 }
222
223 return null;
224 }
225 }