From 9bbbab9d4b7e1575aa1f493814a55a35fd058cd0 Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Tue, 2 Jun 2026 21:33:31 +0200 Subject: [PATCH] Fix collection of rendering issues --- .../features/simulator/SimulatorCursor.java | 28 +++++++-- .../src/de/steamwar/cursor/Cursor.java | 57 +++++++++++++++---- .../de/steamwar/cursor/CursorListener.java | 8 +++ 3 files changed, 78 insertions(+), 15 deletions(-) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java index 8f841721..1c44e35d 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java @@ -53,6 +53,8 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryDragEvent; import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerItemHeldEvent; import org.bukkit.event.player.PlayerJoinEvent; @@ -83,22 +85,40 @@ public class SimulatorCursor implements Listener { return isSimulatorItem(player.getInventory().getItemInMainHand()) || isSimulatorItem(player.getInventory().getItemInOffHand()); } + private static void scheduleCursorUpdate(Player player) { + BauSystem.runTaskLater(BauSystem.getInstance(), () -> calcCursor(player), 1); + } + @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { if (!Permission.BUILD.hasPermission(event.getPlayer())) return; - Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> calcCursor(event.getPlayer()), 0); + scheduleCursorUpdate(event.getPlayer()); } @EventHandler public void onPlayerDropItem(PlayerDropItemEvent event) { if (!Permission.BUILD.hasPermission(event.getPlayer())) return; - calcCursor(event.getPlayer()); + scheduleCursorUpdate(event.getPlayer()); } @EventHandler public void onPlayerItemHeld(PlayerItemHeldEvent event) { if (!Permission.BUILD.hasPermission(event.getPlayer())) return; - Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> calcCursor(event.getPlayer()), 1); + scheduleCursorUpdate(event.getPlayer()); + } + + @EventHandler + public void onInventoryClick(InventoryClickEvent event) { + if (!(event.getWhoClicked() instanceof Player player)) return; + if (!Permission.BUILD.hasPermission(player)) return; + scheduleCursorUpdate(player); + } + + @EventHandler + public void onInventoryDrag(InventoryDragEvent event) { + if (!(event.getWhoClicked() instanceof Player player)) return; + if (!Permission.BUILD.hasPermission(player)) return; + scheduleCursorUpdate(player); } @EventHandler @@ -221,7 +241,7 @@ public class SimulatorCursor implements Listener { @Getter @AllArgsConstructor public enum CursorType { - TNT(Material.TNT, Material.GUNPOWDER, List.of(Cursor.CursorMode.FREE), "TNT", vector -> new TNTElement(vector).add(new TNTPhase())), + TNT(Material.TNT, Material.GUNPOWDER, List.of(Cursor.CursorMode.FREE, Cursor.CursorMode.SURFACE_ALIGNED), "TNT", vector -> new TNTElement(vector).add(new TNTPhase())), REDSTONE_BLOCK(Material.REDSTONE_BLOCK, Material.REDSTONE, List.of(Cursor.CursorMode.BLOCK_ALIGNED), "Redstone Block", vector -> new RedstoneElement(vector).add(new RedstonePhase())), OBSERVER(Material.OBSERVER, Material.QUARTZ, List.of(Cursor.CursorMode.BLOCK_ALIGNED), "Observer", vector -> new ObserverElement(vector).add(new ObserverPhase())), ; diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/cursor/Cursor.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/cursor/Cursor.java index 86973cc5..73e2313c 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/cursor/Cursor.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/cursor/Cursor.java @@ -7,7 +7,6 @@ import de.steamwar.entity.RFallingBlockEntity; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; -import org.apache.logging.log4j.util.TriConsumer; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -44,16 +43,16 @@ public class Cursor implements SWPlayer.Component { @Setter private List allowedCursorModes; private final Material highlightMaterial; - private final TriConsumer, Action> onClick; + private final ClickHandler onClick; private final BiConsumer> onRender; - public Cursor(REntityServer targetServer, Player owner, Material highlightMaterial, Material cursorMaterial, List allowedModes, TriConsumer, Action> onClick) { + public Cursor(REntityServer targetServer, Player owner, Material highlightMaterial, Material cursorMaterial, List allowedModes, ClickHandler onClick) { this(targetServer, owner, highlightMaterial, cursorMaterial, allowedModes, onClick, (location, hitEntity) -> { }); } - public Cursor(REntityServer targetServer, Player owner, Material highlightMaterial, Material cursorMaterial, List allowedModes, TriConsumer, Action> onClick, BiConsumer> onRender) { + public Cursor(REntityServer targetServer, Player owner, Material highlightMaterial, Material cursorMaterial, List allowedModes, ClickHandler onClick, BiConsumer> onRender) { this.targetServer = targetServer; this.owner = owner; this.highlightMaterial = highlightMaterial; @@ -118,7 +117,7 @@ public class Cursor implements SWPlayer.Component { protected void handlePlayerClick(Action clickAction) { renderDeduplicated(); - onClick.accept(this.cursorLocation, Optional.ofNullable(this.hitEntity), clickAction); + onClick.onClick(this.cursorLocation, Optional.ofNullable(this.hitEntity), clickAction); } @Override @@ -161,7 +160,43 @@ public class Cursor implements SWPlayer.Component { return pos; }, Player::isSneaking), - BLOCK_ALIGNED(0, (player, rayTraceResult) -> { + SURFACE_ALIGNED(2, (player, rayTraceResult) -> { + Vector hitPosition = rayTraceResult.getHitPosition().clone(); + Vector pos = blockAlignedPosition(rayTraceResult); + BlockFace face = rayTraceResult.getHitBlockFace(); + + if (face != null && face != BlockFace.SELF) { + switch (face) { + case UP: + pos.setY(hitPosition.getY()); + break; + case DOWN: + pos.setY(hitPosition.getY() + face.getModY()); + break; + case EAST: + case WEST: + pos.setX(hitPosition.getX() + face.getModX() * 0.5); + break; + case NORTH: + case SOUTH: + pos.setZ(hitPosition.getZ() + face.getModZ() * 0.5); + break; + default: + break; + } + } + + return pos; + }, (player) -> true), + + BLOCK_ALIGNED(0, (player, rayTraceResult) -> blockAlignedPosition(rayTraceResult), (player) -> true); + + + private final int priority; + private final BiFunction positionTransform; + private final Predicate isActive; + + private static Vector blockAlignedPosition(RayTraceUtils.RRayTraceResult rayTraceResult) { Vector pos = rayTraceResult.getHitPosition(); BlockFace face = rayTraceResult.getHitBlockFace(); @@ -195,11 +230,11 @@ public class Cursor implements SWPlayer.Component { } pos.setZ(pos.getBlockZ() + 0.5); return pos; - }, (player) -> true); + } + } - - private final int priority; - private final BiFunction positionTransform; - private final Predicate isActive; + @FunctionalInterface + public interface ClickHandler { + void onClick(Location location, Optional hitEntity, Action action); } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/cursor/CursorListener.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/cursor/CursorListener.java index 47f0a91d..2d7b438f 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/cursor/CursorListener.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/cursor/CursorListener.java @@ -1,11 +1,13 @@ package de.steamwar.cursor; import com.comphenix.tinyprotocol.TinyProtocol; +import de.steamwar.core.Core; import de.steamwar.core.SWPlayer; import de.steamwar.linkage.Linked; import lombok.Getter; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -27,6 +29,12 @@ public class CursorListener implements Listener { TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.Pos.class, this::updateCursorFromPacket); TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.Rot.class, this::updateCursorFromPacket); TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.PosRot.class, this::updateCursorFromPacket); + + Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> { + SWPlayer.allWithSingleComponent(Cursor.class) + .map(SWPlayer.SWPlayerWithComponent::getComponent) + .forEach(Cursor::renderDeduplicated); + }, 1, 1); } public Packet updateCursorFromPacket(Player player, Packet packet) {