Documentation ¶
Overview ¶
Package mc implements facilities for detecting and working with Minecraft instances.
Index ¶
Constants ¶
const ( // Main menu StMenu int = iota // Dirt world generation screen StDirt // World preview screen StPreview // In the world, paused and ready to be played StIdle // In the world, currently being played StIngame )
Instance state types
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type InstanceInfo ¶ added in v0.4.0
type InstanceInfo struct { Id int // Instance number Pid uint32 // Process ID Wid xproto.Window // Window ID Dir string // .minecraft directory Version int // Minecraft version ModernWp bool // Has wpstateout.txt WorldPreview ResetKey xproto.Keycode // Atum reset key PreviewKey xproto.Keycode // Leave preview key }
InstanceInfo contains information about how to interact with a Minecraft instance, such as its game directory and window ID.
func FindInstances ¶ added in v0.4.0
func FindInstances(x *x11.Client) ([]InstanceInfo, error)
FindInstances returns a sorted list of all running Minecraft instances, or an error if the running instances do not form a list.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
A Manager controls several Minecraft instances. It keeps track of each instance's state and communicates with a frontend to operate on the instances for the user.
func NewManager ¶
NewManager attempts to create a new Manager for the given instances.
func (*Manager) Focus ¶
Focus attempts to focus the window of the given instance. Any errors will be logged.
func (*Manager) Play ¶
Play attempts to play the given instance.
If there is a currently active instance, the given instance will supersede it. Any additional actions which should happen before playing (e.g. stretching, unpausing, F1) will be handled by this function. Any errors will be logged.
func (*Manager) Reset ¶
Reset attempts to reset the given instance. The return value will indicate whether or not the instance was in a legal state for resetting. If an actual error occurs, it will be logged.
func (*Manager) Run ¶
Run starts managing instances in the background. Any non-fatal errors are logged, any fatal errors are returned via the provided error channel.
func (*Manager) ToggleResolution ¶
ToggleResolution switches the given instance between the normal and alternate resolution and returns whether or not it is now on the alternate resolution.
type State ¶
type State struct { // Current main state (e.g. dirt, preview) Type int // World generation progress (0 to 100) Progress int // Whether or not the instance is in a menu (e.g. pause, inventory). // Requires WorldPreview state reader to detect. Menu bool // The last time the instance reached the world preview screen. LastPreview time.Time }
State contains information about the current state of an instance.
type StateReader ¶
type StateReader interface { // Path returns the path of the file being read. Path() string // Process reads any changes to the file and returns any state updates. Process() (state State, updated bool, err error) // ProcessEvent handles a non-modification change to the file, such as it // being deleted or moved. A non-nil error return signals an irrecoverable // failure. ProcessEvent(fsnotify.Op) error }
The StateReader interface provides a method for obtaining the state of an instance (e.g. generating, previewing, ingame.)
There are currently two implementations: the traditional log reader, and the newer wpstateout.txt reader. The wpstateout.txt reader is preferred and should be used whenever possible, as it is simpler, faster, and more featureful.