Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<FlareEffectLayer> effectLayers) {

public final class FlareEffectTemplate {
public static final Codec<FlareEffectTemplate> CODEC = CodecUtil.singleOrList(FlareEffectLayer.CODEC).fieldOf("layers").xmap(FlareEffectTemplate::new, FlareEffectTemplate::effectLayers).codec();

private final List<FlareEffectLayer> effectLayers;


public FlareEffectTemplate(List<FlareEffectLayer> effectLayers) {
ArrayList<FlareEffectLayer> 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<ResourceLocation, BakedShell> 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<FlareEffectLayer> effectLayers() {
return effectLayers;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@
/**
* @since 2.5.0
*/
public record FlareMaterial(
String clazz,
ResourceLocation renderTypeLocation,
boolean randomizeSeed,
Map<String, Property<?>> properties
) {
public final class FlareMaterial {
public static Codec<FlareMaterial> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codec.STRING.fieldOf("class").forGetter(FlareMaterial::clazz),
ResourceLocation.CODEC.fieldOf("renderType").forGetter(FlareMaterial::renderTypeLocation),
Expand All @@ -42,38 +37,47 @@ 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<String, Property<?>> properties;


public FlareMaterial(String clazz, ResourceLocation renderTypeLocation, boolean randomizeSeed, Map<String, Property<?>> 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<String, List<PropertyModifier<?>>> modifiers) {
if (shader == null) {
return;
}
for (Map.Entry<String, Property<?>> 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;
Expand All @@ -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<String, Property<?>> properties() {
return properties;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, FlareSubModule> subModules) {

public final class FlareModule {
public static final Codec<FlareModule> CODEC = Codec.unboundedMap(Codec.STRING, FlareSubModule.CODEC)
.xmap(FlareModule::new, FlareModule::subModules)
.fieldOf("subModules")
.codec();

private final Map<String, FlareSubModule> subModules;


public FlareModule(Map<String, FlareSubModule> subModules) {
this.subModules = Collections.unmodifiableMap(subModules);
this.subModules = Map.copyOf(subModules);
}

public FlareSubModule getSubModule(String name) {
return this.subModules.get(name);
}


public Map<String, FlareSubModule> subModules() {
return subModules;
}

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

Expand All @@ -18,23 +17,25 @@
/**
* @since 2.5.0
*/
public record FlareSubModule(List<ResourceLocation> templates) {

public final class FlareSubModule {
public static final Codec<FlareSubModule> 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<ResourceLocation> templates;


public FlareSubModule(List<ResourceLocation> 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<ResourceLocation, BakedShell> shellOverrides) {
for (ResourceLocation templateLocation : this.templates) {
FlareEffectTemplate template = FlareEffectManager.getTemplate(templateLocation);
Expand All @@ -45,4 +46,9 @@ public void render(EffectHost host, MatrixStack matrixStack, float partialTick,
template.render(host, matrixStack, partialTick, shellOverrides);
}
}

public List<ResourceLocation> templates() {
return templates;
}

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@
* @author GuyApooye
* @since 2.5.0
*/
public record FlareShell(List<ShellElement> elements) implements UnbakedShell {

public final class FlareShell implements UnbakedShell {
public static final Codec<FlareShell> CODEC = RecordCodecBuilder.create(instance -> instance.group(
ShellElement.CODEC.listOf().fieldOf("elements").forGetter(FlareShell::elements)
).apply(instance, FlareShell::new));

private final List<ShellElement> elements;

public FlareShell(List<ShellElement> elements) {
this.elements = List.copyOf(elements);
}

@Override
public @Nullable BakedShell bake() {
SimpleBakedShell.Builder builder = new SimpleBakedShell.Builder();
Expand All @@ -32,12 +37,13 @@ public record FlareShell(List<ShellElement> elements) implements UnbakedShell {
builder.addFace(ShellBakery.bakeQuad(element, entry.getValue(), entry.getKey()));
}
}

return builder.build();
}

@Override
public List<ShellElement> elements() {
return new ArrayList<>(this.elements);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Direction, ShellElementFace> faces
) {
public final class ShellElement {
public static final Codec<ShellElement> CODEC = RecordCodecBuilder.create(instance -> instance.group(
CodecUtil.VECTOR3FC_CODEC.fieldOf("from").forGetter(ShellElement::from),
CodecUtil.VECTOR3FC_CODEC.fieldOf("to").forGetter(ShellElement::to),
Expand All @@ -30,4 +22,37 @@ public record ShellElement(
Map<Direction, ShellElementFace> 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<Direction, ShellElementFace> faces;

public ShellElement(
Vector3fc from,
Vector3fc to,
@Nullable ShellElementRotation rotation,
Map<Direction, ShellElementFace> 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<Direction, ShellElementFace> faces() {
return faces;
}

}
Loading