Skip to content

Commit

Permalink
Fixed: legacy material querying
Browse files Browse the repository at this point in the history
  • Loading branch information
BestBearr committed Jul 30, 2024
1 parent fd9701c commit c5be28d
Showing 1 changed file with 56 additions and 8 deletions.
64 changes: 56 additions & 8 deletions src/main/java/co/crystaldev/alpinecore/util/MaterialHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,12 @@ public final class MaterialHelper {
return XMaterial.AIR;
}

// TODO(bear): what happened here?
return XMaterial.matchXMaterial(block.getType());
// if (XMaterial.supports(13)) {
// return XMaterial.matchXMaterial(block.getType());
// }
// else {
// return getType(block.getTypeId(), block.getData());
// }
if (XMaterial.supports(13)) {
return XMaterial.matchXMaterial(block.getType());
}
else {
return getType(block.getTypeId(), block.getData());
}
}

/**
Expand Down Expand Up @@ -135,6 +133,11 @@ public static void setType(@NotNull Location location, @NotNull XMaterial type)
setType(location.getBlock(), type, true);
}

private static boolean hasType(int id, byte data) {
XMaterial resolvedMaterial = LEGACY_MATERIALS.get(id << 8 | data);
return resolvedMaterial != null || LEGACY_MATERIALS.get(id << 8) != null;
}

static {
for (XMaterial value : XMaterial.values()) {
int id = value.getId();
Expand All @@ -146,5 +149,50 @@ public static void setType(@NotNull Location location, @NotNull XMaterial type)
LEGACY_MATERIALS.put(key, value);
}
}

// Some types such as repeaters and comparators were flattened into one type
// resulting in them not getting registered
for (Material value : Material.values()) {
int id = value.getId();
for (int data = 0; data < 16; data++) {
if (!hasType(id, (byte) data)) {
LEGACY_MATERIALS.put(id << 8 | data, XMaterial.matchXMaterial(value));
}
}
}

// Register edge-cases
LEGACY_MATERIALS.put(Material.BED_BLOCK.getId() << 8, XMaterial.RED_BED);
LEGACY_MATERIALS.put(Material.FLOWER_POT.getId() << 8, XMaterial.FLOWER_POT);
LEGACY_MATERIALS.put(Material.SKULL.getId() << 8, XMaterial.SKELETON_SKULL);

LEGACY_MATERIALS.put(Material.SIGN_POST.getId() << 8, XMaterial.OAK_SIGN);
LEGACY_MATERIALS.put(Material.WALL_SIGN.getId() << 8, XMaterial.OAK_WALL_SIGN);
LEGACY_MATERIALS.put(Material.WOOD_PLATE.getId() << 8, XMaterial.OAK_PRESSURE_PLATE);
LEGACY_MATERIALS.put(Material.TRAP_DOOR.getId() << 8, XMaterial.OAK_TRAPDOOR);

LEGACY_MATERIALS.put(Material.DOUBLE_PLANT.getId() << 8, XMaterial.SUNFLOWER);
LEGACY_MATERIALS.put(Material.DOUBLE_PLANT.getId() << 8 | 1, XMaterial.LILAC);
LEGACY_MATERIALS.put(Material.DOUBLE_PLANT.getId() << 8 | 2, XMaterial.TALL_GRASS);
LEGACY_MATERIALS.put(Material.DOUBLE_PLANT.getId() << 8 | 3, XMaterial.LARGE_FERN);
LEGACY_MATERIALS.put(Material.DOUBLE_PLANT.getId() << 8 | 4, XMaterial.ROSE_BUSH);
LEGACY_MATERIALS.put(Material.DOUBLE_PLANT.getId() << 8 | 5, XMaterial.PEONY);

LEGACY_MATERIALS.put(Material.DOUBLE_STEP.getId() << 8, XMaterial.SMOOTH_STONE_SLAB);
LEGACY_MATERIALS.put(Material.DOUBLE_STEP.getId() << 8 | 1, XMaterial.SANDSTONE_SLAB);
LEGACY_MATERIALS.put(Material.DOUBLE_STEP.getId() << 8 | 2, XMaterial.PETRIFIED_OAK_SLAB);
LEGACY_MATERIALS.put(Material.DOUBLE_STEP.getId() << 8 | 3, XMaterial.COBBLESTONE_SLAB);
LEGACY_MATERIALS.put(Material.DOUBLE_STEP.getId() << 8 | 4, XMaterial.BRICK_SLAB);
LEGACY_MATERIALS.put(Material.DOUBLE_STEP.getId() << 8 | 5, XMaterial.STONE_BRICK_SLAB);
LEGACY_MATERIALS.put(Material.DOUBLE_STEP.getId() << 8 | 6, XMaterial.NETHER_BRICK_SLAB);
LEGACY_MATERIALS.put(Material.DOUBLE_STEP.getId() << 8 | 7, XMaterial.QUARTZ_SLAB);
LEGACY_MATERIALS.put(Material.DOUBLE_STEP.getId() << 8 | 8, XMaterial.SMOOTH_STONE);
LEGACY_MATERIALS.put(Material.DOUBLE_STEP.getId() << 8 | 9, XMaterial.SMOOTH_SANDSTONE);
LEGACY_MATERIALS.put(Material.DOUBLE_STEP.getId() << 8 | 10, XMaterial.PETRIFIED_OAK_SLAB);
LEGACY_MATERIALS.put(Material.DOUBLE_STEP.getId() << 8 | 11, XMaterial.COBBLESTONE_SLAB);
LEGACY_MATERIALS.put(Material.DOUBLE_STEP.getId() << 8 | 12, XMaterial.BRICK_SLAB);
LEGACY_MATERIALS.put(Material.DOUBLE_STEP.getId() << 8 | 13, XMaterial.STONE_BRICK_SLAB);
LEGACY_MATERIALS.put(Material.DOUBLE_STEP.getId() << 8 | 14, XMaterial.NETHER_BRICK_SLAB);
LEGACY_MATERIALS.put(Material.DOUBLE_STEP.getId() << 8 | 15, XMaterial.SMOOTH_QUARTZ);
}
}

0 comments on commit c5be28d

Please sign in to comment.