mc

package
v0.5.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2024 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package mc implements facilities for detecting and working with Minecraft instances.

Index

Constants

View Source
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

View Source
var ErrInstanceClosed = errors.New("instance closed")

Functions

This section is empty.

Types

type InstanceInfo

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

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

func NewManager(infos []InstanceInfo, conf *cfg.Profile, x *x11.Client) (*Manager, error)

NewManager attempts to create a new Manager for the given instances.

func (*Manager) Focus

func (m *Manager) Focus(id int)

Focus attempts to focus the window of the given instance. Any errors will be logged.

func (*Manager) GetStates

func (m *Manager) GetStates() []State

GetStates returns a list of all instance states.

func (*Manager) Play

func (m *Manager) Play(id int)

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

func (m *Manager) Reset(id int) bool

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

func (m *Manager) Run(ctx context.Context, evtch chan<- Update, errch chan<- error)

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

func (m *Manager) ToggleResolution(id int) bool

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.

type Update

type Update struct {
	State State
	Id    int
}

Update contains a change to the state of a specific instance.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL