Merge upstream port lane c

This commit is contained in:
piexel committed 2026-11-10 01:31:37 +01:00
commit 55786d6297
50 files changed
+2014 -256

No files matched your search

@@ -1,6 +1,10 @@
package art.arcane.iris.api.tree;
public interface TreeFellerRunHooks {
default boolean requiresSneaking() {
return true;
}
TreeFellerRunHooks NONE = new TreeFellerRunHooks() {
@Override
public void onActivationAccepted() {
@@ -333,7 +333,7 @@ public class CommandFind implements DirectorExecutor {
}
Set<String> configuredImportUrls = normalizedImportUrls(
engine.getDimension().getDatapackImports());
DatapackIngestService.configuredImports(engine.getDimension()));
return new StructureExclusionReport(
List.copyOf(exclusions), Set.copyOf(registeredKeys.keySet()),
configuredImportUrls, registeredExcluded, configuredUnregistered,
@@ -520,21 +520,19 @@ public class CommandObject implements DirectorExecutor {
return;
}
if (WandSVC.isHoldingIrisWand(player)) {
Location[] g = WandSVC.getCuboid(player);
Location[] g = WandSVC.getCuboid(player);
if (g == null) {
return;
}
if (!here) {
// TODO: WARNING HEIGHT
g[0] = player.getTargetBlock(null, 256).getLocation().clone();
} else {
g[0] = player.getLocation().getBlock().getLocation().clone().add(0, -1, 0);
}
player.getInventory().setItemInMainHand(WandSVC.createWand(g[0], g[1]));
if (g == null) {
return;
}
if (!here) {
// TODO: WARNING HEIGHT
g[0] = player.getTargetBlock(null, 256).getLocation().clone();
} else {
g[0] = player.getLocation().getBlock().getLocation().clone().add(0, -1, 0);
}
player.getInventory().setItemInMainHand(WandSVC.createWand(g[0], g[1]));
});
}
@@ -112,6 +112,6 @@ public final class DatapackStructureScopeSVC implements IrisService {
return Set.of();
}
return scopeIndex.declaredSources(
generator.getTarget().getDimension().getDatapackImports());
DatapackIngestService.configuredImports(generator.getTarget().getDimension()));
}
}
@@ -220,7 +220,7 @@ public class TreeFellerSVC implements IrisService, IrisTreeFellerService {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void haltWhenSneakingStops(PlayerToggleSneakEvent event) {
if (!event.isSneaking()) {
runner.finishRuns(event.getPlayer().getUniqueId());
runner.finishSneakRuns(event.getPlayer().getUniqueId());
}
}
@@ -526,10 +526,19 @@ final class TreeFellingRunner {
private boolean isRunControlActive(FellingRun run, Player player) {
return player.isOnline()
&& player.getGameMode() == GameMode.SURVIVAL
&& player.isSneaking()
&& (!requiresSneaking(run) || player.isSneaking())
&& player.getWorld().equals(run.candidate.world());
}
private boolean requiresSneaking(FellingRun run) {
try {
return run.runHooks.requiresSneaking();
} catch (RuntimeException error) {
IrisLogging.reportError("An Iris tree-feller integration sneak requirement check failed.", error);
return true;
}
}
private boolean reserveLogCost(FellingRun run) {
try {
return run.runHooks.reserveLogCost();
@@ -611,11 +620,22 @@ final class TreeFellingRunner {
}
void finishRuns(UUID playerId) {
finishRuns(playerId, false);
}
void finishSneakRuns(UUID playerId) {
finishRuns(playerId, true);
}
private void finishRuns(UUID playerId, boolean onlySneakRuns) {
Set<FellingRun> runs = service.activeRuns.get(playerId);
if (runs == null) {
return;
}
for (FellingRun run : List.copyOf(runs)) {
if (onlySneakRuns && !requiresSneaking(run)) {
continue;
}
if (run.abortReason == null) {
run.abortReason = "halted";
}
@@ -27,11 +27,9 @@ import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.World;
import art.arcane.iris.Iris;
import art.arcane.iris.core.IrisSettings;
import art.arcane.iris.core.localization.IrisLanguage;
import art.arcane.iris.core.localization.RuntimeUiMessages;
import art.arcane.iris.core.edit.DustRevealer;
import art.arcane.iris.core.link.WorldEditLink;
import art.arcane.iris.core.wand.WandSelection;
import art.arcane.iris.engine.object.prefab.IrisObject;
import art.arcane.iris.util.project.matter.WorldMatter;
@@ -333,26 +331,14 @@ public class WandSVC implements IrisService {
}
public static Location[] getCuboid(Player p) {
if (isHoldingIrisWand(p)) {
if (isHoldingWand(p)) {
return getCuboidFromItem(p.getInventory().getItemInMainHand());
}
if (IrisSettings.get().getWorld().worldEditWandCUI) {
Cuboid c = WorldEditLink.getSelection(p);
if (c != null) {
return new Location[]{c.getLowerNE(), c.getUpperSW()};
}
}
return null;
}
public static boolean isHoldingWand(Player p) {
return isHoldingIrisWand(p) || (IrisSettings.get().getWorld().worldEditWandCUI && WorldEditLink.getSelection(p) != null);
}
public static boolean isHoldingIrisWand(Player p) {
ItemStack is = p.getInventory().getItemInMainHand();
return is != null && isWand(is);
}
@@ -567,7 +553,7 @@ public class WandSVC implements IrisService {
if (e.getHand() != EquipmentSlot.HAND)
return;
try {
if (isHoldingIrisWand(e.getPlayer())) {
if (isHoldingWand(e.getPlayer())) {
activePlayers.put(e.getPlayer().getUniqueId(), e.getPlayer());
if (e.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
e.setCancelled(true);
@@ -204,7 +204,7 @@ public class IrisStructureLocateCommandContractTest {
assertTrue(method.contains("non-generating structure candidate(s) and their reasons to the server console"));
assertTrue(method.contains("no chunks were searched"));
assertTrue(method.indexOf("DatapackIngestService.installed()") > method.indexOf("J.a(() ->"));
assertTrue(source.contains("engine.getDimension().getDatapackImports()"));
assertTrue(source.contains("DatapackIngestService.configuredImports(engine.getDimension())"));
assertTrue(source.contains("snapshot.configuredImportUrls().contains(importUrl)"));
assertTrue(source.contains("ModuleServices.structureKeys(engine.getData())"));
assertFalse(method.contains("commandSender.sendMessage(exclusion"));
@@ -0,0 +1,99 @@
package art.arcane.iris.core.service;
import art.arcane.iris.api.tree.TreeFellerRunHooks;
import art.arcane.iris.core.service.TreeFellerModel.TreeCandidate;
import art.arcane.iris.core.service.TreeFellerModel.TreeClaim;
import art.arcane.iris.core.service.tree.TreeMarkerTraversal;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.junit.Test;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class TreeFellingRunnerSneakLatchTest {
private static final TreeFellerRunHooks LATCHED_HOOKS = new TreeFellerRunHooks() {
@Override
public boolean requiresSneaking() {
return false;
}
@Override
public void onActivationAccepted() {
}
@Override
public boolean reserveLogCost() {
return true;
}
@Override
public void commitLogCost() {
}
@Override
public void refundLogCost() {
}
};
@Test
public void runHooksRequireSneakingByDefault() {
assertTrue(TreeFellerRunHooks.NONE.requiresSneaking());
}
@Test
public void releasingSneakFinishesOnlyRunsThatRequireIt() {
TreeFellerSVC service = new TreeFellerSVC();
TreeFellingRunner runner = new TreeFellingRunner(service, null);
UUID playerId = UUID.randomUUID();
FellingRun sneakRun = registerRun(service, playerId, TreeFellerRunHooks.NONE, "sneak");
FellingRun latchedRun = registerRun(service, playerId, LATCHED_HOOKS, "latched");
runner.finishSneakRuns(playerId);
assertTrue(sneakRun.finished.get());
assertEquals("halted", sneakRun.abortReason);
assertFalse(latchedRun.finished.get());
assertTrue(service.activeRuns.get(playerId).contains(latchedRun));
}
@Test
public void finishingAllRunsStillEndsLatchedRuns() {
TreeFellerSVC service = new TreeFellerSVC();
TreeFellingRunner runner = new TreeFellingRunner(service, null);
UUID playerId = UUID.randomUUID();
FellingRun latchedRun = registerRun(service, playerId, LATCHED_HOOKS, "latched");
runner.finishRuns(playerId);
assertTrue(latchedRun.finished.get());
assertEquals("halted", latchedRun.abortReason);
}
private FellingRun registerRun(TreeFellerSVC service, UUID playerId, TreeFellerRunHooks hooks, String marker) {
Player player = mock(Player.class);
when(player.getUniqueId()).thenReturn(playerId);
World world = mock(World.class);
TreeCandidate candidate = new TreeCandidate(
null,
world,
player,
mock(ItemStack.class),
null,
new TreeMarkerTraversal.Position(0, 64, 0)
);
TreeClaim claim = new TreeClaim(UUID.randomUUID(), marker);
FellingRun run = new FellingRun(claim, candidate, 0, hooks, 0, new Location(world, 0D, 64D, 0D));
service.activeClaims.add(claim);
service.activeRuns.computeIfAbsent(playerId, ignored -> ConcurrentHashMap.newKeySet()).add(run);
return run;
}
}
@@ -0,0 +1,108 @@
package art.arcane.iris.core.service;
import art.arcane.iris.Iris;
import art.arcane.iris.core.link.WorldEditLink;
import art.arcane.volmlib.util.bukkit.WorldIdentity;
import art.arcane.volmlib.util.data.Cuboid;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.MockedStatic;
import java.util.List;
import java.util.Optional;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;
public class WandSVCTest {
private Iris previousPlugin;
private Player player;
private PlayerInventory inventory;
@Before
public void installPlugin() {
previousPlugin = Iris.instance;
Iris plugin = mock(Iris.class);
when(plugin.namespace()).thenReturn("iris");
Iris.instance = plugin;
player = mock(Player.class);
inventory = mock(PlayerInventory.class);
when(player.getInventory()).thenReturn(inventory);
}
@After
public void restorePlugin() {
Iris.instance = previousPlugin;
}
@Test
public void ignoresWorldEditSelectionWhileHoldingAnOrdinaryAxe() {
ItemStack axe = wandItem(false);
when(inventory.getItemInMainHand()).thenReturn(axe);
Cuboid selection = mock(Cuboid.class);
try (MockedStatic<WorldEditLink> worldEdit = mockStatic(WorldEditLink.class)) {
worldEdit.when(() -> WorldEditLink.getSelection(player)).thenReturn(selection);
assertFalse(WandSVC.isHoldingWand(player));
assertNull(WandSVC.getCuboid(player));
}
}
@Test
public void ignoresWorldEditSelectionWithAnEmptyHand() {
Cuboid selection = mock(Cuboid.class);
try (MockedStatic<WorldEditLink> worldEdit = mockStatic(WorldEditLink.class)) {
worldEdit.when(() -> WorldEditLink.getSelection(player)).thenReturn(selection);
assertFalse(WandSVC.isHoldingWand(player));
assertNull(WandSVC.getCuboid(player));
}
}
@Test
public void readsSelectionFromAnIrisMarkedWand() {
ItemStack wand = wandItem(true);
when(inventory.getItemInMainHand()).thenReturn(wand);
World world = mock(World.class);
try (MockedStatic<WorldIdentity> worlds = mockStatic(WorldIdentity.class)) {
worlds.when(() -> WorldIdentity.resolve("minecraft:overworld")).thenReturn(Optional.of(world));
assertTrue(WandSVC.isHoldingWand(player));
assertArrayEquals(new Location[]{new Location(world, 1D, 64D, 2D), new Location(world, 3D, 68D, 4D)},
WandSVC.getCuboid(player));
}
}
private ItemStack wandItem(boolean marked) {
ItemStack item = mock(ItemStack.class);
ItemMeta meta = mock(ItemMeta.class);
PersistentDataContainer data = mock(PersistentDataContainer.class);
when(item.getType()).thenReturn(marked ? Material.BLAZE_ROD : Material.WOODEN_AXE);
when(item.getItemMeta()).thenReturn(meta);
when(meta.getPersistentDataContainer()).thenReturn(data);
when(meta.getLore()).thenReturn(List.of("1,64,2 in minecraft:overworld", "3,68,4 in minecraft:overworld"));
if (marked) {
when(data.get(new NamespacedKey("iris", "wand"), PersistentDataType.BYTE)).thenReturn((byte) 1);
}
return item;
}
}