Skip to content

Commit

Permalink
Merge pull request #83 from DevotedMC/master
Browse files Browse the repository at this point in the history
Merging up to v4.0.9
  • Loading branch information
ProgrammerDan committed May 3, 2016
2 parents 4ab5bb4 + c47b9fa commit 1e0c38f
Show file tree
Hide file tree
Showing 17 changed files with 337 additions and 223 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.lishid</groupId>
<artifactId>orebfuscator</artifactId>
<version>4.0.7-SNAPSHOT</version>
<version>4.0.9-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Orebfuscator4</name>
Expand Down
62 changes: 50 additions & 12 deletions src/main/java/com/lishid/orebfuscator/OrebfuscatorConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,11 @@ public static File getCacheFolder() {
return CacheFolder;
}

private static boolean[] TransparentBlocks = new boolean[256];
private static boolean TransparentCached = false;
private static boolean[] TransparentBlocks;
private static boolean[] TransparentBlocksMode1;
private static boolean[] TransparentBlocksMode2;

public static boolean isBlockTransparent(int id) {
if (!TransparentCached) {
// Generate TransparentBlocks by reading them from Minecraft
generateTransparentBlocks();
}

if (id < 0)
id += 256;

Expand All @@ -124,12 +120,54 @@ public static boolean isBlockTransparent(int id) {

return TransparentBlocks[id];
}

private static void generateTransparentBlocks() {
if(TransparentBlocks == null) {
readInitialTransparentBlocks();
}

boolean[] transparentBlocks = EngineMode == 1
? TransparentBlocksMode1
: TransparentBlocksMode2;

System.arraycopy(transparentBlocks, 0, TransparentBlocks, 0, TransparentBlocks.length);

List<Integer> customTransparentBlocks = getIntList("Lists.TransparentBlocks", Arrays.asList(new Integer[]{ }));

for(int blockId : customTransparentBlocks) {
if(blockId >= 0 && blockId <= 255) {
TransparentBlocks[blockId] = true;
}
}

List<Integer> customNonTransparentBlocks = getIntList("Lists.NonTransparentBlocks", Arrays.asList(new Integer[]{ }));

for(int blockId : customNonTransparentBlocks) {
if(blockId >= 0 && blockId <= 255) {
TransparentBlocks[blockId] = false;
}
}
}

private static void readInitialTransparentBlocks() {
TransparentBlocks = new boolean[256];
Arrays.fill(TransparentBlocks, false);

InputStream stream = Orebfuscator.class.getResourceAsStream("/resources/transparent_blocks.txt");
InputStream mainStream = Orebfuscator.class.getResourceAsStream("/resources/transparent_blocks.txt");
readTransparentBlocks(TransparentBlocks, mainStream);

TransparentBlocksMode1 = new boolean[256];
System.arraycopy(TransparentBlocks, 0, TransparentBlocksMode1, 0, TransparentBlocksMode1.length);
InputStream mode1Stream = Orebfuscator.class.getResourceAsStream("/resources/transparent_blocks_mode1.txt");
if(mode1Stream != null) readTransparentBlocks(TransparentBlocksMode1, mode1Stream);

TransparentBlocksMode2 = new boolean[256];
System.arraycopy(TransparentBlocks, 0, TransparentBlocksMode2, 0, TransparentBlocksMode2.length);
InputStream mode2Stream = Orebfuscator.class.getResourceAsStream("/resources/transparent_blocks_mode2.txt");
if(mode2Stream != null) readTransparentBlocks(TransparentBlocksMode2, mode2Stream);
}

private static void readTransparentBlocks(boolean[] transparentBlocks, InputStream stream) {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
String line;
Expand All @@ -140,13 +178,11 @@ private static void generateTransparentBlocks() {
int blockId = Integer.parseInt(line.substring(0, index1));
boolean isTransparent = line.substring(index1 + 1, index2).equals("true");

TransparentBlocks[blockId] = isTransparent;
transparentBlocks[blockId] = isTransparent;
}
} catch (IOException e) {
e.printStackTrace();
}

TransparentCached = true;
}

public static boolean isObfuscated(int id, World.Environment environment) {
Expand Down Expand Up @@ -413,6 +449,8 @@ public static void load() {
AntiTexturePackAndFreecam = getBoolean("Booleans.AntiTexturePackAndFreecam", AntiTexturePackAndFreecam);
Enabled = getBoolean("Booleans.Enabled", Enabled);

generateTransparentBlocks();

// Read block lists
setBlockValues(ObfuscateBlocks, getIntList("Lists.ObfuscateBlocks", Arrays.asList(new Integer[]{14, 15, 16, 21, 54, 56, 73, 74, 129, 130})), false);
setBlockValues(NetherObfuscateBlocks, getIntList("Lists.NetherObfuscateBlocks", Arrays.asList(new Integer[]{87, 153})), false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public ObfuscatedCachedChunk(File file, int x, int z) {
path.mkdirs();
}

public void Invalidate() {
public void invalidate() {
Write(0L, new byte[0], new int[0]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ public boolean initOutputPalette() {

this.buffer.outputPaletteLength = this.buffer.paletteLength;

for(byte i = 0; i < this.buffer.paletteLength; i++) {
for(int i = 0; i < this.buffer.paletteLength; i++) {
int blockData = this.buffer.palette[i];

this.buffer.outputPalette[i] = blockData;

if(blockData >= 0) {
this.buffer.outputPaletteMap[blockData] = i;
this.buffer.outputPaletteMap[blockData] = (byte)i;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
import com.lishid.orebfuscator.obfuscation.Calculations;

public class ProtocolLibHook {
private static boolean _isSaved = false;

private ProtocolManager manager;

public void register(Plugin plugin) {
Expand All @@ -42,8 +40,6 @@ public void register(Plugin plugin) {
this.manager.addPacketListener(new PacketAdapter(plugin, PacketType.Play.Server.MAP_CHUNK) {
@Override
public void onPacketSending(PacketEvent event) {
if(_isSaved) return;

PacketContainer packet = event.getPacket();

StructureModifier<Integer> ints = packet.getIntegers();
Expand All @@ -59,7 +55,7 @@ public void onPacketSending(PacketEvent event) {
chunkData.isOverworld = event.getPlayer().getWorld().getEnvironment() == World.Environment.NORMAL;

try {
byte[] newData = Calculations.ObfuscateOrUseCache(chunkData, event.getPlayer());
byte[] newData = Calculations.obfuscateOrUseCache(chunkData, event.getPlayer());

if(newData != null) {
byteArray.write(0, newData);
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/com/lishid/orebfuscator/internal/BlockCoord.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.lishid.orebfuscator.internal;

public class BlockCoord {
public int x;
public int y;
public int z;

public BlockCoord(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}

@Override
public boolean equals(Object other) {
if (other == null || !(other instanceof BlockCoord)) {
return false;
}

BlockCoord object = (BlockCoord) other;

return this.x == object.x && this.y == object.y && this.z == object.z;
}

@Override
public int hashCode() {
return this.x ^ this.y ^ this.z;
}

@Override
public String toString() {
return this.x + " " + this.y + " " + this.z;
}
}
36 changes: 36 additions & 0 deletions src/main/java/com/lishid/orebfuscator/internal/BlockInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.lishid.orebfuscator.internal;

import net.minecraft.server.v1_9_R1.Block;
import net.minecraft.server.v1_9_R1.IBlockData;

public class BlockInfo {
public int x;
public int y;
public int z;
public IBlockData blockData;

public int getTypeId() {
return Block.getId(this.blockData.getBlock());
}

@Override
public boolean equals(Object other) {
if (other == null || !(other instanceof BlockInfo)) {
return false;
}

BlockInfo object = (BlockInfo) other;

return this.x == object.x && this.y == object.y && this.z == object.z;
}

@Override
public int hashCode() {
return this.x ^ this.y ^ this.z;
}

@Override
public String toString() {
return this.x + " " + this.y + " " + this.z;
}
}
33 changes: 33 additions & 0 deletions src/main/java/com/lishid/orebfuscator/internal/ChunkCoord.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.lishid.orebfuscator.internal;


public class ChunkCoord {
public int x;
public int z;

public ChunkCoord(int x, int z) {
this.x = x;
this.z = z;
}

@Override
public boolean equals(Object other) {
if (other == null || !(other instanceof ChunkCoord)) {
return false;
}

ChunkCoord object = (ChunkCoord) other;

return this.x == object.x && this.z == object.z;
}

@Override
public int hashCode() {
return this.x ^ this.z;
}

@Override
public String toString() {
return this.x + " " + this.z;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,87 @@

package com.lishid.orebfuscator.internal;

import net.minecraft.server.v1_9_R1.Block;
import net.minecraft.server.v1_9_R1.BlockPosition;
import net.minecraft.server.v1_9_R1.Chunk;
import net.minecraft.server.v1_9_R1.ChunkProviderServer;
import net.minecraft.server.v1_9_R1.IBlockData;
import net.minecraft.server.v1_9_R1.Packet;
import net.minecraft.server.v1_9_R1.TileEntity;
import net.minecraft.server.v1_9_R1.WorldServer;

import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_9_R1.CraftChunk;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_9_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_9_R1.block.CraftBlock;
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;

//Volatile
import com.lishid.orebfuscator.chunkmap.BlockState;

public class MinecraftInternals {
public static void updateBlockTileEntity(Block block, Player player) {
public static void updateBlockTileEntity(BlockCoord blockCoord, Player player) {
CraftWorld world = (CraftWorld) player.getWorld();
TileEntity tileEntity = world.getTileEntityAt(block.getX(), block.getY(), block.getZ());
TileEntity tileEntity = world.getTileEntityAt(blockCoord.x, blockCoord.y, blockCoord.y);

if (tileEntity == null) {
return;
}

Packet<?> packet = tileEntity.getUpdatePacket();
if (packet != null) {
CraftPlayer player2 = (CraftPlayer) player;
player2.getHandle().playerConnection.sendPacket(packet);
}
}

public static void notifyBlockChange(org.bukkit.World world, CraftBlock block) {
BlockPosition blockPosition = new BlockPosition(block.getX(), block.getY(), block.getZ());
IBlockData blockData = ((CraftChunk)block.getChunk()).getHandle().getBlockData(blockPosition);
public static void notifyBlockChange(org.bukkit.World world, BlockInfo blockInfo) {
BlockPosition blockPosition = new BlockPosition(blockInfo.x, blockInfo.y, blockInfo.z);

((CraftWorld) world).getHandle().notify(blockPosition, blockData, blockData, 0);
((CraftWorld) world).getHandle().notify(blockPosition, blockInfo.blockData, blockInfo.blockData, 0);
}
}

public static int getBlockLightLevel(World world, int x, int y, int z) {
return ((CraftWorld)world).getHandle().getLightLevel(new BlockPosition(x, y, z));
}

public static BlockInfo getBlockInfo(World world, int x, int y, int z) {
IBlockData blockData = getBlockData(world, x, y, z);

if(blockData == null) return null;

BlockInfo block = new BlockInfo();
block.x = x;
block.y = y;
block.z = z;
block.blockData = blockData;

return block;
}

public static BlockState getBlockState(World world, int x, int y, int z) {
IBlockData blockData = getBlockData(world, x, y, z);

if(blockData == null) return null;

Block block = blockData.getBlock();

BlockState blockState = new BlockState();
blockState.id = Block.getId(block);
blockState.meta = block.toLegacyData(blockData);

return blockState;
}

public static int getBlockId(World world, int x, int y, int z) {
IBlockData blockData = getBlockData(world, x, y, z);

return blockData != null ? Block.getId(blockData.getBlock()): -1;
}

private static IBlockData getBlockData(World world, int x, int y, int z) {
WorldServer worldServer = ((CraftWorld)world).getHandle();
ChunkProviderServer chunkProviderServer = worldServer.getChunkProviderServer();
Chunk chunk = chunkProviderServer.getChunkIfLoaded(x >> 4, z >> 4);

return chunk != null ? chunk.getBlockData(new BlockPosition(x, y, z)): null;
}
}
Loading

0 comments on commit 1e0c38f

Please sign in to comment.