From 9b2b2be3a8108f015deabb0ed81b329188127b0d Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Wed, 24 Jan 2024 12:09:54 -0800 Subject: [PATCH] Back me up here! - Add @BackendImplemented annotation to API and use where needed. - Add @ApiStatus.NonExtendable to interfaces that are missing it. --- .../flywheel/api/BackendImplemented.java | 22 +++++++++++++++++++ .../jozufozu/flywheel/api/backend/Engine.java | 2 ++ .../flywheel/api/event/RenderContext.java | 2 ++ .../flywheel/api/instance/InstanceHandle.java | 3 +++ .../flywheel/api/instance/Instancer.java | 3 +++ .../api/instance/InstancerProvider.java | 2 ++ .../api/visual/DistanceUpdateLimiter.java | 3 +++ .../api/visual/VisualFrameContext.java | 2 ++ .../api/visual/VisualTickContext.java | 3 +++ .../visualization/VisualizationContext.java | 3 +++ .../api/visualization/VisualizationLevel.java | 2 +- 11 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/jozufozu/flywheel/api/BackendImplemented.java diff --git a/src/main/java/com/jozufozu/flywheel/api/BackendImplemented.java b/src/main/java/com/jozufozu/flywheel/api/BackendImplemented.java new file mode 100644 index 000000000..5babd1343 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/api/BackendImplemented.java @@ -0,0 +1,22 @@ +package com.jozufozu.flywheel.api; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + *

Indicates that the annotated API class, interface or method must not be extended, implemented or overridden, + * except by backend implementations.

+ * + *

API class, interface or method may not be marked {@code final} because it is extended by classes of registered backends + * but it is not supposed to be extended outside of backend implementations. Instances of classes and interfaces marked with this annotation + * may be cast to an internal implementing class within the active backend, leading to {@code ClassCastException} + * if a different implementation is provided by a client.

