quilt-loader
quilt-loader copied to clipboard
Add quilt's environment annotations, and deprecate fabric's.
Implements #53.
This uses specialized annotations for each side (since there are only two this shouldn't be a problem) rather than using the EnvType enum. This also means the names are shorter:
@Environment(EnvType.CLIENT)
@Environment(EnvType.SERVER)
@EnvironmentInterface(value = EnvType.CLIENT, itf = IRenderable.class)
now becomes:
@ClientOnly
@DedicatedServerOnly
@ClientOnlyInterface(IRenderable.class)
Both @ClientOnly and @DedicatedServerOnly also have a stripLambdas property (defaulting to true), which controls whether or not to also remove methods referenced in only those methods via lambdas. (This allows mods to disable lambda stripping if they don't want it for a particular method, although I'm not sure why).
This leaves only a single non-deprecated class in net.fabricmc.api: EnvType, which this PR doesn't touch.
Fabric's annotations are not processed by the new lambda-stripping functionality, to preserve compatibility.
How would you implement side-specific behavior with this?
The old code would have been something like this:
switch (FabricLoader.getInstance().getEnvironment()) {
EnvType.CLIENT -> LOGGER.info("We're on the client");
EnvType.SERVER -> LOGGER.info("Hello server");
}
@halotroop2288 As mentioned in the OP, EnvType is not touched. So your example would be:
switch (MinecraftQuiltLoader.getEnvironmentType()) {
EnvType.CLIENT -> LOGGER.info("We're on the client");
EnvType.SERVER -> LOGGER.info("Hello server");
}
as it is currently and will still be after this PR.
Leo brought up a useful suggestion on discord:
Leo, Agent of Cursed — Today at 10:33 man, it's too bad TYPE_USE annotations are weird we could've had public class ChestBlockEntity implements @ClientOnly ChestAnimationProgress
So, I'm going to add them since it makes a lot more sense to be able to do that than declare the interface twice. I'm not sure if this means I should remove @ClientOnlyInterface as well.
LambdAurora brought up another useful suggestion:
Question then If we have a client only package Does annotating the package will strip all its classes?
Loader doesn't do this yet - but it probably should, so I'm going to try adding them to this PR too.
As of https://github.com/QuiltMC/quilt-loader/pull/63/commits/a2e988759e4fb29ed6e7a5bc56fdf9889e756af8 this now strips annotated interfaces. For example:
@ClientOnlyInterface(IRenderable.class)
public class CentrifugeBlockEntity implements IRenderable {
}
can now be written as:
public class CentrifugeBlockEntity implements @ClientOnly IRenderable {
}
Okay, annotating a package-info class with @ClientOnly or @DedicatedServerOnly now works.
I'm not sure if I should remove @ClientOnlyInterface, @ClientOnlyInterfaces, @DedicatedServerOnlyInterface and @DedicatedServerOnlyInterfaces, since those just add clutter at this point?