
org.spigotmc.AntiXray Maven / Gradle / Ivy
package org.spigotmc;
import gnu.trove.set.TByteSet;
import gnu.trove.set.hash.TByteHashSet;
import net.minecraft.server.Block;
import net.minecraft.server.BlockPosition;
import net.minecraft.server.Blocks;
import net.minecraft.server.World;
public class AntiXray {
private static final CustomTimingsHandler update = new CustomTimingsHandler("xray - update");
private static final CustomTimingsHandler obfuscate = new CustomTimingsHandler("xray - obfuscate");
/*========================================================================*/
// Used to keep track of which blocks to obfuscate
private final boolean[] obfuscateBlocks = new boolean[Short.MAX_VALUE];
// Used to select a random replacement ore
private final byte[] replacementOres;
public AntiXray(SpigotWorldConfig config) {
// Set all listed blocks as true to be obfuscated
for (int id : (config.engineMode == 1) ? config.hiddenBlocks : config.replaceBlocks) {
obfuscateBlocks[id] = true;
}
// For every block
TByteSet blocks = new TByteHashSet();
for (Integer i : config.hiddenBlocks) {
Block block = Block.getById(i);
// Check it exists and is not a tile entity
if (block != null && !block.isTileEntity()) {
// Add it to the set of replacement blocks
blocks.add((byte) (int) i);
}
}
// Bake it to a flat array of replacements
replacementOres = blocks.toArray();
}
private static boolean isLoaded(World world, BlockPosition position, int radius) {
return world.isLoaded(position)
&& (radius == 0 ||
(isLoaded(world, position.east(), radius - 1)
&& isLoaded(world, position.west(), radius - 1)
&& isLoaded(world, position.up(), radius - 1)
&& isLoaded(world, position.down(), radius - 1)
&& isLoaded(world, position.south(), radius - 1)
&& isLoaded(world, position.north(), radius - 1)));
}
private static boolean hasTransparentBlockAdjacent(World world, BlockPosition position, int radius) {
return !isSolidBlock(world.getType(position, false).getBlock()) /* isSolidBlock */
|| (radius > 0
&& (hasTransparentBlockAdjacent(world, position.east(), radius - 1)
|| hasTransparentBlockAdjacent(world, position.west(), radius - 1)
|| hasTransparentBlockAdjacent(world, position.up(), radius - 1)
|| hasTransparentBlockAdjacent(world, position.down(), radius - 1)
|| hasTransparentBlockAdjacent(world, position.south(), radius - 1)
|| hasTransparentBlockAdjacent(world, position.north(), radius - 1)));
}
private static boolean isSolidBlock(Block block) {
// Mob spawners are treated as solid blocks as far as the
// game is concerned for lighting and other tasks but for
// rendering they can be seen through therefor we special
// case them so that the antixray doesn't show the fake
// blocks around them.
return block.isOccluding() && block != Blocks.MOB_SPAWNER && block != Blocks.BARRIER;
}
/**
* Starts the timings handler, then updates all blocks within the set radius
* of the given coordinate, revealing them if they are hidden ores.
*/
public void updateNearbyBlocks(World world, BlockPosition position) {
}
/**
* Starts the timings handler, and then removes all non exposed ores from
* the chunk buffer.
*/
public void obfuscateSync(int chunkX, int chunkY, int bitmask, byte[] buffer, World world) {
}
/**
* Removes all non exposed ores from the chunk buffer.
*/
public void obfuscate(int chunkX, int chunkY, int bitmask, byte[] buffer, World world) {
}
private void updateNearbyBlocks(World world, BlockPosition position, int radius, boolean updateSelf) {
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy