forked from CloudburstMC/Nukkit
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae386b6
commit 7395588
Showing
4 changed files
with
123 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/cn/nukkit/network/protocol/UpdateSubChunkBlocksPacket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package cn.nukkit.network.protocol; | ||
|
||
import cn.nukkit.network.protocol.types.BlockChangeEntry; | ||
import lombok.ToString; | ||
|
||
@ToString | ||
public class UpdateSubChunkBlocksPacket extends DataPacket { | ||
public static final int NETWORK_ID = ProtocolInfo.UPDATE_SUB_CHUNK_BLOCKS_PACKET; | ||
|
||
public int subChunkBlockX; | ||
public int subChunkBlockY; | ||
public int subChunkBlockZ; | ||
public BlockChangeEntry[] layer0 = new BlockChangeEntry[0]; | ||
public BlockChangeEntry[] layer1 = new BlockChangeEntry[0]; | ||
|
||
@Override | ||
public int pid() { | ||
return NETWORK_ID; | ||
} | ||
|
||
@Override | ||
public void decode() { | ||
} | ||
|
||
@Override | ||
public void encode() { | ||
this.reset(); | ||
this.putBlockVector3(this.subChunkBlockX, this.subChunkBlockY, this.subChunkBlockZ); | ||
|
||
this.putUnsignedVarInt(this.layer0.length); | ||
for (BlockChangeEntry entry : this.layer0) { | ||
writeEntry(entry); | ||
} | ||
|
||
this.putUnsignedVarInt(this.layer1.length); | ||
for (BlockChangeEntry entry : this.layer1) { | ||
writeEntry(entry); | ||
} | ||
} | ||
|
||
private void writeEntry(BlockChangeEntry entry) { | ||
this.putBlockVector3(entry.x(), entry.y(), entry.z()); | ||
this.putUnsignedVarInt(entry.block()); | ||
this.putUnsignedVarInt(entry.flags()); | ||
this.putUnsignedVarLong(entry.syncedUpdateEntityUniqueId()); | ||
this.putUnsignedVarInt(entry.syncedUpdateType()); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/cn/nukkit/network/protocol/types/BlockChangeEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package cn.nukkit.network.protocol.types; | ||
|
||
import cn.nukkit.network.protocol.UpdateBlockPacket; | ||
|
||
public record BlockChangeEntry( | ||
int x, | ||
int y, | ||
int z, | ||
int block, | ||
int flags, | ||
// These two fields are useless 99.99% of the time; they are here to allow this packet to provide UpdateBlockSyncedPacket functionality. | ||
long syncedUpdateEntityUniqueId, | ||
int syncedUpdateType | ||
) { | ||
public static BlockChangeEntry create(int x, int y, int z, int block) { | ||
return create(x, y, z, block, UpdateBlockPacket.FLAG_ALL_PRIORITY); | ||
} | ||
|
||
public static BlockChangeEntry create(int x, int y, int z, int block, int flags) { | ||
return create(x, y, z, block, flags,-1, 0); | ||
} | ||
|
||
public static BlockChangeEntry create(int x, int y, int z, int block, int flags, long syncedUpdateEntityUniqueId, int syncedUpdateType) { | ||
return new BlockChangeEntry(x, y, z, block, flags, syncedUpdateEntityUniqueId, syncedUpdateType); | ||
} | ||
} |