Skip to content

Commit c25abd4

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents ee351c1 + e239aa6 commit c25abd4

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

src/main/java/huix/infinity/common/world/item/GemItem.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import net.minecraft.ChatFormatting;
44
import net.minecraft.network.chat.Component;
5+
import net.minecraft.sounds.SoundEvents;
56
import net.minecraft.world.InteractionHand;
67
import net.minecraft.world.InteractionResultHolder;
78
import net.minecraft.world.entity.player.Player;
@@ -23,12 +24,22 @@ public GemItem(Properties properties, int xpRewards) {
2324
@Override
2425
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand usedHand) {
2526
ItemStack itemstack = player.getItemInHand(usedHand);
26-
if (itemstack != ItemStack.EMPTY && this.xpRewards > 0) {
27-
player.giveExperiencePoints(this.xpRewards);
27+
if (itemstack.isEmpty() || this.xpRewards <= 0) {
28+
return InteractionResultHolder.pass(itemstack);
29+
}
30+
int count = itemstack.getCount();
31+
boolean isShiftKeyDown = player.isShiftKeyDown();
32+
int totalXp;
33+
if (isShiftKeyDown) {
34+
totalXp = this.xpRewards * count;
35+
itemstack.shrink(count);
36+
} else {
37+
totalXp = this.xpRewards;
2838
itemstack.shrink(1);
29-
return InteractionResultHolder.consume(itemstack);
3039
}
31-
return InteractionResultHolder.pass(player.getItemInHand(usedHand));
40+
player.giveExperiencePoints(totalXp);
41+
player.playSound(SoundEvents.GLASS_BREAK, 1.0F, 1.0F);
42+
return InteractionResultHolder.consume(itemstack);
3243
}
3344

3445
@Override

0 commit comments

Comments
 (0)