Skip to content

Commit

Permalink
The Big Rename (ebs, section -> subChunk)
Browse files Browse the repository at this point in the history
  • Loading branch information
FalsePattern committed Dec 28, 2023
1 parent 83bfb89 commit 3dd168f
Show file tree
Hide file tree
Showing 25 changed files with 170 additions and 170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public class ExtendedConstants {

public static final int bitsPerBlock = 8 + bitsPerID + bitsPerMetadata;
public static final int nibblesPerBlock = bitsPerBlock / 4;
public static final int nibblesPerEBS = nibblesPerBlock * 16 * 16 * 16;
public static final int bytesPerEBS = (nibblesPerEBS + 1) / 2;
public static final int nibblesPerSubChunk = nibblesPerBlock * 16 * 16 * 16;
public static final int bytesPerSubChunk = (nibblesPerSubChunk + 1) / 2;

//BiomeIDs
public static final int biomeIDCount = 1 << bitsPerBiome;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public class VanillaConstants {

public static final int bitsPerBlock = 8 + bitsPerID + bitsPerMetadata;
public static final int nibblesPerBlock = bitsPerBlock / 4;
public static final int nibblesPerEBS = nibblesPerBlock * 16 * 16 * 16;
public static final int bytesPerEBS = (nibblesPerEBS + 1) / 2;
public static final int nibblesPerSubChunk = nibblesPerBlock * 16 * 16 * 16;
public static final int bytesPerSubChunk = (nibblesPerSubChunk + 1) / 2;

//BiomeIDs
public static final int biomeIDCount = 1 << bitsPerBiome;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.falsepattern.chunk.api.DataManager;
import com.falsepattern.endlessids.Hooks;
import com.falsepattern.endlessids.Tags;
import com.falsepattern.endlessids.mixin.helpers.IChunkMixin;
import com.falsepattern.endlessids.mixin.helpers.ChunkBiomeHook;
import lombok.val;
import lombok.var;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -33,17 +33,17 @@ public int maxPacketSize() {
}

@Override
public void writeToBuffer(Chunk chunk, int ebsMask, boolean forceUpdate, ByteBuffer data) {
data.asShortBuffer().put(((IChunkMixin)chunk).getBiomeShortArray());
public void writeToBuffer(Chunk chunk, int subChunkMask, boolean forceUpdate, ByteBuffer data) {
data.asShortBuffer().put(((ChunkBiomeHook)chunk).getBiomeShortArray());
data.position(data.position() + maxPacketSize());
}

@Override
public void readFromBuffer(Chunk chunk, int ebsMask, boolean forceUpdate, ByteBuffer buffer) {
var arr = ((IChunkMixin)chunk).getBiomeShortArray();
public void readFromBuffer(Chunk chunk, int subChunkMask, boolean forceUpdate, ByteBuffer buffer) {
var arr = ((ChunkBiomeHook)chunk).getBiomeShortArray();
if (arr == null) {
arr = new short[16 * 16];
((IChunkMixin)chunk).setBiomeShortArray(arr);
((ChunkBiomeHook)chunk).setBiomeShortArray(arr);
}
buffer.asShortBuffer().get(arr);
buffer.position(buffer.position() + maxPacketSize());
Expand All @@ -56,16 +56,16 @@ public boolean chunkPrivilegedAccess() {

@Override
public void writeChunkToNBT(Chunk chunk, NBTTagCompound nbt) {
byte[] arr = Hooks.shortToByteArray(((IChunkMixin)chunk).getBiomeShortArray());
byte[] arr = Hooks.shortToByteArray(((ChunkBiomeHook)chunk).getBiomeShortArray());
nbt.setByteArray("Biomes16v2", arr);
}

@Override
public void readChunkFromNBT(Chunk chunk, NBTTagCompound nbt) {
var data = ((IChunkMixin) chunk).getBiomeShortArray();
var data = ((ChunkBiomeHook) chunk).getBiomeShortArray();
if (data == null) {
data = new short[16 * 16];
((IChunkMixin)chunk).setBiomeShortArray(data);
((ChunkBiomeHook)chunk).setBiomeShortArray(data);
}
if (nbt.hasKey("Biomes16v2", 7)) {
Hooks.byteToShortArray(nbt.getByteArray("Biomes16v2"), 0, data, 0, data.length * 2);
Expand All @@ -79,8 +79,8 @@ public void readChunkFromNBT(Chunk chunk, NBTTagCompound nbt) {

@Override
public void cloneChunk(Chunk fromVanilla, Chunk toVanilla) {
val from = (IChunkMixin) fromVanilla;
val to = (IChunkMixin) toVanilla;
val from = (ChunkBiomeHook) fromVanilla;
val to = (ChunkBiomeHook) toVanilla;

to.setBiomeShortArray(ArrayUtil.copyArray(from.getBiomeShortArray(), to.getBiomeShortArray()));
}
Expand Down
116 changes: 58 additions & 58 deletions src/main/java/com/falsepattern/endlessids/managers/BlockIDManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.falsepattern.chunk.api.ArrayUtil;
import com.falsepattern.chunk.api.DataManager;
import com.falsepattern.endlessids.Tags;
import com.falsepattern.endlessids.mixin.helpers.IExtendedBlockStorageMixin;
import com.falsepattern.endlessids.mixin.helpers.SubChunkBlockHook;
import lombok.val;
import lombok.var;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -34,35 +34,35 @@ public int maxPacketSize() {
}

@Override
public void writeToBuffer(Chunk chunk, int ebsMask, boolean forceUpdate, ByteBuffer data) {
val ebsList = chunk.getBlockStorageArray();
public void writeToBuffer(Chunk chunk, int subChunkMask, boolean forceUpdate, ByteBuffer data) {
val subChunkList = chunk.getBlockStorageArray();
int storageFlags = 0;
val start = data.position() + 4;
data.position(start);
for (int i = 0; i < 16; i++) {
if ((ebsMask & (1 << i)) == 0 || ebsList[i] == null) {
if ((subChunkMask & (1 << i)) == 0 || subChunkList[i] == null) {
continue;
}
val ebs = (IExtendedBlockStorageMixin) ebsList[i];
val subChunk = (SubChunkBlockHook) subChunkList[i];

storageFlags |= ebs.getEBSMSBMask() << (i * 2);
storageFlags |= subChunk.getBlockMask() << (i * 2);

val b1 = ebs.getB1();
val b1 = subChunk.getB1();
data.put(b1);

val b2Low = ebs.getB2Low();
val b2Low = subChunk.getB2Low();
if (b2Low == null) {
continue;
}
data.put(b2Low.data);

val b2High = ebs.getB2High();
val b2High = subChunk.getB2High();
if (b2High == null) {
continue;
}
data.put(b2High.data);

val b3 = ebs.getB3();
val b3 = subChunk.getB3();
if (b3 != null) {
data.put(b3);
}
Expand All @@ -71,45 +71,45 @@ public void writeToBuffer(Chunk chunk, int ebsMask, boolean forceUpdate, ByteBuf
}

@Override
public void readFromBuffer(Chunk chunk, int ebsMask, boolean forceUpdate, ByteBuffer buffer) {
val ebsList = chunk.getBlockStorageArray();
public void readFromBuffer(Chunk chunk, int subChunkMask, boolean forceUpdate, ByteBuffer buffer) {
val subChunkList = chunk.getBlockStorageArray();
val storageFlags = buffer.getInt();
for (int i = 0; i < 16; i++) {
if ((ebsMask & (1 << i)) == 0 || ebsList[i] == null) {
if ((subChunkMask & (1 << i)) == 0 || subChunkList[i] == null) {
continue;
}
val ebs = (IExtendedBlockStorageMixin) ebsList[i];
val subChunk = (SubChunkBlockHook) subChunkList[i];
val storageFlag = (storageFlags >>> (i * 2)) & 3;
val b1 = ebs.getB1();
val b1 = subChunk.getB1();
buffer.get(b1);
if (storageFlag == 0b00) {
ebs.setB2Low(null);
ebs.setB2High(null);
ebs.setB3(null);
subChunk.setB2Low(null);
subChunk.setB2High(null);
subChunk.setB3(null);
continue;
}
var b2Low = ebs.getB2Low();
var b2Low = subChunk.getB2Low();
if (b2Low == null) {
b2Low = ebs.createB2Low();
b2Low = subChunk.createB2Low();
}
buffer.get(b2Low.data);
if (storageFlag == 0b01) {
ebs.setB2High(null);
ebs.setB3(null);
subChunk.setB2High(null);
subChunk.setB3(null);
continue;
}
var b2High = ebs.getB2High();
var b2High = subChunk.getB2High();
if (b2High == null) {
b2High = ebs.createB2High();
b2High = subChunk.createB2High();
}
buffer.get(b2High.data);
if (storageFlag == 0b10) {
ebs.setB3(null);
subChunk.setB3(null);
continue;
}
var b3 = ebs.getB3();
var b3 = subChunk.getB3();
if (b3 == null) {
b3 = ebs.createB3();
b3 = subChunk.createB3();
}
buffer.get(b3);
}
Expand All @@ -122,27 +122,27 @@ public boolean subChunkPrivilegedAccess() {


@Override
public void writeSubChunkToNBT(Chunk chunk, ExtendedBlockStorage ebsVanilla, NBTTagCompound section) {
val ebs = (IExtendedBlockStorageMixin) ebsVanilla;
val b1 = ebs.getB1();
val b2Low = ebs.getB2Low();
val b2High = ebs.getB2High();
val b3 = ebs.getB3();
section.setByteArray("Blocks", b1);
public void writeSubChunkToNBT(Chunk chunk, ExtendedBlockStorage subChunkVanilla, NBTTagCompound nbt) {
val subChunk = (SubChunkBlockHook) subChunkVanilla;
val b1 = subChunk.getB1();
val b2Low = subChunk.getB2Low();
val b2High = subChunk.getB2High();
val b3 = subChunk.getB3();
nbt.setByteArray("Blocks", b1);
if (b2Low != null) {
section.setByteArray("Add", b2Low.data);
nbt.setByteArray("Add", b2Low.data);
}
if (b2High != null) {
section.setByteArray("BlocksB2Hi", b2High.data);
nbt.setByteArray("BlocksB2Hi", b2High.data);
}
if (b3 != null) {
section.setByteArray("BlocksB3", b3);
nbt.setByteArray("BlocksB3", b3);
}
}

//NotEnoughIDs world compatibility
public static void readSectionFromNBTNotEnoughIDsDFU(IExtendedBlockStorageMixin ebs, NBTTagCompound section) {
val data = section.getByteArray("Blocks16");
public static void readSectionFromNBTNotEnoughIDsDFU(SubChunkBlockHook subChunk, NBTTagCompound nbt) {
val data = nbt.getByteArray("Blocks16");
val dataShort = new short[data.length >>> 1];
ByteBuffer.wrap(data).asShortBuffer().get(dataShort);
val b1 = new byte[dataShort.length];
Expand All @@ -156,34 +156,34 @@ public static void readSectionFromNBTNotEnoughIDsDFU(IExtendedBlockStorageMixin
b2L[nI] |= ((s & 0x0F00) >>> 8) << mI;
b2H[nI] |= ((s & 0xF000) >>> 12) << mI;
}
ebs.setB1(b1);
ebs.setB2Low(new NibbleArray(b2L, 4));
ebs.setB2High(new NibbleArray(b2H, 4));
subChunk.setB1(b1);
subChunk.setB2Low(new NibbleArray(b2L, 4));
subChunk.setB2High(new NibbleArray(b2H, 4));
}

@Override
public void readSubChunkFromNBT(Chunk chunk, ExtendedBlockStorage ebsVanilla, NBTTagCompound section) {
val ebs = (IExtendedBlockStorageMixin) ebsVanilla;
if (section.hasKey("Blocks16")) {
readSectionFromNBTNotEnoughIDsDFU(ebs, section);
public void readSubChunkFromNBT(Chunk chunk, ExtendedBlockStorage subChunkVanilla, NBTTagCompound nbt) {
val subChunk = (SubChunkBlockHook) subChunkVanilla;
if (nbt.hasKey("Blocks16")) {
readSectionFromNBTNotEnoughIDsDFU(subChunk, nbt);
return;
}
assert section.hasKey("Blocks");
val b1 = section.getByteArray("Blocks");
final byte[] b2Low = section.hasKey("Add") ? section.getByteArray("Add") : null;
final byte[] b2High = section.hasKey("BlocksB2Hi") ? section.getByteArray("BlocksB2Hi") : null;
final byte[] b3 = section.hasKey("BlocksB3") ? section.getByteArray("BlocksB3") : null;

ebs.setB1(b1);
ebs.setB2Low(b2Low == null ? null : new NibbleArray(b2Low, 4));
ebs.setB2High(b2High == null ? null : new NibbleArray(b2High, 4));
ebs.setB3(b3);
assert nbt.hasKey("Blocks");
val b1 = nbt.getByteArray("Blocks");
final byte[] b2Low = nbt.hasKey("Add") ? nbt.getByteArray("Add") : null;
final byte[] b2High = nbt.hasKey("BlocksB2Hi") ? nbt.getByteArray("BlocksB2Hi") : null;
final byte[] b3 = nbt.hasKey("BlocksB3") ? nbt.getByteArray("BlocksB3") : null;

subChunk.setB1(b1);
subChunk.setB2Low(b2Low == null ? null : new NibbleArray(b2Low, 4));
subChunk.setB2High(b2High == null ? null : new NibbleArray(b2High, 4));
subChunk.setB3(b3);
}

@Override
public void cloneSubChunk(Chunk fromChunk, ExtendedBlockStorage fromVanilla, ExtendedBlockStorage toVanilla) {
val from = (IExtendedBlockStorageMixin) fromVanilla;
val to = (IExtendedBlockStorageMixin) toVanilla;
val from = (SubChunkBlockHook) fromVanilla;
val to = (SubChunkBlockHook) toVanilla;

to.setB1(ArrayUtil.copyArray(from.getB1(), to.getB1()));
to.setB2Low(ArrayUtil.copyArray(from.getB2Low(), to.getB2Low()));
Expand Down
Loading

0 comments on commit 3dd168f

Please sign in to comment.