Fix SteamEditWand

This commit is contained in:
2026-09-01 11:14:30 +02:00
parent ece12df0bc
commit 362468e756
3 changed files with 20 additions and 15 deletions
@@ -48,6 +48,7 @@ public class SteamEditSelectAdjacent {
private LinkedHashSet<Location> frontier = new LinkedHashSet<>(); private LinkedHashSet<Location> frontier = new LinkedHashSet<>();
public SteamEditSelectAdjacent(Location origin) { public SteamEditSelectAdjacent(Location origin) {
// TODO: Fix the flood fill algorithm!
min = origin.clone(); min = origin.clone();
max = origin.clone(); max = origin.clone();
frontier.add(origin); frontier.add(origin);
@@ -134,7 +134,7 @@ public class SteamEditWand implements Listener {
private Packet<?> leftClick(Player player, Packet<?> packet) { private Packet<?> leftClick(Player player, Packet<?> packet) {
if (noWand(player)) return packet; if (noWand(player)) return packet;
if (player.getOpenInventory().getType() != InventoryType.CRAFTING) return packet; if (player.getOpenInventory().getType() != InventoryType.CREATIVE) return packet;
double distance = WorldEditRendererCUIEditor.Type.CURSOR.getWidth(player).blocks; double distance = WorldEditRendererCUIEditor.Type.CURSOR.getWidth(player).blocks;
RayTraceResult result = player.rayTraceBlocks(distance, FluidCollisionMode.NEVER); RayTraceResult result = player.rayTraceBlocks(distance, FluidCollisionMode.NEVER);
if (result == null) return packet; if (result == null) return packet;
@@ -373,7 +373,7 @@ public class SteamEditWand implements Listener {
if (noWand(player)) return packet; if (noWand(player)) return packet;
if (packet.getAction() != ServerboundPlayerActionPacket.Action.SWAP_ITEM_WITH_OFFHAND) return packet; if (packet.getAction() != ServerboundPlayerActionPacket.Action.SWAP_ITEM_WITH_OFFHAND) return packet;
Bukkit.getScheduler().runTask(Core.getInstance(), () -> { Bukkit.getScheduler().runTask(Core.getInstance(), () -> {
WorldEditRendererCUIEditor.open(player); WorldEditRendererCUIEditor.open(player, true);
}); });
return null; return null;
} }
@@ -126,9 +126,9 @@ public class WorldEditRendererCUIEditor implements Listener {
command = new Command(); command = new Command();
} }
public static void open(Player player) { public static void open(Player player, boolean steamEditWand) {
if (command == null) return; if (command == null) return;
command.cuiEditor(player); command.cuiEditor(player, steamEditWand);
} }
private static class Command extends SWCommand { private static class Command extends SWCommand {
@@ -139,10 +139,14 @@ public class WorldEditRendererCUIEditor implements Listener {
@Register @Register
public void cuiEditor(Player player) { public void cuiEditor(Player player) {
cuiEditor(player, false);
}
public void cuiEditor(Player player, boolean steamEditWand) {
SWInventory inv = new SWInventory(player, 9 * 2, Core.MESSAGE.parse("WORLDEDIT_CUI_TITLE", player)); SWInventory inv = new SWInventory(player, 9 * 2, Core.MESSAGE.parse("WORLDEDIT_CUI_TITLE", player));
if (SteamEdit.isInitialized()) { if (SteamEdit.isInitialized() && steamEditWand) {
setElement(inv, player, 1, "WORLDEDIT_CUI_SELECTION", Type.SELECTION); setElement(inv, player, true, 1, "WORLDEDIT_CUI_SELECTION", Type.SELECTION);
setElement(inv, player, 2, "WORLDEDIT_CUI_CLIPBOARD", Type.CLIPBOARD); setElement(inv, player, true, 2, "WORLDEDIT_CUI_CLIPBOARD", Type.CLIPBOARD);
setCursor(inv, player, 3, "WORLDEDIT_CUI_CURSOR"); setCursor(inv, player, 3, "WORLDEDIT_CUI_CURSOR");
inv.setItem(5, new SWItem(Material.PAPER, "WORLDEDIT_CUI_TOOL_COPY").setLore("WORLDEDIT_CUI_TOOL_COPY_LORE").translate(player, Core.MESSAGE).getItemStack(), click -> { inv.setItem(5, new SWItem(Material.PAPER, "WORLDEDIT_CUI_TOOL_COPY").setLore("WORLDEDIT_CUI_TOOL_COPY_LORE").translate(player, Core.MESSAGE).getItemStack(), click -> {
player.performCommand("/copy"); player.performCommand("/copy");
@@ -161,18 +165,18 @@ public class WorldEditRendererCUIEditor implements Listener {
inv.setItem(15, new SWItem(Material.STRUCTURE_VOID, "WORLDEDIT_CUI_TOOL_SOON").translate(player, Core.MESSAGE).getItemStack(), click -> {}); inv.setItem(15, new SWItem(Material.STRUCTURE_VOID, "WORLDEDIT_CUI_TOOL_SOON").translate(player, Core.MESSAGE).getItemStack(), click -> {});
inv.setItem(16, new SWItem(Material.STRUCTURE_VOID, "WORLDEDIT_CUI_TOOL_SOON").translate(player, Core.MESSAGE).getItemStack(), click -> {}); inv.setItem(16, new SWItem(Material.STRUCTURE_VOID, "WORLDEDIT_CUI_TOOL_SOON").translate(player, Core.MESSAGE).getItemStack(), click -> {});
} else { } else {
setElement(inv, player, 3, "WORLDEDIT_CUI_SELECTION", Type.SELECTION); setElement(inv, player, false, 3, "WORLDEDIT_CUI_SELECTION", Type.SELECTION);
setElement(inv, player, 5, "WORLDEDIT_CUI_CLIPBOARD", Type.CLIPBOARD); setElement(inv, player, false, 5, "WORLDEDIT_CUI_CLIPBOARD", Type.CLIPBOARD);
} }
inv.open(); inv.open();
} }
private void setElement(SWInventory inv, Player player, int index, String uiName, Type type) { private void setElement(SWInventory inv, Player player, boolean steamEditWand, int index, String uiName, Type type) {
Material material = type.getMaterial(player); Material material = type.getMaterial(player);
Width width = type.getWidth(player); Width width = type.getWidth(player);
inv.setItem(index, new SWItem(material, Core.MESSAGE.parse("WORLDEDIT_CUI_MATERIAL_NAME", player, Core.MESSAGE.parse(uiName, player)), Arrays.asList(Core.MESSAGE.parse("WORLDEDIT_CUI_MATERIAL_CLICK", player)), false, click -> { inv.setItem(index, new SWItem(material, Core.MESSAGE.parse("WORLDEDIT_CUI_MATERIAL_NAME", player, Core.MESSAGE.parse(uiName, player)), Arrays.asList(Core.MESSAGE.parse("WORLDEDIT_CUI_MATERIAL_CLICK", player)), false, click -> {
cuiMaterial(player, uiName, type, material); cuiMaterial(player, steamEditWand, uiName, type, material);
})); }));
List<String> lore = new ArrayList<>(); List<String> lore = new ArrayList<>();
@@ -187,7 +191,7 @@ public class WorldEditRendererCUIEditor implements Listener {
} }
SWItem lightItem = new SWItem(Material.LIGHT, Core.MESSAGE.parse("WORLDEDIT_CUI_WIDTH_NAME", player, Core.MESSAGE.parse(uiName, player)), lore, false, click -> { SWItem lightItem = new SWItem(Material.LIGHT, Core.MESSAGE.parse("WORLDEDIT_CUI_WIDTH_NAME", player, Core.MESSAGE.parse(uiName, player)), lore, false, click -> {
type.setWidth(player, Width.values()[(width.ordinal() + 1) % Width.values().length]); type.setWidth(player, Width.values()[(width.ordinal() + 1) % Width.values().length]);
setElement(inv, player, index, uiName, type); setElement(inv, player, steamEditWand, index, uiName, type);
}); });
ItemMeta itemMeta = lightItem.getItemMeta(); ItemMeta itemMeta = lightItem.getItemMeta();
Light light = (Light) Material.LIGHT.createBlockData(); Light light = (Light) Material.LIGHT.createBlockData();
@@ -202,7 +206,7 @@ public class WorldEditRendererCUIEditor implements Listener {
Width width = Type.CURSOR.getWidth(player); Width width = Type.CURSOR.getWidth(player);
inv.setItem(index, new SWItem(material, Core.MESSAGE.parse("WORLDEDIT_CUI_MATERIAL_NAME", player, Core.MESSAGE.parse(uiName, player)), Arrays.asList(Core.MESSAGE.parse("WORLDEDIT_CUI_MATERIAL_CLICK", player)), false, click -> { inv.setItem(index, new SWItem(material, Core.MESSAGE.parse("WORLDEDIT_CUI_MATERIAL_NAME", player, Core.MESSAGE.parse(uiName, player)), Arrays.asList(Core.MESSAGE.parse("WORLDEDIT_CUI_MATERIAL_CLICK", player)), false, click -> {
cuiMaterial(player, uiName, Type.CURSOR, material); cuiMaterial(player, true, uiName, Type.CURSOR, material);
})); }));
List<String> lore = new ArrayList<>(); List<String> lore = new ArrayList<>();
@@ -224,14 +228,14 @@ public class WorldEditRendererCUIEditor implements Listener {
private final Material[] materials = {Material.WHITE_CONCRETE, Material.LIGHT_GRAY_CONCRETE, Material.GRAY_CONCRETE, Material.BLACK_CONCRETE, Material.BROWN_CONCRETE, Material.RED_CONCRETE, Material.ORANGE_CONCRETE, Material.YELLOW_CONCRETE, Material.LIME_CONCRETE, Material.GREEN_CONCRETE, Material.CYAN_CONCRETE, Material.LIGHT_BLUE_CONCRETE, Material.BLUE_CONCRETE, Material.PURPLE_CONCRETE, Material.MAGENTA_CONCRETE, Material.PINK_CONCRETE, null, Material.BARRIER}; private final Material[] materials = {Material.WHITE_CONCRETE, Material.LIGHT_GRAY_CONCRETE, Material.GRAY_CONCRETE, Material.BLACK_CONCRETE, Material.BROWN_CONCRETE, Material.RED_CONCRETE, Material.ORANGE_CONCRETE, Material.YELLOW_CONCRETE, Material.LIME_CONCRETE, Material.GREEN_CONCRETE, Material.CYAN_CONCRETE, Material.LIGHT_BLUE_CONCRETE, Material.BLUE_CONCRETE, Material.PURPLE_CONCRETE, Material.MAGENTA_CONCRETE, Material.PINK_CONCRETE, null, Material.BARRIER};
private void cuiMaterial(Player player, String subMenu, Type type, Material currentSelection) { private void cuiMaterial(Player player, boolean steamEditWand, String subMenu, Type type, Material currentSelection) {
SWInventory inv = new SWInventory(player, 9 * 2, Core.MESSAGE.parse("WORLDEDIT_CUI_TITLE_SUBMENU", player, Core.MESSAGE.parse(subMenu, player))); SWInventory inv = new SWInventory(player, 9 * 2, Core.MESSAGE.parse("WORLDEDIT_CUI_TITLE_SUBMENU", player, Core.MESSAGE.parse(subMenu, player)));
for (int i = 0; i < materials.length; i++) { for (int i = 0; i < materials.length; i++) {
Material material = materials[i]; Material material = materials[i];
if (material == null) continue; if (material == null) continue;
inv.setItem(i, new SWItem(material, "", Collections.emptyList(), material == currentSelection, click -> { inv.setItem(i, new SWItem(material, "", Collections.emptyList(), material == currentSelection, click -> {
type.setMaterial(player, material); type.setMaterial(player, material);
cuiEditor(player); cuiEditor(player, steamEditWand);
})); }));
} }
inv.open(); inv.open();