Split @Ref into @Ref(Reference) and @ResourceRef(Kind.class)

@Ref had two attributes of which exactly one had to be given, checked
only at pack load. One annotation per concept makes a wrong
combination a compile error; giving both still fails the load.
This commit is contained in:
piexel committed 2026-11-06 07:16:25 +01:00
1 parent c577b68c00
commit 264f754297
11 files changed
+89 -70

No files matched your search

+5 -13
View File
@@ -2,21 +2,13 @@ package com.volmit.config;
import java.lang.annotation.*;
/** Says what an option's text names: an entry of a platform registry, {@code @Ref(Reference.BLOCK) String block}, or
* a resource of the pack by its key, {@code @Ref(kind = LootTable.class) String table}, where {@code kind} is the type
* of a {@link com.volmit.resource.ResourceKind}: a host kind, the constants of
* {@link com.volmit.resource.PackResources}, or a kind some module of the pack registers. Studio then offers the
* registry's entries or the pack's keys of that kind. Give exactly one of the two. Allowed on {@code String} and
* {@link com.volmit.resource.ResourceId} options and on lists, sets and arrays of them, where it applies to every
* element; a {@code ResourceId} option naming a pack resource holds the id the pack gives the key it writes.
* Anything else fails the pack load.
/** Says that an option's text names an entry of a platform registry, {@code @Ref(Reference.BLOCK) String block}, so
* studio offers the registry's entries. Allowed on {@code String} and {@link com.volmit.resource.ResourceId} options
* and on lists, sets and arrays of them, where it applies to every element. A resource of the pack is named with
* {@link ResourceRef} instead; an option with both, or with either on any other type, fails the pack load.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Ref {
/** The platform registry the text names; give one, or none when {@link #kind} is given. */
Reference[] value() default {};
/** The type of the resource kind the text names by key; {@code void.class}, the default, when {@link #value} is given. */
Class<?> kind() default void.class;
Reference value();
}
@@ -2,7 +2,7 @@ package com.volmit.config;
/** The platform registry a text option names, so studio can offer the matching completion list: entries of the
* server's registries, such as {@code minecraft:stone}, including those that data packs and mods add, and the host's
* own noise generators. Resources of the pack are named by their kind instead, {@code @Ref(kind = ...)}.
* own noise generators. Resources of the pack are named by their kind instead, with {@link ResourceRef}.
*/
public enum Reference {
/** A block type, such as {@code minecraft:stone}. {@link com.volmit.block.BlockState} options are block references without {@link Ref}. */
@@ -0,0 +1,16 @@
package com.volmit.config;
import java.lang.annotation.*;
/** Says that an option's text names a resource of the pack by its key, {@code @ResourceRef(LootTable.class) String table},
* where the value is the type of a {@link com.volmit.resource.ResourceKind}: a host kind, the constants of
* {@link com.volmit.resource.PackResources}, or a kind some module of the pack registers. Studio then offers the pack's
* keys of that kind. Allowed on {@code String} and {@link com.volmit.resource.ResourceId} options and on lists, sets and
* arrays of them, where it applies to every element; a {@code ResourceId} option holds the id the pack gives the key it
* writes. An option with both this and {@link Ref}, or with either on any other type, fails the pack load.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface ResourceRef {
Class<?> value();
}
@@ -5,6 +5,7 @@ import com.volmit.config.MaxNumber;
import com.volmit.config.MinNumber;
import com.volmit.config.Ref;
import com.volmit.config.Reference;
import com.volmit.config.ResourceRef;
import com.volmit.config.Snippet;
import com.volmit.resource.PackResources;
import com.volmit.resource.ResourceId;
@@ -40,11 +41,11 @@ public final class NoiseStyle {
@Desc("How far the noise is stretched: above 1 wider, below 1 tighter.")
private double zoom = 1;
@Ref(kind = PackExpression.class)
@ResourceRef(PackExpression.class)
@Desc("An expression of the pack that gives the noise instead of the style.")
private ResourceId expression;
@Ref(kind = PackImageMap.class)
@ResourceRef(PackImageMap.class)
@Desc("An image map of the pack that gives the noise instead of the style, when there is no expression.")
private ResourceId imageMap;