diff --git a/common/src/main/java/foundry/veil/api/flare/data/effect/FlareEffectTemplate.java b/common/src/main/java/foundry/veil/api/flare/data/effect/FlareEffectTemplate.java index 68f2c7c17..473a143f3 100644 --- a/common/src/main/java/foundry/veil/api/flare/data/effect/FlareEffectTemplate.java +++ b/common/src/main/java/foundry/veil/api/flare/data/effect/FlareEffectTemplate.java @@ -9,37 +9,41 @@ import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @since 2.5.0 */ -public record FlareEffectTemplate(List effectLayers) { - +public final class FlareEffectTemplate { + public static final Codec CODEC = CodecUtil.singleOrList(FlareEffectLayer.CODEC).fieldOf("layers").xmap(FlareEffectTemplate::new, FlareEffectTemplate::effectLayers).codec(); - + private final List effectLayers; + + public FlareEffectTemplate(List effectLayers) { ArrayList enabledLayers = new ArrayList<>(effectLayers.size()); - + for (FlareEffectLayer effectLayer : effectLayers) { if (!effectLayer.isDisabled()) { enabledLayers.add(effectLayer); } } - - this.effectLayers = Collections.unmodifiableList(new ObjectArrayList<>(enabledLayers)); + + this.effectLayers = List.copyOf(new ObjectArrayList<>(enabledLayers)); } - + public void render(EffectHost host, MatrixStack matrixStack, float partialTick, @Nullable Map shellOverrides) { for (FlareEffectLayer effectLayer : this.effectLayers) { effectLayer.render(host, matrixStack, partialTick, shellOverrides); } } - + public void render(EffectHost host, MatrixStack matrixStack, float partialTick) { this.render(host, matrixStack, partialTick, null); } + + public List effectLayers() { + return effectLayers; + } + } diff --git a/common/src/main/java/foundry/veil/api/flare/data/effect/FlareMaterial.java b/common/src/main/java/foundry/veil/api/flare/data/effect/FlareMaterial.java index 254becc69..0265023fc 100644 --- a/common/src/main/java/foundry/veil/api/flare/data/effect/FlareMaterial.java +++ b/common/src/main/java/foundry/veil/api/flare/data/effect/FlareMaterial.java @@ -23,12 +23,7 @@ /** * @since 2.5.0 */ -public record FlareMaterial( - String clazz, - ResourceLocation renderTypeLocation, - boolean randomizeSeed, - Map> properties -) { +public final class FlareMaterial { public static Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( Codec.STRING.fieldOf("class").forGetter(FlareMaterial::clazz), ResourceLocation.CODEC.fieldOf("renderType").forGetter(FlareMaterial::renderTypeLocation), @@ -42,14 +37,23 @@ public record FlareMaterial( .optionalFieldOf("properties", Map.of()) .forGetter(FlareMaterial::properties) ).apply(instance, (clazz, renderType, randomizeSeed, properties) -> new FlareMaterial(clazz, renderType, randomizeSeed, new Object2ObjectArrayMap<>(properties)))); - - public FlareMaterial { + private final String clazz; + private final ResourceLocation renderTypeLocation; + private final boolean randomizeSeed; + private final Map> properties; + + + public FlareMaterial(String clazz, ResourceLocation renderTypeLocation, boolean randomizeSeed, Map> properties) { properties.put("_ClipBrightness", new FloatProperty(1.0f)); if (randomizeSeed) { properties.put("_Seed", RandomFloatProperty.INSTANCE); } + this.clazz = clazz; + this.renderTypeLocation = renderTypeLocation; + this.randomizeSeed = randomizeSeed; + this.properties = Map.copyOf(properties); } - + public void applyProperties(EffectHost host, @Nullable ShaderInstance shader, Map>> modifiers) { if (shader == null) { return; @@ -57,23 +61,23 @@ public void applyProperties(EffectHost host, @Nullable ShaderInstance shader, Ma for (Map.Entry> entry : this.properties.entrySet()) { Property property = entry.getValue(); Class propertyClass = property.getClass(); - + if (propertyClass.getAnnotation(InapplicableProperty.class) != null) { continue; } - + String name = entry.getKey(); if (propertyClass.getAnnotation(ModelProperty.class) == null) { PropertyModifier.modifyProperty(host, this.clazz, property, modifiers.get(name)); } - + property.applyValue(name, shader); if (property instanceof InvertibleProperty invertibleProperty) { invertibleProperty.applyInverseValue(name, shader); } } } - + public void resetProperties(EffectHost host, @Nullable ShaderInstance shader) { if (shader == null) { return; @@ -85,4 +89,21 @@ public void resetProperties(EffectHost host, @Nullable ShaderInstance shader) { property.resetOverrideValue(); } } + + public String clazz() { + return clazz; + } + + public ResourceLocation renderTypeLocation() { + return renderTypeLocation; + } + + public boolean randomizeSeed() { + return randomizeSeed; + } + + public Map> properties() { + return properties; + } + } diff --git a/common/src/main/java/foundry/veil/api/flare/data/effect/FlareModule.java b/common/src/main/java/foundry/veil/api/flare/data/effect/FlareModule.java index cf7e8fe14..ffb4b9968 100644 --- a/common/src/main/java/foundry/veil/api/flare/data/effect/FlareModule.java +++ b/common/src/main/java/foundry/veil/api/flare/data/effect/FlareModule.java @@ -2,25 +2,30 @@ import com.mojang.serialization.Codec; -import java.util.Collections; import java.util.Map; /** * @since 2.5.0 */ -public record FlareModule(Map subModules) { - +public final class FlareModule { + public static final Codec CODEC = Codec.unboundedMap(Codec.STRING, FlareSubModule.CODEC) .xmap(FlareModule::new, FlareModule::subModules) .fieldOf("subModules") .codec(); - + private final Map subModules; + + public FlareModule(Map subModules) { - this.subModules = Collections.unmodifiableMap(subModules); + this.subModules = Map.copyOf(subModules); } - + public FlareSubModule getSubModule(String name) { return this.subModules.get(name); } - + + public Map subModules() { + return subModules; + } + } diff --git a/common/src/main/java/foundry/veil/api/flare/data/effect/FlareSubModule.java b/common/src/main/java/foundry/veil/api/flare/data/effect/FlareSubModule.java index 88c61c1a0..a5a1a9d06 100644 --- a/common/src/main/java/foundry/veil/api/flare/data/effect/FlareSubModule.java +++ b/common/src/main/java/foundry/veil/api/flare/data/effect/FlareSubModule.java @@ -9,7 +9,6 @@ import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.Nullable; -import java.util.Collections; import java.util.List; import java.util.Map; @@ -18,23 +17,25 @@ /** * @since 2.5.0 */ -public record FlareSubModule(List templates) { - +public final class FlareSubModule { + public static final Codec CODEC = Codec.either( ResourceLocation.CODEC.listOf(), ResourceLocation.CODEC ) .xmap(either -> either.map(FlareSubModule::new, single -> new FlareSubModule(List.of(single))), subModule -> subModule.templates.size() == 1 ? Either.right(subModule.templates.getFirst()) : Either.left(subModule.templates)); - + private final List templates; + + public FlareSubModule(List templates) { - this.templates = Collections.unmodifiableList(templates); + this.templates = List.copyOf(templates); } - + public void render(EffectHost host, MatrixStack matrixStack, float partialTick) { this.render(host, matrixStack, partialTick, null); } - + public void render(EffectHost host, MatrixStack matrixStack, float partialTick, @Nullable Map shellOverrides) { for (ResourceLocation templateLocation : this.templates) { FlareEffectTemplate template = FlareEffectManager.getTemplate(templateLocation); @@ -45,4 +46,9 @@ public void render(EffectHost host, MatrixStack matrixStack, float partialTick, template.render(host, matrixStack, partialTick, shellOverrides); } } + + public List templates() { + return templates; + } + } diff --git a/common/src/main/java/foundry/veil/api/flare/data/model/FlareBakedQuad.java b/common/src/main/java/foundry/veil/api/flare/data/model/FlareBakedQuad.java index 6a9cf11c3..f5d46b17c 100644 --- a/common/src/main/java/foundry/veil/api/flare/data/model/FlareBakedQuad.java +++ b/common/src/main/java/foundry/veil/api/flare/data/model/FlareBakedQuad.java @@ -3,45 +3,48 @@ import com.mojang.blaze3d.vertex.VertexConsumer; import net.minecraft.client.renderer.LightTexture; import net.minecraft.client.renderer.texture.OverlayTexture; -import org.joml.Vector3fc; /** * @since 2.5.0 */ -public record FlareBakedQuad(float[] vertexData, Vector3fc normal) { - +public class FlareBakedQuad { + private final float[] vertexData; + + public FlareBakedQuad(float[] vertexData) { + this.vertexData = vertexData; + } + public void putBakedQuadInto(VertexConsumer buffer) { this.putBakedQuadInto(buffer, 1.0F, 1.0F, 1.0F, 1.0F, LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY); } - + public void putBakedQuadInto(VertexConsumer buffer, float red, float green, float blue, float alpha, int packedLight, int packedOverlay) { - float[] vertexData = this.vertexData(); - Vector3fc normal = this.normal(); - + float[] vertexData = this.vertexData; + for (int i = 0; i < 4; i++) { - int j = i * 5; + int j = i * 8; buffer.addVertex(vertexData[j], vertexData[j + 1], vertexData[j + 2]) - .setUv(vertexData[j + 3], vertexData[j + 4]) - .setNormal(normal.x(), normal.y(), normal.z()) + .setNormal(vertexData[j + 3], vertexData[j + 4], vertexData[j + 5]) + .setUv(vertexData[j + 6], vertexData[j + 7]) .setColor(red, green, blue, alpha) .setLight(packedLight) .setOverlay(packedOverlay); - + } } - + public void putBakedQuadInto(VertexConsumer buffer, float red, float green, float blue, float alpha, int[] lightmap, int packedOverlay) { - float[] vertexData = this.vertexData(); - Vector3fc normal = this.normal(); - + float[] vertexData = this.vertexData; + for (int i = 0; i < 4; i++) { - int j = i * 5; + int j = i * 8; buffer.addVertex(vertexData[j], vertexData[j + 1], vertexData[j + 2]) - .setUv(vertexData[j + 3], vertexData[j + 4]) - .setNormal(normal.x(), normal.y(), normal.z()) + .setNormal(vertexData[j + 3], vertexData[j + 4], vertexData[j + 5]) + .setUv(vertexData[j + 6], vertexData[j + 7]) .setColor(red, green, blue, alpha) .setLight(lightmap[i]) .setOverlay(packedOverlay); } } + } diff --git a/common/src/main/java/foundry/veil/api/flare/data/model/FlareShell.java b/common/src/main/java/foundry/veil/api/flare/data/model/FlareShell.java index c2d0229c6..7c665e150 100644 --- a/common/src/main/java/foundry/veil/api/flare/data/model/FlareShell.java +++ b/common/src/main/java/foundry/veil/api/flare/data/model/FlareShell.java @@ -18,12 +18,17 @@ * @author GuyApooye * @since 2.5.0 */ -public record FlareShell(List elements) implements UnbakedShell { - +public final class FlareShell implements UnbakedShell { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( ShellElement.CODEC.listOf().fieldOf("elements").forGetter(FlareShell::elements) ).apply(instance, FlareShell::new)); - + private final List elements; + + public FlareShell(List elements) { + this.elements = List.copyOf(elements); + } + @Override public @Nullable BakedShell bake() { SimpleBakedShell.Builder builder = new SimpleBakedShell.Builder(); @@ -32,12 +37,13 @@ public record FlareShell(List elements) implements UnbakedShell { builder.addFace(ShellBakery.bakeQuad(element, entry.getValue(), entry.getKey())); } } - + return builder.build(); } - + @Override public List elements() { return new ArrayList<>(this.elements); } + } diff --git a/common/src/main/java/foundry/veil/api/flare/data/model/ShellElement.java b/common/src/main/java/foundry/veil/api/flare/data/model/ShellElement.java index 74c182d23..1839b9d0a 100644 --- a/common/src/main/java/foundry/veil/api/flare/data/model/ShellElement.java +++ b/common/src/main/java/foundry/veil/api/flare/data/model/ShellElement.java @@ -7,20 +7,12 @@ import org.jetbrains.annotations.Nullable; import org.joml.Vector3fc; -import java.util.Collections; -import java.util.EnumMap; -import java.util.Map; -import java.util.Optional; +import java.util.*; /** * @since 2.5.0 */ -public record ShellElement( - Vector3fc from, - Vector3fc to, - @Nullable ShellElementRotation rotation, - Map faces -) { +public final class ShellElement { public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( CodecUtil.VECTOR3FC_CODEC.fieldOf("from").forGetter(ShellElement::from), CodecUtil.VECTOR3FC_CODEC.fieldOf("to").forGetter(ShellElement::to), @@ -30,4 +22,37 @@ public record ShellElement( Map facesMap = faces.isEmpty() ? Collections.emptyMap() : Collections.unmodifiableMap(new EnumMap<>(faces)); return new ShellElement(from, to, rotation.orElse(null), facesMap); })); + private final Vector3fc from; + private final Vector3fc to; + private final @Nullable ShellElementRotation rotation; + private final Map faces; + + public ShellElement( + Vector3fc from, + Vector3fc to, + @Nullable ShellElementRotation rotation, + Map faces + ) { + this.from = from; + this.to = to; + this.rotation = rotation; + this.faces = Map.copyOf(faces); + } + + public Vector3fc from() { + return from; + } + + public Vector3fc to() { + return to; + } + + public @Nullable ShellElementRotation rotation() { + return rotation; + } + + public Map faces() { + return faces; + } + } diff --git a/common/src/main/java/foundry/veil/api/flare/model/ShellBakery.java b/common/src/main/java/foundry/veil/api/flare/model/ShellBakery.java index 98f910462..a0c98436b 100644 --- a/common/src/main/java/foundry/veil/api/flare/model/ShellBakery.java +++ b/common/src/main/java/foundry/veil/api/flare/model/ShellBakery.java @@ -56,7 +56,7 @@ public static FlareBakedQuad bakeQuad( ShellElementRotation rotation) { Vector3f normal = facing.step(); float[] vertexData = makeVertices(face.uv(), normal, facing, setupShape(from, to), rotation); - return new FlareBakedQuad(vertexData, normal); + return new FlareBakedQuad(vertexData); } private static float[] makeVertices(ShellFaceUV uvs, Vector3f normal, Direction direction, float[] posDiv16, @Nullable ShellElementRotation rotation) { @@ -72,13 +72,13 @@ private static float[] makeVertices(ShellFaceUV uvs, Vector3f normal, Direction rotationMatrix.transformDirection(normal); } for (int i = 0; i < 4; i++) { - bakeVertex(vertexData, i, direction, uvs, posDiv16, rotation, rotationMatrix); + bakeVertex(vertexData, i, normal, direction, uvs, posDiv16, rotation, rotationMatrix); } return vertexData; } - private static void bakeVertex(float[] vertexData, int vertexIndex, Direction direction, ShellFaceUV shellFaceUV, float[] posDiv16, @Nullable ShellElementRotation rotation, @Nullable Matrix4f transform) { + private static void bakeVertex(float[] vertexData, int vertexIndex, Vector3f normal, Direction direction, ShellFaceUV shellFaceUV, float[] posDiv16, @Nullable ShellElementRotation rotation, @Nullable Matrix4f transform) { FaceInfo.VertexInfo vertexInfo = FaceInfo.fromFacing(direction).getVertexInfo(vertexIndex); Vector3f pos = new Vector3f(posDiv16[vertexInfo.xFace], posDiv16[vertexInfo.yFace], posDiv16[vertexInfo.zFace]); if (rotation != null && transform != null) { @@ -87,7 +87,7 @@ private static void bakeVertex(float[] vertexData, int vertexIndex, Direction di Vector3f offset = transform.transformPosition(new Vector3f(pos.x() - origin.x(), pos.y() - origin.y(), pos.z() - origin.z())); pos.set(offset.x() + origin.x(), offset.y() + origin.y(), offset.z() + origin.z()); } - fillVertex(vertexData, vertexIndex, pos, shellFaceUV); + fillVertex(vertexData, vertexIndex, pos, normal, shellFaceUV); } private static float[] setupShape(Vector3fc min, Vector3fc max) { @@ -102,12 +102,15 @@ private static float[] setupShape(Vector3fc min, Vector3fc max) { return vertexPosition; } - private static void fillVertex(float[] vertexData, int vertexIndex, Vector3f pos, ShellFaceUV shellFaceUV) { + private static void fillVertex(float[] vertexData, int vertexIndex, Vector3f pos, Vector3f normal, ShellFaceUV shellFaceUV) { int i = vertexIndex * 5; vertexData[i] = pos.x(); vertexData[i + 1] = pos.y(); vertexData[i + 2] = pos.z(); - vertexData[i + 3] = shellFaceUV.getU(vertexIndex) / 16.0F; - vertexData[i + 4] = shellFaceUV.getV(vertexIndex) / 16.0F; + vertexData[i + 3] = normal.z(); + vertexData[i + 4] = normal.z(); + vertexData[i + 5] = normal.z(); + vertexData[i + 6] = shellFaceUV.getU(vertexIndex) / 16.0F; + vertexData[i + 7] = shellFaceUV.getV(vertexIndex) / 16.0F; } } diff --git a/common/src/main/java/foundry/veil/api/flare/modifier/Controller.java b/common/src/main/java/foundry/veil/api/flare/modifier/Controller.java index b9892c90a..6ee59a813 100644 --- a/common/src/main/java/foundry/veil/api/flare/modifier/Controller.java +++ b/common/src/main/java/foundry/veil/api/flare/modifier/Controller.java @@ -1,48 +1,18 @@ package foundry.veil.api.flare.modifier; import foundry.veil.api.client.property.Property; -import foundry.veil.api.flare.EffectHost; import foundry.veil.api.flare.data.FloatCurve; /** - * Controllers collect values from {@link EffectHost}s to be used to evaluate {@link FloatCurve}s and modify {@link Property}s. + * Controllers collect values from sources to be used to evaluate {@link FloatCurve FloatCurves} and modify {@link Property Properties}. * * @author GuyApooye - * @since 2.5.0 + * @since 2.5.2 */ -public class Controller { - - protected final ControllerIdentifier identifier; - protected final EffectHost host; - protected float value; - - public Controller(String name, EffectHost host) { - this(new ControllerIdentifier(name, host), host); - } - - public Controller(ControllerIdentifier identifier, EffectHost host) { - this.identifier = identifier; - this.host = host; - } - - protected void initialize() { - this.update(0.0f); - } - - public void update(float partialTick) { - this.host.update(partialTick); - this.value = this.getUpdatedValue(); - } - - protected float getUpdatedValue() { - return this.host.getValue(this.identifier.name()); - } - - public float getValue() { - return this.value; - } - - public ControllerIdentifier getIdentifier() { - return this.identifier; - } +public sealed interface Controller permits GlobalController, HostBoundController { + default void initialize() {} + void update(float partialTick); + float getUpdatedValue(); + float getValue(); + String getName(); } diff --git a/common/src/main/java/foundry/veil/api/flare/modifier/ControllerIdentifier.java b/common/src/main/java/foundry/veil/api/flare/modifier/ControllerIdentifier.java deleted file mode 100644 index b219c20a9..000000000 --- a/common/src/main/java/foundry/veil/api/flare/modifier/ControllerIdentifier.java +++ /dev/null @@ -1,19 +0,0 @@ -package foundry.veil.api.flare.modifier; - -import foundry.veil.api.flare.EffectHost; -import org.jetbrains.annotations.NotNull; - -/** - * @since 2.5.0 - */ -public record ControllerIdentifier(String name, String host) { - - public ControllerIdentifier(String name, EffectHost host) { - this(name, host.getName()); - } - - @Override - public @NotNull String toString() { - return this.name + "$" + this.host; - } -} diff --git a/common/src/main/java/foundry/veil/api/flare/modifier/ControllerManager.java b/common/src/main/java/foundry/veil/api/flare/modifier/ControllerManager.java index 626cf2a59..fe08a68da 100644 --- a/common/src/main/java/foundry/veil/api/flare/modifier/ControllerManager.java +++ b/common/src/main/java/foundry/veil/api/flare/modifier/ControllerManager.java @@ -1,13 +1,14 @@ package foundry.veil.api.flare.modifier; -import com.google.common.collect.HashBasedTable; import com.google.common.collect.Table; +import com.google.common.collect.Tables; import foundry.veil.VeilClient; import foundry.veil.api.flare.EffectHost; import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Map; +import java.util.WeakHashMap; /** * @since 2.5.0 @@ -19,7 +20,7 @@ public class ControllerManager { *

Rows - Controllers

*

Columns - Hosts

*/ - private final Table controllers = HashBasedTable.create(); + private final Table controllers = Tables.newCustomTable(new WeakHashMap<>(), WeakHashMap::new); private final Map globalControllers = new HashMap<>(); public ControllerManager() { @@ -27,17 +28,18 @@ public ControllerManager() { } public void addController(Controller controller) { - String name = controller.getIdentifier().name(); - String host = controller.getIdentifier().host(); + String name = controller.getName(); if (name.startsWith("global::") || controller instanceof GlobalController) { throw new IllegalArgumentException("Global controllers should be "); } else { - this.controllers.put(name, host, controller); + HostBoundController hostBound = ((HostBoundController) controller); + String host = hostBound.getHost(); + this.controllers.put(name, host, hostBound); } } private void addGlobalController(GlobalController globalController) { - String name = globalController.getIdentifier().name(); + String name = globalController.getName(); this.globalControllers.put(name, globalController); } @@ -50,7 +52,7 @@ private void addGlobalController(GlobalController globalController) { public Controller getOrCreateController(String name, EffectHost host) { Controller controller = this.getController(name, host.getName()); if (controller == null) { - controller = new Controller(name, host); + controller = new HostBoundController(name, host); controller.initialize(); this.addController(controller); } diff --git a/common/src/main/java/foundry/veil/api/flare/modifier/GlobalController.java b/common/src/main/java/foundry/veil/api/flare/modifier/GlobalController.java index 6d65424e8..2b4a20b25 100644 --- a/common/src/main/java/foundry/veil/api/flare/modifier/GlobalController.java +++ b/common/src/main/java/foundry/veil/api/flare/modifier/GlobalController.java @@ -1,16 +1,31 @@ package foundry.veil.api.flare.modifier; /** - * Global controller have no host and collect their value locally. + * A controller that collects its value locally. * * @author GuyApooye * @see RandomnessController * @since 2.5.0 */ -public abstract class GlobalController extends Controller { +public abstract non-sealed class GlobalController implements Controller { + private final String name; + public GlobalController(String name) { - super(new ControllerIdentifier("global::" + name, "global"), null); + this.name = "global::" + name; + } + + @Override + public void update(float partialTick) { + } + + @Override + public float getValue() { + return this.getUpdatedValue(); + } + + @Override + public String getName() { + return name; } - } diff --git a/common/src/main/java/foundry/veil/api/flare/modifier/HostBoundController.java b/common/src/main/java/foundry/veil/api/flare/modifier/HostBoundController.java new file mode 100644 index 000000000..39b4c0701 --- /dev/null +++ b/common/src/main/java/foundry/veil/api/flare/modifier/HostBoundController.java @@ -0,0 +1,52 @@ +package foundry.veil.api.flare.modifier; + +import foundry.veil.api.flare.EffectHost; + +/** + * A controller that collects values from {@link EffectHost EffectHosts}. + * + * @author GuyApooye + * @since 2.5.0 + */ +public non-sealed class HostBoundController implements Controller { + + private final String name; + private final String hostName; + protected final EffectHost host; + protected float value; + + public HostBoundController(String name, EffectHost host) { + this.name = name; + this.hostName = host.getName(); + this.host = host; + } + + @Override + public void initialize() { + this.update(0.0f); + } + + @Override + public void update(float partialTick) { + this.host.update(partialTick); + this.value = this.getUpdatedValue(); + } + + @Override + public float getUpdatedValue() { + return this.host.getValue(this.name); + } + + @Override + public float getValue() { + return this.value; + } + + public String getName() { + return this.name; + } + + public String getHost() { + return this.hostName; + } +} diff --git a/common/src/main/java/foundry/veil/api/flare/modifier/PropertyModifier.java b/common/src/main/java/foundry/veil/api/flare/modifier/PropertyModifier.java index 1ee0a225b..050f0149e 100644 --- a/common/src/main/java/foundry/veil/api/flare/modifier/PropertyModifier.java +++ b/common/src/main/java/foundry/veil/api/flare/modifier/PropertyModifier.java @@ -88,7 +88,8 @@ public String inputControllerName() { public PropertyModifierMode mode() { return this.mode; } - + + @ApiStatus.Experimental public Optional> molangExpressions() { return this.optionalMolang; } @@ -127,7 +128,7 @@ public static void modifyProperty(EffectHost host, @Nullable String clazz, Prope return; } for (PropertyModifier modifier : modifiers) { - if (clazz != null && Objects.equals(clazz, modifier.clazz)) { + if (clazz != null && !Objects.equals(clazz, modifier.clazz)) { continue; } modifier.apply(host, property); diff --git a/common/src/main/java/foundry/veil/api/flare/modifier/RandomnessController.java b/common/src/main/java/foundry/veil/api/flare/modifier/RandomnessController.java index 38069773b..672051284 100644 --- a/common/src/main/java/foundry/veil/api/flare/modifier/RandomnessController.java +++ b/common/src/main/java/foundry/veil/api/flare/modifier/RandomnessController.java @@ -3,7 +3,7 @@ import net.minecraft.util.RandomSource; /** - * Controller with a random value each time {@link Controller#getValue()} is called. + * Controller with a random value each time {@link HostBoundController#getValue()} is called. * * @author GuyApooye * @since 2.5.0 @@ -19,12 +19,7 @@ private RandomnessController(String name) { } @Override - protected float getUpdatedValue() { - return this.value; - } - - @Override - public float getValue() { - return this.value = this.randomSource.nextFloat(); + public float getUpdatedValue() { + return this.randomSource.nextFloat(); } } diff --git a/common/src/main/resources/assets/veil/pinwheel/shaders/include/hlsl_utilities.glsl b/common/src/main/resources/assets/veil/pinwheel/shaders/include/hlsl_utilities.glsl index 6ead47e20..1b3f618fa 100644 --- a/common/src/main/resources/assets/veil/pinwheel/shaders/include/hlsl_utilities.glsl +++ b/common/src/main/resources/assets/veil/pinwheel/shaders/include/hlsl_utilities.glsl @@ -1,12 +1,15 @@ //Utilities for making Flare shaders or for porting HLSL shaders to GLSL. +#include veil:space_helper +#veil:buffer veil:camera VeilCamera + uniform mat4 ModelToWorld; uniform mat4 IModelToWorld; float saturate(float x) { return clamp(x, 0.0, 1.0); } -float saturate(vec2 x) { return clamp(x, 0.0, 1.0); } -float saturate(vec3 x) { return clamp(x, 0.0, 1.0); } -float saturate(vec4 x) { return clamp(x, 0.0, 1.0); } +vec2 saturate(vec2 x) { return clamp(x, 0.0, 1.0); } +vec3 saturate(vec3 x) { return clamp(x, 0.0, 1.0); } +vec4 saturate(vec4 x) { return clamp(x, 0.0, 1.0); } float lerp(float x, float y, float s) { return x + s * (y - x); } vec2 lerp(vec2 x, vec2 y, float s) { return x + s * (y - x); } vec2 lerp(vec2 x, vec2 y, vec2 s) { return x + s * (y - x); } @@ -41,7 +44,7 @@ vec4 modelToWorldSpace(vec4 model) { return ModelToWorld * model; } vec4 localToModelSpace(vec4 world) { - return IModelToWorld * (world + vec4(VeilCamera.CameraPosition, 1.0)); + return IModelToWorld * (world + vec4(VeilCamera.CameraPosition, 0.0)); } vec4 modelToLocalSpace(vec4 model) { return (ModelToWorld * model) - vec4(VeilCamera.CameraPosition, 0.0); diff --git a/wiki/Flare.md b/wiki/Flare.md index 256c39810..c5edafdb2 100644 --- a/wiki/Flare.md +++ b/wiki/Flare.md @@ -21,19 +21,19 @@ some hold shader uniforms, some hold model data, and some may hold both. { //Required //This name is used when applying a uniform to a shader - "name": "name", + "name": "Color", //Required //This defines what type of data this property should hold //By default veil implements: bool, int, float, vec2, vec3, vec4, mat3, mat4, sampler2d //If the built-in types don't match your needs, you may register your own ones //Types registered by other mods must begin with "modid:" - "type": "type", + "type": "vec3", //Required //The beginning value of the property, it must fit the type, ie: //floats are single numbers ( 1.52 ), vectors are arrays ( [1.2, 1.3] ) //matrices are arrays of arrays ( [[1.2, 0 ,0], [0, 1.2, 0], [0, 0, 1.2]] ) //and sampler2d s are textures ( "veil:textures/foo/bar.png" ) - "value": 1 + "value": [0.3, 0.6, 0.9] } ``` @@ -51,7 +51,7 @@ and append the result it in a property. //The class the modifier should apply to. //If this field isn't present or the output property holds model data, //the modifier will apply to all classes in the effect. - "class": "class", + "class": "plumeA", //Required //Input controller "controller": "throttle", @@ -79,10 +79,10 @@ and append the result it in a property. } ``` -#### Controllers and Global Controllers +#### Host-Bound Controllers and Global Controllers When rendering an effect, an `EffectHost` has to be present, -controllers collect data from these hosts to use it to evaluate `Property Modifiers`. +host-bound controllers collect data from these hosts to use it to evaluate `Property Modifiers`. To do this, the `EffectHost#getValue` method is called with the name of the controller. Global controllers on the other hand, do not use a host, they gather their data locally. @@ -97,10 +97,10 @@ Materials describe the render type and uniforms used when rendering. { //Required //Used to decide whether a Property Modifier should apply here or not - "class": "class", + "class": "plumeA", //Required //The veil render type used to render things with the material - "renderType": "rendertype", + "renderType": "veil:rendertype", //Optional //Whether the built in "_Seed" property should be added "randomizeSeed": false,