packwiz

package
v1.0.40 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContentKindMod          = "mod"
	ContentKindDatapack     = "datapack"
	ContentKindResourcePack = "resourcepack"
	ContentKindShaderPack   = "shaderpack"
)

Content kinds match both the packwiz category folders and the Modrinth project types. The Studio exposes one manager per kind.

View Source
const MaxDependencyDepth = 5

MaxDependencyDepth bounds transitive resolution to avoid runaway API fan-out.

Variables

This section is empty.

Functions

func ValidContentKind added in v1.0.40

func ValidContentKind(kind string) bool

Types

type BakeResult added in v1.0.40

type BakeResult struct {
	Mods       int `json:"mods"`
	Datapacks  int `json:"datapacks"`
	ClientOnly int `json:"client_only"`
}

BakeResult summarises what a bake wrote into a server's data directory. ClientOnly counts entries that a dedicated server cannot consume: client-side mods, plus every resource and shader pack. Those reach players through packwiz sync or a pack export rather than the server.

type ContentPatch added in v1.0.40

type ContentPatch struct {
	Name              *string `json:"name,omitempty"`
	FileName          *string `json:"file_name,omitempty"`
	Side              *string `json:"side,omitempty"`
	Pinned            *bool   `json:"pinned,omitempty"`
	Optional          *bool   `json:"optional,omitempty"`
	Default           *bool   `json:"default,omitempty"`
	OptionDescription *string `json:"option_description,omitempty"`
	DownloadURL       *string `json:"download_url,omitempty"`
	HashFormat        *string `json:"hash_format,omitempty"`
	Hash              *string `json:"hash,omitempty"`
	SHA512            *string `json:"sha512,omitempty"`
}

ContentPatch is a partial update for one metafile. Nil fields are left alone, so a caller can patch options without re-sending the download block.

type ContentUploadMetadata added in v1.0.40

type ContentUploadMetadata struct {
	Name              string
	Side              string
	Pinned            bool
	Optional          bool
	Default           bool
	OptionDescription string
}

ContentUploadMetadata carries the packwiz options for an uploaded archive.

type DependencyInstallReport

type DependencyInstallReport struct {
	Root       ModItem         `json:"root"`
	Added      []ModItem       `json:"added"`      // transitive deps newly installed
	Skipped    []string        `json:"skipped"`    // slugs already present in the pack
	Unresolved []DependencyRef `json:"unresolved"` // required deps with no compatible version
}

DependencyInstallReport summarises a dependency-aware mod install.

type DependencyRef

type DependencyRef struct {
	Platform       string `json:"platform"`   // "modrinth" | "curseforge"
	ProjectID      string `json:"project_id"` // Modrinth project id/slug or CurseForge numeric mod id
	VersionID      string `json:"version_id,omitempty"`
	Title          string `json:"title,omitempty"`
	DependencyType string `json:"dependency_type"` // "required" | "optional"
}

DependencyRef describes a single mod dependency discovered during resolution.

type DirectURLContentRequest added in v1.0.40

type DirectURLContentRequest struct {
	Kind              string `json:"kind"`
	Name              string `json:"name"`
	FileName          string `json:"file_name"`
	DownloadURL       string `json:"download_url"`
	Side              string `json:"side"`
	Pinned            bool   `json:"pinned"`
	Optional          bool   `json:"optional"`
	Default           bool   `json:"default"`
	OptionDescription string `json:"option_description"`
}

DirectURLContentRequest adds any content kind from a direct download URL.

type DirectURLModRequest

type DirectURLModRequest struct {
	Name        string `json:"name"`
	FileName    string `json:"file_name"`
	DownloadURL string `json:"download_url"`
	Side        string `json:"side"` // "both", "client", "server"
	Pinned      bool   `json:"pinned"`
}

DirectURLModRequest defines parameters for adding a mod from external URL

type DroppedModsError added in v1.0.40

type DroppedModsError struct {
	Dropped []string
}

DroppedModsError is returned by CurseForge export when non-CurseForge mods would be silently dropped. Callers must surface Dropped to the user instead of shipping a partial pack.

func (*DroppedModsError) Error added in v1.0.40

func (e *DroppedModsError) Error() string

type ExportOptions added in v1.0.40

type ExportOptions struct {
	// IncludeClient excludes client-only mods when false (server pack).
	IncludeClient bool `json:"include_client"`
	// OptionalMode is "keep" (default), "required" (force required) or
	// "optional" (mark files optional). It drives mrpack env flags and
	// CurseForge required booleans.
	OptionalMode string `json:"optional_mode"`
	// Overrides is "all" (default), "none" or "configs-only"
	// (only config/ paths are bundled).
	Overrides string `json:"overrides"`
	// Summary overrides the generated mrpack summary / instance notes.
	Summary string `json:"summary"`
}

ExportOptions controls per-launcher export behaviour. All fields are optional; DefaultExportOptions fills the launcher-safe defaults.

func DefaultExportOptions added in v1.0.40

func DefaultExportOptions() ExportOptions

DefaultExportOptions returns launcher-safe export defaults.

type ImportOptions

type ImportOptions struct {
	Name          string `json:"name"`
	Author        string `json:"author"`
	Version       string `json:"version"`
	MCVersion     string `json:"mc_version"`
	ModLoader     string `json:"mod_loader"`
	LoaderVersion string `json:"loader_version"`
}

ImportOptions defines settings for modpack import

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager(baseDir string, log *logger.Logger, options ...ManagerOptions) *Manager

func (*Manager) AddContent added in v1.0.40

func (m *Manager) AddContent(packID string, item ModItem) error

AddContent inserts or replaces one content entry. Slug uniqueness is scoped to the kind, so a datapack and a mod may share a display slug.

func (*Manager) AddContentFile added in v1.0.40

func (m *Manager) AddContentFile(packID, kind, fileName string, meta ContentUploadMetadata, serveURL string, r io.Reader) (*ModItem, error)

AddContentFile stores an uploaded archive at its install path and creates a metafile that points at the panel's public raw-file endpoint. serveURL must be absolute (the handler builds it from the request host).

func (*Manager) AddContentFromURL added in v1.0.40

func (m *Manager) AddContentFromURL(packID string, req DirectURLContentRequest) (*ModItem, error)

AddContentFromURL verifies and hashes a direct download URL. No copy is kept: the metafile points at the origin URL and mrpack exports carry SHA-512.

func (*Manager) AddDatapackFile added in v1.0.39

func (m *Manager) AddDatapackFile(packID, fileName string, r io.Reader) error

AddDatapackFile installs a datapack archive into the pack's datapacks override directory. The archive is validated as a real Minecraft datapack before it lands, repairing the common wrapper-folder packaging mistake when needed.

func (*Manager) AddMod

func (m *Manager) AddMod(packID string, mod ModItem) error

func (*Manager) AddModFromURL

func (m *Manager) AddModFromURL(packID string, req DirectURLModRequest) (*ModItem, error)

AddModFromURL downloads/inspects a direct URL mod and generates a valid .pw.toml

func (*Manager) AddModWithDependencies

func (m *Manager) AddModWithDependencies(packID string, mod ModItem, loader, mcVersion string, fetcher VersionDependencyFetcher) (*DependencyInstallReport, error)

AddModWithDependencies installs mod plus all of its transitive required dependencies (for loader/mcVersion), skipping anything already in the pack. Unresolvable required deps are reported, never fatal.

func (*Manager) ApplyContentUpdate added in v1.0.40

func (m *Manager) ApplyContentUpdate(packID, kind, slug, targetVersionID, targetFileName, targetURL, hashFormat, hash, sha512 string) error

ApplyContentUpdate updates the version and download metadata for one entry.

func (*Manager) ApplyMigration

func (m *Manager) ApplyMigration(packID, targetMC, targetLoader string) (*MigrationReport, error)

ApplyMigration applies target MC and loader version to the pack and upgrades compatible mods

func (*Manager) ApplyModUpdate

func (m *Manager) ApplyModUpdate(packID, slug, targetVersionID, targetFileName, targetURL string) error

ApplyModUpdate updates an individual mod with new version details

func (*Manager) BakeToServer

func (m *Manager) BakeToServer(packID, modsDir string) (int, error)

BakeToServer extracts server-side mods directly into /data/mods.

func (*Manager) BakeToServerContent added in v1.0.40

func (m *Manager) BakeToServerContent(packID, modsDir, datapacksDir string) (BakeResult, error)

BakeToServerContent installs the server-side parts of a pack: mods into modsDir and datapacks into datapacksDir (usually world/datapacks). An empty datapacksDir skips datapacks. Resource packs and shader packs are client-only content and are never written to a server.

func (*Manager) CheckContentUpdates added in v1.0.40

func (m *Manager) CheckContentUpdates(packID string) ([]ModUpdateInfo, error)

CheckContentUpdates queries Modrinth for every unpinned content entry. Mods filter by the pack loader; datapacks, resource packs and shader packs only filter by Minecraft version.

func (*Manager) CheckContentUpdatesContext added in v1.0.40

func (m *Manager) CheckContentUpdatesContext(ctx context.Context, packID string) ([]ModUpdateInfo, error)

func (*Manager) CheckModUpdates

func (m *Manager) CheckModUpdates(packID string) ([]ModUpdateInfo, error)

CheckModUpdates queries platform APIs for updates to mods in the pack

func (*Manager) CheckModUpdatesContext added in v1.0.40

func (m *Manager) CheckModUpdatesContext(ctx context.Context, packID string) ([]ModUpdateInfo, error)

func (*Manager) ClonePack

func (m *Manager) ClonePack(packID, newName string) (*Pack, error)

ClonePack creates an independent duplicate of an existing pack

func (*Manager) ContentFolder added in v1.0.40

func (m *Manager) ContentFolder(packID, kind string) (string, error)

ContentFolder returns the pack-relative folder a kind installs into.

func (*Manager) CreatePack

func (m *Manager) CreatePack(p *Pack) (*Pack, error)

func (*Manager) DeleteContent added in v1.0.40

func (m *Manager) DeleteContent(packID, kind, slug string) error

DeleteContent removes a metafile and, when the download points at this panel's raw file endpoint, the uploaded archive as well.

func (*Manager) DeleteMod

func (m *Manager) DeleteMod(packID, slug string) error

func (*Manager) DeletePack

func (m *Manager) DeletePack(id string) error

func (*Manager) DeletePackFile

func (m *Manager) DeletePackFile(packID, relPath string) error

DeletePackFile removes an override file and updates the pack index

func (*Manager) DryRunMCVersion

func (m *Manager) DryRunMCVersion(packID, newMCVersion string) (*StaleReport, error)

DryRunMCVersion reports which mods would go stale if the pack moved to newMCVersion, without writing anything.

func (*Manager) ExportCurseForge

func (m *Manager) ExportCurseForge(packID string, w io.Writer, opts ...ExportOptions) error

ExportCurseForge generates a CurseForge .zip modpack. Unlike the legacy behaviour it never silently drops mods: any non-CurseForge entry (Modrinth, direct URL, or missing numeric IDs) aborts the export with a *DroppedModsError listing every dropped mod so the UI can warn/block.

func (*Manager) ExportMMC added in v1.0.40

func (m *Manager) ExportMMC(packID string, w io.Writer, opts ...ExportOptions) error

ExportMMC generates a Prism/MultiMC instance.zip (mmc-pack.json + instance.cfg) reusing the resolved packwiz mod list. Mod jars themselves are not bundled (Studio stores URLs, not binaries); a modlist.txt with download URLs plus the .minecraft/ overrides ship instead so launchers import a ready-to-complete instance.

func (*Manager) ExportMrpack

func (m *Manager) ExportMrpack(packID string, w io.Writer, opts ...ExportOptions) error

ExportMrpack generates a Modrinth .mrpack archive. Stored per-mod checksums are reused; mods without a known hash ship with an empty hashes map instead of a placeholder.

func (*Manager) ExportPackwizZip

func (m *Manager) ExportPackwizZip(packID string, w io.Writer, opts ...ExportOptions) error

ExportPackwizZip exports the full native Packwiz archive (.zip with pack.toml, index.toml, mods/, and overrides). The native format always preserves side metadata, so IncludeClient / OptionalMode / Summary are ignored; only the Overrides policy filters which non-mod files are bundled.

func (*Manager) GetPack

func (m *Manager) GetPack(id string) (*Pack, error)

func (*Manager) ImportCurseForge

func (m *Manager) ImportCurseForge(r io.ReaderAt, size int64, opts ImportOptions) (*Pack, error)

ImportCurseForge imports a CurseForge .zip modpack into a new Packwiz project

func (*Manager) ImportMrpack

func (m *Manager) ImportMrpack(r io.ReaderAt, size int64, opts ImportOptions) (*Pack, error)

ImportMrpack imports a Modrinth .mrpack archive into a new Packwiz project

func (*Manager) ImportPackwizZip

func (m *Manager) ImportPackwizZip(r io.ReaderAt, size int64, opts ImportOptions) (*Pack, error)

ImportPackwizZip imports a native Packwiz archive (.zip containing pack.toml, index.toml, mods/)

func (*Manager) ListPackFiles

func (m *Manager) ListPackFiles(packID string) ([]PackFileInfo, error)

ListPackFiles lists non-mod override files in the modpack

func (*Manager) ListPacks

func (m *Manager) ListPacks() ([]PackSummary, error)

func (*Manager) NewHTTPDependencyFetcher

func (m *Manager) NewHTTPDependencyFetcher() VersionDependencyFetcher

NewHTTPDependencyFetcher returns the production fetcher for a Manager.

func (*Manager) NewHTTPDependencyFetcherContext added in v1.0.40

func (m *Manager) NewHTTPDependencyFetcherContext(ctx context.Context) VersionDependencyFetcher

NewHTTPDependencyFetcherContext binds provider calls to the operation lifetime.

func (*Manager) RefreshPack

func (m *Manager) RefreshPack(packID string) error

RefreshPack re-indexes all mod and override files, recomputing hashes according to packwiz refresh

func (*Manager) ResolveTransitiveDependencies

func (m *Manager) ResolveTransitiveDependencies(fetcher VersionDependencyFetcher, platform, projectID, loader, mcVersion string, maxDepth int) ([]DependencyRef, error)

ResolveTransitiveDependencies walks required dependencies breadth-first, cycle-safe and depth-bounded. It returns every distinct required dependency (excluding the root project itself).

func (*Manager) SavePackFile

func (m *Manager) SavePackFile(packID, relPath string, r io.Reader) error

SavePackFile writes an override file and updates the pack index

func (*Manager) ServePackFile

func (m *Manager) ServePackFile(packID, relativePath string) ([]byte, string, error)

func (*Manager) SetDatapackFolder added in v1.0.40

func (m *Manager) SetDatapackFolder(packID, folder string) error

SetDatapackFolder moves a pack's datapack metadata (and any panel-hosted archives) into a new pack-relative folder and records packwiz's [options] datapack-folder.

func (*Manager) SetMCVersion

func (m *Manager) SetMCVersion(packID, newMCVersion string) (*StaleReport, error)

