Not every material has a BlockData

This commit is contained in:
Brokkonaut
2018-07-21 14:30:44 +02:00
parent 51505cf34a
commit 0792fbd32a
2 changed files with 306 additions and 289 deletions

View File

@ -21,6 +21,16 @@ public class MaterialConverter {
private static HashMap<String, Integer> blockStateToID = new HashMap<>();
private static int nextBlockStateId;
private static HashMap<String, Material> materialKeyToMaterial = new HashMap<>();
static {
for (Material m : Material.values()) {
if (!m.name().startsWith("LEGACY_") && m.getKey() != null) {
materialKeyToMaterial.put(m.getKey().toString(), m);
}
}
}
public synchronized static int getOrAddMaterialId(NamespacedKey nameSpaceKey) {
return getOrAddMaterialId(nameSpaceKey.toString());
}
@ -80,7 +90,11 @@ public class MaterialConverter {
}
public static Material getMaterial(int materialId) {
return getBlockData(materialId, -1).getMaterial();
String material = idToMaterial[materialId];
if (materialId >= 0) {
material = material + idToBlockState[materialId];
}
return materialKeyToMaterial.get(material);
}
public static void initializeMaterials(Connection connection) throws SQLException {

View File

@ -158,6 +158,9 @@ public class WorldEditor implements Runnable {
PerformResult perform() throws WorldEditorException {
BlockData replacedBlock = MaterialConverter.getBlockData(this.replacedMaterial, replacedData);
BlockData setBlock = MaterialConverter.getBlockData(this.typeMaterial, typeData);
if (replacedBlock == null || setBlock == null) {
throw new WorldEditorException("Could not parse the material", loc.clone());
}
// action: set to replaced
if (dontRollback.contains(replacedBlock.getMaterial())) {