mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-28 19:22:50 +01:00
SPIGOT-4253: Add way to prioritise item conversion
This commit is contained in:
parent
29e7564874
commit
96778caabb
2 changed files with 19 additions and 2 deletions
|
@ -163,6 +163,10 @@ public class CraftLegacy {
|
|||
}
|
||||
|
||||
public static Material fromLegacy(MaterialData materialData) {
|
||||
return fromLegacy(materialData, false);
|
||||
}
|
||||
|
||||
public static Material fromLegacy(MaterialData materialData, boolean itemPriority) {
|
||||
Material material = materialData.getItemType();
|
||||
if (material == null || !material.isLegacy()) {
|
||||
return material;
|
||||
|
@ -170,7 +174,15 @@ public class CraftLegacy {
|
|||
|
||||
Material mappedData = null;
|
||||
|
||||
if (material.isBlock()) {
|
||||
// Try item first
|
||||
if (itemPriority) {
|
||||
Item item = materialToItem.get(materialData);
|
||||
if (item != null) {
|
||||
mappedData = CraftMagicNumbers.getMaterial(item);
|
||||
}
|
||||
}
|
||||
|
||||
if (mappedData == null && material.isBlock()) {
|
||||
// Try exact match first
|
||||
IBlockData iblock = materialToData.get(materialData);
|
||||
if (iblock != null) {
|
||||
|
@ -187,7 +199,7 @@ public class CraftLegacy {
|
|||
}
|
||||
|
||||
// Fallback to matching item
|
||||
if (mappedData == null) {
|
||||
if (!itemPriority && mappedData == null) {
|
||||
Item item = materialToItem.get(materialData);
|
||||
if (item != null) {
|
||||
mappedData = CraftMagicNumbers.getMaterial(item);
|
||||
|
|
|
@ -134,6 +134,11 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|||
return CraftLegacy.fromLegacy(material);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material fromLegacy(MaterialData material, boolean itemPriority) {
|
||||
return CraftLegacy.fromLegacy(material, itemPriority);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockData fromLegacy(Material material, byte data) {
|
||||
return CraftBlockData.fromData(getBlock(material, data));
|
||||
|
|
Loading…
Reference in a new issue