Method to get material using also data

This commit is contained in:
Fabrizio La Rosa 2020-06-22 16:30:09 +02:00 committed by Brianna
parent 9ec971e219
commit 96a6f33958

View File

@ -1372,13 +1372,40 @@ public enum CompatibleMaterial {
return null;
}
/**
* Lookup a Material by Material and data, corrected for legacy
*
* @param mat material to check
* @param data data of the block
* @return LegacyMaterial or null if none found
*/
public static CompatibleMaterial getMaterial(Material mat, byte data) {
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) { // Flattening
return CompatibleMaterial.getMaterial(mat);
} else { // Pre-Flattening
if(mat != null){
if (data != 0) {
for (CompatibleMaterial cm : CompatibleMaterial.values()) {
if (cm.getMaterial() != null
&& cm.getMaterial().equals(mat)) {
if (cm.getData() == data) {
return cm;
}
}
}
}
return CompatibleMaterial.getMaterial(mat);
}
}
return null;
}
private static CompatibleMaterial getMaterialFromNewBlock(Block block) {
if (block == null) {
return null;
}
Material mat = block.getType();
if (mat == null) return null;
else if (useLegacy) {
if (useLegacy) {
LegacyMaterialBlockType legacyBlock = LegacyMaterialBlockType.getFromLegacy(mat.name());
if (legacyBlock != null) {
return lookupMap.get(legacyBlock.name());