Skip to content

Conversation

@steveb05
Copy link
Contributor

@steveb05 steveb05 commented Aug 19, 2025

To address an issue with cat variants, this pull request updates how their metadata is handled. Previously, the system used the enum's ordinal value for the metadata packet. This caused the wrong variant to be applied to the entity because cat variants are stored in the registry.

To fix this, the code now uses the cat variant registry provided by packet events. To maintain backward compatibility with older API versions, the enum has been mapped to the corresponding registry.

Additionally, since wolves also have variants, a corresponding method for them has been added. This required updating the maximum offset to account for two extra fields: one for the variant and one for the sound variant.

Summary by CodeRabbit

  • New Features

    • Added get/set support for wolf variants.
    • Upgraded cat variant handling to use typed variant objects for more accurate variant representation.
  • API Changes

    • New public methods to manage wolf variants.
    • Cat variant API changed from ordinal-based values to typed variant objects for consistent retrieval and storage.

@coderabbitai
Copy link

coderabbitai bot commented Aug 19, 2025

Walkthrough

Typed variant support is introduced for cats and wolves. CatMeta now maps its Variant enum to Mojang’s CatVariant and writes TYPED_CAT_VARIANT. WolfMeta adds getVariant/setVariant using TYPED_WOLF_VARIANT and increases MAX_OFFSET; imports updated accordingly.

Changes

Cohort / File(s) Summary
Cat typed variant migration
api/src/main/java/me/tofaa/entitylib/meta/mobs/tameable/CatMeta.java
Replaces ordinal-based cat variants with typed CatVariant mapping; Variant enum constants now wrap CatVariant values; adds Variant(CatVariant) constructor and getCatVariant(); setter now writes EntityDataTypes.TYPED_CAT_VARIANT; imports updated.
Wolf typed variant addition
api/src/main/java/me/tofaa/entitylib/meta/mobs/tameable/WolfMeta.java
Adds getVariant() and setVariant(WolfVariant) using TYPED_WOLF_VARIANT at offset (OFFSET, 3) with default WolfVariants.PALE; increases MAX_OFFSET from OFFSET + 3 to OFFSET + 5; imports updated; existing collar/anger/begging accessors unchanged.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Caller
  participant CatMeta
  participant Metadata as Entity Metadata

  rect rgba(230,245,255,0.6)
  note over CatMeta: New typed cat variant flow
  Caller->>CatMeta: setVariant(Variant v)
  CatMeta->>CatMeta: v.getCatVariant()
  CatMeta->>Metadata: write(TYPED_CAT_VARIANT, CatVariant)
  Metadata-->>CatMeta: ack
  CatMeta-->>Caller: return
  end
Loading
sequenceDiagram
  autonumber
  participant Caller
  participant WolfMeta
  participant Metadata as Entity Metadata

  rect rgba(235,255,235,0.6)
  note over WolfMeta: New wolf variant accessors
  Caller->>WolfMeta: getVariant()
  WolfMeta->>Metadata: read(TYPED_WOLF_VARIANT, default=PALE)
  Metadata-->>WolfMeta: WolfVariant
  WolfMeta-->>Caller: WolfVariant
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

A rabbit hops where variants bloom,
Cats wear patterns in typed costume,
Wolves choose hues with tidy lore,
Metadata hums from core to core,
Hop, review, and patch once more! 🐇

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
api/src/main/java/me/tofaa/entitylib/meta/mobs/tameable/CatMeta.java (1)

23-30: Fix type mismatch in getVariant after switching to TYPED_CAT_VARIANT

You now write a CatVariant into metadata (via TYPED_CAT_VARIANT), but getVariant currently reads the index as CatMeta.Variant. This will cause a type mismatch at runtime. Read CatVariant from metadata, then map it to CatMeta.Variant.

Apply this diff to getVariant:

     @NotNull
     public CatMeta.Variant getVariant() {
-        return super.metadata.getIndex(OFFSET, Variant.BLACK);
+        final CatVariant catVariant = super.metadata.getIndex(OFFSET, CatVariants.BLACK);
+        return Variant.fromCatVariant(catVariant);
     }

And add a mapping helper in the enum:

     private static final Variant[] VALUES = values();
 
     public CatVariant getCatVariant() {
         return catVariant;
     }
+
+    public static Variant fromCatVariant(final CatVariant catVariant) {
+        for (final Variant v : VALUES) {
+            if (v.catVariant == catVariant) {
+                return v;
+            }
+        }
+        return BLACK;
+    }
🧹 Nitpick comments (1)
api/src/main/java/me/tofaa/entitylib/meta/mobs/tameable/WolfMeta.java (1)

14-14: Confirm MAX_OFFSET (+5) is intentional; otherwise adjust to +4

