From 7238761ce1dfc5be23a0ab44e19e035b425df7ae Mon Sep 17 00:00:00 2001 From: shsa Date: Sat, 31 Jan 2015 17:03:29 +0700 Subject: [PATCH] added updateRadius --- java/Orebfuscator/Options.java | 63 +++++++++++++-------- java/Orebfuscator/Orebfuscator.java | 2 +- java/Orebfuscator/PlayerHandler.java | 83 ++++++++++------------------ 3 files changed, 71 insertions(+), 77 deletions(-) diff --git a/java/Orebfuscator/Options.java b/java/Orebfuscator/Options.java index 255b632..844604b 100644 --- a/java/Orebfuscator/Options.java +++ b/java/Orebfuscator/Options.java @@ -1,6 +1,7 @@ package Orebfuscator; import java.io.File; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -23,17 +24,11 @@ public class Options public WorldOptions(World world) { this.worldObj = world; - this.name = world.getProviderName(); + this.name = getWorldName(world); } 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; @@ -61,7 +56,7 @@ public class Options public void load(final Configuration config, final String[] blockList) { - this.maxObfuscateHeight = clamp(config.get(name, "maxObfuscateHeight", this.maxObfuscateHeight).getInt(), 0, 256); + this.maxObfuscateHeight = config.getInt("maxObfuscateHeight", name, this.maxObfuscateHeight, 0, 256, "Max obfuscate height"); String[] list = config.getStringList("randomBlocks", this.name, blockList, "[blockID]:[interval]"); int count = validateBlockList(list); @@ -75,7 +70,7 @@ public class Options list = blockList; count = list.length; } - + rndBlocks = new int[count]; rndBlocksInterval = new int[count]; rndBlocksCount = new int[count]; @@ -120,10 +115,15 @@ public class Options } } + public static String getWorldName(World world) + { + return world.provider.getClass().getSimpleName(); + } + private static HashMap worlds = new HashMap(); public static WorldOptions getWorldOptions(World world) { - String name = world.getProviderName(); + String name = getWorldName(world); WorldOptions options = worlds.get(name); if (options == null) { @@ -189,10 +189,17 @@ public class Options private static boolean[] obfuscateBlocks = new boolean[4096]; - public static int[] randomBlocks; - public static boolean[] transparentBlocks = new boolean[4096]; + public static class Offset + { + public int x; + public int y; + public int z; + } + + public static ArrayList updateOffsets = new ArrayList(); + public static File configFile; public static void load(File modDir) @@ -200,6 +207,28 @@ public class Options configFile = new File(modDir, Orebfuscator.MODID + ".cfg"); Configuration config = new Configuration(configFile, false); + int updateRadius = config.getInt("updateRadius", "Options", 2, 1, 5, "How much blocks update after block break"); + for (int x = -updateRadius; x <= updateRadius; x++) + { + for (int y = -updateRadius; y <= updateRadius; y++) + { + for (int z = -updateRadius; z <= updateRadius; z++) + { + if (x == 0 && y == 0 && z == 0) + continue; + + if ((x*x + y*y + z*z) <= updateRadius*2) + { + Offset offset = new Offset(); + offset.x = x; + offset.y = y; + offset.z = z; + updateOffsets.add(offset); + } + } + } + } + int[] list = config.get("Options", "obfuscateBlocks", new int[] { getID(Blocks.stone), getID(Blocks.dirt), @@ -258,16 +287,6 @@ public class Options return String.format("%d:%d", Block.getIdFromBlock(block), interval); } - private static int clamp(int value, int min, int max) { - if (value < min) { - value = min; - } - if (value > max) { - value = max; - } - return value; - } - public static boolean isObfuscated(int id) { return obfuscateBlocks[id]; } diff --git a/java/Orebfuscator/Orebfuscator.java b/java/Orebfuscator/Orebfuscator.java index 1ee3ca8..41fbe2f 100644 --- a/java/Orebfuscator/Orebfuscator.java +++ b/java/Orebfuscator/Orebfuscator.java @@ -23,7 +23,7 @@ import cpw.mods.fml.relauncher.ReflectionHelper; public class Orebfuscator { public static final String MODID = "Orebfuscator"; - public static final String VERSION = "0.2"; + public static final String VERSION = "0.3"; @EventHandler public void init(FMLInitializationEvent event) diff --git a/java/Orebfuscator/PlayerHandler.java b/java/Orebfuscator/PlayerHandler.java index 2a4c84e..e54c284 100644 --- a/java/Orebfuscator/PlayerHandler.java +++ b/java/Orebfuscator/PlayerHandler.java @@ -24,62 +24,39 @@ public class PlayerHandler public static class BlockBreakInfo { - public boolean[][][] isTransparent = new boolean[5][5][5]; - public int x; public int y; public int z; - public void updateBlocksTransparent(World world, int x, int y, int z) + public void update(final int x, final int y, final int z) { this.x = x; this.y = y; this.z = z; - - for (short i = -1; i < 2; i++) - { - for (short j = -1; j < 2; j++) - { - for (short k = -1; k < 2; k++) - { - this.isTransparent[2 + i][2 + j][2 + k] = Options.isBlockTransparent(BlockHelper.getBlockID(world, x + i, y + j, z + k)); - } - } - } - this.isTransparent[0][2][2] = Options.isBlockTransparent(BlockHelper.getBlockID(world, x - 2, y, z)); - this.isTransparent[4][2][2] = Options.isBlockTransparent(BlockHelper.getBlockID(world, x + 2, y, z)); - - this.isTransparent[2][0][2] = Options.isBlockTransparent(BlockHelper.getBlockID(world, x, y - 2, z)); - this.isTransparent[2][4][2] = Options.isBlockTransparent(BlockHelper.getBlockID(world, x, y + 2, z)); - - this.isTransparent[2][2][0] = Options.isBlockTransparent(BlockHelper.getBlockID(world, x, y, z - 2)); - this.isTransparent[2][2][4] = Options.isBlockTransparent(BlockHelper.getBlockID(world, x, y, z + 2)); - - this.isTransparent[2][2][2] = false; - } - - public boolean isTransparent(final World world, final int x, final int y, final int z) - { - return this.isTransparent[2 + x - this.x][2 + y - this.y][2 + z - this.z]; - } - - public void updateBlock(WorldOptions options, int x, int y, int z) - { - if (isTransparent(options.worldObj, x, y, z)) - return; - - if (options.isRandomBlock(BlockHelper.getBlockID(options.worldObj, x, y, z))) - { - 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; - - options.worldObj.markBlockForUpdate(x, y, z); - } } } + public boolean isTransparent(final World world, final int x, final int y, final int z) + { + return Options.isBlockTransparent(BlockHelper.getBlockID(world, x, y, z)); + } + + public void updateBlock(final World world, final int x, final int y, final int z) + { + if (isTransparent(world, x, y, z)) + return; + + if (Options.isObfuscated(BlockHelper.getBlockID(world, 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)) + return; + + world.markBlockForUpdate(x, y, z); + } + } + public void update(EntityPlayer player, int x, int y, int z) { BlockBreakInfo info = list.get(player); @@ -91,15 +68,13 @@ 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(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); + info.update(x, y, z); + + for (int i = 0; i < Options.updateOffsets.size(); i++) + { + Options.Offset offset = Options.updateOffsets.get(i); + updateBlock(player.worldObj, x + offset.x, y + offset.y, z + offset.z); + } } }