summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/VillageSiege.java
blob: b3e9687ea9f182ae9ec41fb4191cbe5b2afc71cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package net.minecraft.server;

import java.util.Iterator;
import java.util.List;

public class VillageSiege {

    private World world;
    private boolean b = false;
    private int c = -1;
    private int d;
    private int e;
    private Village f;
    private int g;
    private int h;
    private int i;

    public VillageSiege(World world) {
        this.world = world;
    }

    public void a() {
        boolean flag = false;

        if (flag) {
            if (this.c == 2) {
                this.d = 100;
                return;
            }
        } else {
            if (this.world.u()) {
                this.c = 0;
                return;
            }

            if (this.c == 2) {
                return;
            }

            if (this.c == 0) {
                float f = this.world.c(0.0F);

                if ((double) f < 0.5D || (double) f > 0.501D) {
                    return;
                }

                this.c = this.world.random.nextInt(10) == 0 ? 1 : 2;
                this.b = false;
                if (this.c == 2) {
                    return;
                }
            }
        }

        if (!this.b) {
            if (!this.b()) {
                return;
            }

            this.b = true;
        }

        if (this.e > 0) {
            --this.e;
        } else {
            this.e = 2;
            if (this.d > 0) {
                this.c();
                --this.d;
            } else {
                this.c = 2;
            }
        }
    }

    private boolean b() {
        List list = this.world.players;
        Iterator iterator = list.iterator();

        while (iterator.hasNext()) {
            EntityHuman entityhuman = (EntityHuman) iterator.next();

            this.f = this.world.villages.getClosestVillage((int) entityhuman.locX, (int) entityhuman.locY, (int) entityhuman.locZ, 1);
            if (this.f != null && this.f.getDoorCount() >= 10 && this.f.d() >= 20 && this.f.getPopulationCount() >= 20) {
                ChunkCoordinates chunkcoordinates = this.f.getCenter();
                float f = (float) this.f.getSize();
                boolean flag = false;
                int i = 0;

                while (true) {
                    if (i < 10) {
                        this.g = chunkcoordinates.x + (int) ((double) (MathHelper.cos(this.world.random.nextFloat() * 3.1415927F * 2.0F) * f) * 0.9D);
                        this.h = chunkcoordinates.y;
                        this.i = chunkcoordinates.z + (int) ((double) (MathHelper.sin(this.world.random.nextFloat() * 3.1415927F * 2.0F) * f) * 0.9D);
                        flag = false;
                        Iterator iterator1 = this.world.villages.getVillages().iterator();

                        while (iterator1.hasNext()) {
                            Village village = (Village) iterator1.next();

                            if (village != this.f && village.a(this.g, this.h, this.i)) {
                                flag = true;
                                break;
                            }
                        }

                        if (flag) {
                            ++i;
                            continue;
                        }
                    }

                    if (flag) {
                        return false;
                    }

                    Vec3D vec3d = this.a(this.g, this.h, this.i);

                    if (vec3d != null) {
                        this.e = 0;
                        this.d = 20;
                        return true;
                    }
                    break;
                }
            }
        }

        return false;
    }

    private boolean c() {
        Vec3D vec3d = this.a(this.g, this.h, this.i);

        if (vec3d == null) {
            return false;
        } else {
            EntityZombie entityzombie;

            try {
                entityzombie = new EntityZombie(this.world);
                entityzombie.bG();
                entityzombie.setVillager(false);
            } catch (Exception exception) {
                exception.printStackTrace();
                return false;
            }

            entityzombie.setPositionRotation(vec3d.c, vec3d.d, vec3d.e, this.world.random.nextFloat() * 360.0F, 0.0F);
            this.world.addEntity(entityzombie, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.VILLAGE_INVASION); // CraftBukkit
            ChunkCoordinates chunkcoordinates = this.f.getCenter();

            entityzombie.b(chunkcoordinates.x, chunkcoordinates.y, chunkcoordinates.z, this.f.getSize());
            return true;
        }
    }

    private Vec3D a(int i, int j, int k) {
        for (int l = 0; l < 10; ++l) {
            int i1 = i + this.world.random.nextInt(16) - 8;
            int j1 = j + this.world.random.nextInt(6) - 3;
            int k1 = k + this.world.random.nextInt(16) - 8;

            if (this.f.a(i1, j1, k1) && SpawnerCreature.a(EnumCreatureType.MONSTER, this.world, i1, j1, k1)) {
                return this.world.getVec3DPool().create((double) i1, (double) j1, (double) k1);
            }
        }

        return null;
    }
}