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 923db49..d9cb7a7 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 @@ -304,7 +304,7 @@ private static void checkTemplateCycle(GameTestHelper helper, Player player) { helper.assertValueEqual(TemplateItem.profile(blueprint).discs(), profile, "blueprint profile"); var tooltip = blueprint.getTooltipLines(Item.TooltipContext.EMPTY, player, TooltipFlag.Default.NORMAL); helper.assertTrue(tooltip.contains(Component.translatable("tooltip.primalpottery.type", - Component.translatable("pottery.primalpottery.type.jug"))), "blueprint is missing its jug tooltip"); + Component.translatable("pottery.primalpottery.type.plate"))), "shallow blueprint is missing its plate tooltip"); helper.assertTrue(tooltip.contains(Component.translatable("tooltip.primalpottery.capacity", 2)), "blueprint is missing its capacity tooltip"); @@ -536,7 +536,7 @@ private static void forming(GameTestHelper helper, Player player, BlockPos wheel wheel.clearTemplate(); var recipes = helper.getLevel().recipeAccess(); - Pottery profile = new Pottery(List.of(new PotteryDisc(1, 2, 0))); + Pottery profile = new Pottery(List.of(new PotteryDisc(4, 2, 0))); ItemStack unpainted = RawPotteryItem.stack(profile); CraftingInput grid = CraftingInput.of(2, 1, List.of(unpainted, new ItemStack(Items.DYE.pick(DyeColor.BLUE)))); var paintHolder = recipes.getRecipeFor(RecipeType.CRAFTING, grid, helper.getLevel()).orElseThrow(); @@ -845,8 +845,61 @@ private static void checkPlanters(GameTestHelper helper, Player player) { holdStack(player, ItemStack.EMPTY); } + private static void checkPlates(GameTestHelper helper, Player player) { + var server = (ServerPlayer) player; + var previousMode = server.gameMode.getGameModeForPlayer(); + server.setGameMode(GameType.SURVIVAL); + BlockPos floor = new BlockPos(4, 1, 5); + BlockPos pos = floor.above(); + helper.setBlock(floor, Blocks.STONE); + Pottery plate = new Pottery(List.of(new PotteryDisc(2, 8, 6), new PotteryDisc(1, 7, 0))); + helper.assertTrue(plate.isPlate(), "shallow small pottery did not become a plate"); + helper.assertFalse(new Pottery(Pottery.Size.LARGE, plate.discs()).isPlate(), "large pottery became a plate"); + for (int edge = 4; edge < 7; edge++) { + holdStack(player, PotteryItem.stack(plate)); + if (edge == 4) clickOn(helper, player, floor, topPoint(floor, edge), Direction.UP); + else useItemOn(helper, player, pos, slotPoint(pos, edge), Direction.UP); + } + var pots = helper.getBlockEntity(pos, PotteryBlockEntity.class); + for (int i = 4; i < 7; i++) helper.assertTrue(pots.get(i) != null, "empty plate edge " + i); + assertFootprint(helper, pos, 4, 5, 6); + holdStack(player, PotteryItem.stack(plate)); + useItemOn(helper, player, floor, topPoint(floor, 7), Direction.UP); + helper.assertTrue(pots.get(7) != null && pots.get(7).isPlate(), "fourth edge did not take the plate"); + helper.assertTrue(player.getMainHandItem().isEmpty(), "placing the fourth plate did not consume it"); + assertFootprint(helper, pos, 4, 5, 6, 7); + holdStack(player, PotteryItem.stack(plate)); + useItemOn(helper, player, pos, slotPoint(pos, 7), Direction.UP); + helper.assertValueEqual(player.getMainHandItem().getCount(), 1, "full block consumed a fifth plate"); + var named = new ItemStack(Items.APPLE, 3); + named.set(DataComponents.CUSTOM_NAME, Component.literal("Orchard apple")); + holdStack(player, named); + useItemOn(helper, player, pos, slotPoint(pos, 5), Direction.UP); + helper.assertTrue(pots.displayed(5).is(Items.APPLE) && pots.displayed(5).getCount() == 1 && named.getCount() == 2, "one apple on east plate"); + useItemOn(helper, player, pos, slotPoint(pos, 5), Direction.UP); + helper.assertValueEqual(named.getCount(), 2, "occupied plate took another item"); + var saved = pots.getUpdateTag(helper.getLevel().registryAccess()); + var loaded = new PotteryBlockEntity(helper.absolutePos(pos), pots.getBlockState()); + loaded.loadCustomOnly(TagValueInput.create(ProblemReporter.DISCARDING, helper.getLevel().registryAccess(), saved)); + helper.assertTrue(ItemStack.isSameItemSameComponents(named, loaded.displayed(5)), "lost displayed item data on reload"); + holdStack(player, ItemStack.EMPTY); + useItemOn(helper, player, pos, slotPoint(pos, 5), Direction.UP); + helper.assertTrue(pots.displayed(5).isEmpty() && player.getInventory().countItem(Items.APPLE) > 0, "could not retrieve the apple"); + holdStack(player, new ItemStack(Items.IRON_INGOT)); + useItemOn(helper, player, pos, slotPoint(pos, 4), Direction.UP); + pots.take(4); + helper.assertValueEqual(count(helper, helper.absolutePos(pos), Items.IRON_INGOT), 1, "removed plate drops its displayed item"); + helper.assertTrue(pots.displayed(4).isEmpty() && pots.get(5) != null, "plate removal affected its neighbor"); + holdStack(player, new ItemStack(Items.OAK_PLANKS)); + useItemOn(helper, player, pos, slotPoint(pos, 6), Direction.UP); + helper.assertTrue(pots.displayed(6).isEmpty(), "displayed a block item"); + server.setGameMode(previousMode); + player.setItemInHand(InteractionHand.MAIN_HAND, ItemStack.EMPTY); + } + private static void vessels(GameTestHelper helper) { Player player = mockPlayer(helper); + checkPlates(helper, player); checkPaintingTable(helper, player); checkPlanters(helper, player); Pottery jug = jug(); @@ -965,7 +1018,7 @@ player, InteractionHand.MAIN_HAND, new BlockHitResult(bubble, Direction.SOUTH, h helper.assertBlockPresent(Blocks.BUBBLE_COLUMN, bubblePos); helper.assertTrue(PotteryItem.contents(player.getMainHandItem()).isEmpty(), "bubble column filled the jug"); - hold(player, new Pottery(List.of(new PotteryDisc(2, 3, 0)))); + hold(player, new Pottery(List.of(new PotteryDisc(4, 3, 0)))); clickThrough(helper, player, waterStone); helper.assertBlockState(water, Blocks.WATER.defaultBlockState()); helper.assertTrue(PotteryItem.contents(player.getMainHandItem()).isEmpty(), "lump filled"); @@ -1065,7 +1118,7 @@ private static void lidsAndBreaks(GameTestHelper helper, Player player) { helper.assertFalse(cleared.contains("lid"), "take lid"); helper.assertFalse(PotteryItem.lid(player.getMainHandItem()), "lid flag"); - hold(player, new Pottery(List.of(new PotteryDisc(2, 3, 0)))); + hold(player, new Pottery(List.of(new PotteryDisc(4, 3, 0)))); LidSync.apply(player, true, true); helper.assertFalse(PotteryItem.lid(player.getMainHandItem()), "lump lid"); @@ -1103,7 +1156,7 @@ private static void lidsAndBreaks(GameTestHelper helper, Player player) { BlockPos lumpFloor = new BlockPos(12, 1, 6); helper.setBlock(lumpFloor, Blocks.STONE); - hold(player, new Pottery(List.of(new PotteryDisc(2, 3, 0)))); + hold(player, new Pottery(List.of(new PotteryDisc(4, 3, 0)))); useItemOn(helper, player, lumpFloor, topPoint(lumpFloor, 0), Direction.UP); BlockPos lumpPos = lumpFloor.above(); helper.assertBlockPresent(ModBlocks.POTTERY, lumpPos); @@ -1365,17 +1418,11 @@ private static void assertFootprint(GameTestHelper helper, BlockPos relative, in helper.assertFalse(Shapes.joinIsNotEmpty(shape, collision, BooleanOp.NOT_SAME), "selection differs from occupied slots"); 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)); - boolean filled = false; - for (int slot : occupied) { - if (slot == index) { - filled = true; - break; - } - } - helper.assertTrue(Shapes.joinIsNotEmpty(collision, box, BooleanOp.AND) == filled, "collision slot " + index); + var expected = Shapes.empty(); + for (int slot : occupied) { + expected = Shapes.or(expected, Shapes.create(PotteryBlockEntity.box(slot))); } + helper.assertFalse(Shapes.joinIsNotEmpty(collision, expected, BooleanOp.NOT_SAME), "collision differs from occupied footprint"); } private static void assertNoPottery(GameTestHelper helper, BlockPos relative, String label) { @@ -1455,7 +1502,7 @@ private static void focusedPots(GameTestHelper helper, Player player) { assertStored(helper, entity.contents(3), Fluids.WATER, 10, "fifth click changed the far slot"); helper.assertBlockNotPresent(ModBlocks.POTTERY, pots.above()); helper.assertBlockNotPresent(ModBlocks.POTTERY, pots.north()); - for (int index = 0; index < PotteryBlockEntity.SLOTS; index++) { + for (int index = 0; index < PotteryBlockEntity.CORNERS; index++) { helper.assertTrue(entity.get(index) != null, "slot " + index + " emptied"); } @@ -1513,7 +1560,7 @@ private static void pourAndBuckets(GameTestHelper helper, Player player, Pottery helper.assertTrue(entity.lid(0), "pour opened the lid"); assertFluid(helper, player.getMainHandItem(), Fluids.WATER, 20, "lidded pot took fluid"); - hold(player, new Pottery(List.of(new PotteryDisc(2, 3, 0)))); + hold(player, new Pottery(List.of(new PotteryDisc(4, 3, 0)))); useItemOn(helper, player, pots, slotPoint(pots, 1), Direction.UP); helper.assertTrue(entity.get(1) != null, "lump was not placed"); holdStack(player, PotteryItem.stack(jug, VesselContents.of(Fluids.WATER, 20))); diff --git a/src/main/java/net/modcrafters/minecraft/primalpottery/block/PotteryBlock.java b/src/main/java/net/modcrafters/minecraft/primalpottery/block/PotteryBlock.java index 5497ef5..035e22f 100644 --- a/src/main/java/net/modcrafters/minecraft/primalpottery/block/PotteryBlock.java +++ b/src/main/java/net/modcrafters/minecraft/primalpottery/block/PotteryBlock.java @@ -90,7 +90,7 @@ public static boolean breakFocused(Level level, BlockPos pos, Player player) { if (hit == null) { return true; } - int part = pottery.hasLargePot() ? 0 : PartHits.quadrant(pos, hit.getLocation(), hit.getDirection()); + int part = pottery.hitSlot(hit); if (pottery.get(part) == null) { return true; } @@ -124,7 +124,7 @@ public static ItemStack pickFocused(BlockGetter level, BlockPos pos, @Nullable B if (hit == null || !(level.getBlockEntity(pos) instanceof PotteryBlockEntity pots)) { return ItemStack.EMPTY; } - int part = pots.hasLargePot() ? 0 : PartHits.quadrant(pos, hit.getLocation(), hit.getDirection()); + int part = pots.hitSlot(hit); Pottery profile = pots.get(part); return profile == null ? ItemStack.EMPTY : PotteryItem.stack(profile, pots.contents(part), pots.lid(part), pots.dye(part), pots.planter(part)); @@ -178,7 +178,7 @@ public static InteractionResult tryPlace( return InteractionResult.FAIL; } Pottery profile = PotteryItem.read(stack); - int target = Placement.destination(pottery, part, sneak, face, profile.size()); + int target = Placement.destination(pottery, part, sneak, face, profile); if (target < 0) { return InteractionResult.FAIL; } @@ -198,8 +198,27 @@ private static InteractionResult interact(Level level, BlockPos pos, Player play if (!(level.getBlockEntity(pos) instanceof PotteryBlockEntity pottery)) { return InteractionResult.PASS; } - int part = pottery.hasLargePot() ? 0 : PartHits.quadrant(pos, hit.getLocation(), hit.getDirection()); + int part = pottery.hitSlot(hit); Pottery pot = pottery.get(part); + if (pot != null && pot.isPlate() && !player.isShiftKeyDown()) { + if (stack.isEmpty() && player.getMainHandItem().isEmpty() && pottery.displayed(part).isEmpty() + && !(player.getOffhandItem().getItem() instanceof BlockItem)) stack = player.getOffhandItem(); + ItemStack shown = pottery.displayed(part); + if (stack.isEmpty() && !shown.isEmpty()) { + if (!level.isClientSide()) { + pottery.setDisplayed(part, ItemStack.EMPTY); + if (!player.addItem(shown)) popResource(level, pos, shown); + } + return InteractionResult.SUCCESS; + } + if (!stack.isEmpty() && !(stack.getItem() instanceof BlockItem)) { + if (shown.isEmpty() && !pottery.lid(part) && !level.isClientSide()) { + pottery.setDisplayed(part, stack); + if (!player.hasInfiniteMaterials()) stack.shrink(1); + } + return InteractionResult.SUCCESS; + } + } if (pot != null && stack.isEmpty() && player.getMainHandItem().isEmpty() && !player.isShiftKeyDown() && player.getOffhandItem().getItem() instanceof BlockItem offhand && (Planter.isSoil(offhand.getBlock()) || Planter.acceptsPlant(pot.size(), offhand.getBlock()))) { @@ -285,7 +304,8 @@ private static InteractionResult interact(Level level, BlockPos pos, Player play return InteractionResult.SUCCESS; } if (Placement.holding(stack)) { - return tryPlace(level, pos, player, stack, part, player.isShiftKeyDown(), hit.getDirection()); + int slot = PartHits.placementSlot(PotteryItem.read(stack), pos, hit.getLocation(), hit.getDirection()); + return tryPlace(level, pos, player, stack, slot, player.isShiftKeyDown(), hit.getDirection()); } return InteractionResult.PASS; } @@ -333,6 +353,16 @@ private static void pour(Level level, BlockPos pos, ItemStack stack, PotteryBloc level.playSound(null, pos, sound, SoundSource.BLOCKS, 1.0F, 1.0F)); } + //? if <26.1 { + /*@Override + protected void onRemove(BlockState state, Level level, BlockPos pos, BlockState replacement, boolean moving) { + if (!state.is(replacement.getBlock()) && level.getBlockEntity(pos) instanceof PotteryBlockEntity pottery) { + pottery.dropDisplayedItems(); + } + super.onRemove(state, level, pos, replacement, moving); + } + *///?} + private static VoxelShape occupied(BlockGetter level, BlockPos pos) { if (!(level.getBlockEntity(pos) instanceof PotteryBlockEntity pottery)) { return Shapes.empty(); diff --git a/src/main/java/net/modcrafters/minecraft/primalpottery/block/PotteryBlockEntity.java b/src/main/java/net/modcrafters/minecraft/primalpottery/block/PotteryBlockEntity.java index 3214a9c..02518c3 100644 --- a/src/main/java/net/modcrafters/minecraft/primalpottery/block/PotteryBlockEntity.java +++ b/src/main/java/net/modcrafters/minecraft/primalpottery/block/PotteryBlockEntity.java @@ -22,7 +22,9 @@ import org.jspecify.annotations.Nullable; public class PotteryBlockEntity extends BlockEntity { - public static final int SLOTS = 4; + public static final int CORNERS = 4; + public static final int SLOTS = 8; + public static final double PLATE_SCALE = 2.0 / 3; public static final AABB FULL_BLOCK = new AABB(0, 0, 0, 1, 1, 1); public static final List BOXES = List.of(box(0), box(1), box(2), box(3)); @@ -30,6 +32,8 @@ public class PotteryBlockEntity extends BlockEntity { private final VesselContents[] contents = blank(); private final Planter[] planters = new Planter[SLOTS]; private final boolean[] lids = new boolean[SLOTS]; + private final net.minecraft.core.NonNullList displayed = + net.minecraft.core.NonNullList.withSize(SLOTS, ItemStack.EMPTY); private final String[] dyes = new String[SLOTS]; public PotteryBlockEntity(BlockPos pos, BlockState state) { @@ -37,6 +41,11 @@ public PotteryBlockEntity(BlockPos pos, BlockState state) { } public static AABB box(int index) { + if (index >= CORNERS) { + double x = index == 5 ? 2.0/3 : index == 7 ? 0 : 1.0/3; + double z = index == 6 ? 2.0/3 : index == 4 ? 0 : 1.0/3; + return new AABB(x, 0, z, x+1.0/3, 3.0/32, z+1.0/3); + } boolean positiveX = index == 1 || index == 2; boolean positiveZ = index == 2 || index == 3; double x = positiveX ? 0.5 : 0; @@ -52,6 +61,35 @@ public boolean hasLargePot() { return this.slots[0] != null && this.slots[0].size() == Pottery.Size.LARGE; } + public boolean canPlace(int index, Pottery profile) { + if (index < 0 || index >= SLOTS || slots[index] != null || hasLargePot()) return false; + if (profile.size() == Pottery.Size.LARGE) return index == 0 && isEmpty(); + if (profile.isPlate() != (index >= CORNERS)) return false; + for (int i = 0; i < SLOTS; i++) { + if (slots[i] == null) continue; + if ((index < CORNERS) != (i < CORNERS) && box(index).intersects(box(i))) return false; + } + return true; + } + + public int hitSlot(net.minecraft.world.phys.BlockHitResult hit) { + if (hasLargePot()) return 0; + var point = hit.getLocation().subtract(net.minecraft.world.phys.Vec3.atLowerCornerOf(worldPosition)); + for (int i = CORNERS; i < SLOTS; i++) { + if (slots[i] != null && box(i).inflate(1.0e-6).contains(point)) return i; + } + return net.modcrafters.minecraft.primalpottery.pottery.PartHits.quadrant(worldPosition, hit.getLocation(), hit.getDirection()); + } + + public ItemStack displayed(int index) { + return displayed.get(index); + } + + public void setDisplayed(int index, ItemStack stack) { + displayed.set(index, stack.isEmpty() ? ItemStack.EMPTY : stack.copyWithCount(1)); + sync(); + } + public boolean isEmpty() { for (Pottery slot : this.slots) { if (slot != null) { @@ -143,7 +181,7 @@ public void setLid(int index, boolean lid) { if (index < 0 || index >= SLOTS || this.slots[index] == null) { return; } - if (lid && this.planters[index] != null) { + if (lid && (this.planters[index] != null || !displayed(index).isEmpty())) { return; } this.lids[index] = lid; @@ -165,7 +203,7 @@ public boolean put(int index, Pottery pottery, VesselContents contents, boolean } index = 0; } - if (index < 0 || index >= this.slots.length || this.hasLargePot() || this.slots[index] != null) { + if (!canPlace(index, pottery)) { return false; } Pottery[] next = Arrays.copyOf(this.slots, this.slots.length); @@ -186,6 +224,7 @@ public boolean put(int index, Pottery pottery, VesselContents contents, boolean return null; } Pottery taken = this.slots[index]; + dropDisplayed(index); this.planters[index] = null; Pottery[] next = Arrays.copyOf(this.slots, this.slots.length); VesselContents[] nextContents = Arrays.copyOf(this.contents, this.contents.length); @@ -199,6 +238,23 @@ public boolean put(int index, Pottery pottery, VesselContents contents, boolean return taken; } + //? if >=26.1 { + @Override + public void preRemoveSideEffects(BlockPos pos, BlockState state) { + dropDisplayedItems(); + super.preRemoveSideEffects(pos, state); + } + //?} + + void dropDisplayedItems() { + for (int i = 0; i < SLOTS; i++) dropDisplayed(i); + } + + private void dropDisplayed(int index) { + ItemStack stack = displayed.set(index, ItemStack.EMPTY); + if (!stack.isEmpty() && level != null && !level.isClientSide()) Block.popResource(level, worldPosition, stack); + } + public void dropAll() { if (this.level == null || this.level.isClientSide()) { return; @@ -208,6 +264,7 @@ public void dropAll() { if (pottery == null) { continue; } + dropDisplayed(index); this.dropPlanting(index); this.level.addFreshEntity(new ItemEntity( this.level, @@ -240,24 +297,30 @@ private void replace(Pottery[] next, VesselContents[] nextContents, boolean[] ne protected void saveAdditional(net.minecraft.world.level.storage.ValueOutput output) { super.saveAdditional(output); output.store("pottery", CompoundTag.CODEC, this.saveSlots()); + net.minecraft.world.ContainerHelper.saveAllItems(output, displayed); } @Override protected void loadAdditional(net.minecraft.world.level.storage.ValueInput input) { super.loadAdditional(input); input.read("pottery", CompoundTag.CODEC).ifPresent(this::loadSlots); + displayed.clear(); + net.minecraft.world.ContainerHelper.loadAllItems(input, displayed); } //?} else { /*@Override protected void saveAdditional(CompoundTag tag, net.minecraft.core.HolderLookup.Provider registries) { super.saveAdditional(tag, registries); tag.put("pottery", this.saveSlots()); + net.minecraft.world.ContainerHelper.saveAllItems(tag, displayed, registries); } @Override protected void loadAdditional(CompoundTag tag, net.minecraft.core.HolderLookup.Provider registries) { super.loadAdditional(tag, registries); this.loadSlots(Nbt.compound(tag, "pottery")); + displayed.clear(); + net.minecraft.world.ContainerHelper.loadAllItems(tag, displayed, registries); } *///?} @@ -273,12 +336,14 @@ private static VesselContents[] blank() { public void removeComponentsFromTag(net.minecraft.world.level.storage.ValueOutput output) { super.removeComponentsFromTag(output); output.discard("pottery"); + output.discard("Items"); } //?} else { /*@Override public void removeComponentsFromTag(CompoundTag tag) { super.removeComponentsFromTag(tag); tag.remove("pottery"); + tag.remove("Items"); } *///?} @@ -322,6 +387,7 @@ private void loadSlots(CompoundTag tag) { CompoundTag pottery = Nbt.compound(entry, "pottery"); if (!pottery.isEmpty()) { this.slots[index] = Pottery.load(pottery); + if (this.slots[index] == null) continue; this.contents[index] = VesselContents.read(entry).limitedTo(this.slots[index]); this.lids[index] = Nbt.getBoolean(entry, "lid"); if (entry.contains("soil") && this.contents[index].isEmpty() && !this.lids[index] && Planter.fits(this.slots[index])) { @@ -331,6 +397,32 @@ private void loadSlots(CompoundTag tag) { this.dyes[index] = dye.isEmpty() ? null : dye; } } + if (list.size() == CORNERS) migrateCornerPlates(); + } + + private void migrateCornerPlates() { + for (int corner = 0; corner < CORNERS; corner++) { + Pottery plate = slots[corner]; + if (plate == null || !plate.isPlate()) continue; + slots[corner] = null; + boolean moved = false; + for (int offset = 0; offset < CORNERS; offset++) { + int edge = CORNERS + (corner + offset) % CORNERS; + if (!canPlace(edge, plate)) continue; + slots[edge] = plate; + contents[edge] = contents[corner]; + contents[corner] = VesselContents.EMPTY; + lids[edge] = lids[corner]; + lids[corner] = false; + dyes[edge] = dyes[corner]; + dyes[corner] = null; + planters[edge] = planters[corner]; + planters[corner] = null; + moved = true; + break; + } + if (!moved) slots[corner] = plate; + } } private void sync() { 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 9d60d19..1c163d5 100644 --- a/src/main/java/net/modcrafters/minecraft/primalpottery/client/FlowerPaint.java +++ b/src/main/java/net/modcrafters/minecraft/primalpottery/client/FlowerPaint.java @@ -6,7 +6,7 @@ /** Maps one square of slip decoration across the throwing rings of each exterior face. */ final class FlowerPaint { - private record Key(double x, double y, double z, java.util.List discs, FacePaint paint) {} + 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; @@ -15,7 +15,7 @@ private FlowerPaint() { } static synchronized Mesh vessel(double x, double base, double z, Pottery pottery) { - Key key = new Key(x, base, z, pottery.discs(), pottery.paint()); + Key key = new Key(pottery.isPlate(), x, base, z, pottery.discs(), pottery.paint()); Mesh mesh = vessels.get(key); if (mesh == null) { mesh = new Mesh(); @@ -32,6 +32,10 @@ static synchronized Mesh vessel(double x, double base, double z, Pottery pottery } static void apply(Mesh vessel, double x, double base, double z, Pottery pottery) { + if (pottery.isPlate()) { + PlatePaint.build(vessel, x, base, z, pottery, false); + return; + } Mesh overlay = overlay(vessel, x, base, z, pottery); if (pottery.hasFlowerPaint()) { vessel.add(overlay); @@ -44,6 +48,10 @@ static void apply(Mesh vessel, double x, double base, double z, Pottery pottery) static Mesh overlay(Mesh vessel, double x, double base, double z, Pottery pottery) { Mesh overlay = new Mesh(); + if (pottery.isPlate()) { + PlatePaint.build(overlay, x, base, z, pottery, true); + return overlay; + } var wall = PotteryProfile.profile(pottery.discs(), false); if (wall.isEmpty()) { return overlay; 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 2da4e91..106ac76 100644 --- a/src/main/java/net/modcrafters/minecraft/primalpottery/client/Mesh.java +++ b/src/main/java/net/modcrafters/minecraft/primalpottery/client/Mesh.java @@ -108,6 +108,15 @@ public void boxRotated(double x0, double y0, double z0, double x1, double y1, do } } + void scaleWidth(double centerX, double centerZ, double scale) { + for (Quad quad : quads) { + for (int v = 0; v < 4; v++) { + quad.x[v] = (float) (centerX + (quad.x[v] - centerX) * scale); + quad.z[v] = (float) (centerZ + (quad.z[v] - centerZ) * scale); + } + } + } + public void add(Mesh other) { this.quads.addAll(other.quads); } diff --git a/src/main/java/net/modcrafters/minecraft/primalpottery/client/PaintingScreen.java b/src/main/java/net/modcrafters/minecraft/primalpottery/client/PaintingScreen.java index 016b061..db8c005 100644 --- a/src/main/java/net/modcrafters/minecraft/primalpottery/client/PaintingScreen.java +++ b/src/main/java/net/modcrafters/minecraft/primalpottery/client/PaintingScreen.java @@ -24,6 +24,7 @@ public final class PaintingScreen extends AbstractContainerScreen private static final int TANK_X = (WIDTH - (FacePaint.COLORS - 1) * STRIDE - SWATCH_SIZE) / 2; private static final int TANK_Y = 127, COUNT_Y = TANK_Y + SWATCH_SIZE + 5; private int selected = DyeColor.WHITE.getId(); + private int columns = FacePaint.SIDE; private int lastCell = -1; private float yaw; private float tilt = 30; @@ -135,6 +136,9 @@ private void panel(GuiGraphicsExtractor graphics) { if (!ItemStack.isSameItemSameComponents(pot, cached)) { cached = pot.copy(); Pottery pottery = PotteryItem.read(pot); + int nextColumns = pot.isEmpty() ? FacePaint.SIDE : pottery.paintColumns(); + if (columns != nextColumns) tilt = pottery.isPlate() ? 65 : 30; + columns = nextColumns; pattern = pot.isEmpty() ? FacePaint.EMPTY : pottery.paint(); preview = pot.isEmpty() ? null : PotteryPreview.rotatablePot(pottery, PREVIEW_WIDTH, PREVIEW_HEIGHT, tilt); dye = PotteryItem.dye(pot); @@ -148,11 +152,18 @@ private void panel(GuiGraphicsExtractor graphics) { graphics.fill(x+slot.x, y+slot.y, x+slot.x+16, y+slot.y+16, 0xFF9B9087); } int clay = dye == null ? 0xFF92583E : 0xFF000000 | Sprites.dyeTint(dye); - graphics.fill(x+GRID_X-1, y+GRID_Y-1, x+GRID_X+97, y+GRID_Y+97, 0xFF594236); - for (int i = 0; i < FacePaint.CELLS; i++) { - int color = pattern.color(i); - int px = x+GRID_X+(i%16)*PIXEL, py = y+GRID_Y+(i/16)*PIXEL; - graphics.fill(px, py, px+PIXEL-1, py+PIXEL-1, color < 0 ? clay : 0xFF000000 | FacePaint.rgb(color)); + int gridLeft = x + gridX(), gridTop = y + GRID_Y; + graphics.fill(gridLeft-1, gridTop-1, gridLeft+columns*PIXEL+1, gridTop+FacePaint.SIDE*PIXEL+1, 0xFF594236); + for (int row = 0; row < FacePaint.SIDE; row++) { + for (int column = 0; column < columns; column++) { + int color = pattern.color(paintCell(column, row)); + int px = gridLeft + column*PIXEL, py = gridTop + row*PIXEL; + graphics.fill(px, py, px+PIXEL-1, py+PIXEL-1, color < 0 ? clay : 0xFF000000 | FacePaint.rgb(color)); + } + } + if (columns < FacePaint.SIDE) { + graphics.text(font, label("center"), gridLeft+columns*PIXEL+4, gridTop, 0xFF51473D, false); + graphics.text(font, label("rim"), gridLeft+columns*PIXEL+4, gridTop+FacePaint.SIDE*PIXEL-font.lineHeight, 0xFF51473D, false); } int previewX = x+PREVIEW_X, previewY = y+PREVIEW_Y; graphics.fillGradient(previewX, previewY, previewX+PREVIEW_WIDTH, previewY+PREVIEW_HEIGHT, 0xFF704B3F, 0xFFA67859); @@ -223,9 +234,19 @@ private void hover(GuiGraphicsExtractor graphics, int mx, int my) { //graphics.renderComponentTooltip(font, lines, mx, my); } + private int gridX() { + return GRID_X + (FacePaint.SIDE - columns)*PIXEL/2; + } + + private int paintCell(int column, int row) { + // A plate's existing 64 pixels are stored one radial column at a time. + return columns == FacePaint.SIDE ? row*FacePaint.SIDE + column : column*FacePaint.SIDE + row; + } + private int cellAt(double x, double y) { - int dx = (int)Math.floor(x-leftPos-GRID_X), dy = (int)Math.floor(y-topPos-GRID_Y); - return dx >= 0 && dy >= 0 && dx < 16*PIXEL && dy < 16*PIXEL ? dy/PIXEL*16 + dx/PIXEL : -1; + int dx = (int)Math.floor(x-leftPos-gridX()), dy = (int)Math.floor(y-topPos-GRID_Y); + return dx >= 0 && dy >= 0 && dx < columns*PIXEL && dy < FacePaint.SIDE*PIXEL + ? paintCell(dx/PIXEL, dy/PIXEL) : -1; } private static Component colorName(int color) { diff --git a/src/main/java/net/modcrafters/minecraft/primalpottery/client/PlatePaint.java b/src/main/java/net/modcrafters/minecraft/primalpottery/client/PlatePaint.java new file mode 100644 index 0000000..057569d --- /dev/null +++ b/src/main/java/net/modcrafters/minecraft/primalpottery/client/PlatePaint.java @@ -0,0 +1,91 @@ +package net.modcrafters.minecraft.primalpottery.client; + +import java.util.ArrayList; +import java.util.List; +import net.modcrafters.minecraft.primalpottery.pottery.FacePaint; +import net.modcrafters.minecraft.primalpottery.pottery.Pottery; +import net.modcrafters.minecraft.primalpottery.pottery.PotteryProfile; +import net.modcrafters.minecraft.primalpottery.pottery.PotteryProfile.Station; + +/** Unwraps one sector along the clay surface, from the middle of the floor to the lip. */ +final class PlatePaint { + private PlatePaint() {} + + static void build(Mesh mesh, double x, double base, double z, Pottery plate, boolean atlas) { + var rim = plate.discs().getFirst(); + List path = new ArrayList<>(); + if (rim.innerRadius() > 0) { + var cavity = PotteryProfile.cavity(plate.discs()); + path.add(new Station(cavity.getFirst().y(), 0)); + path.addAll(cavity); + } else { + path.add(new Station(plate.height(), 0)); + } + path.add(new Station(plate.height(), rim.radius())); + double[] distance = new double[path.size()]; + for (int i = 1; i < path.size(); i++) { + Station a = path.get(i-1), b = path.get(i); + distance[i] = distance[i-1] + Math.hypot(b.radius()-a.radius(), b.y()-a.y()); + } + double length = distance[distance.length-1]; + int columns = plate.paintColumns(); + for (int side = 0; side < 8; side++) { + double angle = Math.PI / 8 + side * Math.PI / 4; + double x0 = Math.cos(angle), z0 = Math.sin(angle); + double x1 = Math.cos(angle + Math.PI/4), z1 = Math.sin(angle + Math.PI/4); + for (int column = 0; column < columns; column++) { + double left = (double)column/columns, right = (double)(column+1)/columns; + for (int i = 1; i < path.size(); i++) { + if (distance[i] <= distance[i-1]) continue; + Station a = path.get(i-1), b = path.get(i); + double start = distance[i-1]*FacePaint.SIDE/length, end = distance[i]*FacePaint.SIDE/length; + for (double from = start; from < end;) { + int row = Math.min((int)from, FacePaint.SIDE-1); + int ink = plate.paint().color(column*FacePaint.SIDE + row); + double to = end; + if (!atlas) { + int stop = row+1; + while (stop < end && plate.paint().color(column*FacePaint.SIDE + stop) == ink) stop++; + to = Math.min(end, stop); + } + if (atlas || ink != FacePaint.ERASE) { + mesh.quads().add(strip(x, base, z, a, b, x0, z0, x1, z1, angle, left, right, + start, end, from, to, column, ink, atlas)); + } + from = to; + } + } + } + } + } + + private static Mesh.Quad strip(double x, double base, double z, Station a, Station b, + double x0, double z0, double x1, double z1, double angle, double left, double right, + double start, double end, double from, double to, int column, int ink, boolean atlas) { + double rise = b.y()-a.y(), run = (b.radius()-a.radius())*Math.cos(Math.PI/8); + double normalLength = Math.hypot(rise, run); + double mid = angle + Math.PI/8; + float nx = (float)(-rise*Math.cos(mid)/normalLength); + float ny = (float)(run/normalLength); + float nz = (float)(-rise*Math.sin(mid)/normalLength); + Mesh.Quad q = new Mesh.Quad(nx, ny, nz, atlas ? Mesh.Texture.FLOWER_PAINT : Mesh.Texture.PIGMENT); + q.cornerNormals = new float[12]; + if (!atlas) q.pigment = FacePaint.rgb(ink); + for (int v = 0; v < 4; v++) { + double u = v < 2 ? from : to; + double t = (u-start)/(end-start); + double across = v == 0 || v == 3 ? left : right; + // The slight inward/upward inset clears the clay, including vertical inner walls. + double radius = Math.max(0, a.radius() + t*(b.radius()-a.radius()) - 0.008); + q.x[v] = (float)(x + radius*(x0 + across*(x1-x0))); + q.z[v] = (float)(z + radius*(z0 + across*(z1-z0))); + q.y[v] = (float)(base + a.y() + t*rise + 0.012); + q.u[v] = atlas ? (float)u : 8; + q.v[v] = atlas ? column + 0.5F : 8; + q.cornerNormals[v*3] = q.nx; + q.cornerNormals[v*3+1] = q.ny; + q.cornerNormals[v*3+2] = q.nz; + } + return q; + } +} diff --git a/src/main/java/net/modcrafters/minecraft/primalpottery/client/PotteryPreview.java b/src/main/java/net/modcrafters/minecraft/primalpottery/client/PotteryPreview.java index 7a6a697..c142245 100644 --- a/src/main/java/net/modcrafters/minecraft/primalpottery/client/PotteryPreview.java +++ b/src/main/java/net/modcrafters/minecraft/primalpottery/client/PotteryPreview.java @@ -59,6 +59,12 @@ static Placement placement(Pottery pottery) { Mesh pot = new Mesh(); pot.vessel(0, 0, 0, pottery.discs(), Mesh.Texture.FIRED_CLAY); pot.fitSprite(); + if (pottery.isPlate()) { + double offset = 32.0 / 3; + pot.scaleWidth(0, 0, net.modcrafters.minecraft.primalpottery.block.PotteryBlockEntity.PLATE_SCALE); + return new Placement(pot, List.of(new Vec3(0, 0, -offset), new Vec3(offset, 0, 0), + new Vec3(0, 0, offset), new Vec3(-offset, 0, 0)), pottery.height(), 16); + } boolean small = pottery.size() == Pottery.Size.SMALL; double radius = pottery.discs().stream().mapToDouble(PotteryDisc::radius).max().orElse(0); double offset = small ? Math.hypot(8, 8) : 0; 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 4d3d3ce..a2510fa 100644 --- a/src/main/java/net/modcrafters/minecraft/primalpottery/client/PotteryRenderer.java +++ b/src/main/java/net/modcrafters/minecraft/primalpottery/client/PotteryRenderer.java @@ -46,9 +46,11 @@ public final class PotteryRenderer implements BlockEntityRenderer=26.1 { private static final BlockDisplayContext PLANT_DISPLAY = BlockDisplayContext.create(); private final BlockModelResolver models; + private final net.minecraft.client.renderer.item.ItemModelResolver items; public PotteryRenderer(BlockEntityRendererProvider.Context context) { this.models = context.blockModelResolver(); + this.items = context.itemModelResolver(); } //?} else { /*public PotteryRenderer(BlockEntityRendererProvider.Context context) { @@ -74,6 +76,15 @@ public void extractRenderState( state.contents = blockEntity.contents(); state.lids = blockEntity.lids(); state.dyes = blockEntity.dyes(); + state.displayed = null; + for (int i = 0; i < state.slots.length; i++) { + var stack = blockEntity.displayed(i); + if (stack.isEmpty() || state.slots[i] == null) continue; + if (state.displayed == null) state.displayed = new net.minecraft.client.renderer.item.ItemStackRenderState[state.slots.length]; + var item = new net.minecraft.client.renderer.item.ItemStackRenderState(); + items.updateForTopItem(item, stack, net.minecraft.world.item.ItemDisplayContext.FIXED, blockEntity.getLevel(), null, i); + state.displayed[i] = item; + } state.plantings = plantings(state.slots, blockEntity); for (Planting planting : state.plantings) { for (BlockState voxel : planting.tree.keySet()) { @@ -132,6 +143,15 @@ public void submit( (pose, buffer) -> drawFluids(draws, buffer, pose, state.lightCoords, false) ); } + if (state.displayed != null) { + for (int i = 0; i < state.displayed.length; i++) { + if (state.displayed[i] == null) continue; + poseStack.pushPose(); + positionDisplay(poseStack, i, state.slots[i]); + state.displayed[i].submit(poseStack, collector, state.lightCoords, OverlayTexture.NO_OVERLAY, 0); + poseStack.popPose(); + } + } for (Planting planting : state.plantings) { planting.drawTree(poseStack, voxel -> planting.treeModels.get(voxel).submit( poseStack, collector, state.lightCoords, OverlayTexture.NO_OVERLAY, 0)); @@ -150,6 +170,7 @@ public void submit( public static final class State extends BlockEntityRenderState { private List plantings = List.of(); + private net.minecraft.client.renderer.item.ItemStackRenderState[] displayed; public Pottery[] slots = new Pottery[PotteryBlockEntity.SLOTS]; public VesselContents[] contents = new VesselContents[PotteryBlockEntity.SLOTS]; public boolean[] lids = new boolean[PotteryBlockEntity.SLOTS]; @@ -193,6 +214,15 @@ public void render( var buffer = buffers.getBuffer(net.minecraft.client.renderer.RenderType.entityTranslucent(Sprites.blocks())); drawFluids(draws, buffer, poseStack.last(), light, false); } + for (int i = 0; i < slots.length; i++) { + var stack = blockEntity.displayed(i); + if (stack.isEmpty() || slots[i] == null) continue; + poseStack.pushPose(); + positionDisplay(poseStack, i, slots[i]); + net.minecraft.client.Minecraft.getInstance().getItemRenderer().renderStatic(stack, + net.minecraft.world.item.ItemDisplayContext.FIXED, light, OverlayTexture.NO_OVERLAY, poseStack, buffers, blockEntity.getLevel(), i); + poseStack.popPose(); + } for (Planting planting : plantings) { planting.drawTree(poseStack, voxel -> net.minecraft.client.Minecraft.getInstance().getBlockRenderer() .renderSingleBlock(voxel, poseStack, buffers, light, OverlayTexture.NO_OVERLAY)); @@ -213,6 +243,18 @@ public void render( } *///?} + private static void positionDisplay(PoseStack pose, int slot, Pottery pottery) { + var center = PotteryBlockEntity.box(slot).getCenter(); + float width = (float) (pottery.discs().getFirst().radius() * 1.4 + * (slot >= PotteryBlockEntity.CORNERS ? PotteryBlockEntity.PLATE_SCALE : 1)); + pose.translate(center.x * 32, pottery.height() + 0.06 + width / 32, center.z * 32); + //? if >=26.1 { + pose.rotateDegrees(com.mojang.math.Axis.XP, -90); + //?} else + //pose.mulPose(com.mojang.math.Axis.XP.rotationDegrees(-90)); + pose.scale(width, width, width); + } + private static final float TREE_BLOCK_SIZE = 4.0F; // Two texture pixels in the pottery mesh's 32 units per block. private static final Map>> TREE_SURFACES = new WeakHashMap<>(); @@ -254,6 +296,7 @@ private static final class Planting { double rim = cavity.getLast().y(); this.y = rim - Math.min(0.25, (rim - cavity.getFirst().y()) / 2); double radius = PotteryProfile.sample(cavity, this.y); + if (slot >= PotteryBlockEntity.CORNERS) radius *= PotteryBlockEntity.PLATE_SCALE; Mesh.Texture texture = Mesh.Texture.DIRT; if (planter.soil() == Blocks.GRASS_BLOCK) { texture = Mesh.Texture.GRASS; @@ -363,7 +406,7 @@ private static final class PlacedPot { vessel.fitSprite(); if (!FacePaint.EMPTY.equals(pottery.paint())) { Mesh overlay = FlowerPaint.overlay(vessel, x, 0, z, pottery); - if (pottery.hasFlowerPaint()) { + if (pottery.hasFlowerPaint() && !pottery.isPlate()) { vessel.add(overlay); } else { paint = overlay; @@ -382,13 +425,21 @@ private PlacedPot[] bodies(Pottery[] slots, boolean[] lids) { if (positions[i] == null || lids[i] && positions[i].lid == null) { var center = PotteryBlockEntity.box(i, pottery.size()).getCenter(); double x = center.x * 32, z = center.z * 32; - if (positions[i] == null) positions[i] = new PlacedPot(pottery, x, z); + 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; + } if (lids[i]) { var cover = pottery.cover(); Mesh lid = new Mesh(); if (cover != null) { lid.cover(x, 0, z, cover, Mesh.Texture.FIRED_CLAY); lid.fitSprite(); + if (i >= PotteryBlockEntity.CORNERS) lid.scaleWidth(x, z, PotteryBlockEntity.PLATE_SCALE); } positions[i].lid = lid; } @@ -427,6 +478,9 @@ private static List fluids(Pottery[] slots, VesselContents[] contents 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); + } if (body.quads().isEmpty()) { continue; } diff --git a/src/main/java/net/modcrafters/minecraft/primalpottery/item/PotteryItem.java b/src/main/java/net/modcrafters/minecraft/primalpottery/item/PotteryItem.java index dfc34bf..b3481dc 100644 --- a/src/main/java/net/modcrafters/minecraft/primalpottery/item/PotteryItem.java +++ b/src/main/java/net/modcrafters/minecraft/primalpottery/item/PotteryItem.java @@ -37,6 +37,7 @@ import net.modcrafters.minecraft.primalpottery.client.PotteryScreen; import net.modcrafters.minecraft.primalpottery.pottery.Nbt; import net.modcrafters.minecraft.primalpottery.pottery.PartHits; +import net.modcrafters.minecraft.primalpottery.pottery.Placement; import net.modcrafters.minecraft.primalpottery.pottery.Planter; import net.modcrafters.minecraft.primalpottery.pottery.Pottery; import net.modcrafters.minecraft.primalpottery.pottery.VesselContents; @@ -293,7 +294,7 @@ public void appendHoverText(ItemStack stack, TooltipContext context, java.util.L public static void contentsTooltip(Pottery pottery, VesselContents contents, Consumer tooltip) { Pottery.Info info = pottery.classify(); - if (!info.type().isVessel()) { + if (info.volume() <= 0) { return; } tooltip.accept(Component.translatable("tooltip.primalpottery.capacity", info.volume())); @@ -375,14 +376,16 @@ public InteractionResult place(BlockPlaceContext context) { BlockPos clicked = context.replacingClickedOnBlock() ? context.getClickedPos() : context.getClickedPos().relative(context.getClickedFace().getOpposite()); - if (context.getLevel().getBlockState(clicked).is(ModBlocks.POTTERY)) { + PotteryBlockEntity existing = Placement.existingPottery(context.getLevel(), clicked, context.getClickedFace()); + if (existing != null) { + BlockPos pos = existing.getBlockPos(); Player player = context.getPlayer(); return PotteryBlock.tryPlace( context.getLevel(), - clicked, + pos, player, context.getItemInHand(), - PartHits.quadrant(clicked, context.getClickLocation(), context.getClickedFace()), + PartHits.placementSlot(read(context.getItemInHand()), pos, context.getClickLocation(), context.getClickedFace()), player != null && player.isShiftKeyDown(), context.getClickedFace() ); @@ -409,7 +412,7 @@ public InteractionResult place(BlockPlaceContext context) { Level level = context.getLevel(); BlockEntity blockEntity = level.getBlockEntity(context.getClickedPos()); if (blockEntity instanceof PotteryBlockEntity pottery) { - pottery.put(PartHits.quadrant(context.getClickedPos(), context.getClickLocation()), shaped, contents, closed, color, planting); + pottery.put(PartHits.placementSlot(shaped, context.getClickedPos(), context.getClickLocation(), context.getClickedFace()), shaped, contents, closed, color, planting); } return result; } @@ -476,7 +479,7 @@ private static VesselContents.Facts facts( Pottery.Info info = pottery.classify(); return new VesselContents.Facts( player != null, - info.type().isVessel(), + info.volume() > 0, contents.isEmpty(), info.volume(), fluidBlock, diff --git a/src/main/java/net/modcrafters/minecraft/primalpottery/item/RawPotteryItem.java b/src/main/java/net/modcrafters/minecraft/primalpottery/item/RawPotteryItem.java index 594cf3d..e9384c8 100644 --- a/src/main/java/net/modcrafters/minecraft/primalpottery/item/RawPotteryItem.java +++ b/src/main/java/net/modcrafters/minecraft/primalpottery/item/RawPotteryItem.java @@ -107,7 +107,7 @@ public static void tooltip(ItemStack stack, Consumer tooltip) { tooltip.accept(Component.translatable("tooltip.primalpottery.can_be_dyed").withStyle(ChatFormatting.GRAY)); } Pottery.Info info = PotteryItem.read(stack).classify(); - if (info.type().isVessel()) { + if (info.volume() > 0) { tooltip.accept(Component.translatable("tooltip.primalpottery.will_contain", info.volume()).withStyle(ChatFormatting.DARK_GRAY)); } } diff --git a/src/main/java/net/modcrafters/minecraft/primalpottery/item/TemplateItem.java b/src/main/java/net/modcrafters/minecraft/primalpottery/item/TemplateItem.java index 86f76b3..97affec 100644 --- a/src/main/java/net/modcrafters/minecraft/primalpottery/item/TemplateItem.java +++ b/src/main/java/net/modcrafters/minecraft/primalpottery/item/TemplateItem.java @@ -102,7 +102,7 @@ private static void appendBlueprintDetails(ItemStack stack, Consumer tooltip.accept(Component.translatable("tooltip.primalpottery.type", info.type().tooltipName())); tooltip.accept(Component.translatable(size(stack) == Pottery.Size.LARGE ? "tooltip.primalpottery.wheel_clay_block" : "tooltip.primalpottery.wheel_clay_ball")); - if (info.type().isVessel()) { + if (info.volume() > 0) { tooltip.accept(Component.translatable("tooltip.primalpottery.capacity", info.volume())); } } diff --git a/src/main/java/net/modcrafters/minecraft/primalpottery/menu/PaintingMenu.java b/src/main/java/net/modcrafters/minecraft/primalpottery/menu/PaintingMenu.java index f5ca5e2..e46ac9b 100644 --- a/src/main/java/net/modcrafters/minecraft/primalpottery/menu/PaintingMenu.java +++ b/src/main/java/net/modcrafters/minecraft/primalpottery/menu/PaintingMenu.java @@ -146,6 +146,7 @@ public boolean clickMenuButton(Player player, int action) { return true; } int cell = action % FacePaint.CELLS; + if (cell >= before.paintColumns() * FacePaint.SIDE) return false; int color = action / FacePaint.CELLS - 1; int previous = before.paint().color(cell); if (previous == color || !spend(color)) { diff --git a/src/main/java/net/modcrafters/minecraft/primalpottery/pottery/PartHits.java b/src/main/java/net/modcrafters/minecraft/primalpottery/pottery/PartHits.java index ac2ecef..0497331 100644 --- a/src/main/java/net/modcrafters/minecraft/primalpottery/pottery/PartHits.java +++ b/src/main/java/net/modcrafters/minecraft/primalpottery/pottery/PartHits.java @@ -50,6 +50,13 @@ public static int quadrant(BlockPos pos, Vec3 hit, Direction face) { return quadrant(pos, hit.add(-face.getStepX() * 1.0e-6, 0, -face.getStepZ() * 1.0e-6)); } + public static int placementSlot(Pottery profile, BlockPos pos, Vec3 hit, Direction face) { + if (!profile.isPlate()) return quadrant(pos, hit, face); + double x = hit.x - pos.getX() - 0.5, z = hit.z - pos.getZ() - 0.5; + if (Math.abs(x) > Math.abs(z)) return x > 0 ? 5 : 7; + return z > 0 ? 6 : 4; + } + public static int beside(int part, Direction direction) { return switch (part) { case 0 -> direction == Direction.EAST ? 1 : direction == Direction.SOUTH ? 3 : -1; diff --git a/src/main/java/net/modcrafters/minecraft/primalpottery/pottery/Placement.java b/src/main/java/net/modcrafters/minecraft/primalpottery/pottery/Placement.java index 0fb2701..26bcce5 100644 --- a/src/main/java/net/modcrafters/minecraft/primalpottery/pottery/Placement.java +++ b/src/main/java/net/modcrafters/minecraft/primalpottery/pottery/Placement.java @@ -25,30 +25,31 @@ private Placement() { if (state.is(ModBlocks.WHEEL)) { return PotteryWheelBlock.outline(state, pos); } - if (player == null || !player.getMainHandItem().is(ModItems.POTTERY)) { + if (player == null) return null; + ItemStack held = player.getMainHandItem().isEmpty() ? player.getOffhandItem() : player.getMainHandItem(); + if (!held.is(ModItems.POTTERY)) { return null; } - Pottery.Size size = PotteryItem.read(player.getMainHandItem()).size(); - if (state.is(ModBlocks.POTTERY)) { - if (!(level.getBlockEntity(pos) instanceof PotteryBlockEntity pottery)) { - return null; - } + Pottery profile = PotteryItem.read(held); + PotteryBlockEntity pottery = existingPottery(level, pos, hit.getDirection()); + if (pottery != null) { + pos = pottery.getBlockPos(); int part = destination( pottery, - PartHits.quadrant(pos, hit.getLocation(), hit.getDirection()), + PartHits.placementSlot(profile, pos, hit.getLocation(), hit.getDirection()), player.isShiftKeyDown(), - hit.getDirection(), size + hit.getDirection(), profile ); if (part < 0) { return null; } - return PotteryBlockEntity.box(part, size).move(pos); + return PotteryBlockEntity.box(part, profile.size()).move(pos); } if (hit.getDirection() != Direction.UP) { return null; } BlockPos above = pos.above(); - return PotteryBlockEntity.box(PartHits.quadrant(pos, hit.getLocation()), size).move(above); + return PotteryBlockEntity.box(PartHits.placementSlot(profile, pos, hit.getLocation(), hit.getDirection()), profile.size()).move(above); } public static Vec3 reachEnd(Player player) { @@ -60,32 +61,30 @@ public static boolean holding(ItemStack stack) { return stack.is(ModItems.POTTERY); } - public static int destination(PotteryBlockEntity pottery, int part, boolean sneak, Direction face) { - return destination(pottery, part, sneak, face, Pottery.Size.SMALL); + public static @Nullable PotteryBlockEntity existingPottery(Level level, BlockPos clicked, Direction face) { + if (level.getBlockEntity(clicked) instanceof PotteryBlockEntity pottery) return pottery; + // A ray through an empty slot hits the support beneath the pottery block. + if (face == Direction.UP && level.getBlockEntity(clicked.above()) instanceof PotteryBlockEntity pottery) return pottery; + return null; } - public static int destination(PotteryBlockEntity pottery, int part, boolean sneak, Direction face, Pottery.Size size) { - if (part < 0 || part >= PotteryBlockEntity.SLOTS || pottery.hasLargePot()) { - return -1; - } - if (size == Pottery.Size.LARGE) { - return pottery.isEmpty() ? 0 : -1; - } - if (!sneak) { - return pottery.get(part) == null ? part : -1; - } - if (pottery.get(part) == null) { - return part; - } - int facing = PartHits.beside(part, face); - if (facing >= 0 && pottery.get(facing) == null) { - return facing; - } - for (int neighbor : PartHits.neighbors(part)) { - if (pottery.get(neighbor) == null) { - return neighbor; + public static int destination(PotteryBlockEntity pottery, int part, boolean sneak, Direction face, Pottery profile) { + if (profile.size() == Pottery.Size.LARGE) return pottery.canPlace(0, profile) ? 0 : -1; + if (pottery.canPlace(part, profile)) return part; + if (!sneak) return -1; + if (profile.isPlate()) { + for (int step = 1; step < 4; step++) { + int next = 4 + (part - 4 + step) % 4; + if (pottery.canPlace(next, profile)) return next; + } + } else { + int facing = PartHits.beside(part, face); + if (pottery.canPlace(facing, profile)) return facing; + for (int next : PartHits.neighbors(part)) { + if (pottery.canPlace(next, profile)) return next; } } return -1; } + } 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 8900969..4892d63 100644 --- a/src/main/java/net/modcrafters/minecraft/primalpottery/pottery/Pottery.java +++ b/src/main/java/net/modcrafters/minecraft/primalpottery/pottery/Pottery.java @@ -126,6 +126,19 @@ public String cacheKey() { return key.toString(); } + /** Three of the 32 model units in a block. Pipes and malformed profiles remain clay failures. */ + public boolean isPlate() { + if (size != Size.SMALL || height() > 3 || !validProfile(discs)) return false; + for (PotteryDisc disc : discs) { + if (disc.radius() - disc.innerRadius() < 0.5) return false; + } + return discs.getLast().innerRadius() == 0; + } + + public int paintColumns() { + return isPlate() ? 4 : FacePaint.SIDE; + } + public Info classify() { int rim = -1; double maxRadius = 0; @@ -146,6 +159,7 @@ public Info classify() { } maxRadius = Math.max(maxRadius, disc.radius()); } + if (rim >= 0 && this.discs.get(rim).innerRadius() == 0 && isPlate()) return new Info(PotteryType.PLATE, 0); if (rim < 0 || this.discs.get(rim).innerRadius() == 0) { return new Info(PotteryType.LUMP, 0); } @@ -158,7 +172,7 @@ public Info classify() { if (disc.radius() == 0) { break; } - PotteryType type = vesselType(openingRadius, maxRadius); + PotteryType type = isPlate() ? PotteryType.PLATE : vesselType(openingRadius, maxRadius); double hollow = PotteryProfile.volume(PotteryProfile.cavity(this.discs)); return new Info(type, this.size.capacity(hollow)); } diff --git a/src/main/java/net/modcrafters/minecraft/primalpottery/pottery/PotteryType.java b/src/main/java/net/modcrafters/minecraft/primalpottery/pottery/PotteryType.java index 89b554b..72ef009 100644 --- a/src/main/java/net/modcrafters/minecraft/primalpottery/pottery/PotteryType.java +++ b/src/main/java/net/modcrafters/minecraft/primalpottery/pottery/PotteryType.java @@ -8,6 +8,7 @@ public enum PotteryType { LUMP("Just a lump of clay", ChatFormatting.DARK_RED), LUMP_NO_BOTTOM("A pipe?", ChatFormatting.DARK_RED), LUMP_THIN("Too thin!", ChatFormatting.DARK_RED), + PLATE("A plate!", ChatFormatting.DARK_AQUA), POT("A bowl!", ChatFormatting.DARK_AQUA), JAR("Pottery", ChatFormatting.DARK_AQUA), JUG("A jug!", ChatFormatting.DARK_AQUA); @@ -29,7 +30,7 @@ public ChatFormatting color() { } public boolean isVessel() { - return this == POT || this == JAR || this == JUG; + return this == PLATE || this == POT || this == JAR || this == JUG; } public Component tooltipName() { @@ -40,6 +41,7 @@ public Component tooltipName() { /** Wide mouth is a bowl, narrow mouth is a jug, and every other shape is pottery. */ public Component shapeName() { String shape = switch (this) { + case PLATE -> "plate"; case JUG -> "jug"; case POT -> "bowl"; default -> "pottery"; diff --git a/src/main/resources/assets/primalpottery/lang/en_us.json b/src/main/resources/assets/primalpottery/lang/en_us.json index 773ecbb..ade505c 100644 --- a/src/main/resources/assets/primalpottery/lang/en_us.json +++ b/src/main/resources/assets/primalpottery/lang/en_us.json @@ -4,6 +4,8 @@ "block.primalpottery.pottery": "Pottery", "block.primalpottery.painting_table": "Pottery Painting Table", "item.primalpottery.painting_table": "Pottery Painting Table", + "gui.primalpottery.paint.center": "Center", + "gui.primalpottery.paint.rim": "Rim", "gui.primalpottery.paint.erase": "Eraser", "gui.primalpottery.paint.undo_cost": "Undo the last square. Restoring a color uses 1 mL of that paint.", "gui.primalpottery.paint.volume": "%s / 100 mL", @@ -48,6 +50,8 @@ "gui.primalpottery.template.shape_hint": "Drag the side of the clay to shape it.", "gui.primalpottery.template.hollow_hint": "Drag inside the pot to hollow it out.", "gui.primalpottery.template.turn_hint": "Drag to turn the display block.", + "pottery.primalpottery.shape.plate": "Plate", + "pottery.primalpottery.type.plate": "Plate", "gui.primalpottery.template.small_place": "Four per block", "gui.primalpottery.template.large_place": "One per block", "tooltip.primalpottery.contents": "%s: %s mL", 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 0eb5a6c..6fd1dcb 100644 --- a/src/test/java/net/modcrafters/minecraft/primalpottery/client/MeshTest.java +++ b/src/test/java/net/modcrafters/minecraft/primalpottery/client/MeshTest.java @@ -13,6 +13,28 @@ import org.junit.jupiter.api.Test; class MeshTest { + @Test + void platePaintSpansFloorInnerWallAndRimOnAllEightSectors() { + var plate = new Pottery(List.of(new PotteryDisc(2, 8, 6), new PotteryDisc(1, 7, 0))); + assertEquals(4, plate.paintColumns()); + assertEquals(16, new Pottery(List.of(new PotteryDisc(4, 8, 0))).paintColumns()); + var faces = FlowerPaint.overlay(new Mesh(), 0, 0, 0, plate).quads(); + for (int col = 0; col < 4; col++) { + float v = col + 0.5F; + var sector = faces.stream().filter(q -> q.v[0] == v).toList(); + assertEquals(8, sector.stream().filter(q -> q.u[0] == 0 && q.x[0] == 0 && q.z[0] == 0 + && Math.abs(q.y[0] - 1) < 0.02).count()); + assertEquals(8, sector.stream().filter(q -> q.u[3] == 16 && Math.abs(q.y[3] - 3) < 0.02).count()); + assertTrue(sector.stream().anyMatch(q -> q.ny == 0 && q.y[3] > q.y[0])); + } + var ink = plate.paint().with(0, 4).with(63, 9); + var painted = new Pottery(plate.size(), plate.discs(), ink); + var pixels = new Mesh(); + FlowerPaint.apply(pixels, 0, 0, 0, painted); + assertEquals(8, pixels.quads().stream().filter(q -> q.x[0] == 0 && q.z[0] == 0).count()); + assertEquals(16, pixels.quads().size()); + } + @Test void flowerWrapsEachExteriorFaceOnceAcrossTheMiddleOfTheVessel() { var plain = Pottery.jug();