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