Current fields consume offsets 0..3:

  • 0: begging
  • 1: collar color
  • 2: anger time
  • 3: typed variant

If “sound variant” (mentioned in the PR summary) is not yet implemented at offset 4, consider setting MAX_OFFSET to OFFSET + 4 to reflect the next free slot. If you are intentionally reserving the slot, a short comment would help future readers.

Apply if unintentional:

-    public static final byte MAX_OFFSET = OFFSET + 5;
+    public static final byte MAX_OFFSET = OFFSET + 4;
📜 Review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between d4c3b1e and a38d772.

📒 Files selected for processing (2)
  • api/src/main/java/me/tofaa/entitylib/meta/mobs/tameable/CatMeta.java (3 hunks)
  • api/src/main/java/me/tofaa/entitylib/meta/mobs/tameable/WolfMeta.java (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
api/src/main/java/me/tofaa/entitylib/meta/mobs/tameable/WolfMeta.java (1)
api/src/main/java/me/tofaa/entitylib/meta/types/TameableMeta.java (1)
  • TameableMeta (9-46)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (2)
api/src/main/java/me/tofaa/entitylib/meta/mobs/tameable/WolfMeta.java (1)

20-27: Typed wolf variant read/write looks correct

Using TYPED_WOLF_VARIANT with WolfVariant default WolfVariants.PALE is aligned with the registry-based metadata change. API is clear with @NotNull annotations.

api/src/main/java/me/tofaa/entitylib/meta/mobs/tameable/CatMeta.java (1)

28-30: Switch to TYPED_CAT_VARIANT is the right move

Writing the registry entry via value.getCatVariant() correctly aligns with PacketEvents’ typed variant handling and resolves ordinal mismatch issues.

@steveb05 steveb05 force-pushed the fix/use-variant-registry branch from a38d772 to b7b69c3 Compare August 19, 2025 22:44
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 (1)
api/src/main/java/me/tofaa/entitylib/meta/mobs/tameable/CatMeta.java (1)

78-90: Optional: Replace linear search with an O(1) lookup map.

fromCatVariant currently does an O(n) scan across VALUES. Small n here, so it’s fine, but this can be simplified and made future-proof with a precomputed map.

Apply this diff to precompute the lookup map and streamline the method:

@@
-        private static final Variant[] VALUES = values();
+        private static final Variant[] VALUES = values();
+        private static final java.util.Map<CatVariant, Variant> BY_CAT_VARIANT = new java.util.HashMap<>();
+        static {
+            for (final Variant v : VALUES) {
+                BY_CAT_VARIIANT.put(v.getCatVariant(), v);
+            }
+        }
@@
-        public static Variant fromCatVariant(@NotNull final CatVariant catVariant) {
-            for (final Variant variant : VALUES) {
-                if (variant.getCatVariant().equals(catVariant)) {
-                    return variant;
-                }
-            }
-            return BLACK;
-        }
+        public static Variant fromCatVariant(@NotNull final CatVariant catVariant) {
+            return BY_CAT_VARIANT.getOrDefault(catVariant, BLACK);
+        }
📜 Review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between a38d772 and b7b69c3.

📒 Files selected for processing (2)
  • api/src/main/java/me/tofaa/entitylib/meta/mobs/tameable/CatMeta.java (3 hunks)
  • api/src/main/java/me/tofaa/entitylib/meta/mobs/tameable/WolfMeta.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • api/src/main/java/me/tofaa/entitylib/meta/mobs/tameable/WolfMeta.java
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (5)
api/src/main/java/me/tofaa/entitylib/meta/mobs/tameable/CatMeta.java (5)

3-4: Good move to use registry-backed CatVariant.

Switching to CatVariant/CatVariants aligns the API with the data-driven registry and avoids ordinal mismatches. No issues spotted here.


25-26: Reading typed variant looks correct and preserves a sensible default.

Using a CatVariant default (CatVariants.BLACK) and mapping it back to the public Variant enum is a clean approach for compatibility.


29-31: Writing TYPED_CAT_VARIANT is the right fix.

Persisting the typed CatVariant via EntityDataTypes.TYPED_CAT_VARIANT avoids the previous ordinal bug and brings this inline with the registry model.


58-68: Enum-to-registry mapping is comprehensive and explicit.

The mappings cover all known cat variants and keep the public API stable. Looks good.


70-74: Encapsulation of the underlying CatVariant is clear.

Storing the mapped CatVariant in the enum is straightforward and keeps responsibilities localized.

@Tofaa2
Copy link
Owner

Tofaa2 commented Aug 20, 2025

LGTM! Thank you for the PR <3

@Tofaa2 Tofaa2 merged commit 598d71f into Tofaa2:master Aug 20, 2025
1 of 2 checks passed
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