Skip to content

Add entity meta support for WrappedBlockState.#39

Merged
Tofaa2 merged 2 commits intoTofaa2:masterfrom
huanmeng-qwq:blockstate
Jul 20, 2025
Merged

Add entity meta support for WrappedBlockState.#39
Tofaa2 merged 2 commits intoTofaa2:masterfrom
huanmeng-qwq:blockstate

Conversation

@huanmeng-qwq
Copy link
Contributor

@huanmeng-qwq huanmeng-qwq commented Jul 20, 2025

Summary by CodeRabbit

  • New Features
    • Added support for retrieving and setting block states using a higher-level abstraction for block displays, Enderman carried blocks, falling blocks, and TNT entities. This allows for easier management and manipulation of block state data in these entities.

@coderabbitai
Copy link

coderabbitai bot commented Jul 20, 2025

Walkthrough

New methods were added to several metadata classes to provide higher-level accessors and mutators for block state information using the WrappedBlockState abstraction. These changes enable direct manipulation of block states rather than relying solely on integer IDs, enhancing the API's expressiveness and consistency across different entity types.

Changes

File(s) Change Summary
.../meta/display/BlockDisplayMeta.java Added getBlockState() and setBlockState(WrappedBlockState) methods for block state abstraction.
.../meta/mobs/monster/EndermanMeta.java Added getCarriedBlockState() and setCarriedBlockState(WrappedBlockState) methods.
.../meta/other/FallingBlockMeta.java Added getBlockState() and setBlockState(WrappedBlockState) methods.
.../meta/other/TntMeta.java Added getBlockState() and setBlockState(WrappedBlockState) methods for TNT block state.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant MetaClass
    participant PacketEvents
    participant WrappedBlockState

    Caller->>MetaClass: setBlockState(WrappedBlockState)
    MetaClass->>WrappedBlockState: getGlobalId()
    MetaClass->>MetaClass: set internal block ID

    Caller->>MetaClass: getBlockState()
    MetaClass->>PacketEvents: getAPI().getServerManager().getVersion()
    MetaClass->>WrappedBlockState: fromGlobalId(blockId, clientVersion)
    MetaClass-->>Caller: WrappedBlockState
Loading

Poem

A hop, a jump, a block anew,
Wrapped states now hop into view!
Endermen, TNT, and blocks that fall,
Can share their secrets, one and all.
With methods fresh and code so neat,
These meta-hops are quite a treat!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 56e64cd and 64021bb.

📒 Files selected for processing (2)
  • api/src/main/java/me/tofaa/entitylib/meta/mobs/monster/EndermanMeta.java (3 hunks)
  • api/src/main/java/me/tofaa/entitylib/meta/other/FallingBlockMeta.java (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • api/src/main/java/me/tofaa/entitylib/meta/mobs/monster/EndermanMeta.java
  • api/src/main/java/me/tofaa/entitylib/meta/other/FallingBlockMeta.java
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
api/src/main/java/me/tofaa/entitylib/meta/other/FallingBlockMeta.java (1)

43-45: Consider renaming for API consistency.

The method name setBlockStateId(WrappedBlockState blockState) is confusing since it takes a WrappedBlockState parameter but has "Id" in the name. For consistency with other classes in this PR, consider renaming it to setBlockState(WrappedBlockState blockState).

-    public void setBlockStateId(WrappedBlockState blockState) {
+    public void setBlockState(WrappedBlockState blockState) {
         setBlockStateId(blockState.getGlobalId());
     }
api/src/main/java/me/tofaa/entitylib/meta/mobs/monster/EndermanMeta.java (1)

35-37: Consider adding null parameter validation.

The setCarriedBlockState() method doesn't handle the case where blockState parameter is null. Consider adding null validation or document the expected behavior.

 public void setCarriedBlockState(WrappedBlockState blockState) {
+    if (blockState == null) {
+        setCarriedBlockID(null);
+        return;
+    }
     setCarriedBlockID(blockState.getGlobalId());
 }

Alternatively, add @Nullable annotation to the parameter and document the behavior.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9dec137 and 56e64cd.

📒 Files selected for processing (4)
  • api/src/main/java/me/tofaa/entitylib/meta/display/BlockDisplayMeta.java (2 hunks)
  • api/src/main/java/me/tofaa/entitylib/meta/mobs/monster/EndermanMeta.java (3 hunks)
  • api/src/main/java/me/tofaa/entitylib/meta/other/FallingBlockMeta.java (2 hunks)
  • api/src/main/java/me/tofaa/entitylib/meta/other/TntMeta.java (2 hunks)
🔇 Additional comments (11)
api/src/main/java/me/tofaa/entitylib/meta/display/BlockDisplayMeta.java (3)

3-3: LGTM: Import statements added correctly.

The necessary imports for PacketEvents and WrappedBlockState are properly added to support the new functionality.

Also applies to: 5-5


25-27: LGTM: Well-implemented getter method.

The getBlockState() method correctly converts the internal block ID to a WrappedBlockState using the appropriate client version context.


29-31: LGTM: Clean setter implementation.

The setBlockState() method properly extracts the global ID from the WrappedBlockState and delegates to the existing setBlockId() method, maintaining consistency with the existing API.

api/src/main/java/me/tofaa/entitylib/meta/other/FallingBlockMeta.java (2)

3-3: LGTM: Import statements added correctly.

The necessary imports for PacketEvents and WrappedBlockState are properly added.

Also applies to: 5-5


39-41: LGTM: Correct getter implementation.

The getBlockState() method properly converts the block state ID to a WrappedBlockState instance using the appropriate version context.

api/src/main/java/me/tofaa/entitylib/meta/other/TntMeta.java (3)

3-3: LGTM: Import statements added correctly.

The necessary imports are properly added to support the new WrappedBlockState functionality.

Also applies to: 5-5


34-36: LGTM: Consistent with existing API.

The getBlockState() method correctly uses getBlockData() to maintain consistency with the existing TntMeta API terminology and properly converts to WrappedBlockState.


38-40: LGTM: Clean delegation pattern.

The setBlockState() method properly delegates to the existing setBlockData() method, maintaining API consistency.

api/src/main/java/me/tofaa/entitylib/meta/mobs/monster/EndermanMeta.java (3)

3-3: LGTM: Import statements added correctly.

The necessary imports for PacketEvents and WrappedBlockState are properly added.

Also applies to: 5-5


29-33: LGTM: Proper null handling in getter.

The getCarriedBlockState() method correctly handles the case where no block is carried by checking for null and returning null appropriately.


48-48: LGTM: Minor formatting improvement.

The whitespace adjustment improves code consistency.

@Tofaa2
Copy link
Owner

Tofaa2 commented Jul 20, 2025

LGTM <3

@Tofaa2 Tofaa2 merged commit d6a3cb7 into Tofaa2:master Jul 20, 2025
1 of 2 checks passed
@huanmeng-qwq huanmeng-qwq deleted the blockstate branch July 21, 2025 01:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants