|
7 | 7 |
|
8 | 8 | package net.elytrium.limboapi.api.protocol.data; |
9 | 9 |
|
| 10 | +import com.velocitypowered.api.network.ProtocolVersion; |
| 11 | +import net.elytrium.limboapi.api.world.WorldVersion; |
| 12 | +import net.elytrium.limboapi.api.world.item.VirtualItem; |
10 | 13 | import net.elytrium.limboapi.api.world.item.datacomponent.DataComponentMap; |
11 | 14 | import net.elytrium.limboapi.api.world.item.datacomponent.DataComponentTypes; |
12 | 15 | import net.kyori.adventure.nbt.CompoundBinaryTag; |
13 | 16 | import org.checkerframework.checker.nullness.qual.Nullable; |
14 | 17 |
|
15 | | -public record ItemStack(int material/*TODO VirtualItem*/, int amount, int data, @Nullable CompoundBinaryTag nbt, @Nullable DataComponentMap map) implements EntityData.Particle.ParticleOptions { |
| 18 | +public record ItemStack(VirtualItem material, int amount, int data, @Nullable CompoundBinaryTag nbt, @Nullable DataComponentMap map) implements EntityData.Particle.ParticleOptions { |
16 | 19 |
|
17 | | - public static final ItemStack EMPTY = new ItemStack(-1, 0, 0, null, null); |
| 20 | + public static final ItemStack EMPTY = new ItemStack(null, 0, 0, null, null); |
18 | 21 |
|
19 | | - public ItemStack(int material, int amount, @Nullable CompoundBinaryTag nbt) { |
| 22 | + public ItemStack(VirtualItem material, int amount, @Nullable CompoundBinaryTag nbt) { |
20 | 23 | this(material, amount, nbt == null ? 0 : nbt.getInt("Damage", 0), nbt, null); |
21 | 24 | } |
22 | 25 |
|
23 | | - public ItemStack(int material, int amount, @Nullable DataComponentMap map) { |
| 26 | + public ItemStack(VirtualItem material, int amount, @Nullable DataComponentMap map) { |
24 | 27 | this(material, amount, map == null ? 0 : map.getDataOrDefault(DataComponentTypes.DAMAGE, 0), map); |
25 | 28 | } |
26 | 29 |
|
27 | | - public ItemStack(int material, int amount, int data) { |
| 30 | + public ItemStack(VirtualItem material, int amount, int data) { |
28 | 31 | this(material, amount, data, null, null); |
29 | 32 | } |
30 | 33 |
|
31 | | - public ItemStack(int material, int amount, int data, @Nullable CompoundBinaryTag nbt) { |
| 34 | + public ItemStack(VirtualItem material, int amount, int data, @Nullable CompoundBinaryTag nbt) { |
32 | 35 | this(material, amount, data, nbt, null); |
33 | 36 | } |
34 | 37 |
|
35 | | - public ItemStack(int material, int amount, int data, @Nullable DataComponentMap map) { |
| 38 | + public ItemStack(VirtualItem material, int amount, int data, @Nullable DataComponentMap map) { |
36 | 39 | this(material, amount, data, null, map); |
37 | 40 | } |
38 | 41 |
|
39 | | - public boolean isEmpty(boolean checkDamage) { |
40 | | - return this == ItemStack.EMPTY || this.material <= 0 || this.amount <= 0 || (checkDamage && (this.data < -32768 || this.data > 65535)); |
| 42 | + public boolean isEmpty(ProtocolVersion version, boolean checkDamage) { |
| 43 | + return this.isEmpty(WorldVersion.from(version), checkDamage); |
| 44 | + } |
| 45 | + |
| 46 | + public boolean isEmpty(WorldVersion version, boolean checkDamage) { |
| 47 | + return this == ItemStack.EMPTY || this.material.itemId(version) <= 0 || this.amount <= 0 || (checkDamage && (this.data < -32768 || this.data > 65535)); |
41 | 48 | } |
42 | 49 | } |
0 commit comments