diff --git a/CHANGELOG.md b/CHANGELOG.md index 3de037e4..da51fe1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,16 +10,15 @@ Before a release, `./gradlew releaseChangelog` turns *Unreleased* into the relea ### Added +- Turrets on a base with a damage amp addon show a small red light on each corner of their base plate - NEEPMeat compatibility (Fabric 1.20.1): vascular conduits power turret bases (1 eJ = 1 E); a full turret base takes no power from the network +- Config sections `upgrades` and `addons` switch each upgrade and addon off: it loses its recipe and does nothing in a machine, which shows it with a red slot frame, a "no" symbol over the icon and a red tooltip line ### Changed - Config: `bases.allowContraptionMovement` is deprecated on Minecraft 1.20.1; it never had an effect here, as no contraption mod (Create, Create Aeronautics) is supported on this version - The game rules (`omtteam.openmodularturrets.core`) come from the shared OpenModularCore 2.1.0 (module `omt-core`, the same on every Minecraft version) and are bundled into the jar - API: `MachineMode` and `TargetingSettings` (formerly `core.base`), `CamoPermissions` (`core.camo`) and the memory card's `MemoryCardData` and `MemoryCardRules` (`core.card`) moved to OMLib's core (`omtteam.omlib.core.machine`, `.camo`, `.card`); `MemoryCardRules.capture` and `apply` are now `omtteam.openmodularturrets.core.card.BaseCardRules`, and `MachineMode.getTranslationKey()` is gone -### Added - -- Config sections `upgrades` and `addons` switch each upgrade and addon off: it loses its recipe and does nothing in a machine, which shows it with a red slot frame, a "no" symbol over the icon and a red tooltip line ## [4.0.0] - 2026-11-03 diff --git a/omlib b/omlib index cacdb385..c751634f 160000 --- a/omlib +++ b/omlib @@ -1 +1 @@ -Subproject commit cacdb38587e5237ce0ebd5a559f931a75ca8a4cb +Subproject commit c751634fe5d879072c9f205ec879f0981f056da4 diff --git a/src/client/java/omtteam/openmodularturrets/client/render/blockentity/DamageAmpRenderer.java b/src/client/java/omtteam/openmodularturrets/client/render/blockentity/DamageAmpRenderer.java new file mode 100644 index 00000000..d2858930 --- /dev/null +++ b/src/client/java/omtteam/openmodularturrets/client/render/blockentity/DamageAmpRenderer.java @@ -0,0 +1,32 @@ +package omtteam.openmodularturrets.client.render.blockentity; + +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.renderer.MultiBufferSource; +import omtteam.openmodularturrets.client.render.effect.GlowPanelsRenderer; + +/** + * Damage amp effect on turrets: a small red LED in each upper corner of the turret's baseplate, lighting the top + * face and both side faces at the corner. + */ +public final class DamageAmpRenderer { + /** Top of the baseplate in the turret's local frame (the plate is 12×12×1 pixels at the bottom of the block). */ + private static final float PLATE_TOP = -0.4375F; + /** Half side of the baseplate (6 pixels). */ + private static final float PLATE_HALF_SIZE = 0.375F; + /** LED edge length, under the plate's thickness of one pixel. */ + private static final float LED_SIZE = 0.04F; + + private static final GlowPanelsRenderer LEDS = GlowPanelsRenderer.builder() + .panels(GlowPanelsRenderer.boxTopCorners(PLATE_HALF_SIZE, PLATE_TOP, LED_SIZE)) + .colour(0xFF1A1A) + .alpha(0.85F) + .build(); + + private DamageAmpRenderer() { + } + + /** @param poseStack at the block center, in the turret's local frame (x = right, y = up, z = forward) */ + public static void render(PoseStack poseStack, MultiBufferSource buffers) { + LEDS.render(poseStack, buffers); + } +} diff --git a/src/client/java/omtteam/openmodularturrets/client/render/blockentity/TurretRenderer.java b/src/client/java/omtteam/openmodularturrets/client/render/blockentity/TurretRenderer.java index 9247dbb4..d6049ed3 100644 --- a/src/client/java/omtteam/openmodularturrets/client/render/blockentity/TurretRenderer.java +++ b/src/client/java/omtteam/openmodularturrets/client/render/blockentity/TurretRenderer.java @@ -19,7 +19,8 @@ /** * Turret renderer (1.12.2 {@code AbstractTurretRenderer}): orients the model on its mounting face with the frame - * from {@link TurretMath}, then applies the interpolated yaw and pitch. Concealed turrets are not drawn. + * from {@link TurretMath}, then applies the interpolated yaw and pitch. Concealed turrets are not drawn. A base with a + * damage amp addon adds the {@link DamageAmpRenderer corner LEDs} to every turret's base plate. */ public class TurretRenderer implements BlockEntityRenderer { private final Map models; @@ -40,6 +41,9 @@ public void render(TurretBlockEntity turret, float partialTick, PoseStack poseSt poseStack.translate(0.5D, 0.5D, 0.5D); poseStack.mulPose(rotationFor(turret.getFace())); renderModel(model, poseStack, buffers, packedLight, packedOverlay); + if (turret.hasDamageAmp()) { + DamageAmpRenderer.render(poseStack, buffers); + } poseStack.popPose(); } diff --git a/src/client/java/omtteam/openmodularturrets/client/render/effect/GlowDotsRenderer.java b/src/client/java/omtteam/openmodularturrets/client/render/effect/GlowDotsRenderer.java new file mode 100644 index 00000000..f97775aa --- /dev/null +++ b/src/client/java/omtteam/openmodularturrets/client/render/effect/GlowDotsRenderer.java @@ -0,0 +1,149 @@ +package omtteam.openmodularturrets.client.render.effect; + +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import net.minecraft.client.renderer.MultiBufferSource; +import omtteam.omlib.client.compat.ClientCompat; +import omtteam.omlib.client.render.fx.GlowGeometry; +import org.joml.Matrix4f; +import org.joml.Vector3f; + +import java.util.ArrayList; +import java.util.List; + +/** + * Small glowing lights at fixed points: a bright core sphere inside an optional faint halo, optionally pulsing. + * Instances are immutable and configured with {@link #builder()}; one instance can be shared by any number of + * renderers. + */ +public final class GlowDotsRenderer { + private final List points; + private final int rgb; + private final float coreRadius; + private final float coreAlpha; + private final float haloRadius; + private final float haloAlpha; + private final int slices; + private final int stacks; + private final double pulseTicks; + private final float pulseMin; + + private GlowDotsRenderer(Builder builder) { + this.points = List.copyOf(builder.points); + this.rgb = builder.rgb; + this.coreRadius = builder.coreRadius; + this.coreAlpha = builder.coreAlpha; + this.haloRadius = builder.haloRadius; + this.haloAlpha = builder.haloAlpha; + this.slices = builder.slices; + this.stacks = builder.stacks; + this.pulseTicks = builder.pulseTicks; + this.pulseMin = builder.pulseMin; + } + + public static Builder builder() { + return new Builder(); + } + + /** The four corners of a square of half side length {@code halfSize}, centred on the y axis at height {@code y}. */ + public static List squareCorners(float halfSize, float y) { + return List.of(new Vector3f(-halfSize, y, -halfSize), new Vector3f(halfSize, y, -halfSize), + new Vector3f(halfSize, y, halfSize), new Vector3f(-halfSize, y, halfSize)); + } + + /** + * Draws the dots ({@link ClientCompat#lightning()}). + * + * @param poseStack the frame the points are given in + * @param ticks animation time in ticks, including the partial tick (only used when pulsing) + */ + public void render(PoseStack poseStack, MultiBufferSource buffers, double ticks) { + draw(buffers.getBuffer(ClientCompat.lightning()), poseStack.last().pose(), ticks); + } + + private void draw(VertexConsumer consumer, Matrix4f pose, double ticks) { + float brightness = brightness(ticks); + int core = GlowGeometry.argb(rgb, coreAlpha * brightness); + int halo = GlowGeometry.argb(rgb, haloAlpha * brightness); + for (Vector3f point : points) { + GlowGeometry.sphere(consumer, pose, point.x(), point.y(), point.z(), coreRadius, slices, stacks, core); + if (haloRadius > coreRadius && haloAlpha > 0) { + GlowGeometry.sphere(consumer, pose, point.x(), point.y(), point.z(), haloRadius, slices, stacks, halo); + } + } + } + + /** Brightness factor: 1 without pulsing, otherwise a sine between {@code pulseMin} and 1. */ + private float brightness(double ticks) { + if (pulseTicks <= 0) return 1.0F; + double wave = 0.5D + 0.5D * Math.sin(2.0D * Math.PI * (ticks % pulseTicks) / pulseTicks); + return (float) (pulseMin + (1.0D - pulseMin) * wave); + } + + /** Configuration of a {@link GlowDotsRenderer}; the defaults draw steady small red dots without a halo. */ + public static final class Builder { + private final List points = new ArrayList<>(); + private int rgb = 0xFF1A1A; + private float coreRadius = 0.02F; + private float coreAlpha = 0.9F; + private float haloRadius; + private float haloAlpha; + private int slices = 8; + private int stacks = 6; + private double pulseTicks; + private float pulseMin = 1.0F; + + private Builder() { + } + + public Builder point(float x, float y, float z) { + points.add(new Vector3f(x, y, z)); + return this; + } + + public Builder points(List points) { + points.forEach(point -> this.points.add(new Vector3f(point))); + return this; + } + + /** RGB colour of the lights. */ + public Builder colour(int rgb) { + this.rgb = rgb; + return this; + } + + public Builder core(float radius, float alpha) { + this.coreRadius = radius; + this.coreAlpha = alpha; + return this; + } + + /** A larger, fainter sphere around each core (radius not above the core radius = no halo). */ + public Builder halo(float radius, float alpha) { + this.haloRadius = radius; + this.haloAlpha = alpha; + return this; + } + + /** Tessellation of the spheres (longitude segments, latitude bands). */ + public Builder detail(int slices, int stacks) { + this.slices = Math.max(3, slices); + this.stacks = Math.max(2, stacks); + return this; + } + + /** + * @param periodTicks ticks of one pulse (0 = steady light) + * @param minBrightness brightness factor at the dimmest point of a pulse, in [0, 1] + */ + public Builder pulse(double periodTicks, float minBrightness) { + this.pulseTicks = Math.max(0.0D, periodTicks); + this.pulseMin = Math.max(0.0F, Math.min(1.0F, minBrightness)); + return this; + } + + public GlowDotsRenderer build() { + return new GlowDotsRenderer(this); + } + } +} diff --git a/src/client/java/omtteam/openmodularturrets/client/render/effect/GlowPanelsRenderer.java b/src/client/java/omtteam/openmodularturrets/client/render/effect/GlowPanelsRenderer.java new file mode 100644 index 00000000..1636ca14 --- /dev/null +++ b/src/client/java/omtteam/openmodularturrets/client/render/effect/GlowPanelsRenderer.java @@ -0,0 +1,136 @@ +package omtteam.openmodularturrets.client.render.effect; + +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import net.minecraft.client.renderer.MultiBufferSource; +import omtteam.omlib.client.compat.ClientCompat; +import omtteam.omlib.client.render.fx.GlowGeometry; +import org.joml.Matrix4f; +import org.joml.Vector3f; + +import java.util.ArrayList; +import java.util.List; + +/** + * Small, uniformly lit panels on surfaces, like LEDs. Instances are immutable and configured with {@link #builder()}; + * one instance can be shared by any number of renderers. + */ +public final class GlowPanelsRenderer { + /** + * A parallelogram panel on a surface: {@code anchor}, {@code anchor + edgeA}, {@code anchor + edgeA + edgeB}, + * {@code anchor + edgeB}. {@code outward} is the surface's unit + * normal; the panel is lifted off the surface along it so the two do not z-fight. Both edges must point away from + * the anchor along the surface: the lifted panel is extended back past the anchor by the same distance, so panels + * on adjacent faces sharing an anchor (like {@link #boxTopCorners}) still meet at the corner without a gap. + */ + public record Panel(Vector3f anchor, Vector3f edgeA, Vector3f edgeB, Vector3f outward) { + } + + private final List panels; + private final int color; + private final float alpha; + private final float surfaceOffset; + + private GlowPanelsRenderer(Builder builder) { + this.panels = List.copyOf(builder.panels); + this.color = builder.rgb; + this.alpha = builder.alpha; + this.surfaceOffset = builder.surfaceOffset; + } + + public static Builder builder() { + return new Builder(); + } + + /** + * Three panels on each of the four upper corners of a box centred on the y axis: one on the top face and one on + * each of the two side faces, all anchored at the corner itself (so they read as one lit corner). The panels lie + * exactly on the faces; the renderer lifts them off. + * + * @param halfSize half the side length of the box's top face + * @param topY height of the box's top face + * @param size edge length of each panel + */ + public static List boxTopCorners(float halfSize, float topY, float size) { + List panels = new ArrayList<>(); + Vector3f up = new Vector3f(0, 1, 0); + for (int sx = -1; sx <= 1; sx += 2) { + for (int sz = -1; sz <= 1; sz += 2) { + Vector3f anchor = new Vector3f(sx * halfSize, topY, sz * halfSize); + Vector3f inX = new Vector3f(-sx * size, 0, 0); + Vector3f inZ = new Vector3f(0, 0, -sz * size); + Vector3f down = new Vector3f(0, -size, 0); + panels.add(new Panel(anchor, inX, inZ, up)); + panels.add(new Panel(anchor, down, inZ, new Vector3f(sx, 0, 0))); + panels.add(new Panel(anchor, inX, down, new Vector3f(0, 0, sz))); + } + } + return panels; + } + + /** + * Draws the panels ({@link ClientCompat#lightning()}). + * + * @param poseStack the frame the panels are given in + */ + public void render(PoseStack poseStack, MultiBufferSource buffers) { + draw(buffers.getBuffer(ClientCompat.lightning()), poseStack.last().pose()); + } + + private void draw(VertexConsumer consumer, Matrix4f pose) { + int lit = GlowGeometry.argb(color, alpha); + int[] colours = {lit, lit, lit, lit}; + for (Panel panel : panels) { + GlowGeometry.doubleSidedQuad(consumer, pose, corners(panel, surfaceOffset), colours); + } + } + + /** + * Corners of the panel lifted by {@code offset}. The anchor moves back by + * {@code offset} along both edges, onto the corner where the lifted panels of adjacent faces meet. + */ + private static float[][] corners(Panel panel, float offset) { + Vector3f backA = new Vector3f(panel.edgeA()).normalize(offset); + Vector3f backB = new Vector3f(panel.edgeB()).normalize(offset); + Vector3f o = new Vector3f(panel.outward()).mul(offset).add(panel.anchor()).sub(backA).sub(backB); + Vector3f a = new Vector3f(panel.edgeA()).add(backA); + Vector3f b = new Vector3f(panel.edgeB()).add(backB); + return new float[][]{ + {o.x(), o.y(), o.z()}, + {o.x() + a.x(), o.y() + a.y(), o.z() + a.z()}, + {o.x() + a.x() + b.x(), o.y() + a.y() + b.y(), o.z() + a.z() + b.z()}, + {o.x() + b.x(), o.y() + b.y(), o.z() + b.z()}}; + } + + /** Configuration of a {@link GlowPanelsRenderer}; the defaults draw red panels. */ + public static final class Builder { + private final List panels = new ArrayList<>(); + private int rgb = 0xCC0000; + private float alpha = 0.85F; + private float surfaceOffset = 0.0001F; + + private Builder() { + } + + public Builder panels(List panels) { + this.panels.addAll(panels); + return this; + } + + /** RGB colour of the panels. */ + public Builder colour(int rgb) { + this.rgb = rgb; + return this; + } + + /** Alpha of the panels. */ + public Builder alpha(float alpha) { + this.alpha = alpha; + return this; + } + + public GlowPanelsRenderer build() { + return new GlowPanelsRenderer(this); + } + } +} diff --git a/src/main/java/omtteam/openmodularturrets/blockentity/turret/TurretBlockEntity.java b/src/main/java/omtteam/openmodularturrets/blockentity/turret/TurretBlockEntity.java index 151b3449..1cf9a1f5 100644 --- a/src/main/java/omtteam/openmodularturrets/blockentity/turret/TurretBlockEntity.java +++ b/src/main/java/omtteam/openmodularturrets/blockentity/turret/TurretBlockEntity.java @@ -74,6 +74,8 @@ public class TurretBlockEntity extends CompatBlockEntity { private float syncedPitch; private int ticksSinceSync; private boolean active; + /** Whether the base has a damage amp addon; synced to clients (the turret shows its damage amp LEDs). */ + private boolean damageAmp; /** Ammo taken by the last {@link #beginShot()}, if the turret uses ammo. */ @Nullable @@ -187,8 +189,10 @@ public static void serverTick(Level level, BlockPos pos, BlockState state, Turre } else { turret.forgetTarget(); } - if (engaging != turret.active) { + boolean amped = logic.getDamageAmpLevel() > 0; + if (engaging != turret.active || amped != turret.damageAmp) { turret.active = engaging; + turret.damageAmp = amped; turret.syncToClient(); } turret.syncAimIfChanged(); @@ -202,6 +206,11 @@ public boolean isActive() { return active; } + /** Whether the base has a damage amp addon (synced to clients). */ + public boolean hasDamageAmp() { + return damageAmp; + } + /** * 1.12.2 {@code AbstractDirectedTurret.update} / {@code TurretHead.updateChecks}: aiming turrets turn towards the * target's eyes every tick (1.12.2 turrets had no effective yaw/pitch limits; the pitch is now limited to @@ -477,6 +486,7 @@ protected void readData(CompoundTag tag, HolderLookup.Provider registries) { yaw = NbtCompat.getFloat(tag, "Yaw", 0); pitch = NbtCompat.getFloat(tag, "Pitch", 0); active = NbtCompat.getBoolean(tag, "Active", false); + damageAmp = NbtCompat.getBoolean(tag, "DamageAmp", false); if (!renderInitialised) { renderYaw = prevRenderYaw = yaw; renderPitch = prevRenderPitch = pitch; @@ -490,11 +500,12 @@ protected void writeData(CompoundTag tag, HolderLookup.Provider registries) { tag.putInt("TicksSinceShot", state.getTicksSinceShot()); } - /** Clients only need the aim and whether the turret is active. */ + /** Clients only need the aim, whether the turret is active and whether it shows the damage amp LEDs. */ @Override protected void writeClientData(CompoundTag tag, HolderLookup.Provider registries) { tag.putFloat("Yaw", yaw); tag.putFloat("Pitch", pitch); tag.putBoolean("Active", active); + tag.putBoolean("DamageAmp", damageAmp); } }