Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void trySellTo(Player player, InteractionHand hand) {
- if (level == null) return;
- // condense stock
- // (try to) charge cost
- // dispense stock
- ItemStack selling = getSellingItem();
- if (selling.isEmpty())
- return;
- condenseItems();
- if (isCreativeVendor()) {
- if (price.deduct(player, hand, false)) {
- ItemStack output = selling.copy();
- ItemUtil.givePlayerItem(player, output);
- giveSellingAdvancements(player);
- level.playSound(null, getBlockPos(), SoundEvents.ARROW_HIT_PLAYER, SoundSource.BLOCKS, 0.5f, 1.0f);
- notifyUpdate();
- } else {
- // insufficient funds
- player.displayClientMessage(Components.translatable("gui.numismatics.vendor.4insufficient_funds")
- .withStyle(ChatFormatting.DARK_RED), true);
- level.playSound(null, getBlockPos(), AllSoundEvents.DENY.getMainEvent(), SoundSource.BLOCKS, 0.5f, 1.0f);
- }
- } else {
- for (ItemStack stack : items) {
- if (matchesSellingItem(stack) && stack.getCount() >= selling.getCount()) {
- if (price.deduct(player, hand, true)) {
- ItemStack output = stack.split(selling.getCount());
- ItemUtil.givePlayerItem(player, output);
- giveSellingAdvancements(player);
- level.playSound(null, getBlockPos(), SoundEvents.ARROW_HIT_PLAYER, SoundSource.BLOCKS, 0.5f, 1.0f);
- notifyUpdate();
- } else {
- // insufficient funds
- player.displayClientMessage(Components.translatable("gui.numismatics.vendor.insufficient_funds")
- .withStyle(ChatFormatting.DARK_RED), true);
- level.playSound(null, getBlockPos(), AllSoundEvents.DENY.getMainEvent(), SoundSource.BLOCKS, 0.5f, 1.0f);
- }
- return;
- }
- }
- // out of stock
- String ownerName = UsernameUtils.INSTANCE.getName(owner, null);
- if (ownerName != null) {
- player.displayClientMessage(Components.translatable("gui.numismatics.vendor.out_of_stock.named", ownerName)
- .withStyle(ChatFormatting.DARK_RED), true);
- level.playSound(null, getBlockPos(), AllSoundEvents.DENY.getMainEvent(), SoundSource.BLOCKS, 0.5f, 1.0f);
- } else {
- player.displayClientMessage(Components.translatable("gui.numismatics.vendor.out_of_stock")
- .withStyle(ChatFormatting.DARK_RED), true);
- level.playSound(null, getBlockPos(), AllSoundEvents.DENY.getMainEvent(), SoundSource.BLOCKS, 0.5f, 1.0f);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement