forked from SteamWar/SteamWar
Fix collection of rendering issues
This commit is contained in:
@@ -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<CursorMode> allowedCursorModes;
|
||||
private final Material highlightMaterial;
|
||||
private final TriConsumer<Location, Optional<REntity>, Action> onClick;
|
||||
private final ClickHandler onClick;
|
||||
private final BiConsumer<Location, Optional<REntity>> onRender;
|
||||
|
||||
|
||||
public Cursor(REntityServer targetServer, Player owner, Material highlightMaterial, Material cursorMaterial, List<CursorMode> allowedModes, TriConsumer<Location, Optional<REntity>, Action> onClick) {
|
||||
public Cursor(REntityServer targetServer, Player owner, Material highlightMaterial, Material cursorMaterial, List<CursorMode> allowedModes, ClickHandler onClick) {
|
||||
this(targetServer, owner, highlightMaterial, cursorMaterial, allowedModes, onClick, (location, hitEntity) -> {
|
||||
});
|
||||
}
|
||||
|
||||
public Cursor(REntityServer targetServer, Player owner, Material highlightMaterial, Material cursorMaterial, List<CursorMode> allowedModes, TriConsumer<Location, Optional<REntity>, Action> onClick, BiConsumer<Location, Optional<REntity>> onRender) {
|
||||
public Cursor(REntityServer targetServer, Player owner, Material highlightMaterial, Material cursorMaterial, List<CursorMode> allowedModes, ClickHandler onClick, BiConsumer<Location, Optional<REntity>> 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<Player, RayTraceUtils.RRayTraceResult, Vector> positionTransform;
|
||||
private final Predicate<Player> 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<Player, RayTraceUtils.RRayTraceResult, Vector> positionTransform;
|
||||
private final Predicate<Player> isActive;
|
||||
@FunctionalInterface
|
||||
public interface ClickHandler {
|
||||
void onClick(Location location, Optional<REntity> hitEntity, Action action);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user