|
1 | 1 | package net.modfest.scatteredshards.item; |
2 | 2 |
|
| 3 | +import net.minecraft.entity.Entity; |
3 | 4 | import net.minecraft.entity.player.PlayerEntity; |
4 | 5 | import net.minecraft.item.Item; |
5 | 6 | import net.minecraft.item.ItemStack; |
@@ -40,25 +41,17 @@ public static ItemStack createShardItem(Identifier shardId) { |
40 | 41 | } |
41 | 42 |
|
42 | 43 | @Override |
43 | | - public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) { |
44 | | - var itemStack = player.getStackInHand(hand); |
45 | | - var id = itemStack.get(ScatteredShardsContent.SHARD_ID_COMPONENT); |
| 44 | + public void inventoryTick(ItemStack itemStack, World world, Entity entity, int slot, boolean selected) { |
| 45 | + if (world.isClient || !(entity instanceof ServerPlayerEntity player) || player.isInCreativeMode()) return; |
46 | 46 |
|
47 | | - if (world.isClient) { |
48 | | - return TypedActionResult.consume(itemStack); |
49 | | - } |
50 | | - |
51 | | - itemStack.decrementUnlessCreative(1, player); |
| 47 | + Identifier id = itemStack.get(ScatteredShardsContent.SHARD_ID_COMPONENT); |
| 48 | + player.getInventory().setStack(slot, ItemStack.EMPTY); |
52 | 49 |
|
53 | 50 | ShardLibrary library = ScatteredShardsAPI.getServerLibrary(); |
54 | 51 | Optional<Shard> toCollect = library.shards().get(id); |
| 52 | + if (toCollect.isEmpty()) return; |
55 | 53 |
|
56 | | - if (toCollect.isEmpty() || !(player instanceof ServerPlayerEntity serverPlayer)) { |
57 | | - return TypedActionResult.fail(itemStack); |
58 | | - } |
59 | | - |
60 | | - ScatteredShardsAPI.triggerShardCollection(serverPlayer, id); |
61 | | - return TypedActionResult.consume(itemStack); |
| 54 | + ScatteredShardsAPI.triggerShardCollection(player, id); |
62 | 55 | } |
63 | 56 |
|
64 | 57 | @Override |
|
0 commit comments