//Blaze Trading

//Blaze (PSI Gem)
onEvent('item.entity_interact', event => {
    if (event.hand == MAIN_HAND)
    if (event.item.id == 'minecraft:diamond')
    if (event.target.type == 'minecraft:blaze'){
    if (!event.player.isCreativeMode()) {event.item.setCount(event.item.getCount() - 1)}
      event.server.schedule(5, event.server, function (callback) {                                 
      callback.server.runCommandSilent(`execute as ${event.player.name} in ${event.player.world.dimension} run summon item ${event.target.x} ${event.target.y+0.5} ${event.target.z} {Item:{id:'psi:psigem',Count:1b}}`);  
      callback.server.runCommandSilent(`execute as ${event.player.name} in ${event.player.world.dimension} run tellraw @p {"text":"Thanks for the diamond have a psigem","color":"green"}`);  
   })}})
  //Blaze Trading (PSI Metal)
  onEvent('item.entity_interact', event => {
    if (event.hand == MAIN_HAND)
    if (event.item.id == 'minecraft:gold_ingot')
    if (event.target.type == 'minecraft:blaze'){
    if (!event.player.isCreativeMode()) {event.item.setCount(event.item.getCount() - 1)}
      event.server.schedule(5, event.server, function (callback) {                                 
      callback.server.runCommandSilent(`execute as ${event.player.name} in ${event.player.world.dimension} run summon item ${event.target.x} ${event.target.y+0.5} ${event.target.z} {Item:{id:'psi:psimetal',Count:1b}}`);  
      callback.server.runCommandSilent(`execute as ${event.player.name} in ${event.player.world.dimension} run tellraw @p {"text":"Thanks for the gold have a psi metal ingot","color":"green"}`);  
   })}})
  //Blaze Trading (Rod Constructor)
  onEvent('item.entity_interact', event => {
    if (event.hand == MAIN_HAND)
    if (event.item.id == 'tconstruct:crafting_station')
    if (event.target.type == 'minecraft:blaze'){
    if (!event.player.isCreativeMode()) {event.item.setCount(event.item.getCount() - 1)}
      event.server.schedule(5, event.server, function (callback) {                                 
      callback.server.runCommandSilent(`execute as ${event.player.name} in ${event.player.world.dimension} run summon item ${event.target.x} ${event.target.y+0.5} ${event.target.z} {Item:{id:'psi:cad_assembler',Count:1b}}`);  
      callback.server.runCommandSilent(`execute as ${event.player.name} in ${event.player.world.dimension} run tellraw @p {"text":"Thanks for the crafting station have a rod constructor","color":"green"}`);  
   })}})
  //Blaze Trading (Rod Programer)
  onEvent('item.entity_interact', event => {
    if (event.hand == MAIN_HAND)
    if (event.item.id == 'bloodmagic:altar')
    if (event.target.type == 'minecraft:blaze'){
    if (!event.player.isCreativeMode()) {event.item.setCount(event.item.getCount() - 1)}
      event.server.schedule(5, event.server, function (callback) {                                 
      callback.server.runCommandSilent(`execute as ${event.player.name} in ${event.player.world.dimension} run summon item ${event.target.x} ${event.target.y+0.5} ${event.target.z} {Item:{id: 'psi:programmer',Count:1b}}`);  
      callback.server.runCommandSilent(`execute as ${event.player.name} in ${event.player.world.dimension} run tellraw @p {"text":"Thanks for the altar have a spell inscriber","color":"green"}`);  
   })}})
  //Blaze Trading (Empty Handed)
  // onEvent('item.entity_interact', event => {
  //  if (event.hand == MAIN_HAND)
  //  if (event.item.id == 'minecraft:air')
  //  if (event.target.type == 'minecraft:blaze'){
  //    event.server.schedule(5, event.server, function (callback) {                                 
  //   callback.server.runCommandSilent(`execute as ${event.player.name} in ${event.player.world.dimension} run tellraw @p {"text":"You offer me nothing!","color":"dark_red"}`);
  // })}})
  //Blaze Trading (Wrong Item)
   onEvent('item.entity_interact', event => {
    if (event.hand == MAIN_HAND)
    if (event.item.id != 'minecraft:diamond')
    if (event.item.id != 'minecraft:air')
    if (event.item.id != 'minecraft:gold_ingot')
    if (event.item.id != 'bloodmagic:altar')
    if (event.item.id != 'tconstruct:crafting_station')
    if (event.target.type == 'minecraft:blaze'){
      event.server.schedule(5, event.server, function (callback) {                                 
      callback.server.runCommandSilent(`execute as ${event.player.name} in ${event.player.world.dimension} run tellraw @p {"text":"I don't want this!","color":"dark_red"}`);
   })}})

   //TEST
