16 million item IDs

This commit is contained in:
FalsePattern committed 2022-03-17 22:24:32 +01:00
1 parent c486782e32
commit 366582f781
13 files changed
+260 -139

No files matched your search

@@ -2,122 +2,111 @@ package com.falsepattern.endlessids;
import com.falsepattern.endlessids.constants.ExtendedConstants;
import com.falsepattern.endlessids.mixin.helpers.IExtendedBlockStorageMixin;
import lombok.val;
import net.minecraft.init.Blocks;
import net.minecraft.block.Block;
import net.minecraft.nbt.NBTTagCompound;
import java.nio.ShortBuffer;
import java.nio.ByteBuffer;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
public class Hooks
{
public Hooks() {
super();
}
public class Hooks {
public static byte[] getBlockData(final IExtendedBlockStorageMixin ebs) {
final short[] data = ebs.get16B();
final byte[] ret = new byte[data.length * 2];
ByteBuffer.wrap(ret).asShortBuffer().put(data);
val lsb = ebs.getLSB();
val msb = ebs.getMSB();
final byte[] ret = new byte[lsb.length * 3];
ByteBuffer.wrap(ret).asShortBuffer().put(lsb);
System.arraycopy(msb, 0, ret, lsb.length * 2, lsb.length);
return ret;
}
public static void setBlockData(final IExtendedBlockStorageMixin ebs, final byte[] data, final int offset) {
ShortBuffer.wrap(ebs.get16B()).put(ByteBuffer.wrap(data, offset, 8192).asShortBuffer());
}
public static void writeChunkToNbt(final NBTTagCompound nbt, final IExtendedBlockStorageMixin ebs) {
nbt.setByteArray("Blocks16", getBlockData(ebs));
if (IEConfig.postNeidWorldsSupport) {
final short[] data = ebs.getLSB();
final byte[] lsbData = new byte[data.length];
byte[] msbData = null;
for (int i = 0; i < data.length; ++i) {
final int id = data[i] & ExtendedConstants.blockIDMask;
if (id <= 255) {
lsbData[i] = (byte)id;
}
else if (id <= 4095) {
if (msbData == null) {
msbData = new byte[data.length / 2];
}
lsbData[i] = (byte)id;
if (i % 2 == 0) {
final byte[] array = msbData;
final int n = i / 2;
array[n] |= (byte)(id >>> 8 & 0xF);
}
else {
final byte[] array2 = msbData;
final int n2 = i / 2;
array2[n2] |= (byte)(id >>> 4 & 0xF0);
}
}
}
nbt.setByteArray("Blocks", lsbData);
if (msbData != null) {
nbt.setByteArray("Add", msbData);
}
}
}
public static void readChunkFromNbt(final IExtendedBlockStorageMixin ebs, final NBTTagCompound nbt) {
if (nbt.hasKey("Blocks16")) {
setBlockData(ebs, nbt.getByteArray("Blocks16"), 0);
}
else if (nbt.hasKey("Blocks")) {
final short[] out = ebs.get16B();
final byte[] lsbData = nbt.getByteArray("Blocks");
if (nbt.hasKey("Add")) {
final byte[] msbData = nbt.getByteArray("Add");
for (int i = 0; i < out.length; i += 2) {
final byte msPart = msbData[i / 2];
out[i] = (short)((lsbData[i] & 0xFF) | (msPart & 0xF) << 8);
out[i + 1] = (short)((lsbData[i + 1] & 0xFF) | (msPart & 0xF0) << 4);
}
}
else {
for (int j = 0; j < out.length; ++j) {
out[j] = (short)(lsbData[j] & 0xFF);
}
}
}
else {
assert false;
}
}
public static int getBlockId(final IExtendedBlockStorageMixin ebs, final int x, final int y, final int z) {
return ebs.get16B()[y << 8 | z << 4 | x] & 0xFFFF;
}
public static Block getBlock(final IExtendedBlockStorageMixin ebs, final int x, final int y, final int z) {
return Block.getBlockById(getBlockId(ebs, x, y, z));
}
public static void setBlockId(final IExtendedBlockStorageMixin ebs, final int x, final int y, final int z, final int id) {
ebs.get16B()[y << 8 | z << 4 | x] = (short)id;
}
public static short[] create16BArray() {
return new short[4096];
val lsb = ebs.getLSB();
val msb = ebs.getMSB();
val lsbBytes = lsb.length * 2;
ShortBuffer.wrap(ebs.getLSB()).put(ByteBuffer.wrap(data, offset, lsbBytes).asShortBuffer());
System.arraycopy(data, offset + lsbBytes, msb, 0, msb.length);
}
public static byte[] create8BArray() {
return new byte[4096];
public static void writeChunkToNbt(final NBTTagCompound nbt, final IExtendedBlockStorageMixin ebs) {
val ebsLSB = ebs.getLSB();
val ebsMSB = ebs.getMSB();
val byte1Data = new byte[ebsLSB.length];
byte[] byte2BottomNibbleData = null;
byte[] byte2TopNibbleData = null;
byte[] byte3Data = null;
for (int i = 0; i < ebsLSB.length; ++i) {
if (ebsMSB[i] != 0) {
if (byte3Data == null) {
byte3Data = new byte[ebsLSB.length];
}
byte3Data[i] = ebsMSB[i];
}
val idLSB = (ebsLSB[i] & 0xFFFF);
byte1Data[i] = (byte)(idLSB & 0xFF);
if (idLSB <= 0xFF) continue;
val nibbleIndex = i >> 1;
val nibbleShift = (i & 1) * 4;
if (byte2BottomNibbleData == null) {
byte2BottomNibbleData = new byte[ebsLSB.length / 2];
}
byte2BottomNibbleData[nibbleIndex] |= ((idLSB >>> 8) & 0xF) << nibbleShift;
if (idLSB <= 0xFFF) continue;
if (byte2TopNibbleData == null) {
byte2TopNibbleData = new byte[ebsLSB.length / 2];
}
byte2TopNibbleData[nibbleIndex] |= ((idLSB >>> 12) & 0xF) << nibbleShift;
}
nbt.setByteArray("Blocks", byte1Data);
if (byte2BottomNibbleData != null)
nbt.setByteArray("Add", byte2BottomNibbleData);
if (byte2TopNibbleData != null)
nbt.setByteArray("BlocksB2Hi", byte2TopNibbleData);
if (byte3Data != null)
nbt.setByteArray("BlocksB3", byte3Data);
}
public static void readChunkFromNbt(final IExtendedBlockStorageMixin ebs, final NBTTagCompound nbt) {
assert nbt.hasKey("Blocks");
val byte1Data = nbt.getByteArray("Blocks");
val byte2BottomNibbleData = nbt.hasKey("Add") ? nbt.getByteArray("Add") : null;
val byte2TopNibbleData = nbt.hasKey("BlocksB2Hi") ? nbt.getByteArray("BlocksB2Hi") : null;
val byte3Data = nbt.hasKey("BlocksB3") ? nbt.getByteArray("BlocksB3") : null;
val lsb = ebs.getLSB();
val msb = ebs.getMSB();
for (int i = 0; i < lsb.length; i++) {
if (byte3Data != null) {
msb[i] = byte3Data[i];
}
int nibbleShift = (i & 1) * 4;
int id = byte1Data[i] & 0xFF;
if (byte2BottomNibbleData != null) {
id |= ((byte2BottomNibbleData[i >> 1] >> nibbleShift) & 0xF) << 8;
}
if (byte2TopNibbleData != null) {
id |= ((byte2TopNibbleData[i >> 1] >> nibbleShift) & 0xF) << 12;
}
lsb[i] = (short)id;
}
}
public static void removeInvalidBlocksHook(final IExtendedBlockStorageMixin ebs) {
final short[] blkIds = ebs.get16B();
val blkIdsLSB = ebs.getLSB();
val blkIdsMSB = ebs.getMSB();
int cntNonEmpty = 0;
int cntTicking = 0;
for (int off = 0; off < blkIds.length; ++off) {
final int id = blkIds[off] & 0xFFFF;
for (int off = 0; off < blkIdsLSB.length; ++off) {
final int id = ((blkIdsLSB[off] & 0xFFFF) | ((blkIdsMSB[off] & 0xFF) << 16)) & ExtendedConstants.blockIDMask;
if (id > 0) {
final Block block = (Block)Block.blockRegistry.getObjectById(id);
if (block == null) {
if (IEConfig.removeInvalidBlocks) {
blkIds[off] = 0;
blkIdsLSB[off] = 0;
}
}
else if (block != Blocks.air) {