# I ADDED SOME OF THE THINGS YOU NEED TO SEND TO THE PLAYER. IF YOU WANT TO ADD THE REST, YOU CAN DO IT ON YOUR OWN TIME.
command /toolenchant:
aliases: /toolench
trigger:
# We're seeing if the variable is not set (or false).
# That way, we know if the player is just trying to access their inventory normally, or if they're trying to enchant an item.
if {opened::%player's uuid%} != true:
send "&aClick the item that you want to enchant!"
set {opened::%player's uuid%} to true # literally what I was just talking about.
wait 0.5 seconds # this is to give the player a bit of time to read the message.
open player's inventory to player
on inventory click:
if {opened::%player's uuid%} is true: # we talked about this a bit ago.
event-inventory is player's inventory # making sure the inventory the click happened was the player's.
if {clicked::%player's uuid%::1} is not set: # seeing if we already have the item we need to enchant.
if event-item is any pickaxe:
cancel event # making sure the player doesn't pick up the item.
set {clicked::%player's uuid%::1} to event-item # setting the item we need to enchant.
set {clicked::%player's uuid%::2} to event-slot
set {fc::%player's uuid%} to true # letting us know that we closed the inventory and not the player
close event-inventory
send "&aNow click the book that you want to enchant the item with!&r" # it might produce an error here since we already closed the inventory, but idk
wait 0.5 seconds
open player's inventory to player
else:
if event-item is any enchanted book:
cancel event
set {_ench} to event-item's enchantment # getting the enchantment of the book
if {_ench} is set:
enchant {clicked::%player's uuid%::1} with {_ench} # enchanting the item
set slot {clicked::%player's uuid%::2} to {clicked::%player's uuid%::1} # replacing the previous item with the enchanted one
delete {clicked::%player's uuid%::*}
delete {opened::%player's uuid%} # instead of setting it to false, we delete it so that excess storage doesn't get taken up.
close event-inventory
on inventory open:
if {fc::%player's uuid%} is true: # if we closed the inventory
delete {fc::%player's uuid%} # we opened it back up so we don't need this var anymore
on inventory close:
if {opened::%player's uuid%} is true: # if we opened the inventory
if {fc::%player's uuid%} is true: # if we closed the inventory
stop # ignores the rest of the code
# deletes variables (if the player closed the inventory)
delete {clicked::%player's uuid%::*}
delete {opened::%player's uuid%}