mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Move the jigsaw commands and the structure importers onto the tooling api
Add PlatformStructures, the capability the structure importers read the platform through: templates, registered structures and structure sets, jigsaw structures, template pools with their connectors, and a closable capture area. The Bukkit host implements it in the plugin and takes over all reflection, the structure manager and the NMS calls; the importers keep only their model-building logic and report through the api sender. CommandContext.platformStructures() reaches it, ToolPlayer.targetBlock() lets a command read what the player looks at. CommandJigsaw, JigsawStudioBridge, IrisStructureHandler, the Director import and capture of CommandStructure and the modded stubs that explained the Bukkit workflow are replaced by the neutral jigsaw command tree in core/structure/tooling, mounted by StructureModelModule. Import and capture are now jigsaw sub-commands. The graph editor, the vanilla exporter and StructureIndexService speak api types: IrisObject hands out its contents as BlockState and BlockEntityData, exports go below ToolPack.outputFolder(), and the index writes through ToolPack.edit. The move lint is at 0 for the B2 set.
This commit is contained in:
1 parent
23c93e6e74
commit
ae11b38093
82 files changed
+6529
-4789
No files matched your search
+2
-2
@@ -47,8 +47,8 @@ types that carry them and lists what the Iris adapter still owes.
|
||||
| Positions, boxes and faces | `com.volmit.geometry`: `BlockPosition`, `BlockBox`, `BlockFace` |
|
||||
| Sparse geometry | `GeneratedObject` |
|
||||
| Studio views of what a module builds | `com.volmit.tooling`: `ModuleSetup.tooling()` (`ToolingRegistry.registerView`), sealed `StudioView` (`SceneView` with `SceneEntry`, `PatternView` with `PatternEntry`, `PatternArea`, `BlockPattern`), `EditableSceneView` (`SceneFile`, `NodeGraph`, `GraphNode` with `Link`, `NodeSettings`, `Edits`, `Addition`), `JsonText`, `JsonPath` (`Key`, `Index`), host `StudioViewRegistration` |
|
||||
| Commands of a module | `com.volmit.tooling`: `ToolingRegistry.registerCommand`, immutable `Command` (`named`, `alias`, `describe`, `child`, `argument`, `runs`, `openToEveryone`), typed `Argument` (`word`, `text`, `integer`, `decimal`, `flag`, `choice`, `resource`, `registered`, `orElse`, `suggesting`), `CommandAction`, `CommandContext` (`get`, `sender`, `pack`, `world`, `platform`), plain-text `Sender` (with `player()`), `ToolPack` (`edit` with `PackEdit`, `outputFolder`, `objects` with `ObjectCodec`, `worlds`, `services`), host `CommandRegistration` in `FeatureCatalog.commands()` |
|
||||
| Worlds a tool opens | `com.volmit.tooling.world`, exposed to pack modules by host `ExposedPackages`: `ToolWorlds` (`open`, `find`) with `ToolWorldSpec`, `ChunkPainter` and `ChunkCanvas`, `ToolWorld` (`players`, `owns`, `run`, `call`, `block`, `blockEntity`, `setBlock`, `loaded`, `repaint`, `close`), `ToolPlayer` (`teleport`, `creative`, `message`, `actionBar`, `sound`, `sidebar`, `particles`, `give` answering whether the item fitted, `held`, `openMenu`), `ToolText` with `TextColor` (styled text: item names and lore, menu titles, sidebar, chat and action bar; the host shows each span in its colour and style, an empty sidebar title keeps the platform's, and an item read back has plain text), `ToolItem`, `ToolMenu` with `MenuButton` and `MenuClick`, `Particle`, `ToolWorldListener` (`entered`, `left`, `teleported` for every arrival other than walking, at the time of the teleport, `moved`, `sneakToggled`, `used` with `ToolUse`, `blockChanging` with `BlockChange.Cause` and `BlockChange.changed`, `containerChanged` for a closed container inventory or a furnace or brewing stand that started, `command`, `chunkLoaded`, `closeRefusal`, `closing`, `closed`), `com.volmit.geometry.ChunkPos`; a tool world takes the pack's studio slot, so the host asks `closeRefusal` before it closes the world for another studio, the studio close command or a server stop, and waits for `closing` when another studio replaces it; every Y is the world's own; implemented by each platform adapter (Bukkit; modded adapters answer with a failed `open`) |
|
||||
| Commands of a module | `com.volmit.tooling`: `ToolingRegistry.registerCommand`, immutable `Command` (`named`, `alias`, `describe`, `child`, `argument`, `runs`, `openToEveryone`), typed `Argument` (`word`, `text`, `integer`, `decimal`, `flag`, `choice`, `resource`, `registered`, `orElse`, `suggesting`), `CommandAction`, `CommandContext` (`get`, `sender`, `pack`, `world`, `platform`, `platformStructures`), plain-text `Sender` (with `player()`), `PlatformStructures` (`templates`, `template` answering `StructureTemplate`, `structures`, `structureSets`, `jigsaw` answering `JigsawStructureInfo`, `pool` answering `TemplatePool` with `Member`, `Element`, `ConnectorSource`, `Connectors` and `JigsawConnector`, `supportsCapture`, `openCaptureArea` answering a closable `CaptureArea` whose `capture` answers `CapturedStructure`; `TemplateBlock`; readers throw `StructureAccessException`), `ToolPack` (`edit` with `PackEdit`, `outputFolder`, `objects` with `ObjectCodec`, `worlds`, `services`), host `CommandRegistration` in `FeatureCatalog.commands()` |
|
||||
| Worlds a tool opens | `com.volmit.tooling.world`, exposed to pack modules by host `ExposedPackages`: `ToolWorlds` (`open`, `find`) with `ToolWorldSpec`, `ChunkPainter` and `ChunkCanvas`, `ToolWorld` (`players`, `owns`, `run`, `call`, `block`, `blockEntity`, `setBlock`, `loaded`, `repaint`, `close`), `ToolPlayer` (`targetBlock`, `teleport`, `creative`, `message`, `actionBar`, `sound`, `sidebar`, `particles`, `give` answering whether the item fitted, `held`, `openMenu`), `ToolText` with `TextColor` (styled text: item names and lore, menu titles, sidebar, chat and action bar; the host shows each span in its colour and style, an empty sidebar title keeps the platform's, and an item read back has plain text), `ToolItem`, `ToolMenu` with `MenuButton` and `MenuClick`, `Particle`, `ToolWorldListener` (`entered`, `left`, `teleported` for every arrival other than walking, at the time of the teleport, `moved`, `sneakToggled`, `used` with `ToolUse`, `blockChanging` with `BlockChange.Cause` and `BlockChange.changed`, `containerChanged` for a closed container inventory or a furnace or brewing stand that started, `command`, `chunkLoaded`, `closeRefusal`, `closing`, `closed`), `com.volmit.geometry.ChunkPos`; a tool world takes the pack's studio slot, so the host asks `closeRefusal` before it closes the world for another studio, the studio close command or a server stop, and waits for `closing` when another studio replaces it; every Y is the world's own; implemented by each platform adapter (Bukkit; modded adapters answer with a failed `open`) |
|
||||
| Buffered placement writes | `PlacementRequest`, `PlacementAccess`, host-owned `PlacementEdit` |
|
||||
| Typed generation and persistent storage | `mantle` package |
|
||||
|
||||
|
||||
@@ -1434,6 +1434,12 @@ It exists so the tool lives in a module and runs on every platform: a tool that
|
||||
its own widgets (VolmLib windows and scoreboards on Bukkit). Their text is `ToolText`: spans of a named colour
|
||||
(`TextColor`) and a few styles, so no colour codes or components cross the api, and the host maps the spans onto
|
||||
whatever its platform draws text with.
|
||||
- **The platform's structures are one capability.** Registries, resource managers and structure managers differ by
|
||||
platform and version, and some are reached only by reflection. `PlatformStructures` is the one door for the tools that
|
||||
import them, and answers in api types (`BlockState`, `BlockEntityData`, `ResourceId`), so an importer holds only
|
||||
model-building logic. Capturing a structure needs a scratch area that has to be removed, so it is a `CaptureArea` the
|
||||
tool closes, and not a call that leaves the area to the platform. A platform without the capability gives
|
||||
`CommandContext.platformStructures()` empty and the tool says so.
|
||||
- **A platform may not have it.** `ToolWorlds.open` then returns a failed future and `Sender.player()` is empty, so a tool
|
||||
tells its user instead of failing at class loading. The package is exposed to pack modules, unlike the platform
|
||||
packages below `com.volmit.tooling`.
|
||||
|
||||
@@ -579,6 +579,14 @@ private void info(CommandContext context) {
|
||||
naming both modules. A host without commands, such as a build check, accepts the registration and ignores it.
|
||||
- `Sender.player()` is the sender as a `ToolPlayer` (see Tool worlds), empty for the console and on a platform without
|
||||
tool worlds.
|
||||
- `CommandContext.platformStructures()` is the platform's structures for the tools that turn them into pack resources,
|
||||
empty on a platform that has none. `PlatformStructures` lists the registered structures and structure sets and the
|
||||
loadable templates (`templates`, `template`, `structures`, `structureSets`), reads a registered jigsaw structure and a
|
||||
template pool (`jigsaw` answering `JigsawStructureInfo`, `pool` answering `TemplatePool` with its members, fallback and
|
||||
the connectors of each element), and generates structures that have no template in a throwaway area
|
||||
(`supportsCapture`, `openCaptureArea`). A template or a captured structure is a list of `TemplateBlock` with
|
||||
`BlockState` and `BlockEntityData`. A reader throws `StructureAccessException` when the platform's registries cannot be
|
||||
read, and says whether asking again may help.
|
||||
|
||||
## Tool worlds
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.volmit.tooling;
|
||||
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* A structure the platform generated in a scratch area and read back.
|
||||
*
|
||||
* @param size the width, height and depth of the box the structure filled
|
||||
* @param blocks every block in that box that is not plain air, with positions from the box's corner
|
||||
*/
|
||||
public record CapturedStructure(BlockPosition size, List<TemplateBlock> blocks) {
|
||||
public CapturedStructure {
|
||||
Objects.requireNonNull(size, "size");
|
||||
blocks = List.copyOf(blocks);
|
||||
}
|
||||
}
|
||||
@@ -30,4 +30,7 @@ public interface CommandContext {
|
||||
|
||||
/** The platform's registries; empty when the host runs without a platform. */
|
||||
Optional<PlatformRegistries> platform();
|
||||
|
||||
/** The structures the platform registers and the templates it loads; empty on a platform that does not offer them. */
|
||||
Optional<PlatformStructures> platformStructures();
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.volmit.tooling;
|
||||
|
||||
import com.volmit.resource.ResourceId;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* What a registered jigsaw structure says about itself.
|
||||
*
|
||||
* @param startPool the template pool the structure starts from
|
||||
* @param maxDepth how many pieces deep the structure grows
|
||||
* @param maxDistance how far from its centre the structure may reach, in blocks; the horizontal reach when the platform
|
||||
* keeps a horizontal and a vertical one
|
||||
* @param gameVersion the platform's own version string, which tools record as where the structure came from
|
||||
* @param shuffleSeed what the platform seeds its shuffle of the connectors of this structure's pool elements with, so
|
||||
* that reading the same structure twice lists them in the same order
|
||||
*/
|
||||
public record JigsawStructureInfo(ResourceId startPool, int maxDepth, int maxDistance, String gameVersion,
|
||||
long shuffleSeed) {
|
||||
public JigsawStructureInfo {
|
||||
Objects.requireNonNull(startPool, "startPool");
|
||||
Objects.requireNonNull(gameVersion, "gameVersion");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.volmit.tooling;
|
||||
|
||||
import com.volmit.resource.ResourceId;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* The structures a platform registers and the templates it loads, for the tools that turn them into pack resources.
|
||||
* A command reaches it as {@link CommandContext#platformStructures()}, which is empty on a platform without it. Every
|
||||
* method may take a while and reads the running server, so a tool calls them from its worker thread and never
|
||||
* from the platform's main or region thread.
|
||||
*
|
||||
* <p>Each reader that cannot answer because the platform's registries cannot be read throws a
|
||||
* {@link StructureAccessException}; a reader that answers empty means the platform has no such thing.
|
||||
*/
|
||||
public interface PlatformStructures {
|
||||
/** The ids of the structure templates the platform can load, such as {@code minecraft:village/plains/houses/plains_small_house_1}, in id order. */
|
||||
List<ResourceId> templates();
|
||||
|
||||
/** The template {@code id}; empty when the platform has none or it holds no palette. */
|
||||
Optional<StructureTemplate> template(ResourceId id);
|
||||
|
||||
/** The ids of the structures the platform registers, in id order. */
|
||||
List<ResourceId> structures();
|
||||
|
||||
/** The ids of the structure sets the platform registers, in id order. */
|
||||
List<ResourceId> structureSets();
|
||||
|
||||
/** What {@code structure} says about itself; empty when it is no jigsaw structure or is not registered. */
|
||||
Optional<JigsawStructureInfo> jigsaw(ResourceId structure);
|
||||
|
||||
/** The template pool {@code pool}; empty when it is not registered. */
|
||||
Optional<TemplatePool> pool(ResourceId pool);
|
||||
|
||||
/** Whether the platform can generate a structure in a scratch area and read it back, which {@link #openCaptureArea} needs. */
|
||||
boolean supportsCapture();
|
||||
|
||||
/**
|
||||
* Opens a throwaway area to generate structures in, for the structures that have no template. Close it when the
|
||||
* captures are done; it is removed then.
|
||||
*
|
||||
* @param sender where the platform reports what it does while it opens and removes the area
|
||||
* @return the area; empty when it could not be opened, which the platform has told the sender
|
||||
*/
|
||||
Optional<CaptureArea> openCaptureArea(Sender sender);
|
||||
|
||||
/** A throwaway area structures are generated in, one after another. */
|
||||
interface CaptureArea extends AutoCloseable {
|
||||
/**
|
||||
* Generates {@code structure} in the next free spot of the area and reads it back.
|
||||
*
|
||||
* @param seed what the platform generates the structure with
|
||||
* @param maxSpan the widest and tallest box, in blocks, the platform reads back
|
||||
* @return the structure; empty when it placed nothing capturable here, such as one wider than {@code maxSpan}
|
||||
* @throws IllegalStateException when the platform could not place it, with the reason
|
||||
*/
|
||||
Optional<CapturedStructure> capture(ResourceId structure, long seed, int maxSpan);
|
||||
|
||||
/** Removes the area. */
|
||||
@Override
|
||||
void close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.volmit.tooling;
|
||||
|
||||
/**
|
||||
* What a {@link PlatformStructures} reader throws when the platform cannot answer, such as a server version whose
|
||||
* registries it cannot read. The message is written for the sender who ran the tool, so a tool shows it as it is.
|
||||
*/
|
||||
public final class StructureAccessException extends RuntimeException {
|
||||
private final boolean retryable;
|
||||
|
||||
/**
|
||||
* @param message what went wrong, as the sender should read it
|
||||
* @param retryable whether asking again later may succeed, as for a registry that was not ready yet
|
||||
*/
|
||||
public StructureAccessException(String message, boolean retryable) {
|
||||
super(message);
|
||||
this.retryable = retryable;
|
||||
}
|
||||
|
||||
public StructureAccessException(String message, boolean retryable, Throwable cause) {
|
||||
super(message, cause);
|
||||
this.retryable = retryable;
|
||||
}
|
||||
|
||||
/** Whether asking again later may succeed. */
|
||||
public boolean retryable() {
|
||||
return retryable;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.volmit.tooling;
|
||||
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* A structure template the platform loads, such as a vanilla {@code .nbt}: its size and the blocks of its first palette.
|
||||
*
|
||||
* @param size the template's width, height and depth in blocks
|
||||
* @param paletteCount how many palettes the template has; only the first is in {@code blocks}
|
||||
* @param entityCount how many entities the template holds, which tools do not read
|
||||
* @param blocks the blocks of the first palette, with positions from the template's corner
|
||||
*/
|
||||
public record StructureTemplate(BlockPosition size, int paletteCount, int entityCount, List<TemplateBlock> blocks) {
|
||||
public StructureTemplate {
|
||||
Objects.requireNonNull(size, "size");
|
||||
blocks = List.copyOf(blocks);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.volmit.tooling;
|
||||
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import com.volmit.object.BlockEntityData;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* One block of a {@link StructureTemplate} or {@link CapturedStructure}.
|
||||
*
|
||||
* @param position where the block is, from the template's corner
|
||||
* @param state the block as the platform stores it; a jigsaw block is the jigsaw block itself
|
||||
* @param blockEntity the block entity data of a block that has some; empty for a jigsaw block, which tools resolve
|
||||
* through {@code jigsawFinalState}
|
||||
* @param jigsawFinalState what a jigsaw block turns into when its piece is placed: the {@code final_state} the block
|
||||
* names, as the platform writes it; empty for any other block and for a jigsaw block that names
|
||||
* none
|
||||
*/
|
||||
public record TemplateBlock(BlockPosition position, BlockState state, Optional<BlockEntityData> blockEntity,
|
||||
Optional<String> jigsawFinalState) {
|
||||
public TemplateBlock {
|
||||
Objects.requireNonNull(position, "position");
|
||||
Objects.requireNonNull(state, "state");
|
||||
Objects.requireNonNull(blockEntity, "blockEntity");
|
||||
Objects.requireNonNull(jigsawFinalState, "jigsawFinalState");
|
||||
}
|
||||
|
||||
/** A block with no jigsaw final state. */
|
||||
public static TemplateBlock of(BlockPosition position, BlockState state, Optional<BlockEntityData> blockEntity) {
|
||||
return new TemplateBlock(position, state, blockEntity, Optional.empty());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
package com.volmit.tooling;
|
||||
|
||||
import com.volmit.geometry.BlockFace;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.LongSupplier;
|
||||
|
||||
/**
|
||||
* A jigsaw template pool the platform registers: what its entries are and where it falls back to.
|
||||
*
|
||||
* @param members the entries in the order the platform lists them, every one of them, so the count is the
|
||||
* pool's own size
|
||||
* @param fallback the pool used when none of the entries fits; empty when it has none
|
||||
* @param fallbackFailure why the fallback could not be read, when it could not; the fallback is then empty
|
||||
*/
|
||||
public record TemplatePool(List<Member> members, Optional<ResourceId> fallback, Optional<String> fallbackFailure) {
|
||||
public TemplatePool {
|
||||
members = List.copyOf(members);
|
||||
Objects.requireNonNull(fallback, "fallback");
|
||||
Objects.requireNonNull(fallbackFailure, "fallbackFailure");
|
||||
}
|
||||
|
||||
/** One entry of a pool. */
|
||||
public sealed interface Member permits Absent, Unreadable, Element {
|
||||
}
|
||||
|
||||
/** An entry that holds no element. */
|
||||
public record Absent() implements Member {
|
||||
}
|
||||
|
||||
/** Which part of an entry could not be read. */
|
||||
public enum Part {
|
||||
/** The element and its weight. */
|
||||
ENTRY,
|
||||
/** Where the element's template is. */
|
||||
TEMPLATE_LOCATION
|
||||
}
|
||||
|
||||
/**
|
||||
* An entry the platform could not read.
|
||||
*
|
||||
* @param part what could not be read
|
||||
* @param detail why, as the platform reports it
|
||||
*/
|
||||
public record Unreadable(Part part, String detail) implements Member {
|
||||
public Unreadable {
|
||||
Objects.requireNonNull(part, "part");
|
||||
Objects.requireNonNull(detail, "detail");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* One element of a pool with its weight.
|
||||
*
|
||||
* @param weight how likely the element is among the entries; at least 1
|
||||
* @param type the platform's name for the kind of element, such as {@code SinglePoolElement}, which tells an
|
||||
* empty element from one a tool cannot convert when {@code template} is empty
|
||||
* @param template the template the element places; when the platform wraps several elements in a list, the
|
||||
* first one that places a template; empty for an element that places none
|
||||
* @param listLevels how many list elements wrap the one {@code template} came from
|
||||
* @param omittedElements how many elements those lists held besides the one {@code template} came from
|
||||
* @param connectors reads the jigsaw connectors of the element
|
||||
*/
|
||||
public record Element(int weight, String type, Optional<ResourceId> template, int listLevels, int omittedElements,
|
||||
ConnectorSource connectors) implements Member {
|
||||
public Element {
|
||||
Objects.requireNonNull(type, "type");
|
||||
Objects.requireNonNull(template, "template");
|
||||
Objects.requireNonNull(connectors, "connectors");
|
||||
}
|
||||
}
|
||||
|
||||
/** Reads the jigsaw connectors of one pool element. */
|
||||
@FunctionalInterface
|
||||
public interface ConnectorSource {
|
||||
/**
|
||||
* The connectors of the element, in the order the platform shuffles them with a seed.
|
||||
*
|
||||
* @param shuffleSeeds gives the seed to shuffle with; the platform asks only when it shuffles, so the caller's
|
||||
* random sequence advances once for each element that has connectors to shuffle
|
||||
* @throws StructureAccessException when the platform cannot read the connectors at all
|
||||
*/
|
||||
Connectors read(LongSupplier shuffleSeeds);
|
||||
}
|
||||
|
||||
/** Whether the platform could list an element's connectors. */
|
||||
public enum Availability {
|
||||
READ,
|
||||
/** The platform's version has no way to list them. */
|
||||
UNAVAILABLE,
|
||||
/** The platform answered with no list. */
|
||||
NO_COLLECTION
|
||||
}
|
||||
|
||||
/**
|
||||
* The connectors of an element.
|
||||
*
|
||||
* @param availability whether {@code connectors} were listed
|
||||
* @param connectors one entry for each jigsaw block, in the platform's shuffled order
|
||||
*/
|
||||
public record Connectors(Availability availability, List<Connector> connectors) {
|
||||
public Connectors {
|
||||
Objects.requireNonNull(availability, "availability");
|
||||
connectors = List.copyOf(connectors);
|
||||
}
|
||||
}
|
||||
|
||||
/** One jigsaw block of an element. */
|
||||
public sealed interface Connector permits JigsawConnector, UnreadableConnector {
|
||||
}
|
||||
|
||||
/**
|
||||
* A jigsaw block the platform could not convert.
|
||||
*
|
||||
* @param detail why, as the platform reports it
|
||||
*/
|
||||
public record UnreadableConnector(String detail) implements Connector {
|
||||
public UnreadableConnector {
|
||||
Objects.requireNonNull(detail, "detail");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A jigsaw block.
|
||||
*
|
||||
* @param position where it is, from the element's corner
|
||||
* @param front the side it connects through
|
||||
* @param top the side its top faces, which fixes the roll of a rollable joint
|
||||
* @param pool the pool it pulls its next piece from; empty when it names none
|
||||
* @param name the name other blocks target
|
||||
* @param target the name of the blocks it connects to
|
||||
* @param aligned whether the joint keeps the pieces aligned rather than letting them roll
|
||||
* @param finalState the block it turns into once it connects, as the platform writes block states; empty when
|
||||
* the block names none
|
||||
* @param selectionPriority which block is tried first
|
||||
* @param placementPriority which connected piece is expanded first
|
||||
*/
|
||||
public record JigsawConnector(BlockPosition position, BlockFace front, BlockFace top, Optional<ResourceId> pool,
|
||||
String name, String target, boolean aligned, Optional<String> finalState,
|
||||
int selectionPriority, int placementPriority) implements Connector {
|
||||
public JigsawConnector {
|
||||
Objects.requireNonNull(position, "position");
|
||||
Objects.requireNonNull(front, "front");
|
||||
Objects.requireNonNull(top, "top");
|
||||
Objects.requireNonNull(pool, "pool");
|
||||
Objects.requireNonNull(name, "name");
|
||||
Objects.requireNonNull(target, "target");
|
||||
Objects.requireNonNull(finalState, "finalState");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,12 @@ public interface ToolPlayer {
|
||||
|
||||
boolean sneaking();
|
||||
|
||||
/**
|
||||
* The block the player looks at within {@code maxDistance} blocks, fluids not counting; empty when they look at none.
|
||||
* Like the other readers, valid only on the thread that owns the player.
|
||||
*/
|
||||
Optional<BlockPosition> targetBlock(int maxDistance);
|
||||
|
||||
/** Runs {@code task} on the thread that owns the player: at once when the caller is that thread, else later. */
|
||||
void run(Runnable task);
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.volmit.tooling;
|
||||
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.geometry.BlockFace;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class PlatformStructuresTest {
|
||||
@Test
|
||||
void aTemplateKeepsItsOwnCopyOfItsBlocks() {
|
||||
var blocks = new ArrayList<>(List.of(TemplateBlock.of(
|
||||
new BlockPosition(0, 0, 0), BlockState.parse("minecraft:stone"), Optional.empty())));
|
||||
var template = new StructureTemplate(new BlockPosition(1, 1, 1), 1, 0, blocks);
|
||||
|
||||
blocks.clear();
|
||||
|
||||
assertEquals(1, template.blocks().size());
|
||||
assertThrows(UnsupportedOperationException.class, () -> template.blocks().clear());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aPoolListsEveryMemberWhetherTheToolCanReadItOrNot() {
|
||||
var unreadable = new TemplatePool.Unreadable(TemplatePool.Part.ENTRY, "no weight");
|
||||
var element = new TemplatePool.Element(3, "SinglePoolElement",
|
||||
Optional.of(ResourceId.parse("minecraft:village/house")), 0, 0,
|
||||
seeds -> new TemplatePool.Connectors(TemplatePool.Availability.READ, List.of(
|
||||
new TemplatePool.JigsawConnector(new BlockPosition(1, 2, 3), BlockFace.NORTH, BlockFace.UP,
|
||||
Optional.empty(), "minecraft:door", "minecraft:door", false, Optional.empty(), 0, 0))));
|
||||
var pool = new TemplatePool(List.of(new TemplatePool.Absent(), unreadable, element), Optional.empty(), Optional.empty());
|
||||
|
||||
assertEquals(3, pool.members().size());
|
||||
assertEquals(1, element.connectors().read(() -> 7L).connectors().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void anAccessFailureSaysWhetherAskingAgainMayHelp() {
|
||||
assertTrue(new StructureAccessException("registry not ready", true).retryable());
|
||||
assertEquals("no such member", new StructureAccessException("no such member", false).getMessage());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user