-
Notifications
You must be signed in to change notification settings - Fork 497
/
TileGenericPipe.java
783 lines (658 loc) · 22.3 KB
/
TileGenericPipe.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
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
/**
* 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 buildcraft.api.transport.PipeWire;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.LinkedList;
import java.util.logging.Level;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.IIconProvider;
import buildcraft.api.core.Position;
import buildcraft.api.core.SafeTimeTracker;
import buildcraft.api.gates.GateExpansions;
import buildcraft.api.gates.IGateExpansion;
import buildcraft.api.gates.IOverrideDefaultTriggers;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.transport.IPipeConnection;
import buildcraft.api.transport.IPipeTile;
import buildcraft.core.DefaultProps;
import buildcraft.core.IDropControlInventory;
import buildcraft.core.ITileBufferHolder;
import buildcraft.core.TileBuffer;
import buildcraft.core.inventory.InvUtils;
import buildcraft.core.network.IClientState;
import buildcraft.core.network.IGuiReturnHandler;
import buildcraft.core.network.ISyncedTile;
import buildcraft.core.network.PacketTileState;
import buildcraft.core.utils.BCLog;
import buildcraft.transport.gates.GateDefinition;
import buildcraft.transport.gates.GateFactory;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.server.management.PlayerInstance;
import net.minecraft.world.WorldServer;
public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFluidHandler, IPipeTile, IOverrideDefaultTriggers, ITileBufferHolder,
IDropControlInventory, ISyncedTile, ISolidSideTile, IGuiReturnHandler {
public class CoreState implements IClientState {
public int pipeId = -1;
public int gateMaterial = -1;
public int gateLogic = -1;
public final Set<Byte> expansions = new HashSet<Byte>();
@Override
public void writeData(DataOutputStream data) throws IOException {
data.writeInt(pipeId);
data.writeByte(gateMaterial);
data.writeByte(gateLogic);
data.writeByte(expansions.size());
for (Byte expansion : expansions) {
data.writeByte(expansion);
}
}
@Override
public void readData(DataInputStream data) throws IOException {
pipeId = data.readInt();
gateMaterial = data.readByte();
gateLogic = data.readByte();
expansions.clear();
int numExp = data.readByte();
for (int i = 0; i < numExp; i++) {
expansions.add(data.readByte());
}
}
}
public final PipeRenderState renderState = new PipeRenderState();
public final CoreState coreState = new CoreState();
private boolean deletePipe = false;
private TileBuffer[] tileBuffer;
public boolean[] pipeConnectionsBuffer = new boolean[6];
public SafeTimeTracker networkSyncTracker = new SafeTimeTracker();
public Pipe pipe;
private boolean sendClientUpdate = false;
private boolean blockNeighborChange = false;
private boolean refreshRenderState = false;
private boolean pipeBound = false;
private boolean resyncGateExpansions = false;
public int redstoneInput = 0;
private int[] facadeBlocks = new int[ForgeDirection.VALID_DIRECTIONS.length];
private int[] facadeMeta = new int[ForgeDirection.VALID_DIRECTIONS.length];
private boolean[] plugs = new boolean[ForgeDirection.VALID_DIRECTIONS.length];
public TileGenericPipe() {
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
nbt.setByte("redstoneInput", (byte)redstoneInput);
if (pipe != null) {
nbt.setInteger("pipeId", pipe.itemID);
pipe.writeToNBT(nbt);
} else
nbt.setInteger("pipeId", coreState.pipeId);
for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) {
nbt.setInteger("facadeBlocks[" + i + "]", facadeBlocks[i]);
nbt.setInteger("facadeMeta[" + i + "]", facadeMeta[i]);
nbt.setBoolean("plug[" + i + "]", plugs[i]);
}
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
redstoneInput = nbt.getByte("redstoneInput");
coreState.pipeId = nbt.getInteger("pipeId");
pipe = BlockGenericPipe.createPipe(coreState.pipeId);
bindPipe();
if (pipe != null)
pipe.readFromNBT(nbt);
else {
BCLog.logger.log(Level.WARNING, "Pipe failed to load from NBT at {0},{1},{2}", new Object[]{xCoord, yCoord, zCoord});
deletePipe = true;
}
for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) {
facadeBlocks[i] = nbt.getInteger("facadeBlocks[" + i + "]");
facadeMeta[i] = nbt.getInteger("facadeMeta[" + i + "]");
plugs[i] = nbt.getBoolean("plug[" + i + "]");
}
}
@Override
public void invalidate() {
initialized = false;
tileBuffer = null;
if (pipe != null)
pipe.invalidate();
super.invalidate();
}
@Override
public void validate() {
super.validate();
initialized = false;
tileBuffer = null;
bindPipe();
if (pipe != null)
pipe.validate();
}
public boolean initialized = false;
@Override
public void updateEntity() {
if (!worldObj.isRemote) {
if (deletePipe)
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
if (pipe == null)
return;
if (!initialized)
initialize(pipe);
}
if (!BlockGenericPipe.isValid(pipe))
return;
pipe.updateEntity();
if (worldObj.isRemote) {
if (resyncGateExpansions)
syncGateExpansions();
return;
}
if (blockNeighborChange) {
computeConnections();
pipe.onNeighborBlockChange(0);
blockNeighborChange = false;
refreshRenderState = true;
}
if (refreshRenderState) {
refreshRenderState();
refreshRenderState = false;
}
PowerReceiver provider = getPowerReceiver(null);
if (provider != null)
provider.update();
if (sendClientUpdate) {
sendClientUpdate = false;
if (worldObj instanceof WorldServer) {
WorldServer world = (WorldServer) worldObj;
PlayerInstance playerInstance = world.getPlayerManager().getOrCreateChunkWatcher(xCoord >> 4, zCoord >> 4, false);
if (playerInstance != null) {
playerInstance.sendToAllPlayersWatchingChunk(getDescriptionPacket());
}
}
}
}
// PRECONDITION: worldObj must not be null
private void refreshRenderState() {
// Pipe connections;
for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
renderState.pipeConnectionMatrix.setConnected(o, this.pipeConnectionsBuffer[o.ordinal()]);
}
// Pipe Textures
for (int i = 0; i < 7; i++) {
ForgeDirection o = ForgeDirection.getOrientation(i);
renderState.textureMatrix.setIconIndex(o, pipe.getIconIndex(o));
}
// WireState
for (PipeWire color : PipeWire.values()) {
renderState.wireMatrix.setWire(color, pipe.wireSet[color.ordinal()]);
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
renderState.wireMatrix.setWireConnected(color, direction, pipe.isWireConnectedTo(this.getTile(direction), color));
}
boolean lit = pipe.signalStrength[color.ordinal()] > 0;
switch (color) {
case RED:
renderState.wireMatrix.setWireIndex(color, lit ? WireIconProvider.Texture_Red_Lit : WireIconProvider.Texture_Red_Dark);
break;
case BLUE:
renderState.wireMatrix.setWireIndex(color, lit ? WireIconProvider.Texture_Blue_Lit : WireIconProvider.Texture_Blue_Dark);
break;
case GREEN:
renderState.wireMatrix.setWireIndex(color, lit ? WireIconProvider.Texture_Green_Lit : WireIconProvider.Texture_Green_Dark);
break;
case YELLOW:
renderState.wireMatrix.setWireIndex(color, lit ? WireIconProvider.Texture_Yellow_Lit : WireIconProvider.Texture_Yellow_Dark);
break;
default:
break;
}
}
// Gate Textures and movement
renderState.setIsGateLit(pipe.gate != null ? pipe.gate.isGateActive() : false);
renderState.setIsGatePulsing(pipe.gate != null ? pipe.gate.isGatePulsing(): false);
// Facades
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
int blockId = this.facadeBlocks[direction.ordinal()];
renderState.facadeMatrix.setFacade(direction, blockId, this.facadeMeta[direction.ordinal()]);
}
//Plugs
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
renderState.plugMatrix.setConnected(direction, plugs[direction.ordinal()]);
}
if (renderState.isDirty()) {
renderState.clean();
sendUpdateToClient();
}
}
public void initialize(Pipe pipe) {
this.blockType = getBlockType();
if (pipe == null) {
BCLog.logger.log(Level.WARNING, "Pipe failed to initialize at {0},{1},{2}, deleting", new Object[]{xCoord, yCoord, zCoord});
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
return;
}
this.pipe = pipe;
for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
TileEntity tile = getTile(o);
if (tile instanceof ITileBufferHolder)
((ITileBufferHolder) tile).blockCreated(o, BuildCraftTransport.genericPipeBlock.blockID, this);
if (tile instanceof TileGenericPipe)
((TileGenericPipe) tile).scheduleNeighborChange();
}
bindPipe();
computeConnections();
scheduleRenderUpdate();
if (pipe.needsInit())
pipe.initialize();
initialized = true;
}
private void bindPipe() {
if (!pipeBound && pipe != null) {
pipe.setTile(this);
coreState.pipeId = pipe.itemID;
pipeBound = true;
}
}
public boolean isInitialized() {
return initialized;
}
@Override
public PowerHandler.PowerReceiver getPowerReceiver(ForgeDirection side) {
if (BlockGenericPipe.isValid(pipe) && pipe instanceof IPowerReceptor)
return ((IPowerReceptor) pipe).getPowerReceiver(null);
else
return null;
}
@Override
public void doWork(PowerHandler workProvider) {
if (BlockGenericPipe.isValid(pipe) && pipe instanceof IPowerReceptor)
((IPowerReceptor) pipe).doWork(workProvider);
}
public void scheduleNeighborChange() {
blockNeighborChange = true;
}
/* IPIPEENTRY */
@Override
public int injectItem(ItemStack payload, boolean doAdd, ForgeDirection from) {
if (BlockGenericPipe.isValid(pipe) && pipe.transport instanceof PipeTransportItems && isPipeConnected(from)) {
if (doAdd) {
Position itemPos = new Position(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, from.getOpposite());
itemPos.moveBackwards(0.4);
TravelingItem pipedItem = TravelingItem.make(itemPos.x, itemPos.y, itemPos.z, payload);
((PipeTransportItems) pipe.transport).injectItem(pipedItem, itemPos.orientation);
}
return payload.stackSize;
}
return 0;
}
@Override
public PipeType getPipeType() {
if (BlockGenericPipe.isValid(pipe))
return pipe.transport.getPipeType();
return null;
}
/* SMP */
@Override
public Packet getDescriptionPacket() {
bindPipe();
PacketTileState packet = new PacketTileState(this.xCoord, this.yCoord, this.zCoord);
coreState.expansions.clear();
if (pipe != null && pipe.gate != null) {
coreState.gateMaterial = pipe.gate.material.ordinal();
coreState.gateLogic = pipe.gate.logic.ordinal();
for (IGateExpansion ex : pipe.gate.expansions.keySet()) {
coreState.expansions.add(GateExpansions.getServerExpansionID(ex.getUniqueIdentifier()));
}
} else {
coreState.gateMaterial = -1;
coreState.gateLogic = -1;
}
if (pipe != null && pipe.transport != null)
pipe.transport.sendDescriptionPacket();
packet.addStateForSerialization((byte) 0, coreState);
packet.addStateForSerialization((byte) 1, renderState);
if (pipe instanceof IClientState)
packet.addStateForSerialization((byte) 2, (IClientState) pipe);
return packet.getPacket();
}
public void sendUpdateToClient() {
sendClientUpdate = true;
}
@Override
public LinkedList<ITrigger> getTriggers() {
LinkedList<ITrigger> result = new LinkedList<ITrigger>();
if (BlockGenericPipe.isFullyDefined(pipe) && pipe.hasGate()) {
result.add(BuildCraftCore.triggerRedstoneActive);
result.add(BuildCraftCore.triggerRedstoneInactive);
}
return result;
}
@Override
public void blockRemoved(ForgeDirection from) {
// TODO Auto-generated method stub
}
public TileBuffer[] getTileCache() {
if (tileBuffer == null && pipe != null)
tileBuffer = TileBuffer.makeBuffer(worldObj, xCoord, yCoord, zCoord, pipe.transport.delveIntoUnloadedChunks());
return tileBuffer;
}
@Override
public void blockCreated(ForgeDirection from, int blockID, TileEntity tile) {
TileBuffer[] cache = getTileCache();
if (cache != null)
cache[from.getOpposite().ordinal()].set(blockID, tile);
}
@Override
public int getBlockId(ForgeDirection to) {
TileBuffer[] cache = getTileCache();
if (cache != null)
return cache[to.ordinal()].getBlockID();
else
return 0;
}
@Override
public TileEntity getTile(ForgeDirection to) {
TileBuffer[] cache = getTileCache();
if (cache != null)
return cache[to.ordinal()].getTile();
else
return null;
}
/**
* Checks if this tile can connect to another tile
*
* @param with - The other Tile
* @param side - The orientation to get to the other tile ('with')
* @return true if pipes are considered connected
*/
protected boolean canPipeConnect(TileEntity with, ForgeDirection side) {
if (with == null)
return false;
if (hasPlug(side))
return false;
if (!BlockGenericPipe.isValid(pipe))
return false;
if (!(pipe instanceof IPipeConnectionForced) || !((IPipeConnectionForced) pipe).ignoreConnectionOverrides(side))
if (with instanceof IPipeConnection) {
IPipeConnection.ConnectOverride override = ((IPipeConnection) with).overridePipeConnection(pipe.transport.getPipeType(), side.getOpposite());
if (override != IPipeConnection.ConnectOverride.DEFAULT)
return override == IPipeConnection.ConnectOverride.CONNECT ? true : false;
}
if (with instanceof TileGenericPipe) {
if (((TileGenericPipe) with).hasPlug(side.getOpposite()))
return false;
Pipe otherPipe = ((TileGenericPipe) with).pipe;
if (!BlockGenericPipe.isValid(otherPipe))
return false;
if (!otherPipe.canPipeConnect(this, side.getOpposite()))
return false;
}
return pipe.canPipeConnect(with, side);
}
private void computeConnections() {
TileBuffer[] cache = getTileCache();
if (cache == null)
return;
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
TileBuffer t = cache[side.ordinal()];
t.refresh();
pipeConnectionsBuffer[side.ordinal()] = canPipeConnect(t.getTile(), side);
}
}
@Override
public boolean isPipeConnected(ForgeDirection with) {
if (worldObj.isRemote)
return renderState.pipeConnectionMatrix.isConnected(with);
return pipeConnectionsBuffer[with.ordinal()];
}
@Override
public boolean isWireActive(PipeWire wire) {
if (pipe == null)
return false;
return pipe.signalStrength[wire.ordinal()] > 0;
}
@Override
public boolean doDrop() {
if (BlockGenericPipe.isValid(pipe))
return pipe.doDrop();
else
return false;
}
@Override
public void onChunkUnload() {
if (pipe != null)
pipe.onChunkUnload();
}
/**
* ITankContainer implementation *
*/
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
if (BlockGenericPipe.isValid(pipe) && pipe.transport instanceof IFluidHandler && !hasPlug(from))
return ((IFluidHandler) pipe.transport).fill(from, resource, doFill);
else
return 0;
}
@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
if (BlockGenericPipe.isValid(pipe) && pipe.transport instanceof IFluidHandler && !hasPlug(from))
return ((IFluidHandler) pipe.transport).drain(from, maxDrain, doDrain);
else
return null;
}
@Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
if (BlockGenericPipe.isValid(pipe) && pipe.transport instanceof IFluidHandler && !hasPlug(from))
return ((IFluidHandler) pipe.transport).drain(from, resource, doDrain);
else
return null;
}
@Override
public boolean canFill(ForgeDirection from, Fluid fluid) {
if (BlockGenericPipe.isValid(pipe) && pipe.transport instanceof IFluidHandler && !hasPlug(from))
return ((IFluidHandler) pipe.transport).canFill(from, fluid);
else
return false;
}
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid) {
if (BlockGenericPipe.isValid(pipe) && pipe.transport instanceof IFluidHandler && !hasPlug(from))
return ((IFluidHandler) pipe.transport).canDrain(from, fluid);
else
return false;
}
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
return null;
}
public void scheduleRenderUpdate() {
refreshRenderState = true;
}
public boolean addFacade(ForgeDirection direction, int blockid, int meta) {
if (this.worldObj.isRemote)
return false;
if (this.facadeBlocks[direction.ordinal()] == blockid)
return false;
if (hasFacade(direction))
dropFacadeItem(direction);
this.facadeBlocks[direction.ordinal()] = blockid;
this.facadeMeta[direction.ordinal()] = meta;
worldObj.notifyBlockChange(this.xCoord, this.yCoord, this.zCoord, getBlockId());
scheduleRenderUpdate();
return true;
}
public boolean hasFacade(ForgeDirection direction) {
if (direction == null || direction == ForgeDirection.UNKNOWN)
return false;
if (this.worldObj.isRemote)
return renderState.facadeMatrix.getFacadeBlockId(direction) != 0;
return (this.facadeBlocks[direction.ordinal()] != 0);
}
private void dropFacadeItem(ForgeDirection direction) {
InvUtils.dropItems(worldObj, ItemFacade.getStack(this.facadeBlocks[direction.ordinal()], this.facadeMeta[direction.ordinal()]), this.xCoord, this.yCoord, this.zCoord);
}
public boolean dropFacade(ForgeDirection direction) {
if (!hasFacade(direction))
return false;
if (!worldObj.isRemote) {
dropFacadeItem(direction);
this.facadeBlocks[direction.ordinal()] = 0;
this.facadeMeta[direction.ordinal()] = 0;
worldObj.notifyBlockChange(this.xCoord, this.yCoord, this.zCoord, getBlockId());
scheduleRenderUpdate();
}
return true;
}
@SideOnly(Side.CLIENT)
public IIconProvider getPipeIcons() {
if (pipe == null)
return null;
return pipe.getIconProvider();
}
@Override
public IClientState getStateInstance(byte stateId) {
switch (stateId) {
case 0:
return coreState;
case 1:
return renderState;
case 2:
return (IClientState) pipe;
}
throw new RuntimeException("Unknown state requested: " + stateId + " this is a bug!");
}
@Override
public void afterStateUpdated(byte stateId) {
if (!worldObj.isRemote)
return;
switch (stateId) {
case 0:
if (pipe == null && coreState.pipeId != 0)
initialize(BlockGenericPipe.createPipe(coreState.pipeId));
if (pipe == null)
break;
if (coreState.gateMaterial == -1)
pipe.gate = null;
else if (pipe.gate == null)
pipe.gate = GateFactory.makeGate(pipe, GateDefinition.GateMaterial.fromOrdinal(coreState.gateMaterial), GateDefinition.GateLogic.fromOrdinal(coreState.gateLogic));
syncGateExpansions();
worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord);
break;
case 1: {
if (renderState.needsRenderUpdate()) {
worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord);
renderState.clean();
}
break;
}
}
}
private void syncGateExpansions() {
resyncGateExpansions = false;
if (pipe.gate != null && !coreState.expansions.isEmpty()) {
for (byte id : coreState.expansions) {
IGateExpansion ex = GateExpansions.getExpansionClient(id);
if (ex != null) {
if (!pipe.gate.expansions.containsKey(ex))
pipe.gate.addGateExpansion(ex);
} else {
resyncGateExpansions = true;
}
}
}
}
@Override
@SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared() {
return DefaultProps.PIPE_CONTENTS_RENDER_DIST * DefaultProps.PIPE_CONTENTS_RENDER_DIST;
}
@Override
public boolean shouldRefresh(int oldID, int newID, int oldMeta, int newMeta, World world, int x, int y, int z) {
return oldID != newID;
}
@Override
public boolean isSolidOnSide(ForgeDirection side) {
if (hasFacade(side))
return true;
if (BlockGenericPipe.isValid(pipe) && pipe instanceof ISolidSideTile)
if (((ISolidSideTile) pipe).isSolidOnSide(side))
return true;
return false;
}
public boolean hasPlug(ForgeDirection side) {
if (side == null || side == ForgeDirection.UNKNOWN)
return false;
if (this.worldObj.isRemote)
return renderState.plugMatrix.isConnected(side);
return plugs[side.ordinal()];
}
public boolean removeAndDropPlug(ForgeDirection side) {
if (!hasPlug(side))
return false;
if (!worldObj.isRemote) {
plugs[side.ordinal()] = false;
InvUtils.dropItems(worldObj, new ItemStack(BuildCraftTransport.plugItem), this.xCoord, this.yCoord, this.zCoord);
worldObj.notifyBlockChange(this.xCoord, this.yCoord, this.zCoord, getBlockId());
scheduleNeighborChange(); //To force recalculation of connections
scheduleRenderUpdate();
}
return true;
}
public boolean addPlug(ForgeDirection forgeDirection) {
if (hasPlug(forgeDirection))
return false;
plugs[forgeDirection.ordinal()] = true;
worldObj.notifyBlockChange(this.xCoord, this.yCoord, this.zCoord, getBlockId());
scheduleNeighborChange(); //To force recalculation of connections
scheduleRenderUpdate();
return true;
}
public int getBlockId() {
Block block = getBlockType();
if (block != null)
return block.blockID;
return 0;
}
@Override
public World getWorld() {
return worldObj;
}
public boolean isUseableByPlayer(EntityPlayer player) {
return worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this;
}
@Override
public void writeGuiData(DataOutputStream data) throws IOException {
if (BlockGenericPipe.isValid(pipe) && pipe instanceof IGuiReturnHandler)
((IGuiReturnHandler) pipe).writeGuiData(data);
}
@Override
public void readGuiData(DataInputStream data, EntityPlayer sender) throws IOException {
if (BlockGenericPipe.isValid(pipe) && pipe instanceof IGuiReturnHandler)
((IGuiReturnHandler) pipe).readGuiData(data, sender);
}
}