22
33import net .minecraft .ChatFormatting ;
44import net .minecraft .network .chat .Component ;
5+ import net .minecraft .sounds .SoundEvents ;
56import net .minecraft .world .InteractionHand ;
67import net .minecraft .world .InteractionResultHolder ;
78import 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