-
Notifications
You must be signed in to change notification settings - Fork 25
/
ReactorPacketCore.java
189 lines (182 loc) · 5.61 KB
/
ReactorPacketCore.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
/*******************************************************************************
* @author Reika Kalseki
*
* Copyright 2017
*
* All rights reserved.
* Distribution of the software in any form is only allowed with
* explicit, prior permission from the owner.
******************************************************************************/
package Reika.ReactorCraft;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.UUID;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import Reika.DragonAPI.Auxiliary.PacketTypes;
import Reika.DragonAPI.Interfaces.PacketHandler;
import Reika.DragonAPI.Libraries.IO.ReikaChatHelper;
import Reika.DragonAPI.Libraries.IO.ReikaPacketHelper;
import Reika.DragonAPI.Libraries.IO.ReikaPacketHelper.PacketObj;
import Reika.ReactorCraft.Auxiliary.RadiationEffects;
import Reika.ReactorCraft.Registry.ReactorPackets;
import Reika.ReactorCraft.TileEntities.Fission.TileEntityCPU;
import Reika.ReactorCraft.TileEntities.Fission.TileEntityControlRod;
public class ReactorPacketCore implements PacketHandler {
protected ReactorPackets pack;
public void handleData(PacketObj packet, World world, EntityPlayer ep) {
DataInputStream inputStream = packet.getDataIn();
int control = Integer.MIN_VALUE;
int len;
int[] data = new int[0];
long longdata = 0;
float floatdata = 0;
int x = 0;
int y = 0;
int z = 0;
double dx = 0;
double dy = 0;
double dz = 0;
boolean readinglong = false;
String stringdata = null;
UUID id = null;
//System.out.print(packet.length);
try {
//ReikaJavaLibrary.pConsole(inputStream.readInt()+":"+inputStream.readInt()+":"+inputStream.readInt()+":"+inputStream.readInt()+":"+inputStream.readInt()+":"+inputStream.readInt()+":"+inputStream.readInt());
PacketTypes packetType = packet.getType();
switch(packetType) {
case FULLSOUND:
break;
case SOUND:
return;
case STRING:
stringdata = packet.readString();
control = inputStream.readInt();
pack = ReactorPackets.getEnum(control);
break;
case DATA:
control = inputStream.readInt();
pack = ReactorPackets.getEnum(control);
len = pack.getNumberDataInts();
data = new int[len];
readinglong = pack.isLongPacket();
if (!readinglong) {
for (int i = 0; i < len; i++)
data[i] = inputStream.readInt();
}
else
longdata = inputStream.readLong();
break;
case POS:
control = inputStream.readInt();
pack = ReactorPackets.getEnum(control);
dx = inputStream.readDouble();
dy = inputStream.readDouble();
dz = inputStream.readDouble();
len = pack.getNumberDataInts();
if (len > 0) {
data = new int[len];
for (int i = 0; i < len; i++)
data[i] = inputStream.readInt();
}
break;
case UPDATE:
control = inputStream.readInt();
pack = ReactorPackets.getEnum(control);
break;
case FLOAT:
control = inputStream.readInt();
pack = ReactorPackets.getEnum(control);
floatdata = inputStream.readFloat();
break;
case SYNC:
String name = packet.readString();
x = inputStream.readInt();
y = inputStream.readInt();
z = inputStream.readInt();
ReikaPacketHelper.updateTileEntityData(world, x, y, z, name, inputStream);
return;
case TANK:
String tank = packet.readString();
x = inputStream.readInt();
y = inputStream.readInt();
z = inputStream.readInt();
int level = inputStream.readInt();
ReikaPacketHelper.updateTileEntityTankData(world, x, y, z, tank, level);
return;
case RAW:
control = inputStream.readInt();
pack = ReactorPackets.getEnum(control);
len = pack.getNumberDataInts();
data = new int[len];
readinglong = pack.isLongPacket();
if (!readinglong) {
for (int i = 0; i < len; i++)
data[i] = inputStream.readInt();
}
else
longdata = inputStream.readLong();
break;
case PREFIXED:
control = inputStream.readInt();
pack = ReactorPackets.getEnum(control);
len = inputStream.readInt();
data = new int[len];
for (int i = 0; i < len; i++)
data[i] = inputStream.readInt();
break;
case NBT:
break;
case STRINGINT:
case STRINGINTLOC:
stringdata = packet.readString();
control = inputStream.readInt();
pack = ReactorPackets.getEnum(control);
data = new int[pack.getNumberDataInts()];
for (int i = 0; i < data.length; i++)
data[i] = inputStream.readInt();
break;
case UUID:
control = inputStream.readInt();
pack = ReactorPackets.getEnum(control);
long l1 = inputStream.readLong(); //most
long l2 = inputStream.readLong(); //least
id = new UUID(l1, l2);
break;
}
if (packetType.hasCoordinates()) {
x = inputStream.readInt();
y = inputStream.readInt();
z = inputStream.readInt();
}
}
catch (IOException e) {
e.printStackTrace();
return;
}
TileEntity te = world.getTileEntity(x, y, z);
try {
switch (pack) {
case CPUTOGGLE:
((TileEntityControlRod)te).toggle(true, true);
break;
case CPURAISE:
((TileEntityCPU)te).raiseAllRods();
break;
case CPULOWER:
((TileEntityCPU)te).lowerAllRods();
break;
case ORERADIATION: {
RadiationEffects.instance.doOreIrradiation(world, x, y, z, ep);
break;
}
}
}
catch (Exception e) {
ReactorCraft.logger.logError("Machine/item was deleted before its packet could be received!");
ReikaChatHelper.writeString("Machine/item was deleted before its packet could be received!");
e.printStackTrace();
}
}
}