Add Material#getPlacedType API#9607
Conversation
Machine-Maker
left a comment
There was a problem hiding this comment.
I think returning BlockData would be more appropriate if we had a method that called BlockItem#getPlacementState which returns the equivalent BlockData in nms (BlockState). For just this, Material is fine.
I guess since Material is just going to be straight up deprecated by upstream hopefully next major version, I don't really have an issue adding more methods to Material that only apply to items or blocks but not both
| + /** | ||
| + * Gets the material that would be placed down by {@code item}. | ||
| + * For most placeable items this is the same type as the item, but it is different for some. | ||
| + * <p> | ||
| + * Some examples include: | ||
| + * <pre> | ||
| + * {@link Material#REDSTONE} -> {@link Material#REDSTONE_WIRE} | ||
| + * {@link Material#PUMPKIN_SEEDS} -> {@link Material#PUMPKIN_STEM} | ||
| + * </pre> | ||
| + * @param item An item material. | ||
| + * @return The material that would be placed down by {@code item}, or {@code null} if it can't be placed. | ||
| + * @throws IllegalArgumentException if {@code item} isn't an item ({@link Material#isItem()} is {@code false}) | ||
| + */ |
There was a problem hiding this comment.
Can drop the javadoc here, just increases workload to maintain it since its a copy
|
This seems to be a duplicate of #6680 if I'm not mistaken |
|
Closing, as in general we are waiting for upstream's blocktype/itemtype API to better expose this types of API. |
Additions
Material#getPlacedType- returns the type an item would be placed as (usually the same, but is different in some cases, e.g. pumpkin seeds -> pumpkin stem).UnsafeValues#getPlacedType(Material)- bridge method forMaterial#getPlacedType.Notes
Material, as that's what's stored internally - might make sense to returnBlockDatato avoid potential issues with more complex data being added in the future/as it might make sense to represent it asBlockData?BlockData#getPlacementMaterial(other way around from this) seems to returnAIRwhen a block doesn't have an item equivalent, while this returnsnullfor items that can't be placed.nullmakes more sense imo, but either is fine I guess - let me know if that should be changed to match.