Preserve BlockData in 1.13+

This commit is contained in:
Brianna 2020-04-16 02:57:42 -04:00
parent 1df8a0a3d4
commit 53e029bd3b
2 changed files with 19 additions and 2 deletions

View File

@ -17,6 +17,7 @@ import java.util.Map;
public class BlockData {
private String material;
private String blockData = "";
private String biome;
private String stateType = BlockStateType.NORMAL.toString();
private String dataType = BlockDataType.NORMAL.toString();
@ -72,6 +73,15 @@ public class BlockData {
this.material = material.name();
}
public String getBlockData() {
return blockData;
}
public void setBlockData(String blockData) {
this.blockData = blockData;
}
public String getBiome() {
return this.biome;
}

View File

@ -28,6 +28,10 @@ public final class BlockUtil extends BlockUtils {
int NMSVersion = NMSUtil.getVersionNumber();
blockData.setVersion(NMSVersion);
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
blockData.setBlockData(block.getBlockData().getAsString());
}
BlockState blockState = block.getState();
MaterialData materialData = blockState.getData();
@ -252,7 +256,10 @@ public final class BlockUtil extends BlockUtils {
Material material = Material.valueOf(materialStr);
if (material == Material.AIR) return;
setBlockFast(block.getWorld(), block.getX(), block.getY(), block.getZ(), material, blockData.getData());
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_13))
setBlockFast(block.getWorld(), block.getX(), block.getY(), block.getZ(), material, blockData.getData());
else
block.setBlockData(Bukkit.getServer().createBlockData(blockData.getBlockData()));
// TODO Create a class to support biome changes
// block.setBiome(Biome.valueOf(blockData.getBiome().toUpperCase()));
@ -417,7 +424,7 @@ public final class BlockUtil extends BlockUtils {
state.setData(stairs);
} else if (blockDataType == BlockDataType.FLOWERPOT) {
setBlockFast(block.getWorld(), block.getX(), block.getY() - 1, block.getZ(), CompatibleMaterial.STONE, (byte) 0);
if (NMSVersion >= 8 && NMSVersion <= 12) {
if (NMSVersion >= 8 && NMSVersion <= 12) {
if (block.getLocation().clone().subtract(0.0D, 1.0D, 0.0D).getBlock().getType() == Material.AIR) {
setBlockFast(block.getWorld(), block.getX(), block.getY() - 1, block.getZ(), CompatibleMaterial.STONE, (byte) 0);
}