Skip to content

Commit

Permalink
Remove dependency on mcdev-annotations, fixes #179
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Jul 20, 2024
1 parent 2cec25c commit 0bc00c6
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 19 deletions.
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();

Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -48,7 +48,7 @@ public interface ClientLoadAwareComponent extends Component {
* In <em>most</em> cases, this method will only be called once in an object's lifecycle,
* and it <em>should</em> be called as many times as the corresponding unloading event if applicable.
*/
@CheckEnv(Env.CLIENT)
@CheckEnvironment(EnvType.CLIENT)
@CalledByAsm
void loadClientside();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -47,7 +47,7 @@ public interface ClientUnloadAwareComponent extends Component {
* In <em>most</em> cases, this method will only be called once in an object's lifecycle,
* and it <em>should</em> be called as many times as the corresponding loading event if applicable.
*/
@CheckEnv(Env.CLIENT)
@CheckEnvironment(EnvType.CLIENT)
@CalledByAsm
void unloadClientside();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
*
* <p>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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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));
Expand All @@ -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());
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0bc00c6

Please sign in to comment.