Add direct catalog item egg and enchantment book delivery

This commit is contained in:
2026-09-12 14:19:03 +03:00
parent 5541d291e4
commit ce96870a1c
8 changed files with 30 additions and 4 deletions
+9
View File
@@ -0,0 +1,9 @@
# Быстрая выдача
Справа в строке предмета, блока, моба или зачарования доступно действие «Выдать». Оно не открывает настройки и не сохраняет черновики. Предметы выдаются по одному, мобы — яйцом призыва, зачарования — книгой первого уровня. Другой уровень книги можно выбрать в настройках зачарования.
Для групп и навыков выдача не предлагается. Клик по названию открывает редактор, стрелка раскрывает группу. Результат или причина отказа отображается в строке состояния. Все действия проверяются сервером, включая права администратора и новые ограничения `editor.give`.
В основных свойствах предмета также доступно поле «Отдельная иконка предмета» (`itemTexture`). Оно не изменяет текстуру установленного блока.
JAR AstraPlusEditor устанавливается только на клиент администратора.
@@ -32,6 +32,8 @@ public final class ContentFields {
fields.add(FormField.text("asset", "Путь к текстуре / модели", "Например minecraft:item/diamond_sword. Без расширения файла.",
() -> draft.text(draft.text("", "texture"), "model"),
value -> draft.model(value.trim(), !draft.get("model").isJsonNull())));
fields.add(FormField.text("itemTexture", "Отдельная иконка предмета", "Текстура автоматически создаваемой предметной модели. Пусто — стандартная; вид блока в мире не меняется.",
() -> draft.text("", "itemTexture"), value -> { if (value.isBlank()) draft.set(null, "itemTexture"); else draft.string(value.trim(), "itemTexture"); }));
if (!draft.block()) fields.add(new FormField("handheld", "Положение инструмента в руке", "Для простой автоматически созданной модели.",
() -> draft.text("false", "handheld").equals("true") ? "Да" : "Нет",
value -> draft.bool(value.equals("Да"), "handheld"), List.of("Нет", "Да"), true));
@@ -11,6 +11,8 @@ import net.minecraft.network.chat.Component;
public final class ChoiceList extends ObjectSelectionList<ChoiceList.Row> {
private final Consumer<String> selected;
private Consumer<String> give;
public void quickGive(Consumer<String> action) { give = action; }
public ChoiceList(Minecraft minecraft, int x, int y, int width, int height, Consumer<String> selected) {
super(minecraft, width, height, y, 26);
@@ -34,12 +36,14 @@ public final class ChoiceList extends ObjectSelectionList<ChoiceList.Row> {
@Override public void extractContent(GuiGraphicsExtractor graphics, int mouseX, int mouseY, boolean hovered, float a) {
if (hovered) graphics.fill(getX(), getY(), getX() + getWidth(), getY() + getHeight(), 0x80365962);
graphics.text(minecraft.font, minecraft.font.plainSubstrByWidth(value, getContentWidth()),
if (give != null) graphics.text(minecraft.font, "Выдать", getContentX() + getContentWidth() - 54, getContentY() + 6, 0xFF8FE0B0);
graphics.text(minecraft.font, minecraft.font.plainSubstrByWidth(value, Math.max(0, getContentWidth() - (give == null ? 0 : 60))),
getContentX() + 3, getContentY() + 6, 0xFFE4EBED);
}
@Override public boolean mouseClicked(MouseButtonEvent event, boolean doubleClick) {
if (event.button() != 0) return false;
if (give != null && event.x() >= getContentX() + getContentWidth() - 60) { give.accept(value); return true; }
setSelected(this);
selected.accept(value);
return true;
@@ -33,6 +33,7 @@ public final class ContentBrowserScreen extends EditorScreen {
search.setResponder(value -> { query = value; searchDelay = 6; page = 0; });
list = addRenderableWidget(new ContentList(minecraft, 12, 92, width - 24, Math.max(25, height - 193), this::load));
list.values(rows);
list.quickGive(id -> { var request = new JsonObject(); request.addProperty("id", id); connection.request("give", request, this::reply); });
int row = height - 94;
int part = Math.max(50, (width - 48) / 4);
button("+ Предмет", 12, row, part, () -> create(false));
@@ -15,6 +15,8 @@ import online.astradev.plus.editor.client.CatalogIcon;
/** Inventory icons, names and identifiers stay readable independently in the content catalog. */
public final class ContentList extends ObjectSelectionList<ContentList.Row> {
private final Consumer<String> selected;
private Consumer<String> give;
public void quickGive(Consumer<String> action) { give = action; }
public ContentList(Minecraft minecraft, int x, int y, int width, int height, Consumer<String> selected) {
super(minecraft, width, height, y, 36);
@@ -54,7 +56,8 @@ public final class ContentList extends ObjectSelectionList<ContentList.Row> {
var stack = icon.stack();
if (stack.isEmpty()) graphics.text(minecraft.font, "?", x + 10, y + 13, 0xFF91A6B2);
else graphics.item(stack, x + 5, y + 9);
int textX = x + 34, textWidth = Math.max(0, getContentWidth() - 42);
int textX = x + 34, textWidth = Math.max(0, getContentWidth() - 42 - (give == null ? 0 : 60));
if (give != null) graphics.text(minecraft.font, "Выдать", getContentX() + getContentWidth() - 54, y + 12, 0xFF8FE0B0);
graphics.text(minecraft.font, minecraft.font.plainSubstrByWidth(name, textWidth), textX, y + 5, 0xFFE5EFF1);
graphics.text(minecraft.font, minecraft.font.plainSubstrByWidth(kind + " " + id, textWidth), textX, y + 19, 0xFF9AAFB8);
if (hovered) {
@@ -66,6 +69,7 @@ public final class ContentList extends ObjectSelectionList<ContentList.Row> {
@Override public boolean mouseClicked(MouseButtonEvent event, boolean doubleClick) {
if (event.button() != 0) return false;
if (give != null && event.x() >= getContentX() + getContentWidth() - 60) { give.accept(id); return true; }
setSelected(this);
selected.accept(selectionId);
return true;
@@ -24,6 +24,7 @@ public final class EnchantmentBrowserScreen extends EditorScreen {
search.setResponder(value -> { query = value; page = 0; delay = 6; });
list = addRenderableWidget(new ChoiceList(minecraft, 12, 92, width - 24, Math.max(26, height - 193), label -> load(rows.get(label)))); list.values(rows.keySet().stream().toList());
button("+ Зачарование", 12, height - 94, 140, this::create);
list.quickGive(label -> { var request = new JsonObject(); request.addProperty("id", rows.get(label)); request.addProperty("level", 1); connection.request("enchantment_book", request, this::reply); });
button("Обновить", width - 132, height - 94, 120, this::refresh);
button("←", 12, height - 27, 30, () -> { if (page > 0) { page--; refresh(); } });
button("→", 48, height - 27, 30, () -> { if (page + 1 < pages) { page++; refresh(); } });
@@ -44,7 +45,7 @@ public final class EnchantmentBrowserScreen extends EditorScreen {
+ (!row.get("enabled").getAsBoolean() ? " Выключено" : "") + (row.get("pending").getAsBoolean() ? " Нужен перезапуск" : ""), id);
}
page = response.get("page").getAsInt(); pages = response.get("pages").getAsInt(); list.values(rows.keySet().stream().toList());
status("Страница " + (page + 1) + " / " + pages + ". Откройте зачарование для настройки эффектов и получения.", false);
status("Страница " + (page + 1) + " / " + pages + ". «Выдать» — книга I уровня. Нажмите название для настройки.", false);
});
}
private void load(String id) {
@@ -35,6 +35,7 @@ public final class MobBrowserScreen extends EditorScreen {
} else mobList = addRenderableWidget(new MobList(minecraft, 12, 92, width - 24,
Math.max(40, height - 158), connection, groups, (id, isSkill) -> load(id, isSkill)));
button(skill ? "+ Навык" : "+ Моб", 12, height - 27, 60, this::create);
if (!skill) mobList.quickGive(id -> { var request = new JsonObject(); request.addProperty("id", id); connection.request("mob_egg", request, this::reply); });
button("Обновить", 78, height - 27, 72, this::refresh);
previous = button("←", 156, height - 27, 24, () -> { if (page > 0) { page--; refresh(); } }); previous.active = page > 0;
next = button("→", 186, height - 27, 24, () -> { if (page + 1 < pages) { page++; refresh(); } }); next.active = page + 1 < pages;
@@ -26,6 +26,8 @@ public final class MobList extends ObjectSelectionList<MobList.Row> {
private final EditorConnection connection;
private final BiConsumer<String, Boolean> selected;
private final MobGroups groups;
private java.util.function.Consumer<String> give;
public void quickGive(java.util.function.Consumer<String> action) { give = action; }
private final Map<String, Thumbnail> models = new HashMap<>();
private int pending;
@@ -135,7 +137,8 @@ public final class MobList extends ObjectSelectionList<MobList.Row> {
graphics.text(minecraft.font, "?", x + iconSize / 2 - 4, y + iconSize / 2 - 2, 0xFF91A6B2);
}
}
int textX = x + iconSize + 8, textWidth = Math.max(0, getContentWidth() - 34 - iconSize - inset);
int textX = x + iconSize + 8, textWidth = Math.max(0, getContentWidth() - 34 - iconSize - inset - (give == null ? 0 : 60));
if (give != null && !data.skill() && !data.section()) graphics.text(minecraft.font, "Выдать", getContentX() + getContentWidth() - 54, y + 12, 0xFF8FE0B0);
graphics.text(minecraft.font, minecraft.font.plainSubstrByWidth(name, textWidth), textX, y + 5, 0xFFE5EFF1);
graphics.text(minecraft.font, minecraft.font.plainSubstrByWidth(id, textWidth), textX, y + 5 + lineSpacing, 0xFF9AAFB8);
String role = MobGroups.label(data.role());
@@ -152,6 +155,7 @@ public final class MobList extends ObjectSelectionList<MobList.Row> {
@Override public boolean mouseClicked(MouseButtonEvent event, boolean doubleClick) {
if (event.button() != 0) return false;
if (give != null && !data.skill() && !data.section() && event.x() >= getContentX() + getContentWidth() - 60) { give.accept(id); return true; }
if (data.expandable() && (data.section() || event.x() < getContentX() + 22 + 18 * data.indent())) {
groups.toggle(data); rebuild(); return true;
}