diff --git a/java/Orebfuscator/ChunkObfuscator.java b/java/Orebfuscator/ChunkObfuscator.java index 52140ed..59ada98 100644 --- a/java/Orebfuscator/ChunkObfuscator.java +++ b/java/Orebfuscator/ChunkObfuscator.java @@ -1,6 +1,7 @@ package Orebfuscator; import Orebfuscator.Options.WorldOptions; +import net.minecraft.block.Block; import net.minecraft.network.play.server.S26PacketMapChunkBulk; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; @@ -27,7 +28,7 @@ public class ChunkObfuscator public int[] offsetsMSB = new int[16]; public int startX; - public int startY; + public int startZ; // Максимальный индекс+1 секции public int len; @@ -36,7 +37,7 @@ public class ChunkObfuscator public void obfuscate(World world, int chunkX, int chunkZ, int sectionLSB, int sectionMSB, byte[] data) { this.startX = chunkX << 4; - this.startY = chunkZ << 4; + this.startZ = chunkZ << 4; this.data = data; int countLSB = 0; @@ -100,7 +101,7 @@ public class ChunkObfuscator } } - Options.worldOptions = Options.getWorldOptions(world.provider); + Options.worldOptions = Options.getWorldOptions(world); for (i = 0; i < len; i++) { if (offsetsLSB[i] > -1) @@ -114,7 +115,7 @@ public class ChunkObfuscator { if (neetObfuscate(world, x, l | y, z)) { - setBlockID(x, l | y, z, Options.worldOptions.getRandomBlock()); + setBlockID(x, l | y, z, Options.worldOptions.getRandomID()); } } } @@ -181,7 +182,7 @@ public class ChunkObfuscator if (x < 0 || x > 15 || z < 0 || z > 15) { - return Options.isBlockTransparent(BlockHelper.getBlockID(world, this.startX | x, y, this.startY | z)); + return Options.isBlockTransparent(BlockHelper.getBlockID(world, this.startX + x, y, this.startZ + z)); } return Options.isBlockTransparent(getBlockID(world, x, y, z)); diff --git a/java/Orebfuscator/Options.java b/java/Orebfuscator/Options.java index b91a435..255b632 100644 --- a/java/Orebfuscator/Options.java +++ b/java/Orebfuscator/Options.java @@ -7,6 +7,7 @@ import java.util.HashSet; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.init.Blocks; +import net.minecraft.world.World; import net.minecraft.world.WorldProvider; import net.minecraft.world.WorldProviderEnd; import net.minecraft.world.WorldProviderHell; @@ -17,96 +18,166 @@ public class Options { public static class WorldOptions { - public static int maxObfuscateHeight = 128; - - public int[] randomBlocks; - - private int randomBlock = 0; - public int getRandomBlock() + public World worldObj; + public String name; + public WorldOptions(World world) { - randomBlock++; - if (randomBlock >= randomBlocks.length) - randomBlock = 0; + this.worldObj = world; + this.name = world.getProviderName(); + } + + public int maxObfuscateHeight = 128; + + private boolean[] isRandomBlock = new boolean[4096]; + public boolean isRandomBlock(int blockID) + { + return this.isRandomBlock[blockID]; + } + + private int[] rndBlocks; + private int[] rndBlocksInterval; + private int[] rndBlocksCount; + + private int rndBlockIndex = 0; + public int getRandomID() + { + while (true) + { + rndBlockIndex++; + if (rndBlockIndex >= rndBlocks.length) + rndBlockIndex = 0; + + if (rndBlocksCount[rndBlockIndex] >= rndBlocksInterval[rndBlockIndex]) + { + rndBlocksCount[rndBlockIndex] = 1; + return rndBlocks[rndBlockIndex]; + } + else + { + rndBlocksCount[rndBlockIndex]++; + } + } + } + + public void load(final Configuration config, final String[] blockList) + { + this.maxObfuscateHeight = clamp(config.get(name, "maxObfuscateHeight", this.maxObfuscateHeight).getInt(), 0, 256); + + String[] list = config.getStringList("randomBlocks", this.name, blockList, "[blockID]:[interval]"); + int count = validateBlockList(list); + if (count == 0) + { + if (list.length == 0) + Log.error("%s.randomBlocks.length == 0", this.name); + else + Log.error("%s.randomBlocks has errors", this.name); + + list = blockList; + count = list.length; + } - return randomBlocks[randomBlock]; + rndBlocks = new int[count]; + rndBlocksInterval = new int[count]; + rndBlocksCount = new int[count]; + int i = 0; + for (String value : list) + { + String[] values = value.split(":"); + try + { + int v0 = Integer.valueOf(values[0]); + int v1 = Integer.valueOf(values[1]); + if (v0 >= 0 && v0 < 4096 && v1 > 0) + { + rndBlocks[i] = v0; + rndBlocksCount[i] = 1; + rndBlocksInterval[i] = v1; + i++; + } + } + catch (Exception e) { } + } + } + + private int validateBlockList(String[] list) + { + int count = 0; + for (int i = 0; i < list.length; i++) + { + String[] values = list[i].split(":"); + try + { + int v0 = Integer.valueOf(values[0]); + int v1 = Integer.valueOf(values[1]); + if (v0 >= 0 && v0 < 4096 && v1 > 0) + count++; + } + catch(Exception e) + { + } + } + return count; } } private static HashMap worlds = new HashMap(); - public static WorldOptions getWorldOptions(WorldProvider provider) + public static WorldOptions getWorldOptions(World world) { - String name = provider.getClass().getSimpleName(); + String name = world.getProviderName(); WorldOptions options = worlds.get(name); if (options == null) { Configuration config = new Configuration(configFile, false); - options = new WorldOptions(); + options = new WorldOptions(world); - options.maxObfuscateHeight = clamp(config.get(name, "maxObfuscateHeight", options.maxObfuscateHeight).getInt(), 0, 256); - - if (provider instanceof WorldProviderSurface) + if (world.provider instanceof WorldProviderSurface) { - options.randomBlocks = config.get(name, "randomBlocks", new int[] { - getID(Blocks.gold_ore), - getID(Blocks.iron_ore), - getID(Blocks.coal_ore), - getID(Blocks.lapis_ore), - getID(Blocks.diamond_ore), - getID(Blocks.redstone_ore), - getID(Blocks.emerald_ore), - getID(Blocks.mossy_cobblestone), - }).getIntList(); - if (options.randomBlocks.length == 0) - options.randomBlocks = new int[] {getID(Blocks.stone)}; + options.load(config, new String[] { + getID(Blocks.gold_ore, 1), + getID(Blocks.iron_ore, 1), + getID(Blocks.coal_ore, 1), + getID(Blocks.lapis_ore, 1), + getID(Blocks.diamond_ore, 1), + getID(Blocks.redstone_ore, 1), + getID(Blocks.emerald_ore, 1), + getID(Blocks.mossy_cobblestone, 1), + getID(Blocks.mob_spawner, 100), + }); } - if (provider instanceof WorldProviderHell) + if (world.provider instanceof WorldProviderHell) { - options.randomBlocks = config.get(name, "randomBlocks", new int[] { - getID(Blocks.glowstone), - getID(Blocks.netherrack), - getID(Blocks.nether_brick), - getID(Blocks.nether_brick_fence), - getID(Blocks.nether_brick_stairs), - getID(Blocks.nether_wart), - getID(Blocks.quartz_ore), - }).getIntList(); - if (options.randomBlocks.length == 0) - options.randomBlocks = new int[] {getID(Blocks.nether_brick)}; + options.load(config, new String[] { + getID(Blocks.glowstone, 1), + getID(Blocks.netherrack, 1), + getID(Blocks.nether_brick, 1), + getID(Blocks.nether_brick_fence, 1), + getID(Blocks.nether_brick_stairs, 1), + getID(Blocks.nether_wart, 1), + getID(Blocks.quartz_ore, 1), + }); } else - if (provider instanceof WorldProviderEnd) + if (world.provider instanceof WorldProviderEnd) { - options.randomBlocks = config.get(name, "randomBlocks", new int[] { - getID(Blocks.end_stone), - }).getIntList(); - if (options.randomBlocks.length == 0) - options.randomBlocks = new int[] {getID(Blocks.end_stone)}; + options.load(config, new String[] { + getID(Blocks.end_stone, 1), + }); } else { - options.randomBlocks = config.get(name, "randomBlocks", new int[] { - getID(Blocks.stone), - getID(Blocks.gold_ore), - getID(Blocks.iron_ore), - getID(Blocks.coal_ore), - getID(Blocks.lapis_ore), - getID(Blocks.diamond_ore), - getID(Blocks.redstone_ore), - getID(Blocks.emerald_ore), - getID(Blocks.netherrack), - getID(Blocks.nether_brick), - getID(Blocks.quartz_ore), - getID(Blocks.end_portal_frame), - getID(Blocks.end_portal), - getID(Blocks.end_stone), - getID(Blocks.mob_spawner), - }).getIntList(); - if (options.randomBlocks.length == 0) - options.randomBlocks = new int[] {getID(Blocks.stone)}; + options.load(config, new String[] { + getID(Blocks.gold_ore, 1), + getID(Blocks.iron_ore, 1), + getID(Blocks.coal_ore, 1), + getID(Blocks.lapis_ore, 1), + getID(Blocks.diamond_ore, 1), + getID(Blocks.redstone_ore, 1), + getID(Blocks.emerald_ore, 1), + getID(Blocks.mossy_cobblestone, 1), + getID(Blocks.mob_spawner, 1000), + }); } - if (options.randomBlocks.length == 0) - options.randomBlocks = new int[] {getID(Blocks.stone)}; config.save(); } @@ -182,6 +253,11 @@ public class Options return Block.getIdFromBlock(block); } + private static String getID(Block block, int interval) + { + return String.format("%d:%d", Block.getIdFromBlock(block), interval); + } + private static int clamp(int value, int min, int max) { if (value < min) { value = min; diff --git a/java/Orebfuscator/PlayerHandler.java b/java/Orebfuscator/PlayerHandler.java index f9a5254..2a4c84e 100644 --- a/java/Orebfuscator/PlayerHandler.java +++ b/java/Orebfuscator/PlayerHandler.java @@ -4,6 +4,7 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.Callable; +import Orebfuscator.Options.WorldOptions; import net.minecraft.block.Block; import net.minecraft.crash.CrashReport; import net.minecraft.crash.CrashReportCategory; @@ -62,16 +63,19 @@ public class PlayerHandler return this.isTransparent[2 + x - this.x][2 + y - this.y][2 + z - this.z]; } - public void updateBlock(World world, int x, int y, int z) + public void updateBlock(WorldOptions options, int x, int y, int z) { - if (Options.isObfuscated(BlockHelper.getBlockID(world, x, y, z))) + if (isTransparent(options.worldObj, x, y, z)) + return; + + if (options.isRandomBlock(BlockHelper.getBlockID(options.worldObj, x, y, z))) { - if (isTransparent(world, x - 1, y, z) || isTransparent(world, x + 1, y, z) || - isTransparent(world, x, y - 1, z) || isTransparent(world, x, y + 1, z) || - isTransparent(world, x, y, z - 1) || isTransparent(world, x, y, z + 1)) + if (isTransparent(options.worldObj, x - 1, y, z) || isTransparent(options.worldObj, x + 1, y, z) || + isTransparent(options.worldObj, x, y - 1, z) || isTransparent(options.worldObj, x, y + 1, z) || + isTransparent(options.worldObj, x, y, z - 1) || isTransparent(options.worldObj, x, y, z + 1)) return; - world.markBlockForUpdate(x, y, z); + options.worldObj.markBlockForUpdate(x, y, z); } } } @@ -87,14 +91,15 @@ public class PlayerHandler if (info.x != x || info.y != y || info.z != z) { + WorldOptions options = Options.getWorldOptions(player.worldObj); info.updateBlocksTransparent(player.worldObj, x, y, z); - info.updateBlock(player.worldObj, x-1, y, z); - info.updateBlock(player.worldObj, x+1, y, z); - info.updateBlock(player.worldObj, x, y-1, z); - info.updateBlock(player.worldObj, x, y+1, z); - info.updateBlock(player.worldObj, x, y, z-1); - info.updateBlock(player.worldObj, x, y, z+1); + info.updateBlock(options, x-1, y, z); + info.updateBlock(options, x+1, y, z); + info.updateBlock(options, x, y-1, z); + info.updateBlock(options, x, y+1, z); + info.updateBlock(options, x, y, z-1); + info.updateBlock(options, x, y, z+1); } }