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