Skip to content

Commit 91a38cd

Browse files
committed
Finish more item data component API
1 parent c1f5409 commit 91a38cd

18 files changed

+328
-164
lines changed

paper-api/src/main/java/io/papermc/paper/datacomponent/DataComponentTypes.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.papermc.paper.datacomponent.item.BannerPatternLayers;
44
import io.papermc.paper.datacomponent.item.BlockItemDataProperties;
5+
import io.papermc.paper.datacomponent.item.BlocksAttacks;
56
import io.papermc.paper.datacomponent.item.BundleContents;
67
import io.papermc.paper.datacomponent.item.ChargedProjectiles;
78
import io.papermc.paper.datacomponent.item.Consumable;
@@ -32,9 +33,10 @@
3233
import io.papermc.paper.datacomponent.item.SeededContainerLoot;
3334
import io.papermc.paper.datacomponent.item.SuspiciousStewEffects;
3435
import io.papermc.paper.datacomponent.item.Tool;
35-
import io.papermc.paper.datacomponent.item.Unbreakable;
36+
import io.papermc.paper.datacomponent.item.TooltipDisplay;
3637
import io.papermc.paper.datacomponent.item.UseCooldown;
3738
import io.papermc.paper.datacomponent.item.UseRemainder;
39+
import io.papermc.paper.datacomponent.item.Weapon;
3840
import io.papermc.paper.datacomponent.item.WritableBookContent;
3941
import io.papermc.paper.datacomponent.item.WrittenBookContent;
4042
import io.papermc.paper.item.MapPostProcessing;
@@ -58,7 +60,6 @@
5860
import org.bukkit.entity.Horse;
5961
import org.bukkit.entity.Llama;
6062
import org.bukkit.entity.MushroomCow;
61-
import org.bukkit.entity.Painting;
6263
import org.bukkit.entity.Parrot;
6364
import org.bukkit.entity.Pig;
6465
import org.bukkit.entity.Rabbit;
@@ -109,7 +110,7 @@ public final class DataComponentTypes {
109110
/**
110111
* If set, the item will not lose any durability when used.
111112
*/
112-
public static final DataComponentType.Valued<Unbreakable> UNBREAKABLE = valued("unbreakable");
113+
public static final DataComponentType.NonValued UNBREAKABLE = unvalued("unbreakable");
113114
/**
114115
* Custom name override for an item (as set by renaming with an Anvil).
115116
*
@@ -165,6 +166,7 @@ public final class DataComponentTypes {
165166
* Controls the minecraft:custom_model_data property in the item model.
166167
*/
167168
public static final DataComponentType.Valued<CustomModelData> CUSTOM_MODEL_DATA = valued("custom_model_data");
169+
public static final DataComponentType.Valued<TooltipDisplay> TOOLTIP_DISPLAY = valued("tooltip_display");
168170
/**
169171
* The additional experience cost required to modify an item in an Anvil.
170172
* If not present, has an implicit default value of: {@code 0}.
@@ -200,12 +202,14 @@ public final class DataComponentTypes {
200202
* Controls the behavior of the item as a tool.
201203
*/
202204
public static final DataComponentType.Valued<Tool> TOOL = valued("tool");
205+
public static final DataComponentType.Valued<Weapon> WEAPON = valued("weapon");
203206
public static final DataComponentType.Valued<Enchantable> ENCHANTABLE = valued("enchantable");
204207
public static final DataComponentType.Valued<Equippable> EQUIPPABLE = valued("equippable");
205208
public static final DataComponentType.Valued<Repairable> REPAIRABLE = valued("repairable");
206209
public static final DataComponentType.NonValued GLIDER = unvalued("glider");
207210
public static final DataComponentType.Valued<Key> TOOLTIP_STYLE = valued("tooltip_style");
208211
public static final DataComponentType.Valued<DeathProtection> DEATH_PROTECTION = valued("death_protection");
212+
public static final DataComponentType.Valued<BlocksAttacks> BLOCKS_ATTACKS = valued("blocks_attacks");
209213
/**
210214
* Stores list of enchantments and their levels for an Enchanted Book.
211215
* Unlike {@link #ENCHANTMENTS}, the effects provided by enchantments

paper-api/src/main/java/io/papermc/paper/datacomponent/item/BlocksAttacks.java

+13-11
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,30 @@
88
import org.jetbrains.annotations.Contract;
99
import org.jetbrains.annotations.Nullable;
1010

11+
// TODO
1112
public interface BlocksAttacks {
1213

1314
@Contract(value = "-> new", pure = true)
1415
static Builder blocksAttacks() {
16+
return ItemComponentTypesBridge.bridge().blocksAttacks();
1517
}
1618

1719
float blockDelaySeconds();
1820

1921
float disableCooldownScale();
2022

21-
List<DamageReduction> damageReductions();
23+
//List<DamageReduction> damageReductions();
2224

23-
ItemDamageFunction itemDamage();
25+
//ItemDamageFunction itemDamage();
2426

2527
@Nullable
2628
TagKey<DamageType> bypassedBy();
2729

2830
@Nullable
29-
TagKey<DamageType> blockSound();
31+
Key blockSound();
3032

3133
@Nullable
32-
TagKey<DamageType> disableSound();
34+
Key disableSound();
3335

3436
/**
3537
* Builder for {@link BlocksAttacks}.
@@ -44,14 +46,14 @@ interface Builder extends DataComponentBuilder<BlocksAttacks> {
4446
@Contract(value = "_ -> this", mutates = "this")
4547
Builder disableCooldownScale(float scale);
4648

47-
@Contract(value = "_ -> this", mutates = "this")
48-
Builder addDamageReduction(DamageReduction reduction);
49+
//@Contract(value = "_ -> this", mutates = "this")
50+
//Builder addDamageReduction(DamageReduction reduction);
4951

50-
@Contract(value = "_ -> this", mutates = "this")
51-
Builder damageReductions(List<DamageReduction> reductions);
52+
//@Contract(value = "_ -> this", mutates = "this")
53+
//Builder damageReductions(List<DamageReduction> reductions);
5254

53-
@Contract(value = "_ -> this", mutates = "this")
54-
Builder itemDamage(ItemDamageFunction function);
55+
//@Contract(value = "_ -> this", mutates = "this")
56+
//Builder itemDamage(ItemDamageFunction function);
5557

5658
@Contract(value = "_ -> this", mutates = "this")
5759
Builder bypassedBy(@Nullable TagKey<DamageType> bypassedBy);
@@ -63,4 +65,4 @@ interface Builder extends DataComponentBuilder<BlocksAttacks> {
6365
Builder disableSound(@Nullable Key sound);
6466

6567
}
66-
}
68+
}

paper-api/src/main/java/io/papermc/paper/datacomponent/item/ItemComponentTypesBridge.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ static ItemComponentTypesBridge bridge() {
3434

3535
PotDecorations.Builder potDecorations();
3636

37-
Unbreakable.Builder unbreakable();
38-
3937
ItemLore.Builder lore();
4038

4139
ItemEnchantments.Builder enchantments();
@@ -109,4 +107,10 @@ static ItemComponentTypesBridge bridge() {
109107
DeathProtection.Builder deathProtection();
110108

111109
OminousBottleAmplifier ominousBottleAmplifier(int amplifier);
110+
111+
BlocksAttacks.Builder blocksAttacks();
112+
113+
TooltipDisplay.Builder tooltipDisplay();
114+
115+
Weapon.Builder weapon();
112116
}

paper-api/src/main/java/io/papermc/paper/datacomponent/item/Tool.java

+18
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ static Rule rule(final RegistryKeySet<BlockType> blocks, final @Nullable Float s
7171
@Contract(pure = true)
7272
@Unmodifiable List<Tool.Rule> rules();
7373

74+
/**
75+
* Whether this tool can destroy blocks in creative mode.
76+
*
77+
* @return whether this tool can destroy blocks in creative mode
78+
*/
79+
@Contract(pure = true)
80+
boolean canDestroyBlocksInCreative();
81+
7482
@ApiStatus.Experimental
7583
@ApiStatus.NonExtendable
7684
interface Rule {
@@ -136,6 +144,16 @@ interface Builder extends DataComponentBuilder<Tool> {
136144
@Contract(value = "_ -> this", mutates = "this")
137145
Builder addRule(Rule rule);
138146

147+
/**
148+
* Controls whether this tool can destroy blocks in creative mode.
149+
*
150+
* @param canDestroyBlocksInCreative whether this tool can destroy blocks in creative mode
151+
* @return the builder for chaining
152+
* @see #canDestroyBlocksInCreative()
153+
*/
154+
@Contract(value = "_ -> this", mutates = "this")
155+
Builder canDestroyBlocksInCreative(boolean canDestroyBlocksInCreative);
156+
139157
/**
140158
* Adds rules to the tool that control the breaking speed / damage per block if matched.
141159
*

paper-api/src/main/java/io/papermc/paper/datacomponent/item/TooltipDisplay.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public interface TooltipDisplay {
2121
*/
2222
@Contract(value = "-> new", pure = true)
2323
static Builder tooltipDisplay() {
24-
// TODO:
24+
return ItemComponentTypesBridge.bridge().tooltipDisplay();
2525
}
2626

2727
boolean hideTooltip();
@@ -44,4 +44,4 @@ interface Builder extends DataComponentBuilder<TooltipDisplay> {
4444
@Contract(value = "_ -> this", mutates = "this")
4545
Builder hiddenComponents(Set<DataComponentType> components);
4646
}
47-
}
47+
}

paper-api/src/main/java/io/papermc/paper/datacomponent/item/Weapon.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public interface Weapon {
1010
* @return a builder instance.
1111
*/
1212
static Builder builder() {
13-
// TODO
13+
return ItemComponentTypesBridge.bridge().weapon();
1414
}
1515

1616
/**
@@ -44,4 +44,4 @@ interface Builder extends DataComponentBuilder<Weapon> {
4444
Builder disableBlockingForSeconds(float seconds);
4545

4646
}
47-
}
47+
}

paper-server/src/main/java/io/papermc/paper/datacomponent/DataComponentAdapters.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.papermc.paper.adventure.PaperAdventure;
44
import io.papermc.paper.datacomponent.item.PaperBannerPatternLayers;
55
import io.papermc.paper.datacomponent.item.PaperBlockItemDataProperties;
6+
import io.papermc.paper.datacomponent.item.PaperBlocksAttacks;
67
import io.papermc.paper.datacomponent.item.PaperBundleContents;
78
import io.papermc.paper.datacomponent.item.PaperChargedProjectiles;
89
import io.papermc.paper.datacomponent.item.PaperConsumable;
@@ -33,9 +34,10 @@
3334
import io.papermc.paper.datacomponent.item.PaperResolvableProfile;
3435
import io.papermc.paper.datacomponent.item.PaperSeededContainerLoot;
3536
import io.papermc.paper.datacomponent.item.PaperSuspiciousStewEffects;
36-
import io.papermc.paper.datacomponent.item.PaperUnbreakable;
37+
import io.papermc.paper.datacomponent.item.PaperTooltipDisplay;
3738
import io.papermc.paper.datacomponent.item.PaperUseCooldown;
3839
import io.papermc.paper.datacomponent.item.PaperUseRemainder;
40+
import io.papermc.paper.datacomponent.item.PaperWeapon;
3941
import io.papermc.paper.datacomponent.item.PaperWritableBookContent;
4042
import io.papermc.paper.datacomponent.item.PaperWrittenBookContent;
4143
import java.util.HashMap;
@@ -73,7 +75,7 @@ public static void bootstrap() {
7375
registerIdentity(DataComponents.MAX_STACK_SIZE);
7476
registerIdentity(DataComponents.MAX_DAMAGE);
7577
registerIdentity(DataComponents.DAMAGE);
76-
register(DataComponents.UNBREAKABLE, PaperUnbreakable::new);
78+
registerIdentity(DataComponents.POTION_DURATION_SCALE);
7779
register(DataComponents.CUSTOM_NAME, PaperAdventure::asAdventure, PaperAdventure::asVanilla);
7880
register(DataComponents.ITEM_NAME, PaperAdventure::asAdventure, PaperAdventure::asVanilla);
7981
register(DataComponents.ITEM_MODEL, PaperAdventure::asAdventure, PaperAdventure::asVanilla);
@@ -84,8 +86,6 @@ public static void bootstrap() {
8486
register(DataComponents.CAN_BREAK, PaperItemAdventurePredicate::new);
8587
register(DataComponents.ATTRIBUTE_MODIFIERS, PaperItemAttributeModifiers::new);
8688
register(DataComponents.CUSTOM_MODEL_DATA, PaperCustomModelData::new);
87-
registerUntyped(DataComponents.HIDE_ADDITIONAL_TOOLTIP);
88-
registerUntyped(DataComponents.HIDE_TOOLTIP);
8989
registerIdentity(DataComponents.REPAIR_COST);
9090
// registerUntyped(DataComponents.CREATIVE_SLOT_LOCK);
9191
registerIdentity(DataComponents.ENCHANTMENT_GLINT_OVERRIDE);
@@ -119,7 +119,7 @@ public static void bootstrap() {
119119
// entity data
120120
// bucket entity data
121121
// block entity data
122-
register(DataComponents.INSTRUMENT, CraftMusicInstrument::minecraftHolderToBukkit, CraftMusicInstrument::bukkitToMinecraftHolder);
122+
//register(DataComponents.INSTRUMENT, CraftMusicInstrument::minecraftHolderToBukkit, CraftMusicInstrument::bukkitToMinecraftHolder); // TODO
123123
register(DataComponents.OMINOUS_BOTTLE_AMPLIFIER, PaperOminousBottleAmplifier::new);
124124
register(DataComponents.JUKEBOX_PLAYABLE, PaperJukeboxPlayable::new);
125125
register(DataComponents.RECIPES,
@@ -139,6 +139,10 @@ public static void bootstrap() {
139139
// bees
140140
// register(DataComponents.LOCK, PaperLockCode::new);
141141
register(DataComponents.CONTAINER_LOOT, PaperSeededContainerLoot::new);
142+
// TODO break_sound, provides_, entity data
143+
register(DataComponents.TOOLTIP_DISPLAY, PaperTooltipDisplay::new);
144+
register(DataComponents.WEAPON, PaperWeapon::new);
145+
register(DataComponents.BLOCKS_ATTACKS, PaperBlocksAttacks::new);
142146

143147
for (final Map.Entry<ResourceKey<DataComponentType<?>>, DataComponentType<?>> componentType : BuiltInRegistries.DATA_COMPONENT_TYPE.entrySet()) {
144148
if (!ADAPTERS.containsKey(componentType.getKey())) {

paper-server/src/main/java/io/papermc/paper/datacomponent/item/ItemComponentTypesBridgesImpl.java

+15-5
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ public PotDecorations.Builder potDecorations() {
3535
return new PaperPotDecorations.BuilderImpl();
3636
}
3737

38-
@Override
39-
public Unbreakable.Builder unbreakable() {
40-
return new PaperUnbreakable.BuilderImpl();
41-
}
42-
4338
@Override
4439
public ItemLore.Builder lore() {
4540
return new PaperItemLore.BuilderImpl();
@@ -236,4 +231,19 @@ public PaperOminousBottleAmplifier ominousBottleAmplifier(final int amplifier) {
236231
new OminousBottleAmplifier(amplifier)
237232
);
238233
}
234+
235+
@Override
236+
public BlocksAttacks.Builder blocksAttacks() {
237+
return new PaperBlocksAttacks.BuilderImpl();
238+
}
239+
240+
@Override
241+
public TooltipDisplay.Builder tooltipDisplay() {
242+
return new PaperTooltipDisplay.BuilderImpl();
243+
}
244+
245+
@Override
246+
public Weapon.Builder weapon() {
247+
return new PaperWeapon.BuilderImpl();
248+
}
239249
}

0 commit comments

Comments
 (0)