revert back to using Material for compatibility with old saves.

This commit is contained in:
Brianna 2020-04-06 06:27:25 -04:00
parent ddc2f026e5
commit 415715d952
3 changed files with 16 additions and 19 deletions

View File

@ -177,7 +177,7 @@ public final class StructureUtil {
BlockUtil.convertBlockDataToBlock(blockLocation.getBlock(), blockDataList); BlockUtil.convertBlockDataToBlock(blockLocation.getBlock(), blockDataList);
} catch (Exception e) { } catch (Exception e) {
SkyBlock.getInstance().getLogger() SkyBlock.getInstance().getLogger()
.warning("Unable to convert BlockData to Block for type {" + blockDataList.getCompatibleMaterial() + ":" + blockDataList.getData() + "} in structure {" + structure.getStructureFile() + "}"); .warning("Unable to convert BlockData to Block for type {" + blockDataList.getMaterial() + ":" + blockDataList.getData() + "} in structure {" + structure.getStructureFile() + "}");
} }
}); });
} }

View File

@ -17,7 +17,6 @@ import java.util.Map;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class BlockData { public class BlockData {
private CompatibleMaterial compatibleMaterial;
private String material; private String material;
private String biome; private String biome;
private String stateType = BlockStateType.NORMAL.toString(); private String stateType = BlockStateType.NORMAL.toString();
@ -55,8 +54,8 @@ public class BlockData {
private boolean exactTeleport = true; private boolean exactTeleport = true;
public BlockData(CompatibleMaterial material, int x, int y, int z, String biome) { public BlockData(String material, int x, int y, int z, String biome) {
this.compatibleMaterial = material; this.material = material;
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
@ -64,14 +63,12 @@ public class BlockData {
this.biome = biome; this.biome = biome;
} }
public CompatibleMaterial getCompatibleMaterial() { public String getMaterial() {
if (compatibleMaterial == null) return this.material;
return CompatibleMaterial.getMaterial(material);
return compatibleMaterial;
} }
public void setMaterial(CompatibleMaterial material) { public void setMaterial(Material material) {
this.compatibleMaterial = material; this.material = material.name();
} }
public String getBiome() { public String getBiome() {

View File

@ -22,7 +22,7 @@ import java.util.List;
public final class BlockUtil extends BlockUtils { public final class BlockUtil extends BlockUtils {
public static BlockData convertBlockToBlockData(Block block, int x, int y, int z) { public static BlockData convertBlockToBlockData(Block block, int x, int y, int z) {
BlockData blockData = new BlockData(CompatibleMaterial.getMaterial(block), x, y, z, block.getBiome().toString()); BlockData blockData = new BlockData(block.getType().name(), x, y, z, block.getBiome().toString());
int NMSVersion = NMSUtil.getVersionNumber(); int NMSVersion = NMSUtil.getVersionNumber();
blockData.setVersion(NMSVersion); blockData.setVersion(NMSVersion);
@ -246,10 +246,10 @@ public final class BlockUtil extends BlockUtils {
public static void convertBlockDataToBlock(Block block, BlockData blockData) { public static void convertBlockDataToBlock(Block block, BlockData blockData) {
int NMSVersion = NMSUtil.getVersionNumber(); int NMSVersion = NMSUtil.getVersionNumber();
CompatibleMaterial material = blockData.getCompatibleMaterial(); String material = blockData.getMaterial();
if (material == null) return; if (material == null) return;
setBlockFast(block.getWorld(), block.getX(), block.getY(), block.getZ(), material, blockData.getData()); setBlockFast(block.getWorld(), block.getX(), block.getY(), block.getZ(), Material.valueOf(material), blockData.getData());
// TODO Create a class to support biome changes // TODO Create a class to support biome changes
// block.setBiome(Biome.valueOf(blockData.getBiome().toUpperCase())); // block.setBiome(Biome.valueOf(blockData.getBiome().toUpperCase()));
@ -424,10 +424,10 @@ public final class BlockUtil extends BlockUtils {
String[] flower = blockData.getFlower().split(":"); String[] flower = blockData.getFlower().split(":");
int materialData = Integer.parseInt(flower[1]); int materialData = Integer.parseInt(flower[1]);
material = CompatibleMaterial.getMaterial(flower[0].toUpperCase()); material = flower[0].toUpperCase();
if (material != null) { if (material != null) {
ItemStack is = new ItemStack(material.getMaterial(), 1, (byte) materialData); ItemStack is = new ItemStack(Material.getMaterial(material), 1, (byte) materialData);
World world = block.getWorld(); World world = block.getWorld();
@ -462,16 +462,16 @@ public final class BlockUtil extends BlockUtils {
if (blockData.getVersion() > 12) { if (blockData.getVersion() > 12) {
if (NMSVersion > 12) { if (NMSVersion > 12) {
material = CompatibleMaterial.valueOf(flower[0].toUpperCase()); material = flower[0].toUpperCase();
} }
} else { } else {
if (NMSVersion < 13) { if (NMSVersion < 13) {
material = CompatibleMaterial.valueOf(flower[0].toUpperCase()); material = flower[0].toUpperCase();
} }
} }
if (material != null) { if (material != null) {
flowerPot.setContents(new MaterialData(material.getMaterial(), (byte) Integer.parseInt(flower[1]))); flowerPot.setContents(new MaterialData(Material.getMaterial(material), (byte) Integer.parseInt(flower[1])));
} }
state.setData(flowerPot); state.setData(flowerPot);
@ -479,7 +479,7 @@ public final class BlockUtil extends BlockUtils {
} }
} }
if (blockData.getCompatibleMaterial().equals("DOUBLE_PLANT")) { if (material.equals("DOUBLE_PLANT")) {
Block topBlock = block.getLocation().add(0.0D, 1.0D, 0.0D).getBlock(); Block topBlock = block.getLocation().add(0.0D, 1.0D, 0.0D).getBlock();
Block bottomBlock = block.getLocation().subtract(0.0D, 1.0D, 0.0D).getBlock(); Block bottomBlock = block.getLocation().subtract(0.0D, 1.0D, 0.0D).getBlock();