Minecraftblock0, Jighello and Sgt_Blinky introduced me to Autohotkey scripting the other night, and I have since spent a good 4-5 hours playing with it, and I thought I'd share my first proper script.
What this script does is, at the press of ONE button, swap all items from an open small chest (ie, the chest/inventory is on screen) with all the items in your inventory. You only need to set one variable in the script to tell it what setting you have your gui set to (ie: small, medium, large, auto), and it works out the rest itself.
A few notes, if something weird happens (like the script dropping your items) because you didn't read these notes, I AM NOT RESPONSIBLE!
- It only works with the client, not the in browser game.
- You need to have the chest open. The script causes the mouse to move to certain positions and click, if the chest isn't open, you could accidentally hit someone or break something.
- It only works with SMALL chests!
- If your inv is empty, all items in the chest will be put in your inv, and vice-versa. If you have items in both the chest and your inv, they will be swapped.
As I said, this is the result of my first foray into Autohotkey scripting, and I'm not sure it is of much use, but I daresay someone might have a use for it. Also, if you're also playing with AHK scripts and want to see how I did it, it's fairly well annotated.
Here's the script!
[color]
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#IfWinActive, Minecraft
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Swap all items in inventory with items in a SMALL chest (will not work ;;
;; with large chest). If chest is empty, items will just be placed into ;;
;; chest and inventory emptied (and vice-versa). Script ONLY works with ;;
;; the client, NOT browser ;;
;; ;;
;;====MAKE SURE YOU CHANGE "gui = 0" TO MATCH YOUR SETUP! You shouldn't===;;
;;======================need to change anything else======================;;
;; ;;
;; by John Bullock (beagrie) - http://jbullock.co.uk ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
F11::
gui = 0 ;; Your GUI setting. 1 = Small, 2 = Normal, 3 = Large, 0 = Auto
delay := 5 ;; If you experience items not being transferred, try increasing
;; the delay
;; WinGetActiveStats returns the width, height, x and y position and title of the active window,
;; which should be Minecraft (this is why this script only works with the client, not browser),
;; the width and height are then divided by 2 to get the centre of the client window
WinGetActiveStats, Title, Width, Height, X, Y
centre_x:=(Width*.5)
centre_y:=(Height*.5)
if (Height < 518) { ;; If window height is less than 518, Minecraft uses
;; small GUI, regardless of option setting
slot_size := 18
divider := 13
} else if (Height > 757) { ;; If window is greater than 757, Minecraft will use
;; large GUI, unless "small" or "normal" are selected
if (gui = 1) {
slot_size := 18
divider := 13
} else if (gui = 2) {
slot_size := 36
divider := 26
} else {
slot_size := 54
divider := 39
}
} else { ;; If window is between 518 and 757 high, Minecraft will use
;; medium GUI, unless "small" is selected
if (gui = 1) {
slot_size := 18
divider := 13
} else {
slot_size := 36
divider := 26
}
}
;; Set start point to the centre of the top left inventory slot, all calculations
;; work from this variable
datum_x := centre_x - (slot_size * 4)
datum_y := centre_y - (slot_size * 3)
;; Set column and row variables to 0
inv_col := 0
inv_row := 0
;; Nested Loop. The outer loop (9) moves the mouse horizontally across the chest slots. At the
;; end of each loop, inv_col is incremented by 1. The position of the mouse is determined by
;; multiplying the inventory/chest slot size (calculated above) by the column number (inv_col)
;; and added to the datum value.
Loop 9
{
;; With every iteration of the main loop, a second loop is run to move the mouse vertically
;; down each of the three rows in the chest. The mouse is clicked, moved down to the inventory,
;; clicked again, and finally moved back to corresponding chest slot and clicked, in case there
;; was an item in the inventory to put in the chest.
Loop 3
{
slot_x := datum_x + (inv_col * slot_size)
slot_y := datum_y + (inv_row * slot_size)
MouseMove, slot_x, slot_y
Send {Click}
Sleep, delay
MouseMove, slot_x, (slot_y + divider + (slot_size * 3))
Send {Click}
Sleep, delay
MouseMove, slot_x, slot_y
Send {Click}
Sleep, delay
inv_row += 1
}
inv_col += 1 ;; Increment column value by 1 to move horizontally across slots
inv_row := 0 ;; Reset row value to move back to top of slots
}
return