Skip to content

Add Material#getPlacedType API#9607

Closed
tal5 wants to merge 2 commits into
PaperMC:masterfrom
tal5:Placed_Material_API
Closed

Add Material#getPlacedType API#9607
tal5 wants to merge 2 commits into
PaperMC:masterfrom
tal5:Placed_Material_API

Conversation

@tal5
Copy link
Copy Markdown
Contributor

@tal5 tal5 commented Aug 15, 2023

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 for Material#getPlacedType.

Notes

  • Currently it returns a Material, as that's what's stored internally - might make sense to return BlockData to avoid potential issues with more complex data being added in the future/as it might make sense to represent it as BlockData?
  • BlockData#getPlacementMaterial (other way around from this) seems to return AIR when a block doesn't have an item equivalent, while this returns null for items that can't be placed.
    null makes more sense imo, but either is fine I guess - let me know if that should be changed to match.

@tal5 tal5 requested a review from a team as a code owner August 15, 2023 09:35
Copy link
Copy Markdown
Member

@Machine-Maker Machine-Maker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines +45 to +57
+ /**
+ * 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})
+ */
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can drop the javadoc here, just increases workload to maintain it since its a copy

@Warriorrrr
Copy link
Copy Markdown
Member

This seems to be a duplicate of #6680 if I'm not mistaken

@Owen1212055
Copy link
Copy Markdown
Member

Closing, as in general we are waiting for upstream's blocktype/itemtype API to better expose this types of API.

@tal5 tal5 deleted the Placed_Material_API branch May 13, 2024 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Closed

Development

Successfully merging this pull request may close these issues.

4 participants