blob: c69772a2fb8acf1afdabb6778701aa366b87f2df (
plain)
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
|
package gregtech.api.net;
import net.minecraft.world.IBlockAccess;
import com.google.common.io.ByteArrayDataInput;
import gregtech.api.util.GTMusicSystem;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
public class GTPacketMusicSystemData extends GTPacket {
ByteBuf storedData;
public GTPacketMusicSystemData() {
super();
}
public GTPacketMusicSystemData(ByteBuf data) {
super();
this.storedData = data;
}
@Override
public byte getPacketID() {
return GTPacketTypes.MUSIC_SYSTEM_DATA.id;
}
@Override
public void encode(ByteBuf aOut) {
if (storedData == null) {
return;
}
storedData.markReaderIndex();
final int len = storedData.readableBytes();
aOut.writeInt(len);
aOut.writeBytes(storedData);
storedData.resetReaderIndex();
}
@Override
public GTPacket decode(ByteArrayDataInput aData) {
final int len = aData.readInt();
final byte[] fullData = new byte[len];
aData.readFully(fullData);
return new GTPacketMusicSystemData(Unpooled.wrappedBuffer(fullData));
}
@Override
public void process(IBlockAccess aWorld) {
if (aWorld == null || storedData == null) {
return;
}
storedData.markReaderIndex();
GTMusicSystem.ClientSystem.loadUpdatedSources(storedData);
storedData.resetReaderIndex();
}
}
|