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
|
package gregtech.api.net;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
/**
* Used to transfer Block Events in a much better fashion
*/
public class GT_Packet_Block_Event extends GT_Packet {
private int mX, mZ;
private short mY;
private byte mID, mValue;
public GT_Packet_Block_Event() {
super(true);
}
public GT_Packet_Block_Event(int aX, short aY, int aZ, byte aID, byte aValue) {
super(false);
mX = aX;
mY = aY;
mZ = aZ;
mID = aID;
mValue = aValue;
}
@Override
public byte[] encode() {
ByteArrayDataOutput tOut = ByteStreams.newDataOutput(10);
tOut.writeInt(mX);
tOut.writeShort(mY);
tOut.writeInt(mZ);
tOut.writeByte(mID);
tOut.writeByte(mValue);
return tOut.toByteArray();
}
@Override
public GT_Packet decode(ByteArrayDataInput aData) {
return new GT_Packet_Block_Event(aData.readInt(), aData.readShort(), aData.readInt(), aData.readByte(), aData.readByte());
}
@Override
public void process(IBlockAccess aWorld) {
if (aWorld != null) {
TileEntity tTileEntity = aWorld.getTileEntity(mX, mY, mZ);
if (tTileEntity != null) tTileEntity.receiveClientEvent(mID, mValue);
}
}
@Override
public byte getPacketID() {
return 2;
}
}
|