From c577b68c004a1a9d026b455e8be4daa343ef8058 Mon Sep 17 00:00:00 2001 From: piexel Date: Fri, 6 Nov 2026 06:37:32 +0100 Subject: [PATCH] PlacedMarker is a sealed type of the markers the host keeps The open (type, attributes) shape promised markers the host refused at runtime. PackMarker, TreeMaterial and BuriedTreasure make an unkept marker a compile error and remove the shared id strings. --- README.md | 2 + .../com/volmit/placement/PlacedMarker.java | 37 ++++++++++++++----- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 4d1ed2d05..91ecf8dc5 100644 --- a/README.md +++ b/README.md @@ -300,6 +300,8 @@ if (!outcome.isPlaced()) { - `input` is what the module hands its own placement stages (`PlacementContext.input(type)`); other modules' stages do not know its type. The area bounds what the placement may write, widened by the reach of the pack's placement stages. - A placement commits whole or not at all: blocks, then markers, and only when no stage rejected and none threw. +- A marker is one of the kinds the host keeps, a `PlacedMarker`: `PackMarker` (a marker the pack declares, by key), + `TreeMaterial` (a tree block, for felling and growth) or `BuriedTreasure` (a chest treasure maps lead to). - A rotated object turns its blocks with `BlockRegistry.rotate(state, turn)`: the `BlockTurn` says where the rotation moves a direction, and the platform turns the state's facing, axis or rotation to the nearest it has. `merge`, `withPropertyIfAccepted` and `matches` change and compare states the way the platform does (`BlockState.withProperty` diff --git a/api/src/main/java/com/volmit/placement/PlacedMarker.java b/api/src/main/java/com/volmit/placement/PlacedMarker.java index 9e4cae445..4858b782b 100644 --- a/api/src/main/java/com/volmit/placement/PlacedMarker.java +++ b/api/src/main/java/com/volmit/placement/PlacedMarker.java @@ -1,17 +1,36 @@ package com.volmit.placement; -import com.volmit.resource.ResourceId; import com.volmit.geometry.BlockPosition; -import java.util.Map; import java.util.Objects; -/** Marker metadata. The position has world X and Z and a Y that is the height above the dimension's bottom - * (0 = bottom). +/** A mark a placement leaves at a block, of one of the kinds the host keeps. The position has world X and Z and a Y + * that is the height above the dimension's bottom (0 = bottom). */ -public record PlacedMarker(BlockPosition position, ResourceId type, Map attributes) { - public PlacedMarker { - Objects.requireNonNull(position, "position"); - Objects.requireNonNull(type, "type"); - attributes = Map.copyOf(attributes); +public sealed interface PlacedMarker permits PlacedMarker.PackMarker, PlacedMarker.TreeMaterial, PlacedMarker.BuriedTreasure { + BlockPosition position(); + + /** A marker the pack declares, by its key such as {@code spawn/zombie}. */ + record PackMarker(BlockPosition position, String key) implements PlacedMarker { + public PackMarker { + Objects.requireNonNull(position, "position"); + Objects.requireNonNull(key, "key"); + if (key.isBlank()) { + throw new IllegalArgumentException("A pack marker needs a key"); + } + } + } + + /** A block of a tree: the host keeps the block's material so the tree can be felled and grown. */ + record TreeMaterial(BlockPosition position) implements PlacedMarker { + public TreeMaterial { + Objects.requireNonNull(position, "position"); + } + } + + /** A buried treasure chest: the host keeps it as a point of interest that treasure maps lead to. */ + record BuriedTreasure(BlockPosition position) implements PlacedMarker { + public BuriedTreasure { + Objects.requireNonNull(position, "position"); + } } }