-
Notifications
You must be signed in to change notification settings - Fork 755
/
SmelteryScan.java
159 lines (138 loc) · 4.81 KB
/
SmelteryScan.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
package tconstruct.blocks.component;
import java.util.ArrayList;
import java.util.Iterator;
import mantle.blocks.iface.IServantLogic;
import mantle.world.CoordTuple;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagIntArray;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import tconstruct.common.TContent;
import tconstruct.common.TRepo;
import tconstruct.library.component.TankLayerScan;
public class SmelteryScan extends TankLayerScan
{
public ArrayList<CoordTuple> lavaTanks = new ArrayList<CoordTuple>();
public SmelteryScan(TileEntity te, Block... id)
{
super(te, id);
}
@Override
public void checkValidStructure ()
{
lavaTanks.clear();
super.checkValidStructure();
}
protected boolean checkAir (int x, int y, int z)
{
Block block = world.func_147439_a(x, y, z);
if (block == null || block == Blocks.air || block == TRepo.tankAir)
return true;
return false;
}
@Override
protected boolean checkServant (int x, int y, int z)
{
Block block = world.func_147439_a(x, y, z);
if (block == null || world.func_147439_a( x, y, z) == Blocks.air || !isValidBlock(x, y, z))
return false;
if (!block.hasTileEntity(world.getBlockMetadata(x, y, z)))
return false;
TileEntity be = world.func_147438_o(x, y, z);
if (be instanceof IServantLogic)
{
boolean ret = ((IServantLogic) be).setPotentialMaster(this.imaster, this.world, x, y, z);
if (ret && block == TRepo.lavaTank)
lavaTanks.add(new CoordTuple(x, y, z));
return ret;
}
return false;
}
@Override
protected void finalizeStructure ()
{
super.finalizeStructure();
if (lavaTanks.size() < 1)
completeStructure = false;
else
{
for (CoordTuple coord : airCoords)
{
if (world.func_147439_a(coord.x, coord.y, coord.z) != TRepo.tankAir)
{
world.setBlock(coord.x, coord.y, coord.z, TRepo.tankAir);
IServantLogic servant = (IServantLogic) world.func_147438_o(coord.x, coord.y, coord.z);
servant.verifyMaster(imaster, world, master.field_145851_c, master.field_145848_d, master.field_145849_e);
}
}
}
}
@Override
protected void invalidateStructure ()
{
super.invalidateStructure();
for (CoordTuple coord : airCoords)
{
TileEntity servant = world.func_147438_o(coord.x, coord.y, coord.z);
if (servant instanceof IServantLogic)
((IServantLogic) servant).invalidateMaster(imaster, world, master.field_145851_c, master.field_145848_d, master.field_145849_e);
}
}
@Override
protected void invalidateBlocksAbove (int height)
{
for (CoordTuple coord : airCoords)
{
if (coord.y < height)
continue;
TileEntity servant = world.func_147438_o(coord.x, coord.y, coord.z);
if (servant instanceof IServantLogic)
((IServantLogic) servant).invalidateMaster(imaster, world, master.field_145851_c, master.field_145848_d, master.field_145849_e);
}
}
@Override
public void cleanup ()
{
super.cleanup();
Iterator i = airCoords.iterator();
while (i.hasNext())
{
CoordTuple coord = (CoordTuple) i.next();
TileEntity te = world.func_147438_o(coord.x, coord.y, coord.z);
if (te != null && te instanceof IServantLogic)
{
((IServantLogic) te).invalidateMaster(imaster, world, master.field_145851_c, master.field_145848_d, master.field_145849_e);
}
}
}
//Sync lava tanks for fuel values
@Override
public void readNetworkNBT (NBTTagCompound tags)
{
super.readNetworkNBT(tags);
NBTTagList tanks = tags.getTagList("Tanks");
if (tanks != null)
{
lavaTanks.clear();
for (int i = 0; i < tanks.tagCount(); ++i)
{
NBTTagIntArray tag = (NBTTagIntArray) tanks.tagAt(i);
int[] coord = tag.intArray;
layerAirCoords.add(new CoordTuple(coord[0], coord[1], coord[2]));
}
}
}
@Override
public void writeNetworkNBT (NBTTagCompound tags)
{
super.writeNetworkNBT(tags);
NBTTagList tanks = new NBTTagList();
for (CoordTuple coord : lavaTanks)
{
tanks.appendTag(new NBTTagIntArray("coord", new int[] { coord.x, coord.y, coord.z }));
}
tags.setTag("Tanks", tanks);
}
}