summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/WorldGenVillagePieces.java
blob: e08c6fe2ac500f0e98316c435cc83e83b5177154 (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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
package net.minecraft.server;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;

public class WorldGenVillagePieces {

    public static void a() {
        WorldGenFactory.a(WorldGenVillageLibrary.class, "ViBH");
        WorldGenFactory.a(WorldGenVillageFarm2.class, "ViDF");
        WorldGenFactory.a(WorldGenVillageFarm.class, "ViF");
        WorldGenFactory.a(WorldGenVillageLight.class, "ViL");
        WorldGenFactory.a(WorldGenVillageButcher.class, "ViPH");
        WorldGenFactory.a(WorldGenVillageHouse.class, "ViSH");
        WorldGenFactory.a(WorldGenVillageHut.class, "ViSmH");
        WorldGenFactory.a(WorldGenVillageTemple.class, "ViST");
        WorldGenFactory.a(WorldGenVillageBlacksmith.class, "ViS");
        WorldGenFactory.a(WorldGenVillageStartPiece.class, "ViStart");
        WorldGenFactory.a(WorldGenVillageRoad.class, "ViSR");
        WorldGenFactory.a(WorldGenVillageHouse2.class, "ViTRH");
        WorldGenFactory.a(WorldGenVillageWell.class, "ViW");
    }

    public static List a(Random random, int i) {
        ArrayList arraylist = new ArrayList();

        arraylist.add(new WorldGenVillagePieceWeight(WorldGenVillageHouse.class, 4, MathHelper.nextInt(random, 2 + i, 4 + i * 2)));
        arraylist.add(new WorldGenVillagePieceWeight(WorldGenVillageTemple.class, 20, MathHelper.nextInt(random, 0 + i, 1 + i)));
        arraylist.add(new WorldGenVillagePieceWeight(WorldGenVillageLibrary.class, 20, MathHelper.nextInt(random, 0 + i, 2 + i)));
        arraylist.add(new WorldGenVillagePieceWeight(WorldGenVillageHut.class, 3, MathHelper.nextInt(random, 2 + i, 5 + i * 3)));
        arraylist.add(new WorldGenVillagePieceWeight(WorldGenVillageButcher.class, 15, MathHelper.nextInt(random, 0 + i, 2 + i)));
        arraylist.add(new WorldGenVillagePieceWeight(WorldGenVillageFarm2.class, 3, MathHelper.nextInt(random, 1 + i, 4 + i)));
        arraylist.add(new WorldGenVillagePieceWeight(WorldGenVillageFarm.class, 3, MathHelper.nextInt(random, 2 + i, 4 + i * 2)));
        arraylist.add(new WorldGenVillagePieceWeight(WorldGenVillageBlacksmith.class, 15, MathHelper.nextInt(random, 0, 1 + i)));
        arraylist.add(new WorldGenVillagePieceWeight(WorldGenVillageHouse2.class, 8, MathHelper.nextInt(random, 0 + i, 3 + i * 2)));
        Iterator iterator = arraylist.iterator();

        while (iterator.hasNext()) {
            if (((WorldGenVillagePieceWeight) iterator.next()).d == 0) {
                iterator.remove();
            }
        }

        return arraylist;
    }

    private static int a(List list) {
        boolean flag = false;
        int i = 0;

        WorldGenVillagePieceWeight worldgenvillagepieceweight;

        for (Iterator iterator = list.iterator(); iterator.hasNext(); i += worldgenvillagepieceweight.b) {
            worldgenvillagepieceweight = (WorldGenVillagePieceWeight) iterator.next();
            if (worldgenvillagepieceweight.d > 0 && worldgenvillagepieceweight.c < worldgenvillagepieceweight.d) {
                flag = true;
            }
        }

        return flag ? i : -1;
    }

    private static WorldGenVillagePiece a(WorldGenVillageStartPiece worldgenvillagestartpiece, WorldGenVillagePieceWeight worldgenvillagepieceweight, List list, Random random, int i, int j, int k, int l, int i1) {
        Class oclass = worldgenvillagepieceweight.a;
        Object object = null;

        if (oclass == WorldGenVillageHouse.class) {
            object = WorldGenVillageHouse.a(worldgenvillagestartpiece, list, random, i, j, k, l, i1);
        } else if (oclass == WorldGenVillageTemple.class) {
            object = WorldGenVillageTemple.a(worldgenvillagestartpiece, list, random, i, j, k, l, i1);
        } else if (oclass == WorldGenVillageLibrary.class) {
            object = WorldGenVillageLibrary.a(worldgenvillagestartpiece, list, random, i, j, k, l, i1);
        } else if (oclass == WorldGenVillageHut.class) {
            object = WorldGenVillageHut.a(worldgenvillagestartpiece, list, random, i, j, k, l, i1);
        } else if (oclass == WorldGenVillageButcher.class) {
            object = WorldGenVillageButcher.a(worldgenvillagestartpiece, list, random, i, j, k, l, i1);
        } else if (oclass == WorldGenVillageFarm2.class) {
            object = WorldGenVillageFarm2.a(worldgenvillagestartpiece, list, random, i, j, k, l, i1);
        } else if (oclass == WorldGenVillageFarm.class) {
            object = WorldGenVillageFarm.a(worldgenvillagestartpiece, list, random, i, j, k, l, i1);
        } else if (oclass == WorldGenVillageBlacksmith.class) {
            object = WorldGenVillageBlacksmith.a(worldgenvillagestartpiece, list, random, i, j, k, l, i1);
        } else if (oclass == WorldGenVillageHouse2.class) {
            object = WorldGenVillageHouse2.a(worldgenvillagestartpiece, list, random, i, j, k, l, i1);
        }

        return (WorldGenVillagePiece) object;
    }

    private static WorldGenVillagePiece c(WorldGenVillageStartPiece worldgenvillagestartpiece, List list, Random random, int i, int j, int k, int l, int i1) {
        int j1 = a(worldgenvillagestartpiece.e);

        if (j1 <= 0) {
            return null;
        } else {
            int k1 = 0;

            while (k1 < 5) {
                ++k1;
                int l1 = random.nextInt(j1);
                Iterator iterator = worldgenvillagestartpiece.e.iterator();

                while (iterator.hasNext()) {
                    WorldGenVillagePieceWeight worldgenvillagepieceweight = (WorldGenVillagePieceWeight) iterator.next();

                    l1 -= worldgenvillagepieceweight.b;
                    if (l1 < 0) {
                        if (!worldgenvillagepieceweight.a(i1) || worldgenvillagepieceweight == worldgenvillagestartpiece.d && worldgenvillagestartpiece.e.size() > 1) {
                            break;
                        }

                        WorldGenVillagePiece worldgenvillagepiece = a(worldgenvillagestartpiece, worldgenvillagepieceweight, list, random, i, j, k, l, i1);

                        if (worldgenvillagepiece != null) {
                            ++worldgenvillagepieceweight.c;
                            worldgenvillagestartpiece.d = worldgenvillagepieceweight;
                            if (!worldgenvillagepieceweight.a()) {
                                worldgenvillagestartpiece.e.remove(worldgenvillagepieceweight);
                            }

                            return worldgenvillagepiece;
                        }
                    }
                }
            }

            StructureBoundingBox structureboundingbox = WorldGenVillageLight.a(worldgenvillagestartpiece, list, random, i, j, k, l);

            if (structureboundingbox != null) {
                return new WorldGenVillageLight(worldgenvillagestartpiece, i1, random, structureboundingbox, l);
            } else {
                return null;
            }
        }
    }

    private static StructurePiece d(WorldGenVillageStartPiece worldgenvillagestartpiece, List list, Random random, int i, int j, int k, int l, int i1) {
        if (i1 > 50) {
            return null;
        } else if (Math.abs(i - worldgenvillagestartpiece.c().a) <= 112 && Math.abs(k - worldgenvillagestartpiece.c().c) <= 112) {
            WorldGenVillagePiece worldgenvillagepiece = c(worldgenvillagestartpiece, list, random, i, j, k, l, i1 + 1);

            if (worldgenvillagepiece != null) {
                int j1 = (worldgenvillagepiece.f.a + worldgenvillagepiece.f.d) / 2;
                int k1 = (worldgenvillagepiece.f.c + worldgenvillagepiece.f.f) / 2;
                int l1 = worldgenvillagepiece.f.d - worldgenvillagepiece.f.a;
                int i2 = worldgenvillagepiece.f.f - worldgenvillagepiece.f.c;
                int j2 = l1 > i2 ? l1 : i2;

                if (worldgenvillagestartpiece.e().a(j1, k1, j2 / 2 + 4, WorldGenVillage.e)) {
                    list.add(worldgenvillagepiece);
                    worldgenvillagestartpiece.i.add(worldgenvillagepiece);
                    return worldgenvillagepiece;
                }
            }

            return null;
        } else {
            return null;
        }
    }

    private static StructurePiece e(WorldGenVillageStartPiece worldgenvillagestartpiece, List list, Random random, int i, int j, int k, int l, int i1) {
        if (i1 > 3 + worldgenvillagestartpiece.c) {
            return null;
        } else if (Math.abs(i - worldgenvillagestartpiece.c().a) <= 112 && Math.abs(k - worldgenvillagestartpiece.c().c) <= 112) {
            StructureBoundingBox structureboundingbox = WorldGenVillageRoad.a(worldgenvillagestartpiece, list, random, i, j, k, l);

            if (structureboundingbox != null && structureboundingbox.b > 10) {
                WorldGenVillageRoad worldgenvillageroad = new WorldGenVillageRoad(worldgenvillagestartpiece, i1, random, structureboundingbox, l);
                int j1 = (worldgenvillageroad.f.a + worldgenvillageroad.f.d) / 2;
                int k1 = (worldgenvillageroad.f.c + worldgenvillageroad.f.f) / 2;
                int l1 = worldgenvillageroad.f.d - worldgenvillageroad.f.a;
                int i2 = worldgenvillageroad.f.f - worldgenvillageroad.f.c;
                int j2 = l1 > i2 ? l1 : i2;

                if (worldgenvillagestartpiece.e().a(j1, k1, j2 / 2 + 4, WorldGenVillage.e)) {
                    list.add(worldgenvillageroad);
                    worldgenvillagestartpiece.j.add(worldgenvillageroad);
                    return worldgenvillageroad;
                }
            }

            return null;
        } else {
            return null;
        }
    }

    static StructurePiece a(WorldGenVillageStartPiece worldgenvillagestartpiece, List list, Random random, int i, int j, int k, int l, int i1) {
        return d(worldgenvillagestartpiece, list, random, i, j, k, l, i1);
    }

    static StructurePiece b(WorldGenVillageStartPiece worldgenvillagestartpiece, List list, Random random, int i, int j, int k, int l, int i1) {
        return e(worldgenvillagestartpiece, list, random, i, j, k, l, i1);
    }
}