Skip to content

Commit

Permalink
improve isPlayerHead
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Aug 8, 2024
1 parent e21a5ce commit f9dfc14
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions shared/src/main/java/me/xginko/aef/utils/MaterialUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,30 @@ public static boolean isPlayerHead(BlockState blockState) {
return skull.getSkullType() == SkullType.PLAYER || skull.hasOwner();
}

@SuppressWarnings("deprecation")
public static boolean isPlayerHead(ItemStack itemStack) {
if (!PLAYER_HEADS.contains(itemStack.getType()))
if (!PLAYER_HEADS.contains(itemStack.getType())) {
return false;
if (PlatformUtil.getMinecraftVersion() > 12)
}

if (PlatformUtil.getMinecraftVersion() > 12) {
return true; // Player heads have their own Material enum post 1.12.2
}

if (!itemStack.hasItemMeta()) {
return false;
}

if (((SkullMeta) itemStack.getItemMeta()).hasOwner()) {
return true;
// Legacy sums entity heads and player heads into one type: skull.
// therefore we need to make sure this is not an entity's head
return ((SkullMeta) itemStack.getItemMeta()).hasOwner();
}

if (itemStack.getItemMeta() instanceof BlockStateMeta) {
BlockStateMeta blockStateMeta = (BlockStateMeta) itemStack.getItemMeta();
return blockStateMeta.hasBlockState() && ((Skull) blockStateMeta.getBlockState()).getSkullType() == SkullType.PLAYER;
}

return false;
}

public static final Set<Material> SLAB_LIKE = Stream.concat(
Expand Down

0 comments on commit f9dfc14

Please sign in to comment.