Skip to content

Custom item API v2 #5189

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

Open
wants to merge 223 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 202 commits
Commits
Show all changes
223 commits
Select commit Hold shift + click to select a range
61f5db1
First work on a new API (wow that's a lot of TODOs)
eclipseisoffline Nov 29, 2024
ea6c3c6
Add component readers for all the planned components
eclipseisoffline Nov 29, 2024
0922b18
Fix equippable slot reading and add support for all consume animations
eclipseisoffline Nov 29, 2024
435b73d
Add use cooldown support
eclipseisoffline Nov 29, 2024
cce49fa
Fix max stack size and max damage components
eclipseisoffline Nov 30, 2024
1dd854a
Implement block item and entity placer properties
eclipseisoffline Nov 30, 2024
4af8e12
Add documentation and change some stuff in the API
eclipseisoffline Nov 30, 2024
efae1f3
Implement the changes in Geyser
eclipseisoffline Nov 30, 2024
8bbad9d
Implement the changes in Geyser part 2
eclipseisoffline Nov 30, 2024
7eeb5bb
Remove old custom item options
eclipseisoffline Nov 30, 2024
4514f55
Work on support for the old format
eclipseisoffline Nov 30, 2024
8ea3c97
Start work on predicates, somewhat
eclipseisoffline Nov 30, 2024
7888956
More work on predicates, I'll probably simplify it later
eclipseisoffline Dec 1, 2024
ce55d88
Clean up predicates a bit
eclipseisoffline Dec 1, 2024
52f2b9f
Add model grouping
eclipseisoffline Dec 2, 2024
49f31c9
Work on range dispatch predicate
eclipseisoffline Dec 6, 2024
9139af2
Implement range dispatch predicates when converting old mappings to n…
eclipseisoffline Dec 6, 2024
4d09104
Implement reading range dispatch predicates from mappings
eclipseisoffline Dec 6, 2024
0346a80
Implement sorting for range dispatch predicates, needs testing
eclipseisoffline Dec 6, 2024
c38bf26
Add model check to custom item comparator
eclipseisoffline Dec 6, 2024
79bf4af
Clean up predicates a bit
eclipseisoffline Dec 6, 2024
f6f6423
Merge remote-tracking branch 'upstream/master' into custom-item-api-v2
eclipseisoffline Dec 12, 2024
fd09a05
Update custom item translator for 1.21.4, implement custom model data
eclipseisoffline Dec 6, 2024
7fabf0c
Implement/update register items event for new custom item definitions
eclipseisoffline Dec 11, 2024
04d7f48
More stuff in the custom item registry populator
eclipseisoffline Dec 12, 2024
04fe043
Add priority option to definitions, deprecate texture size and render…
eclipseisoffline Dec 12, 2024
5ecc61f
Implement priority option
eclipseisoffline Dec 12, 2024
12499bf
Read priority option from mappings
eclipseisoffline Dec 12, 2024
bca98c7
Add unbreakable condition predicate
eclipseisoffline Dec 12, 2024
6e0e3c0
Use unbreakable predicate when converting v1 to v2 mappings
eclipseisoffline Dec 12, 2024
774e556
Remove BedrockCreativeTab in favour of CreativeCategory
eclipseisoffline Dec 12, 2024
1685918
Remove adventure from API module
eclipseisoffline Dec 12, 2024
7164ca0
Some fixes
eclipseisoffline Dec 12, 2024
2263cc8
Remove this
eclipseisoffline Dec 12, 2024
3fac2cd
Reimplement unbreakable predicate check
eclipseisoffline Dec 12, 2024
361df16
Fix build
eclipseisoffline Dec 12, 2024
b80c054
Fix charge type predicate
eclipseisoffline Dec 12, 2024
eb0b40c
I'm very confused at why this doesn't work
eclipseisoffline Dec 12, 2024
a4c17da
Fix adding multiple definitions for same item model and sorting of pr…
eclipseisoffline Dec 12, 2024
a80e90d
Fix adding multiple definitions for same item model again
eclipseisoffline Dec 12, 2024
e7d7a9d
Improve mapping custom items
eclipseisoffline Dec 14, 2024
12f2e1a
Improve the reading and error handling of item mappings
eclipseisoffline Dec 16, 2024
fe8336a
Some of Adventure was left in the API
eclipseisoffline Dec 16, 2024
f44f368
Improve predicate reading error handling
eclipseisoffline Dec 16, 2024
a997820
Make item definitions in group able to override the group's model
eclipseisoffline Dec 16, 2024
7ed830a
Improve error handling when registering custom items
eclipseisoffline Dec 16, 2024
b5cef99
Clean up custom item registry populator a bit
eclipseisoffline Dec 16, 2024
66e288f
Improve documentation of (predicate) new API
eclipseisoffline Dec 16, 2024
852c5c2
Apparently Javadoc can break builds
eclipseisoffline Dec 16, 2024
18cde32
Improve documentation just a bit
eclipseisoffline Dec 16, 2024
885c4d9
Merge remote-tracking branch 'upstream/master' into custom-item-api-v2
eclipseisoffline Dec 16, 2024
25109b7
Add predicate caching
eclipseisoffline Dec 19, 2024
635c8c4
Default to definition type when no type key is given
eclipseisoffline Dec 19, 2024
e84f8a3
Whoops got to include the lib
eclipseisoffline Dec 19, 2024
bcc7915
Factor in range dispatch scaling when sorting predicate
eclipseisoffline Dec 19, 2024
4aea17a
Component combination validation
eclipseisoffline Dec 19, 2024
1683243
Fix max stack size validation when reading json mappings
eclipseisoffline Dec 19, 2024
4629f7b
"Implement" v2 block mappings reading
eclipseisoffline Dec 19, 2024
2b9f519
Cleanup item registry populator a bit
eclipseisoffline Dec 19, 2024
ff35c6e
Fix mapping reading
eclipseisoffline Dec 19, 2024
b254594
Move identifierToKey out of ItemRegistryPopulator
eclipseisoffline Dec 19, 2024
56c508d
Throw UnsupportedOperationException when reading block v2 mappings
eclipseisoffline Dec 19, 2024
5620f0a
Move predicate implementations out of API module
eclipseisoffline Jan 10, 2025
0986203
Send nutrition and saturation to the client
eclipseisoffline Jan 10, 2025
e8bd2a1
Refactor mappings reading with proper type checking and conversions a…
eclipseisoffline Jan 10, 2025
aa365d9
Small cleanup
eclipseisoffline Jan 10, 2025
aa13113
Clean up predicates in the API
eclipseisoffline Jan 10, 2025
094ff41
Merge remote-tracking branch 'upstream/master' into custom-item-api-v2
eclipseisoffline Jan 10, 2025
7af9518
Implement predicate strategies
eclipseisoffline Jan 10, 2025
f4c9c3d
Read predicate strategies from mappings
eclipseisoffline Jan 10, 2025
46e6fd3
Remove MCPL from API module, but now stuff is broken. Also still need…
eclipseisoffline Jan 11, 2025
03402d4
Update implementations and mappings reader, but populator is broken
eclipseisoffline Jan 11, 2025
aabd537
My IDE did something it shouldn't have
eclipseisoffline Jan 11, 2025
d06ad0b
Improve enum reader error message
eclipseisoffline Jan 11, 2025
1dce683
Move predicate classes up
eclipseisoffline Jan 11, 2025
7e973ea
Fix component patching, MCPL removal is done now
eclipseisoffline Jan 11, 2025
9f21221
Component validation in the API
eclipseisoffline Jan 11, 2025
ffb94ff
Proper support for the enchantable value property
eclipseisoffline Jan 13, 2025
44a1bba
Reformat some stuff my IDE shouldn't have done
eclipseisoffline Jan 13, 2025
33b49eb
Properly implement protection value
eclipseisoffline Jan 13, 2025
0e5dba1
Documentation improvements, add converter for enchantable component
eclipseisoffline Jan 13, 2025
0308388
Remove unused stuff
eclipseisoffline Jan 13, 2025
d522f61
Remove rarely used method
eclipseisoffline Jan 13, 2025
61b703c
Merge remote-tracking branch 'upstream/master' into custom-item-api-v2
eclipseisoffline Jan 13, 2025
ebbd1c5
Small documentation stuff
eclipseisoffline Jan 13, 2025
1afb733
Work on tool component stuff
eclipseisoffline Jan 14, 2025
75e371c
Add tool component to API
eclipseisoffline Jan 14, 2025
67b615e
Implement tool component in custom item populator
eclipseisoffline Jan 14, 2025
261b6ca
Add tool component mappings reader
eclipseisoffline Jan 14, 2025
c63386a
Update documentation
eclipseisoffline Jan 14, 2025
2558620
Add repairable mappings reader
eclipseisoffline Jan 14, 2025
373eeac
Implement repairable component in custom item registry populator
eclipseisoffline Jan 14, 2025
fbbf210
Documentation whoopsy
eclipseisoffline Jan 14, 2025
ab174b5
Javadoc broke my build again (this isn't proper HTML)
eclipseisoffline Jan 14, 2025
422c5a9
Update MCPL
eclipseisoffline Jan 17, 2025
a5d6fb1
Consistency renames, start on has component predicate
eclipseisoffline Jan 17, 2025
af76cd0
Update API module with has component predicate
eclipseisoffline Jan 17, 2025
505a74b
Update implementations and implement has component predicate
eclipseisoffline Jan 18, 2025
dee7b5a
Update reading of match predicate property
eclipseisoffline Jan 18, 2025
6705513
Fix broken/damaged predicates
eclipseisoffline Jan 18, 2025
bd7e471
Remove enchantable stuff from chargeable properties as that is decide…
eclipseisoffline Jan 18, 2025
ea850f4
Clean up custom item registry populator
eclipseisoffline Jan 18, 2025
020e78e
Make new item definition register method throw exception
eclipseisoffline Jan 18, 2025
27b2ec7
Charge type javadocs
eclipseisoffline Jan 18, 2025
fc0103b
Make air model constant
eclipseisoffline Jan 18, 2025
2662c81
Rename creative category internal name to bedrock name
eclipseisoffline Jan 18, 2025
6f67814
Make sure deprecated getExistingCustomItems method still functions
eclipseisoffline Jan 18, 2025
c1bd5fa
Data component map javadoc
eclipseisoffline Jan 18, 2025
99b01ee
Apply suggestions from code review
eclipseisoffline Jan 18, 2025
b2776a3
Forgot one
eclipseisoffline Jan 18, 2025
5ac8a24
Merge remote-tracking branch 'upstream/master' into custom-item-api-v2
eclipseisoffline Jan 18, 2025
ec9e9fc
I messed up the merge conflicts, whoops
eclipseisoffline Jan 18, 2025
d22e815
Work on component javadoc
eclipseisoffline Jan 18, 2025
4b7ef99
Some fixes
eclipseisoffline Jan 19, 2025
a0b785c
Whoops
eclipseisoffline Jan 19, 2025
92d3296
Work on changing mappings reader to Gson
eclipseisoffline Jan 19, 2025
af371b1
Update data component readers to use Gson
eclipseisoffline Jan 19, 2025
2c9596d
Mappings reader gson part 1
eclipseisoffline Jan 19, 2025
4095f89
Mappings reader gson part 2
eclipseisoffline Jan 19, 2025
a7fbcc6
Mappings reader gson part 3
eclipseisoffline Jan 19, 2025
0ae556c
Whoops almost removed v2 mappings
eclipseisoffline Jan 19, 2025
3fff601
Some fixes and stuff
eclipseisoffline Jan 19, 2025
de95eb5
Bye bye render offsets
eclipseisoffline Jan 19, 2025
215c309
Merge remote-tracking branch 'upstream/master' into custom-item-api-v2
eclipseisoffline Feb 11, 2025
97a2e99
More small fixes
eclipseisoffline Feb 11, 2025
dac6d53
Rename getExistingCustomItemDefinitions to customItemDefinitions in d…
eclipseisoffline Feb 15, 2025
3c388a7
Use API Identifiers to represent vanilla items instead of strings
eclipseisoffline Feb 15, 2025
2558ca6
Add javadocs to CustomItemDefinitionRegisterException
eclipseisoffline Feb 15, 2025
292efc6
Switch tags to identifiers
eclipseisoffline Feb 15, 2025
b3d7747
Merge remote-tracking branch 'upstream/master' into custom-item-api-v2
eclipseisoffline Feb 15, 2025
ac5c391
Switch Identifier constructors to short .of call
eclipseisoffline Feb 15, 2025
1b4fc15
Change Identifier in API to interface
eclipseisoffline Feb 15, 2025
085bb6e
Add tag(Identifier) method to bedrock options builder
eclipseisoffline Feb 15, 2025
22d7ef9
Add new creative categories
eclipseisoffline Feb 15, 2025
e709e64
Work on making predicates in API abstract
eclipseisoffline Feb 16, 2025
07cd54d
Implement predicate changes in geyser, range predicates still broken
eclipseisoffline Feb 16, 2025
5131a3d
Write javadocs for new predicate stuff in the API
eclipseisoffline Feb 16, 2025
6a8e70c
Merge remote-tracking branch 'upstream/master' into custom-item-api-v2
eclipseisoffline Feb 22, 2025
4b3e671
Fix the build™
eclipseisoffline Feb 22, 2025
a882d7f
Merge branch 'custom-item-api-v2' into api-predicates
eclipseisoffline Feb 22, 2025
573ace1
Fix the build™ v2.0: now for the fancy predicate API
eclipseisoffline Feb 22, 2025
5bcd9d9
Lazy initialise the stuff in predicate context
eclipseisoffline Feb 22, 2025
a433b91
Move item predicate context
eclipseisoffline Feb 22, 2025
4adbccb
Work on fishing_rod/cast predicate
eclipseisoffline Feb 23, 2025
d5bbccf
Work on range-dispatch predicates in the new predicate API
eclipseisoffline Mar 9, 2025
f2b1b7b
Improve some javadocs
eclipseisoffline Mar 9, 2025
81fefb9
Write more javadocs
eclipseisoffline Mar 9, 2025
7cde240
Re-implement reading range dispatch predicates from JSON mappings
eclipseisoffline Mar 9, 2025
bb2f758
Cleanup ItemMatchProperty a bit
eclipseisoffline Mar 9, 2025
6bb5575
Write some TODOs
eclipseisoffline Mar 9, 2025
4c9676e
Some fixes and docs
eclipseisoffline Mar 10, 2025
a4a1222
Merge remote-tracking branch 'upstream/master' into custom-item-api-v2
eclipseisoffline Mar 10, 2025
17fa9e3
Start working on non-vanilla custom items v2
eclipseisoffline Mar 11, 2025
63a9f8e
Implement the stuff in Geyser
eclipseisoffline Mar 11, 2025
2a3ca59
Update the define custom items event
eclipseisoffline Mar 14, 2025
33ba15d
More progress with non-vanilla custom items
eclipseisoffline Mar 14, 2025
f3db517
Implement NonVanillaCustomItemData -> definition conversion
eclipseisoffline Mar 14, 2025
c91db0c
Fix v1 mappings using the vanilla item identifier as bedrock identifier
eclipseisoffline Mar 17, 2025
109474c
Add chargeable geyser data component
eclipseisoffline Mar 17, 2025
c183b8e
Implement chargeable data component in geyser
eclipseisoffline Mar 17, 2025
ffc0481
Convert old chargeable property to new component, don't allow chargea…
eclipseisoffline Mar 17, 2025
e0c228f
Remove chargeable method from NonVanillaCustomItemDefinition, work on…
eclipseisoffline Mar 17, 2025
0efee85
Implement attack damage component
eclipseisoffline Mar 17, 2025
366d8b6
Add and implement block placer component
eclipseisoffline Mar 17, 2025
a9021d1
Update documentation
eclipseisoffline Mar 17, 2025
1dfb6c5
Merge remote-tracking branch 'upstream/master' into custom-item-api-v2
eclipseisoffline Mar 17, 2025
6bf2d0f
Write some more documentation
eclipseisoffline Mar 17, 2025
bfbca7b
Some TODOs and stuff
eclipseisoffline Mar 17, 2025
5a64c65
Merge remote-tracking branch 'upstream/master' into custom-item-api-v2
eclipseisoffline Mar 26, 2025
826e2f3
Merge remote-tracking branch 'upstream/master' into custom-item-api-v2
eclipseisoffline Mar 29, 2025
306c3ea
Merge remote-tracking branch 'upstream/master' into custom-item-api-v2
eclipseisoffline Apr 6, 2025
6218884
Reintroduce player place null check in BlockPlaceMixin
eclipseisoffline Apr 7, 2025
c510204
Merge branch 'block-item-mixin-fix' into custom-item-api-v2
eclipseisoffline Apr 7, 2025
dd9cc61
Make it build
eclipseisoffline Apr 8, 2025
1b0d3f6
Support new equipment slots
eclipseisoffline Apr 8, 2025
8641196
Introduce component converter for tool component and use in custom it…
eclipseisoffline Apr 8, 2025
ab9d645
Merge branch 'custom-item-api-v2' into api-predicates
eclipseisoffline Apr 20, 2025
9fcc8eb
Random stuff to make it build
eclipseisoffline Apr 20, 2025
cfdde40
Some cleanups
eclipseisoffline Apr 20, 2025
d84856e
Predicate conflict detection is back, sort of, by using a bunch of re…
eclipseisoffline Apr 20, 2025
1eb4caa
Add back fishing rod cast predicate
eclipseisoffline Apr 22, 2025
9df0a35
Merge remote-tracking branch 'upstream/master' into custom-item-api-v2
eclipseisoffline May 6, 2025
dcff4ec
Implement removing of default vanilla item components
eclipseisoffline May 5, 2025
baed6cf
Fix the build
eclipseisoffline May 6, 2025
4e55579
Merge remote-tracking branch 'upstream/master' into custom-item-api-v2
eclipseisoffline May 9, 2025
d004a13
Allow 0 values for max draw duration in chargeable component
eclipseisoffline May 9, 2025
aa3e0bd
Fix applying component removals to custom items
eclipseisoffline May 11, 2025
2a2738b
Allow overriding vanilla models if the model is not used by the vanil…
eclipseisoffline May 11, 2025
d5a1f22
Some small changes
eclipseisoffline May 13, 2025
7887ba9
Some more small changes
eclipseisoffline May 13, 2025
9dafa6c
Merge branch 'custom-item-api-v2' into api-predicates
eclipseisoffline May 13, 2025
78a2aa4
Range dispatch predicate sorting and comments/documentation
eclipseisoffline May 13, 2025
90c883d
More javadocs
eclipseisoffline May 13, 2025
da6f859
Merge pull request #2 from eclipseisoffline/api-predicates
eclipseisoffline May 13, 2025
17bfcf9
Some more comments
eclipseisoffline May 13, 2025
45a6a7e
Add back enchantment glint override component
eclipseisoffline May 13, 2025
1ce84cd
Add enchantment_glint_override component reader
eclipseisoffline May 16, 2025
1e3ce1e
Give custom items a breaking speed of 1
eclipseisoffline May 16, 2025
4eab395
Add useBlockIcon property
eclipseisoffline May 17, 2025
b035ae2
Merge remote-tracking branch 'upstream/master' into custom-item-api-v2
eclipseisoffline May 17, 2025
9b6be61
Some clarifying comments
eclipseisoffline May 17, 2025
6ddad6d
Allow null values for cooldown group in use cooldown component
eclipseisoffline May 19, 2025
c28ee88
I worked on this in 2025 too
eclipseisoffline May 19, 2025
33f4247
Merge remote-tracking branch 'upstream/master' into custom-item-api-v2
eclipseisoffline Jun 17, 2025
2f41ae9
Merge remote-tracking branch 'upstream/master' into custom-item-api-v2
eclipseisoffline Jun 17, 2025
9638f82
Merge remote-tracking branch 'upstream/master' into custom-item-api-v2
eclipseisoffline Jun 26, 2025
5a85f52
Let it build
eclipseisoffline Jun 26, 2025
6d25f4f
Use the right mappings
eclipseisoffline Jun 26, 2025
f9a4467
Component Javadocs and interfaces (#3)
onebeastchris Jun 29, 2025
1d234d9
Start on extended tool properties component, API is done
eclipseisoffline Jun 29, 2025
c587673
Work on resolvable components/session based components
eclipseisoffline Jun 29, 2025
49a303f
Create CustomItemContext record
eclipseisoffline Jun 29, 2025
bdc9279
Fix build, actually create resolvable tool properties component
eclipseisoffline Jun 29, 2025
a2ab1bb
Make it run
eclipseisoffline Jun 29, 2025
7fec9df
Register Holders builder API
eclipseisoffline Jun 29, 2025
f764bed
Only store ComponentCache for item stacks, debug statements
eclipseisoffline Jun 29, 2025
e0fd201
Fix build
eclipseisoffline Jun 29, 2025
d2db5af
Null-safety for component cache
eclipseisoffline Jul 1, 2025
94ddb38
Fix looking up block IDs by key
eclipseisoffline Jul 1, 2025
502396b
Merge remote-tracking branch 'upstream/master' into custom-item-api-v2
eclipseisoffline Jul 1, 2025
69d93ff
Javadocs and minor API changes
eclipseisoffline Jul 1, 2025
eeaf827
Proper Repairable component
eclipseisoffline Jul 1, 2025
b622ad1
Fix repairable reader
eclipseisoffline Jul 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@

import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.event.Event;
import org.geysermc.geyser.api.exception.CustomItemDefinitionRegisterException;
import org.geysermc.geyser.api.item.custom.CustomItemData;
import org.geysermc.geyser.api.item.custom.NonVanillaCustomItemData;
import org.geysermc.geyser.api.item.custom.v2.CustomItemDefinition;
import org.geysermc.geyser.api.item.custom.v2.NonVanillaCustomItemDefinition;
import org.geysermc.geyser.api.util.Identifier;

import java.util.Collection;
import java.util.List;
Expand All @@ -40,37 +44,77 @@
* This event will not be called if the "add non-Bedrock items" setting is disabled in the Geyser config.
*/
public interface GeyserDefineCustomItemsEvent extends Event {

/**
* Gets a multimap of all the already registered custom items indexed by the item's extended java item's identifier.
* A multimap of all the already registered (using the deprecated method) custom items indexed by the item's extended java item's identifier.
*
* @return a multimap of all the already registered custom items
* @deprecated use {@link GeyserDefineCustomItemsEvent#customItemDefinitions()}
*/
@Deprecated
@NonNull
Map<String, Collection<CustomItemData>> getExistingCustomItems();

/**
* Gets the list of the already registered non-vanilla custom items.
* A multimap of all the already registered custom item definitions indexed by the item's extended java item's identifier.
*/
@NonNull
Map<Identifier, Collection<CustomItemDefinition>> customItemDefinitions();

/**
* A list of the already registered (using the deprecated method) non-vanilla custom items.
*
* @return the list of the already registered non-vanilla custom items
* @deprecated use {@link GeyserDefineCustomItemsEvent#nonVanillaCustomItemDefinitions()}
*/
@Deprecated
@NonNull
List<NonVanillaCustomItemData> getExistingNonVanillaCustomItems();

/**
* A multimap of all the already registered non-vanilla custom items indexed by the item's extended java item's identifier.
*
* <p>This multimap will, at the moment, always have one entry per key.</p>
*/
@NonNull
Map<Identifier, Collection<NonVanillaCustomItemDefinition>> nonVanillaCustomItemDefinitions();

/**
* Registers a custom item with a base Java item. This is used to register items with custom textures and properties
* based on NBT data.
* based on NBT data. This method should not be used anymore, {@link CustomItemDefinition}s are preferred now and this method will convert {@link CustomItemData} to {@link CustomItemDefinition} internally.
*
* @deprecated use {@link GeyserDefineCustomItemsEvent#register(Identifier, CustomItemDefinition)}
* @param identifier the base (java) item
* @param customItemData the custom item data to register
* @return if the item was registered
*/
@Deprecated
boolean register(@NonNull String identifier, @NonNull CustomItemData customItemData);

/**
* Registers a custom item with a base Java item. This is used to register items with custom textures and properties
* based on NBT data.
*
* @param identifier of the Java edition base item
* @param customItemDefinition the custom item definition to register
* @throws CustomItemDefinitionRegisterException when an error occurred while registering the item
*/
void register(@NonNull Identifier identifier, @NonNull CustomItemDefinition customItemDefinition) throws CustomItemDefinitionRegisterException;

/**
* Registers a custom item with no base item. This is used for mods.
* This method should not be used anymore, {@link NonVanillaCustomItemDefinition}s are preferred now and this method will convert {@link NonVanillaCustomItemData} to {@link NonVanillaCustomItemDefinition} internally.
*
* @deprecated use {@link GeyserDefineCustomItemsEvent#register(NonVanillaCustomItemDefinition)}
* @param customItemData the custom item data to register
* @return if the item was registered
*/
@Deprecated
boolean register(@NonNull NonVanillaCustomItemData customItemData);
}

/**
* Registers a custom item with no base item. This is used for mods.
*
* @param customItemDefinition the custom item definition to register
* @throws CustomItemDefinitionRegisterException when an error occurred while registering the item
*/
void register(@NonNull NonVanillaCustomItemDefinition customItemDefinition) throws CustomItemDefinitionRegisterException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2025 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/

package org.geysermc.geyser.api.exception;

/**
* Thrown when there was an error registering the custom item definition. The exception message will have details as to what went wrong.
*/
public class CustomItemDefinitionRegisterException extends Exception {

public CustomItemDefinitionRegisterException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,24 @@
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.api.GeyserApi;
import org.geysermc.geyser.api.item.custom.v2.CustomItemBedrockOptions;
import org.geysermc.geyser.api.item.custom.v2.CustomItemDefinition;
import org.geysermc.geyser.api.predicate.item.ItemConditionPredicate;
import org.geysermc.geyser.api.predicate.item.ItemRangeDispatchPredicate;
import org.geysermc.geyser.api.util.CreativeCategory;
import org.geysermc.geyser.api.util.Identifier;
import org.geysermc.geyser.api.util.TriState;

import java.util.OptionalInt;
import java.util.Set;
import java.util.stream.Collectors;

/**
* This is used to store data for a custom item.
*
* @deprecated use the new {@link org.geysermc.geyser.api.item.custom.v2.CustomItemDefinition}
*/
@Deprecated
public interface CustomItemData {
/**
* Gets the item's name.
Expand Down Expand Up @@ -118,6 +129,35 @@ static CustomItemData.Builder builder() {
return GeyserApi.api().provider(CustomItemData.Builder.class);
}

default CustomItemDefinition.Builder toDefinition(Identifier javaItem) {
CustomItemDefinition.Builder definition = CustomItemDefinition.builder(Identifier.of("geyser_custom", name()), javaItem)
.displayName(displayName())
.bedrockOptions(CustomItemBedrockOptions.builder()
.icon(icon())
.allowOffhand(allowOffhand())
.displayHandheld(displayHandheld())
.creativeCategory(creativeCategory().isEmpty() ? CreativeCategory.NONE : CreativeCategory.values()[creativeCategory().getAsInt()])
.creativeGroup(creativeGroup())
.tags(tags().stream().map(Identifier::of).collect(Collectors.toSet()))
);

CustomItemOptions options = customItemOptions();
if (options.customModelData().isPresent()) {
definition.predicate(ItemRangeDispatchPredicate.LEGACY_CUSTOM_MODEL_DATA.create(options.customModelData().getAsInt()));
}
if (options.damagePredicate().isPresent()) {
definition.predicate(ItemRangeDispatchPredicate.DAMAGE.create(options.damagePredicate().getAsInt()));
}
if (options.unbreakable() != TriState.NOT_SET) {
if (options.unbreakable() == TriState.TRUE) {
definition.predicate(ItemConditionPredicate.UNBREAKABLE);
} else {
definition.predicate(ItemConditionPredicate.UNBREAKABLE.negate());
}
}
return definition;
}

interface Builder {
/**
* Will also set the display name and icon to the provided parameter, if it is currently not set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@

/**
* This class represents the different ways you can register custom items
*
* @deprecated use the new {@link org.geysermc.geyser.api.item.custom.v2.CustomItemDefinition}.
*/
@Deprecated
public interface CustomItemOptions {
/**
* Gets if the item should be unbreakable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,28 @@
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.api.GeyserApi;
import org.geysermc.geyser.api.item.custom.v2.CustomItemBedrockOptions;
import org.geysermc.geyser.api.item.custom.v2.CustomItemDefinition;
import org.geysermc.geyser.api.item.custom.v2.NonVanillaCustomItemDefinition;
import org.geysermc.geyser.api.item.custom.v2.component.BlockPlacer;
import org.geysermc.geyser.api.item.custom.v2.component.Chargeable;
import org.geysermc.geyser.api.item.custom.v2.component.Consumable;
import org.geysermc.geyser.api.item.custom.v2.component.DataComponent;
import org.geysermc.geyser.api.item.custom.v2.component.Equippable;
import org.geysermc.geyser.api.item.custom.v2.component.FoodProperties;
import org.geysermc.geyser.api.item.custom.v2.component.GeyserDataComponent;
import org.geysermc.geyser.api.util.CreativeCategory;
import org.geysermc.geyser.api.util.Identifier;

import java.util.Set;
import java.util.stream.Collectors;

/**
* Represents a completely custom item that is not based on an existing vanilla Minecraft item.
*
* @deprecated use the new {@link org.geysermc.geyser.api.item.custom.v2.NonVanillaCustomItemDefinition}
*/
@Deprecated
public interface NonVanillaCustomItemData extends CustomItemData {
/**
* Gets the java identifier for this item.
Expand Down Expand Up @@ -170,6 +186,61 @@ static NonVanillaCustomItemData.Builder builder() {
return GeyserApi.api().provider(NonVanillaCustomItemData.Builder.class);
}

@Override
default CustomItemDefinition.Builder toDefinition(Identifier javaItem) {
throw new UnsupportedOperationException("Use toDefinition()");
}

default NonVanillaCustomItemDefinition.Builder toDefinition() {
NonVanillaCustomItemDefinition.Builder definition = NonVanillaCustomItemDefinition.builder(Identifier.of(identifier()), javaId())
.displayName(displayName())
.bedrockOptions(CustomItemBedrockOptions.builder()
.icon(icon())
.allowOffhand(allowOffhand())
.displayHandheld(displayHandheld())
.creativeCategory(creativeCategory().isEmpty() ? CreativeCategory.NONE : CreativeCategory.values()[creativeCategory().getAsInt()])
.creativeGroup(creativeGroup())
.tags(tags().stream().map(Identifier::of).collect(Collectors.toSet()))
.protectionValue(protectionValue())
)
.component(DataComponent.MAX_STACK_SIZE, stackSize())
.component(DataComponent.MAX_DAMAGE, maxDamage())
.component(GeyserDataComponent.ATTACK_DAMAGE, attackDamage())
.translationString(translationString());

if (isHat()) {
definition.component(DataComponent.EQUIPPABLE, new Equippable(Equippable.EquipmentSlot.HEAD));
} else if (armorType() != null) {
switch (armorType()) {
case "helmet" -> definition.component(DataComponent.EQUIPPABLE, new Equippable(Equippable.EquipmentSlot.HEAD));
case "chestplate" -> definition.component(DataComponent.EQUIPPABLE, new Equippable(Equippable.EquipmentSlot.CHEST));
case "leggings" -> definition.component(DataComponent.EQUIPPABLE, new Equippable(Equippable.EquipmentSlot.LEGS));
case "boots" -> definition.component(DataComponent.EQUIPPABLE, new Equippable(Equippable.EquipmentSlot.FEET));
}
}

if (isEdible()) {
definition.component(DataComponent.CONSUMABLE, new Consumable(1.6F, Consumable.Animation.EAT)); // Default values
if (canAlwaysEat()) {
definition.component(DataComponent.FOOD, new FoodProperties(0, 0, true));
}
}

if (isChargeable() && toolType() != null) {
if (toolType().equals("bow")) {
definition.component(GeyserDataComponent.CHARGEABLE, new Chargeable(1.0F, true, Identifier.of("arrow")));
} else {
definition.component(GeyserDataComponent.CHARGEABLE, new Chargeable(0.0F, false, Identifier.of("arrow")));
}
}

if (block() != null) {
definition.component(GeyserDataComponent.BLOCK_PLACER, new BlockPlacer(Identifier.of(block()), false));
}

return definition;
}

interface Builder extends CustomItemData.Builder {
@Override
Builder name(@NonNull String name);
Expand Down
Loading