-
Notifications
You must be signed in to change notification settings - Fork 497
/
RobotStationPluggable.java
256 lines (213 loc) · 7.41 KB
/
RobotStationPluggable.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
package buildcraft.transport;
import java.awt.*;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.render.ITextureStates;
import buildcraft.api.pipes.IPipe;
import buildcraft.api.pipes.IPipeContainer;
import buildcraft.api.pipes.IPipePluggable;
import buildcraft.api.pipes.IPipePluggableRenderer;
import buildcraft.core.robots.DockingStation;
import buildcraft.core.robots.RobotRegistry;
import buildcraft.core.utils.MatrixTranformations;
/**
* Created by asie on 12/15/14.
*/
public class RobotStationPluggable implements IPipePluggable {
public class RobotStationPluggableRenderer implements IPipePluggableRenderer {
private float zFightOffset = 1 / 4096.0F;
private void robotStationPartRender(RenderBlocks renderblocks, RobotStationState state,
ForgeDirection side, ITextureStates blockStateMachine, int x, int y, int z,
float xStart, float xEnd, float yStart, float yEnd, float zStart,
float zEnd) {
float[][] zeroState = new float[3][2];
// X START - END
zeroState[0][0] = xStart + zFightOffset;
zeroState[0][1] = xEnd - zFightOffset;
// Y START - END
zeroState[1][0] = yStart;
zeroState[1][1] = yEnd;
// Z START - END
zeroState[2][0] = zStart + zFightOffset;
zeroState[2][1] = zEnd - zFightOffset;
switch (state) {
case None:
case Available:
blockStateMachine.getTextureState().set(BuildCraftTransport.instance.pipeIconProvider
.getIcon(PipeIconProvider.TYPE.PipeRobotStation.ordinal()));
break;
case Reserved:
blockStateMachine.getTextureState().set(BuildCraftTransport.instance.pipeIconProvider
.getIcon(PipeIconProvider.TYPE.PipeRobotStationReserved.ordinal()));
break;
case Linked:
blockStateMachine.getTextureState().set(BuildCraftTransport.instance.pipeIconProvider
.getIcon(PipeIconProvider.TYPE.PipeRobotStationLinked.ordinal()));
break;
}
float[][] rotated = MatrixTranformations.deepClone(zeroState);
MatrixTranformations.transform(rotated, side);
renderblocks.setRenderBounds(rotated[0][0], rotated[1][0],
rotated[2][0], rotated[0][1], rotated[1][1],
rotated[2][1]);
renderblocks.renderStandardBlock(blockStateMachine.getBlock(), x, y, z);
}
@Override
public void renderPluggable(RenderBlocks renderblocks, IPipe pipe, ForgeDirection side, IPipePluggable pipePluggable, ITextureStates blockStateMachine, int x, int y, int z) {
RobotStationState state = ((RobotStationPluggable) pipePluggable).renderState;
//float width = 0.075F;
robotStationPartRender (renderblocks, state, side, blockStateMachine, x, y, z,
0.45F, 0.55F,
0.0F, 0.224F,
0.45F, 0.55F);
/*pipeRobotStationPartRender (renderblocks, block, state, x, y, z,
0.25F, 0.75F,
0.025F, 0.224F,
0.25F, 0.25F + width);
pipeRobotStationPartRender (renderblocks, block, state, x, y, z,
0.25F, 0.75F,
0.025F, 0.224F,
0.75F - width, 0.75F);
pipeRobotStationPartRender (renderblocks, block, state, x, y, z,
0.25F, 0.25F + width,
0.025F, 0.224F,
0.25F + width, 0.75F - width);
pipeRobotStationPartRender (renderblocks, block, state, x, y, z,
0.75F - width, 0.75F,
0.025F, 0.224F,
0.25F + width, 0.75F - width);*/
float[][] zeroState = new float[3][2];
// X START - END
zeroState[0][0] = 0.25F + zFightOffset;
zeroState[0][1] = 0.75F - zFightOffset;
// Y START - END
zeroState[1][0] = 0.225F;
zeroState[1][1] = 0.251F;
// Z START - END
zeroState[2][0] = 0.25F + zFightOffset;
zeroState[2][1] = 0.75F - zFightOffset;
switch(state) {
case None:
case Available:
blockStateMachine.getTextureState().set(BuildCraftTransport.instance.pipeIconProvider
.getIcon(PipeIconProvider.TYPE.PipeRobotStation.ordinal()));
break;
case Reserved:
blockStateMachine.getTextureState().set(BuildCraftTransport.instance.pipeIconProvider
.getIcon(PipeIconProvider.TYPE.PipeRobotStationReserved.ordinal()));
break;
case Linked:
blockStateMachine.getTextureState().set(BuildCraftTransport.instance.pipeIconProvider
.getIcon(PipeIconProvider.TYPE.PipeRobotStationLinked.ordinal()));
break;
}
float[][] rotated = MatrixTranformations.deepClone(zeroState);
MatrixTranformations.transform(rotated, side);
renderblocks.setRenderBounds(rotated[0][0], rotated[1][0],
rotated[2][0], rotated[0][1], rotated[1][1],
rotated[2][1]);
renderblocks.renderStandardBlock(blockStateMachine.getBlock(), x, y, z);
}
}
public static enum RobotStationState {
None,
Available,
Reserved,
Linked
}
private RobotStationState renderState;
private DockingStation station;
private boolean isValid = false;
public RobotStationPluggable() {
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
}
@Override
public ItemStack[] getDropItems(IPipeContainer pipe) {
return new ItemStack[] { new ItemStack(BuildCraftTransport.robotStationItem) };
}
@Override
public void onAttachedPipe(IPipeContainer pipe, ForgeDirection direction) {
validate(pipe, direction);
}
@Override
public void onDetachedPipe(IPipeContainer pipe, ForgeDirection direction) {
invalidate();
}
public DockingStation getStation() {
return station;
}
@Override
public boolean isBlocking(IPipeContainer pipe, ForgeDirection direction) {
return true;
}
@Override
public void invalidate() {
if (station != null
&& station.getPipe() != null
&& !station.getPipe().getWorld().isRemote) {
RobotRegistry.getRegistry(station.world).removeStation(station);
isValid = false;
}
}
@Override
public void validate(IPipeContainer pipe, ForgeDirection direction) {
TileGenericPipe gPipe = (TileGenericPipe) pipe;
if (!isValid && !gPipe.getWorld().isRemote) {
station = (DockingStation)
RobotRegistry.getRegistry(gPipe.getWorld()).getStation(
gPipe.xCoord,
gPipe.yCoord,
gPipe.zCoord,
direction);
if (station == null) {
station = new DockingStation(gPipe, direction);
RobotRegistry.getRegistry(gPipe.getWorld()).registerStation(station);
}
isValid = true;
}
}
@Override
public AxisAlignedBB getBoundingBox(ForgeDirection side) {
float[][] bounds = new float[3][2];
// X START - END
bounds[0][0] = 0.25F;
bounds[0][1] = 0.75F;
// Y START - END
bounds[1][0] = 0.125F;
bounds[1][1] = 0.251F;
// Z START - END
bounds[2][0] = 0.25F;
bounds[2][1] = 0.75F;
MatrixTranformations.transform(bounds, side);
return AxisAlignedBB.getBoundingBox(bounds[0][0], bounds[1][0], bounds[2][0], bounds[0][1], bounds[1][1], bounds[2][1]);
}
public RobotStationState getRenderState() {
return renderState;
}
@Override
public IPipePluggableRenderer getRenderer() {
return new RobotStationPluggableRenderer();
}
@Override
public void writeData(ByteBuf data) {
DockingStation station = getStation();
this.renderState = station.isTaken()
? (station.isMainStation() ? RobotStationState.Linked : RobotStationState.Reserved)
: RobotStationState.Available;
data.writeByte(getRenderState().ordinal());
}
@Override
public void readData(ByteBuf data) {
this.renderState = RobotStationState.values()[data.readUnsignedByte()];
}
}