update blocks on damage
This commit is contained in:
parent
a86a5d2cf3
commit
999f0e6bb5
6
java/Orebfuscator/BlockUpdate.java
Normal file
6
java/Orebfuscator/BlockUpdate.java
Normal file
|
@ -0,0 +1,6 @@
|
|||
package Orebfuscator;
|
||||
|
||||
public class BlockUpdate
|
||||
{
|
||||
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package Orebfuscator;
|
||||
|
||||
import Orebfuscator.Options.WorldOptions;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.network.play.server.S26PacketMapChunkBulk;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -100,6 +101,7 @@ public class ChunkInfo
|
|||
}
|
||||
}
|
||||
|
||||
Options.worldOptions = Options.getWorldOptions(world.provider);
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
if (offsetsLSB[i] > -1)
|
||||
|
@ -113,7 +115,7 @@ public class ChunkInfo
|
|||
{
|
||||
if (neetObfuscate(world, x, l | y, z))
|
||||
{
|
||||
setBlockID(x, l | y, z, Options.getRandomBlock());
|
||||
setBlockID(x, l | y, z, Options.worldOptions.getRandomBlock());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -180,12 +182,12 @@ public class ChunkInfo
|
|||
|
||||
if (x < 0 || x > 15 || z < 0 || z > 15)
|
||||
{
|
||||
if (Options.engineMode == 2)
|
||||
//if (Options.engineMode == 2)
|
||||
{
|
||||
Block block = world.getBlock(this.startX | x, y, this.startY | z);
|
||||
return Options.isBlockTransparent(Block.getIdFromBlock(block));
|
||||
}
|
||||
return true;
|
||||
//return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -194,10 +196,10 @@ public class ChunkInfo
|
|||
|
||||
public boolean neetObfuscate(World world, int x, int y, int z)
|
||||
{
|
||||
if (y > Options.maxObfuscateHeight)
|
||||
if (y > Options.worldOptions.maxObfuscateHeight)
|
||||
return false;
|
||||
|
||||
if (isTransparent(world, x, y, z))
|
||||
if (!Options.isObfuscated(getBlockID(world, x, y, z)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -1,18 +1,128 @@
|
|||
package Orebfuscator;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.world.WorldProvider;
|
||||
import net.minecraft.world.WorldProviderEnd;
|
||||
import net.minecraft.world.WorldProviderHell;
|
||||
import net.minecraft.world.WorldProviderSurface;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
|
||||
public class Options
|
||||
{
|
||||
public static int engineMode = 2;
|
||||
public static class WorldOptions
|
||||
{
|
||||
public static int maxObfuscateHeight = 128;
|
||||
|
||||
public int[] randomBlocks;
|
||||
|
||||
private int randomBlock = 0;
|
||||
public int getRandomBlock()
|
||||
{
|
||||
randomBlock++;
|
||||
if (randomBlock >= randomBlocks.length)
|
||||
randomBlock = 0;
|
||||
|
||||
return randomBlocks[randomBlock];
|
||||
}
|
||||
}
|
||||
|
||||
private static HashMap<String, WorldOptions> worlds = new HashMap<String, WorldOptions>();
|
||||
public static WorldOptions getWorldOptions(WorldProvider provider)
|
||||
{
|
||||
String name = provider.getClass().getSimpleName();
|
||||
WorldOptions options = worlds.get(name);
|
||||
if (options == null)
|
||||
{
|
||||
Configuration config = new Configuration(configFile, false);
|
||||
|
||||
options = new WorldOptions();
|
||||
|
||||
options.maxObfuscateHeight = clamp(config.get(name, "maxObfuscateHeight", options.maxObfuscateHeight).getInt(), 0, 256);
|
||||
|
||||
if (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.end_portal_frame),
|
||||
getID(Blocks.end_portal),
|
||||
getID(Blocks.mob_spawner),
|
||||
getID(Blocks.mossy_cobblestone),
|
||||
}).getIntList();
|
||||
if (options.randomBlocks.length == 0)
|
||||
options.randomBlocks = new int[] {getID(Blocks.stone)};
|
||||
}
|
||||
if (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),
|
||||
getID(Blocks.mob_spawner),
|
||||
}).getIntList();
|
||||
if (options.randomBlocks.length == 0)
|
||||
options.randomBlocks = new int[] {getID(Blocks.nether_brick)};
|
||||
}
|
||||
else
|
||||
if (provider instanceof WorldProviderEnd)
|
||||
{
|
||||
options.randomBlocks = config.get(name, "randomBlocks", new int[] {
|
||||
getID(Blocks.end_portal_frame),
|
||||
getID(Blocks.end_portal),
|
||||
getID(Blocks.end_stone),
|
||||
}).getIntList();
|
||||
if (options.randomBlocks.length == 0)
|
||||
options.randomBlocks = new int[] {getID(Blocks.end_stone)};
|
||||
}
|
||||
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)};
|
||||
}
|
||||
if (options.randomBlocks.length == 0)
|
||||
options.randomBlocks = new int[] {getID(Blocks.stone)};
|
||||
|
||||
config.save();
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
public static int maxObfuscateHeight = 128;
|
||||
public static WorldOptions worldOptions;
|
||||
|
||||
public static int engineMode = 2;
|
||||
|
||||
private static boolean[] obfuscateBlocks = new boolean[4096];
|
||||
|
||||
|
@ -20,17 +130,17 @@ public class Options
|
|||
|
||||
public static boolean[] transparentBlocks = new boolean[4096];
|
||||
|
||||
public static File configFile;
|
||||
|
||||
public static void load(File modDir)
|
||||
{
|
||||
File configFile = new File(modDir, Orebfuscator.MODID + ".cfg");
|
||||
configFile = new File(modDir, Orebfuscator.MODID + ".cfg");
|
||||
Configuration config = new Configuration(configFile, false);
|
||||
|
||||
engineMode = clamp(config.get("Options", "engineMode", engineMode).getInt(), 1, 2);
|
||||
//engineMode = clamp(config.get("Options", "engineMode", engineMode).getInt(), 1, 2);
|
||||
|
||||
BlockChange.updateRadius = clamp(config.get("Options", "updateRadius", BlockChange.updateRadius).getInt(), 1, 5);
|
||||
//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),
|
||||
|
@ -60,24 +170,6 @@ public class Options
|
|||
}
|
||||
|
||||
|
||||
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);
|
||||
|
||||
|
@ -116,6 +208,10 @@ public class Options
|
|||
return obfuscateBlocks[id];
|
||||
}
|
||||
|
||||
public static boolean isObfuscated(Block block) {
|
||||
return obfuscateBlocks[Block.getIdFromBlock(block)];
|
||||
}
|
||||
|
||||
private static boolean[] _transparentBlocks = new boolean[4096];
|
||||
private static boolean TransparentCached = false;
|
||||
public static boolean isBlockTransparent(int id)
|
||||
|
@ -147,14 +243,4 @@ public class Options
|
|||
}
|
||||
return _transparentBlocks[id];
|
||||
}
|
||||
|
||||
private static int randomBlock = 0;
|
||||
public static int getRandomBlock()
|
||||
{
|
||||
randomBlock++;
|
||||
if (randomBlock >= randomBlocks.length)
|
||||
randomBlock = 0;
|
||||
|
||||
return randomBlocks[randomBlock];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.util.HashSet;
|
|||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.NetHandlerPlayServer;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
|
@ -33,6 +34,7 @@ public class Orebfuscator
|
|||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
FMLCommonHandler.instance().bus().register(this);
|
||||
MinecraftForge.EVENT_BUS.register(new PlayerHandler());
|
||||
|
||||
Options.load(event.getModConfigurationDirectory());
|
||||
}
|
||||
|
|
67
java/Orebfuscator/PlayerHandler.java
Normal file
67
java/Orebfuscator/PlayerHandler.java
Normal file
|
@ -0,0 +1,67 @@
|
|||
package Orebfuscator;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
public class PlayerHandler
|
||||
{
|
||||
public Map<EntityPlayer, BlockBreakInfo> list = new HashMap<EntityPlayer, BlockBreakInfo>();
|
||||
|
||||
public static class BlockBreakInfo
|
||||
{
|
||||
public int x;
|
||||
public int y;
|
||||
public int z;
|
||||
}
|
||||
|
||||
public void updateBlock(World world, int x, int y, int z)
|
||||
{
|
||||
if (Options.isObfuscated(world.getBlock(x, y, z)))
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
}
|
||||
|
||||
public void update(EntityPlayer player, int x, int y, int z)
|
||||
{
|
||||
BlockBreakInfo info = list.get(player);
|
||||
if (info == null)
|
||||
{
|
||||
info = new BlockBreakInfo();
|
||||
list.put(player, info);
|
||||
}
|
||||
|
||||
if (info.x != x || info.y != y || info.z != z)
|
||||
{
|
||||
info.x = x;
|
||||
info.y = y;
|
||||
info.z = z;
|
||||
|
||||
updateBlock(player.worldObj, x-1, y, z);
|
||||
updateBlock(player.worldObj, x+1, y, z);
|
||||
updateBlock(player.worldObj, x, y-1, z);
|
||||
updateBlock(player.worldObj, x, y+1, z);
|
||||
updateBlock(player.worldObj, x, y, z-1);
|
||||
updateBlock(player.worldObj, x, y, z+1);
|
||||
}
|
||||
//Log.msg("updated: %d, %d, %d", x, y, z);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onBreakSpeed(PlayerEvent.BreakSpeed event)
|
||||
{
|
||||
update(event.entityPlayer, event.x, event.y, event.z);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onBlockBreak(BlockEvent.BreakEvent event)
|
||||
{
|
||||
update(event.getPlayer(), event.x, event.y, event.z);
|
||||
}
|
||||
|
||||
}
|
|
@ -36,15 +36,17 @@ public class ProxyChannel implements Channel
|
|||
MapChunkBulk.parse(player.worldObj, packet);
|
||||
return;
|
||||
}
|
||||
/*
|
||||
if (msg instanceof S23PacketBlockChange)
|
||||
{
|
||||
S23PacketBlockChange packet = (S23PacketBlockChange)msg;
|
||||
BlockChange.parse(player.worldObj, channel, packet);
|
||||
return;
|
||||
}
|
||||
|
||||
//world.scheduleBlockUpdate(x, y, z, this, tickRate);
|
||||
//Log.msg("%s", msg.getClass().getName());
|
||||
*/
|
||||
//String className = msg.getClass().getSimpleName();
|
||||
//if (className.indexOf("Entity") == -1)
|
||||
//Log.msg("%s", msg.getClass().getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue