Mask gameplay overlays and page native Decisions
This commit is contained in:
parent
450fe08df6
commit
5d80713483
3 changed files with 106 additions and 14 deletions
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
DuneGit builds this provider as a separate development artifact. It requires Paper 26.2 build 135 and Java 25. Build `DuneRealmsGUI` first, then run `gradle -p DuneFullscreenPaper test jar` with Java 25 and Gradle 9.2.1.
|
||||
|
||||
The Java Decisions dashboard uses this provider only for UUIDs listed under `development.fullscreen-decisions-viewers` in the DunerealmsGUI config. Keep the allowlist empty on live servers. The existing menu path handles unsupported clients, unavailable providers and documents outside the current six-card development layout.
|
||||
The Java Decisions dashboard uses this provider only for UUIDs listed under `development.fullscreen-decisions-viewers` in the DunerealmsGUI config. Keep the allowlist empty on live servers. The existing menu path handles unsupported clients, unavailable providers and documents with invalid slots or outside the 54-card inventory limit.
|
||||
|
||||
The current visual prototype still exposes parts of the vanilla HUD and hand, along with the mount prompt.
|
||||
Larger documents retain their server-provided slots and show four entries per page. The mounted view can still expose vanilla overlays such as the experience bar, crosshair, chat and system notifications.
|
||||
|
|
|
|||
|
|
@ -18,9 +18,11 @@ import net.minecraft.world.entity.Entity;
|
|||
import net.minecraft.world.entity.decoration.*;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.saveddata.maps.*;
|
||||
import net.minecraft.world.scores.DisplaySlot;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.scoreboard.CraftScoreboard;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.*;
|
||||
import org.bukkit.event.player.*;
|
||||
|
|
@ -30,6 +32,8 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||
final class PaperDecisionsScene implements DecisionsViewTransport, Listener, AutoCloseable {
|
||||
private static final String INPUT = "dune_fullscreen_decisions";
|
||||
private static final int COLS = 11, ROWS = 9;
|
||||
private static final int CARDS_PER_PAGE = 4;
|
||||
private static final int PREVIOUS = -1, NEXT = -2, EMPTY = -3;
|
||||
private final Map<UUID, Scene> scenes = new HashMap<>();
|
||||
private final JavaPlugin plugin;
|
||||
// This range is private to each connection and reused on reopen to bound the client map cache.
|
||||
|
|
@ -40,6 +44,7 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
|
|||
}
|
||||
|
||||
private record Tile(MapId map, BufferedImage normal, BufferedImage focused) {}
|
||||
private record Page(int index, List<Card> cards) {}
|
||||
|
||||
private static final class Scene {
|
||||
final Player viewer;
|
||||
|
|
@ -51,7 +56,9 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
|
|||
final List<Entity> entities = new ArrayList<>();
|
||||
final Map<Integer, Tile> buttons = new HashMap<>();
|
||||
Integer focus;
|
||||
volatile Page page;
|
||||
int mountId;
|
||||
boolean presentationMasked;
|
||||
volatile boolean closed;
|
||||
boolean positioning;
|
||||
|
||||
|
|
@ -62,6 +69,7 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
|
|||
this.dismiss = dismiss;
|
||||
original = viewer.getLocation();
|
||||
gravity = viewer.hasGravity();
|
||||
page = page(document, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -72,7 +80,7 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
|
|||
@Override public boolean open(Player viewer, Document document, IntConsumer select, Runnable dismiss) {
|
||||
if (!(viewer instanceof CraftPlayer player) || !viewer.isOnline() || viewer.isDead() ||
|
||||
viewer.isInsideVehicle() || scenes.containsKey(viewer.getUniqueId()) ||
|
||||
document.cards().isEmpty() || document.cards().size() > 6) return false;
|
||||
!canPresent(document)) return false;
|
||||
var pipeline = player.getHandle().connection.connection.channel.pipeline();
|
||||
if (pipeline.get("packet_handler") == null || pipeline.get(INPUT) != null) return false;
|
||||
|
||||
|
|
@ -103,8 +111,7 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
|
|||
var handle = ((CraftPlayer) scene.viewer).getHandle();
|
||||
var level = handle.level();
|
||||
var origin = scene.original;
|
||||
var cards = scene.document.cards();
|
||||
BufferedImage art = artwork(cards);
|
||||
paint(scene, true);
|
||||
for (int row = 0; row < ROWS; row++) {
|
||||
for (int col = 0; col < COLS; col++) {
|
||||
var pos = new BlockPos(origin.getBlockX() + 5 - col, origin.getBlockY() + 11 - row, origin.getBlockZ() + 2);
|
||||
|
|
@ -114,11 +121,6 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
|
|||
var item = new net.minecraft.world.item.ItemStack(Items.FILLED_MAP);
|
||||
item.set(DataComponents.MAP_ID, map);
|
||||
frame.setItem(item, false, false);
|
||||
var image = art.getSubimage(col * 128, row * 128, 128, 128);
|
||||
Card card = cardAt(cards, row, col);
|
||||
var tile = new Tile(map, image, card == null ? image : focused(image));
|
||||
if (card != null && card.actionable()) scene.buttons.put(card.slot(), tile);
|
||||
pixels(scene, tile, false);
|
||||
add(scene, frame, Direction.NORTH.get3DDataValue());
|
||||
}
|
||||
}
|
||||
|
|
@ -133,23 +135,33 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
|
|||
scene.mountId = mount.getId();
|
||||
handle.connection.send(passengers(scene.mountId, handle.getId()));
|
||||
handle.connection.send(new ClientboundSetCameraPacket(camera));
|
||||
scene.presentationMasked = true;
|
||||
maskHands(handle, true);
|
||||
sidebar(scene.viewer, true);
|
||||
handle.connection.send(new ClientboundSetActionBarTextPacket(net.minecraft.network.chat.Component.empty()));
|
||||
var channel = handle.connection.connection.channel;
|
||||
var ids = scene.entities.stream().map(Entity::getId).collect(java.util.stream.Collectors.toUnmodifiableSet());
|
||||
channel.pipeline().addBefore("packet_handler", INPUT, new ChannelInboundHandlerAdapter() {
|
||||
private Integer focus;
|
||||
private Page previous;
|
||||
@Override public void channelRead(ChannelHandlerContext context, Object input) throws Exception {
|
||||
if (!scene.closed) {
|
||||
Page page = scene.page;
|
||||
if (page != previous) {
|
||||
previous = page;
|
||||
focus = null;
|
||||
}
|
||||
if (input instanceof ServerboundMovePlayerPacket move && move.hasRotation()) {
|
||||
Integer target = target(cards, move.getYRot(0), move.getXRot(0));
|
||||
Integer target = target(page.cards, move.getYRot(0), move.getXRot(0));
|
||||
if (!Objects.equals(target, focus)) {
|
||||
focus = target;
|
||||
Bukkit.getScheduler().runTask(plugin, () -> focus(scene, target));
|
||||
Bukkit.getScheduler().runTask(plugin, () -> { if (scene.page == page) focus(scene, target); });
|
||||
}
|
||||
}
|
||||
if (input instanceof ServerboundInteractPacket use && ids.contains(use.entityId())) {
|
||||
Integer target = focus;
|
||||
if (use.hand() == net.minecraft.world.InteractionHand.MAIN_HAND)
|
||||
Bukkit.getScheduler().runTask(plugin, () -> select(scene, target));
|
||||
Bukkit.getScheduler().runTask(plugin, () -> { if (scene.page == page) select(scene, target); });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -158,6 +170,76 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
|
|||
});
|
||||
}
|
||||
|
||||
private static void sidebar(Player viewer, boolean masked) {
|
||||
var scoreboard = ((CraftScoreboard) viewer.getScoreboard()).getHandle();
|
||||
var connection = ((CraftPlayer) viewer).getHandle().connection;
|
||||
for (DisplaySlot slot : DisplaySlot.values()) {
|
||||
if (slot != DisplaySlot.SIDEBAR && !slot.name().startsWith("TEAM_")) continue;
|
||||
var objective = scoreboard.getDisplayObjective(slot);
|
||||
if (objective != null) connection.send(new ClientboundSetDisplayObjectivePacket(slot, masked ? null : objective));
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean canPresent(Document document) {
|
||||
var cards = document.cards();
|
||||
return !cards.isEmpty() && cards.size() <= 54 &&
|
||||
cards.stream().allMatch(card -> card.slot() >= 0) &&
|
||||
cards.stream().map(Card::slot).distinct().count() == cards.size();
|
||||
}
|
||||
|
||||
private static Page page(Document document, int index) {
|
||||
var cards = document.cards();
|
||||
if (cards.size() <= 6) return new Page(0, cards);
|
||||
int start = index * CARDS_PER_PAGE;
|
||||
int end = Math.min(start + CARDS_PER_PAGE, cards.size());
|
||||
var visible = new ArrayList<>(cards.subList(start, end));
|
||||
while (visible.size() < CARDS_PER_PAGE) visible.add(new Card(EMPTY, "", List.of(), false));
|
||||
String pageNumber = "Page " + (index + 1) + " / " + ((cards.size() + CARDS_PER_PAGE - 1) / CARDS_PER_PAGE);
|
||||
visible.add(new Card(PREVIOUS, "Previous", List.of(pageNumber), index > 0));
|
||||
visible.add(new Card(NEXT, "Next", List.of(pageNumber), end < cards.size()));
|
||||
return new Page(index, List.copyOf(visible));
|
||||
}
|
||||
|
||||
private void paint(Scene scene, boolean initial) {
|
||||
var cards = scene.page.cards;
|
||||
BufferedImage art = artwork(cards);
|
||||
scene.buttons.clear();
|
||||
scene.focus = null;
|
||||
for (int row = 0; row < ROWS; row++) {
|
||||
for (int col = 0; col < COLS; col++) {
|
||||
if (!initial && (row < 3 || row > 5 || (col != 4 && col != 6))) continue;
|
||||
var map = new MapId(FIRST_SCENE_MAP + row * COLS + col);
|
||||
var image = art.getSubimage(col * 128, row * 128, 128, 128);
|
||||
var card = cardAt(cards, row, col);
|
||||
var tile = new Tile(map, image, card == null || !card.actionable() ? image : focused(image));
|
||||
if (card != null && card.actionable()) scene.buttons.put(card.slot(), tile);
|
||||
pixels(scene, tile, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void maskHands(net.minecraft.server.level.ServerPlayer player, boolean masked) {
|
||||
var data = player.getEntityData().packAll();
|
||||
if (data != null) {
|
||||
for (var value : data) {
|
||||
if (value.id() != 0 || !(value.value() instanceof Byte flags)) continue;
|
||||
var display = new net.minecraft.network.syncher.SynchedEntityData.DataValue<>(
|
||||
value.id(), net.minecraft.network.syncher.EntityDataSerializers.BYTE,
|
||||
masked ? (byte) (flags | 0x20) : flags);
|
||||
player.connection.send(new ClientboundSetEntityDataPacket(player.getId(), List.of(display)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
int offhand = net.minecraft.world.entity.player.Inventory.SLOT_OFFHAND;
|
||||
for (int slot = 0; slot < 9; slot++) sendHandSlot(player, slot, masked);
|
||||
sendHandSlot(player, offhand, masked);
|
||||
}
|
||||
|
||||
private static void sendHandSlot(net.minecraft.server.level.ServerPlayer player, int slot, boolean masked) {
|
||||
var item = masked ? net.minecraft.world.item.ItemStack.EMPTY : player.getInventory().getItem(slot).copy();
|
||||
player.connection.send(new ClientboundSetPlayerInventoryPacket(slot, item));
|
||||
}
|
||||
|
||||
private void add(Scene scene, Entity entity, int extra) {
|
||||
var connection = ((CraftPlayer) scene.viewer).getHandle().connection;
|
||||
scene.entities.add(entity);
|
||||
|
|
@ -213,6 +295,11 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
|
|||
|
||||
private void select(Scene scene, Integer slot) {
|
||||
if (scene.closed || slot == null || !scene.buttons.containsKey(slot)) return;
|
||||
if (slot == PREVIOUS || slot == NEXT) {
|
||||
scene.page = page(scene.document, scene.page.index + (slot == NEXT ? 1 : -1));
|
||||
paint(scene, false);
|
||||
return;
|
||||
}
|
||||
finish(scene, true, false);
|
||||
scene.select.accept(slot);
|
||||
}
|
||||
|
|
@ -258,6 +345,10 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
|
|||
try {
|
||||
if (pipeline.get(INPUT) != null) pipeline.remove(INPUT);
|
||||
if (viewer.isOnline() && !scene.entities.isEmpty()) {
|
||||
if (scene.presentationMasked) {
|
||||
maskHands(handle, false);
|
||||
sidebar(viewer, false);
|
||||
}
|
||||
connection.send(new ClientboundSetCameraPacket(handle));
|
||||
if (scene.mountId != 0) connection.send(passengers(scene.mountId));
|
||||
connection.send(new ClientboundRemoveEntitiesPacket(scene.entities.stream().mapToInt(Entity::getId).toArray()));
|
||||
|
|
@ -282,6 +373,7 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
|
|||
draw.drawString("YOUR DECISIONS", 523, 372);
|
||||
for (int index = 0; index < cards.size(); index++) {
|
||||
Card card = cards.get(index);
|
||||
if (card.slot() == EMPTY) continue;
|
||||
int x = (index % 2 == 0 ? 4 : 6) * 128;
|
||||
int y = (3 + index / 2) * 128;
|
||||
draw.setColor(card.actionable() ? new Color(52, 93, 107) : new Color(55, 63, 66));
|
||||
|
|
|
|||
|
|
@ -308,6 +308,7 @@ final class QuestMenus implements Listener {
|
|||
Map<Integer,Runnable> visibleActions=new HashMap<>();
|
||||
for(var card:cards)if(card.actionable())visibleActions.put(card.slot(),screen.actions.get(card.slot()));
|
||||
var callbacks=Map.copyOf(visibleActions);
|
||||
player.closeInventory();
|
||||
var world=player.getWorld().getUID();
|
||||
try{
|
||||
if(!transport.open(player,document,slot->{
|
||||
|
|
@ -321,7 +322,6 @@ final class QuestMenus implements Listener {
|
|||
plugin.getLogger().warning("Development Decisions view unavailable: "+failure.getClass().getSimpleName());
|
||||
return false;
|
||||
}
|
||||
player.closeInventory();
|
||||
screen.gate.markFormVisible(world);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff