Search in sources :

Example 1 with ArmorStandPreset

use of eu.pb4.armorstandeditor.config.ArmorStandPreset in project ArmorStandEditor by Patbox.

the class EditorGuis method openPresetSelector.

public static void openPresetSelector(ServerPlayerEntity player) {
    List<ArmorStandPreset> presets = new ArrayList<>(ConfigManager.PRESETS.values());
    final int presetsSize = presets.size();
    AtomicInteger page = new AtomicInteger();
    final int maxPage = (int) Math.ceil((double) presetsSize / 18);
    SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X3, player, false) {

        @Override
        public void onUpdate(boolean firstUpdate) {
            super.onUpdate(firstUpdate);
            if (firstUpdate) {
                for (int x = 0; x < 9; x++) {
                    this.setSlot(x + 18, new GuiElementBuilder(Items.GRAY_STAINED_GLASS_PANE).setName(new LiteralText("")));
                }
            }
            for (int x = 0; x < 18; x++) {
                this.clearSlot(x);
                if (page.get() * 18 + x < presetsSize) {
                    final ArmorStandPreset preset = presets.get(page.get() * 18 + x);
                    this.setSlot(x, new GuiElementBuilder(Items.ARMOR_STAND).setName(new LiteralText(preset.name).setStyle(Style.EMPTY.withItalic(false).withColor(Formatting.GREEN))).addLoreLine(new TranslatableText("armorstandeditor.gui.preset-author", preset.author).setStyle(Style.EMPTY.withItalic(false).withColor(Formatting.GRAY))).setCallback((t1, t2, t3) -> {
                        ((SPEInterface) this.player).setArmorStandEditorData(preset.asData());
                        ((SPEInterface) this.player).setArmorStandEditorAction(EditorActions.PASTE);
                        player.sendMessage(new TranslatableText("armorstandeditor.message.copied"), true);
                        this.close();
                    }));
                }
            }
            this.setSlot(this.size - 5, new GuiElementBuilder(Items.BARRIER).setName(new TranslatableText("dataPack.validation.back").setStyle(Style.EMPTY.withItalic(false))).setCallback((index, type, action) -> {
                this.close();
            }));
            this.setSlot(this.size - 8, new GuiElementBuilder(page.get() != 0 ? Items.ARROW : Items.LIGHT_GRAY_STAINED_GLASS_PANE).setName(new TranslatableText("spectatorMenu.previous_page").setStyle(Style.EMPTY.withItalic(false))).setCallback((index, type, action) -> {
                if (page.addAndGet(-1) < 0) {
                    page.set(0);
                }
                this.onUpdate(false);
            }));
            this.setSlot(this.size - 2, new GuiElementBuilder(page.get() != maxPage - 1 ? Items.ARROW : Items.LIGHT_GRAY_STAINED_GLASS_PANE).setName(new TranslatableText("spectatorMenu.next_page").setStyle(Style.EMPTY.withItalic(false))).setCallback((index, type, action) -> {
                if (page.addAndGet(1) >= maxPage) {
                    page.set(maxPage - 1);
                }
                this.onUpdate(false);
            }));
        }
    };
    gui.setTitle(new TranslatableText("armorstandeditor.gui.presets_title"));
    gui.open();
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) LiteralText(net.minecraft.text.LiteralText) ConfigManager(eu.pb4.armorstandeditor.config.ConfigManager) Item(net.minecraft.item.Item) StringTag(net.minecraft.nbt.StringTag) Permissions(me.lucko.fabric.api.permissions.v0.Permissions) TranslatableText(net.minecraft.text.TranslatableText) ItemFrameEntity(net.minecraft.entity.decoration.ItemFrameEntity) Slot(net.minecraft.screen.slot.Slot) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) Style(net.minecraft.text.Style) GuiElementInterface(eu.pb4.sgui.api.elements.GuiElementInterface) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AnvilInputGui(eu.pb4.sgui.api.gui.AnvilInputGui) ItemFrameEntityAccessor(eu.pb4.armorstandeditor.mixin.ItemFrameEntityAccessor) Enchantments(net.minecraft.enchantment.Enchantments) EquipmentSlot(net.minecraft.entity.EquipmentSlot) GuiElementBuilder(eu.pb4.sgui.api.elements.GuiElementBuilder) ClickType(eu.pb4.sgui.api.ClickType) ScreenHandlerType(net.minecraft.screen.ScreenHandlerType) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ArmorStandEntityAccessor(eu.pb4.armorstandeditor.mixin.ArmorStandEntityAccessor) LivingEntity(net.minecraft.entity.LivingEntity) ArmorStandEntity(net.minecraft.entity.decoration.ArmorStandEntity) Collection(java.util.Collection) ItemFrameInventory(eu.pb4.armorstandeditor.helpers.ItemFrameInventory) GuiElement(eu.pb4.sgui.api.elements.GuiElement) Items(net.minecraft.item.Items) ArmorStandData(eu.pb4.armorstandeditor.helpers.ArmorStandData) Collectors(java.util.stream.Collectors) SPEInterface(eu.pb4.armorstandeditor.helpers.SPEInterface) Formatting(net.minecraft.util.Formatting) List(java.util.List) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ArmorStandInventory(eu.pb4.armorstandeditor.helpers.ArmorStandInventory) ArmorStandPreset(eu.pb4.armorstandeditor.config.ArmorStandPreset) Text(net.minecraft.text.Text) SlotActionType(net.minecraft.screen.slot.SlotActionType) ListTag(net.minecraft.nbt.ListTag) SimpleGui(eu.pb4.sgui.api.gui.SimpleGui) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArmorStandPreset(eu.pb4.armorstandeditor.config.ArmorStandPreset) ArrayList(java.util.ArrayList) GuiElementBuilder(eu.pb4.sgui.api.elements.GuiElementBuilder) SimpleGui(eu.pb4.sgui.api.gui.SimpleGui) LiteralText(net.minecraft.text.LiteralText)

