-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlockRedstoneWire.java
More file actions
449 lines (423 loc) · 14.4 KB
/
BlockRedstoneWire.java
File metadata and controls
449 lines (423 loc) · 14.4 KB
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
package net.minecraft.src;
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) braces deadcode
import java.util.*;
public class BlockRedstoneWire extends Block
{
public BlockRedstoneWire(int i, int j)
{
super(i, j, Material.circuits);
wiresProvidePower = true;
field_21031_b = new HashSet();
setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.0625F, 1.0F);
}
public int getBlockTextureFromSideAndMetadata(int i, int j)
{
return blockIndexInTexture;
}
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int i, int j, int k)
{
return null;
}
public boolean isOpaqueCube()
{
return false;
}
public boolean renderAsNormalBlock()
{
return false;
}
public int getRenderType()
{
return 5;
}
public boolean canPlaceBlockAt(World world, int i, int j, int k)
{
return world.isBlockOpaqueCube(i, j - 1, k);
}
private void updateAndPropagateCurrentStrength(World world, int i, int j, int k)
{
func_21030_a(world, i, j, k, i, j, k);
ArrayList arraylist = new ArrayList(field_21031_b);
field_21031_b.clear();
for(int l = 0; l < arraylist.size(); l++)
{
ChunkPosition chunkposition = (ChunkPosition)arraylist.get(l);
world.notifyBlocksOfNeighborChange(chunkposition.x, chunkposition.y, chunkposition.z, blockID);
}
}
private void func_21030_a(World world, int i, int j, int k, int l, int i1, int j1)
{
int k1 = world.getBlockMetadata(i, j, k);
int l1 = 0;
wiresProvidePower = false;
boolean flag = world.isBlockIndirectlyGettingPowered(i, j, k);
wiresProvidePower = true;
if(flag)
{
l1 = 15;
} else
{
for(int i2 = 0; i2 < 4; i2++)
{
int k2 = i;
int i3 = k;
if(i2 == 0)
{
k2--;
}
if(i2 == 1)
{
k2++;
}
if(i2 == 2)
{
i3--;
}
if(i2 == 3)
{
i3++;
}
if(k2 != l || j != i1 || i3 != j1)
{
l1 = getMaxCurrentStrength(world, k2, j, i3, l1);
}
if(world.isBlockOpaqueCube(k2, j, i3) && !world.isBlockOpaqueCube(i, j + 1, k))
{
if(k2 != l || j + 1 != i1 || i3 != j1)
{
l1 = getMaxCurrentStrength(world, k2, j + 1, i3, l1);
}
continue;
}
if(!world.isBlockOpaqueCube(k2, j, i3) && (k2 != l || j - 1 != i1 || i3 != j1))
{
l1 = getMaxCurrentStrength(world, k2, j - 1, i3, l1);
}
}
if(l1 > 0)
{
l1--;
} else
{
l1 = 0;
}
}
if(k1 != l1)
{
world.field_1043_h = true;
world.setBlockMetadataWithNotify(i, j, k, l1);
world.markBlocksDirty(i, j, k, i, j, k);
world.field_1043_h = false;
for(int j2 = 0; j2 < 4; j2++)
{
int l2 = i;
int j3 = k;
int k3 = j - 1;
if(j2 == 0)
{
l2--;
}
if(j2 == 1)
{
l2++;
}
if(j2 == 2)
{
j3--;
}
if(j2 == 3)
{
j3++;
}
if(world.isBlockOpaqueCube(l2, j, j3))
{
k3 += 2;
}
int l3 = 0;
l3 = getMaxCurrentStrength(world, l2, j, j3, -1);
l1 = world.getBlockMetadata(i, j, k);
if(l1 > 0)
{
l1--;
}
if(l3 >= 0 && l3 != l1)
{
func_21030_a(world, l2, j, j3, i, j, k);
}
l3 = getMaxCurrentStrength(world, l2, k3, j3, -1);
l1 = world.getBlockMetadata(i, j, k);
if(l1 > 0)
{
l1--;
}
if(l3 >= 0 && l3 != l1)
{
func_21030_a(world, l2, k3, j3, i, j, k);
}
}
if(k1 == 0 || l1 == 0)
{
field_21031_b.add(new ChunkPosition(i, j, k));
field_21031_b.add(new ChunkPosition(i - 1, j, k));
field_21031_b.add(new ChunkPosition(i + 1, j, k));
field_21031_b.add(new ChunkPosition(i, j - 1, k));
field_21031_b.add(new ChunkPosition(i, j + 1, k));
field_21031_b.add(new ChunkPosition(i, j, k - 1));
field_21031_b.add(new ChunkPosition(i, j, k + 1));
}
}
}
private void notifyWireNeighborsOfNeighborChange(World world, int i, int j, int k)
{
if(world.getBlockId(i, j, k) != blockID)
{
return;
} else
{
world.notifyBlocksOfNeighborChange(i, j, k, blockID);
world.notifyBlocksOfNeighborChange(i - 1, j, k, blockID);
world.notifyBlocksOfNeighborChange(i + 1, j, k, blockID);
world.notifyBlocksOfNeighborChange(i, j, k - 1, blockID);
world.notifyBlocksOfNeighborChange(i, j, k + 1, blockID);
world.notifyBlocksOfNeighborChange(i, j - 1, k, blockID);
world.notifyBlocksOfNeighborChange(i, j + 1, k, blockID);
return;
}
}
public void onBlockAdded(World world, int i, int j, int k)
{
super.onBlockAdded(world, i, j, k);
if(world.multiplayerWorld)
{
return;
}
updateAndPropagateCurrentStrength(world, i, j, k);
world.notifyBlocksOfNeighborChange(i, j + 1, k, blockID);
world.notifyBlocksOfNeighborChange(i, j - 1, k, blockID);
notifyWireNeighborsOfNeighborChange(world, i - 1, j, k);
notifyWireNeighborsOfNeighborChange(world, i + 1, j, k);
notifyWireNeighborsOfNeighborChange(world, i, j, k - 1);
notifyWireNeighborsOfNeighborChange(world, i, j, k + 1);
if(world.isBlockOpaqueCube(i - 1, j, k))
{
notifyWireNeighborsOfNeighborChange(world, i - 1, j + 1, k);
} else
{
notifyWireNeighborsOfNeighborChange(world, i - 1, j - 1, k);
}
if(world.isBlockOpaqueCube(i + 1, j, k))
{
notifyWireNeighborsOfNeighborChange(world, i + 1, j + 1, k);
} else
{
notifyWireNeighborsOfNeighborChange(world, i + 1, j - 1, k);
}
if(world.isBlockOpaqueCube(i, j, k - 1))
{
notifyWireNeighborsOfNeighborChange(world, i, j + 1, k - 1);
} else
{
notifyWireNeighborsOfNeighborChange(world, i, j - 1, k - 1);
}
if(world.isBlockOpaqueCube(i, j, k + 1))
{
notifyWireNeighborsOfNeighborChange(world, i, j + 1, k + 1);
} else
{
notifyWireNeighborsOfNeighborChange(world, i, j - 1, k + 1);
}
}
public void onBlockRemoval(World world, int i, int j, int k)
{
super.onBlockRemoval(world, i, j, k);
if(world.multiplayerWorld)
{
return;
}
world.notifyBlocksOfNeighborChange(i, j + 1, k, blockID);
world.notifyBlocksOfNeighborChange(i, j - 1, k, blockID);
updateAndPropagateCurrentStrength(world, i, j, k);
notifyWireNeighborsOfNeighborChange(world, i - 1, j, k);
notifyWireNeighborsOfNeighborChange(world, i + 1, j, k);
notifyWireNeighborsOfNeighborChange(world, i, j, k - 1);
notifyWireNeighborsOfNeighborChange(world, i, j, k + 1);
if(world.isBlockOpaqueCube(i - 1, j, k))
{
notifyWireNeighborsOfNeighborChange(world, i - 1, j + 1, k);
} else
{
notifyWireNeighborsOfNeighborChange(world, i - 1, j - 1, k);
}
if(world.isBlockOpaqueCube(i + 1, j, k))
{
notifyWireNeighborsOfNeighborChange(world, i + 1, j + 1, k);
} else
{
notifyWireNeighborsOfNeighborChange(world, i + 1, j - 1, k);
}
if(world.isBlockOpaqueCube(i, j, k - 1))
{
notifyWireNeighborsOfNeighborChange(world, i, j + 1, k - 1);
} else
{
notifyWireNeighborsOfNeighborChange(world, i, j - 1, k - 1);
}
if(world.isBlockOpaqueCube(i, j, k + 1))
{
notifyWireNeighborsOfNeighborChange(world, i, j + 1, k + 1);
} else
{
notifyWireNeighborsOfNeighborChange(world, i, j - 1, k + 1);
}
}
private int getMaxCurrentStrength(World world, int i, int j, int k, int l)
{
if(world.getBlockId(i, j, k) != blockID)
{
return l;
}
int i1 = world.getBlockMetadata(i, j, k);
if(i1 > l)
{
return i1;
} else
{
return l;
}
}
public void onNeighborBlockChange(World world, int i, int j, int k, int l)
{
if(world.multiplayerWorld)
{
return;
}
int i1 = world.getBlockMetadata(i, j, k);
boolean flag = canPlaceBlockAt(world, i, j, k);
if(!flag)
{
dropBlockAsItem(world, i, j, k, i1);
world.setBlockWithNotify(i, j, k, 0);
} else
{
updateAndPropagateCurrentStrength(world, i, j, k);
}
super.onNeighborBlockChange(world, i, j, k, l);
}
public int idDropped(int i, Random random)
{
return Item.redstone.shiftedIndex;
}
public boolean isIndirectlyPoweringTo(World world, int i, int j, int k, int l)
{
if(!wiresProvidePower)
{
return false;
} else
{
return isPoweringTo(world, i, j, k, l);
}
}
public boolean isPoweringTo(IBlockAccess iblockaccess, int i, int j, int k, int l)
{
if(!wiresProvidePower)
{
return false;
}
if(iblockaccess.getBlockMetadata(i, j, k) == 0)
{
return false;
}
if(l == 1)
{
return true;
}
boolean flag = isPowerProviderOrWire(iblockaccess, i - 1, j, k) || !iblockaccess.isBlockOpaqueCube(i - 1, j, k) && isPowerProviderOrWire(iblockaccess, i - 1, j - 1, k);
boolean flag1 = isPowerProviderOrWire(iblockaccess, i + 1, j, k) || !iblockaccess.isBlockOpaqueCube(i + 1, j, k) && isPowerProviderOrWire(iblockaccess, i + 1, j - 1, k);
boolean flag2 = isPowerProviderOrWire(iblockaccess, i, j, k - 1) || !iblockaccess.isBlockOpaqueCube(i, j, k - 1) && isPowerProviderOrWire(iblockaccess, i, j - 1, k - 1);
boolean flag3 = isPowerProviderOrWire(iblockaccess, i, j, k + 1) || !iblockaccess.isBlockOpaqueCube(i, j, k + 1) && isPowerProviderOrWire(iblockaccess, i, j - 1, k + 1);
if(!iblockaccess.isBlockOpaqueCube(i, j + 1, k))
{
if(iblockaccess.isBlockOpaqueCube(i - 1, j, k) && isPowerProviderOrWire(iblockaccess, i - 1, j + 1, k))
{
flag = true;
}
if(iblockaccess.isBlockOpaqueCube(i + 1, j, k) && isPowerProviderOrWire(iblockaccess, i + 1, j + 1, k))
{
flag1 = true;
}
if(iblockaccess.isBlockOpaqueCube(i, j, k - 1) && isPowerProviderOrWire(iblockaccess, i, j + 1, k - 1))
{
flag2 = true;
}
if(iblockaccess.isBlockOpaqueCube(i, j, k + 1) && isPowerProviderOrWire(iblockaccess, i, j + 1, k + 1))
{
flag3 = true;
}
}
if(!flag2 && !flag1 && !flag && !flag3 && l >= 2 && l <= 5)
{
return true;
}
if(l == 2 && flag2 && !flag && !flag1)
{
return true;
}
if(l == 3 && flag3 && !flag && !flag1)
{
return true;
}
if(l == 4 && flag && !flag2 && !flag3)
{
return true;
}
return l == 5 && flag1 && !flag2 && !flag3;
}
public boolean canProvidePower()
{
return wiresProvidePower;
}
public void randomDisplayTick(World world, int i, int j, int k, Random random)
{
int l = world.getBlockMetadata(i, j, k);
if(l > 0)
{
double d = (double)i + 0.5D + ((double)random.nextFloat() - 0.5D) * 0.20000000000000001D;
double d1 = (float)j + 0.0625F;
double d2 = (double)k + 0.5D + ((double)random.nextFloat() - 0.5D) * 0.20000000000000001D;
float f = (float)l / 15F;
float f1 = f * 0.6F + 0.4F;
if(l == 0)
{
f1 = 0.0F;
}
float f2 = f * f * 0.7F - 0.5F;
float f3 = f * f * 0.6F - 0.7F;
if(f2 < 0.0F)
{
f2 = 0.0F;
}
if(f3 < 0.0F)
{
f3 = 0.0F;
}
world.spawnParticle("reddust", d, d1, d2, f1, f2, f3);
}
}
public static boolean isPowerProviderOrWire(IBlockAccess iblockaccess, int i, int j, int k)
{
int l = iblockaccess.getBlockId(i, j, k);
if(l == Block.redstoneWire.blockID)
{
return true;
}
if(l == 0)
{
return false;
}
return Block.blocksList[l].canProvidePower();
}
private boolean wiresProvidePower;
private Set field_21031_b;
}