mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2024-12-04 21:01:02 -05:00
Implement ServerUpdateLightPacket
This commit is contained in:
parent
02d3f6f319
commit
228535b23c
1 changed files with 105 additions and 15 deletions
|
@ -1,41 +1,131 @@
|
|||
package com.github.steveice10.mc.protocol.packet.ingame.server.world;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.chunk.NibbleArray3d;
|
||||
import com.github.steveice10.mc.protocol.packet.MinecraftPacket;
|
||||
import com.github.steveice10.packetlib.io.NetInput;
|
||||
import com.github.steveice10.packetlib.io.NetOutput;
|
||||
|
||||
// TODO: Implement
|
||||
public class ServerUpdateLightPacket extends MinecraftPacket {
|
||||
private static final NibbleArray3d EMPTY = new NibbleArray3d(4096);
|
||||
private int x;
|
||||
private int z;
|
||||
private List<NibbleArray3d> skyLight;
|
||||
private List<NibbleArray3d> blockLight;
|
||||
|
||||
private byte[] data;
|
||||
|
||||
public ServerUpdateLightPacket() {
|
||||
@SuppressWarnings("unused")
|
||||
private ServerUpdateLightPacket() {
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public ServerUpdateLightPacket(byte[] data) {
|
||||
this.data = data;
|
||||
public ServerUpdateLightPacket(int x, int z, List<NibbleArray3d> skyLight, List<NibbleArray3d> blockLight) {
|
||||
if (skyLight.size() != 18) {
|
||||
throw new IllegalArgumentException("skyLight must have exactly 18 entries (null entries are permitted)");
|
||||
}
|
||||
if (blockLight.size() != 18) {
|
||||
throw new IllegalArgumentException("blockLight must have exactly 18 entries (null entries are permitted)");
|
||||
}
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
this.skyLight = skyLight;
|
||||
this.blockLight = blockLight;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public byte[] getData() {
|
||||
return data;
|
||||
public int getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setData(byte[] data) {
|
||||
this.data = data;
|
||||
public int getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
public List<NibbleArray3d> getSkyLight() {
|
||||
return this.skyLight;
|
||||
}
|
||||
|
||||
public List<NibbleArray3d> getBlockLight() {
|
||||
return this.blockLight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(NetInput in) throws IOException {
|
||||
data = in.readBytes(in.available());
|
||||
this.x = in.readVarInt();
|
||||
this.z = in.readVarInt();
|
||||
|
||||
int skyLightMask = in.readVarInt();
|
||||
int blockLightMask = in.readVarInt();
|
||||
int emptySkyLightMask = in.readVarInt();
|
||||
int emptyBlockLightMask = in.readVarInt();
|
||||
|
||||
this.skyLight = new ArrayList<>(18);
|
||||
for (int i = 0; i < 18; i++) {
|
||||
if ((skyLightMask & 1 << i) != 0) {
|
||||
this.skyLight.add(new NibbleArray3d(in, 2048)); // 2048 bytes read = 4096 entries
|
||||
} else if ((emptySkyLightMask & 1 << i) != 0) {
|
||||
this.skyLight.add(new NibbleArray3d(4096));
|
||||
} else {
|
||||
this.skyLight.add(null);
|
||||
}
|
||||
}
|
||||
|
||||
this.blockLight = new ArrayList<>(18);
|
||||
for (int i = 0; i < 18; i++) {
|
||||
if ((blockLightMask & 1 << i) != 0) {
|
||||
this.blockLight.add(new NibbleArray3d(in, 2048)); // 2048 bytes read = 4096 entries
|
||||
} else if ((emptyBlockLightMask & 1 << i) != 0) {
|
||||
this.blockLight.add(new NibbleArray3d(4096));
|
||||
} else {
|
||||
this.blockLight.add(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(NetOutput out) throws IOException {
|
||||
out.writeBytes(data);
|
||||
out.writeVarInt(this.x);
|
||||
out.writeVarInt(this.z);
|
||||
|
||||
int skyLightMask = 0;
|
||||
int blockLightMask = 0;
|
||||
int emptySkyLightMask = 0;
|
||||
int emptyBlockLightMask = 0;
|
||||
|
||||
for (int i = 0; i < 18; i++) {
|
||||
NibbleArray3d skyLight = this.skyLight.get(i);
|
||||
if (skyLight != null) {
|
||||
if (EMPTY.equals(skyLight)) {
|
||||
emptySkyLightMask |= 1 << i;
|
||||
} else {
|
||||
skyLightMask |= 1 << i;
|
||||
}
|
||||
}
|
||||
NibbleArray3d blockLight = this.blockLight.get(i);
|
||||
if (blockLight != null) {
|
||||
if (EMPTY.equals(blockLight)) {
|
||||
emptyBlockLightMask |= 1 << i;
|
||||
} else {
|
||||
blockLightMask |= 1 << i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out.writeVarInt(skyLightMask);
|
||||
out.writeVarInt(blockLightMask);
|
||||
out.writeVarInt(emptySkyLightMask);
|
||||
out.writeVarInt(emptyBlockLightMask);
|
||||
|
||||
for (int i = 0; i < 18; i++) {
|
||||
if ((skyLightMask & 1 << i) != 0) {
|
||||
this.skyLight.get(i).write(out);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 18; i++) {
|
||||
if ((blockLightMask & 1 << i) != 0) {
|
||||
this.blockLight.get(i).write(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue