-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
Quilt Tags API #35
Conversation
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. |
library/data/tags/src/main/java/org/quiltmc/qsl/tag/api/TagRegistry.java
Outdated
Show resolved
Hide resolved
library/data/tags/src/main/java/org/quiltmc/qsl/tag/api/package-info.java
Outdated
Show resolved
Hide resolved
library/data/tags/src/main/java/org/quiltmc/qsl/tag/api/package-info.java
Outdated
Show resolved
Hide resolved
library/data/tags/src/main/java/org/quiltmc/qsl/tag/api/package-info.java
Outdated
Show resolved
Hide resolved
Co-authored-by: BasiqueEvangelist <basiqueevangelist@yandex.ru>
…aries into tags_api
library/data/tags/src/main/java/org/quiltmc/qsl/tag/api/package-info.java
Show resolved
Hide resolved
build-logic/src/main/java/qsl/internal/extension/QslModuleExtension.java
Outdated
Show resolved
Hide resolved
|
||
/** | ||
* Interface implemented by {@link net.minecraft.tag.Tag} instances when QSL is present. | ||
* |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay a compromise:
-
Note in the docs that casting to
QuiltTag
is a usage error. Encourage using thecast
function as it is currently named to get the functionality provided by this interface. -
Implementations of
Tag
may implement this interface. A default implementation is provided.
library/data/tags/src/main/java/org/quiltmc/qsl/tag/api/QuiltTagBuilder.java
Show resolved
Hide resolved
library/data/tags/src/main/java/org/quiltmc/qsl/tag/api/TagRegistry.java
Show resolved
Hide resolved
library/data/tags/src/main/java/org/quiltmc/qsl/tag/impl/TagDelegate.java
Show resolved
Hide resolved
library/data/tags/src/main/java/org/quiltmc/qsl/tag/impl/TagDelegate.java
Show resolved
Hide resolved
library/data/tags/src/main/java/org/quiltmc/qsl/tag/mixin/RequiredTagListRegistryMixin.java
Outdated
Show resolved
Hide resolved
|
||
@Inject(method = "onDisconnected", at = @At("TAIL")) | ||
private void onDisconnected(Text reason, CallbackInfo ci) { | ||
// @TODO Replace with networking API? |
There was a problem hiding this comment.
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.
library/data/tags/src/testmod/java/org/quiltmc/qsl/tag/test/client/ClientTagsTestMod.java
Outdated
Show resolved
Hide resolved
library/data/tags/src/main/java/org/quiltmc/qsl/tag/api/package-info.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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(); |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
library/data/tags/src/main/java/org/quiltmc/qsl/tag/api/QuiltTagBuilder.java
Outdated
Show resolved
Hide resolved
library/data/tags/src/main/java/org/quiltmc/qsl/tag/api/package-info.java
Outdated
Show resolved
Hide resolved
library/data/tags/src/main/java/org/quiltmc/qsl/tag/impl/TagDelegate.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
public static void forceInit() { | ||
// noop. this only forces to run the static initializer. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
library/data/tags/src/main/java/org/quiltmc/qsl/tag/impl/TagRegistryImpl.java
Outdated
Show resolved
Hide resolved
library/data/tags/src/main/java/org/quiltmc/qsl/tag/impl/client/ClientTagRegistryManager.java
Outdated
Show resolved
Hide resolved
library/data/tags/src/main/java/org/quiltmc/qsl/tag/impl/QuiltTagHooks.java
Outdated
Show resolved
Hide resolved
library/data/tags/src/main/java/org/quiltmc/qsl/tag/mixin/RequiredTagListMixin.java
Outdated
Show resolved
Hide resolved
library/data/tags/src/main/java/org/quiltmc/qsl/tag/mixin/TagBuilderMixin.java
Outdated
Show resolved
Hide resolved
library/data/tags/src/testmod/java/org/quiltmc/qsl/tag/test/client/ClientTagsTestMod.java
Outdated
Show resolved
Hide resolved
…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>
library/data/tags/src/main/java/org/quiltmc/qsl/tag/api/package-info.java
Outdated
Show resolved
Hide resolved
library/data/tags/src/main/java/org/quiltmc/qsl/tag/api/TagRegistry.java
Outdated
Show resolved
Hide resolved
…istry.java Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com>
library/data/tags/src/main/java/org/quiltmc/qsl/tag/api/QuiltTag.java
Outdated
Show resolved
Hide resolved
|
||
/** | ||
* Interface implemented by {@link net.minecraft.tag.Tag} instances when QSL is present. | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay a compromise:
-
Note in the docs that casting to
QuiltTag
is a usage error. Encourage using thecast
function as it is currently named to get the functionality provided by this interface. -
Implementations of
Tag
may implement this interface. A default implementation is provided.
library/data/tags/src/main/java/org/quiltmc/qsl/tag/api/TagRegistry.java
Show resolved
Hide resolved
library/data/tags/src/main/java/org/quiltmc/qsl/tag/api/TagRegistry.java
Outdated
Show resolved
Hide resolved
@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<>(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
library/data/tags/src/main/java/org/quiltmc/qsl/tag/impl/TagRegistryImpl.java
Show resolved
Hide resolved
library/data/tags/src/main/java/org/quiltmc/qsl/tag/impl/TagRegistryImpl.java
Outdated
Show resolved
Hide resolved
|
||
@Override | ||
default boolean hasBeenReplaced() { | ||
return false; // The goal is to prevent hard-fails with custom Tag implementations. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
library/data/tags/src/testmod/java/org/quiltmc/qsl/tag/test/client/ClientTagsTestMod.java
Outdated
Show resolved
Hide resolved
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. |
Big PR, but very useful features, including:
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!