#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
#
#    This function has been created by Skilendarz Group.
#             https://skilendarz.com
#
#      GIVE MAP MAKERS THE CREDIT THEY DESERVE!
#             COPYING IS PROHIBITED!
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

#Buy
scoreboard players add @s gold 0
scoreboard players set @s[scores={buy=1,gold=..9}] buy 0
scoreboard players set @s[scores={buy=2,gold=..7}] buy 0
scoreboard players set @s[scores={buy=3,gold=..17}] buy 0
scoreboard players set @s[scores={buy=4,gold=..9}] buy 0

##Reject
execute if score @s buy matches 0 at @s run playsound minecraft:entity.villager.no master @s ~ ~ ~ 1

##Accept
execute if score @s buy matches 1.. run playsound minecraft:entity.villager.yes master @s ~ ~ ~ 1

execute if score @s buy matches 1.. run playsound minecraft:entity.experience_orb.pickup master @s ~ ~ ~ 1

execute if score @s buy matches 1 run give @s carrot_on_a_stick{CustomModelData:10,Unbreakable:1,display:{Name:'{"translate":"item.bonegun","color":"green","bold":true,"italic":false}'},HideFlags:4}
execute if score @s buy matches 2 run give @s pufferfish_spawn_egg{CanPlaceOn:["polished_deepslate","polished_deepslate_stairs","cobbled_deepslate_stairs","deepslate_tiles","cobbled_deepslate","deepslate","cobblestone_slab","spruce_stairs","oak_log","podzol","oak_planks","stone_bricks","cracked_stone_bricks","diorite","purpur_pillar","hay_block","stone","stone_brick_slab","cobblestone","dirt","coarse_dirt","infested_cobblestone","oak_slab","mycelium","iron_trapdoor","spruce_slab","polished_andesite","spruce_planks","gravel","cobblestone_stairs","andesite","stone_slab","smooth_stone_slab","stone_brick_stairs","oak_stairs","grass_block","spruce_leaves","oak_leaves","dark_oak_leaves"],display:{Name:'{"translate":"item.minisweetgun","color":"green","bold":true,"italic":false}'},EntityTag:{NoAI:1,Silent:1,CustomName:""},HideFlags:16}
execute if score @s buy matches 3 run give @s carrot_on_a_stick{CustomModelData:9,Unbreakable:1,display:{Name:'{"translate":"item.returntobase","color":"green","bold":true,"italic":false}'},HideFlags:4}
execute if score @s buy matches 4 run give @s milk_bucket{display:{Name:'{"translate":"item.milk","color":"green","bold":true,"italic":false}'}}

execute if score @s buy matches 1 run scoreboard players remove @s gold 10
execute if score @s buy matches 2 run scoreboard players remove @s gold 8
execute if score @s buy matches 3 run scoreboard players remove @s gold 18
execute if score @s buy matches 4 run scoreboard players remove @s gold 10
execute if score @s buy matches 1 run clear @s gold_ingot 10
execute if score @s buy matches 2 run clear @s gold_ingot 8
execute if score @s buy matches 3 run clear @s gold_ingot 18
execute if score @s buy matches 4 run clear @s gold_ingot 10