-
Notifications
You must be signed in to change notification settings - Fork 497
/
BlockGenericPipe.java
637 lines (494 loc) · 19.4 KB
/
BlockGenericPipe.java
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
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.transport;
import java.util.List;
import java.util.Random;
import java.util.TreeMap;
import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly;
import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftTransport;
import net.minecraftforge.common.ForgeDirection;
import buildcraft.api.tools.IToolWrench;
import buildcraft.api.transport.IPipe;
import buildcraft.core.BlockIndex;
import buildcraft.core.DefaultProps;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.Utils;
import buildcraft.transport.render.PipeWorldRenderer;
import net.minecraft.src.AxisAlignedBB;
import net.minecraft.src.BlockContainer;
import net.minecraft.src.Entity;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.IBlockAccess;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraft.src.Material;
import net.minecraft.src.MovingObjectPosition;
import net.minecraft.src.TileEntity;
import net.minecraft.src.Vec3;
import net.minecraft.src.World;
public class BlockGenericPipe extends BlockContainer {
/* Defined subprograms **************************************************/
public BlockGenericPipe(int i) {
super(i, Material.glass);
}
@Override
public float getBlockHardness(World par1World, int par2, int par3, int par4) {
return BuildCraftTransport.pipeDuribility;
}
@Override
public int getRenderType() {
return TransportProxy.pipeModel;
}
@Override
public boolean isOpaqueCube() {
return false;
}
@Override
public boolean canBeReplacedByLeaves(World world, int x, int y, int z) {
return false;
}
@Override
public boolean renderAsNormalBlock() {
return false;
}
public boolean isACube() {
return false;
}
@SuppressWarnings("rawtypes")
@Override
public void addCollidingBlockToList(World world, int i, int j, int k, AxisAlignedBB axisalignedbb, List arraylist, Entity par7Entity) {
setBlockBounds(Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMaxPos, Utils.pipeMaxPos, Utils.pipeMaxPos);
super.addCollidingBlockToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
TileEntity tile1 = world.getBlockTileEntity(i, j, k);
TileGenericPipe tileG = (TileGenericPipe) tile1;
if (Utils.checkPipesConnections(world, tile1, i - 1, j, k)) {
setBlockBounds(0.0F, Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMaxPos, Utils.pipeMaxPos, Utils.pipeMaxPos);
super.addCollidingBlockToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (Utils.checkPipesConnections(world, tile1, i + 1, j, k)) {
setBlockBounds(Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMinPos, 1.0F, Utils.pipeMaxPos, Utils.pipeMaxPos);
super.addCollidingBlockToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (Utils.checkPipesConnections(world, tile1, i, j - 1, k)) {
setBlockBounds(Utils.pipeMinPos, 0.0F, Utils.pipeMinPos, Utils.pipeMaxPos, Utils.pipeMaxPos, Utils.pipeMaxPos);
super.addCollidingBlockToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (Utils.checkPipesConnections(world, tile1, i, j + 1, k)) {
setBlockBounds(Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMaxPos, 1.0F, Utils.pipeMaxPos);
super.addCollidingBlockToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (Utils.checkPipesConnections(world, tile1, i, j, k - 1)) {
setBlockBounds(Utils.pipeMinPos, Utils.pipeMinPos, 0.0F, Utils.pipeMaxPos, Utils.pipeMaxPos, Utils.pipeMaxPos);
super.addCollidingBlockToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (Utils.checkPipesConnections(world, tile1, i, j, k + 1)) {
setBlockBounds(Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMaxPos, Utils.pipeMaxPos, 1.0F);
super.addCollidingBlockToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (tileG != null) {
float facadeThickness = PipeWorldRenderer.facadeThickness;
if (tileG.hasFacade(ForgeDirection.EAST)) {
setBlockBounds(1 - facadeThickness, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
super.addCollidingBlockToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (tileG.hasFacade(ForgeDirection.WEST)) {
setBlockBounds(0.0F, 0.0F, 0.0F, facadeThickness, 1.0F, 1.0F);
super.addCollidingBlockToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (tileG.hasFacade(ForgeDirection.UP)) {
setBlockBounds(0.0F, 1 - facadeThickness, 0.0F, 1.0F, 1.0F, 1.0F);
super.addCollidingBlockToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (tileG.hasFacade(ForgeDirection.DOWN)) {
setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, facadeThickness, 1.0F);
super.addCollidingBlockToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (tileG.hasFacade(ForgeDirection.SOUTH)) {
setBlockBounds(0.0F, 0.0F, 1 - facadeThickness, 1.0F, 1.0F, 1.0F);
super.addCollidingBlockToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (tileG.hasFacade(ForgeDirection.NORTH)) {
setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, facadeThickness);
super.addCollidingBlockToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
}
setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
@Override
public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int i, int j, int k) {
float xMin = Utils.pipeMinPos, xMax = Utils.pipeMaxPos, yMin = Utils.pipeMinPos, yMax = Utils.pipeMaxPos, zMin = Utils.pipeMinPos, zMax = Utils.pipeMaxPos;
TileEntity tile1 = world.getBlockTileEntity(i, j, k);
TileGenericPipe tileG = (TileGenericPipe) tile1;
if (Utils.checkPipesConnections(world, tile1, i - 1, j, k) || (tileG != null && tileG.hasFacade(ForgeDirection.WEST)))
xMin = 0.0F;
if (Utils.checkPipesConnections(world, tile1, i + 1, j, k) || (tileG != null && tileG.hasFacade(ForgeDirection.EAST)))
xMax = 1.0F;
if (Utils.checkPipesConnections(world, tile1, i, j - 1, k) || (tileG != null && tileG.hasFacade(ForgeDirection.DOWN)))
yMin = 0.0F;
if (Utils.checkPipesConnections(world, tile1, i, j + 1, k) || (tileG != null && tileG.hasFacade(ForgeDirection.UP)))
yMax = 1.0F;
if (Utils.checkPipesConnections(world, tile1, i, j, k - 1) || (tileG != null && tileG.hasFacade(ForgeDirection.NORTH)))
zMin = 0.0F;
if (Utils.checkPipesConnections(world, tile1, i, j, k + 1) || (tileG != null && tileG.hasFacade(ForgeDirection.SOUTH)))
zMax = 1.0F;
if (tileG != null) {
if (tileG.hasFacade(ForgeDirection.EAST) || tileG.hasFacade(ForgeDirection.WEST)) {
yMin = 0.0F;
yMax = 1.0F;
zMin = 0.0F;
zMax = 1.0F;
}
if (tileG.hasFacade(ForgeDirection.UP) || tileG.hasFacade(ForgeDirection.DOWN)) {
xMin = 0.0F;
xMax = 1.0F;
zMin = 0.0F;
zMax = 1.0F;
}
if (tileG.hasFacade(ForgeDirection.SOUTH) || tileG.hasFacade(ForgeDirection.NORTH)) {
xMin = 0.0F;
xMax = 1.0F;
yMin = 0.0F;
yMax = 1.0F;
}
}
return AxisAlignedBB.getBoundingBox((double) i + xMin, (double) j + yMin, (double) k + zMin, (double) i + xMax,
(double) j + yMax, (double) k + zMax);
}
@Override
public MovingObjectPosition collisionRayTrace(World world, int i, int j, int k, Vec3 vec3d, Vec3 vec3d1) {
float xMin = Utils.pipeMinPos, xMax = Utils.pipeMaxPos, yMin = Utils.pipeMinPos, yMax = Utils.pipeMaxPos, zMin = Utils.pipeMinPos, zMax = Utils.pipeMaxPos;
TileEntity tile1 = world.getBlockTileEntity(i, j, k);
if (Utils.checkPipesConnections(world, tile1, i - 1, j, k))
xMin = 0.0F;
if (Utils.checkPipesConnections(world, tile1, i + 1, j, k))
xMax = 1.0F;
if (Utils.checkPipesConnections(world, tile1, i, j - 1, k))
yMin = 0.0F;
if (Utils.checkPipesConnections(world, tile1, i, j + 1, k))
yMax = 1.0F;
if (Utils.checkPipesConnections(world, tile1, i, j, k - 1))
zMin = 0.0F;
if (Utils.checkPipesConnections(world, tile1, i, j, k + 1))
zMax = 1.0F;
setBlockBounds(xMin, yMin, zMin, xMax, yMax, zMax);
MovingObjectPosition r = super.collisionRayTrace(world, i, j, k, vec3d, vec3d1);
setBlockBounds(0, 0, 0, 1, 1, 1);
return r;
}
public static void removePipe(Pipe pipe) {
if (pipe == null)
return;
if (isValid(pipe))
pipe.onBlockRemoval();
World world = pipe.worldObj;
if (world == null)
return;
int i = pipe.xCoord;
int j = pipe.yCoord;
int k = pipe.zCoord;
if (lastRemovedDate != world.getWorldTime()) {
lastRemovedDate = world.getWorldTime();
pipeRemoved.clear();
}
pipeRemoved.put(new BlockIndex(i, j, k), pipe);
world.removeBlockTileEntity(i, j, k);
}
@Override
public void breakBlock(World world, int x, int y, int z, int par5, int par6) {
Utils.preDestroyBlock(world, x, y, z);
removePipe(getPipe(world, x, y, z));
super.breakBlock(world, x, y, z, par5, par6);
}
@Override
public String getTextureFile() {
return DefaultProps.TEXTURE_BLOCKS;
}
@Override
public TileEntity createNewTileEntity(World var1) {
return new TileGenericPipe();
}
@Override
public void dropBlockAsItemWithChance(World world, int i, int j, int k, int l, float f, int dmg) {
if (CoreProxy.proxy.isRenderWorld(world))
return;
int i1 = quantityDropped(world.rand);
for (int j1 = 0; j1 < i1; j1++) {
if (world.rand.nextFloat() > f)
continue;
Pipe pipe = getPipe(world, i, j, k);
if (pipe == null)
pipe = pipeRemoved.get(new BlockIndex(i, j, k));
if (pipe != null) {
int k1 = pipe.itemID;
if (k1 > 0) {
pipe.dropContents();
dropBlockAsItem_do(world, i, j, k, new ItemStack(k1, 1, damageDropped(l)));
}
}
}
}
@Override
public int idDropped(int meta, Random rand, int dmg) {
// Returns 0 to be safe - the id does not depend on the meta
return 0;
}
@SideOnly(Side.CLIENT)
@Override
public int idPicked(World world, int i, int j, int k)
{
Pipe pipe = getPipe(world, i, j, k);
if (pipe == null)
return 0;
else
return pipe.itemID;
}
/* Wrappers *************************************************************/
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int l) {
super.onNeighborBlockChange(world, x, y, z, l);
Pipe pipe = getPipe(world, x, y, z);
if (isValid(pipe))
pipe.container.scheduleNeighborChange();
}
@Override
public int func_85104_a(World world, int x, int y, int z, int side, float par6, float par7, float par8, int meta) {
super.func_85104_a(world, x, y, z, side, par6, par7, par8, meta);
Pipe pipe = getPipe(world, x, y, z);
if (isValid(pipe))
pipe.onBlockPlaced();
return meta;
}
@Override
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityplayer, int par6, float par7, float par8, float par9) {
super.onBlockActivated(world, i, j, k, entityplayer, par6, par7, par8, par9);
world.notifyBlocksOfNeighborChange(i, j, k, BuildCraftTransport.genericPipeBlock.blockID);
Pipe pipe = getPipe(world, i, j, k);
if (isValid(pipe)) {
// / Right click while sneaking without wrench to strip equipment
// from the pipe.
if (entityplayer.isSneaking()
&& (entityplayer.getCurrentEquippedItem() == null || !(entityplayer.getCurrentEquippedItem().getItem() instanceof IToolWrench))) {
if (pipe.hasGate() || pipe.isWired())
return stripEquipment(pipe);
} else if (entityplayer.getCurrentEquippedItem() == null) {
// Fall through the end of the test
} else if (entityplayer.getCurrentEquippedItem().itemID == Item.sign.shiftedIndex){
// Sign will be placed anyway, so lets show the sign gui
return false;
} else if (entityplayer.getCurrentEquippedItem().getItem() instanceof ItemPipe)
return false;
else if (entityplayer.getCurrentEquippedItem().getItem() instanceof IToolWrench) {
// Only check the instance at this point. Call the IToolWrench
// interface callbacks for the individual pipe/logic calls
return pipe.blockActivated(world, i, j, k, entityplayer);
} else if (entityplayer.getCurrentEquippedItem().getItem() == BuildCraftTransport.redPipeWire) {
if (!pipe.wireSet[IPipe.WireColor.Red.ordinal()]) {
pipe.wireSet[IPipe.WireColor.Red.ordinal()] = true;
if (!entityplayer.capabilities.isCreativeMode)
entityplayer.getCurrentEquippedItem().splitStack(1);
pipe.container.scheduleRenderUpdate();
//world.markBlockNeedsUpdate(i, j, k);
return true;
}
} else if (entityplayer.getCurrentEquippedItem().getItem() == BuildCraftTransport.bluePipeWire) {
if (!pipe.wireSet[IPipe.WireColor.Blue.ordinal()]) {
pipe.wireSet[IPipe.WireColor.Blue.ordinal()] = true;
if (!entityplayer.capabilities.isCreativeMode)
entityplayer.getCurrentEquippedItem().splitStack(1);
pipe.container.scheduleRenderUpdate();
//world.markBlockNeedsUpdate(i, j, k);
return true;
}
} else if (entityplayer.getCurrentEquippedItem().getItem() == BuildCraftTransport.greenPipeWire) {
if (!pipe.wireSet[IPipe.WireColor.Green.ordinal()]) {
pipe.wireSet[IPipe.WireColor.Green.ordinal()] = true;
if (!entityplayer.capabilities.isCreativeMode)
entityplayer.getCurrentEquippedItem().splitStack(1);
pipe.container.scheduleRenderUpdate();
return true;
}
} else if (entityplayer.getCurrentEquippedItem().getItem() == BuildCraftTransport.yellowPipeWire) {
if (!pipe.wireSet[IPipe.WireColor.Yellow.ordinal()]) {
pipe.wireSet[IPipe.WireColor.Yellow.ordinal()] = true;
if (!entityplayer.capabilities.isCreativeMode)
entityplayer.getCurrentEquippedItem().splitStack(1);
pipe.container.scheduleRenderUpdate();
return true;
}
} else if (entityplayer.getCurrentEquippedItem().itemID == BuildCraftTransport.pipeGate.shiftedIndex
|| entityplayer.getCurrentEquippedItem().itemID == BuildCraftTransport.pipeGateAutarchic.shiftedIndex)
if (!pipe.hasInterface()) {
pipe.gate = new GateVanilla(pipe, entityplayer.getCurrentEquippedItem());
if (!entityplayer.capabilities.isCreativeMode)
entityplayer.getCurrentEquippedItem().splitStack(1);
pipe.container.scheduleRenderUpdate();
return true;
}
if (pipe.hasGate()) {
pipe.gate.openGui(entityplayer);
return true;
} else
return pipe.blockActivated(world, i, j, k, entityplayer);
}
return false;
}
private boolean stripEquipment(Pipe pipe) {
// Try to strip wires first, starting with yellow.
for (IPipe.WireColor color : IPipe.WireColor.values())
if (pipe.wireSet[color.reverse().ordinal()]) {
if (!CoreProxy.proxy.isRenderWorld(pipe.worldObj))
dropWire(color.reverse(), pipe.worldObj, pipe.xCoord, pipe.yCoord, pipe.zCoord);
pipe.wireSet[color.reverse().ordinal()] = false;
//pipe.worldObj.markBlockNeedsUpdate(pipe.xCoord, pipe.yCoord, pipe.zCoord);
pipe.container.scheduleRenderUpdate();
return true;
}
// Try to strip gate next
if (pipe.hasGate()) {
if (!CoreProxy.proxy.isRenderWorld(pipe.worldObj))
pipe.gate.dropGate(pipe.worldObj, pipe.xCoord, pipe.yCoord, pipe.zCoord);
pipe.resetGate();
return true;
}
return false;
}
/**
* Drops a pipe wire item of the passed color.
*
* @param color
*/
private void dropWire(IPipe.WireColor color, World world, int i, int j, int k) {
Item wireItem;
switch (color) {
case Red:
wireItem = BuildCraftTransport.redPipeWire;
break;
case Blue:
wireItem = BuildCraftTransport.bluePipeWire;
break;
case Green:
wireItem = BuildCraftTransport.greenPipeWire;
break;
default:
wireItem = BuildCraftTransport.yellowPipeWire;
}
Utils.dropItems(world, new ItemStack(wireItem), i, j, k);
}
@SuppressWarnings({ "all" })
public int getBlockTexture(IBlockAccess iblockaccess, int i, int j, int k, int l) {
TileEntity tile = iblockaccess.getBlockTileEntity(i, j, k);
if (!(tile instanceof IPipeRenderState)) return 0;
return ((IPipeRenderState)tile).getRenderState().currentTextureIndex;
// Pipe pipe = getPipe(iblockaccess, i, j, k);
// if (!isValid(pipe)) {
// CoreProxy.BindTexture(DefaultProps.TEXTURE_BLOCKS);
// return 0;
// }
// int pipeTexture = pipe.getPipeTexture();
// if (pipeTexture > 255) {
// CoreProxy.BindTexture(DefaultProps.TEXTURE_EXTERNAL);
// return pipeTexture - 256;
// }
// CoreProxy.BindTexture(DefaultProps.TEXTURE_BLOCKS);
// return pipeTexture;
}
@Override
public void onEntityCollidedWithBlock(World world, int i, int j, int k, Entity entity) {
super.onEntityCollidedWithBlock(world, i, j, k, entity);
Pipe pipe = getPipe(world, i, j, k);
if (isValid(pipe))
pipe.onEntityCollidedWithBlock(entity);
}
@Override
public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side)
{
Pipe pipe = getPipe(world, x, y, z);
if (isValid(pipe))
return pipe.canConnectRedstone();
else
return false;
}
@Override
public boolean isProvidingStrongPower(IBlockAccess iblockaccess, int x, int y, int z, int l) {
Pipe pipe = getPipe(iblockaccess, x, y, z);
if (isValid(pipe))
return pipe.isPoweringTo(l);
else
return false;
}
@Override
public boolean canProvidePower() {
return true;
}
@Override
public boolean isProvidingWeakPower(IBlockAccess world, int i, int j, int k, int l) {
Pipe pipe = getPipe(world, i, j, k);
if (isValid(pipe))
return pipe.isIndirectlyPoweringTo(l);
else
return false;
}
@SuppressWarnings({ "all" })
@Override
public void randomDisplayTick(World world, int i, int j, int k, Random random) {
Pipe pipe = getPipe(world, i, j, k);
if (isValid(pipe))
pipe.randomDisplayTick(random);
}
/* Registration *********************************************************/
public static TreeMap<Integer, Class<? extends Pipe>> pipes = new TreeMap<Integer, Class<? extends Pipe>>();
static long lastRemovedDate = -1;
public static TreeMap<BlockIndex, Pipe> pipeRemoved = new TreeMap<BlockIndex, Pipe>();
public static ItemPipe registerPipe(int key, Class<? extends Pipe> clas) {
ItemPipe item = new ItemPipe(key);
pipes.put(item.shiftedIndex, clas);
Pipe dummyPipe = createPipe(item.shiftedIndex);
if (dummyPipe != null){
item.setTextureFile(dummyPipe.getTextureFile());
item.setTextureIndex(dummyPipe.getTextureIndexForItem());
}
return item;
}
public static Pipe createPipe(int key) {
try {
Class<? extends Pipe> pipe = pipes.get(key);
if (pipe != null) {
return pipe.getConstructor(int.class).newInstance(key);
} else {
BuildCraftCore.bcLog.warning("Detected pipe with unknown key (" + key + "). Did you remove a buildcraft addon?");
}
} catch (Throwable t) {
t.printStackTrace();
}
return null;
}
public static boolean placePipe(Pipe pipe, World world, int i, int j, int k, int blockId, int meta) {
if (world.isRemote) return true;
boolean placed = world.setBlockAndMetadataWithNotify(i, j, k, blockId, meta);
if (placed) {
TileGenericPipe tile = (TileGenericPipe) world.getBlockTileEntity(i, j, k);
tile.initialize(pipe);
}
return placed;
}
public static Pipe getPipe(IBlockAccess blockAccess, int i, int j, int k) {
TileEntity tile = blockAccess.getBlockTileEntity(i, j, k);
if(!(tile instanceof TileGenericPipe) || tile.isInvalid())
return null;
return ((TileGenericPipe)tile).pipe;
}
public static boolean isFullyDefined(Pipe pipe) {
return pipe != null && pipe.transport != null && pipe.logic != null;
}
public static boolean isValid(Pipe pipe) {
return isFullyDefined(pipe);
}
}