dev.polymodloader.api.content.item
This page is generated from the source's Javadoc by ./gradlew apiReference. Do not edit it; fix the source comment and generate it again.
| Type | Kind | Description |
|---|---|---|
ComponentType | class | The value type of an ItemComponentKey. |
FoodDefinition | record | Makes an item edible. |
ItemBehavior | interface | Code that runs when a mod item is used. |
ItemComponentKey | record | A data component that mods attach to item stacks, such as a charge level or an owner's name. |
ItemDefinition | record | Properties of a mod item or block item. |
ItemDefinition.Builder | class | Builds an ItemDefinition. |
ItemHandle | interface | A declared item. |
ItemRarity | enum | Name colour of an item. |
ItemUse | record | A player using (right-clicking) a mod item in the air. |
ComponentType
class · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier
public final class ComponentType<T>
The value type of an ItemComponentKey.
| Constant or field | Type | Description |
|---|---|---|
INTEGER | ComponentType<Integer> | A whole number. |
BOOLEAN | ComponentType<Boolean> | true or false. |
STRING | ComponentType<String> | Text. |
TREE | ComponentType<DataTree> | A DataTree; stored and returned as copies. |
valueClass()
public Class<T> valueClass()
Since 0.1.0-alpha.4 or earlier
Java type of the value.
Returns Class<T>
FoodDefinition
record · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier
public record FoodDefinition(int nutrition, float saturation, boolean alwaysEdible)
Makes an item edible.
| Component | Type | Description |
|---|---|---|
nutrition | int | hunger points restored (bread: 5) |
saturation | float | saturation modifier (bread: 0.6) |
alwaysEdible | boolean | whether it can be eaten with a full hunger bar |
ItemBehavior
interface · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier
public interface ItemBehavior
Code that runs when a mod item is used. Same thread and failure rules as BlockBehavior.
onUse(ItemUse)
default InteractionResult onUse(ItemUse use)
Since 0.1.0-alpha.4 or earlier
The item was used in the air. Returning InteractionResult.PASS keeps the game's default (for example eating, for food items).
| Parameter | Type | Description |
|---|---|---|
use | ItemUse | — |
Returns InteractionResult
ItemComponentKey
record · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier
public record ItemComponentKey<T>(ResourceId id, ComponentType<T> type)
A data component that mods attach to item stacks, such as a charge level or an owner's name. The value is saved with the stack, copied with it, shown in /give syntax as <id>=<value>, and synchronised to clients. Stacks with different values do not stack. Obtain keys from ContentRegistrar.itemComponent.
| Component | Type | Description |
|---|---|---|
id | ResourceId | component ID, <mod id>:<path> |
type | ComponentType<T> | value type |
ItemDefinition
record · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier
public record ItemDefinition(int maxStackSize, int durability, boolean fireResistant, ItemRarity rarity, Optional<FoodDefinition> food, Optional<CreativeTab> creativeTab, ItemBehavior behavior)
Properties of a mod item or block item. Created with builder(); immutable.
| Component | Type | Description |
|---|---|---|
maxStackSize | int | 1–99; items with durability always stack to 1 |
durability | int | uses before breaking, 0 for none |
fireResistant | boolean | whether the dropped item survives fire and lava |
rarity | ItemRarity | name colour |
food | Optional<FoodDefinition> | what eating it does, or empty when it is not food |
creativeTab | Optional<CreativeTab> | creative inventory tab to list it in, or empty |
behavior | ItemBehavior | use callbacks; ignored for block items |
builder()
public static ItemDefinition.Builder builder()
Since 0.1.0-alpha.4 or earlier
A builder for a common item stacking to 64, listed in no tab.
Returns ItemDefinition.Builder
ItemDefinition.Builder
class · Since 0.1.0-alpha.4 or earlier
public static final class Builder
Builds an ItemDefinition.
maxStackSize(int)
public ItemDefinition.Builder maxStackSize(int maxStackSize)
Since 0.1.0-alpha.4 or earlier
Sets the maximum stack size, 1–99.
| Parameter | Type | Description |
|---|---|---|
maxStackSize | int | — |
Returns ItemDefinition.Builder
durability(int)
public ItemDefinition.Builder durability(int durability)
Since 0.1.0-alpha.4 or earlier
Gives the item durability; also sets the stack size to 1.
| Parameter | Type | Description |
|---|---|---|
durability | int | — |
Returns ItemDefinition.Builder
fireResistant()
public ItemDefinition.Builder fireResistant()
Since 0.1.0-alpha.4 or earlier
The dropped item survives fire and lava.
Returns ItemDefinition.Builder
rarity(ItemRarity)
public ItemDefinition.Builder rarity(ItemRarity rarity)
Since 0.1.0-alpha.4 or earlier
Sets the name colour.
| Parameter | Type | Description |
|---|---|---|
rarity | ItemRarity | — |
Returns ItemDefinition.Builder
food(FoodDefinition)
public ItemDefinition.Builder food(FoodDefinition food)
Since 0.1.0-alpha.4 or earlier
Makes the item edible.
| Parameter | Type | Description |
|---|---|---|
food | FoodDefinition | — |
Returns ItemDefinition.Builder
creativeTab(CreativeTab)
public ItemDefinition.Builder creativeTab(CreativeTab tab)
Since 0.1.0-alpha.4 or earlier
Lists the item at the end of a creative inventory tab.
| Parameter | Type | Description |
|---|---|---|
tab | CreativeTab | — |
Returns ItemDefinition.Builder
behavior(ItemBehavior)
public ItemDefinition.Builder behavior(ItemBehavior behavior)
Since 0.1.0-alpha.4 or earlier
Sets the use callbacks.
| Parameter | Type | Description |
|---|---|---|
behavior | ItemBehavior | — |
Returns ItemDefinition.Builder
build()
public ItemDefinition build()
Since 0.1.0-alpha.4 or earlier
Creates the definition; invalid values throw IllegalArgumentException.
Returns ItemDefinition
ItemHandle
interface · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier
public interface ItemHandle extends ContentHandle
A declared item.
Supertypes: ContentHandle
ItemRarity
enum · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier
public enum ItemRarity
Name colour of an item.
| Constant | Description |
|---|---|
COMMON | — |
UNCOMMON | — |
RARE | — |
EPIC | — |
ItemUse
record · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier
public record ItemUse(WorldView world, PlayerView player, ItemStackRef stack)
A player using (right-clicking) a mod item in the air.
| Component | Type | Description |
|---|---|---|
world | WorldView | the world, client or server copy |
player | PlayerView | the player holding the item |
stack | ItemStackRef | the used stack, live |