-
-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/data components #514
base: main
Are you sure you want to change the base?
Feat/data components #514
Conversation
built with Refined Cloudflare Pages Action⚡ Cloudflare Pages Deployment
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely helps a ton with understanding data components.
One thing I would maybe suggest to add is a small line which explains whether you can use ItemMeta and DataComponents concurrently, since I am not quite sure about that, even after reading your docs.
EDIT: Also sorry if some of these reviews are broken. I haven't really used this specific feature of GitHub yet
itemStack.setData(DataComponentTypes.RARITY, ItemRarity.RARE); | ||
|
||
itemStack.unsetData(DataComponentTypes.TOOL); // Remove the cool component | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you meant to say tool here?
itemStack.unsetData(DataComponentTypes.TOOL); // Remove the tool component |
ItemStack originalSword = new ItemStack(Material.DIAMOND_SWORD); | ||
|
||
boolean match = damagedSword.matchesWithoutData(originalSword, Set.of(DataComponentTypes.DAMAGE), false); | ||
System.out.println("Match ignoring damage? " + match); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the last sout call I would replace with logger
System.out.println("Match ignoring damage? " + match); | |
logger.info("Match ignoring damage? " + match); |
::: | ||
|
||
The Data Component API provides a version-specific, programmatic interface for accessing and manipulating item data that is otherwise not representable by the `ItemMeta` API. Through this API, you can read and write properties of an item—called "data components"—in a stable and object-oriented manner. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhabs remove the "programming interface" part, as that is already contained within API. Also add a line wrap for better readability in-editor
The Data Component API provides a version-specific interface for accessing and manipulating item data that is otherwise not representable by the `ItemMeta` API. | |
Through this API, you can read and write properties, called "data components", of an item in a stable and object-oriented manner. |
### Structure | ||
![Component Structure](assets/data-component-api-tree.png) | ||
See implementation [here](#example-cool-sword) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe make it clearer what this link does?
For implementation details, [click here](#example-cool-sword) |
allowing us to make modifications to an item. | ||
|
||
The patch also allows for removing components that were previously in the prototype, this is shown by | ||
the `minecraft:tool` example in red. We are removing this component, so this sword item will no longer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the `minecraft:tool` example in red. We are removing this component, so this sword item will no longer | |
The patch also allows for removing components that were previously in the prototype. This is shown by |
|
||
#### No Snapshot | ||
Currently, ItemMeta represents a *Snapshot* of an ItemStack's patched map. | ||
This is expensive as it requires the entire patch to be read, even values that you may not be using. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is expensive as it requires the entire patch to be read, even values that you may not be using. | |
Currently, ItemMeta represents a *snapshot* of an ItemStack's patched map. |
if (damageValue != null) { | ||
System.out.println("Current damage: " + damageValue); | ||
} else { | ||
System.out.println("This item doesn't have a damage component set."); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also here, replace sout call with logging
if (damageValue != null) { | |
System.out.println("Current damage: " + damageValue); | |
} else { | |
System.out.println("This item doesn't have a damage component set."); | |
} | |
if (damageValue != null) { | |
logger.info("Current damage: " + damageValue); | |
} else { | |
logger.info("This item doesn't have a damage component set."); | |
} |
```java | ||
// Set a custom model data value on this item | ||
stack.setData(DataComponentTypes.CUSTOM_MODEL_DATA, CustomModelData.customModelData() | ||
.addFloat(0.5f) | ||
.addFlag(true) | ||
.build() | ||
); | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe smaller indentation to be easier on the reader?
```java | |
// Set a custom model data value on this item | |
stack.setData(DataComponentTypes.CUSTOM_MODEL_DATA, CustomModelData.customModelData() | |
.addFloat(0.5f) | |
.addFlag(true) | |
.build() | |
); | |
``` | |
```java | |
// Set a custom model data value on this item | |
stack.setData(DataComponentTypes.CUSTOM_MODEL_DATA, CustomModelData.customModelData() | |
.addFloat(0.5f) | |
.addFlag(true) | |
.build() | |
); |
``` | ||
This will create a diamond helmet that looks like a netherrite helmet when equipped, but plays a spooky | ||
ghast sound when equipped. | ||
|
||
### Example: Written Book |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
``` | |
This will create a diamond helmet that looks like a netherrite helmet when equipped, but plays a spooky | |
ghast sound when equipped. | |
### Example: Written Book |
This will create a diamond helmet that looks like a netherrite helmet and plays a spooky ghast sound when equipped.
Example: Written Book
// Check if this item has a custom name data component | ||
boolean hasCustomName = stack.hasData(DataComponentTypes.CUSTOM_NAME); | ||
System.out.println("Has custom name? " + hasCustomName); | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe replace System.out.println with more robust logging in order to not endorse people to sout in production?
``` | |
logger.info("Has custom name? " + hasCustomName); |
Please feel free to make modifications directly to the PR.
This is meant as an initial base.