Example 2 with ArmorStandPreset

use of eu.pb4.armorstandeditor.config.ArmorStandPreset in project ArmorStandEditor by Patbox.

the class GeneralCommands method savePreset.

private static int savePreset(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
    ServerPlayerEntity player = context.getSource().getPlayer();
    SPEInterface spei = (SPEInterface) player;
    String id = context.getArgument("id", String.class);
    String name = context.getArgument("name", String.class);
    if (ConfigManager.INVALID_CHAR.matcher(id).matches()) {
        context.getSource().sendFeedback(new TranslatableText("armorstandeditor.command.invalid-id", id).formatted(Formatting.RED), false);
        return 0;
    }
    if (spei.getArmorStandEditorData() != null) {
        ArmorStandPreset preset = new ArmorStandPreset(id, name, player.getGameProfile().getName());
        preset.fromData(spei.getArmorStandEditorData());
        ConfigManager.savePreset(preset);
        context.getSource().sendFeedback(new TranslatableText("armorstandeditor.command.save-preset.success", name, id), false);
    } else {
        context.getSource().sendFeedback(new TranslatableText("armorstandeditor.command.save-preset.fail", name, id).formatted(Formatting.RED), false);
    }
    return 0;
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) ArmorStandPreset(eu.pb4.armorstandeditor.config.ArmorStandPreset) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity)

Example 3 with ArmorStandPreset

use of eu.pb4.armorstandeditor.config.ArmorStandPreset in project ArmorStandEditor by Patbox.

the class GeneralCommands method listPresets.

private static int listPresets(CommandContext<ServerCommandSource> context) {
    MutableText text = new LiteralText("").formatted(Formatting.DARK_GRAY);
    Iterator<ArmorStandPreset> iterator = ConfigManager.PRESETS.values().iterator();
    while (iterator.hasNext()) {
        ArmorStandPreset preset = iterator.next();
        if (preset.id.startsWith("$")) {
            text.append(new LiteralText(preset.name).formatted(Formatting.YELLOW).append(new LiteralText(" (").formatted(Formatting.GRAY).append(new LiteralText("buildin/" + preset.id.substring(1)).formatted(Formatting.RED)).append(new LiteralText(")").formatted(Formatting.GRAY))));
        } else {
            text.append(new LiteralText(preset.name).formatted(Formatting.WHITE).append(new LiteralText(" (").formatted(Formatting.GRAY).append(new LiteralText(preset.id).formatted(Formatting.BLUE)).append(new LiteralText(")").formatted(Formatting.GRAY))));
        }
        if (iterator.hasNext()) {
            text.append(new LiteralText(", "));
        }
    }
    context.getSource().sendFeedback(text, false);
    return 0;
}
Also used : MutableText(net.minecraft.text.MutableText) ArmorStandPreset(eu.pb4.armorstandeditor.config.ArmorStandPreset) LiteralText(net.minecraft.text.LiteralText)

Aggregations

ArmorStandPreset (eu.pb4.armorstandeditor.config.ArmorStandPreset)3 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)2 LiteralText (net.minecraft.text.LiteralText)2 TranslatableText (net.minecraft.text.TranslatableText)2 ConfigManager (eu.pb4.armorstandeditor.config.ConfigManager)1 ArmorStandData (eu.pb4.armorstandeditor.helpers.ArmorStandData)1 ArmorStandInventory (eu.pb4.armorstandeditor.helpers.ArmorStandInventory)1 ItemFrameInventory (eu.pb4.armorstandeditor.helpers.ItemFrameInventory)1 SPEInterface (eu.pb4.armorstandeditor.helpers.SPEInterface)1 ArmorStandEntityAccessor (eu.pb4.armorstandeditor.mixin.ArmorStandEntityAccessor)1 ItemFrameEntityAccessor (eu.pb4.armorstandeditor.mixin.ItemFrameEntityAccessor)1 ClickType (eu.pb4.sgui.api.ClickType)1 GuiElement (eu.pb4.sgui.api.elements.GuiElement)1 GuiElementBuilder (eu.pb4.sgui.api.elements.GuiElementBuilder)1 GuiElementInterface (eu.pb4.sgui.api.elements.GuiElementInterface)1 AnvilInputGui (eu.pb4.sgui.api.gui.AnvilInputGui)1 SimpleGui (eu.pb4.sgui.api.gui.SimpleGui)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1