alpha version
This commit is contained in:
parent
c307ff5387
commit
a86a5d2cf3
|
@ -22,7 +22,7 @@ public class BlockChange
|
||||||
public static int baseY;
|
public static int baseY;
|
||||||
public static int baseZ;
|
public static int baseZ;
|
||||||
|
|
||||||
public static byte offset = 2;
|
public static int updateRadius = 2;
|
||||||
public static int startPos;
|
public static int startPos;
|
||||||
|
|
||||||
public static void parse(World world, Channel channel, S23PacketBlockChange packet)
|
public static void parse(World world, Channel channel, S23PacketBlockChange packet)
|
||||||
|
@ -40,18 +40,18 @@ public class BlockChange
|
||||||
|
|
||||||
// èñïîëüçóåì áàçîâóþ òî÷êó, ÷òîáû â äàëüíåéøåì âûñ÷èòûâàòü ñìåùåíèÿ îáíîâëÿåìûõ áëîêîâ
|
// èñïîëüçóåì áàçîâóþ òî÷êó, ÷òîáû â äàëüíåéøåì âûñ÷èòûâàòü ñìåùåíèÿ îáíîâëÿåìûõ áëîêîâ
|
||||||
// ñìåùåíèÿ áóäåì ñâîäèòü â îäèí int è õðàíèòü â HashSet
|
// ñìåùåíèÿ áóäåì ñâîäèòü â îäèí int è õðàíèòü â HashSet
|
||||||
baseX = x - offset;
|
baseX = x - updateRadius;
|
||||||
baseY = y - offset;
|
baseY = y - updateRadius;
|
||||||
baseZ = z - offset;
|
baseZ = z - updateRadius;
|
||||||
|
|
||||||
x = offset;
|
x = updateRadius;
|
||||||
y = offset;
|
y = updateRadius;
|
||||||
z = offset;
|
z = updateRadius;
|
||||||
|
|
||||||
startPos = (offset << 16) | (offset << 8) | offset;
|
startPos = (updateRadius << 16) | (updateRadius << 8) | updateRadius;
|
||||||
|
|
||||||
list.clear();
|
list.clear();
|
||||||
updateAjacentBlocks(world, offset, offset, offset, offset + 1);
|
updateAjacentBlocks(world, updateRadius, updateRadius, updateRadius, updateRadius + 1);
|
||||||
for (int pos : list)
|
for (int pos : list)
|
||||||
{
|
{
|
||||||
x = baseX + (pos >> 16 & 255);
|
x = baseX + (pos >> 16 & 255);
|
||||||
|
@ -69,7 +69,7 @@ public class BlockChange
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Block block = world.getBlock(baseX + x, baseY + y, baseZ + z);
|
Block block = world.getBlock(baseX + x, baseY + y, baseZ + z);
|
||||||
return Orebfuscator.isBlockTransparent(Block.getIdFromBlock(block));
|
return Options.isBlockTransparent(Block.getIdFromBlock(block));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean needUpdate(World world, int x, int y, int z)
|
public static boolean needUpdate(World world, int x, int y, int z)
|
||||||
|
|
|
@ -26,8 +26,8 @@ public class ChunkInfo
|
||||||
// NibbleArray ExtendedBlockStorage.blockMSBArray
|
// NibbleArray ExtendedBlockStorage.blockMSBArray
|
||||||
public int[] offsetsMSB = new int[16];
|
public int[] offsetsMSB = new int[16];
|
||||||
|
|
||||||
public int chunkX;
|
public int startX;
|
||||||
public int chunkZ;
|
public int startY;
|
||||||
|
|
||||||
// Ìàêñèìàëüíûé èíäåêñ+1 ñåêöèè
|
// Ìàêñèìàëüíûé èíäåêñ+1 ñåêöèè
|
||||||
public int len;
|
public int len;
|
||||||
|
@ -35,8 +35,8 @@ public class ChunkInfo
|
||||||
|
|
||||||
public void parse(World world, int chunkX, int chunkZ, int sectionLSB, int sectionMSB, byte[] data)
|
public void parse(World world, int chunkX, int chunkZ, int sectionLSB, int sectionMSB, byte[] data)
|
||||||
{
|
{
|
||||||
this.chunkX = chunkX;
|
this.startX = chunkX << 4;
|
||||||
this.chunkZ = chunkZ;
|
this.startY = chunkZ << 4;
|
||||||
|
|
||||||
this.data = data;
|
this.data = data;
|
||||||
int countLSB = 0;
|
int countLSB = 0;
|
||||||
|
@ -104,23 +104,16 @@ public class ChunkInfo
|
||||||
{
|
{
|
||||||
if (offsetsLSB[i] > -1)
|
if (offsetsLSB[i] > -1)
|
||||||
{
|
{
|
||||||
|
l = i << 4;
|
||||||
for (int x = 0; x < 16; x++)
|
for (int x = 0; x < 16; x++)
|
||||||
{
|
{
|
||||||
for (int y = 0; y < 16; y++)
|
for (int y = 0; y < 16; y++)
|
||||||
{
|
{
|
||||||
for (int z = 0; z < 16; z++)
|
for (int z = 0; z < 16; z++)
|
||||||
{
|
{
|
||||||
/*
|
if (neetObfuscate(world, x, l | y, z))
|
||||||
if ((x > 0 && x < 16) && (y == 0 || y == 15) && (z == 0 || z == 15))
|
|
||||||
setBlockID(x, y, z, 1);
|
|
||||||
if ((x == 0 || x == 15) && (y > 0 || y < 16) && (z == 0 || z == 15))
|
|
||||||
setBlockID(x, y, z, 1);
|
|
||||||
if ((x == 0 || x == 15) && (y == 0 || y == 15) && (z > 0 || z < 16))
|
|
||||||
setBlockID(x, y, z, 1);
|
|
||||||
*/
|
|
||||||
if (neetObfuscate(world, x, i << 4 | y, z))
|
|
||||||
{
|
{
|
||||||
setBlockID(x, i << 4 | y, z, 57);
|
setBlockID(x, l | y, z, Options.getRandomBlock());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,19 +180,23 @@ public class ChunkInfo
|
||||||
|
|
||||||
if (x < 0 || x > 15 || z < 0 || z > 15)
|
if (x < 0 || x > 15 || z < 0 || z > 15)
|
||||||
{
|
{
|
||||||
/*
|
if (Options.engineMode == 2)
|
||||||
Block block = world.getBlock((this.chunkX << 4) | x, y, (this.chunkZ << 4) | z);
|
{
|
||||||
return Orebfuscator.isBlockTransparent(Block.getIdFromBlock(block));
|
Block block = world.getBlock(this.startX | x, y, this.startY | z);
|
||||||
*/
|
return Options.isBlockTransparent(Block.getIdFromBlock(block));
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return Orebfuscator.isBlockTransparent(getBlockID(world, x, y, z));
|
return Options.isBlockTransparent(getBlockID(world, x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean neetObfuscate(World world, int x, int y, int z)
|
public boolean neetObfuscate(World world, int x, int y, int z)
|
||||||
{
|
{
|
||||||
|
if (y > Options.maxObfuscateHeight)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (isTransparent(world, x, y, z))
|
if (isTransparent(world, x, y, z))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|
160
java/Orebfuscator/Options.java
Normal file
160
java/Orebfuscator/Options.java
Normal file
|
@ -0,0 +1,160 @@
|
||||||
|
package Orebfuscator;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.material.Material;
|
||||||
|
import net.minecraft.init.Blocks;
|
||||||
|
import net.minecraftforge.common.config.Configuration;
|
||||||
|
|
||||||
|
public class Options
|
||||||
|
{
|
||||||
|
public static int engineMode = 2;
|
||||||
|
|
||||||
|
public static int maxObfuscateHeight = 128;
|
||||||
|
|
||||||
|
private static boolean[] obfuscateBlocks = new boolean[4096];
|
||||||
|
|
||||||
|
public static int[] randomBlocks;
|
||||||
|
|
||||||
|
public static boolean[] transparentBlocks = new boolean[4096];
|
||||||
|
|
||||||
|
public static void load(File modDir)
|
||||||
|
{
|
||||||
|
File configFile = new File(modDir, Orebfuscator.MODID + ".cfg");
|
||||||
|
Configuration config = new Configuration(configFile, false);
|
||||||
|
|
||||||
|
engineMode = clamp(config.get("Options", "engineMode", engineMode).getInt(), 1, 2);
|
||||||
|
|
||||||
|
BlockChange.updateRadius = clamp(config.get("Options", "updateRadius", BlockChange.updateRadius).getInt(), 1, 5);
|
||||||
|
|
||||||
|
maxObfuscateHeight = clamp(config.get("Options", "maxObfuscateHeight", maxObfuscateHeight).getInt(), 0, 256);
|
||||||
|
|
||||||
|
int[] list = config.get("Options", "obfuscateBlocks", new int[] {
|
||||||
|
getID(Blocks.stone),
|
||||||
|
getID(Blocks.dirt),
|
||||||
|
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_stone),
|
||||||
|
}).getIntList();
|
||||||
|
|
||||||
|
if (list.length == 0)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < obfuscateBlocks.length; i++)
|
||||||
|
{
|
||||||
|
obfuscateBlocks[i] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
updateList(obfuscateBlocks, list);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
randomBlocks = config.get("Options", "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_stone),
|
||||||
|
}).getIntList();
|
||||||
|
if (randomBlocks.length == 0)
|
||||||
|
randomBlocks = new int[] {getID(Blocks.stone)};
|
||||||
|
|
||||||
|
list = config.get("Options", "transparentBlocks", new int[] {}).getIntList();
|
||||||
|
updateList(transparentBlocks, list);
|
||||||
|
|
||||||
|
config.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void updateList(boolean[] blocks, int[] list)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < blocks.length; i++)
|
||||||
|
{
|
||||||
|
blocks[i] = false;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < list.length; i++)
|
||||||
|
{
|
||||||
|
if (list[i] >= 0 || list[i] < blocks.length)
|
||||||
|
blocks[list[i]] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getID(Block block)
|
||||||
|
{
|
||||||
|
return Block.getIdFromBlock(block);
|
||||||
|
}
|
||||||
|
|
||||||
|
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];
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean[] _transparentBlocks = new boolean[4096];
|
||||||
|
private static boolean TransparentCached = false;
|
||||||
|
public static boolean isBlockTransparent(int id)
|
||||||
|
{
|
||||||
|
if (id < 0)
|
||||||
|
return true;
|
||||||
|
if (!TransparentCached)
|
||||||
|
{
|
||||||
|
// Generate TransparentBlocks by reading them from Minecraft
|
||||||
|
for (int i = 0; i < _transparentBlocks.length; i++) {
|
||||||
|
if (transparentBlocks[i])
|
||||||
|
{
|
||||||
|
_transparentBlocks[i] = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Block block = Block.getBlockById(i);
|
||||||
|
if (block == null)
|
||||||
|
{
|
||||||
|
_transparentBlocks[i] = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_transparentBlocks[i] = !block.isNormalCube();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TransparentCached = true;
|
||||||
|
}
|
||||||
|
return _transparentBlocks[id];
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int randomBlock = 0;
|
||||||
|
public static int getRandomBlock()
|
||||||
|
{
|
||||||
|
randomBlock++;
|
||||||
|
if (randomBlock >= randomBlocks.length)
|
||||||
|
randomBlock = 0;
|
||||||
|
|
||||||
|
return randomBlocks[randomBlock];
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,10 +1,12 @@
|
||||||
package Orebfuscator;
|
package Orebfuscator;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.network.NetHandlerPlayServer;
|
import net.minecraft.network.NetHandlerPlayServer;
|
||||||
|
import net.minecraftforge.common.config.Configuration;
|
||||||
import cpw.mods.fml.common.FMLCommonHandler;
|
import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
import cpw.mods.fml.common.Mod;
|
import cpw.mods.fml.common.Mod;
|
||||||
import cpw.mods.fml.common.Mod.EventHandler;
|
import cpw.mods.fml.common.Mod.EventHandler;
|
||||||
|
@ -31,6 +33,8 @@ public class Orebfuscator
|
||||||
public void preInit(FMLPreInitializationEvent event)
|
public void preInit(FMLPreInitializationEvent event)
|
||||||
{
|
{
|
||||||
FMLCommonHandler.instance().bus().register(this);
|
FMLCommonHandler.instance().bus().register(this);
|
||||||
|
|
||||||
|
Options.load(event.getModConfigurationDirectory());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
|
@ -53,37 +57,4 @@ public class Orebfuscator
|
||||||
PlayerInjector.hookPlayer(handler.playerEntity, handler.netManager);
|
PlayerInjector.hookPlayer(handler.playerEntity, handler.netManager);
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HashSet<Integer> forcedTransparentBlocks = new HashSet<Integer>();
|
|
||||||
private static boolean[] TransparentBlocks = new boolean[4096];
|
|
||||||
private static boolean TransparentCached = false;
|
|
||||||
public static boolean isBlockTransparent(int id)
|
|
||||||
{
|
|
||||||
if (id < 0)
|
|
||||||
return true;
|
|
||||||
if (!TransparentCached)
|
|
||||||
{
|
|
||||||
// Generate TransparentBlocks by reading them from Minecraft
|
|
||||||
for (int i = 0; i < TransparentBlocks.length; i++) {
|
|
||||||
if (forcedTransparentBlocks.contains(i))
|
|
||||||
{
|
|
||||||
TransparentBlocks[i] = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Block block = Block.getBlockById(i);
|
|
||||||
if (block == null)
|
|
||||||
{
|
|
||||||
TransparentBlocks[i] = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
TransparentBlocks[i] = !block.isNormalCube();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
TransparentCached = true;
|
|
||||||
}
|
|
||||||
return TransparentBlocks[id];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,10 +36,6 @@ public class ProxyChannel implements Channel
|
||||||
MapChunkBulk.parse(player.worldObj, packet);
|
MapChunkBulk.parse(player.worldObj, packet);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (msg instanceof MyPacketBlockChange)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (msg instanceof S23PacketBlockChange)
|
if (msg instanceof S23PacketBlockChange)
|
||||||
{
|
{
|
||||||
S23PacketBlockChange packet = (S23PacketBlockChange)msg;
|
S23PacketBlockChange packet = (S23PacketBlockChange)msg;
|
||||||
|
|
Loading…
Reference in a new issue