Advertisement
TIMAS_Bro

Untitled

May 15th, 2024
625
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.91 KB | None | 0 0
  1. private void trySellTo(Player player, InteractionHand hand) {
  2.         if (level == null) return;
  3.         // condense stock
  4.         // (try to) charge cost
  5.         // dispense stock
  6.         ItemStack selling = getSellingItem();
  7.         if (selling.isEmpty())
  8.             return;
  9.  
  10.         condenseItems();
  11.  
  12.         if (isCreativeVendor()) {
  13.             if (price.deduct(player, hand, false)) {
  14.                 ItemStack output = selling.copy();
  15.                 ItemUtil.givePlayerItem(player, output);
  16.                 giveSellingAdvancements(player);
  17.  
  18.                 level.playSound(null, getBlockPos(), SoundEvents.ARROW_HIT_PLAYER, SoundSource.BLOCKS, 0.5f, 1.0f);
  19.                 notifyUpdate();
  20.             } else {
  21.                 // insufficient funds
  22.                 player.displayClientMessage(Components.translatable("gui.numismatics.vendor.4insufficient_funds")
  23.                     .withStyle(ChatFormatting.DARK_RED), true);
  24.                 level.playSound(null, getBlockPos(), AllSoundEvents.DENY.getMainEvent(), SoundSource.BLOCKS, 0.5f, 1.0f);
  25.             }
  26.         } else {
  27.             for (ItemStack stack : items) {
  28.                 if (matchesSellingItem(stack) && stack.getCount() >= selling.getCount()) {
  29.                     if (price.deduct(player, hand, true)) {
  30.                         ItemStack output = stack.split(selling.getCount());
  31.                         ItemUtil.givePlayerItem(player, output);
  32.                         giveSellingAdvancements(player);
  33.  
  34.                         level.playSound(null, getBlockPos(), SoundEvents.ARROW_HIT_PLAYER, SoundSource.BLOCKS, 0.5f, 1.0f);
  35.                         notifyUpdate();
  36.                     } else {
  37.                         // insufficient funds
  38.                         player.displayClientMessage(Components.translatable("gui.numismatics.vendor.insufficient_funds")
  39.                             .withStyle(ChatFormatting.DARK_RED), true);
  40.                         level.playSound(null, getBlockPos(), AllSoundEvents.DENY.getMainEvent(), SoundSource.BLOCKS, 0.5f, 1.0f);
  41.                     }
  42.                     return;
  43.                 }
  44.             }
  45.  
  46.             // out of stock
  47.             String ownerName = UsernameUtils.INSTANCE.getName(owner, null);
  48.             if (ownerName != null) {
  49.                 player.displayClientMessage(Components.translatable("gui.numismatics.vendor.out_of_stock.named", ownerName)
  50.                     .withStyle(ChatFormatting.DARK_RED), true);
  51.                 level.playSound(null, getBlockPos(), AllSoundEvents.DENY.getMainEvent(), SoundSource.BLOCKS, 0.5f, 1.0f);
  52.             } else {
  53.                 player.displayClientMessage(Components.translatable("gui.numismatics.vendor.out_of_stock")
  54.                     .withStyle(ChatFormatting.DARK_RED), true);
  55.                 level.playSound(null, getBlockPos(), AllSoundEvents.DENY.getMainEvent(), SoundSource.BLOCKS, 0.5f, 1.0f);
  56.             }
  57.         }
  58.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement