Skip to content

Conversation

@FerusGrim
Copy link

AI Assistance Notice: I used an AI assistant to help draft this PR text and Javadocs. The code and docs were reviewed and adjusted by me; any mistakes are my own, and I’m responsible for the final result. I just really hate writing documents.

Summary

Converts PackFormat from an int-only API to a major.minor model to support Mojang’s minor pack-format bumps (e.g., 65.2, 68.0), while retaining the int-based API via deprecations (not removals).

Highlights

  • Introduces FormatVersion value object and public accessors:

    • formatVersion(), minVersion(), maxVersion()
    • isInRange(FormatVersion)
  • Keeps legacy API (deprecated):
    format(), min(), max(), isInRange(int), format(int), format(int,int,int)

  • Validates ranges and comparisons in PackFormatImpl

  • Adds FormatVersion factory overloads

  • Corrects isSingle() semantics and hashCode() implementation

Motivation

Recent/coming snapshots use minor increments for pack formats (e.g., 65.1, 65.2). An int cannot represent these precisely. We provide forward compatibility without breaking existing consumers that still rely on the int-based API.

What changed

  • API

    • New: FormatVersion-based surface (formatVersion, minVersion, maxVersion, isInRange(FormatVersion))
    • Legacy int methods preserved and marked @deprecated
  • Factories

    • New: format(FormatVersion) and format(FormatVersion, FormatVersion, FormatVersion)
    • Legacy format(int) / format(int,int,int) now delegate to the new factories
  • Implementation

    • PackFormatImpl now checks min ≤ format ≤ max using FormatVersion.compareTo
    • isSingle() requires format == min == max
    • isInRange(int) delegates to isInRange(FormatVersion.of(int))
    • isInRange(FormatVersion) uses inclusive bounds
    • hashCode() now uses Objects.hash(...)
  • Quality

    • Int-ctor delegates to the FormatVersion ctor to avoid duplication

Backwards compatibility

  • Binary: preserved. No method removals; only deprecations.
  • Source: existing code compiles (with deprecation warnings).
  • Behavior: int-only callers still get the major component (e.g., 68.0 → 68).

Migration guide

Before

PackFormat pf = PackFormat.format(18);
boolean ok = pf.isInRange(22);

After (preferred)

PackFormat pf = PackFormat.format(FormatVersion.of(65, 2));
boolean ok = pf.isInRange(FormatVersion.of(68, 0));

Bridging (still works, deprecated)

boolean ok = pf.isInRange(22); // compares majors

Risks

  • Callers relying on previous isSingle() (only min == max) will see corrected behavior (format == min == max).

Example usage

PackFormat p = PackFormat.format(FormatVersion.of(65, 2))
    .union(PackFormat.format(FormatVersion.of(68, 0)));

boolean supports = p.isInRange(FormatVersion.of(66, 0)); // true
int legacyMajor = p.format(); // 65 (deprecated path), still works

Type: Enhancement / Compatibility
Breaking changes: No (API additions + deprecations only)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant