added updateRadius

This commit is contained in:
shsa 2015-01-31 17:03:29 +07:00
parent ceb4c4aecf
commit 7238761ce1
3 changed files with 71 additions and 77 deletions

View file

@ -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<String, WorldOptions> worlds = new HashMap<String, WorldOptions>();
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<Offset> updateOffsets = new ArrayList<Offset>();
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];
}

View file

@ -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)

View file

@ -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);
}
}
}