+ */ +@Documented +@Retention(RetentionPolicy.CLASS) +@Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.PACKAGE}) +public @interface BackendImplemented { +} diff --git a/src/main/java/com/jozufozu/flywheel/api/backend/Engine.java b/src/main/java/com/jozufozu/flywheel/api/backend/Engine.java index 3e9b7bd59..22c755acd 100644 --- a/src/main/java/com/jozufozu/flywheel/api/backend/Engine.java +++ b/src/main/java/com/jozufozu/flywheel/api/backend/Engine.java @@ -2,6 +2,7 @@ package com.jozufozu.flywheel.api.backend; import java.util.List; +import com.jozufozu.flywheel.api.BackendImplemented; import com.jozufozu.flywheel.api.event.RenderContext; import com.jozufozu.flywheel.api.event.RenderStage; import com.jozufozu.flywheel.api.instance.Instance; @@ -13,6 +14,7 @@ import net.minecraft.client.Camera; import net.minecraft.core.BlockPos; import net.minecraft.core.Vec3i; +@BackendImplemented public interface Engine extends InstancerProvider { /** * Create a plan that will be executed every frame. diff --git a/src/main/java/com/jozufozu/flywheel/api/event/RenderContext.java b/src/main/java/com/jozufozu/flywheel/api/event/RenderContext.java index 4108b9934..aa89eb32f 100644 --- a/src/main/java/com/jozufozu/flywheel/api/event/RenderContext.java +++ b/src/main/java/com/jozufozu/flywheel/api/event/RenderContext.java @@ -1,5 +1,6 @@ package com.jozufozu.flywheel.api.event; +import org.jetbrains.annotations.ApiStatus; import org.joml.Matrix4f; import com.mojang.blaze3d.vertex.PoseStack; @@ -9,6 +10,7 @@ import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.renderer.LevelRenderer; import net.minecraft.client.renderer.RenderBuffers; +@ApiStatus.NonExtendable public interface RenderContext { LevelRenderer renderer(); diff --git a/src/main/java/com/jozufozu/flywheel/api/instance/InstanceHandle.java b/src/main/java/com/jozufozu/flywheel/api/instance/InstanceHandle.java index 609d3f4cd..3d2b1264a 100644 --- a/src/main/java/com/jozufozu/flywheel/api/instance/InstanceHandle.java +++ b/src/main/java/com/jozufozu/flywheel/api/instance/InstanceHandle.java @@ -1,5 +1,8 @@ package com.jozufozu.flywheel.api.instance; +import com.jozufozu.flywheel.api.BackendImplemented; + +@BackendImplemented public interface InstanceHandle { void setChanged(); diff --git a/src/main/java/com/jozufozu/flywheel/api/instance/Instancer.java b/src/main/java/com/jozufozu/flywheel/api/instance/Instancer.java index 7d6032a9d..293265850 100644 --- a/src/main/java/com/jozufozu/flywheel/api/instance/Instancer.java +++ b/src/main/java/com/jozufozu/flywheel/api/instance/Instancer.java @@ -2,6 +2,8 @@ package com.jozufozu.flywheel.api.instance; import org.jetbrains.annotations.Nullable; +import com.jozufozu.flywheel.api.BackendImplemented; + /** * An instancer is how you interact with an instanced model. *

@@ -20,6 +22,7 @@ import org.jetbrains.annotations.Nullable; * * @param the data that represents a copy of the instanced model. */ +@BackendImplemented public interface Instancer { /** * @return a handle to a new copy of this model. diff --git a/src/main/java/com/jozufozu/flywheel/api/instance/InstancerProvider.java b/src/main/java/com/jozufozu/flywheel/api/instance/InstancerProvider.java index f20c17e2d..1cc987d50 100644 --- a/src/main/java/com/jozufozu/flywheel/api/instance/InstancerProvider.java +++ b/src/main/java/com/jozufozu/flywheel/api/instance/InstancerProvider.java @@ -1,8 +1,10 @@ package com.jozufozu.flywheel.api.instance; +import com.jozufozu.flywheel.api.BackendImplemented; import com.jozufozu.flywheel.api.event.RenderStage; import com.jozufozu.flywheel.api.model.Model; +@BackendImplemented public interface InstancerProvider { /** * Get an instancer for the given instance type, model, and render stage. diff --git a/src/main/java/com/jozufozu/flywheel/api/visual/DistanceUpdateLimiter.java b/src/main/java/com/jozufozu/flywheel/api/visual/DistanceUpdateLimiter.java index 25ffccfa6..66e039891 100644 --- a/src/main/java/com/jozufozu/flywheel/api/visual/DistanceUpdateLimiter.java +++ b/src/main/java/com/jozufozu/flywheel/api/visual/DistanceUpdateLimiter.java @@ -1,8 +1,11 @@ package com.jozufozu.flywheel.api.visual; +import org.jetbrains.annotations.ApiStatus; + /** * Interface for rate-limiting updates based on an object's distance from the camera. */ +@ApiStatus.NonExtendable public interface DistanceUpdateLimiter { /** * Check to see if an object at the given position relative to the camera should be updated. diff --git a/src/main/java/com/jozufozu/flywheel/api/visual/VisualFrameContext.java b/src/main/java/com/jozufozu/flywheel/api/visual/VisualFrameContext.java index 2fe30d1ad..23976d1cf 100644 --- a/src/main/java/com/jozufozu/flywheel/api/visual/VisualFrameContext.java +++ b/src/main/java/com/jozufozu/flywheel/api/visual/VisualFrameContext.java @@ -1,7 +1,9 @@ package com.jozufozu.flywheel.api.visual; +import org.jetbrains.annotations.ApiStatus; import org.joml.FrustumIntersection; +@ApiStatus.NonExtendable public interface VisualFrameContext { double cameraX(); diff --git a/src/main/java/com/jozufozu/flywheel/api/visual/VisualTickContext.java b/src/main/java/com/jozufozu/flywheel/api/visual/VisualTickContext.java index 7faa1ff29..31a1ab6a1 100644 --- a/src/main/java/com/jozufozu/flywheel/api/visual/VisualTickContext.java +++ b/src/main/java/com/jozufozu/flywheel/api/visual/VisualTickContext.java @@ -1,5 +1,8 @@ package com.jozufozu.flywheel.api.visual; +import org.jetbrains.annotations.ApiStatus; + +@ApiStatus.NonExtendable public interface VisualTickContext { double cameraX(); diff --git a/src/main/java/com/jozufozu/flywheel/api/visualization/VisualizationContext.java b/src/main/java/com/jozufozu/flywheel/api/visualization/VisualizationContext.java index f8c116359..b03b7609a 100644 --- a/src/main/java/com/jozufozu/flywheel/api/visualization/VisualizationContext.java +++ b/src/main/java/com/jozufozu/flywheel/api/visualization/VisualizationContext.java @@ -1,5 +1,7 @@ package com.jozufozu.flywheel.api.visualization; +import org.jetbrains.annotations.ApiStatus; + import com.jozufozu.flywheel.api.instance.InstancerProvider; import net.minecraft.core.Vec3i; @@ -7,6 +9,7 @@ import net.minecraft.core.Vec3i; /** * A context object passed on visual creation. */ +@ApiStatus.NonExtendable public interface VisualizationContext { /** * @return The {@link InstancerProvider} that the visual can use to get instancers to render models. diff --git a/src/main/java/com/jozufozu/flywheel/api/visualization/VisualizationLevel.java b/src/main/java/com/jozufozu/flywheel/api/visualization/VisualizationLevel.java index 6339cbad9..d4dbbca7d 100644 --- a/src/main/java/com/jozufozu/flywheel/api/visualization/VisualizationLevel.java +++ b/src/main/java/com/jozufozu/flywheel/api/visualization/VisualizationLevel.java @@ -6,7 +6,7 @@ import net.minecraft.world.level.LevelAccessor; * A marker interface custom levels can override to indicate * that block entities and entities inside the level should * render with Flywheel. - * + *
* {@link net.minecraft.client.Minecraft#level Minecraft#level} is special cased and will support Flywheel by default. */ public interface VisualizationLevel extends LevelAccessor {