mirror of
https://github.com/LegacyModdingMC/ChunkAPI.git
synced 2026-11-16 18:44:52 +00:00
netcode works
This commit is contained in:
24 files changed
+827
-161
No files matched your search
@@ -0,0 +1,83 @@
|
||||
package com.falsepattern.chunk.internal.vanilla;
|
||||
|
||||
import lombok.val;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static com.falsepattern.chunk.internal.Common.BLOCKS_PER_EBS;
|
||||
import static com.falsepattern.chunk.internal.Common.EBS_PER_CHUNK;
|
||||
|
||||
public class BlockIDManager extends VanillaManager {
|
||||
private static final int LSB_BYTES_PER_EBS = BLOCKS_PER_EBS;
|
||||
private static final int MSB_BYTES_PER_EBS = BLOCKS_PER_EBS / 2;
|
||||
private static final int HEADER_SIZE = 2;
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
return "blockid";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int maxPacketSize() {
|
||||
return HEADER_SIZE + EBS_PER_CHUNK * (LSB_BYTES_PER_EBS + MSB_BYTES_PER_EBS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToBuffer(Chunk chunk, int ebsMask, boolean forceUpdate, ByteBuffer data) {
|
||||
val ebsArray = chunk.getBlockStorageArray();
|
||||
int currentPos = data.position();
|
||||
data.putShort((short) 0);
|
||||
int msbMask = 0;
|
||||
for (int i = 0; i < ebsArray.length; i++) {
|
||||
if ((ebsMask & (1 << i)) != 0) {
|
||||
val ebs = ebsArray[i];
|
||||
val lsb = ebs.getBlockLSBArray();
|
||||
val msb = ebs.getBlockMSBArray();
|
||||
data.put(lsb);
|
||||
if (msb != null) {
|
||||
msbMask |= 1 << i;
|
||||
data.put(msb.data);
|
||||
}
|
||||
}
|
||||
}
|
||||
int endPos = data.position();
|
||||
data.position(currentPos);
|
||||
data.putShort((short) msbMask);
|
||||
data.position(endPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromBuffer(Chunk chunk, int ebsMask, boolean forceUpdate, ByteBuffer buffer) {
|
||||
val ebsArray = chunk.getBlockStorageArray();
|
||||
val msbMask = buffer.getShort() & 0xFFFF;
|
||||
for (int i = 0; i < ebsArray.length; i++) {
|
||||
val ebs = ebsArray[i];
|
||||
if ((ebsMask & (1 << i)) != 0 && ebs != null) {
|
||||
buffer.get(ebs.getBlockLSBArray());
|
||||
if ((msbMask & (1 << i)) != 0) {
|
||||
val msb = ebs.getBlockMSBArray();
|
||||
if (msb == null) {
|
||||
ebs.createBlockMSBArray();
|
||||
}
|
||||
buffer.get(ebs.getBlockMSBArray().data);
|
||||
} else {
|
||||
ebs.setBlockMSBArray(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(Chunk chunk, @NotNull NBTTagCompound tag) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(Chunk chunk, @NotNull NBTTagCompound tag) {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user