mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 16:54:04 +00:00
Give tools a platform-neutral world api and let modules ask each other's services
PackWorld, ValidationContext and ToolPack answer services(type) with the pack's providers. com.volmit.tooling.world lets a tool open a painter-backed world and drive its players, menus, items and block changes; ToolPack.worlds() and Sender.player() reach it. The Bukkit adapter implements it over the studio world creation with a painter slot keyed by world, one protection listener, VolmLib menus, persistent-data items and BoardSVC sidebars. Other platforms answer that tool worlds are not supported yet.
This commit is contained in:
1 parent
a81a3abb9f
commit
3691611c6c
76 files changed
+4533
-23
No files matched your search
@@ -26,6 +26,7 @@ import com.volmit.host.WorldStates;
|
||||
import com.volmit.placement.Placements;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.RunningWorld;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -100,6 +101,11 @@ public final class IrisPackWorld implements PackWorld {
|
||||
return states.state(type, () -> create.apply(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S> List<S> services(Class<S> service) {
|
||||
return PackServices.of(engine.getData()).providers(service);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleLog log() {
|
||||
return log;
|
||||
|
||||
@@ -90,6 +90,11 @@ public final class IrisValidationContext implements ValidationContext {
|
||||
return platform;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S> List<S> services(Class<S> service) {
|
||||
return PackServices.of(data).providers(service);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void report(Problem problem) {
|
||||
problems.add(Objects.requireNonNull(problem, "problem"));
|
||||
|
||||
@@ -77,7 +77,7 @@ public final class ModuleObjectPlacement {
|
||||
}
|
||||
long worldSeed = rng.nextLong();
|
||||
try (ToolWorld toolWorld = new ToolWorld(worldSeed, data.getPackResources(), new PackDeclaredSettings(data),
|
||||
world -> new IrisPlacements(data, null, () -> world))) {
|
||||
PackServices.of(data), world -> new IrisPlacements(data, null, () -> world))) {
|
||||
return run.placeIn(toolWorld, terrain);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* The service providers of one pack's modules, as {@code PackWorld.services}, {@code ValidationContext.services} and
|
||||
* {@code ToolPack.services} answer them. Asking a pack whose modules fail to load throws its {@link PackModulesException}.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface PackServices {
|
||||
/**
|
||||
* Every provider of {@code service}, in module id order; empty when no module provides it.
|
||||
*
|
||||
* @throws IllegalArgumentException when {@code service} is not an interface marked as a service
|
||||
*/
|
||||
<S> List<S> providers(Class<S> service);
|
||||
|
||||
/** The providers of the modules of the pack {@code data} holds, looked up whenever they are asked for. */
|
||||
static PackServices of(IrisData data) {
|
||||
Objects.requireNonNull(data, "data");
|
||||
return new PackServices() {
|
||||
@Override
|
||||
public <S> List<S> providers(Class<S> service) {
|
||||
return data.getModules().pack().catalog().services(service);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import com.volmit.resource.PackResources;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.RunningWorld;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -42,12 +43,15 @@ final class ToolWorld implements PackWorld, AutoCloseable {
|
||||
private final WorldStates states;
|
||||
private final ModuleLog log;
|
||||
private final Placements placements;
|
||||
private final PackServices services;
|
||||
|
||||
/** {@code placements} makes the placements of the new world. */
|
||||
ToolWorld(long seed, PackResources resources, PackSettings settings, Function<PackWorld, Placements> placements) {
|
||||
/** {@code placements} makes the placements of the new world; {@code services} are those of the pack's modules. */
|
||||
ToolWorld(long seed, PackResources resources, PackSettings settings, PackServices services,
|
||||
Function<PackWorld, Placements> placements) {
|
||||
this.seeds = new SeedManager(seed);
|
||||
this.resources = resources;
|
||||
this.settings = settings;
|
||||
this.services = services;
|
||||
this.states = new WorldStates();
|
||||
this.log = IrisApiLogger.hostLog();
|
||||
this.placements = placements.apply(this);
|
||||
@@ -91,6 +95,11 @@ final class ToolWorld implements PackWorld, AutoCloseable {
|
||||
return states.state(type, () -> create.apply(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S> List<S> services(Class<S> service) {
|
||||
return services.providers(service);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleLog log() {
|
||||
return log;
|
||||
|
||||
@@ -97,6 +97,16 @@ public final class StudioOpenCoordinator {
|
||||
return closeWorldCoordinated(provider, worldName, world, true, project);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unloads a tool world and deletes its files, reserving the world mutation lock like a studio close. Players must be
|
||||
* gone from it already; any that remain are sent to the spawn of another world.
|
||||
*/
|
||||
public CompletableFuture<StudioCloseResult> closeToolWorld(World world) {
|
||||
Objects.requireNonNull(world, "world");
|
||||
PlatformChunkGenerator provider = IrisToolbelt.access(world);
|
||||
return closeWorldCoordinated(provider, IrisWorldStorage.logicalName(world), world, true, null);
|
||||
}
|
||||
|
||||
public CompletableFuture<Boolean> teleportPlayerToProject(
|
||||
IrisProject project,
|
||||
Player player
|
||||
@@ -772,7 +782,7 @@ public final class StudioOpenCoordinator {
|
||||
}
|
||||
String transientName = TransientWorldCleanupSupport.transientStudioBaseWorldName(
|
||||
child.getFileName().toString());
|
||||
if (transientName != null) {
|
||||
if (transientName != null && !StudioPainterSlots.isInstalled(transientName)) {
|
||||
worldNames.add(transientName);
|
||||
}
|
||||
}
|
||||
@@ -923,6 +933,10 @@ public final class StudioOpenCoordinator {
|
||||
true,
|
||||
IrisCreator.DatapackPreparation.REUSE_LOADED_RUNTIME_IF_READY),
|
||||
JIGSAW(
|
||||
false,
|
||||
false,
|
||||
IrisCreator.DatapackPreparation.REUSE_LOADED_RUNTIME_IF_READY),
|
||||
TOOL(
|
||||
false,
|
||||
false,
|
||||
IrisCreator.DatapackPreparation.REUSE_LOADED_RUNTIME_IF_READY);
|
||||
@@ -952,7 +966,7 @@ public final class StudioOpenCoordinator {
|
||||
}
|
||||
|
||||
public boolean prepareGeneratorState() {
|
||||
return this != JIGSAW;
|
||||
return this != JIGSAW && this != TOOL;
|
||||
}
|
||||
|
||||
public IrisCreator.DatapackPreparation datapackPreparation() {
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.core.runtime;
|
||||
|
||||
import com.volmit.object.BlockEntityData;
|
||||
import com.volmit.tooling.world.ChunkPainter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Which studio worlds are painted by a tool instead of generated from their pack, keyed by the logical name of the
|
||||
* world. A tool world installs its slot before the world is created, so the first chunk the world generates is already
|
||||
* the tool's, and removes it when the world closes. The world's generator reads the slot on every chunk, so a slot that
|
||||
* is installed or removed takes effect at the next chunk.
|
||||
*/
|
||||
public final class StudioPainterSlots {
|
||||
private static final Map<String, Slot> SLOTS = new ConcurrentHashMap<>();
|
||||
|
||||
private StudioPainterSlots() {
|
||||
}
|
||||
|
||||
/**
|
||||
* A tool's claim on one world: the painter, and where the block entities it painted go. They go to
|
||||
* {@code blockEntities} because they can only be applied once the chunk is live, which is later than the paint.
|
||||
*/
|
||||
public record Slot(ChunkPainter painter, Consumer<PaintedChunk> blockEntities) {
|
||||
public Slot {
|
||||
Objects.requireNonNull(painter, "painter");
|
||||
Objects.requireNonNull(blockEntities, "blockEntities");
|
||||
}
|
||||
}
|
||||
|
||||
/** The block entities one paint of chunk {@code chunkX}, {@code chunkZ} asked for; never empty. */
|
||||
public record PaintedChunk(int chunkX, int chunkZ, List<PaintedBlockEntity> blockEntities) {
|
||||
public PaintedChunk {
|
||||
blockEntities = List.copyOf(blockEntities);
|
||||
}
|
||||
}
|
||||
|
||||
/** A block entity at chunk-local {@code x} and {@code z} and world {@code y}. */
|
||||
public record PaintedBlockEntity(int x, int y, int z, BlockEntityData data) {
|
||||
public PaintedBlockEntity {
|
||||
Objects.requireNonNull(data, "data");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the world called {@code worldName} a painted one.
|
||||
*
|
||||
* @throws IllegalStateException when a tool painted that world already
|
||||
*/
|
||||
public static void install(String worldName, Slot slot) {
|
||||
Objects.requireNonNull(worldName, "worldName");
|
||||
Objects.requireNonNull(slot, "slot");
|
||||
if (SLOTS.putIfAbsent(worldName, slot) != null) {
|
||||
throw new IllegalStateException("The world " + worldName + " is painted by a tool already");
|
||||
}
|
||||
}
|
||||
|
||||
/** The slot of the world called {@code worldName}; empty for a world generated from its pack. */
|
||||
public static Optional<Slot> slotOf(String worldName) {
|
||||
return worldName == null ? Optional.empty() : Optional.ofNullable(SLOTS.get(worldName));
|
||||
}
|
||||
|
||||
public static boolean isInstalled(String worldName) {
|
||||
return slotOf(worldName).isPresent();
|
||||
}
|
||||
|
||||
/** Gives the world back to its pack. Does nothing for a world nobody painted. */
|
||||
public static void remove(String worldName) {
|
||||
if (worldName != null) {
|
||||
SLOTS.remove(worldName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,6 +65,7 @@ public class BoardSVC implements IrisService, BoardProvider {
|
||||
|
||||
private final Map<Player, PlayerBoard> boards = new ConcurrentHashMap<>();
|
||||
private final Map<UUID, JigsawStudioBoardContext> jigsawContexts = new ConcurrentHashMap<>();
|
||||
private final Map<UUID, ToolSidebar> toolSidebars = new ConcurrentHashMap<>();
|
||||
private final Map<UUID, UUID> yieldedWorlds = new ConcurrentHashMap<>();
|
||||
private final Set<UUID> hiddenPlayers = ConcurrentHashMap.newKeySet();
|
||||
private volatile BoardSettings settings;
|
||||
@@ -118,6 +119,7 @@ public class BoardSVC implements IrisService, BoardProvider {
|
||||
}
|
||||
boards.clear();
|
||||
jigsawContexts.clear();
|
||||
toolSidebars.clear();
|
||||
yieldedWorlds.clear();
|
||||
hiddenPlayers.clear();
|
||||
settings = null;
|
||||
@@ -137,6 +139,7 @@ public class BoardSVC implements IrisService, BoardProvider {
|
||||
public void on(PlayerQuitEvent e) {
|
||||
remove(e.getPlayer());
|
||||
jigsawContexts.remove(e.getPlayer().getUniqueId());
|
||||
toolSidebars.remove(e.getPlayer().getUniqueId());
|
||||
yieldedWorlds.remove(e.getPlayer().getUniqueId());
|
||||
clearPlayerPreference(e.getPlayer().getUniqueId());
|
||||
}
|
||||
@@ -164,19 +167,58 @@ public class BoardSVC implements IrisService, BoardProvider {
|
||||
|
||||
if (!isEligibleWorld(p)) {
|
||||
jigsawContexts.remove(playerId);
|
||||
toolSidebars.remove(playerId);
|
||||
remove(p);
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerBoard playerBoard = boards.computeIfAbsent(p, PlayerBoard::new);
|
||||
ToolSidebar toolSidebar = currentToolSidebar(p);
|
||||
JigsawStudioBoardContext jigsawContext = currentJigsawContext(p);
|
||||
if (jigsawContext != null) {
|
||||
if (toolSidebar != null) {
|
||||
playerBoard.showTool(toolSidebar);
|
||||
} else if (jigsawContext != null) {
|
||||
playerBoard.showJigsaw(jigsawContext);
|
||||
} else {
|
||||
playerBoard.showOrdinary();
|
||||
}
|
||||
}
|
||||
|
||||
/** What a tool shows a player in a tool world: a title and plain lines, top to bottom, for as long as the player stays in {@code worldId}. */
|
||||
public record ToolSidebar(UUID worldId, String title, List<String> lines) {
|
||||
public ToolSidebar {
|
||||
Objects.requireNonNull(worldId, "worldId");
|
||||
Objects.requireNonNull(title, "title");
|
||||
lines = List.copyOf(lines);
|
||||
}
|
||||
}
|
||||
|
||||
public void applyToolSidebar(Player player, ToolSidebar sidebar) {
|
||||
Objects.requireNonNull(player, "Tool sidebar player");
|
||||
Objects.requireNonNull(sidebar, "Tool sidebar");
|
||||
if (!J.isOwnedByCurrentRegion(player)) {
|
||||
J.runEntity(player, () -> applyToolSidebar(player, sidebar));
|
||||
return;
|
||||
}
|
||||
if (!player.isOnline()) {
|
||||
return;
|
||||
}
|
||||
toolSidebars.put(player.getUniqueId(), sidebar);
|
||||
if (sidebar.worldId().equals(player.getWorld().getUID())) {
|
||||
updatePlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearToolSidebar(Player player) {
|
||||
Objects.requireNonNull(player, "Tool sidebar player");
|
||||
if (!J.isOwnedByCurrentRegion(player)) {
|
||||
J.runEntity(player, () -> clearToolSidebar(player));
|
||||
return;
|
||||
}
|
||||
toolSidebars.remove(player.getUniqueId());
|
||||
updatePlayer(player);
|
||||
}
|
||||
|
||||
public void applyJigsawContext(Player player, JigsawStudioBoardContext context) {
|
||||
Objects.requireNonNull(player, "Jigsaw Studio board player");
|
||||
Objects.requireNonNull(context, "Jigsaw Studio board context");
|
||||
@@ -212,6 +254,7 @@ public class BoardSVC implements IrisService, BoardProvider {
|
||||
PlayerBoard previousBoard = boards.get(player);
|
||||
boolean alreadyOrdinary = previousBoard != null && previousBoard.isOrdinary();
|
||||
jigsawContexts.remove(player.getUniqueId());
|
||||
toolSidebars.remove(player.getUniqueId());
|
||||
updatePlayer(player);
|
||||
PlayerBoard playerBoard = boards.get(player);
|
||||
if (alreadyOrdinary && playerBoard == previousBoard) {
|
||||
@@ -247,6 +290,10 @@ public class BoardSVC implements IrisService, BoardProvider {
|
||||
|
||||
@Override
|
||||
public String getTitle(Player player) {
|
||||
PlayerBoard board = boards.get(player);
|
||||
if (board != null && board.view == BoardView.TOOL) {
|
||||
return board.title;
|
||||
}
|
||||
return IrisLanguage.text(BukkitUiMessages.SCOREBOARD_TITLE);
|
||||
}
|
||||
|
||||
@@ -342,6 +389,18 @@ public class BoardSVC implements IrisService, BoardProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private ToolSidebar currentToolSidebar(Player player) {
|
||||
ToolSidebar sidebar = toolSidebars.get(player.getUniqueId());
|
||||
if (sidebar == null || !sidebar.worldId().equals(player.getWorld().getUID())) {
|
||||
return null;
|
||||
}
|
||||
return sidebar;
|
||||
}
|
||||
|
||||
static List<String> toolLines(ToolSidebar sidebar) {
|
||||
return sidebar.lines().stream().map(BoardSVC::untrustedBoardValue).toList();
|
||||
}
|
||||
|
||||
private JigsawStudioBoardContext currentJigsawContext(Player player) {
|
||||
JigsawStudioBoardContext context = jigsawContexts.get(player.getUniqueId());
|
||||
if (context == null || !context.worldId().equals(player.getWorld().getUID())) {
|
||||
@@ -355,6 +414,8 @@ public class BoardSVC implements IrisService, BoardProvider {
|
||||
private final Board board;
|
||||
private volatile List<String> lines;
|
||||
private volatile JigsawStudioBoardContext jigsawContext;
|
||||
private volatile ToolSidebar toolSidebar;
|
||||
private volatile String title;
|
||||
private volatile BoardView view;
|
||||
private volatile boolean cancelled;
|
||||
private volatile boolean ordinaryTickScheduled;
|
||||
@@ -364,6 +425,8 @@ public class BoardSVC implements IrisService, BoardProvider {
|
||||
this.board = new Board(player, settings);
|
||||
this.lines = List.of();
|
||||
this.jigsawContext = null;
|
||||
this.toolSidebar = null;
|
||||
this.title = "";
|
||||
this.view = BoardView.NONE;
|
||||
this.cancelled = false;
|
||||
this.ordinaryTickScheduled = false;
|
||||
@@ -380,6 +443,7 @@ public class BoardSVC implements IrisService, BoardProvider {
|
||||
boolean switched = view != BoardView.ORDINARY;
|
||||
view = BoardView.ORDINARY;
|
||||
jigsawContext = null;
|
||||
toolSidebar = null;
|
||||
if (switched) {
|
||||
updateOrdinary();
|
||||
board.update();
|
||||
@@ -412,10 +476,30 @@ public class BoardSVC implements IrisService, BoardProvider {
|
||||
}
|
||||
view = BoardView.JIGSAW;
|
||||
jigsawContext = context;
|
||||
toolSidebar = null;
|
||||
lines = jigsawLines(context);
|
||||
board.update();
|
||||
}
|
||||
|
||||
private void showTool(ToolSidebar sidebar) {
|
||||
if (cancelled) {
|
||||
return;
|
||||
}
|
||||
if (!board.ownsScoreboardAssignment()) {
|
||||
yieldBoard(player, this);
|
||||
return;
|
||||
}
|
||||
if (view == BoardView.TOOL && sidebar.equals(toolSidebar)) {
|
||||
return;
|
||||
}
|
||||
view = BoardView.TOOL;
|
||||
toolSidebar = sidebar;
|
||||
jigsawContext = null;
|
||||
title = untrustedBoardValue(sidebar.title());
|
||||
lines = toolLines(sidebar);
|
||||
board.update();
|
||||
}
|
||||
|
||||
private void scheduleOrdinaryTick() {
|
||||
if (ordinaryTickScheduled || cancelled || view != BoardView.ORDINARY
|
||||
|| !boardEnabled || !player.isOnline()) {
|
||||
@@ -444,6 +528,11 @@ public class BoardSVC implements IrisService, BoardProvider {
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
ToolSidebar sidebar = currentToolSidebar(player);
|
||||
if (sidebar != null) {
|
||||
showTool(sidebar);
|
||||
return;
|
||||
}
|
||||
JigsawStudioBoardContext context = currentJigsawContext(player);
|
||||
if (context != null) {
|
||||
showJigsaw(context);
|
||||
@@ -534,6 +623,7 @@ public class BoardSVC implements IrisService, BoardProvider {
|
||||
private enum BoardView {
|
||||
NONE,
|
||||
ORDINARY,
|
||||
JIGSAW
|
||||
JIGSAW,
|
||||
TOOL
|
||||
}
|
||||
}
|
||||
@@ -20,19 +20,23 @@ package art.arcane.iris.core.tooling;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.IrisValidationContext;
|
||||
import art.arcane.iris.core.modules.PackServices;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.IrisServices;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.tooling.ObjectCodec;
|
||||
import com.volmit.tooling.PackEdit;
|
||||
import com.volmit.tooling.ToolPack;
|
||||
import com.volmit.tooling.world.ToolWorlds;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@@ -101,6 +105,17 @@ public final class IrisToolPack implements ToolPack {
|
||||
return log;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ToolWorlds worlds() {
|
||||
ToolWorldsHost host = IrisServices.getOrNull(ToolWorldsHost.class);
|
||||
return host == null ? UnsupportedToolWorlds.INSTANCE : host.worldsOf(data.getDataFolder().getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S> List<S> services(Class<S> service) {
|
||||
return PackServices.of(data).providers(service);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "pack " + data.getDataFolder().getName();
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.core.tooling;
|
||||
|
||||
import com.volmit.tooling.world.ToolWorlds;
|
||||
|
||||
/**
|
||||
* The tool worlds a platform adapter offers, bound with {@code IrisServices} by an adapter that has them. A platform
|
||||
* that binds none answers {@link UnsupportedToolWorlds}.
|
||||
*/
|
||||
public interface ToolWorldsHost {
|
||||
/** The tool worlds of the pack in the folder {@code packName}, which tools reach through {@code ToolPack.worlds()}. */
|
||||
ToolWorlds worldsOf(String packName);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.core.tooling;
|
||||
|
||||
import com.volmit.tooling.world.ToolWorld;
|
||||
import com.volmit.tooling.world.ToolWorldSpec;
|
||||
import com.volmit.tooling.world.ToolWorlds;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/** The tool worlds of a platform that has none: nothing opens and nothing is found. */
|
||||
public final class UnsupportedToolWorlds implements ToolWorlds {
|
||||
public static final String MESSAGE = "Tool worlds are not supported on this platform yet";
|
||||
public static final UnsupportedToolWorlds INSTANCE = new UnsupportedToolWorlds();
|
||||
|
||||
private UnsupportedToolWorlds() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ToolWorld> open(ToolWorldSpec spec) {
|
||||
Objects.requireNonNull(spec, "spec");
|
||||
return CompletableFuture.failedFuture(new UnsupportedOperationException(MESSAGE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ToolWorld> find(String name) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
@@ -28,11 +28,13 @@ import java.util.concurrent.Semaphore;
|
||||
import art.arcane.iris.spi.IrisServices;
|
||||
import art.arcane.iris.platform.bukkit.BukkitPlatform;
|
||||
import art.arcane.iris.core.IrisSettings;
|
||||
import art.arcane.iris.core.IrisWorldStorage;
|
||||
import art.arcane.iris.core.IrisWorlds;
|
||||
import art.arcane.iris.core.gui.PregeneratorJob;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.nms.INMS;
|
||||
import art.arcane.iris.core.runtime.ObjectStudioActivation;
|
||||
import art.arcane.iris.core.runtime.StudioPainterSlots;
|
||||
import art.arcane.iris.core.runtime.jigsaw.JigsawStudioActivation;
|
||||
import art.arcane.iris.core.runtime.jigsaw.JigsawStudioSession;
|
||||
import art.arcane.iris.core.service.StudioSVC;
|
||||
@@ -52,6 +54,7 @@ import art.arcane.iris.engine.object.world.IrisWorld;
|
||||
import art.arcane.iris.engine.object.runtime.StudioMode;
|
||||
import art.arcane.iris.engine.platform.studio.StudioGenerator;
|
||||
import art.arcane.iris.engine.platform.studio.generators.JigsawStudioGenerator;
|
||||
import art.arcane.iris.engine.platform.studio.generators.PainterStudioGenerator;
|
||||
import art.arcane.iris.platform.bukkit.BukkitWorldBinding;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
@@ -90,6 +93,7 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -128,6 +132,7 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
||||
private volatile Looper hotloader;
|
||||
private volatile StudioMode lastMode;
|
||||
private volatile UUID lastJigsawStudioRequestId;
|
||||
private volatile StudioPainterSlots.Slot lastPainterSlot;
|
||||
private volatile boolean jigsawStudioActive;
|
||||
private volatile DummyBiomeProvider dummyBiomeProvider;
|
||||
private volatile Throwable initializationFailure;
|
||||
@@ -343,6 +348,7 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
||||
private void setupEngine() {
|
||||
lastMode = StudioMode.NORMAL;
|
||||
lastJigsawStudioRequestId = null;
|
||||
lastPainterSlot = null;
|
||||
EngineTarget engineTarget = getTarget();
|
||||
String packKey = engineTarget.getDimension().getLoadKey();
|
||||
JigsawStudioActivation.Request request = studio
|
||||
@@ -351,9 +357,10 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
||||
JigsawStudioSession session = request == null
|
||||
? null
|
||||
: JigsawStudioActivation.getGeneratorSession(packKey);
|
||||
jigsawStudioActive = request != null
|
||||
boolean jigsawRequestActive = request != null
|
||||
&& session != null
|
||||
&& session.sessionId().equals(request.requestId());
|
||||
jigsawStudioActive = jigsawRequestActive || paintedStudioSlot().isPresent();
|
||||
IrisEngine createdEngine = new IrisEngine(
|
||||
engineTarget,
|
||||
selectInitializationMode(studio, jigsawStudioActive));
|
||||
@@ -965,6 +972,9 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
||||
lastJigsawStudioRequestId = null;
|
||||
lastMode = null;
|
||||
}
|
||||
if (installPaintedStudioGenerator()) {
|
||||
return;
|
||||
}
|
||||
// Gson nulls unknown enum names, so a pack carrying a removed or typo'd studioMode must not NPE the generator.
|
||||
// Pack-declared studio modes are studio-only: a shipped pack that forgot to reset
|
||||
// studioMode must never replace production terrain with a debug generator.
|
||||
@@ -980,6 +990,31 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
||||
}
|
||||
}
|
||||
|
||||
private Optional<StudioPainterSlots.Slot> paintedStudioSlot() {
|
||||
if (!studio || world.identity() == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return StudioPainterSlots.slotOf(IrisWorldStorage.logicalName(WorldIdentity.parse(world.identity())));
|
||||
}
|
||||
|
||||
/** Makes the generator the tool's painter while a slot is installed for this world; false when none is. */
|
||||
private boolean installPaintedStudioGenerator() {
|
||||
Optional<StudioPainterSlots.Slot> slot = paintedStudioSlot();
|
||||
if (slot.isEmpty()) {
|
||||
if (lastPainterSlot != null) {
|
||||
lastPainterSlot = null;
|
||||
lastMode = null;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (slot.get() != lastPainterSlot) {
|
||||
setStudioGenerator(new PainterStudioGenerator(slot.get()));
|
||||
lastPainterSlot = slot.get();
|
||||
lastMode = null;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<BlockPopulator> getDefaultPopulators(@NotNull World world) {
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.platform.studio;
|
||||
|
||||
import art.arcane.iris.core.modules.PlatformBlockStates;
|
||||
import art.arcane.iris.core.runtime.StudioPainterSlots.PaintedBlockEntity;
|
||||
import art.arcane.iris.engine.data.chunk.TerrainChunk;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.object.BlockEntityData;
|
||||
import com.volmit.tooling.world.ChunkCanvas;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* The canvas of one paint of a tool world: block states go into a {@link TerrainChunk}, and the block entities the
|
||||
* painter asks for are kept to be applied once the chunk is live. One canvas serves one paint on one thread.
|
||||
*/
|
||||
public final class TerrainChunkCanvas implements ChunkCanvas {
|
||||
private static final int CHUNK_SIZE = 16;
|
||||
|
||||
private final TerrainChunk chunk;
|
||||
private final PlatformBlockStates states;
|
||||
private final List<PaintedBlockEntity> blockEntities = new ArrayList<>();
|
||||
|
||||
/** {@code platformStates} turns a block state key into the platform's state; it fails for a key the platform lacks. */
|
||||
public TerrainChunkCanvas(TerrainChunk chunk, Function<String, PlatformBlockState> platformStates) {
|
||||
this.chunk = Objects.requireNonNull(chunk, "chunk");
|
||||
this.states = new PlatformBlockStates(Objects.requireNonNull(platformStates, "platformStates"));
|
||||
}
|
||||
|
||||
/** A canvas over {@code chunk} that resolves block states through the platform Iris is bound to. */
|
||||
public static TerrainChunkCanvas onPlatform(TerrainChunk chunk) {
|
||||
return new TerrainChunkCanvas(chunk, TerrainChunkCanvas::platformState);
|
||||
}
|
||||
|
||||
private static PlatformBlockState platformState(String key) {
|
||||
PlatformBlockState state = B.getStateOrNull(key, false);
|
||||
if (state == null) {
|
||||
throw new IllegalArgumentException("The platform has no block state " + key);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int minY() {
|
||||
return chunk.getMinHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int maxY() {
|
||||
return chunk.getMaxHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int z, BlockState state) {
|
||||
requireInside(x, y, z);
|
||||
chunk.setBlock(x, y, z, states.toPlatform(Objects.requireNonNull(state, "state")));
|
||||
blockEntities.removeIf(painted -> painted.x() == x && painted.y() == y && painted.z() == z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int z, BlockState state, BlockEntityData data) {
|
||||
Objects.requireNonNull(data, "data");
|
||||
set(x, y, z, state);
|
||||
blockEntities.add(new PaintedBlockEntity(x, y, z, data));
|
||||
}
|
||||
|
||||
/** The block entities painted so far, one for each position that still holds the block it was painted with. */
|
||||
public List<PaintedBlockEntity> blockEntities() {
|
||||
return List.copyOf(blockEntities);
|
||||
}
|
||||
|
||||
private void requireInside(int x, int y, int z) {
|
||||
if (x < 0 || x >= CHUNK_SIZE || z < 0 || z >= CHUNK_SIZE) {
|
||||
throw new IllegalArgumentException("Chunk-local x and z are 0 to 15: " + x + ", " + z);
|
||||
}
|
||||
if (y < minY() || y >= maxY()) {
|
||||
throw new IllegalArgumentException("Y " + y + " is outside the world, " + minY() + " up to " + maxY());
|
||||
}
|
||||
}
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.platform.studio.generators;
|
||||
|
||||
import art.arcane.iris.core.runtime.StudioPainterSlots;
|
||||
import art.arcane.iris.engine.data.chunk.TerrainChunk;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.GenerationSessionLease;
|
||||
import art.arcane.iris.engine.framework.WrongEngineBroException;
|
||||
import art.arcane.iris.engine.platform.studio.StudioGenerator;
|
||||
import art.arcane.iris.engine.platform.studio.TerrainChunkCanvas;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.util.project.context.IrisContext;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
|
||||
/** Generates the chunks of a tool world: whatever the world's {@link StudioPainterSlots.Slot} paints, and nothing else. */
|
||||
public final class PainterStudioGenerator implements StudioGenerator {
|
||||
private static final String LEASE_OPERATION = "bukkit_tool_world_paint";
|
||||
|
||||
private final StudioPainterSlots.Slot slot;
|
||||
private final Function<TerrainChunk, TerrainChunkCanvas> canvases;
|
||||
|
||||
public PainterStudioGenerator(StudioPainterSlots.Slot slot) {
|
||||
this(slot, TerrainChunkCanvas::onPlatform);
|
||||
}
|
||||
|
||||
PainterStudioGenerator(StudioPainterSlots.Slot slot, Function<TerrainChunk, TerrainChunkCanvas> canvases) {
|
||||
this.slot = Objects.requireNonNull(slot, "slot");
|
||||
this.canvases = Objects.requireNonNull(canvases, "canvases");
|
||||
}
|
||||
|
||||
/** The slot this generator paints for; a world whose slot changed needs a new generator. */
|
||||
public StudioPainterSlots.Slot slot() {
|
||||
return slot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateChunk(Engine engine, TerrainChunk terrainChunk, int chunkX, int chunkZ)
|
||||
throws WrongEngineBroException {
|
||||
try (GenerationSessionLease lease = engine.acquireGenerationLease(LEASE_OPERATION);
|
||||
IrisContext.Scope ignored = IrisContext.open(engine, lease.sessionId(), null)) {
|
||||
paint(terrainChunk, chunkX, chunkZ);
|
||||
}
|
||||
}
|
||||
|
||||
/** Paints the chunk into {@code terrainChunk}; a painter that throws leaves the chunk as far as it got. */
|
||||
void paint(TerrainChunk terrainChunk, int chunkX, int chunkZ) {
|
||||
TerrainChunkCanvas canvas = canvases.apply(terrainChunk);
|
||||
try {
|
||||
slot.painter().paint(chunkX, chunkZ, canvas);
|
||||
} catch (RuntimeException failure) {
|
||||
IrisLogging.reportError("A tool world painter failed at chunk " + chunkX + "," + chunkZ + ".", failure);
|
||||
}
|
||||
if (!canvas.blockEntities().isEmpty()) {
|
||||
slot.blockEntities().accept(new StudioPainterSlots.PaintedChunk(chunkX, chunkZ, canvas.blockEntities()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -153,6 +153,11 @@ public final class CarveTestWorld implements PackWorld {
|
||||
return type.cast(known);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S> List<S> services(Class<S> service) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleLog log() {
|
||||
return ModuleLogs.discarding();
|
||||
|
||||
@@ -25,6 +25,8 @@ import com.volmit.resource.PackResources;
|
||||
import com.volmit.world.PackWorld;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
@@ -48,7 +50,8 @@ public class ToolWorldTest {
|
||||
public void theWorldKeepsItsStateUntilItIsClosed() {
|
||||
PackResources resources = mock(PackResources.class);
|
||||
Tracked tracked;
|
||||
try (ToolWorld world = new ToolWorld(SEED, resources, mock(PackSettings.class), ignored -> mock(Placements.class))) {
|
||||
try (ToolWorld world = new ToolWorld(SEED, resources, mock(PackSettings.class), mock(PackServices.class),
|
||||
ignored -> mock(Placements.class))) {
|
||||
tracked = world.state(Tracked.class, ignored -> new Tracked());
|
||||
|
||||
assertSame(tracked, world.state(Tracked.class, ignored -> new Tracked()));
|
||||
@@ -60,4 +63,22 @@ public class ToolWorldTest {
|
||||
|
||||
assertTrue(tracked.closed);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theWorldAnswersServicesWithTheProvidersOfThePacksModules() {
|
||||
Runnable provider = () -> { };
|
||||
PackServices services = new PackServices() {
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <S> List<S> providers(Class<S> service) {
|
||||
return service == Runnable.class ? (List<S>) List.of(provider) : List.of();
|
||||
}
|
||||
};
|
||||
|
||||
try (ToolWorld world = new ToolWorld(SEED, mock(PackResources.class), mock(PackSettings.class), services,
|
||||
ignored -> mock(Placements.class))) {
|
||||
assertEquals(List.of(provider), world.services(Runnable.class));
|
||||
assertEquals(List.of(), world.services(Comparable.class));
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -71,6 +71,18 @@ public class StudioOpenCoordinatorOpenKindTest {
|
||||
kind.datapackPreparation());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toolWorldsOpenLikeAJigsawStudioWithTheirOwnDestinationTeleport() {
|
||||
StudioOpenCoordinator.StudioOpenKind kind = StudioOpenCoordinator.StudioOpenKind.TOOL;
|
||||
|
||||
assertFalse(kind.openWorkspace());
|
||||
assertFalse(kind.teleportThroughStandardEntry());
|
||||
assertFalse(kind.prepareGeneratorState());
|
||||
assertEquals(
|
||||
IrisCreator.DatapackPreparation.REUSE_LOADED_RUNTIME_IF_READY,
|
||||
kind.datapackPreparation());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void studioRequestRetainsExplicitOpenKind() {
|
||||
IrisProject project = new IrisProject(new File("overworld"));
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package art.arcane.iris.core.runtime;
|
||||
|
||||
import com.volmit.tooling.world.ChunkPainter;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class StudioPainterSlotsTest {
|
||||
private static final String WORLD = "iris-00000000-0000-0000-0000-000000000001";
|
||||
private static final String OTHER_WORLD = "iris-00000000-0000-0000-0000-000000000002";
|
||||
|
||||
private final ChunkPainter painter = (chunkX, chunkZ, canvas) -> { };
|
||||
|
||||
@After
|
||||
public void removeSlots() {
|
||||
StudioPainterSlots.remove(WORLD);
|
||||
StudioPainterSlots.remove(OTHER_WORLD);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aWorldIsPaintedFromTheMomentItsSlotIsInstalledUntilItIsRemoved() {
|
||||
StudioPainterSlots.Slot slot = new StudioPainterSlots.Slot(painter, painted -> { });
|
||||
assertFalse(StudioPainterSlots.isInstalled(WORLD));
|
||||
|
||||
StudioPainterSlots.install(WORLD, slot);
|
||||
|
||||
assertTrue(StudioPainterSlots.isInstalled(WORLD));
|
||||
assertSame(slot, StudioPainterSlots.slotOf(WORLD).orElseThrow());
|
||||
assertFalse("other worlds keep their pack", StudioPainterSlots.isInstalled(OTHER_WORLD));
|
||||
|
||||
StudioPainterSlots.remove(WORLD);
|
||||
|
||||
assertFalse(StudioPainterSlots.isInstalled(WORLD));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aWorldHasOneSlotAtATime() {
|
||||
StudioPainterSlots.install(WORLD, new StudioPainterSlots.Slot(painter, painted -> { }));
|
||||
|
||||
assertThrows(IllegalStateException.class,
|
||||
() -> StudioPainterSlots.install(WORLD, new StudioPainterSlots.Slot(painter, painted -> { })));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removingASlotThatIsNotThereOrAskingForANullNameIsHarmless() {
|
||||
StudioPainterSlots.remove(WORLD);
|
||||
StudioPainterSlots.remove(null);
|
||||
|
||||
assertTrue(StudioPainterSlots.slotOf(null).isEmpty());
|
||||
assertTrue(StudioPainterSlots.slotOf(WORLD).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aPaintedChunkKeepsItsOwnCopyOfTheBlockEntities() {
|
||||
List<StudioPainterSlots.PaintedBlockEntity> entities = new java.util.ArrayList<>();
|
||||
StudioPainterSlots.PaintedChunk chunk = new StudioPainterSlots.PaintedChunk(1, 2, entities);
|
||||
entities.add(null);
|
||||
|
||||
assertTrue(chunk.blockEntities().isEmpty());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package art.arcane.iris.core.service;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
|
||||
public class BoardSVCToolSidebarTest {
|
||||
private static final UUID WORLD = UUID.fromString("11111111-1111-1111-1111-111111111111");
|
||||
|
||||
@Test
|
||||
public void aToolSidebarKeepsItsOwnCopyOfTheLines() {
|
||||
List<String> lines = new ArrayList<>(List.of("one"));
|
||||
BoardSVC.ToolSidebar sidebar = new BoardSVC.ToolSidebar(WORLD, "Title", lines);
|
||||
lines.add("two");
|
||||
|
||||
assertEquals(List.of("one"), sidebar.lines());
|
||||
assertThrows(NullPointerException.class, () -> new BoardSVC.ToolSidebar(null, "Title", List.of()));
|
||||
assertThrows(NullPointerException.class, () -> new BoardSVC.ToolSidebar(WORLD, null, List.of()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toolLinesAreShownAsPlainTextWithoutColourOrMarkup() {
|
||||
BoardSVC.ToolSidebar sidebar = new BoardSVC.ToolSidebar(WORLD, "Title",
|
||||
List.of("&cStructure§a<red>", "line\nbreak", "plain"));
|
||||
|
||||
assertEquals(List.of(BoardSVC.untrustedBoardValue("&cStructure§a<red>"), "line break", "plain"),
|
||||
BoardSVC.toolLines(sidebar));
|
||||
assertEquals("&cStructure‹red›", BoardSVC.toolLines(sidebar).get(0));
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,16 @@
|
||||
package art.arcane.iris.core.tooling;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.PackModuleSet;
|
||||
import art.arcane.iris.spi.IrisPlatform;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.IrisServices;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.host.FeatureCatalog;
|
||||
import com.volmit.host.LoadedPack;
|
||||
import com.volmit.service.Providers;
|
||||
import com.volmit.service.Service;
|
||||
import com.volmit.tooling.world.ToolWorlds;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
@@ -14,6 +21,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
@@ -138,6 +146,45 @@ public class IrisToolPackTest {
|
||||
assertFalse(output.startsWith(packFolder.toPath()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aPlatformWithoutToolWorldsAnswersThatTheyAreNotSupported() {
|
||||
IrisServices.remove(ToolWorldsHost.class);
|
||||
|
||||
ToolWorlds worlds = pack.worlds();
|
||||
|
||||
assertSame(UnsupportedToolWorlds.INSTANCE, worlds);
|
||||
assertTrue(worlds.find("any").isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aPlatformWithToolWorldsAnswersWithThoseOfThePacksFolder() {
|
||||
ToolWorlds overworldWorlds = mock(ToolWorlds.class);
|
||||
IrisServices.register(ToolWorldsHost.class, (ToolWorldsHost) packName -> "overworld".equals(packName) ? overworldWorlds : null);
|
||||
try {
|
||||
assertSame(overworldWorlds, pack.worlds());
|
||||
} finally {
|
||||
IrisServices.remove(ToolWorldsHost.class);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void servicesAreTheProvidersOfThePacksModules() {
|
||||
Probe probe = new Probe() { };
|
||||
FeatureCatalog catalog = mock(FeatureCatalog.class);
|
||||
LoadedPack loaded = mock(LoadedPack.class);
|
||||
PackModuleSet modules = mock(PackModuleSet.class);
|
||||
when(catalog.services(Probe.class)).thenReturn(List.of(probe));
|
||||
when(loaded.catalog()).thenReturn(catalog);
|
||||
when(modules.pack()).thenReturn(loaded);
|
||||
when(data.getModules()).thenReturn(modules);
|
||||
|
||||
assertEquals(List.of(probe), pack.services(Probe.class));
|
||||
}
|
||||
|
||||
@Service(Providers.ALL)
|
||||
interface Probe {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theObjectCodecReadsAndWritesIobFiles() {
|
||||
assertEquals(".iob", pack.objects().extension());
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.core.tooling;
|
||||
|
||||
import com.volmit.tooling.world.ToolPlayer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -39,6 +41,11 @@ final class RecordingSender implements ToolingSender {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ToolPlayer> player() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOperator() {
|
||||
return operator;
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package art.arcane.iris.core.tooling;
|
||||
|
||||
import com.volmit.tooling.world.ToolWorld;
|
||||
import com.volmit.tooling.world.ToolWorldListener;
|
||||
import com.volmit.tooling.world.ToolWorldSpec;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class UnsupportedToolWorldsTest {
|
||||
@Test
|
||||
public void openingFailsAndSaysThatToolWorldsAreNotSupportedYet() {
|
||||
ToolWorldSpec spec = new ToolWorldSpec("scratch", (chunkX, chunkZ, canvas) -> { }, new ToolWorldListener() { });
|
||||
|
||||
CompletableFuture<ToolWorld> opened = UnsupportedToolWorlds.INSTANCE.open(spec);
|
||||
|
||||
ExecutionException failure = assertThrows(ExecutionException.class, opened::get);
|
||||
assertTrue(failure.getCause() instanceof UnsupportedOperationException);
|
||||
assertEquals("Tool worlds are not supported on this platform yet", failure.getCause().getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nothingIsFound() {
|
||||
assertTrue(UnsupportedToolWorlds.INSTANCE.find("scratch").isEmpty());
|
||||
}
|
||||
}
|
||||
@@ -226,6 +226,11 @@ public class LootValidatorTest {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S> List<S> services(Class<S> service) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void report(Problem problem) {
|
||||
problems.add(problem);
|
||||
|
||||
@@ -690,6 +690,11 @@ public final class ApiChunk implements GenerationContext {
|
||||
return type.cast(known);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S> List<S> services(Class<S> service) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleLog log() {
|
||||
return ModuleLogs.discarding();
|
||||
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
package art.arcane.iris.engine.platform.studio;
|
||||
|
||||
import art.arcane.iris.core.runtime.StudioPainterSlots.PaintedBlockEntity;
|
||||
import art.arcane.iris.engine.data.chunk.TerrainChunk;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.object.BlockEntityData;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class TerrainChunkCanvasTest {
|
||||
private static final int MIN_Y = -64;
|
||||
private static final int MAX_Y = 320;
|
||||
private static final BlockEntityData CHEST_DATA =
|
||||
new BlockEntityData(ResourceId.parse("iris:tile"), 1, new byte[] {1, 2, 3});
|
||||
private static final BlockEntityData SIGN_DATA =
|
||||
new BlockEntityData(ResourceId.parse("iris:tile"), 1, new byte[] {9});
|
||||
|
||||
private TerrainChunk chunk;
|
||||
private final Map<String, PlatformBlockState> platformStates = new HashMap<>();
|
||||
private TerrainChunkCanvas canvas;
|
||||
|
||||
@Before
|
||||
public void anEmptyChunk() {
|
||||
chunk = mock(TerrainChunk.class);
|
||||
when(chunk.getMinHeight()).thenReturn(MIN_Y);
|
||||
when(chunk.getMaxHeight()).thenReturn(MAX_Y);
|
||||
canvas = new TerrainChunkCanvas(chunk, key -> platformStates.computeIfAbsent(key, ignored -> mock(PlatformBlockState.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theCanvasReportsTheHeightRangeOfTheChunk() {
|
||||
assertEquals(MIN_Y, canvas.minY());
|
||||
assertEquals(MAX_Y, canvas.maxY());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aBlockGoesIntoTheChunkAsThePlatformsStateOfItsKey() {
|
||||
canvas.set(3, 70, 12, BlockState.parse("minecraft:oak_log[axis=y]"));
|
||||
|
||||
PlatformBlockState written = platformStates.get("minecraft:oak_log[axis=y]");
|
||||
verify(chunk).setBlock(3, 70, 12, written);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void thePlatformIsAskedOnceForAKeyAndItsAnswerIsReused() {
|
||||
canvas.set(0, 0, 0, BlockState.parse("minecraft:stone"));
|
||||
canvas.set(1, 0, 0, BlockState.parse("minecraft:stone"));
|
||||
|
||||
PlatformBlockState stone = platformStates.get("minecraft:stone");
|
||||
verify(chunk).setBlock(0, 0, 0, stone);
|
||||
verify(chunk).setBlock(1, 0, 0, stone);
|
||||
assertEquals(1, platformStates.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void positionsOutsideTheChunkOrTheWorldAreRefusedAndNothingIsWritten() {
|
||||
BlockState stone = BlockState.parse("minecraft:stone");
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> canvas.set(16, 0, 0, stone));
|
||||
assertThrows(IllegalArgumentException.class, () -> canvas.set(-1, 0, 0, stone));
|
||||
assertThrows(IllegalArgumentException.class, () -> canvas.set(0, 0, 16, stone));
|
||||
assertThrows(IllegalArgumentException.class, () -> canvas.set(0, MIN_Y - 1, 0, stone));
|
||||
assertThrows(IllegalArgumentException.class, () -> canvas.set(0, MAX_Y, 0, stone));
|
||||
verify(chunk, never()).setBlock(anyInt(), anyInt(), anyInt(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theLowestAndHighestBlocksOfTheWorldAreInside() {
|
||||
canvas.set(0, MIN_Y, 0, BlockState.parse("minecraft:bedrock"));
|
||||
canvas.set(15, MAX_Y - 1, 15, BlockState.parse("minecraft:glass"));
|
||||
|
||||
verify(chunk).setBlock(0, MIN_Y, 0, platformStates.get("minecraft:bedrock"));
|
||||
verify(chunk).setBlock(15, MAX_Y - 1, 15, platformStates.get("minecraft:glass"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void blockEntitiesAreKeptInPaintOrderWithTheirPositions() {
|
||||
canvas.set(1, 64, 2, BlockState.parse("minecraft:chest"), CHEST_DATA);
|
||||
canvas.set(4, 65, 5, BlockState.parse("minecraft:oak_sign"), SIGN_DATA);
|
||||
|
||||
assertEquals(List.of(new PaintedBlockEntity(1, 64, 2, CHEST_DATA), new PaintedBlockEntity(4, 65, 5, SIGN_DATA)),
|
||||
canvas.blockEntities());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void paintingAnotherBlockOverABlockEntityDropsTheEntity() {
|
||||
canvas.set(1, 64, 2, BlockState.parse("minecraft:chest"), CHEST_DATA);
|
||||
canvas.set(1, 64, 2, BlockState.parse("minecraft:stone"));
|
||||
|
||||
assertTrue(canvas.blockEntities().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void paintingTwoEntitiesAtOnePositionKeepsTheLaterOne() {
|
||||
canvas.set(1, 64, 2, BlockState.parse("minecraft:chest"), CHEST_DATA);
|
||||
canvas.set(1, 64, 2, BlockState.parse("minecraft:chest"), SIGN_DATA);
|
||||
|
||||
assertEquals(List.of(new PaintedBlockEntity(1, 64, 2, SIGN_DATA)), canvas.blockEntities());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aStateThePlatformLacksFailsThePaint() {
|
||||
TerrainChunkCanvas strict = new TerrainChunkCanvas(chunk, key -> {
|
||||
throw new IllegalArgumentException("no " + key);
|
||||
});
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> strict.set(0, 0, 0, BlockState.parse("example:nothing")));
|
||||
}
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package art.arcane.iris.engine.platform.studio.generators;
|
||||
|
||||
import art.arcane.iris.core.runtime.StudioPainterSlots;
|
||||
import art.arcane.iris.engine.data.chunk.TerrainChunk;
|
||||
import art.arcane.iris.engine.platform.studio.TerrainChunkCanvas;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.object.BlockEntityData;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.tooling.world.ChunkPainter;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class PainterStudioGeneratorTest {
|
||||
private static final BlockEntityData CHEST_DATA =
|
||||
new BlockEntityData(ResourceId.parse("iris:tile"), 1, new byte[] {1});
|
||||
|
||||
private TerrainChunk chunk;
|
||||
private final List<StudioPainterSlots.PaintedChunk> sunk = new ArrayList<>();
|
||||
|
||||
@Before
|
||||
public void anEmptyChunk() {
|
||||
chunk = mock(TerrainChunk.class);
|
||||
when(chunk.getMinHeight()).thenReturn(0);
|
||||
when(chunk.getMaxHeight()).thenReturn(256);
|
||||
}
|
||||
|
||||
private PainterStudioGenerator generatorPainting(ChunkPainter painter) {
|
||||
StudioPainterSlots.Slot slot = new StudioPainterSlots.Slot(painter, sunk::add);
|
||||
return new PainterStudioGenerator(slot, terrain -> new TerrainChunkCanvas(terrain, key -> mock(PlatformBlockState.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theChunkIsWhatThePainterPaintsForThatChunkPosition() {
|
||||
List<int[]> asked = new ArrayList<>();
|
||||
PainterStudioGenerator generator = generatorPainting((chunkX, chunkZ, canvas) -> {
|
||||
asked.add(new int[] {chunkX, chunkZ});
|
||||
canvas.set(0, 5, 0, BlockState.parse("minecraft:stone"));
|
||||
});
|
||||
|
||||
generator.paint(chunk, 3, -4);
|
||||
|
||||
assertEquals(1, asked.size());
|
||||
assertEquals(3, asked.get(0)[0]);
|
||||
assertEquals(-4, asked.get(0)[1]);
|
||||
verify(chunk).setBlock(eq(0), eq(5), eq(0), any());
|
||||
assertTrue("no block entities were painted", sunk.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void blockEntitiesGoToTheSlotWithTheChunkTheyBelongTo() {
|
||||
PainterStudioGenerator generator = generatorPainting((chunkX, chunkZ, canvas) ->
|
||||
canvas.set(1, 64, 2, BlockState.parse("minecraft:chest"), CHEST_DATA));
|
||||
|
||||
generator.paint(chunk, 7, 8);
|
||||
|
||||
assertEquals(1, sunk.size());
|
||||
assertEquals(7, sunk.get(0).chunkX());
|
||||
assertEquals(8, sunk.get(0).chunkZ());
|
||||
assertEquals(List.of(new StudioPainterSlots.PaintedBlockEntity(1, 64, 2, CHEST_DATA)), sunk.get(0).blockEntities());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aPainterThatThrowsLeavesTheChunkAsFarAsItGotAndDoesNotFailTheGeneration() {
|
||||
PainterStudioGenerator generator = generatorPainting((chunkX, chunkZ, canvas) -> {
|
||||
canvas.set(0, 5, 0, BlockState.parse("minecraft:stone"));
|
||||
throw new IllegalStateException("painter bug");
|
||||
});
|
||||
|
||||
generator.paint(chunk, 0, 0);
|
||||
|
||||
verify(chunk).setBlock(eq(0), eq(5), eq(0), any());
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.RunningWorld;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
@@ -85,6 +86,11 @@ public final class TestLayerBlocks {
|
||||
return type.cast(states.computeIfAbsent(type, ignored -> create.apply(this)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S> List<S> services(Class<S> service) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleLog log() {
|
||||
return ModuleLogs.discarding();
|
||||
|
||||
@@ -114,6 +114,11 @@ public final class TestPackWorld implements PackWorld {
|
||||
return type.cast(states.computeIfAbsent(type, ignored -> create.apply(this)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S> List<S> services(Class<S> service) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleLog log() {
|
||||
return ModuleLogs.discarding();
|
||||
|
||||
Reference in new issue
Block a user