Rename ClientboundLevelChunkPacket to ClientboundLevelChunkWithLightPacket & other minor tweaks

This commit is contained in:
RednedEpic 2021-11-13 22:41:28 -06:00
parent 955986da96
commit 78b4763b86
8 changed files with 28 additions and 40 deletions

View file

@ -344,7 +344,7 @@ public class MinecraftProtocol extends PacketProtocol {
clientboundPackets.register(0x1F, ClientboundHorseScreenOpenPacket.class, ClientboundHorseScreenOpenPacket::new);
clientboundPackets.register(0x20, ClientboundInitializeBorderPacket.class, ClientboundInitializeBorderPacket::new);
clientboundPackets.register(0x21, ClientboundKeepAlivePacket.class, ClientboundKeepAlivePacket::new);
clientboundPackets.register(0x22, ClientboundLevelChunkPacket.class, ClientboundLevelChunkPacket::new);
clientboundPackets.register(0x22, ClientboundLevelChunkWithLightPacket.class, ClientboundLevelChunkWithLightPacket::new);
clientboundPackets.register(0x23, ClientboundLevelEventPacket.class, ClientboundLevelEventPacket::new);
clientboundPackets.register(0x24, ClientboundLevelParticlesPacket.class, ClientboundLevelParticlesPacket::new);
clientboundPackets.register(0x25, ClientboundLightUpdatePacket.class, ClientboundLightUpdatePacket::new);

View file

@ -1,12 +0,0 @@
package com.github.steveice10.mc.protocol.data.game.level.block;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class ExplodedBlockRecord {
private final int x;
private final int y;
private final int z;
}

View file

@ -16,15 +16,15 @@ import java.io.IOException;
@With
@AllArgsConstructor
public class ClientboundBlockUpdatePacket implements Packet {
private final @NonNull BlockChangeEntry record;
private final @NonNull BlockChangeEntry entry;
public ClientboundBlockUpdatePacket(NetInput in) throws IOException {
this.record = new BlockChangeEntry(Position.read(in), in.readVarInt());
this.entry = new BlockChangeEntry(Position.read(in), in.readVarInt());
}
@Override
public void write(NetOutput out) throws IOException {
Position.write(out, this.record.getPosition());
out.writeVarInt(this.record.getBlock());
Position.write(out, this.entry.getPosition());
out.writeVarInt(this.entry.getBlock());
}
}

View file

@ -1,6 +1,6 @@
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.level;
import com.github.steveice10.mc.protocol.data.game.level.block.ExplodedBlockRecord;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
import com.github.steveice10.packetlib.io.NetInput;
import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.packetlib.packet.Packet;
@ -21,7 +21,7 @@ public class ClientboundExplodePacket implements Packet {
private final float y;
private final float z;
private final float radius;
private final @NonNull List<ExplodedBlockRecord> exploded;
private final @NonNull List<Position> exploded;
private final float pushX;
private final float pushY;
private final float pushZ;
@ -31,10 +31,10 @@ public class ClientboundExplodePacket implements Packet {
this.y = in.readFloat();
this.z = in.readFloat();
this.radius = in.readFloat();
this.exploded = new ArrayList<ExplodedBlockRecord>();
this.exploded = new ArrayList<>();
int length = in.readVarInt();
for (int count = 0; count < length; count++) {
this.exploded.add(new ExplodedBlockRecord(in.readByte(), in.readByte(), in.readByte()));
this.exploded.add(new Position(in.readByte(), in.readByte(), in.readByte()));
}
this.pushX = in.readFloat();
@ -49,7 +49,7 @@ public class ClientboundExplodePacket implements Packet {
out.writeFloat(this.z);
out.writeFloat(this.radius);
out.writeVarInt(this.exploded.size());
for (ExplodedBlockRecord record : this.exploded) {
for (Position record : this.exploded) {
out.writeByte(record.getX());
out.writeByte(record.getY());
out.writeByte(record.getZ());

View file

@ -22,10 +22,10 @@ import java.util.BitSet;
@Data
@With
@AllArgsConstructor
public class ClientboundLevelChunkPacket implements Packet {
public class ClientboundLevelChunkWithLightPacket implements Packet {
private final @NonNull Chunk chunk;
public ClientboundLevelChunkPacket(NetInput in) throws IOException {
public ClientboundLevelChunkWithLightPacket(NetInput in) throws IOException {
int x = in.readInt();
int z = in.readInt();
BitSet chunkMask = BitSet.valueOf(in.readLongs(in.readVarInt()));

View file

@ -69,7 +69,7 @@ public class ClientboundLevelEventPacket implements Packet {
if (this.data instanceof RecordEventData) {
value = ((RecordEventData) this.data).getRecordId();
} else if (this.data instanceof SmokeEventData) {
value = MagicValues.value(Integer.class, (SmokeEventData) this.data);
value = MagicValues.value(Integer.class, this.data);
} else if (this.data instanceof BreakBlockEventData) {
value = ((BreakBlockEventData) this.data).getBlockState();
} else if (this.data instanceof BreakPotionEventData) {

View file

@ -21,18 +21,18 @@ public class ClientboundSectionBlocksUpdatePacket implements Packet {
/**
* The server sends the record position in terms of the local chunk coordinate but it is stored here in terms of global coordinates.
*/
private final @NonNull BlockChangeEntry[] records;
private final @NonNull BlockChangeEntry[] entries;
public ClientboundSectionBlocksUpdatePacket(int chunkX, int chunkY, int chunkZ, boolean ignoreOldLight, BlockChangeEntry... records) {
if (records == null || records.length == 0) {
throw new IllegalArgumentException("Records must contain at least 1 value.");
public ClientboundSectionBlocksUpdatePacket(int chunkX, int chunkY, int chunkZ, boolean ignoreOldLight, BlockChangeEntry... entries) {
if (entries == null || entries.length == 0) {
throw new IllegalArgumentException("Entries must contain at least 1 value.");
}
this.chunkX = chunkX;
this.chunkY = chunkY;
this.chunkZ = chunkZ;
this.ignoreOldLight = ignoreOldLight;
this.records = records;
this.entries = entries;
}
public ClientboundSectionBlocksUpdatePacket(NetInput in) throws IOException {
@ -41,14 +41,14 @@ public class ClientboundSectionBlocksUpdatePacket implements Packet {
this.chunkY = (int) (chunkPosition << 44 >> 44);
this.chunkZ = (int) (chunkPosition << 22 >> 42);
this.ignoreOldLight = in.readBoolean();
this.records = new BlockChangeEntry[in.readVarInt()];
for (int index = 0; index < this.records.length; index++) {
this.entries = new BlockChangeEntry[in.readVarInt()];
for (int index = 0; index < this.entries.length; index++) {
long blockData = in.readVarLong();
short position = (short) (blockData & 0xFFFL);
int x = (this.chunkX << 4) + (position >>> 8 & 0xF);
int y = (this.chunkY << 4) + (position & 0xF);
int z = (this.chunkZ << 4) + (position >>> 4 & 0xF);
this.records[index] = new BlockChangeEntry(new Position(x, y, z), (int) (blockData >>> 12));
this.entries[index] = new BlockChangeEntry(new Position(x, y, z), (int) (blockData >>> 12));
}
}
@ -59,10 +59,10 @@ public class ClientboundSectionBlocksUpdatePacket implements Packet {
chunkPosition |= (this.chunkZ & 0x3FFFFFL) << 20;
out.writeLong(chunkPosition | (this.chunkY & 0xFFFFFL));
out.writeBoolean(this.ignoreOldLight);
out.writeVarInt(this.records.length);
for (BlockChangeEntry record : this.records) {
short position = (short) ((record.getPosition().getX() - (this.chunkX << 4)) << 8 | (record.getPosition().getZ() - (this.chunkZ << 4)) << 4 | (record.getPosition().getY() - (this.chunkY << 4)));
out.writeVarLong((long) record.getBlock() << 12 | position);
out.writeVarInt(this.entries.length);
for (BlockChangeEntry entry : this.entries) {
short position = (short) ((entry.getPosition().getX() - (this.chunkX << 4)) << 8 | (entry.getPosition().getZ() - (this.chunkZ << 4)) << 4 | (entry.getPosition().getY() - (this.chunkY << 4)));
out.writeVarLong((long) entry.getBlock() << 12 | position);
}
}
}

View file

@ -6,14 +6,14 @@ import com.github.steveice10.mc.protocol.packet.PacketTest;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import org.junit.Before;
public class ClientboundLevelChunkPacketTest extends PacketTest {
public class ClientboundLevelChunkWithLightPacketTest extends PacketTest {
@Before
public void setup() {
ChunkSection chunk = new ChunkSection();
chunk.set(0, 0, 0, 10);
this.setPackets(
new ClientboundLevelChunkPacket(
new ClientboundLevelChunkWithLightPacket(
new Chunk(0, 0, new ChunkSection[]{
null, null, null, null, null, null, null, chunk,
null, chunk, null, null, null, chunk, null, null, null, null, null, null, null, null, null,
@ -22,7 +22,7 @@ public class ClientboundLevelChunkPacketTest extends PacketTest {
null, null, null, null, null, null, null, null, null, null, null
}, new CompoundTag[0], new CompoundTag("HeightMaps"), new int[1024])
),
new ClientboundLevelChunkPacket(
new ClientboundLevelChunkWithLightPacket(
new Chunk(1, 1, new ChunkSection[]{
chunk, chunk, chunk, chunk, chunk, chunk, chunk, chunk,
chunk, chunk, chunk, chunk, chunk, chunk, chunk, chunk, null, null, null, null, null,