SetMCVersion switches the pack to newMCVersion without touching installed mod versions, and reports every mod that is now stale. Only version-tracked mods (curseforge, or modrinth with a project ID) carry an MC-scoped upstream version: direct-URL ("url") mods — including ones that round-tripped through pack files without update metadata — are never marked stale. Callers should follow up with SimulateMigration/ApplyMigration to offer the update-and-resolve-conflicts flow.

func (*Manager) SimulateMigration

func (m *Manager) SimulateMigration(packID, targetMC, targetLoader string) (*MigrationReport, error)

SimulateMigration tests if mods in a pack support a new target Minecraft & loader version

func (*Manager) SimulateMigrationContext added in v1.0.40

func (m *Manager) SimulateMigrationContext(ctx context.Context, packID, targetMC, targetLoader string) (*MigrationReport, error)

func (*Manager) UpdateContent added in v1.0.40

func (m *Manager) UpdateContent(packID, kind, slug string, patch ContentPatch) error

UpdateContent applies a partial patch to one entry in a kind.

func (*Manager) UpdateMod

func (m *Manager) UpdateMod(packID, slug, side string, pinned bool) error

func (*Manager) UpdatePack

func (m *Manager) UpdatePack(p *Pack) error

type ManagerOptions added in v1.0.40

type ManagerOptions struct {
	HTTPClient        *http.Client
	ModrinthBaseURL   string
	CurseForgeBaseURL string
}

type MigrationModItem

type MigrationModItem struct {
	Slug              string `json:"slug"`
	Name              string `json:"name"`
	Platform          string `json:"platform"`
	CurrentVersionID  string `json:"current_version_id"`
	TargetVersionID   string `json:"target_version_id,omitempty"`
	TargetFileName    string `json:"target_file_name,omitempty"`
	TargetDownloadURL string `json:"target_download_url,omitempty"`
	Compatible        bool   `json:"compatible"`
}

MigrationModItem represents compatibility of an individual mod during migration

type MigrationReport

type MigrationReport struct {
	PackID            string             `json:"pack_id"`
	CurrentMC         string             `json:"current_mc"`
	CurrentLoader     string             `json:"current_loader"`
	TargetMC          string             `json:"target_mc"`
	TargetLoader      string             `json:"target_loader"`
	TotalMods         int                `json:"total_mods"`
	CompatibleCount   int                `json:"compatible_count"`
	IncompatibleCount int                `json:"incompatible_count"`
	Mods              []MigrationModItem `json:"mods"`
}

MigrationReport holds the outcome of a version migration check/apply

type ModItem

type ModItem struct {
	Slug        string `json:"slug"`
	Name        string `json:"name"`
	FileName    string `json:"file_name"`
	Side        string `json:"side"` // "both", "client", "server"
	Platform    string `json:"platform"`
	ProjectID   string `json:"project_id"`
	VersionID   string `json:"version_id"`
	DownloadURL string `json:"download_url"`
	FileSize    int64  `json:"file_size"`
	Pinned      bool   `json:"pinned"`
	// Kind is one of mod, datapack, resourcepack or shaderpack. Older clients
	// can ignore it; GetPack always sets it so the Studio can render one list.
	Kind string `json:"kind,omitempty"`
	// Optional files are installed only when the user selects them. Default
	// controls whether an optional file starts enabled. OptionDescription is
	// shown next to that choice.
	Optional          bool   `json:"optional"`
	Default           bool   `json:"default"`
	OptionDescription string `json:"option_description,omitempty"`
	// Hash/HashFormat persist the mod file checksum (sha256/sha512/sha1)
	// captured at import or AddModFromURL time. Exporters reuse these
	// instead of emitting placeholder hashes.
	Hash       string `json:"hash,omitempty"`
	HashFormat string `json:"hash_format,omitempty"`
	// SHA512 is kept separately because Modrinth supplies it and mrpack
	// exports require it.
	SHA512 string `json:"sha512,omitempty"`
}

