Items & Food
Creare un Item Base
```java public static final Item RAW_RUBY = new Item( new Item.Settings().fireproof() // Non brucia nella lava ); ```
Cibo (Food Components)
Per rendere un oggetto commestibile, devi aggiungere un FoodComponent.
```java public static final FoodComponent TOMATO_COMPONENT = new FoodComponent.Builder() .hunger(4) // 2 cosce piene .saturationModifier(0.3f) // Quanto a lungo dura la sazietà .snack() // Si mangia velocemente (come le bacche) .alwaysEdible() // Si può mangiare anche se sazi .statusEffect(new StatusEffectInstance(StatusEffects.SPEED, 20*10), 0.5f) // 50% chance di Speed .build();
public static final Item TOMATO = new Item(new Item.Settings().food(TOMATO_COMPONENT)); ```
Strumenti (Tools)
Per creare picconi, asce o spade, devi definire un ToolMaterial.
- Crea una classe/enum che implementa
ToolMaterial. - Definisci durabilità, velocità, livello di scavo e ingrediente di riparazione.
```java public class RubyToolMaterial implements ToolMaterial { // … implementazione metodi … @Override public int getDurability() { return 500; } // … }
public static final Item RUBY_PICKAXE = new PickaxeItem( new RubyToolMaterial(), 1, // Attack damage -2.8f, // Attack speed new Item.Settings() ); ```
Armature (Armor)
Simile agli strumenti, serve un ArmorMaterial.
Definisce la protezione per ogni pezzo (elmo, petto, ecc.), la durabilità, l’incantabilità e il suono di equipaggiamento.
```java public static final Item RUBY_CHESTPLATE = new ArmorItem( ModArmorMaterials.RUBY, ArmorItem.Type.CHESTPLATE, new Item.Settings() ); ```