From 49e57b6a5c55e98ab5884ae833f59b740757b7fc Mon Sep 17 00:00:00 2001 From: Face o' Cat Date: Wed, 2 Dec 2026 05:22:37 +0200 Subject: [PATCH] Reduce rendering cost for large pottery displays Share fired vessel meshes across matching profiles, reuse fluid and wheel geometry, and submit complete vertices to the renderer. Cover mesh reuse and consolidate the unreleased changelog. Co-authored-by: Face of Cat --- CHANGELOG.md | 33 +++------ .../primalpottery/client/FlowerPaint.java | 22 ------ .../minecraft/primalpottery/client/Mesh.java | 40 ++++++++-- .../primalpottery/client/PotteryRenderer.java | 58 ++++++++------- .../primalpottery/client/Sprites.java | 32 ++++++-- .../primalpottery/client/WheelRenderer.java | 73 ++++++++++++++----- .../primalpottery/client/MeshTest.java | 21 ++++++ 7 files changed, 177 insertions(+), 102 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 842c952..100c416 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,28 +8,17 @@ After publishing, the action commits the next development version and changelog ## Unreleased -- Raw pottery and empty fired pottery each stack to 16 small pieces or 4 large pieces when their shapes and finishes match. Filling a vessel or changing its lid affects one piece at a time. -- Inventory icons show a fluid level gauge, including when the lid is on. Open vessels also show their fluid surface. -- Middle-click in Creative to copy the piece under the crosshair, including its shape, dye, lid, and contents. - -- You can fill or break a pot through an empty slot in front of it. Aim at the floor of an empty slot to place another pot there. - -- Fired vessels and lids have the reddish, pixel-grained finish of a flower pot. Light wraps smoothly around the belly and shoulders, and dyed vessels show the same grain in their chosen color. - -- Right-click a potted tree with the same type of sapling to grow a new shape for free. The pot saves the shape you choose between visits. - -- Large pots holding at least 1,000 mL take dirt, grass blocks, or sand. Plant tall flowers or grow a miniature tree from a sapling. Each generated tree block is two Minecraft texture pixels wide and uses its own block textures. - -- Fill an open, empty small pot of at least 250 mL with dirt, a grass block, or sand. Both pot sizes accept short grass and anything a vanilla flower pot accepts. An empty-hand click takes the plant out, and a second click takes the soil. - -- Shape or hollow clay directly on the template, undo a stroke, and stamp the blueprint when the pot looks right. Drag the display block to see four small pots or one large pot from another angle. -- Hover over the clay to see which ring you are shaping. The editor shows how many mL the pot will hold and keeps clay around the hollow when you pinch a narrow shoulder. -- Capacity follows the smoothed hollow from floor to lip. Narrowing or shortening a nearly full-size template still changes its mL. The wooden wheel guides now meet the finished clay along its curve. -- Adjust the template height with − and +. Small pots hold up to 1,000 mL and take a clay ball on the wheel. Large pots hold up to 4,000 mL, take a clay block, and have lids fitted to the outer rim. -- Small templates give you 16 × 16 × 16 units of clay. Craft a clay block with a stick for a 32 × 32 × 32 large template. Its finished vessel takes a whole block. - -- A new pot is a rounded jug with an open mouth, and its clay uses Minecraft's terracotta pixels instead of one picture stretched over the shape. -- Thrown and placed pottery curves from one width to the next, so the shape looks smoother. Liquid inside follows that curve. +- Large displays of matching pottery render faster. Filled pots reuse their liquid surface until the level changes, and wheels reuse their wooden guides until you change the blueprint. +- Use the new painting table while holding fired pottery. Paint one face and the pattern repeats around the vessel. Each square costs 1 mL of paint, and one matching dye refills 100 mL. You can erase squares or undo your last stroke. +- Shape a shallow small pot to make a plate. Paint from its center to its rim and place up to four plates along the edges of a block. Right-click an open plate with a non-block item to display one, then use an empty hand to take it back. +- Shape and hollow clay directly on the template. Hover to see the ring you’re editing, adjust the height with − and +, and undo strokes before stamping the blueprint. The editor keeps clay around the hollow at narrow shoulders and shows how many mL it will hold. Drag the preview to see how four small pots or one large pot will sit on a block. +- A small template gives you 16 × 16 × 16 units of clay. Use a clay ball on the wheel to throw a vessel that holds up to 1,000 mL. Craft a clay block with a stick for a 32 × 32 × 32 large template. A large vessel takes a clay block, holds up to 4,000 mL, and has a lid fitted to its outer rim. +- New templates start as open-mouthed jugs. Thrown and placed pots have smoother curves, and capacity follows the hollow from floor to lip, even near the template’s size limit. Fired pots and lids have the reddish grain of a flower pot, with smoother lighting around the belly and shoulders. Dyed pottery keeps the grain in its chosen color. +- The pottery wheel has a pegged wooden frame and stone wheels. Its wooden guides follow the blueprint’s curve and stay still as the clay spins and throws off flecks. +- Fill an open, empty pot with dirt, a grass block, or sand. Small pots need at least 250 mL of capacity and large pots need 1,000 mL. Both sizes take short grass and vanilla flower-pot plants. A message explains when a pot can’t take soil. An empty hand removes the plant first, then the soil. +- Large planters also take tall flowers and grow miniature trees with their original bark and leaf textures. Each tree block is two texture pixels wide. Use the same sapling to reroll the tree for free. Its shape is saved between visits. +- Matching raw pieces and matching empty fired pieces stack to 16 small or 4 large. Filling a vessel or changing its lid affects one piece. Inventory icons show a fill gauge even with the lid on, and open pots show the liquid surface. When you inspect a pot, you can see the lid on the rim or beside it. +- Aim through an empty slot to fill or break the pot behind it, or aim at the slot floor to place another piece. In Creative, middle-click copies the targeted piece with its shape, dye, lid, and contents. ## 0.0.2 diff --git a/src/main/java/net/modcrafters/minecraft/primalpottery/client/FlowerPaint.java b/src/main/java/net/modcrafters/minecraft/primalpottery/client/FlowerPaint.java index 1c163d5..209767a 100644 --- a/src/main/java/net/modcrafters/minecraft/primalpottery/client/FlowerPaint.java +++ b/src/main/java/net/modcrafters/minecraft/primalpottery/client/FlowerPaint.java @@ -6,31 +6,9 @@ /** Maps one square of slip decoration across the throwing rings of each exterior face. */ final class FlowerPaint { - private record Key(boolean plate, double x, double y, double z, java.util.List discs, FacePaint paint) {} - - private static final java.util.LinkedHashMap vessels = new java.util.LinkedHashMap<>(16, 0.75F, true); - private static int cachedQuads; - private FlowerPaint() { } - static synchronized Mesh vessel(double x, double base, double z, Pottery pottery) { - Key key = new Key(pottery.isPlate(), x, base, z, pottery.discs(), pottery.paint()); - Mesh mesh = vessels.get(key); - if (mesh == null) { - mesh = new Mesh(); - mesh.vessel(x, base, z, pottery.discs(), Mesh.Texture.FIRED_CLAY); - mesh.fitSprite(); - apply(mesh, x, base, z, pottery); - vessels.put(key, mesh); - cachedQuads += mesh.quads().size(); - while (vessels.size() > 64 || cachedQuads > 32768) { - cachedQuads -= vessels.pollFirstEntry().getValue().quads().size(); - } - } - return mesh; - } - static void apply(Mesh vessel, double x, double base, double z, Pottery pottery) { if (pottery.isPlate()) { PlatePaint.build(vessel, x, base, z, pottery, false); diff --git a/src/main/java/net/modcrafters/minecraft/primalpottery/client/Mesh.java b/src/main/java/net/modcrafters/minecraft/primalpottery/client/Mesh.java index 106ac76..5e43f23 100644 --- a/src/main/java/net/modcrafters/minecraft/primalpottery/client/Mesh.java +++ b/src/main/java/net/modcrafters/minecraft/primalpottery/client/Mesh.java @@ -1,12 +1,14 @@ package net.modcrafters.minecraft.primalpottery.client; import java.util.ArrayList; -import net.modcrafters.minecraft.primalpottery.pottery.PotteryProfile; -import net.modcrafters.minecraft.primalpottery.pottery.PotteryProfile.Station; +import java.util.LinkedHashMap; import java.util.List; import net.minecraft.core.Direction; +import net.modcrafters.minecraft.primalpottery.pottery.FacePaint; import net.modcrafters.minecraft.primalpottery.pottery.Pottery; import net.modcrafters.minecraft.primalpottery.pottery.PotteryDisc; +import net.modcrafters.minecraft.primalpottery.pottery.PotteryProfile; +import net.modcrafters.minecraft.primalpottery.pottery.PotteryProfile.Station; public final class Mesh { static final double FLUID_INSET = 0.05; @@ -53,13 +55,37 @@ public List quads() { return this.quads; } + private record FiredKey(boolean plate, double x, double y, double z, double width, List discs, FacePaint paint) {} + private static final LinkedHashMap firedMeshes = new LinkedHashMap<>(16, 0.75F, true); + private static int cachedQuads; + static Mesh firedVessel(double x, double y, double z, Pottery pottery) { - if (!net.modcrafters.minecraft.primalpottery.pottery.FacePaint.EMPTY.equals(pottery.paint())) { - return FlowerPaint.vessel(x, y, z, pottery); + return firedVessel(x, y, z, pottery, pottery.paint(), 1); + } + + static Mesh placedVessel(double x, double z, Pottery pottery, double width) { + FacePaint bakedPaint = pottery.hasFlowerPaint() && !pottery.isPlate() ? FacePaint.FLOWER : FacePaint.EMPTY; + return firedVessel(x, 0, z, pottery, bakedPaint, width); + } + + /** Shared read-only geometry. Placed custom designs draw their paint atlas separately. */ + private static synchronized Mesh firedVessel(double x, double y, double z, Pottery pottery, FacePaint bakedPaint, double width) { + FiredKey key = new FiredKey(pottery.isPlate(), x, y, z, width, pottery.discs(), bakedPaint); + Mesh mesh = firedMeshes.get(key); + if (mesh == null) { + mesh = new Mesh(); + mesh.vessel(x, y, z, pottery.discs(), Texture.FIRED_CLAY); + mesh.fitSprite(); + if (!FacePaint.EMPTY.equals(bakedPaint)) { + FlowerPaint.apply(mesh, x, y, z, pottery); + } + if (width != 1) mesh.scaleWidth(x, z, width); + firedMeshes.put(key, mesh); + cachedQuads += mesh.quads().size(); + while (firedMeshes.size() > 64 || cachedQuads > 32768) { + cachedQuads -= firedMeshes.pollFirstEntry().getValue().quads().size(); + } } - Mesh mesh = new Mesh(); - mesh.vessel(x, y, z, pottery.discs(), Texture.FIRED_CLAY); - mesh.fitSprite(); return mesh; } diff --git a/src/main/java/net/modcrafters/minecraft/primalpottery/client/PotteryRenderer.java b/src/main/java/net/modcrafters/minecraft/primalpottery/client/PotteryRenderer.java index a2510fa..584f96d 100644 --- a/src/main/java/net/modcrafters/minecraft/primalpottery/client/PotteryRenderer.java +++ b/src/main/java/net/modcrafters/minecraft/primalpottery/client/PotteryRenderer.java @@ -24,7 +24,6 @@ import net.modcrafters.minecraft.primalpottery.pottery.Pottery; import net.modcrafters.minecraft.primalpottery.pottery.FacePaint; import net.modcrafters.minecraft.primalpottery.pottery.VesselContents; -import net.minecraft.world.phys.AABB; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.client.renderer.texture.OverlayTexture; @@ -110,7 +109,7 @@ public void submit( net.minecraft.client.renderer.state.level.CameraRenderState camera ) { PlacedPot[] bodies = bodies(state.slots, state.lids); - List draws = fluids(state.slots, state.contents); + List draws = fluids(bodies, state.slots, state.contents); boolean solidFluid = has(draws, true); boolean translucent = has(draws, false); if (!occupied(state.slots) && !solidFluid && !translucent) { @@ -190,7 +189,7 @@ public void render( var lids = blockEntity.lids(); PlacedPot[] bodies = bodies(slots, lids); List plantings = plantings(slots, blockEntity); - List draws = fluids(slots, blockEntity.contents()); + List draws = fluids(bodies, slots, blockEntity.contents()); boolean solidFluid = has(draws, true); boolean translucent = has(draws, false); if (!occupied(slots) && !solidFluid && !translucent) { @@ -396,22 +395,36 @@ private static boolean occupied(Pottery[] slots) { private final Map placed = new WeakHashMap<>(); private static final class PlacedPot { - final Mesh vessel = new Mesh(); + final Mesh vessel; Mesh lid; Mesh paint; PaintAtlas.Tile tile; - PlacedPot(Pottery pottery, double x, double z) { - vessel.vessel(x, 0, z, pottery.discs(), Mesh.Texture.FIRED_CLAY); - vessel.fitSprite(); - if (!FacePaint.EMPTY.equals(pottery.paint())) { - Mesh overlay = FlowerPaint.overlay(vessel, x, 0, z, pottery); - if (pottery.hasFlowerPaint() && !pottery.isPlate()) { - vessel.add(overlay); - } else { - paint = overlay; - tile = PaintAtlas.acquire(pottery.paint()); + private Mesh fluid; + private int fluidAmount; + + Mesh fluidMesh(int slot, Pottery pottery, int amount) { + if (fluid == null || amount != fluidAmount) { + var center = PotteryBlockEntity.box(slot, pottery.size()).getCenter(); + double x = center.x * 32, z = center.z * 32; + Mesh mesh = new Mesh(); + mesh.cavity(x, 0, z, pottery, amount); + if (slot >= PotteryBlockEntity.CORNERS) { + mesh.scaleWidth(x, z, PotteryBlockEntity.PLATE_SCALE); } + fluid = mesh; + fluidAmount = amount; + } + return fluid; + } + + PlacedPot(Pottery pottery, double x, double z, double width) { + vessel = Mesh.placedVessel(x, z, pottery, width); + if (!FacePaint.EMPTY.equals(pottery.paint()) && (pottery.isPlate() || !pottery.hasFlowerPaint())) { + paint = FlowerPaint.overlay(vessel, x, 0, z, pottery); + // Plate paint is generated from the unscaled profile, vessel paint from the mesh. + if (pottery.isPlate() && width != 1) paint.scaleWidth(x, z, width); + tile = PaintAtlas.acquire(pottery.paint()); } } } @@ -426,12 +439,8 @@ private PlacedPot[] bodies(Pottery[] slots, boolean[] lids) { var center = PotteryBlockEntity.box(i, pottery.size()).getCenter(); double x = center.x * 32, z = center.z * 32; if (positions[i] == null) { - var body = new PlacedPot(pottery, x, z); - if (i >= PotteryBlockEntity.CORNERS) { - body.vessel.scaleWidth(x, z, PotteryBlockEntity.PLATE_SCALE); - if (body.paint != null) body.paint.scaleWidth(x, z, PotteryBlockEntity.PLATE_SCALE); - } - positions[i] = body; + double width = i >= PotteryBlockEntity.CORNERS ? PotteryBlockEntity.PLATE_SCALE : 1; + positions[i] = new PlacedPot(pottery, x, z, width); } if (lids[i]) { var cover = pottery.cover(); @@ -460,7 +469,7 @@ private static void drawClay( } } - private static List fluids(Pottery[] slots, VesselContents[] contents) { + private static List fluids(PlacedPot[] bodies, Pottery[] slots, VesselContents[] contents) { List draws = new ArrayList<>(); if (contents == null) { return draws; @@ -475,12 +484,7 @@ private static List fluids(Pottery[] slots, VesselContents[] contents if (sprite == null) { continue; } - Mesh body = new Mesh(); - AABB box = PotteryBlockEntity.box(index, pottery.size()); - body.cavity(box.getCenter().x * 32, 0, box.getCenter().z * 32, pottery, held.amount()); - if (index >= PotteryBlockEntity.CORNERS) { - body.scaleWidth(box.getCenter().x * 32, box.getCenter().z * 32, PotteryBlockEntity.PLATE_SCALE); - } + Mesh body = bodies[index].fluidMesh(index, pottery, held.amount()); if (body.quads().isEmpty()) { continue; } diff --git a/src/main/java/net/modcrafters/minecraft/primalpottery/client/Sprites.java b/src/main/java/net/modcrafters/minecraft/primalpottery/client/Sprites.java index ea3b636..e73950e 100644 --- a/src/main/java/net/modcrafters/minecraft/primalpottery/client/Sprites.java +++ b/src/main/java/net/modcrafters/minecraft/primalpottery/client/Sprites.java @@ -12,6 +12,7 @@ import net.minecraft.world.level.material.Fluids; import net.modcrafters.minecraft.primalpottery.Ids; import org.jspecify.annotations.Nullable; +import org.joml.Vector3f; public final class Sprites { private static final Identifier FIRED_CLAY = Ids.of("block/fired_clay"); @@ -174,9 +175,19 @@ private static void write(Mesh mesh, @Nullable TextureAtlasSprite forced, Vertex } private static void write(Mesh mesh, @Nullable TextureAtlasSprite forced, VertexConsumer buffer, PoseStack.Pose pose, int light, int red, int green, int blue, int alpha, boolean shade) { + Vector3f transformed = new Vector3f(); + Mesh.Texture lastTexture = null; + TextureAtlasSprite lastSprite = null; for (Mesh.Quad quad : mesh.quads()) { boolean paint = quad.texture == Mesh.Texture.FLOWER_PAINT || quad.texture == Mesh.Texture.PIGMENT; - TextureAtlasSprite sprite = forced == null || paint ? get(quad.texture) : forced; + TextureAtlasSprite sprite = forced; + if (sprite == null || paint) { + if (lastTexture != quad.texture) { + lastTexture = quad.texture; + lastSprite = get(lastTexture); + } + sprite = lastSprite; + } int r = paint ? (quad.pigment >> 16) & 255 : red; int g = paint ? (quad.pigment >> 8) & 255 : green; int b = paint ? quad.pigment & 255 : blue; @@ -191,7 +202,7 @@ private static void write(Mesh mesh, @Nullable TextureAtlasSprite forced, Vertex float brightness = shade && normals != null ? nx * nx * 0.6F + nz * nz * 0.8F + ny * ny * (ny > 0 ? 1.0F : 0.5F) : flatShade; - put(buffer, pose, quad.x[vertex], quad.y[vertex], quad.z[vertex], + put(buffer, pose, transformed, quad.x[vertex], quad.y[vertex], quad.z[vertex], sampleU(sprite, quad.u[vertex]), sampleV(sprite, quad.v[vertex]), light, (int) (r * brightness), (int) (g * brightness), (int) (b * brightness), alpha, nx, ny, nz); } @@ -220,9 +231,10 @@ public static void drawFluid(Mesh mesh, VertexConsumer buffer, PoseStack.Pose po int red = (color >> 16) & 255; int green = (color >> 8) & 255; int blue = color & 255; + Vector3f transformed = new Vector3f(); for (Mesh.Quad quad : mesh.quads()) { for (int vertex = 0; vertex < 4; vertex++) { - put(buffer, pose, quad.x[vertex], quad.y[vertex], quad.z[vertex], sampleU(sprite, quad.u[vertex]), sampleV(sprite, quad.v[vertex]), light, red, green, blue, 255, quad.nx, quad.ny, quad.nz); + put(buffer, pose, transformed, quad.x[vertex], quad.y[vertex], quad.z[vertex], sampleU(sprite, quad.u[vertex]), sampleV(sprite, quad.v[vertex]), light, red, green, blue, 255, quad.nx, quad.ny, quad.nz); } } } @@ -233,11 +245,12 @@ private static float sampleU(TextureAtlasSprite sprite, float unit) { static void drawPaint(Mesh overlay, PaintAtlas.Tile tile, VertexConsumer buffer, PoseStack.Pose pose, int light) { tile.page().upload(); + Vector3f transformed = new Vector3f(); for (Mesh.Quad quad : overlay.quads()) { for (int v = 0; v < 4; v++) { float u = (tile.x() + quad.u[v]) / PaintAtlas.SIZE; float t = (tile.y() + quad.v[v]) / PaintAtlas.SIZE; - put(buffer, pose, quad.x[v], quad.y[v], quad.z[v], u, t, light, 255, 255, 255, 255, + put(buffer, pose, transformed, quad.x[v], quad.y[v], quad.z[v], u, t, light, 255, 255, 255, 255, quad.cornerNormals[3*v], quad.cornerNormals[3*v+1], quad.cornerNormals[3*v+2]); } } @@ -250,6 +263,7 @@ private static float sampleV(TextureAtlasSprite sprite, float unit) { private static void put( VertexConsumer buffer, PoseStack.Pose pose, + Vector3f transformed, float x, float y, float z, @@ -264,10 +278,16 @@ private static void put( float ny, float nz ) { + pose.pose().transformPosition(x, y, z, transformed); + float px = transformed.x, py = transformed.y, pz = transformed.z; + pose.transformNormal(nx, ny, nz, transformed); + // Use the consumer's whole-vertex path for the entity buffer format. //? if <1.21 { - /*buffer.vertex(pose, x, y, z).color(red, green, blue, alpha).uv(u, v).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(pose, nx, ny, nz).endVertex(); + /*buffer.vertex(px, py, pz, red / 255F, green / 255F, blue / 255F, alpha / 255F, + u, v, OverlayTexture.NO_OVERLAY, light, transformed.x, transformed.y, transformed.z); *///?} else { - buffer.addVertex(pose, x, y, z).setColor(red, green, blue, alpha).setUv(u, v).setOverlay(OverlayTexture.NO_OVERLAY).setUv2(light & 0xFFFF, light >> 16).setNormal(pose, nx, ny, nz); + int argb = alpha << 24 | red << 16 | green << 8 | blue; + buffer.addVertex(px, py, pz, argb, u, v, OverlayTexture.NO_OVERLAY, light, transformed.x, transformed.y, transformed.z); //?} } } diff --git a/src/main/java/net/modcrafters/minecraft/primalpottery/client/WheelRenderer.java b/src/main/java/net/modcrafters/minecraft/primalpottery/client/WheelRenderer.java index 48ffce3..ab57ecf 100644 --- a/src/main/java/net/modcrafters/minecraft/primalpottery/client/WheelRenderer.java +++ b/src/main/java/net/modcrafters/minecraft/primalpottery/client/WheelRenderer.java @@ -5,6 +5,11 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Axis; +import java.util.Map; +import java.util.WeakHashMap; +import net.minecraft.core.component.DataComponents; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.component.CustomData; import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; //? if >=26.1 import net.minecraft.client.renderer.blockentity.state.BlockEntityRenderState; @@ -18,6 +23,44 @@ public final class WheelRenderer implements BlockEntityRenderer meshes = new WeakHashMap<>(); + + private static final class WheelMeshes { + private ItemStack blueprint; + private CustomData blueprintData; + private Mesh guides; + private Pottery start; + private Pottery target; + private float progress; + private Mesh forming; + + void update(PotteryWheelBlockEntity wheel) { + ItemStack installed = wheel.templateItem(); + if (installed.isEmpty()) installed = ItemStack.EMPTY; + CustomData data = installed.get(DataComponents.CUSTOM_DATA); + if (installed != blueprint || data != blueprintData) { + blueprint = installed; + blueprintData = data; + Pottery template = wheel.template(); + guides = template == null ? null : pattern(template); + } + + Pottery nextTarget = wheel.hasClay() ? wheel.formed() : null; + if (target != nextTarget || start != wheel.start() || progress != wheel.clayProgress()) { + target = nextTarget; + start = wheel.start(); + progress = wheel.clayProgress(); + forming = target == null ? null : clay(Pottery.shaped(start, target, progress)); + } + } + } + + private WheelMeshes meshesFor(PotteryWheelBlockEntity wheel) { + WheelMeshes result = meshes.computeIfAbsent(wheel, ignored -> new WheelMeshes()); + result.update(wheel); + return result; + } + //? if >=26.1 { @Override public State createRenderState() { @@ -34,11 +77,9 @@ public void extractRenderState( ) { BlockEntityRenderState.extractBase(blockEntity, state, breakProgress); state.angle = blockEntity.angle(); - state.hasClay = blockEntity.hasClay(); - state.progress = blockEntity.clayProgress(); - state.template = blockEntity.template(); - state.start = blockEntity.start(); - state.target = state.hasClay ? blockEntity.formed() : null; + WheelMeshes meshes = meshesFor(blockEntity); + state.guides = meshes.guides; + state.forming = meshes.forming; } @Override @@ -51,7 +92,7 @@ public void submit( var renderType = net.minecraft.client.renderer.rendertype.RenderTypes.entitySolid(Sprites.blocks()); poseStack.pushPose(); poseStack.scale(1 / 32.0F, 1 / 32.0F, 1 / 32.0F); - Mesh pattern = state.template == null ? null : pattern(state.template); + Mesh pattern = state.guides; collector.submitCustomGeometry(poseStack, renderType, (pose, buffer) -> { Sprites.draw(MODEL.stand(), buffer, pose, state.lightCoords); if (pattern != null) { @@ -61,7 +102,7 @@ public void submit( poseStack.translate(16, 0, 16); poseStack.rotate(Axis.YP, -state.angle); poseStack.translate(-16, 0, -16); - Mesh clay = state.hasClay ? clay(Pottery.shaped(state.start, state.target, state.progress)) : null; + Mesh clay = state.forming; collector.submitCustomGeometry(poseStack, renderType, (pose, buffer) -> { Sprites.draw(MODEL.spinning(), buffer, pose, state.lightCoords); if (clay != null) { @@ -78,11 +119,8 @@ public boolean shouldRenderOffScreen() { public static final class State extends BlockEntityRenderState { public float angle; - public boolean hasClay; - public float progress; - public Pottery template; - public Pottery start; - public Pottery target; + private Mesh guides; + private Mesh forming; } //?} else { /*@Override @@ -99,9 +137,9 @@ public void render( var buffer = buffers.getBuffer(net.minecraft.client.renderer.RenderType.entitySolid(Sprites.blocks())); var pose = poseStack.last(); Sprites.draw(MODEL.stand(), buffer, pose, light); - Pottery template = blockEntity.template(); - if (template != null) { - Sprites.draw(pattern(template), buffer, pose, light); + WheelMeshes meshes = meshesFor(blockEntity); + if (meshes.guides != null) { + Sprites.draw(meshes.guides, buffer, pose, light); } poseStack.pushPose(); poseStack.translate(16, 0, 16); @@ -109,9 +147,8 @@ public void render( poseStack.translate(-16, 0, -16); pose = poseStack.last(); Sprites.draw(MODEL.spinning(), buffer, pose, light); - if (blockEntity.hasClay()) { - Pottery shaped = Pottery.shaped(blockEntity.start(), blockEntity.formed(), blockEntity.clayProgress()); - Sprites.draw(clay(shaped), buffer, pose, light, Sprites.rawTexture()); + if (meshes.forming != null) { + Sprites.draw(meshes.forming, buffer, pose, light, Sprites.rawTexture()); } poseStack.popPose(); poseStack.popPose(); diff --git a/src/test/java/net/modcrafters/minecraft/primalpottery/client/MeshTest.java b/src/test/java/net/modcrafters/minecraft/primalpottery/client/MeshTest.java index 6fd1dcb..d8c293a 100644 --- a/src/test/java/net/modcrafters/minecraft/primalpottery/client/MeshTest.java +++ b/src/test/java/net/modcrafters/minecraft/primalpottery/client/MeshTest.java @@ -2,6 +2,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; import com.mojang.blaze3d.vertex.PoseStack; @@ -13,6 +15,25 @@ import org.junit.jupiter.api.Test; class MeshTest { + @Test + void firedMeshCacheReusesEqualProfilesAndKeepsFinishesAndPositionsSeparate() { + Pottery jug = Pottery.jug(); + Mesh plain = Mesh.firedVessel(0, 0, 0, jug); + assertSame(plain, Mesh.firedVessel(0, 0, 0, Pottery.load(jug.save()))); + assertNotSame(plain, Mesh.firedVessel(0, 0, 0, new Pottery(jug.size(), jug.discs(), true))); + assertNotSame(plain, Mesh.firedVessel(8, 0, 0, jug)); + var custom = new Pottery(jug.size(), jug.discs(), jug.paint().with(48, 3)); + assertSame(plain, Mesh.placedVessel(0, 0, custom, 1)); + assertNotSame(plain, Mesh.firedVessel(0, 0, 0, custom)); + var plate = new Pottery(List.of(new PotteryDisc(2, 8, 6), new PotteryDisc(1, 7, 0))); + var full = Mesh.placedVessel(0, 0, plate, 1); + float fullX = full.quads().getFirst().x[0]; + var narrow = Mesh.placedVessel(0, 0, plate, 0.75); + assertTrue(Math.abs(fullX) > 0.01F); + assertEquals(fullX * 0.75F, narrow.quads().getFirst().x[0], 1e-5F); + assertEquals(fullX, full.quads().getFirst().x[0]); + } + @Test void platePaintSpansFloorInnerWallAndRimOnAllEightSectors() { var plate = new Pottery(List.of(new PotteryDisc(2, 8, 6), new PotteryDisc(1, 7, 0)));