diff --git a/.github/scripts/release-publish.sh b/.github/scripts/release-publish.sh index fa016c2..524d52a 100644 --- a/.github/scripts/release-publish.sh +++ b/.github/scripts/release-publish.sh @@ -186,7 +186,7 @@ github_release() { if gh release view "$tag" >/dev/null 2>&1; then echo "GitHub release ${tag} already exists" else - local -a args=(release create "$tag" --title "Feast Dominion ${tag#v}" --notes-file "$notes") + local -a args=(release create "$tag" --title "Primal Pottery ${tag#v}" --notes-file "$notes") [[ "$release_type" == release ]] || args+=(--prerelease) gh "${args[@]}" fi @@ -245,15 +245,15 @@ upload() { echo "CurseForge file list returned ${code}. A repeated run may upload the same jar again." >&2 fi - modrinth_upload "${version}+1.20.6" "Feast Dominion ${version} for NeoForge 1.20.6" neoforge 1.20.6 "$neo_1206" - modrinth_upload "${version}+1.21.1" "Feast Dominion ${version} for NeoForge 1.21.1" neoforge 1.21.1 "$neo_121" - modrinth_upload "${version}+26.3+fabric" "Feast Dominion ${version} for Fabric 26.3" fabric 26.3 "$fabric_263" - modrinth_upload "${version}+26.3+neoforge" "Feast Dominion ${version} for NeoForge 26.3" neoforge 26.3 "$neo_263" + modrinth_upload "${version}+1.20.6" "Primal Pottery ${version} for NeoForge 1.20.6" neoforge 1.20.6 "$neo_1206" + modrinth_upload "${version}+1.21.1" "Primal Pottery ${version} for NeoForge 1.21.1" neoforge 1.21.1 "$neo_121" + modrinth_upload "${version}+26.3+fabric" "Primal Pottery ${version} for Fabric 26.3" fabric 26.3 "$fabric_263" + modrinth_upload "${version}+26.3+neoforge" "Primal Pottery ${version} for NeoForge 26.3" neoforge 26.3 "$neo_263" - curseforge_upload "Feast Dominion ${version} for NeoForge 1.20.6" NeoForge "$neo_1206" "$cf_neo_1206" - curseforge_upload "Feast Dominion ${version} for NeoForge 1.21.1" NeoForge "$neo_121" "$cf_neo_121" - curseforge_upload "Feast Dominion ${version} for Fabric 26.3" Fabric "$fabric_263" "$cf_fabric_263" - curseforge_upload "Feast Dominion ${version} for NeoForge 26.3" NeoForge "$neo_263" "$cf_neo_263" + curseforge_upload "Primal Pottery ${version} for NeoForge 1.20.6" NeoForge "$neo_1206" "$cf_neo_1206" + curseforge_upload "Primal Pottery ${version} for NeoForge 1.21.1" NeoForge "$neo_121" "$cf_neo_121" + curseforge_upload "Primal Pottery ${version} for Fabric 26.3" Fabric "$fabric_263" "$cf_fabric_263" + curseforge_upload "Primal Pottery ${version} for NeoForge 26.3" NeoForge "$neo_263" "$cf_neo_263" github_release "$TAG" "$neo_1206" "$neo_121" "$fabric_263" "$neo_263" } diff --git a/.gitignore b/.gitignore index 49d9216..d6e4548 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,5 @@ bin/ /AGENTS.md /.cursor/ /docs/team/ +/.sprite-room/backups/ +/versions/*/logs/ diff --git a/CHANGELOG.md b/CHANGELOG.md index ec04fe3..9c15f9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ After publishing, the action commits the next development version and changelog ## Unreleased +- Picking up clay unlocks recipes for the pottery wheel and raw template. Mining either half of the wheel returns the wheel in Survival. +- Nearby players see the wheel spin together, and a wheel keeps its shaping progress when its chunk unloads. +- The liquid surface in a placed vessel rises as you pour. Placed lids can be changed only within reach. - A jug, jar, or pot holds liquid, and you can see the liquid when you look inside. Use it on water or lava, flowing or still, or on another fluid, and it fills without using up the source. A waterlogged block or a bubble column does not fill it. - The tooltip shows how many millilitres it holds, and the liquid and how full it is when there is some. Water's name is blue. - Use a vessel in the air, or right-click a placed one with an empty hand, to look inside and put a lid on or take it off. The lid sits just above the rim, a little wider than the mouth, with a small handle. diff --git a/art/primal-pottery-icon.png b/art/primal-pottery-icon.png new file mode 100644 index 0000000..a9d0110 Binary files /dev/null and b/art/primal-pottery-icon.png differ diff --git a/neoforge/versions/26.3/src/main/java/net/modcrafters/minecraft/primalpottery/neoforge/PotteryGameTests.java b/neoforge/versions/26.3/src/main/java/net/modcrafters/minecraft/primalpottery/neoforge/PotteryGameTests.java index a26ac66..27dd943 100644 --- a/neoforge/versions/26.3/src/main/java/net/modcrafters/minecraft/primalpottery/neoforge/PotteryGameTests.java +++ b/neoforge/versions/26.3/src/main/java/net/modcrafters/minecraft/primalpottery/neoforge/PotteryGameTests.java @@ -110,6 +110,13 @@ private static void wheel(GameTestHelper helper) { } helper.assertTrue(Math.abs(wheel.clayProgress() - 0.1F) < 0.0001F, "clay progress was " + wheel.clayProgress()); + var snapshot = wheel.getUpdateTag(helper.getLevel().registryAccess()); + var tracked = new PotteryWheelBlockEntity(helper.absolutePos(wheelPos), wheel.getBlockState()); + tracked.loadCustomOnly(TagValueInput.create(ProblemReporter.DISCARDING, helper.getLevel().registryAccess(), snapshot)); + helper.assertValueEqual(tracked.spinTicks(), wheel.spinTicks(), "remaining spin in tracking snapshot"); + helper.assertValueEqual(tracked.angle(), wheel.angle(), "wheel angle in tracking snapshot"); + helper.assertValueEqual(tracked.clayProgress(), wheel.clayProgress(), "saved shaping progress"); + helper.useBlock(wheelPos, player); helper.assertFalse(wheel.hasClay(), "clay was not taken off"); ItemStack shaped = potteryItem(helper); @@ -139,6 +146,21 @@ private static void wheel(GameTestHelper helper) { player.setShiftKeyDown(false); helper.assertBlockNotPresent(ModBlocks.POTTERY, floor.above()); potteryItem(helper); + + ((ServerPlayer) player).setGameMode(GameType.SURVIVAL); + helper.assertFalse(player.preventsBlockDrops(), "survival wheel drops disabled"); + BlockPos absoluteWheel = helper.absolutePos(wheelPos); + for (BlockPos broken : List.of(absoluteWheel, absoluteWheel.above())) { + helper.setBlock(wheelPos, ModBlocks.WHEEL); + helper.getBlockEntity(wheelPos, PotteryWheelBlockEntity.class).tick(); + ((ServerPlayer) player).gameMode.destroyBlock(broken); + helper.assertBlockNotPresent(ModBlocks.WHEEL, wheelPos); + helper.assertBlockNotPresent(ModBlocks.WHEEL, wheelPos.above()); + var drops = helper.getLevel().getEntitiesOfClass(ItemEntity.class, new AABB(absoluteWheel).inflate(2), + item -> item.getItem().is(ModItems.WHEEL)); + helper.assertValueEqual(drops.stream().mapToInt(item -> item.getItem().getCount()).sum(), 1, "wheel drops from " + broken); + drops.forEach(ItemEntity::discard); + } helper.succeed(); } @@ -146,6 +168,8 @@ private static void checkTemplateCycle(GameTestHelper helper, Player player) { ItemStack raw = new ItemStack(ModItems.RAW_TEMPLATE); player.setItemInHand(InteractionHand.MAIN_HAND, raw); List profile = List.of(new PotteryDisc(1, 4, 1), new PotteryDisc(1, 4)); + TemplateSync.apply(player, true, List.of(new PotteryDisc(Double.NaN, 4))); + helper.assertTrue(player.getMainHandItem().is(ModItems.RAW_TEMPLATE), "invalid edit consumed the raw template"); TemplateSync.apply(player, true, profile); ItemStack blueprint = player.getMainHandItem(); @@ -158,6 +182,15 @@ private static void checkTemplateCycle(GameTestHelper helper, Player player) { "blueprint is missing its capacity tooltip"); var recipes = helper.getLevel().recipeAccess(); + CraftingInput blank = CraftingInput.of(2, 1, List.of(new ItemStack(Items.STICK), new ItemStack(Items.CLAY_BALL))); + helper.assertTrue(recipes.getRecipeFor(RecipeType.CRAFTING, blank, helper.getLevel()).orElseThrow() + .value().assemble(blank).is(ModItems.RAW_TEMPLATE), "survival template recipe"); + CraftingInput wheel = CraftingInput.of(3, 3, List.of( + ItemStack.EMPTY, new ItemStack(Items.STONE_SLAB), ItemStack.EMPTY, + new ItemStack(Items.OAK_PLANKS), new ItemStack(Items.BIRCH_PLANKS), new ItemStack(Items.OAK_PLANKS), + new ItemStack(Items.STICK), new ItemStack(Items.STONE_SLAB), new ItemStack(Items.STICK))); + helper.assertTrue(recipes.getRecipeFor(RecipeType.CRAFTING, wheel, helper.getLevel()).orElseThrow() + .value().assemble(wheel).is(ModItems.WHEEL), "survival wheel recipe"); CraftingInput input = CraftingInput.of(1, 1, List.of(blueprint)); var recipe = recipes.getRecipeFor(RecipeType.CRAFTING, input, helper.getLevel()); helper.assertTrue(recipe.isPresent(), "no reset recipe matched the saved blueprint"); @@ -425,6 +458,10 @@ private static void lidsAndBreaks(GameTestHelper helper, Player player) { assertStored(helper, loaded.contents(0), Fluids.WATER, volume, "saved water"); BlockPos absolute = helper.absolutePos(pots); + placeEyes(player, Vec3.atCenterOf(absolute).add(0, 12, 0)); + PlacedLidSync.apply(player, absolute, 0, false); + helper.assertTrue(entity.lid(0), "a distant player removed the lid"); + placeEyes(player, Vec3.atCenterOf(absolute).add(0, 2, 0)); PlacedLidSync.apply(player, absolute, 0, false); helper.assertFalse(entity.lid(0), "take placed lid"); helper.assertFalse(entity.lid(1), "neighbor gained a lid"); @@ -449,8 +486,6 @@ private static void lidsAndBreaks(GameTestHelper helper, Player player) { player.setItemInHand(InteractionHand.MAIN_HAND, ItemStack.EMPTY); float progress = state.getDestroyProgress(player, helper.getLevel(), absolute); helper.assertTrue(progress > 0.0F && progress < 1.0F, "destroy progress " + progress); - // The two-argument getCollisionShape returns the shape cached at startup, which is empty - // because no pot exists then. The block methods are what the outline and entity collision use. assertFootprint(helper, pots, 0, 1); Vec3 gap = helper.absoluteVec(new Vec3(pots.getX() + 0.5, pots.getY() + 0.2, pots.getZ() + 0.5)); @@ -653,7 +688,9 @@ private static void assertFootprint(GameTestHelper helper, BlockPos relative, in BlockState state = helper.getBlockState(relative); CollisionContext context = CollisionContext.empty(); var shape = state.getShape(helper.getLevel(), absolute, context); - var collision = state.getCollisionShape(helper.getLevel(), absolute, context); + var collision = state.getCollisionShape(helper.getLevel(), absolute); + helper.assertFalse(Shapes.joinIsNotEmpty(collision, state.getCollisionShape(helper.getLevel(), absolute, context), + BooleanOp.NOT_SAME), "cached collision differs from occupied slots"); for (int index = 0; index < PotteryBlockEntity.SLOTS; index++) { var box = Shapes.create(PotteryBlockEntity.box(index)); helper.assertFalse(Shapes.joinIsNotEmpty(shape, box, BooleanOp.ONLY_SECOND), "outline missing " + index); diff --git a/src/main/java/net/modcrafters/minecraft/primalpottery/block/ModBlocks.java b/src/main/java/net/modcrafters/minecraft/primalpottery/block/ModBlocks.java index 9c073a8..f40922b 100644 --- a/src/main/java/net/modcrafters/minecraft/primalpottery/block/ModBlocks.java +++ b/src/main/java/net/modcrafters/minecraft/primalpottery/block/ModBlocks.java @@ -27,6 +27,7 @@ public final class ModBlocks { public static final PotteryBlock POTTERY = new PotteryBlock(properties(POTTERY_ID) .mapColor(MapColor.TERRACOTTA_RED) .sound(SoundType.DECORATED_POT) + .dynamicShape() .strength(0.5F, 3600000.0F) .noOcclusion() .lightLevel(state -> state.getValue(PotteryBlock.LIGHT))); diff --git a/src/main/java/net/modcrafters/minecraft/primalpottery/block/PotteryWheelBlockEntity.java b/src/main/java/net/modcrafters/minecraft/primalpottery/block/PotteryWheelBlockEntity.java index 73737b4..fbaab3b 100644 --- a/src/main/java/net/modcrafters/minecraft/primalpottery/block/PotteryWheelBlockEntity.java +++ b/src/main/java/net/modcrafters/minecraft/primalpottery/block/PotteryWheelBlockEntity.java @@ -18,6 +18,7 @@ import org.jspecify.annotations.Nullable; public class PotteryWheelBlockEntity extends BlockEntity { + /** Collision height. The drawn wheel stays one block tall. */ public static final double BLOCK_HEIGHT = 1.5; public static final int TABLE = 0; public static final int BIG_WHEEL = 1; @@ -41,16 +42,19 @@ public PotteryWheelBlockEntity(BlockPos pos, BlockState state) { public static AABB box(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) { return new AABB( minX / 32.0, - minY / 32.0 * BLOCK_HEIGHT, + minY / 32.0, minZ / 32.0, maxX / 32.0, - maxY / 32.0 * BLOCK_HEIGHT, + maxY / 32.0, maxZ / 32.0 ); } public void spin() { - this.spinTicks += 24; + if (this.level != null && !this.level.isClientSide()) { + this.spinTicks += 24; + this.sync(); + } } public void install(Pottery pottery) { @@ -120,6 +124,14 @@ public void tick() { if (this.hasClay && this.clayProgress < 1) { this.clayProgress = Math.min(1, this.clayProgress + 0.01F); } + // Clients animate between server snapshots. Persist the authoritative tick and settle all clients at rest. + if (this.level != null && !this.level.isClientSide()) { + if (this.spinTicks == 0) { + this.sync(); + } else { + this.setChanged(); + } + } } //? if >=26.1 { @@ -150,6 +162,8 @@ protected void loadAdditional(CompoundTag tag, net.minecraft.core.HolderLookup.P private CompoundTag saveWheel() { CompoundTag tag = new CompoundTag(); + tag.putInt("spin_ticks", this.spinTicks); + tag.putDouble("angle", this.angle); tag.putBoolean("clay", this.hasClay); tag.putFloat("progress", this.clayProgress); if (this.template != null) { @@ -159,6 +173,9 @@ private CompoundTag saveWheel() { } private void loadWheel(CompoundTag tag) { + this.spinTicks = Math.max(0, Nbt.getInt(tag, "spin_ticks")); + double savedAngle = Nbt.getDouble(tag, "angle"); + this.angle = Double.isFinite(savedAngle) ? savedAngle % (Math.PI * 2) : 0; this.hasClay = Nbt.getBoolean(tag, "clay"); this.clayProgress = Nbt.getFloat(tag, "progress"); CompoundTag template = Nbt.compound(tag, "template"); 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 f5681b6..128e693 100644 --- a/src/main/java/net/modcrafters/minecraft/primalpottery/client/Mesh.java +++ b/src/main/java/net/modcrafters/minecraft/primalpottery/client/Mesh.java @@ -199,17 +199,21 @@ private static double cut(double backX, double heel, double reach, double radius /** * The fluid body. Each open disc is an octagon at its inner radius, inset so it stays inside the clay. - * The top face sits just under the top of the rim disc. A slice whose inset radius is not positive is skipped. + * Fill from the floor by slice volume. A full vessel's surface sits just below its rim. */ - public void cavity(double centerX, double base, double centerZ, List discs) { + public void cavity(double centerX, double base, double centerZ, List discs, int amount) { int rim = openRim(discs); - if (rim < 0) { + if (rim < 0 || amount <= 0) { return; } int end = rim; + double capacity = 0; while (end < discs.size() && discs.get(end).innerRadius() > 0) { - end++; + PotteryDisc disc = discs.get(end++); + capacity += Pottery.cavityArea(disc.innerRadius()) * disc.height(); } + // Stored capacity is rounded to whole millilitres. + double remaining = amount >= Math.round(capacity) ? capacity : amount; double y = base; for (int index = discs.size() - 1; index >= end; index--) { y += Math.max(0, discs.get(index).height()); @@ -218,15 +222,23 @@ public void cavity(double centerX, double base, double centerZ, List 0 && drawHeight > 0) { this.ringWalls(centerX, centerZ, y, drawHeight, radius, Texture.CLAY); if (top) { this.cap(centerX, centerZ, y + drawHeight, radius, Texture.CLAY, true); } } + if (top) { + break; + } + remaining -= sliceVolume; y += height; } } 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 367fa86..3571014 100644 --- a/src/main/java/net/modcrafters/minecraft/primalpottery/client/PotteryRenderer.java +++ b/src/main/java/net/modcrafters/minecraft/primalpottery/client/PotteryRenderer.java @@ -9,7 +9,6 @@ import net.minecraft.client.renderer.blockentity.state.BlockEntityRenderState; import net.modcrafters.minecraft.primalpottery.block.PotteryBlockEntity; import net.modcrafters.minecraft.primalpottery.pottery.Pottery; -import net.modcrafters.minecraft.primalpottery.pottery.PotteryDisc; import net.modcrafters.minecraft.primalpottery.pottery.VesselContents; import net.minecraft.world.phys.AABB; @@ -147,7 +146,15 @@ private static Mesh clay(Pottery[] slots, boolean[] lids) { } boolean closed = lids != null && index < lids.length && lids[index]; Mesh pot = new Mesh(); - placed(index, pot, pottery, closed, false); + AABB box = PotteryBlockEntity.box(index); + double x = box.getCenter().x * 32; + double z = box.getCenter().z * 32; + pot.vessel(x, 0, z, pottery.discs(), Mesh.Texture.CLAY); + Pottery.Cover cover = closed ? pottery.cover() : null; + if (cover != null) { + pot.cover(x, 0, z, cover, Mesh.Texture.CLAY); + } + pot.fitSprite(); mesh.add(pot); } return mesh; @@ -169,7 +176,8 @@ private static List fluids(Pottery[] slots, VesselContents[] contents continue; } Mesh body = new Mesh(); - placed(index, body, pottery, false, true); + AABB box = PotteryBlockEntity.box(index); + body.cavity(box.getCenter().x * 32, 0, box.getCenter().z * 32, pottery.discs(), held.amount()); if (body.quads().isEmpty()) { continue; } @@ -178,20 +186,4 @@ private static List fluids(Pottery[] slots, VesselContents[] contents return draws; } - private static void placed(int index, Mesh mesh, Pottery pottery, boolean closed, boolean fluid) { - AABB box = PotteryBlockEntity.box(index); - double centerX = (box.minX + box.maxX) / 2.0 * 32.0; - double centerZ = (box.minZ + box.maxZ) / 2.0 * 32.0; - double base = box.minY * 32.0; - List discs = pottery.discs(); - if (fluid) { - mesh.cavity(centerX, base, centerZ, discs); - return; - } - mesh.vessel(centerX, base, centerZ, discs, Mesh.Texture.CLAY); - if (closed && pottery.cover() != null) { - mesh.cover(centerX, base, centerZ, pottery.cover(), Mesh.Texture.CLAY); - } - mesh.fitSprite(); - } } diff --git a/src/main/java/net/modcrafters/minecraft/primalpottery/client/TemplateScreen.java b/src/main/java/net/modcrafters/minecraft/primalpottery/client/TemplateScreen.java index 424908d..6f0d620 100644 --- a/src/main/java/net/modcrafters/minecraft/primalpottery/client/TemplateScreen.java +++ b/src/main/java/net/modcrafters/minecraft/primalpottery/client/TemplateScreen.java @@ -30,7 +30,6 @@ public final class TemplateScreen extends Screen { private static final int PROFILE_Y = 10; private static final int PROFILE_WIDTH = 100; private static final int PROFILE_HEIGHT = 120; - private static final double MAX_RADIUS = 5.5; private static final int BAR_COLOR = 0x60500000; private final boolean mainHand; @@ -176,13 +175,13 @@ private boolean sculpt(double mouseX, double mouseY, int button) { if (x < 0 || x >= PROFILE_WIDTH || y < 0 || y >= PROFILE_HEIGHT || this.discs.isEmpty() || (button != 0 && button != 1)) { return false; } - double value = x * MAX_RADIUS / (PROFILE_WIDTH - 1); + double value = x * Pottery.MAX_RADIUS / (PROFILE_WIDTH - 1); int row = y * this.discs.size() / PROFILE_HEIGHT; PotteryDisc disc = this.discs.get(row); if (button == 0) { - this.discs.set(row, new PotteryDisc(disc.height(), value, disc.innerRadius())); + this.discs.set(row, new PotteryDisc(disc.height(), value, Math.min(value, disc.innerRadius()))); } else { - this.discs.set(row, new PotteryDisc(disc.height(), disc.radius(), value)); + this.discs.set(row, new PotteryDisc(disc.height(), disc.radius(), Math.min(disc.radius(), value))); } return true; } @@ -240,7 +239,7 @@ private void layout() { } private static int barWidth(double radius) { - return Math.max(0, Math.min(PROFILE_WIDTH, (int) (radius * PROFILE_WIDTH / MAX_RADIUS))); + return Math.max(0, Math.min(PROFILE_WIDTH, (int) (radius * PROFILE_WIDTH / Pottery.MAX_RADIUS))); } private static int rowEdge(int row, int rows) { 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 8b3b3de..b3b08d9 100644 --- a/src/main/java/net/modcrafters/minecraft/primalpottery/client/WheelRenderer.java +++ b/src/main/java/net/modcrafters/minecraft/primalpottery/client/WheelRenderer.java @@ -49,7 +49,7 @@ public void submit( ) { var renderType = net.minecraft.client.renderer.rendertype.RenderTypes.entitySolid(Sprites.blocks()); poseStack.pushPose(); - poseStack.scale(1 / 32.0F, (float) (PotteryWheelBlockEntity.BLOCK_HEIGHT / 32.0), 1 / 32.0F); + poseStack.scale(1 / 32.0F, 1 / 32.0F, 1 / 32.0F); Mesh pattern = state.template == null ? null : pattern(state.template); collector.submitCustomGeometry(poseStack, renderType, (pose, buffer) -> { Sprites.draw(STAND, buffer, pose, state.lightCoords); @@ -92,7 +92,7 @@ public void render( int overlay ) { poseStack.pushPose(); - poseStack.scale(1 / 32.0F, (float) (PotteryWheelBlockEntity.BLOCK_HEIGHT / 32.0), 1 / 32.0F); + poseStack.scale(1 / 32.0F, 1 / 32.0F, 1 / 32.0F); var buffer = buffers.getBuffer(net.minecraft.client.renderer.RenderType.entitySolid(Sprites.blocks())); var pose = poseStack.last(); Sprites.draw(STAND, buffer, pose, light); diff --git a/src/main/java/net/modcrafters/minecraft/primalpottery/network/PlacedLidSync.java b/src/main/java/net/modcrafters/minecraft/primalpottery/network/PlacedLidSync.java index 7a7e68c..ebcbe02 100644 --- a/src/main/java/net/modcrafters/minecraft/primalpottery/network/PlacedLidSync.java +++ b/src/main/java/net/modcrafters/minecraft/primalpottery/network/PlacedLidSync.java @@ -24,7 +24,12 @@ public static void send(BlockPos pos, int slot, boolean closed) { public static void apply(Player player, BlockPos pos, int slot, boolean closed) { Level level = player.level(); - if (!level.mayInteract(player, pos) || !level.getBlockState(pos).is(ModBlocks.POTTERY)) { + //? if >=26.1 { + boolean inReach = player.isWithinBlockInteractionRange(pos, 0); + //?} else + //boolean inReach = player.canInteractWithBlock(pos, 0); + if (!inReach || player.isSpectator() || !level.hasChunkAt(pos) + || !level.mayInteract(player, pos) || !level.getBlockState(pos).is(ModBlocks.POTTERY)) { return; } if (!(level.getBlockEntity(pos) instanceof PotteryBlockEntity pottery)) { diff --git a/src/main/java/net/modcrafters/minecraft/primalpottery/network/TemplatePayload.java b/src/main/java/net/modcrafters/minecraft/primalpottery/network/TemplatePayload.java index ebb39cb..ad6a315 100644 --- a/src/main/java/net/modcrafters/minecraft/primalpottery/network/TemplatePayload.java +++ b/src/main/java/net/modcrafters/minecraft/primalpottery/network/TemplatePayload.java @@ -7,6 +7,7 @@ import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.modcrafters.minecraft.primalpottery.Ids; +import net.modcrafters.minecraft.primalpottery.pottery.Pottery; import net.modcrafters.minecraft.primalpottery.pottery.PotteryDisc; /** The sculpted profile, sent to the server so the template item keeps it. */ @@ -30,7 +31,7 @@ private static void write(RegistryFriendlyByteBuf buf, TemplatePayload payload) private static TemplatePayload read(RegistryFriendlyByteBuf buf) { boolean mainHand = buf.readBoolean(); int count = buf.readVarInt(); - if (count < 0 || count > 64) { + if (count < 0 || count > Pottery.MAX_DISCS) { throw new DecoderException("template"); } List discs = new ArrayList<>(count); diff --git a/src/main/java/net/modcrafters/minecraft/primalpottery/network/TemplateSync.java b/src/main/java/net/modcrafters/minecraft/primalpottery/network/TemplateSync.java index c9a1c21..f332aec 100644 --- a/src/main/java/net/modcrafters/minecraft/primalpottery/network/TemplateSync.java +++ b/src/main/java/net/modcrafters/minecraft/primalpottery/network/TemplateSync.java @@ -26,7 +26,7 @@ public static void send(boolean mainHand, List discs) { } public static void apply(Player player, boolean mainHand, List discs) { - if (discs.isEmpty() || discs.size() > 64) { + if (!Pottery.validProfile(discs)) { return; } InteractionHand hand = mainHand ? InteractionHand.MAIN_HAND : InteractionHand.OFF_HAND; diff --git a/src/main/java/net/modcrafters/minecraft/primalpottery/pottery/Pottery.java b/src/main/java/net/modcrafters/minecraft/primalpottery/pottery/Pottery.java index b430ce2..5dccdd4 100644 --- a/src/main/java/net/modcrafters/minecraft/primalpottery/pottery/Pottery.java +++ b/src/main/java/net/modcrafters/minecraft/primalpottery/pottery/Pottery.java @@ -7,6 +7,9 @@ import org.jspecify.annotations.Nullable; public final class Pottery { + public static final int MAX_DISCS = 64; + public static final double MAX_RADIUS = 5.5; + private static final double MAX_HEIGHT = 12; // Height of the wheel's editable clay blank. // The clay mesh uses regular octagons whose vertices lie on the disc radius. private static final double CAVITY_AREA_FACTOR = 2 * Math.sqrt(2); private final List discs; @@ -15,6 +18,21 @@ public Pottery(List discs) { this.discs = List.copyOf(discs); } + public static boolean validProfile(List discs) { + if (discs.isEmpty() || discs.size() > MAX_DISCS) { + return false; + } + double height = 0; + for (PotteryDisc disc : discs) { + if (!(disc.height() > 0 && disc.radius() >= 0 && disc.radius() <= MAX_RADIUS + && disc.innerRadius() >= 0 && disc.innerRadius() <= disc.radius())) { + return false; + } + height += disc.height(); + } + return height <= MAX_HEIGHT; + } + public List discs() { return this.discs; } @@ -64,11 +82,15 @@ public Info classify() { return new Info(type, (int) Math.min(Integer.MAX_VALUE, Math.round(volume))); } // One profile unit represents one centimeter for the capacity estimate. - volume += CAVITY_AREA_FACTOR * inner * inner * disc.height(); + volume += cavityArea(inner) * disc.height(); } return new Info(PotteryType.LUMP_NO_BOTTOM, 0); } + public static double cavityArea(double innerRadius) { + return CAVITY_AREA_FACTOR * innerRadius * innerRadius; + } + /** One block pixel in the placed mesh, which uses 32 units per block. */ public static final double PIXEL = 2; @@ -154,15 +176,20 @@ public CompoundTag save() { public static Pottery load(CompoundTag tag) { List discs = new ArrayList<>(); ListTag list = Nbt.list(tag, "discs"); + if (list.size() > MAX_DISCS) { + return display(); + } for (int index = 0; index < list.size(); index++) { CompoundTag discTag = Nbt.compoundAt(list, index); - discs.add(new PotteryDisc( - Nbt.getDouble(discTag, "height"), - Nbt.getDouble(discTag, "radius"), - Nbt.getDouble(discTag, "inner") - )); + double radius = Nbt.getDouble(discTag, "radius"); + double inner = Nbt.getDouble(discTag, "inner"); + // Older editors allowed the inner brush to cross the outer edge, producing a zero-width wall. + if (inner > radius && inner <= MAX_RADIUS) { + inner = radius; + } + discs.add(new PotteryDisc(Nbt.getDouble(discTag, "height"), radius, inner)); } - return new Pottery(discs); + return validProfile(discs) ? new Pottery(discs) : display(); } /** The pot a wheel forms: the installed template, or the plain vase when none is installed. */ 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 6f90831..5258ea3 100644 --- a/src/test/java/net/modcrafters/minecraft/primalpottery/client/MeshTest.java +++ b/src/test/java/net/modcrafters/minecraft/primalpottery/client/MeshTest.java @@ -188,7 +188,7 @@ void lidSitsOnTheRimAndCavityStaysOpen() { assertTrue(reach(lidded, plateTop, maxY(lidded)) < reach(lidded, rimTop + layer, plateTop)); Mesh cavity = new Mesh(); - cavity.cavity(0, 0, 0, pottery.discs()); + cavity.cavity(0, 0, 0, pottery.discs(), pottery.classify().volume()); assertFalse(cavity.quads().isEmpty()); assertEquals(pottery.classify().volume(), new Pottery(pottery.discs()).classify().volume()); } @@ -201,7 +201,7 @@ void fluidSurfaceFollowsEachOpenDisc() { new PotteryDisc(1, 6, 0) ); Mesh mesh = new Mesh(); - mesh.cavity(0, 0, 0, discs); + mesh.cavity(0, 0, 0, discs, new Pottery(discs).classify().volume()); assertFalse(mesh.quads().isEmpty()); float rimTop = 7; float belly = 0; @@ -228,10 +228,29 @@ void fluidSurfaceFollowsEachOpenDisc() { assertEquals(rimTop - Mesh.FLUID_INSET, highest, 0.02); Mesh skipped = new Mesh(); - skipped.cavity(0, 0, 0, List.of(new PotteryDisc(2, 4, Mesh.FLUID_INSET), new PotteryDisc(1, 4, 0))); + skipped.cavity(0, 0, 0, List.of(new PotteryDisc(2, 4, Mesh.FLUID_INSET), new PotteryDisc(1, 4, 0)), 1); assertEquals(0, skipped.quads().size()); } + @Test + void partialFillStopsInTheCorrectSlice() { + List discs = List.of(new PotteryDisc(2, 4, 2), new PotteryDisc(1, 4, 3), new PotteryDisc(1, 4)); + for (int amount : new int[] {1, 30}) { + Mesh mesh = new Mesh(); + mesh.cavity(0, 0, 0, discs, amount); + double bottomVolume = Pottery.cavityArea(3); + double surface = amount <= bottomVolume ? 1 + amount / bottomVolume + : 2 + (amount - bottomVolume) / Pottery.cavityArea(2); + float highest = 0; + for (Mesh.Quad quad : mesh.quads()) { + for (float y : quad.y) { + highest = Math.max(highest, y); + } + } + assertEquals(surface, highest, 0.0001); + } + } + @Test void fittedClayStaysOnOneSprite() { List discs = List.of(new PotteryDisc(12, 5.5, 0)); diff --git a/src/test/java/net/modcrafters/minecraft/primalpottery/pottery/PotteryTest.java b/src/test/java/net/modcrafters/minecraft/primalpottery/pottery/PotteryTest.java index 5ded518..1af9829 100644 --- a/src/test/java/net/modcrafters/minecraft/primalpottery/pottery/PotteryTest.java +++ b/src/test/java/net/modcrafters/minecraft/primalpottery/pottery/PotteryTest.java @@ -131,6 +131,22 @@ void tooltipColorTintsOnlyWater() { assertEquals(Blocks.LAVA.getName().getString(), PotteryItem.fluidName(Fluids.LAVA).getString()); } + @Test + void profilesRejectInvalidDimensionsAndKeepOlderZeroWidthWalls() { + for (PotteryDisc invalid : List.of(new PotteryDisc(0, 2), new PotteryDisc(Double.NaN, 2), + new PotteryDisc(1, Double.POSITIVE_INFINITY), new PotteryDisc(1, -1), new PotteryDisc(1, 6), + new PotteryDisc(1, 2, Double.NaN), new PotteryDisc(1, 2, -1))) { + Pottery bad = new Pottery(List.of(invalid)); + assertFalse(Pottery.validProfile(bad.discs())); + assertEquals(Pottery.display().discs(), Pottery.load(bad.save()).discs()); + } + assertFalse(Pottery.validProfile(List.of(new PotteryDisc(7, 2), new PotteryDisc(7, 2)))); + assertFalse(Pottery.validProfile(java.util.Collections.nCopies(65, new PotteryDisc(0.1, 2)))); + Pottery crossed = new Pottery(List.of(new PotteryDisc(1, 2, 3), new PotteryDisc(1, 2))); + assertFalse(Pottery.validProfile(crossed.discs())); + assertEquals(List.of(new PotteryDisc(1, 2, 2), new PotteryDisc(1, 2)), Pottery.load(crossed.save()).discs()); + } + @Test void nbtRoundTripKeepsTheShape() { Pottery pottery = new Pottery(List.of( diff --git a/versions/1.20.6/src/main/resources/data/primalpottery/advancements/recipes/pottery.json b/versions/1.20.6/src/main/resources/data/primalpottery/advancements/recipes/pottery.json new file mode 100644 index 0000000..3e6408c --- /dev/null +++ b/versions/1.20.6/src/main/resources/data/primalpottery/advancements/recipes/pottery.json @@ -0,0 +1,21 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_clay": { + "trigger": "minecraft:inventory_changed", + "conditions": { + "items": [ + { + "items": "minecraft:clay_ball" + } + ] + } + } + }, + "rewards": { + "recipes": [ + "primalpottery:pottery_wheel", + "primalpottery:raw_pottery_template" + ] + } +} diff --git a/versions/1.20.6/src/main/resources/data/primalpottery/loot_tables/blocks/pottery_wheel.json b/versions/1.20.6/src/main/resources/data/primalpottery/loot_tables/blocks/pottery_wheel.json new file mode 100644 index 0000000..ea9dd35 --- /dev/null +++ b/versions/1.20.6/src/main/resources/data/primalpottery/loot_tables/blocks/pottery_wheel.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "primalpottery:pottery_wheel" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} diff --git a/versions/1.20.6/src/main/resources/data/primalpottery/recipes/pottery_wheel.json b/versions/1.20.6/src/main/resources/data/primalpottery/recipes/pottery_wheel.json new file mode 100644 index 0000000..0c53197 --- /dev/null +++ b/versions/1.20.6/src/main/resources/data/primalpottery/recipes/pottery_wheel.json @@ -0,0 +1,22 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + " S ", + "PPP", + "TST" + ], + "key": { + "S": { + "item": "minecraft:stone_slab" + }, + "P": { + "tag": "minecraft:planks" + }, + "T": { + "item": "minecraft:stick" + } + }, + "result": { + "id": "primalpottery:pottery_wheel" + } +} diff --git a/versions/1.20.6/src/main/resources/data/primalpottery/recipes/raw_pottery_template.json b/versions/1.20.6/src/main/resources/data/primalpottery/recipes/raw_pottery_template.json new file mode 100644 index 0000000..6fac4ae --- /dev/null +++ b/versions/1.20.6/src/main/resources/data/primalpottery/recipes/raw_pottery_template.json @@ -0,0 +1,14 @@ +{ + "type": "minecraft:crafting_shapeless", + "ingredients": [ + { + "item": "minecraft:clay_ball" + }, + { + "item": "minecraft:stick" + } + ], + "result": { + "id": "primalpottery:raw_pottery_template" + } +} diff --git a/versions/1.21.1/src/main/resources/data/primalpottery/advancement/recipes/pottery.json b/versions/1.21.1/src/main/resources/data/primalpottery/advancement/recipes/pottery.json new file mode 100644 index 0000000..3e6408c --- /dev/null +++ b/versions/1.21.1/src/main/resources/data/primalpottery/advancement/recipes/pottery.json @@ -0,0 +1,21 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_clay": { + "trigger": "minecraft:inventory_changed", + "conditions": { + "items": [ + { + "items": "minecraft:clay_ball" + } + ] + } + } + }, + "rewards": { + "recipes": [ + "primalpottery:pottery_wheel", + "primalpottery:raw_pottery_template" + ] + } +} diff --git a/versions/1.21.1/src/main/resources/data/primalpottery/loot_table/blocks/pottery_wheel.json b/versions/1.21.1/src/main/resources/data/primalpottery/loot_table/blocks/pottery_wheel.json new file mode 100644 index 0000000..ea9dd35 --- /dev/null +++ b/versions/1.21.1/src/main/resources/data/primalpottery/loot_table/blocks/pottery_wheel.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "primalpottery:pottery_wheel" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} diff --git a/versions/1.21.1/src/main/resources/data/primalpottery/recipe/pottery_wheel.json b/versions/1.21.1/src/main/resources/data/primalpottery/recipe/pottery_wheel.json new file mode 100644 index 0000000..0c53197 --- /dev/null +++ b/versions/1.21.1/src/main/resources/data/primalpottery/recipe/pottery_wheel.json @@ -0,0 +1,22 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + " S ", + "PPP", + "TST" + ], + "key": { + "S": { + "item": "minecraft:stone_slab" + }, + "P": { + "tag": "minecraft:planks" + }, + "T": { + "item": "minecraft:stick" + } + }, + "result": { + "id": "primalpottery:pottery_wheel" + } +} diff --git a/versions/1.21.1/src/main/resources/data/primalpottery/recipe/raw_pottery_template.json b/versions/1.21.1/src/main/resources/data/primalpottery/recipe/raw_pottery_template.json new file mode 100644 index 0000000..6fac4ae --- /dev/null +++ b/versions/1.21.1/src/main/resources/data/primalpottery/recipe/raw_pottery_template.json @@ -0,0 +1,14 @@ +{ + "type": "minecraft:crafting_shapeless", + "ingredients": [ + { + "item": "minecraft:clay_ball" + }, + { + "item": "minecraft:stick" + } + ], + "result": { + "id": "primalpottery:raw_pottery_template" + } +} diff --git a/versions/26.3/src/main/resources/data/primalpottery/advancement/recipes/pottery.json b/versions/26.3/src/main/resources/data/primalpottery/advancement/recipes/pottery.json new file mode 100644 index 0000000..3e6408c --- /dev/null +++ b/versions/26.3/src/main/resources/data/primalpottery/advancement/recipes/pottery.json @@ -0,0 +1,21 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_clay": { + "trigger": "minecraft:inventory_changed", + "conditions": { + "items": [ + { + "items": "minecraft:clay_ball" + } + ] + } + } + }, + "rewards": { + "recipes": [ + "primalpottery:pottery_wheel", + "primalpottery:raw_pottery_template" + ] + } +} diff --git a/versions/26.3/src/main/resources/data/primalpottery/loot_table/blocks/pottery_wheel.json b/versions/26.3/src/main/resources/data/primalpottery/loot_table/blocks/pottery_wheel.json new file mode 100644 index 0000000..aa59e16 --- /dev/null +++ b/versions/26.3/src/main/resources/data/primalpottery/loot_table/blocks/pottery_wheel.json @@ -0,0 +1,17 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "primalpottery:pottery_wheel" + } + ], + "condition": { + "type": "minecraft:survives_explosion" + } + } + ] +} diff --git a/versions/26.3/src/main/resources/data/primalpottery/recipe/pottery_wheel.json b/versions/26.3/src/main/resources/data/primalpottery/recipe/pottery_wheel.json new file mode 100644 index 0000000..0ec8801 --- /dev/null +++ b/versions/26.3/src/main/resources/data/primalpottery/recipe/pottery_wheel.json @@ -0,0 +1,16 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + " S ", + "PPP", + "TST" + ], + "key": { + "S": "minecraft:stone_slab", + "P": "#minecraft:planks", + "T": "minecraft:stick" + }, + "result": { + "id": "primalpottery:pottery_wheel" + } +} diff --git a/versions/26.3/src/main/resources/data/primalpottery/recipe/raw_pottery_template.json b/versions/26.3/src/main/resources/data/primalpottery/recipe/raw_pottery_template.json new file mode 100644 index 0000000..83ee009 --- /dev/null +++ b/versions/26.3/src/main/resources/data/primalpottery/recipe/raw_pottery_template.json @@ -0,0 +1,10 @@ +{ + "type": "minecraft:crafting_shapeless", + "ingredients": [ + "minecraft:clay_ball", + "minecraft:stick" + ], + "result": { + "id": "primalpottery:raw_pottery_template" + } +}