From 0bc00c6e4c704bde1ac27467c2829a6be51dbb0e Mon Sep 17 00:00:00 2001 From: Pyrofab Date: Sat, 20 Jul 2024 20:52:19 +0200 Subject: [PATCH] Remove dependency on mcdev-annotations, fixes #179 --- build.gradle.kts | 1 - .../api/v3/component/ComponentContainer.java | 10 ++++---- .../load/ClientLoadAwareComponent.java | 6 ++--- .../load/ClientUnloadAwareComponent.java | 6 ++--- .../component/sync/AutoSyncedComponent.java | 6 ++--- .../cca/api/v3/util/CheckEnvironment.java | 23 +++++++++++++++++++ .../v3/entity/C2SSelfMessagingComponent.java | 8 +++---- changelog.md | 1 + 8 files changed, 42 insertions(+), 19 deletions(-) create mode 100644 cardinal-components-base/src/main/java/org/ladysnake/cca/api/v3/util/CheckEnvironment.java diff --git a/build.gradle.kts b/build.gradle.kts index 69352e9a..037a3426 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -65,7 +65,6 @@ allprojects { modLocalImplementation("org.ladysnake:elmendorf:${props["elmendorf_version"]}") compileOnly("com.google.code.findbugs:jsr305:3.0.2") - compileOnly("com.demonwav.mcdev:annotations:1.0") compileOnly("org.jetbrains:annotations:24.0.1") } diff --git a/cardinal-components-base/src/main/java/org/ladysnake/cca/api/v3/component/ComponentContainer.java b/cardinal-components-base/src/main/java/org/ladysnake/cca/api/v3/component/ComponentContainer.java index ab93c0d3..27085ed4 100644 --- a/cardinal-components-base/src/main/java/org/ladysnake/cca/api/v3/component/ComponentContainer.java +++ b/cardinal-components-base/src/main/java/org/ladysnake/cca/api/v3/component/ComponentContainer.java @@ -22,8 +22,7 @@ */ package org.ladysnake.cca.api.v3.component; -import com.demonwav.mcdev.annotations.CheckEnv; -import com.demonwav.mcdev.annotations.Env; +import net.fabricmc.api.EnvType; import net.minecraft.nbt.NbtCompound; import net.minecraft.registry.RegistryWrapper; import org.jetbrains.annotations.ApiStatus; @@ -36,6 +35,7 @@ import org.ladysnake.cca.api.v3.component.load.ServerUnloadAwareComponent; import org.ladysnake.cca.api.v3.component.tick.ClientTickingComponent; import org.ladysnake.cca.api.v3.component.tick.ServerTickingComponent; +import org.ladysnake.cca.api.v3.util.CheckEnvironment; import org.ladysnake.cca.api.v3.util.NbtSerializable; import org.ladysnake.cca.internal.base.GenericContainerBuilder; import org.ladysnake.cca.internal.base.asm.AsmGeneratedCallback; @@ -66,7 +66,7 @@ public interface ComponentContainer extends NbtSerializable { @AsmGeneratedCallback(ServerTickingComponent.class) void tickServerComponents(); - @CheckEnv(Env.CLIENT) + @CheckEnvironment(EnvType.CLIENT) @AsmGeneratedCallback(ClientTickingComponent.class) void tickClientComponents(); @@ -79,12 +79,12 @@ public interface ComponentContainer extends NbtSerializable { void onServerUnload(); @ApiStatus.Experimental - @CheckEnv(Env.CLIENT) + @CheckEnvironment(EnvType.CLIENT) @AsmGeneratedCallback(ClientLoadAwareComponent.class) void onClientLoad(); @ApiStatus.Experimental - @CheckEnv(Env.CLIENT) + @CheckEnvironment(EnvType.CLIENT) @AsmGeneratedCallback(ClientUnloadAwareComponent.class) void onClientUnload(); diff --git a/cardinal-components-base/src/main/java/org/ladysnake/cca/api/v3/component/load/ClientLoadAwareComponent.java b/cardinal-components-base/src/main/java/org/ladysnake/cca/api/v3/component/load/ClientLoadAwareComponent.java index c6ae4ccd..9af630f7 100644 --- a/cardinal-components-base/src/main/java/org/ladysnake/cca/api/v3/component/load/ClientLoadAwareComponent.java +++ b/cardinal-components-base/src/main/java/org/ladysnake/cca/api/v3/component/load/ClientLoadAwareComponent.java @@ -22,11 +22,11 @@ */ package org.ladysnake.cca.api.v3.component.load; -import com.demonwav.mcdev.annotations.CheckEnv; -import com.demonwav.mcdev.annotations.Env; +import net.fabricmc.api.EnvType; import net.minecraft.util.Identifier; import org.ladysnake.cca.api.v3.component.Component; import org.ladysnake.cca.api.v3.component.ComponentRegistryV3; +import org.ladysnake.cca.api.v3.util.CheckEnvironment; import org.ladysnake.cca.internal.base.asm.CalledByAsm; /** @@ -48,7 +48,7 @@ public interface ClientLoadAwareComponent extends Component { * In most cases, this method will only be called once in an object's lifecycle, * and it should be called as many times as the corresponding unloading event if applicable. */ - @CheckEnv(Env.CLIENT) + @CheckEnvironment(EnvType.CLIENT) @CalledByAsm void loadClientside(); } diff --git a/cardinal-components-base/src/main/java/org/ladysnake/cca/api/v3/component/load/ClientUnloadAwareComponent.java b/cardinal-components-base/src/main/java/org/ladysnake/cca/api/v3/component/load/ClientUnloadAwareComponent.java index a7a6ca7c..5fa15dfd 100644 --- a/cardinal-components-base/src/main/java/org/ladysnake/cca/api/v3/component/load/ClientUnloadAwareComponent.java +++ b/cardinal-components-base/src/main/java/org/ladysnake/cca/api/v3/component/load/ClientUnloadAwareComponent.java @@ -22,11 +22,11 @@ */ package org.ladysnake.cca.api.v3.component.load; -import com.demonwav.mcdev.annotations.CheckEnv; -import com.demonwav.mcdev.annotations.Env; +import net.fabricmc.api.EnvType; import net.minecraft.util.Identifier; import org.ladysnake.cca.api.v3.component.Component; import org.ladysnake.cca.api.v3.component.ComponentRegistryV3; +import org.ladysnake.cca.api.v3.util.CheckEnvironment; import org.ladysnake.cca.internal.base.asm.CalledByAsm; /** @@ -47,7 +47,7 @@ public interface ClientUnloadAwareComponent extends Component { * In most cases, this method will only be called once in an object's lifecycle, * and it should be called as many times as the corresponding loading event if applicable. */ - @CheckEnv(Env.CLIENT) + @CheckEnvironment(EnvType.CLIENT) @CalledByAsm void unloadClientside(); } diff --git a/cardinal-components-base/src/main/java/org/ladysnake/cca/api/v3/component/sync/AutoSyncedComponent.java b/cardinal-components-base/src/main/java/org/ladysnake/cca/api/v3/component/sync/AutoSyncedComponent.java index 55de7823..9e723ce2 100644 --- a/cardinal-components-base/src/main/java/org/ladysnake/cca/api/v3/component/sync/AutoSyncedComponent.java +++ b/cardinal-components-base/src/main/java/org/ladysnake/cca/api/v3/component/sync/AutoSyncedComponent.java @@ -22,8 +22,7 @@ */ package org.ladysnake.cca.api.v3.component.sync; -import com.demonwav.mcdev.annotations.CheckEnv; -import com.demonwav.mcdev.annotations.Env; +import net.fabricmc.api.EnvType; import net.minecraft.entity.Entity; import net.minecraft.nbt.NbtCompound; import net.minecraft.network.RegistryByteBuf; @@ -33,6 +32,7 @@ import org.jetbrains.annotations.Contract; import org.ladysnake.cca.api.v3.component.Component; import org.ladysnake.cca.api.v3.component.ComponentKey; +import org.ladysnake.cca.api.v3.util.CheckEnvironment; /** * A {@link Component} implementing this interface will have its data automatically @@ -95,7 +95,7 @@ default void writeSyncPacket(RegistryByteBuf buf, ServerPlayerEntity recipient) * such that it uses a different data format must override this method. * @see #writeSyncPacket(RegistryByteBuf, ServerPlayerEntity) */ - @CheckEnv(Env.CLIENT) + @CheckEnvironment(EnvType.CLIENT) default void applySyncPacket(RegistryByteBuf buf) { NbtCompound tag = buf.readNbt(); if (tag != null) { diff --git a/cardinal-components-base/src/main/java/org/ladysnake/cca/api/v3/util/CheckEnvironment.java b/cardinal-components-base/src/main/java/org/ladysnake/cca/api/v3/util/CheckEnvironment.java new file mode 100644 index 00000000..a8991a92 --- /dev/null +++ b/cardinal-components-base/src/main/java/org/ladysnake/cca/api/v3/util/CheckEnvironment.java @@ -0,0 +1,23 @@ +package org.ladysnake.cca.api.v3.util; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Indicates that the annotated method must only be called in a specific environment. + * + *

