Remove world instance and use directly data from the loaded chunk
This commit is contained in:
parent
e3ac0f5e35
commit
1df8778984
|
@ -1,27 +1,24 @@
|
||||||
package Orebfuscator;
|
package Orebfuscator;
|
||||||
|
|
||||||
import Orebfuscator.Options.WorldOptions;
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.network.play.server.S26PacketMapChunkBulk;
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
|
||||||
|
|
||||||
public class ChunkObfuscator
|
public class ChunkObfuscator
|
||||||
{
|
{
|
||||||
// èíôîðìàöèÿ î íàëè÷èè ñåêöèè. Ñåêöèè - ýòî áëîêè ðàçìåðîì 16õ16õ16, ñåêöèè ðàñïîëàãàþòñÿ äðóã íàä äðóãîì
|
// ?????????? ? ??????? ??????. ?????? - ??? ????? ???????? 16?16?16, ?????? ????????????? ???? ??? ??????
|
||||||
// Chunk ñîñòîèò èç 16 ñåêöèé, ðàçìåð ÷àíêà 16x16x256
|
// Chunk ??????? ?? 16 ??????, ?????? ????? 16x16x256
|
||||||
//public boolean[] listLSB = new boolean[16];
|
//public boolean[] listLSB = new boolean[16];
|
||||||
//public boolean[] listMSB = new boolean[16];
|
//public boolean[] listMSB = new boolean[16];
|
||||||
|
|
||||||
// offsetsLSB[] - ñîäåðæèò ñïèñîê ñåêöèé, ñ êîòîðûõ íà÷èíàþòñÿ áëîêè ðàçìåðîì 16x16x16 ñîäåðæàùèå ïåðâûå 8 áèò BlockID
|
// offsetsLSB[] - ???????? ?????? ??????, ? ??????? ?????????? ????? ???????? 16x16x16 ?????????? ?????? 8 ??? BlockID
|
||||||
// ðàçìåð ñåêöèè 16*16*16 = 4096 áàéò
|
// ?????? ?????? 16*16*16 = 4096 ????
|
||||||
public int[] offsetsLSB = new int[16];
|
public int[] offsetsLSB = new int[16];
|
||||||
|
|
||||||
// íà÷àëî NibbleArrays ñîäåðæàùèõ ExtendedBlockStorage.blockMetadataArray
|
// ?????? NibbleArrays ?????????? ExtendedBlockStorage.blockMetadataArray
|
||||||
// ðàçìåð ìàññèâà (16*16*16)/2 = 2048 (äåëèì ïîïàëàì, ò.ê. â îäíîì áàéòå ñîäåðæèòñÿ äâà çíà÷åíèÿ ïî 4 áèòà)
|
// ?????? ??????? (16*16*16)/2 = 2048 (????? ???????, ?.?. ? ????? ????? ?????????? ??? ???????? ?? 4 ????)
|
||||||
public int[] offsetsMetadata = new int[16];
|
public int[] offsetsMetadata = new int[16];
|
||||||
|
|
||||||
// íà÷àëî NibbleArray ñîäåðæàùåãî ExtendedBlockStorage.blocklightArray
|
// ?????? NibbleArray ??????????? ExtendedBlockStorage.blocklightArray
|
||||||
public int[] offsetsBlocklight = new int[16];
|
public int[] offsetsBlocklight = new int[16];
|
||||||
|
|
||||||
// NibbleArray ExtendedBlockStorage.blockMSBArray
|
// NibbleArray ExtendedBlockStorage.blockMSBArray
|
||||||
|
@ -30,7 +27,7 @@ public class ChunkObfuscator
|
||||||
public int startX;
|
public int startX;
|
||||||
public int startZ;
|
public int startZ;
|
||||||
|
|
||||||
// Ìàêñèìàëüíûé èíäåêñ+1 ñåêöèè
|
// ???????????? ??????+1 ??????
|
||||||
public int len;
|
public int len;
|
||||||
public byte[] data;
|
public byte[] data;
|
||||||
|
|
||||||
|
@ -40,175 +37,174 @@ public class ChunkObfuscator
|
||||||
this.startZ = chunkZ << 4;
|
this.startZ = chunkZ << 4;
|
||||||
|
|
||||||
this.data = data;
|
this.data = data;
|
||||||
int countLSB = 0;
|
int countLSB = 0;
|
||||||
len = 0;
|
len = 0;
|
||||||
int l;
|
int l;
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < 16; ++i)
|
for (i = 0; i < 16; ++i)
|
||||||
{
|
{
|
||||||
l = sectionLSB >> i & 1;
|
l = sectionLSB >> i & 1;
|
||||||
if (l == 1)
|
if (l == 1)
|
||||||
{
|
{
|
||||||
offsetsLSB[i] = pos;
|
offsetsLSB[i] = pos;
|
||||||
pos += 4096;
|
pos += 4096;
|
||||||
|
|
||||||
countLSB++;
|
countLSB++;
|
||||||
len = i + 1;
|
len = i + 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
offsetsLSB[i] = -1;
|
offsetsLSB[i] = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
if (offsetsLSB[i] > -1)
|
if (offsetsLSB[i] > -1)
|
||||||
{
|
{
|
||||||
offsetsMetadata[i] = pos;
|
offsetsMetadata[i] = pos;
|
||||||
pos += 2048;
|
pos += 2048;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
if (offsetsLSB[i] > -1)
|
if (offsetsLSB[i] > -1)
|
||||||
{
|
{
|
||||||
offsetsBlocklight[i] = pos;
|
offsetsBlocklight[i] = pos;
|
||||||
pos += 2048;
|
pos += 2048;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//if (!world.provider.hasNoSky)
|
//if (!world.provider.hasNoSky)
|
||||||
if (hasSky)
|
if (hasSky)
|
||||||
{
|
{
|
||||||
// åñëè åñòü íåáî, òî â áóôåðå áóäåò ìàññèâ ExtendedBlockStorage.skylightArray
|
// ???? ???? ????, ?? ? ?????? ????? ?????? ExtendedBlockStorage.skylightArray
|
||||||
pos += countLSB * 2048;
|
pos += countLSB * 2048;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
l = sectionMSB >> i & 1;
|
l = sectionMSB >> i & 1;
|
||||||
if (l == 1)
|
if (l == 1)
|
||||||
{
|
{
|
||||||
offsetsMSB[i] = pos;
|
offsetsMSB[i] = pos;
|
||||||
pos += 2048;
|
pos += 2048;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
offsetsMSB[i] = -1;
|
offsetsMSB[i] = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// biome info
|
// biome info
|
||||||
pos += 256;
|
pos += 256;
|
||||||
|
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
if (offsetsLSB[i] > -1)
|
if (offsetsLSB[i] > -1)
|
||||||
{
|
{
|
||||||
l = i << 4;
|
l = i << 4;
|
||||||
for (int x = 0; x < 16; x++)
|
for (int x = 0; x < 16; x++)
|
||||||
{
|
{
|
||||||
for (int y = 0; y < 16; y++)
|
for (int y = 0; y < 16; y++)
|
||||||
{
|
{
|
||||||
for (int z = 0; z < 16; z++)
|
for (int z = 0; z < 16; z++)
|
||||||
{
|
{
|
||||||
if (neetObfuscate(world, x, l | y, z))
|
if (neetObfuscate(x, l | y, z))
|
||||||
{
|
{
|
||||||
setBlockID(x, l | y, z, Options.worldOptions.getRandomID());
|
setBlockID(x, l | y, z, Options.worldOptions.getRandomID());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the block corresponding to the given coordinates inside a chunk.
|
* Returns the block corresponding to the given coordinates inside a chunk.
|
||||||
*/
|
*/
|
||||||
public int getBlockID(World world, int x, int y, int z)
|
public int getBlockID(int x, int y, int z) {
|
||||||
{
|
int sectionIndex = y >> 4; // Index de la section
|
||||||
int section = y >> 4;
|
if (sectionIndex >= offsetsLSB.length || offsetsLSB[sectionIndex] == -1) {
|
||||||
if (this.offsetsLSB[section] > -1)
|
return 0;
|
||||||
{
|
}
|
||||||
y = y & 15;
|
int yLocal = y & 15;
|
||||||
|
int xLocal = x & 15;
|
||||||
|
int zLocal = z & 15;
|
||||||
|
int blockIndex = (yLocal << 8) | (zLocal << 4) | xLocal;
|
||||||
|
|
||||||
int id = this.data[this.offsetsLSB[section] + (y << 8 | z << 4 | x)] & 255;
|
int lsbIndex = offsetsLSB[sectionIndex] + blockIndex;
|
||||||
if (this.offsetsMSB[section] > -1)
|
int lsb = data[lsbIndex] & 0xFF;
|
||||||
{
|
|
||||||
int l = y << 4 | z << 4 | x;
|
|
||||||
int i1 = l >> 1;
|
|
||||||
int j1 = l & 1;
|
|
||||||
id |= j1 == 0 ? this.data[this.offsetsMSB[section] + i1] & 15 : this.data[this.offsetsMSB[section] + i1] >> 4 & 15;
|
|
||||||
}
|
|
||||||
|
|
||||||
return id;
|
int msb = 0;
|
||||||
}
|
if (offsetsMSB[sectionIndex] > -1) {
|
||||||
|
int msbByteIndex = offsetsMSB[sectionIndex] + (blockIndex >> 1);
|
||||||
|
int msbByte = data[msbByteIndex] & 0xFF;
|
||||||
|
if ((blockIndex & 1) == 0) {
|
||||||
|
msb = msbByte & 0x0F;
|
||||||
|
} else {
|
||||||
|
msb = (msbByte >> 4) & 0x0F;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return (msb << 8) | lsb;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBlockID(int x, int y, int z, int blockID)
|
public void setBlockID(int x, int y, int z, int blockID)
|
||||||
{
|
{
|
||||||
int section = y >> 4;
|
int section = y >> 4;
|
||||||
if (this.offsetsLSB[section] > -1)
|
if (this.offsetsLSB[section] > -1)
|
||||||
{
|
|
||||||
y = y & 15;
|
|
||||||
|
|
||||||
this.data[this.offsetsLSB[section] + (y << 8 | z << 4 | x)] = (byte) (blockID & 255);
|
|
||||||
if (this.offsetsMSB[section] > -1)
|
|
||||||
{
|
|
||||||
int l = y << 4 | z << 4 | x;
|
|
||||||
int i1 = l >> 1;
|
|
||||||
int j1 = l & 1;
|
|
||||||
int pos = this.offsetsMSB[section] + i1;
|
|
||||||
if (j1 == 0)
|
|
||||||
{
|
|
||||||
this.data[pos] = (byte)(this.data[pos] & 240 | blockID & 15);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.data[pos] = (byte)(this.data[pos] & 15 | (blockID & 15) << 4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isTransparent(World world, int x, int y, int z)
|
|
||||||
{
|
|
||||||
if (y < 0 || y > 255)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (x < 0 || x > 15 || z < 0 || z > 15)
|
|
||||||
{
|
{
|
||||||
return Options.isBlockTransparent(BlockHelper.getBlockID(world, this.startX + x, y, this.startZ + z));
|
y = y & 15;
|
||||||
}
|
|
||||||
|
|
||||||
return Options.isBlockTransparent(getBlockID(world, x, y, z));
|
this.data[this.offsetsLSB[section] + (y << 8 | z << 4 | x)] = (byte) (blockID & 255);
|
||||||
|
if (this.offsetsMSB[section] > -1)
|
||||||
|
{
|
||||||
|
int l = y << 4 | z << 4 | x;
|
||||||
|
int i1 = l >> 1;
|
||||||
|
int j1 = l & 1;
|
||||||
|
int pos = this.offsetsMSB[section] + i1;
|
||||||
|
if (j1 == 0)
|
||||||
|
{
|
||||||
|
this.data[pos] = (byte)(this.data[pos] & 240 | blockID & 15);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.data[pos] = (byte)(this.data[pos] & 15 | (blockID & 15) << 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean neetObfuscate(World world, int x, int y, int z)
|
public boolean isTransparent(int x, int y, int z) {
|
||||||
{
|
if (x < 0 || x > 15 || y < 0 || y > 255 || z < 0 || z > 15) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
int blockID = getBlockID(x, y, z);
|
||||||
|
return Options.isTransparent(Block.getBlockById(blockID));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean neetObfuscate(int x, int y, int z) {
|
||||||
if (y > Options.worldOptions.maxObfuscateHeight)
|
if (y > Options.worldOptions.maxObfuscateHeight)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!Options.isObfuscated(getBlockID(world, x, y, z)))
|
int blockID = getBlockID(x, y, z);
|
||||||
{
|
if (!Options.isObfuscated(blockID)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return !(
|
return !(
|
||||||
isTransparent(world, x - 1, y, z) ||
|
isTransparent(x - 1, y, z) ||
|
||||||
isTransparent(world, x + 1, y, z) ||
|
isTransparent(x + 1, y, z) ||
|
||||||
isTransparent(world, x, y - 1, z) ||
|
isTransparent(x, y - 1, z) ||
|
||||||
isTransparent(world, x, y + 1, z) ||
|
isTransparent(x, y + 1, z) ||
|
||||||
isTransparent(world, x, y, z - 1) ||
|
isTransparent(x, y, z - 1) ||
|
||||||
isTransparent(world, x, y, z + 1)
|
isTransparent(x, y, z + 1)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue