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

Quilt Tags API #35

Merged
merged 29 commits into from
Nov 21, 2021
Merged

Quilt Tags API #35

merged 29 commits into from
Nov 21, 2021

Conversation

LambdAurora
Copy link
Contributor

@LambdAurora LambdAurora commented Oct 4, 2021

Big PR, but very useful features, including:

  • TagType! A way to assign some behavior to tags like making them load on the client only, or have a tag that have a default on client in-case the server doesn't have a tag, or prevent the loading of a world/server if a tag isn't present to avoid breakage, etc.
  • TagRegistry! The equivalent of TagFactory from FAPI, includes a new method to accept a TagType parameter, all tags are defaulted to TagType.NEUTRAL otherwise. Also include biome tags.
  • Do not include an equivalent to FabricDataGeneratorTagBuilder since the class it hooks into is not public, can be ported once global access wideners are a thing perhaps.

Reviews are welcome, testing is encouraged!

@LambdAurora LambdAurora added documentation enhancement New feature or request new: module A pull request which adds a new module new: library A pull request which adds a new library. library: data Related to the data library. labels Oct 4, 2021
@Leo40Git Leo40Git mentioned this pull request Oct 4, 2021
6 tasks
@LambdAurora
Copy link
Contributor Author

Latest commit includes the latest tweaks I wanted to include, which tl;dr is preventing log spam of missing entries from tags due to dynamic registries shenanigans.

@LambdAurora LambdAurora requested a review from a team October 17, 2021 11:21
library/data/tags/build.gradle Outdated Show resolved Hide resolved

/**
* Interface implemented by {@link net.minecraft.tag.Tag} instances when QSL is present.
*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This semantic has caused issues in the past before. Such an interface should exist for other tag impls but access to functions should be done through static helper functions that may return a value if this data is not present.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely sure, my big issue with that is static helper functions are way too disconnected on an usage standpoint.
What I could do is force this interface to be implemented with default methods on the Tag interface so no cast exceptions.

Copy link
Contributor

@i509VCB i509VCB Nov 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay a compromise:

  1. Note in the docs that casting to QuiltTag is a usage error. Encourage using the cast function as it is currently named to get the functionality provided by this interface.

  2. Implementations of Tag may implement this interface. A default implementation is provided.


@Inject(method = "onDisconnected", at = @At("TAIL"))
private void onDisconnected(Text reason, CallbackInfo ci) {
// @TODO Replace with networking API?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make an issue on this todo after this api is merged.

Copy link
Contributor

@Juuxel Juuxel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like the client tags and different tag types (including required tags especially - even though they're a vanilla feature, some APIs like FAPI and Architectury API only expose optionals).

/**
* {@return {@code true} if the given tag has been "replaced" by a data pack at least once}
*/
boolean hasBeenReplaced();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the use case for this? Although I recall Fabric also has this weird API...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it can be for debugging?

I don't know all the details honestly, would need to find which PR added this to FAPI.

Copy link
Contributor Author

@LambdAurora LambdAurora Nov 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually found why: FabricMC/fabric#63, original reason sounds sensible.

Edit: asie did explained the entire reason why and the use case: FabricMC/fabric#579 (comment)

I think we should keep it then.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be useful to mention an example of why this would be used similar to the fabric api comment.

@LambdAurora LambdAurora added this to In Progress in Launch Roadmap Nov 13, 2021
@LambdAurora LambdAurora added this to the Initial release milestone Nov 13, 2021
}

public static void forceInit() {
// noop. this only forces to run the static initializer.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to force running clinit? Isn't only the ThreadLocal and Logger being initialized?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this isn't ran when it forced, it will cause recursion and very bad crashes.

LambdAurora and others added 3 commits November 13, 2021 23:19
…t/ClientTagRegistryManager.java

Co-authored-by: BasiqueEvangelist <basiqueevangelist@yandex.ru>
…legate.java

Co-authored-by: BasiqueEvangelist <basiqueevangelist@yandex.ru>
…e-info.java

Co-authored-by: BasiqueEvangelist <basiqueevangelist@yandex.ru>
@LambdAurora LambdAurora changed the base branch from 1.17.1 to 1.18 November 18, 2021 00:04
@LambdAurora LambdAurora changed the title Add Quilt Tags API. Quilt Tags API Nov 20, 2021

/**
* Interface implemented by {@link net.minecraft.tag.Tag} instances when QSL is present.
*
Copy link
Contributor

@i509VCB i509VCB Nov 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay a compromise:

  1. Note in the docs that casting to QuiltTag is a usage error. Encourage using the cast function as it is currently named to get the functionality provided by this interface.

  2. Implementations of Tag may implement this interface. A default implementation is provided.

@ApiStatus.Internal
public final class TagRegistryImpl<T> implements TagRegistry<T> {
private static final Logger LOGGER = LogManager.getLogger();
private static final ThreadLocal<Boolean> MISSING_TAGS_CLIENT_FETCH = new ThreadLocal<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a thread local an error here? My interpretation of the uses is that the integrated server would never see the client thread signal it that it is fetching tags because the signal would never signal the server's thread.

If it is an error, would AtomicBoolean suffice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This boolean is used exclusively on the client to check whether there is missing tags that should prevent the connection to the server, the entire goal of this ThreadLocal is to change the behavior of getMissingTags to exclude any tags not required to connect in onSynchronizeTags(SynchronizeTagsS2CPacket).

AtomicBoolean could introduce unwanted behavior on the integrated server.


@Override
default boolean hasBeenReplaced() {
return false; // The goal is to prevent hard-fails with custom Tag implementations.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we can prove beyond a reasonable doubt that any implementation of Tag we or anyone else does not explicitly handle may replace it's contents or has had it's contents replaced.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't, but not providing a default implementation could lead to bad crashes quickly.

So either we force the implementation of QuiltTag, or we encourage it without forcing.

@LambdAurora
Copy link
Contributor Author

Since we're a bit short on time, and all reviews should have been addressed, merging it.

If any issue occurs they always can be corrected in a later PR.

@LambdAurora LambdAurora merged commit 3348c0d into QuiltMC:1.18 Nov 21, 2021
@LambdAurora LambdAurora mentioned this pull request Nov 21, 2021
@TheGlitch76 TheGlitch76 mentioned this pull request Dec 4, 2021
4 tasks
@OroArmor OroArmor moved this from In Progress to Done in Launch Roadmap Jan 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hacktoberfest-accepted library: data Related to the data library. new: library A pull request which adds a new library. new: module A pull request which adds a new module
Projects
Development

Successfully merging this pull request may close these issues.

None yet

10 participants