Search in sources :

Example 1 with ChunkPacketBlockController

use of com.destroystokyo.paper.antixray.ChunkPacketBlockController in project RayTraceAntiXray by stonar96.

the class RayTraceRunnable method run.

@Override
public void run() {
    List<? extends Location> locations = playerData.getLocations();
    Location playerLocation = locations.get(0);
    ChunkPacketBlockController chunkPacketBlockController = ((CraftWorld) playerLocation.getWorld()).getHandle().chunkPacketBlockController;
    if (!(chunkPacketBlockController instanceof ChunkPacketBlockControllerAntiXray)) {
        return;
    }
    boolean[] solidGlobal = ((ChunkPacketBlockControllerAntiXray) chunkPacketBlockController).solidGlobal;
    double rayTraceDistance = Math.max(plugin.getConfig().getDouble("world-settings." + playerLocation.getWorld().getName() + ".anti-xray.ray-trace-distance", plugin.getConfig().getDouble("world-settings.default.anti-xray.ray-trace-distance")), 0.);
    Location temp = playerLocation.clone();
    temp.setX(playerLocation.getX() - rayTraceDistance);
    temp.setZ(playerLocation.getZ() - rayTraceDistance);
    int chunkXMin = temp.getBlockX() >> 4;
    int chunkZMin = temp.getBlockZ() >> 4;
    temp.setX(playerLocation.getX() + rayTraceDistance);
    temp.setZ(playerLocation.getZ() + rayTraceDistance);
    int chunkXMax = temp.getBlockX() >> 4;
    int chunkZMax = temp.getBlockZ() >> 4;
    double rayTraceDistanceSquared = rayTraceDistance * rayTraceDistance;
    for (Location location : locations) {
        Vector vector = location.toVector();
        Vector direction = location.getDirection();
        for (Entry<ChunkPos, ChunkBlocks> chunkEntry : playerData.getChunks().entrySet()) {
            ChunkBlocks chunkBlocks = chunkEntry.getValue();
            LevelChunk chunk = chunkBlocks.getChunk();
            if (chunk == null) {
                playerData.getChunks().remove(chunkEntry.getKey(), chunkBlocks);
                continue;
            }
            if (chunk.locX < chunkXMin || chunk.locX > chunkXMax || chunk.locZ < chunkZMin || chunk.locZ > chunkZMax) {
                continue;
            }
            Iterator<? extends BlockPos> iterator = chunkBlocks.getBlocks().iterator();
            while (iterator.hasNext()) {
                BlockPos block = iterator.next();
                block = new BlockPos((chunk.locX << 4) + block.getX(), block.getY(), (chunk.locZ << 4) + block.getZ());
                Vector blockCenter = new Vector(block.getX() + 0.5, block.getY() + 0.5, block.getZ() + 0.5);
                Vector difference = vector.clone().subtract(blockCenter);
                if (difference.lengthSquared() > rayTraceDistanceSquared || difference.dot(direction) > 0.) {
                    continue;
                }
                Iterator<BlockPos> blockIterator = new BlockIterator(blockCenter, vector);
                boolean update = true;
                while (blockIterator.hasNext()) {
                    BlockPos rayBlock = blockIterator.next();
                    ChunkPos chunkPos = new ChunkPos(rayBlock);
                    ChunkBlocks rayChunkBlocks = playerData.getChunks().get(chunkPos);
                    if (rayChunkBlocks == null) {
                        update = false;
                        break;
                    }
                    LevelChunk rayChunk = rayChunkBlocks.getChunk();
                    if (rayChunk == null) {
                        playerData.getChunks().remove(chunkPos, rayChunkBlocks);
                        update = false;
                        break;
                    }
                    int sectionY = rayBlock.getY() >> 4;
                    if (sectionY < rayChunk.getMinSection() || sectionY > rayChunk.getMaxSection() - 1) {
                        continue;
                    }
                    LevelChunkSection section = rayChunk.getSections()[sectionY - rayChunk.getMinSection()];
                    if (section == null || section.hasOnlyAir()) {
                        // Sections aren't null anymore.
                        continue;
                    }
                    BlockState blockState;
                    // section.getStates().acquire();
                    try {
                        blockState = section.getBlockState(rayBlock.getX() & 15, rayBlock.getY() & 15, rayBlock.getZ() & 15);
                    } catch (MissingPaletteEntryException e) {
                        blockState = Blocks.AIR.defaultBlockState();
                    }
                    if (solidGlobal[ChunkPacketBlockControllerAntiXray.GLOBAL_BLOCKSTATE_PALETTE.idFor(blockState)] && checkSurroundingBlocks(block.getX(), block.getY(), block.getZ(), rayBlock.getX(), rayBlock.getY(), rayBlock.getZ(), difference, section, chunkPos.x, sectionY, chunkPos.z, playerData, solidGlobal)) {
                        update = false;
                        break;
                    }
                }
                if (update) {
                    playerData.getResult().add(block);
                    iterator.remove();
                }
            }
        }
    }
}
Also used : BlockIterator(com.vanillage.raytraceantixray.util.BlockIterator) ChunkPacketBlockController(com.destroystokyo.paper.antixray.ChunkPacketBlockController) ChunkBlocks(com.vanillage.raytraceantixray.data.ChunkBlocks) ChunkPacketBlockControllerAntiXray(com.vanillage.raytraceantixray.antixray.ChunkPacketBlockControllerAntiXray) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) BlockState(net.minecraft.world.level.block.state.BlockState) LevelChunkSection(net.minecraft.world.level.chunk.LevelChunkSection) MissingPaletteEntryException(net.minecraft.world.level.chunk.MissingPaletteEntryException) ChunkPos(net.minecraft.world.level.ChunkPos) BlockPos(net.minecraft.core.BlockPos) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 2 with ChunkPacketBlockController

use of com.destroystokyo.paper.antixray.ChunkPacketBlockController in project RayTraceAntiXray by stonar96.

the class UpdateBukkitRunnable method run.

@Override
public void run() {
    for (Entry<UUID, PlayerData> entry : plugin.getPlayerData().entrySet()) {
        PlayerData playerData = entry.getValue();
        Level level = ((CraftWorld) playerData.getLocations().get(0).getWorld()).getHandle();
        ChunkPacketBlockController chunkPacketBlockController = level.chunkPacketBlockController;
        if (chunkPacketBlockController instanceof ChunkPacketBlockControllerAntiXray) {
            Queue<BlockPos> result = playerData.getResult();
            for (BlockPos block = result.poll(); block != null; block = result.poll()) {
                ((ChunkPacketBlockControllerAntiXray) chunkPacketBlockController).updateBlock(level, block);
            }
        }
    }
}
Also used : ChunkPacketBlockController(com.destroystokyo.paper.antixray.ChunkPacketBlockController) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) UUID(java.util.UUID) ChunkPacketBlockControllerAntiXray(com.vanillage.raytraceantixray.antixray.ChunkPacketBlockControllerAntiXray) PlayerData(com.vanillage.raytraceantixray.data.PlayerData) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld)

Aggregations

ChunkPacketBlockController (com.destroystokyo.paper.antixray.ChunkPacketBlockController)2 ChunkPacketBlockControllerAntiXray (com.vanillage.raytraceantixray.antixray.ChunkPacketBlockControllerAntiXray)2 BlockPos (net.minecraft.core.BlockPos)2 ChunkBlocks (com.vanillage.raytraceantixray.data.ChunkBlocks)1 PlayerData (com.vanillage.raytraceantixray.data.PlayerData)1 BlockIterator (com.vanillage.raytraceantixray.util.BlockIterator)1 UUID (java.util.UUID)1 ChunkPos (net.minecraft.world.level.ChunkPos)1 Level (net.minecraft.world.level.Level)1 BlockState (net.minecraft.world.level.block.state.BlockState)1 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)1 LevelChunkSection (net.minecraft.world.level.chunk.LevelChunkSection)1 MissingPaletteEntryException (net.minecraft.world.level.chunk.MissingPaletteEntryException)1 Location (org.bukkit.Location)1 CraftWorld (org.bukkit.craftbukkit.v1_18_R2.CraftWorld)1 Vector (org.bukkit.util.Vector)1