Skip to content

Commit 468de78

Browse files
committed
fix potion consume bug, add a cosume sound
1 parent 546d050 commit 468de78

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/main/java/com/robertx22/mine_and_slash/vanilla_mc/items/SlashPotionItem.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,14 @@ public InteractionResultHolder<ItemStack> use(Level pLevel, Player p, Interactio
100100

101101
}
102102

103-
public void handlePotionRestore(Player p, ItemStack stack) {
104-
if (type.restoreResource(p, stack, this)) {
103+
public boolean handlePotionRestore(Player p, ItemStack stack) {
104+
boolean b = type.restoreResource(p, stack, this);
105+
if (b) {
105106
type.getSameTypePotions().forEach(x -> p.getCooldowns().addCooldown(x, getCooldownTicks()));
106107
SoundUtils.playSound(p, SoundEvents.GENERIC_DRINK);
107108
stack.shrink(1);
108109
}
110+
return b;
109111
}
110112

111113
public int getCooldownTicks() {

src/main/java/com/robertx22/mine_and_slash/vanilla_mc/packets/QuickUsePotionPacket.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
import com.robertx22.library_of_exile.main.MyPacket;
44
import com.robertx22.library_of_exile.packets.ExilePacketContext;
5+
import com.robertx22.library_of_exile.utils.SoundUtils;
56
import com.robertx22.mine_and_slash.mmorpg.SlashRef;
67
import com.robertx22.mine_and_slash.vanilla_mc.items.SlashPotionItem;
78
import net.minecraft.network.FriendlyByteBuf;
89
import net.minecraft.resources.ResourceLocation;
910
import net.minecraft.server.level.ServerPlayer;
11+
import net.minecraft.sounds.SoundEvents;
1012
import net.minecraft.world.entity.player.Player;
1113
import net.minecraft.world.inventory.Slot;
1214
import net.minecraft.world.item.ItemStack;
@@ -45,7 +47,7 @@ public void onReceived(ExilePacketContext exilePacketContext) {
4547
}
4648
potionItems.stream()
4749
//remove all in-cooldown potions
48-
.filter(x -> player.getCooldowns().isOnCooldown(x.getItem()))
50+
.filter(x -> !player.getCooldowns().isOnCooldown(x.getItem()))
4951
.map(x -> Pair.of(x, ((SlashPotionItem) x.getItem())))
5052
.collect(Collectors.groupingBy(x -> x.getRight().getType()))
5153
.values()
@@ -64,7 +66,11 @@ public void onReceived(ExilePacketContext exilePacketContext) {
6466

6567
})
6668
//try drink
67-
.forEach(x -> x.getRight().handlePotionRestore(player, x.getLeft()));
69+
.map(x -> x.getRight().handlePotionRestore(player, x.getLeft()))
70+
.filter(x -> x)
71+
//at least one potion is consumed
72+
.findFirst()
73+
.ifPresentOrElse(x -> SoundUtils.playSound(player, SoundEvents.VILLAGER_YES), () -> SoundUtils.playSound(player, SoundEvents.VILLAGER_NO));
6874
}
6975
}
7076

0 commit comments

Comments
 (0)