type ModUpdateInfo

type ModUpdateInfo struct {
	Slug              string `json:"slug"`
	Name              string `json:"name"`
	Kind              string `json:"kind,omitempty"`
	Platform          string `json:"platform"`
	CurrentVersionID  string `json:"current_version_id"`
	LatestVersionID   string `json:"latest_version_id"`
	LatestFileName    string `json:"latest_file_name"`
	LatestDownloadURL string `json:"latest_download_url"`
	LatestHashFormat  string `json:"latest_hash_format,omitempty"`
	LatestHash        string `json:"latest_hash,omitempty"`
	LatestSHA512      string `json:"latest_sha512,omitempty"`
	Changelog         string `json:"changelog,omitempty"`
	UpdateAvailable   bool   `json:"update_available"`
	Pinned            bool   `json:"pinned"`
}

ModUpdateInfo represents available updates for a mod

type Pack

type Pack struct {
	ID             string    `json:"id"`
	Name           string    `json:"name"`
	Author         string    `json:"author"`
	Version        string    `json:"version"`
	MCVersion      string    `json:"mc_version"`
	ModLoader      string    `json:"mod_loader"`
	LoaderVersion  string    `json:"loader_version"`
	UpdatedAt      time.Time `json:"updated_at"`
	Mods           []ModItem `json:"mods"`
	Datapacks      []ModItem `json:"datapacks"`
	ResourcePacks  []ModItem `json:"resourcepacks"`
	ShaderPacks    []ModItem `json:"shaderpacks"`
	DatapackFolder string    `json:"datapack_folder,omitempty"`
	// Options preserves the pack.toml [options] table (acceptable versions,
	// meta-folder, datapack-folder, ...) so editing a pack never drops it.
	Options map[string]any `json:"options,omitempty"`
}

type PackFileInfo

type PackFileInfo struct {
	Path     string    `json:"path"`
	Size     int64     `json:"size"`
	ModTime  time.Time `json:"mod_time"`
	Category string    `json:"category"`
}

PackFileInfo represents extra non-mod override files in packwiz

type PackSummary

type PackSummary struct {
	ID            string    `json:"id"`
	Name          string    `json:"name"`
	Author        string    `json:"author"`
	Version       string    `json:"version"`
	MCVersion     string    `json:"mc_version"`
	ModLoader     string    `json:"mod_loader"`
	LoaderVersion string    `json:"loader_version"`
	ModCount      int       `json:"mod_count"`
	UpdatedAt     time.Time `json:"updated_at"`
}

type StaleModInfo

type StaleModInfo struct {
	Slug             string `json:"slug"`
	Name             string `json:"name"`
	Platform         string `json:"platform"`
	CurrentVersionID string `json:"current_version_id"`
	Reason           string `json:"reason"` // "mc_version_changed"
}

StaleModInfo marks a single mod as stale after the pack's Minecraft version changed: its installed version was resolved for the previous MC version and must be re-checked (update) before the pack is consistent again.

type StaleReport

type StaleReport struct {
	PackID     string         `json:"pack_id"`
	PreviousMC string         `json:"previous_mc"`
	NewMC      string         `json:"new_mc"`
	StaleMods  []StaleModInfo `json:"stale_mods"`
	StaleCount int            `json:"stale_count"`
}

StaleReport is returned when a pack's Minecraft version changes.

type VersionDependencyFetcher

type VersionDependencyFetcher interface {
	// LatestCompatibleMod returns install metadata for the newest version of
	// projectID compatible with loader/mcVersion, plus its required deps.
	LatestCompatibleMod(platform, projectID, loader, mcVersion string) (ModItem, []DependencyRef, error)
}

VersionDependencyFetcher resolves the latest compatible version metadata for a project plus that version's own required dependencies. The default implementation queries the Modrinth / CurseForge APIs over HTTP; tests inject a stub.

Jump to

Keyboard shortcuts

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