Last active
August 26, 2020 22:31
-
-
Save MajsterTynek/d53baef04967c72d3183811276b2c7d2 to your computer and use it in GitHub Desktop.
Script for crafting enchanted items on Hypixel (a Minecraft server). Script written in Lua for supposed use with Advanced Macros mod.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- event container open | |
local _, _, controls, name = ... | |
if name ~= "chest" then return end | |
if not craft_sync then return end -- craft script not invoked | |
if not craft_type then craft_type = "minecraft:cobblestone" end | |
if craft_type == "minecraft:ender_pearl" then craft_stack = 16 end | |
if not craft_stack then craft_stack = 64 end | |
-- making these local for efficiency | |
local clock, push, pop = os.clock, table.insert, table.remove | |
local inv, rnd, wait = controls.inventory, math.random, waitTick | |
local craft_type, craft_stack = craft_type, craft_stack | |
local isOpen, close, getSlot, click, quick = | |
controls.isOpen, -- is gui still open? | |
controls.close, -- close currently opened | |
inv.getSlot, -- get slot data | |
inv.click, -- left mouse button | |
inv.quick -- shift + click | |
local function is_still_open() | |
if not isOpen() then | |
log("&4Crafting broke &7"..clock()) | |
-- structure is invalid anyway | |
craft_sync = false | |
error("GUIclosedByUnknownMeanings") | |
end | |
end | |
local function GUIwait() | |
local customGUI = false | |
while not customGUI do | |
wait() -- waits for items to load | |
local pane = getSlot(1) | |
pane = pane and pane.id or "" | |
customGUI = pane == "minecraft:stained_glass_pane" | |
is_still_open() | |
end | |
end | |
local function HypixelQuick(slottie) | |
quick(slottie) | |
wait() | |
if getSlot(slottie) then | |
quick(slottie) | |
wait() | |
end | |
sleep( 200 + 75*rnd() ) | |
end | |
if controls.getUpperLabel():find("SkyBlock Menu") then | |
GUIwait() | |
click(32) -- Go to Crafting | |
end | |
if controls.getUpperLabel():find("Craft Item") then | |
GUIwait() | |
local stacks = 0 | |
local cobble = {} | |
local inventory_ = getInventory() | |
for i, item in ipairs(inventory_) do | |
if i < 37 and item and item.amount == craft_stack then | |
if not item.nbt.tag.ench and item.id == craft_type then | |
if i < 10 then | |
push(cobble, i+81) | |
else push(cobble, i+45) end | |
stacks = stacks + 1 | |
end | |
end | |
end | |
is_still_open() | |
if stacks < 5 then | |
sleep(225) | |
log("&7Crafting skipped") | |
craft_sync = false | |
close() | |
return | |
end | |
local putten = 0 | |
while stacks + putten >= 5 do | |
is_still_open() | |
HypixelQuick( pop(cobble) ) | |
stacks = stacks - 1 | |
putten = putten + 1 | |
if putten >= 5 then | |
putten = 0 -- here should be additional check for reverted item transactions | |
while isOpen() and getSlot(24).id == "minecraft:barrier" do wait() end -- might stuck | |
is_still_open() -- patchwork lol | |
HypixelQuick(24) | |
end | |
end | |
sleep(225) | |
log("&7Crafting ended") | |
craft_sync = false | |
close() | |
return | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- attach to keypress : recommended F4 | |
local wait, mtx = waitTick, newMutex("craft_sync") | |
if craft_sync or not mtx.tryLock() then | |
log("&4Previous crafting in action!") | |
else | |
local inv, tag, craftable = openInventory(), {}, false | |
local held = inv.getSlot(inv.mapping[inv.getType()].hotbar[getHotbar()]) | |
if held then -- tag is assumed to exist | |
tag = held.nbt.tag.ExtraAttributes | |
craftable = tag.id == "SKYBLOCK_MENU" | |
craftable = craftable or tag.uuid | |
craftable = not craftable -- checks are inversed | |
end | |
-- you might additionaly check if resource exist | |
-- before opening and traversing guis if there is not enough | |
held = craftable and held.id or "minecraft:cobblestone" | |
craft_stack = 64 | |
craft_sync = true | |
craft_type = held -- "minecraft:obsidian" | |
say("/viewsbmenu") -- or set hotbar 9 and use() | |
log("&7Crafting "..held:sub(11)) | |
while craft_sync do wait() end | |
mtx.unlock() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment