| 1 | package net.minecraft.village;
|
| 2 |
|
| 3 | import java.util.Iterator;
|
| 4 | import java.util.List;
|
| 5 | import net.minecraft.entity.EntityLiving;
|
| 6 | import net.minecraft.entity.IEntityLivingData;
|
| 7 | import net.minecraft.entity.monster.EntityZombie;
|
| 8 | import net.minecraft.entity.player.EntityPlayer;
|
| 9 | import net.minecraft.util.BlockPos;
|
| 10 | import net.minecraft.util.MathHelper;
|
| 11 | import net.minecraft.util.Vec3;
|
| 12 | import net.minecraft.world.SpawnerAnimals;
|
| 13 | import net.minecraft.world.World;
|
| 14 |
|
| 15 | public class VillageSiege
|
| 16 | {
|
| 17 | private World worldObj;
|
| 18 | private boolean field_75535_b;
|
| 19 | private int field_75536_c = -1;
|
| 20 | private int field_75533_d;
|
| 21 | private int field_75534_e;
|
| 22 |
|
| 23 | /** Instance of Village. */
|
| 24 | private Village theVillage;
|
| 25 | private int field_75532_g;
|
| 26 | private int field_75538_h;
|
| 27 | private int field_75539_i;
|
| 28 |
|
| 29 | public VillageSiege(World worldIn)
|
| 30 | {
|
| 31 | this.worldObj = worldIn;
|
| 32 | }
|
| 33 |
|
| 34 | /**
|
| 35 | * Runs a single tick for the village siege
|
| 36 | */
|
| 37 | public void tick()
|
| 38 | {
|
| 39 | if (this.worldObj.isDaytime())
|
| 40 | {
|
| 41 | this.field_75536_c = 0;
|
| 42 | }
|
| 43 | else if (this.field_75536_c != 2)
|
| 44 | {
|
| 45 | if (this.field_75536_c == 0)
|
| 46 | {
|
| 47 | float f = this.worldObj.getCelestialAngle(0.0F);
|
| 48 |
|
| 49 | if ((double)f < 0.5D || (double)f > 0.501D)
|
| 50 | {
|
| 51 | return;
|
| 52 | }
|
| 53 |
|
| 54 | this.field_75536_c = this.worldObj.rand.nextInt(10) == 0 ? 1 : 2;
|
| 55 | this.field_75535_b = false;
|
| 56 |
|
| 57 | if (this.field_75536_c == 2)
|
| 58 | {
|
| 59 | return;
|
| 60 | }
|
| 61 | }
|
| 62 |
|
| 63 | if (this.field_75536_c != -1)
|
| 64 | {
|
| 65 | if (!this.field_75535_b)
|
| 66 | {
|
| 67 | if (!this.func_75529_b())
|
| 68 | {
|
| 69 | return;
|
| 70 | }
|
| 71 |
|
| 72 | this.field_75535_b = true;
|
| 73 | }
|
| 74 |
|
| 75 | if (this.field_75534_e > 0)
|
| 76 | {
|
| 77 | --this.field_75534_e;
|
| 78 | }
|
| 79 | else
|
| 80 | {
|
| 81 | this.field_75534_e = 2;
|
| 82 |
|
| 83 | if (this.field_75533_d > 0)
|
| 84 | {
|
| 85 | this.spawnZombie();
|
| 86 | --this.field_75533_d;
|
| 87 | }
|
| 88 | else
|
| 89 | {
|
| 90 | this.field_75536_c = 2;
|
| 91 | }
|
| 92 | }
|
| 93 | }
|
| 94 | }
|
| 95 | }
|
| 96 |
|
| 97 | private boolean func_75529_b()
|
| 98 | {
|
| 99 | List<EntityPlayer> list = this.worldObj.playerEntities;
|
| 100 | Iterator iterator = list.iterator();
|
| 101 |
|
| 102 | while (true)
|
| 103 | {
|
| 104 | if (!iterator.hasNext())
|
| 105 | {
|
| 106 | return false;
|
| 107 | }
|
| 108 |
|
| 109 | EntityPlayer entityplayer = (EntityPlayer)iterator.next();
|
| 110 |
|
| 111 | if (!entityplayer.isSpectator())
|
| 112 | {
|
| 113 | this.theVillage = this.worldObj.getVillageCollection().getNearestVillage(new BlockPos(entityplayer), 1);
|
| 114 |
|
| 115 | if (this.theVillage != null && this.theVillage.getNumVillageDoors() >= 10 && this.theVillage.getTicksSinceLastDoorAdding() >= 20 && this.theVillage.getNumVillagers() >= 20)
|
| 116 | {
|
| 117 | BlockPos blockpos = this.theVillage.getCenter();
|
| 118 | float f = (float)this.theVillage.getVillageRadius();
|
| 119 | boolean flag = false;
|
| 120 |
|
| 121 | for (int i = 0; i < 10; ++i)
|
| 122 | {
|
| 123 | float f1 = this.worldObj.rand.nextFloat() * (float)Math.PI * 2.0F;
|
| 124 | this.field_75532_g = blockpos.getX() + (int)((double)(MathHelper.cos(f1) * f) * 0.9D);
|
| 125 | this.field_75538_h = blockpos.getY();
|
| 126 | this.field_75539_i = blockpos.getZ() + (int)((double)(MathHelper.sin(f1) * f) * 0.9D);
|
| 127 | flag = false;
|
| 128 |
|
| 129 | for (Village village : this.worldObj.getVillageCollection().getVillageList())
|
| 130 | {
|
| 131 | if (village != this.theVillage && village.func_179866_a(new BlockPos(this.field_75532_g, this.field_75538_h, this.field_75539_i)))
|
| 132 | {
|
| 133 | flag = true;
|
| 134 | break;
|
| 135 | }
|
| 136 | }
|
| 137 |
|
| 138 | if (!flag)
|
| 139 | {
|
| 140 | break;
|
| 141 | }
|
| 142 | }
|
| 143 |
|
| 144 | if (flag)
|
| 145 | {
|
| 146 | return false;
|
| 147 | }
|
| 148 |
|
| 149 | Vec3 vec3 = this.func_179867_a(new BlockPos(this.field_75532_g, this.field_75538_h, this.field_75539_i));
|
| 150 |
|
| 151 | if (vec3 != null)
|
| 152 | {
|
| 153 | break;
|
| 154 | }
|
| 155 | }
|
| 156 | }
|
| 157 | }
|
| 158 |
|
| 159 | this.field_75534_e = 0;
|
| 160 | this.field_75533_d = 20;
|
| 161 | return true;
|
| 162 | }
|
| 163 |
|
| 164 | private boolean spawnZombie()
|
| 165 | {
|
| 166 | Vec3 vec3 = this.func_179867_a(new BlockPos(this.field_75532_g, this.field_75538_h, this.field_75539_i));
|
| 167 |
|
| 168 | if (vec3 == null)
|
| 169 | {
|
| 170 | return false;
|
| 171 | }
|
| 172 | else
|
| 173 | {
|
| 174 | EntityZombie entityzombie;
|
| 175 |
|
| 176 | try
|
| 177 | {
|
| 178 | entityzombie = new EntityZombie(this.worldObj);
|
| 179 | entityzombie.onInitialSpawn(this.worldObj.getDifficultyForLocation(new BlockPos(entityzombie)), (IEntityLivingData)null);
|
| 180 | entityzombie.setVillager(false);
|
| 181 | }
|
| 182 | catch (Exception exception)
|
| 183 | {
|
| 184 | exception.printStackTrace();
|
| 185 | return false;
|
| 186 | }
|
| 187 |
|
| 188 | entityzombie.setLocationAndAngles(vec3.xCoord, vec3.yCoord, vec3.zCoord, this.worldObj.rand.nextFloat() * 360.0F, 0.0F);
|
| 189 | this.worldObj.spawnEntityInWorld(entityzombie);
|
| 190 | BlockPos blockpos = this.theVillage.getCenter();
|
| 191 | entityzombie.setHomePosAndDistance(blockpos, this.theVillage.getVillageRadius());
|
| 192 | return true;
|
| 193 | }
|
| 194 | }
|
| 195 |
|
| 196 | private Vec3 func_179867_a(BlockPos p_179867_1_)
|
| 197 | {
|
| 198 | for (int i = 0; i < 10; ++i)
|
| 199 | {
|
| 200 | BlockPos blockpos = p_179867_1_.add(this.worldObj.rand.nextInt(16) - 8, this.worldObj.rand.nextInt(6) - 3, this.worldObj.rand.nextInt(16) - 8);
|
| 201 |
|
| 202 | if (this.theVillage.func_179866_a(blockpos) && SpawnerAnimals.canCreatureTypeSpawnAtLocation(EntityLiving.SpawnPlacementType.ON_GROUND, this.worldObj, blockpos))
|
| 203 | {
|
| 204 | return new Vec3((double)blockpos.getX(), (double)blockpos.getY(), (double)blockpos.getZ());
|
| 205 | }
|
| 206 | }
|
| 207 |
|
| 208 | return null;
|
| 209 | }
|
| 210 | }
|
| 211 |
|