Skip to content

Commit 0e5dba1

Browse files
Documentation improvements, add converter for enchantable component
1 parent 33b49eb commit 0e5dba1

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

api/src/main/java/org/geysermc/geyser/api/item/custom/v2/CustomItemDefinition.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,19 @@ public interface CustomItemDefinition {
111111
* <p>Currently, the following components are supported:</p>
112112
*
113113
* <ul>
114-
* <li>{@code minecraft:consumable}</li>
115-
* <li>{@code minecraft:equippable}</li>
116-
* <li>{@code minecraft:food}</li>
117-
* <li>{@code minecraft:max_damage}</li>
118-
* <li>{@code minecraft:max_stack_size}</li>
119-
* <li>{@code minecraft:use_cooldown}</li>
114+
* <li>{@code minecraft:consumable} ({@link DataComponent#CONSUMABLE})</li>
115+
* <li>{@code minecraft:equippable} ({@link DataComponent#EQUIPPABLE})</li>
116+
* <li>{@code minecraft:food} ({@link DataComponent#FOOD})</li>
117+
* <li>{@code minecraft:max_damage} ({@link DataComponent#MAX_DAMAGE})</li>
118+
* <li>{@code minecraft:max_stack_size} ({@link DataComponent#MAX_STACK_SIZE})</li>
119+
* <li>{@code minecraft:use_cooldown} ({@link DataComponent#USE_COOLDOWN})</li>
120+
* <li>{@code minecraft:enchantable} ({@link DataComponent#ENCHANTABLE})</li>
120121
* </ul>
121122
*
122123
* <p>Note: some components, for example {@code minecraft:rarity}, {@code minecraft:enchantment_glint_override}, and {@code minecraft:attribute_modifiers} are translated automatically,
123124
* and do not have to be specified here.</p>
125+
*
126+
* @see DataComponent
124127
*/
125128
@NonNull DataComponentMap components();
126129

core/src/main/java/org/geysermc/geyser/item/custom/ComponentConverters.java

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
// However, those component classes have the same names as the MCPL ones, which causes some issues when they both have to be used in the same file.
4949
// One can't be imported, and as such its full qualifier (e.g. org.geysermc.mcprotocollib.protocol.data.game.item.component.Consumable) would have to be used.
5050
// That would be a mess to code in, and as such this code here was carefully designed to only require one set of component classes by name (the MCPL ones).
51+
//
52+
// It is VERY IMPORTANT to note that for every component in the API, a converter to MCPL must be put here (better solutions are welcome).
5153
public class ComponentConverters {
5254
private static final Map<DataComponent<?>, ComponentConverter<?>> converters = new HashMap<>();
5355

@@ -88,6 +90,8 @@ public class ComponentConverters {
8890

8991
registerConverter(DataComponent.USE_COOLDOWN, (itemMap, value) -> itemMap.put(DataComponentType.USE_COOLDOWN,
9092
new UseCooldown(value.seconds(), MinecraftKey.identifierToKey(value.cooldownGroup()))));
93+
94+
registerConverter(DataComponent.ENCHANTABLE, (itemMap, value) -> itemMap.put(DataComponentType.ENCHANTABLE, value));
9195
}
9296

9397
private static <T> void registerConverter(DataComponent<T> component, ComponentConverter<T> converter) {

0 commit comments

Comments
 (0)