Search in sources :

Example 1 with ArmorStandInventory

use of eu.pb4.armorstandeditor.helpers.ArmorStandInventory in project ArmorStandEditor by Patbox.

the class EditorGuis method openInventoryEditor.

public static void openInventoryEditor(ServerPlayerEntity player, LivingEntity entity) {
    SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X2, player, false);
    ArmorStandInventory inventory = new ArmorStandInventory(entity);
    gui.setTitle(new TranslatableText("armorstandeditor.gui.inventory_title"));
    for (int x = 0; x < inventory.size(); x++) {
        gui.setSlotRedirect(x, new Slot(inventory, x, 0, 0));
        if (entity instanceof ArmorStandEntity) {
            ArmorStandEntity ae = (ArmorStandEntity) entity;
            ArmorStandEntityAccessor asea = (ArmorStandEntityAccessor) ae;
            boolean isUnlocked = isSlotUnlocked(ae, ArmorStandInventory.getEquipmentSlot(x));
            gui.setSlot(x + 9, new GuiElementBuilder(isUnlocked ? Items.GREEN_STAINED_GLASS_PANE : Items.RED_STAINED_GLASS_PANE).setName(new TranslatableText(isUnlocked ? "narrator.button.difficulty_lock.unlocked" : "narrator.button.difficulty_lock.locked").setStyle(Style.EMPTY.withItalic(false))).setCallback((index, type, action) -> {
                EquipmentSlot slot = ArmorStandInventory.getEquipmentSlot(index - 9);
                int disabledSlots = asea.getDisabledSlots();
                boolean isUnlockedTmp = isSlotUnlocked(ae, slot);
                if (isUnlockedTmp) {
                    disabledSlots |= 1 << slot.getArmorStandSlotId();
                    disabledSlots |= 1 << slot.getArmorStandSlotId() + 8;
                    disabledSlots |= 1 << slot.getArmorStandSlotId() + 16;
                } else {
                    disabledSlots &= ~(1 << slot.getArmorStandSlotId());
                    disabledSlots &= ~(1 << slot.getArmorStandSlotId() + 8);
                    disabledSlots &= ~(1 << slot.getArmorStandSlotId() + 16);
                }
                asea.setDisabledSlots(disabledSlots);
                boolean isUnlocked2 = isSlotUnlocked(ae, slot);
                ItemStack stack = new ItemStack(isUnlocked2 ? Items.GREEN_STAINED_GLASS_PANE : Items.RED_STAINED_GLASS_PANE);
                stack.setCustomName(new TranslatableText(isUnlocked2 ? "narrator.button.difficulty_lock.unlocked" : "narrator.button.difficulty_lock.locked").setStyle(Style.EMPTY.withItalic(false)));
                ((GuiElement) gui.getSlot(index)).setItemStack(stack);
            }));
        } else {
            gui.setSlot(x + 9, new GuiElementBuilder(Items.RED_STAINED_GLASS_PANE).setName(new TranslatableText("armorstandeditor.gui.cantlockslots").setStyle(Style.EMPTY.withItalic(false).withColor(Formatting.RED))));
        }
    }
    GuiElement empty = new GuiElementBuilder(Items.GRAY_STAINED_GLASS_PANE).setName(new LiteralText("")).build();
    gui.setSlot(6, empty);
    gui.setSlot(7, empty);
    gui.setSlot(8, empty);
    gui.setSlot(15, empty);
    gui.setSlot(16, empty);
    gui.setSlot(17, new GuiElementBuilder(Items.BARRIER).setName(new TranslatableText("armorstandeditor.gui.close").setStyle(Style.EMPTY.withItalic(false))).setCallback(((index, type, action) -> {
        gui.close();
    })));
    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) EquipmentSlot(net.minecraft.entity.EquipmentSlot) ArmorStandInventory(eu.pb4.armorstandeditor.helpers.ArmorStandInventory) GuiElementBuilder(eu.pb4.sgui.api.elements.GuiElementBuilder) ArmorStandEntityAccessor(eu.pb4.armorstandeditor.mixin.ArmorStandEntityAccessor) Slot(net.minecraft.screen.slot.Slot) EquipmentSlot(net.minecraft.entity.EquipmentSlot) SimpleGui(eu.pb4.sgui.api.gui.SimpleGui) ItemStack(net.minecraft.item.ItemStack) ArmorStandEntity(net.minecraft.entity.decoration.ArmorStandEntity) GuiElement(eu.pb4.sgui.api.elements.GuiElement) LiteralText(net.minecraft.text.LiteralText)

Aggregations

ArmorStandPreset (eu.pb4.armorstandeditor.config.ArmorStandPreset)1 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 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Collectors (java.util.stream.Collectors)1 Permissions (me.lucko.fabric.api.permissions.v0.Permissions)1