summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/BlockRedstoneWire.java
blob: 7caebbc3020c6bf54573d1dce959a90c03c6e108 (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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
package net.minecraft.server;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;

// CraftBukkit start
import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.event.block.BlockRedstoneEvent;
// CraftBukkit end

public class BlockRedstoneWire extends Block {

    private boolean a = true;
    private Set b = new HashSet();

    public BlockRedstoneWire(int i, int j) {
        super(i, j, Material.ORIENTABLE);
        this.a(0.0F, 0.0F, 0.0F, 1.0F, 0.0625F, 1.0F);
    }

    public int a(int i, int j) {
        return this.textureId;
    }

    public AxisAlignedBB d(World world, int i, int j, int k) {
        return null;
    }

    public boolean a() {
        return false;
    }

    public boolean a(World world, int i, int j, int k) {
        return world.d(i, j - 1, k);
    }

    private void g(World world, int i, int j, int k) {
        this.a(world, i, j, k, i, j, k);
        ArrayList arraylist = new ArrayList(this.b);

        this.b.clear();

        for (int l = 0; l < arraylist.size(); ++l) {
            ChunkPosition chunkposition = (ChunkPosition) arraylist.get(l);

            world.h(chunkposition.a, chunkposition.b, chunkposition.c, this.id);
        }
    }

    private void a(World world, int i, int j, int k, int l, int i1, int j1) {
        int k1 = world.getData(i, j, k);
        int l1 = 0;

        this.a = false;
        boolean flag = world.p(i, j, k);

        this.a = true;
        int i2;
        int j2;
        int k2;

        if (flag) {
            l1 = 15;
        } else {
            for (i2 = 0; i2 < 4; ++i2) {
                j2 = i;
                k2 = k;
                if (i2 == 0) {
                    j2 = i - 1;
                }

                if (i2 == 1) {
                    ++j2;
                }

                if (i2 == 2) {
                    k2 = k - 1;
                }

                if (i2 == 3) {
                    ++k2;
                }

                if (j2 != l || j != i1 || k2 != j1) {
                    l1 = this.g(world, j2, j, k2, l1);
                }

                if (world.d(j2, j, k2) && !world.d(i, j + 1, k)) {
                    if (j2 != l || j + 1 != i1 || k2 != j1) {
                        l1 = this.g(world, j2, j + 1, k2, l1);
                    }
                } else if (!world.d(j2, j, k2) && (j2 != l || j - 1 != i1 || k2 != j1)) {
                    l1 = this.g(world, j2, j - 1, k2, l1);
                }
            }

            if (l1 > 0) {
                --l1;
            } else {
                l1 = 0;
            }
        }

        // CraftBukkit start
        if (k1 != l1) {
            CraftBlock block = (CraftBlock) ((WorldServer) world).getWorld().getBlockAt(i, j, k);
            BlockRedstoneEvent event = new BlockRedstoneEvent(block, k1, l1);
            ((WorldServer) world).getServer().getPluginManager().callEvent(event);
            l1 = event.getNewCurrent();
        }
        // CraftBukkit end

        if (k1 != l1) {
            world.h = true;
            world.c(i, j, k, l1);
            world.b(i, j, k, i, j, k);
            world.h = false;

            for (i2 = 0; i2 < 4; ++i2) {
                j2 = i;
                k2 = k;
                int l2 = j - 1;

                if (i2 == 0) {
                    j2 = i - 1;
                }

                if (i2 == 1) {
                    ++j2;
                }

                if (i2 == 2) {
                    k2 = k - 1;
                }

                if (i2 == 3) {
                    ++k2;
                }

                if (world.d(j2, j, k2)) {
                    l2 += 2;
                }

                boolean flag1 = false;
                int i3 = this.g(world, j2, j, k2, -1);

                l1 = world.getData(i, j, k);
                if (l1 > 0) {
                    --l1;
                }

                if (i3 >= 0 && i3 != l1) {
                    this.a(world, j2, j, k2, i, j, k);
                }

                i3 = this.g(world, j2, l2, k2, -1);
                l1 = world.getData(i, j, k);
                if (l1 > 0) {
                    --l1;
                }

                if (i3 >= 0 && i3 != l1) {
                    this.a(world, j2, l2, k2, i, j, k);
                }
            }

            if (k1 == 0 || l1 == 0) {
                this.b.add(new ChunkPosition(i, j, k));
                this.b.add(new ChunkPosition(i - 1, j, k));
                this.b.add(new ChunkPosition(i + 1, j, k));
                this.b.add(new ChunkPosition(i, j - 1, k));
                this.b.add(new ChunkPosition(i, j + 1, k));
                this.b.add(new ChunkPosition(i, j, k - 1));
                this.b.add(new ChunkPosition(i, j, k + 1));
            }
        }
    }

    private void h(World world, int i, int j, int k) {
        if (world.getTypeId(i, j, k) == this.id) {
            world.h(i, j, k, this.id);
            world.h(i - 1, j, k, this.id);
            world.h(i + 1, j, k, this.id);
            world.h(i, j, k - 1, this.id);
            world.h(i, j, k + 1, this.id);
            world.h(i, j - 1, k, this.id);
            world.h(i, j + 1, k, this.id);
        }
    }

    public void e(World world, int i, int j, int k) {
        super.e(world, i, j, k);
        if (!world.isStatic) {
            this.g(world, i, j, k);
            world.h(i, j + 1, k, this.id);
            world.h(i, j - 1, k, this.id);
            this.h(world, i - 1, j, k);
            this.h(world, i + 1, j, k);
            this.h(world, i, j, k - 1);
            this.h(world, i, j, k + 1);
            if (world.d(i - 1, j, k)) {
                this.h(world, i - 1, j + 1, k);
            } else {
                this.h(world, i - 1, j - 1, k);
            }

            if (world.d(i + 1, j, k)) {
                this.h(world, i + 1, j + 1, k);
            } else {
                this.h(world, i + 1, j - 1, k);
            }

            if (world.d(i, j, k - 1)) {
                this.h(world, i, j + 1, k - 1);
            } else {
                this.h(world, i, j - 1, k - 1);
            }

            if (world.d(i, j, k + 1)) {
                this.h(world, i, j + 1, k + 1);
            } else {
                this.h(world, i, j - 1, k + 1);
            }
        }
    }

    public void b(World world, int i, int j, int k) {
        super.b(world, i, j, k);
        if (!world.isStatic) {
            world.h(i, j + 1, k, this.id);
            world.h(i, j - 1, k, this.id);
            this.g(world, i, j, k);
            this.h(world, i - 1, j, k);
            this.h(world, i + 1, j, k);
            this.h(world, i, j, k - 1);
            this.h(world, i, j, k + 1);
            if (world.d(i - 1, j, k)) {
                this.h(world, i - 1, j + 1, k);
            } else {
                this.h(world, i - 1, j - 1, k);
            }

            if (world.d(i + 1, j, k)) {
                this.h(world, i + 1, j + 1, k);
            } else {
                this.h(world, i + 1, j - 1, k);
            }

            if (world.d(i, j, k - 1)) {
                this.h(world, i, j + 1, k - 1);
            } else {
                this.h(world, i, j - 1, k - 1);
            }

            if (world.d(i, j, k + 1)) {
                this.h(world, i, j + 1, k + 1);
            } else {
                this.h(world, i, j - 1, k + 1);
            }
        }
    }

    public int g(World world, int i, int j, int k, int l) { // Craftbukkit made public
        if (world.getTypeId(i, j, k) != this.id) {
            return l;
        } else {
            int i1 = world.getData(i, j, k);

            return i1 > l ? i1 : l;
        }
    }

    public void a(World world, int i, int j, int k, int l) {
        if (!world.isStatic) {
            int i1 = world.getData(i, j, k);
            boolean flag = this.a(world, i, j, k);

            if (!flag) {
                this.b_(world, i, j, k, i1);
                world.e(i, j, k, 0);
            } else 
            // Craftbukkit
            if ((Block.byId[l] != null && Block.byId[l].c()) || Block.DIODE_OFF.id == l || Block.DIODE_ON.id == l) { 
                this.g(world, i, j, k);
            }

            super.a(world, i, j, k, l);
        }
    }

    public int a(int i, Random random) {
        return Item.REDSTONE.id;
    }

    public boolean c(World world, int i, int j, int k, int l) {
        // CraftBukkit -- cast to IBlockAccess
        return !this.a ? false : this.b((IBlockAccess) world, i, j, k, l);
    }

    public boolean b(IBlockAccess iblockaccess, int i, int j, int k, int l) {
        if (!this.a) {
            return false;
        } else if (iblockaccess.getData(i, j, k) == 0) {
            return false;
        } else if (l == 1) {
            return true;
        } else {
            boolean flag = b(iblockaccess, i - 1, j, k) || !iblockaccess.d(i - 1, j, k) && b(iblockaccess, i - 1, j - 1, k);
            boolean flag1 = b(iblockaccess, i + 1, j, k) || !iblockaccess.d(i + 1, j, k) && b(iblockaccess, i + 1, j - 1, k);
            boolean flag2 = b(iblockaccess, i, j, k - 1) || !iblockaccess.d(i, j, k - 1) && b(iblockaccess, i, j - 1, k - 1);
            boolean flag3 = b(iblockaccess, i, j, k + 1) || !iblockaccess.d(i, j, k + 1) && b(iblockaccess, i, j - 1, k + 1);

            if (!iblockaccess.d(i, j + 1, k)) {
                if (iblockaccess.d(i - 1, j, k) && b(iblockaccess, i - 1, j + 1, k)) {
                    flag = true;
                }

                if (iblockaccess.d(i + 1, j, k) && b(iblockaccess, i + 1, j + 1, k)) {
                    flag1 = true;
                }

                if (iblockaccess.d(i, j, k - 1) && b(iblockaccess, i, j + 1, k - 1)) {
                    flag2 = true;
                }

                if (iblockaccess.d(i, j, k + 1) && b(iblockaccess, i, j + 1, k + 1)) {
                    flag3 = true;
                }
            }

            return !flag2 && !flag1 && !flag && !flag3 && l >= 2 && l <= 5 ? true : (l == 2 && flag2 && !flag && !flag1 ? true : (l == 3 && flag3 && !flag && !flag1 ? true : (l == 4 && flag && !flag2 && !flag3 ? true : l == 5 && flag1 && !flag2 && !flag3)));
        }
    }

    public boolean c() {
        return this.a;
    }

    public static boolean b(IBlockAccess iblockaccess, int i, int j, int k) {
        int l = iblockaccess.getTypeId(i, j, k);

        return l == Block.REDSTONE_WIRE.id ? true : (l == 0 ? false : Block.byId[l].c());
    }
}