Unlike {@link Environment}, this annotation is purely informational and does not strip bytecode. + */ +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.SOURCE) +public @interface CheckEnvironment { + /** + * Returns the environment type that the annotated element requires. + */ + EnvType value(); +} diff --git a/cardinal-components-entity/src/main/java/org/ladysnake/cca/api/v3/entity/C2SSelfMessagingComponent.java b/cardinal-components-entity/src/main/java/org/ladysnake/cca/api/v3/entity/C2SSelfMessagingComponent.java index 28bf9954..1b33ad25 100644 --- a/cardinal-components-entity/src/main/java/org/ladysnake/cca/api/v3/entity/C2SSelfMessagingComponent.java +++ b/cardinal-components-entity/src/main/java/org/ladysnake/cca/api/v3/entity/C2SSelfMessagingComponent.java @@ -22,9 +22,8 @@ */ package org.ladysnake.cca.api.v3.entity; -import com.demonwav.mcdev.annotations.CheckEnv; -import com.demonwav.mcdev.annotations.Env; import com.mojang.datafixers.util.Unit; +import net.fabricmc.api.EnvType; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; import net.fabricmc.fabric.api.networking.v1.PacketSender; @@ -36,6 +35,7 @@ import org.ladysnake.cca.api.v3.component.ComponentKey; import org.ladysnake.cca.api.v3.component.ComponentProvider; import org.ladysnake.cca.api.v3.component.sync.C2SComponentPacketWriter; +import org.ladysnake.cca.api.v3.util.CheckEnvironment; import org.ladysnake.cca.internal.base.ComponentUpdatePayload; import org.ladysnake.cca.internal.entity.CardinalComponentsEntity; @@ -65,7 +65,7 @@ public interface C2SSelfMessagingComponent extends Component { * which is inefficient and may even produce incorrect results in some edge cases. * @see #sendC2SMessage(ComponentKey, C2SComponentPacketWriter) */ - @CheckEnv(Env.CLIENT) + @CheckEnvironment(EnvType.CLIENT) default void sendC2SMessage(C2SComponentPacketWriter writer) { ComponentProvider provider = (ComponentProvider) Objects.requireNonNull(MinecraftClient.getInstance().player); ComponentKey key = Objects.requireNonNull(provider.getComponentContainer().getKey(this)); @@ -78,7 +78,7 @@ default void sendC2SMessage(C2SComponentPacketWriter writer) { * @param key the key describing the component being sent an update * @param writer a {@link C2SComponentPacketWriter} writing the component's data to the packet */ - @CheckEnv(Env.CLIENT) + @CheckEnvironment(EnvType.CLIENT) static void sendC2SMessage(ComponentKey key, C2SComponentPacketWriter writer) { PacketSender sender = ClientPlayNetworking.getSender(); // checks that the player is in game RegistryByteBuf buf = new RegistryByteBuf(PacketByteBufs.create(), Objects.requireNonNull(MinecraftClient.getInstance().getNetworkHandler()).getRegistryManager()); diff --git a/changelog.md b/changelog.md index cf14afa2..917dafcd 100644 --- a/changelog.md +++ b/changelog.md @@ -3,6 +3,7 @@ Version 6.1.1 ------------------------------------------------------ **Fixes** - Fixed `C2SSelfMessagingComponent#sendC2SMessage` mistakenly adding the component ID to the custom data buffer +- Removed dependency on `com.demonwav.mcdev:annotations` - this should remove some errors in dev environments ------------------------------------------------------ Version 6.1.0