Skip to content

Commit

Permalink
Added support for pre-1.13 MC, adjusted list of transparency blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksey-Terzi committed Oct 6, 2018
1 parent 9fa505a commit 972286a
Show file tree
Hide file tree
Showing 21 changed files with 1,584 additions and 731 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
public interface INmsManager {
ConfigDefaults getConfigDefaults();

Material[] getExtraTransparentBlocks();

void setMaxLoadedCacheFiles(int value);

INBT createNBT();
Expand Down Expand Up @@ -52,7 +54,5 @@ public interface INmsManager {

Set<Integer> getMaterialIds(Material material);

int getTypeId(int combinedBlockId);

boolean sendBlockChange(Player player, Location blockLocation);
}
2 changes: 1 addition & 1 deletion Plugin/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.4.0-SNAPSHOT</version>
<version>4.4.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Orebfuscator4</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.Arrays;

import com.lishid.orebfuscator.NmsInstance;
import com.lishid.orebfuscator.utils.MaterialHelper;

public class ChunkMapManager {
private static final ThreadLocal<ChunkMapBuffer> _buffer = new ThreadLocal<ChunkMapBuffer>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,25 +343,35 @@ private static void commandListMaterials(CommandSender sender, String[] args) {
private static void commandTransparentBlocks(CommandSender sender, String[] args) {
Material[] materials = Material.values();

List<String> blockNames = new ArrayList<>();
List<String> transparentBlockNames = new ArrayList<>();
List<String> nonTransparentBlockNames = new ArrayList<>();

for (Material material : materials) {
if(material.isBlock()) {
int blockId = NmsInstance.current.getMaterialIds(material).iterator().next();
boolean isTransparent = Orebfuscator.config.isBlockTransparent(blockId);

if(isTransparent) {
blockNames.add(material.name());
transparentBlockNames.add(material.name());
} else {
nonTransparentBlockNames.add(material.name());
}
}
}

Collections.sort(blockNames);
Collections.sort(transparentBlockNames);
Collections.sort(nonTransparentBlockNames);

StringBuilder blocks = new StringBuilder();
blocks.append("Transparent blocks:");

for (String blockName : blockNames) {
for (String blockName : transparentBlockNames) {
blocks.append("\n - " + blockName);
}

blocks.append("\nNon-Transparent blocks:");

for (String blockName : nonTransparentBlockNames) {
blocks.append("\n - " + blockName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import com.lishid.orebfuscator.DeprecatedMethods;
import com.lishid.orebfuscator.NmsInstance;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.utils.MaterialHelper;
import org.bukkit.Material;
import org.bukkit.World;
Expand Down Expand Up @@ -262,24 +263,40 @@ private boolean getBoolean(String path, boolean defaultData) {
}

private byte[] generateTransparentBlocks(int engineMode) {
byte[] transparentBlocks = new byte[NmsInstance.current.getTypeId(MaterialHelper.getMaxId() + 1)];
byte[] transparentBlocks = new byte[MaterialHelper.getMaxId() + 1];

Material[] allMaterials = Material.values();

for(Material material : allMaterials) {
if(material.isBlock()) {
boolean isTransparent = DeprecatedMethods.isTransparent(material);

if(!isTransparent) {
if(isTransparent) {
Set<Integer> ids = NmsInstance.current.getMaterialIds(material);

for (int id : ids) {
transparentBlocks[NmsInstance.current.getTypeId(id)] = 1;
transparentBlocks[id] = 1;
}
}
}
}

Material[] extraTransparentBlocks = NmsInstance.current.getExtraTransparentBlocks();

for(Material material : extraTransparentBlocks) {
Set<Integer> ids = NmsInstance.current.getMaterialIds(material);

for (int id : ids) {
transparentBlocks[id] = 1;
}
}

Set<Integer> lavaIds = NmsInstance.current.getMaterialIds(Material.LAVA);

for (int id : lavaIds) {
transparentBlocks[id] = (byte)(engineMode == 1 ? 0 : 1);
}

return transparentBlocks;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@

package com.lishid.orebfuscator.config;

import java.util.HashSet;
import java.util.Map;

import com.lishid.orebfuscator.NmsInstance;
import com.lishid.orebfuscator.utils.Globals;
import org.bukkit.entity.Player;

import com.lishid.orebfuscator.Orebfuscator;
Expand Down Expand Up @@ -257,8 +254,7 @@ public long getCacheCleanRate() {
// Helper methods

public boolean isBlockTransparent(int id) {
int blockTypeId = NmsInstance.current.getTypeId(id);
return this.transparentBlocks[blockTypeId] == 0;
return this.transparentBlocks[id] == 1;
}

public boolean obfuscateForPlayer(Player player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import com.lishid.orebfuscator.NmsInstance;

import com.lishid.orebfuscator.utils.Globals;
import com.lishid.orebfuscator.utils.MaterialHelper;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Player;

Expand Down
219 changes: 0 additions & 219 deletions Plugin/src/main/resources/resources/transparent_blocks.txt

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public int getZ() {
}

public int getCombinedId() {
return Block.getCombinedId(this.blockData);
Block block = this.blockData.getBlock();
return (Block.getId(block) << 4) | block.toLegacyData(this.blockData);
}

public IBlockData getBlockData() {
Expand Down
Loading

0 comments on commit 972286a

Please sign in to comment.