Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interfaceification fixes #2635

Merged
merged 10 commits into from
Jul 10, 2024
Merged

Conversation

tal5
Copy link
Member

@tal5 tal5 commented Jul 7, 2024

Changes

  • Changed usages of valueOf, asEnum, etc. with old enums to LegacyNamingHelper#convert.
  • Changed uses of #name/toString, the ElementTag enum constructor, etc. with old enums to String#valueOf (since it doesn't contain any explicit method calls on the instance, it doesn't blow up about having the wrong invoke instructions on old versions).
  • Changed usages of Mechanism#requireEnum with old enums to LegacyNamingHelper#requireType.
  • VillagerChangesProfessionScriptEvent: enum constructor in getContext (unrelated cleanup).
  • Renamed EntityColor#listForEnum to listTypes, and changed it to take a class for the type instead of an enum array, and get the types list from the registry with Utilities#registryKeys for no-longer-enum types.
  • server.map_cursor_types now uses different registry-based logic on 1.20+.
  • server.structures now uses the new Utilities#registryKeys.

Additions

  • LegacyNamingHelper#convert - takes in a class and string, and converts that string to the type of the class with either registries or enum conversions.
  • LegacyNamingHelper#requireType - Mechanism#requireEnum but for no-longer-enums.
  • Utilities#registryKeys - returns a ListTag of a registry's keys.

Note

Used an Optional for LegacyNamingHelper#requireType, since it just seemed like a good place to use it and have slightly cleaner & maybe faster code using it, with the alternatives being

if (mechanism.matches("profession") && LegacyNamingHelper.matches(Villager.Profession.class, mechanism.getValue().asString())) {
    setProfession(LegacyNamingHelper.convet(Villager.Profession.class, mechanism.getValue().asString()));
}

or

if (mechanism.matches("profession")) {
    Villager.Profession profession = LegacyNamingHelper.requireType(mechanism, Villager.Profession.class);
    if (profession != null) {
        setProfession(profession);
    }
}

Which are messier, especially when there's a bunch, I.e. in EntityColor (and since this is a temporary thing till 1.21 is the min version anyway) - let me know if you'd still prefer one of the other approaches though.

Note

Some of these technically have registries on all supported versions, but can't really cleanly make them use these as it'd still involve method calls on interfaces that are enums in older versions - can have a separate set of utils for handling registry stuff in mechs/tags which'll probably be needed anyway as more stuff move to registries, but that's for a different PR.

mcmonkey4eva
mcmonkey4eva previously approved these changes Jul 10, 2024
@tal5 tal5 merged commit b645892 into DenizenScript:dev Jul 10, 2024
1 check passed
@tal5 tal5 deleted the Interfaceification_Fixes branch July 10, 2024 09:12
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.

None yet

2 participants