use of net.minecraft.server.v1_10_R1.ChunkSection in project Movecraft by APDevTeam.
the class IWorldHandler method setBlockFast.
private void setBlockFast(@NotNull World world, @NotNull BlockPosition position, @NotNull IBlockData data) {
Chunk chunk = world.getChunkAtWorldCoords(position);
ChunkSection chunkSection = chunk.getSections()[position.getY() >> 4];
if (chunkSection == null) {
// Put a GLASS block to initialize the section. It will be replaced next with the real block.
chunk.setType(position, Blocks.GLASS.getBlockData(), false);
chunkSection = chunk.getSections()[position.getY() >> 4];
}
if (chunkSection.getType(position.getX() & 15, position.getY() & 15, position.getZ() & 15).equals(data)) {
// Block is already of correct type and data, don't overwrite
return;
}
chunkSection.setType(position.getX() & 15, position.getY() & 15, position.getZ() & 15, data);
world.notify(position, data, data, 3);
var engine = chunk.e();
if (engine != null)
engine.a(position);
chunk.markDirty();
}
use of net.minecraft.server.v1_10_R1.ChunkSection in project Movecraft by APDevTeam.
the class IWorldHandler method setBlockFast.
private void setBlockFast(@NotNull World world, @NotNull BlockPosition position, @NotNull IBlockData data) {
Chunk chunk = world.getChunkAtWorldCoords(position);
ChunkSection chunkSection = chunk.getSections()[position.getY() >> 4];
if (chunkSection == null) {
// Put a GLASS block to initialize the section. It will be replaced next with the real block.
chunk.setType(position, Blocks.GLASS.getBlockData(), false);
chunkSection = chunk.getSections()[position.getY() >> 4];
}
if (chunkSection.getType(position.getX() & 15, position.getY() & 15, position.getZ() & 15).equals(data)) {
// Block is already of correct type and data, don't overwrite
return;
}
chunkSection.setType(position.getX() & 15, position.getY() & 15, position.getZ() & 15, data);
world.notify(position, data, data, 3);
var engine = chunk.e();
if (engine != null)
engine.a(position);
chunk.markDirty();
}
use of net.minecraft.server.v1_10_R1.ChunkSection in project PaperDev by Kamillaova.
the class ChunkPacketBlockControllerAntiXray method obfuscate.
public void obfuscate(PacketPlayOutMapChunkInfoAntiXray packetPlayOutMapChunkInfoAntiXray) {
boolean[] solidTemp = null;
boolean[] obfuscateTemp = null;
dataBitsReader.setDataBits(packetPlayOutMapChunkInfoAntiXray.getData());
dataBitsWriter.setDataBits(packetPlayOutMapChunkInfoAntiXray.getData());
int counter = 0;
for (int chunkSectionIndex = 0; chunkSectionIndex <= maxChunkSectionIndex; chunkSectionIndex++) {
if (packetPlayOutMapChunkInfoAntiXray.isWritten(chunkSectionIndex) && packetPlayOutMapChunkInfoAntiXray.getPredefinedBlockData(chunkSectionIndex) != null) {
int[] predefinedBlockDataBitsTemp = packetPlayOutMapChunkInfoAntiXray.getDataPalette(chunkSectionIndex) instanceof DataPaletteGlobal ? engineMode == EngineMode.HIDE ? packetPlayOutMapChunkInfoAntiXray.getChunk().world.getWorld().getEnvironment() == Environment.NETHER ? predefinedBlockDataBitsNetherrackGlobal : packetPlayOutMapChunkInfoAntiXray.getChunk().world.getWorld().getEnvironment() == Environment.THE_END ? predefinedBlockDataBitsEndStoneGlobal : predefinedBlockDataBitsStoneGlobal : predefinedBlockDataBitsGlobal : predefinedBlockDataBits;
dataBitsWriter.setIndex(packetPlayOutMapChunkInfoAntiXray.getDataBitsIndex(chunkSectionIndex));
// Check if the chunk section below was not obfuscated
if (chunkSectionIndex == 0 || !packetPlayOutMapChunkInfoAntiXray.isWritten(chunkSectionIndex - 1) || packetPlayOutMapChunkInfoAntiXray.getPredefinedBlockData(chunkSectionIndex - 1) == null) {
// If so, initialize some stuff
dataBitsReader.setBitsPerValue(packetPlayOutMapChunkInfoAntiXray.getBitsPerValue(chunkSectionIndex));
dataBitsReader.setIndex(packetPlayOutMapChunkInfoAntiXray.getDataBitsIndex(chunkSectionIndex));
solidTemp = readDataPalette(packetPlayOutMapChunkInfoAntiXray.getDataPalette(chunkSectionIndex), solid, solidGlobal);
obfuscateTemp = readDataPalette(packetPlayOutMapChunkInfoAntiXray.getDataPalette(chunkSectionIndex), obfuscate, obfuscateGlobal);
// Read the blocks of the upper layer of the chunk section below if it exists
ChunkSection belowChunkSection = null;
boolean skipFirstLayer = chunkSectionIndex == 0 || (belowChunkSection = packetPlayOutMapChunkInfoAntiXray.getChunk().getSections()[chunkSectionIndex - 1]) == Chunk.EMPTY_CHUNK_SECTION;
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++) {
current[z][x] = true;
next[z][x] = skipFirstLayer || !solidGlobal[Block.REGISTRY_ID.getId(belowChunkSection.getType(x, 15, z))];
}
}
// Abuse the obfuscateLayer method to read the blocks of the first layer of the current chunk section
dataBitsWriter.setBitsPerValue(0);
obfuscateLayer(-1, dataBitsReader, dataBitsWriter, solidTemp, obfuscateTemp, predefinedBlockDataBitsTemp, current, next, nextNext, emptyNearbyChunkSections, counter);
}
dataBitsWriter.setBitsPerValue(packetPlayOutMapChunkInfoAntiXray.getBitsPerValue(chunkSectionIndex));
nearbyChunkSections[0] = packetPlayOutMapChunkInfoAntiXray.getNearbyChunks()[0] == null ? Chunk.EMPTY_CHUNK_SECTION : packetPlayOutMapChunkInfoAntiXray.getNearbyChunks()[0].getSections()[chunkSectionIndex];
nearbyChunkSections[1] = packetPlayOutMapChunkInfoAntiXray.getNearbyChunks()[1] == null ? Chunk.EMPTY_CHUNK_SECTION : packetPlayOutMapChunkInfoAntiXray.getNearbyChunks()[1].getSections()[chunkSectionIndex];
nearbyChunkSections[2] = packetPlayOutMapChunkInfoAntiXray.getNearbyChunks()[2] == null ? Chunk.EMPTY_CHUNK_SECTION : packetPlayOutMapChunkInfoAntiXray.getNearbyChunks()[2].getSections()[chunkSectionIndex];
nearbyChunkSections[3] = packetPlayOutMapChunkInfoAntiXray.getNearbyChunks()[3] == null ? Chunk.EMPTY_CHUNK_SECTION : packetPlayOutMapChunkInfoAntiXray.getNearbyChunks()[3].getSections()[chunkSectionIndex];
// Obfuscate all layers of the current chunk section except the upper one
for (int y = 0; y < 15; y++) {
boolean[][] temp = current;
current = next;
next = nextNext;
nextNext = temp;
counter = obfuscateLayer(y, dataBitsReader, dataBitsWriter, solidTemp, obfuscateTemp, predefinedBlockDataBitsTemp, current, next, nextNext, nearbyChunkSections, counter);
}
// Check if the chunk section above doesn't need obfuscation
if (chunkSectionIndex == maxChunkSectionIndex || !packetPlayOutMapChunkInfoAntiXray.isWritten(chunkSectionIndex + 1) || packetPlayOutMapChunkInfoAntiXray.getPredefinedBlockData(chunkSectionIndex + 1) == null) {
// If so, obfuscate the upper layer of the current chunk section by reading blocks of the first layer from the chunk section above if it exists
ChunkSection aboveChunkSection;
if (chunkSectionIndex != 15 && (aboveChunkSection = packetPlayOutMapChunkInfoAntiXray.getChunk().getSections()[chunkSectionIndex + 1]) != Chunk.EMPTY_CHUNK_SECTION) {
boolean[][] temp = current;
current = next;
next = nextNext;
nextNext = temp;
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++) {
if (!solidGlobal[Block.REGISTRY_ID.getId(aboveChunkSection.getType(x, 0, z))]) {
current[z][x] = true;
}
}
}
// There is nothing to read anymore
dataBitsReader.setBitsPerValue(0);
solid[0] = true;
counter = obfuscateLayer(15, dataBitsReader, dataBitsWriter, solid, obfuscateTemp, predefinedBlockDataBitsTemp, current, next, nextNext, nearbyChunkSections, counter);
}
} else {
// If not, initialize the reader and other stuff for the chunk section above to obfuscate the upper layer of the current chunk section
dataBitsReader.setBitsPerValue(packetPlayOutMapChunkInfoAntiXray.getBitsPerValue(chunkSectionIndex + 1));
dataBitsReader.setIndex(packetPlayOutMapChunkInfoAntiXray.getDataBitsIndex(chunkSectionIndex + 1));
solidTemp = readDataPalette(packetPlayOutMapChunkInfoAntiXray.getDataPalette(chunkSectionIndex + 1), solid, solidGlobal);
obfuscateTemp = readDataPalette(packetPlayOutMapChunkInfoAntiXray.getDataPalette(chunkSectionIndex + 1), obfuscate, obfuscateGlobal);
boolean[][] temp = current;
current = next;
next = nextNext;
nextNext = temp;
counter = obfuscateLayer(15, dataBitsReader, dataBitsWriter, solidTemp, obfuscateTemp, predefinedBlockDataBitsTemp, current, next, nextNext, nearbyChunkSections, counter);
}
dataBitsWriter.finish();
}
}
packetPlayOutMapChunkInfoAntiXray.getPacketPlayOutMapChunk().setReady(true);
}
Aggregations