Search in sources :

Example 11 with Slot

use of net.minecraft.screen.slot.Slot in project ArmorStandEditor by Patbox.

the class EditorGuis method openItemFrameEditor.

public static void openItemFrameEditor(ServerPlayerEntity player, ItemFrameEntity entity) {
    ItemFrameEntityAccessor ifa = (ItemFrameEntityAccessor) entity;
    SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X1, player, false);
    ItemFrameInventory inventory = new ItemFrameInventory(entity);
    GuiElement empty = new GuiElementBuilder(Items.GRAY_STAINED_GLASS_PANE).setName(new LiteralText("")).build();
    gui.setTitle(new TranslatableText("armorstandeditor.gui.item_frame_title"));
    gui.setSlotRedirect(0, new Slot(inventory, 0, 0, 0));
    gui.setSlot(1, empty);
    gui.setSlot(2, new GuiElementBuilder(ifa.getFixed() ? Items.GREEN_STAINED_GLASS_PANE : Items.RED_STAINED_GLASS_PANE).setName(new TranslatableText("armorstandeditor.gui.name.if-fixed", ifa.getFixed()).setStyle(Style.EMPTY.withItalic(false))).setCallback((index, type, action) -> {
        ifa.setFixed(!ifa.getFixed());
        ItemStack stack = new ItemStack(ifa.getFixed() ? Items.GREEN_STAINED_GLASS_PANE : Items.RED_STAINED_GLASS_PANE);
        stack.setCustomName(new TranslatableText("armorstandeditor.gui.name.if-fixed", ifa.getFixed()).setStyle(Style.EMPTY.withItalic(false)));
        ((GuiElement) gui.getSlot(index)).setItemStack(stack);
    }));
    gui.setSlot(3, new GuiElementBuilder(entity.isInvisible() ? Items.GREEN_STAINED_GLASS_PANE : Items.RED_STAINED_GLASS_PANE).setName(new TranslatableText("armorstandeditor.gui.name.if-invisible", entity.isInvisible()).setStyle(Style.EMPTY.withItalic(false))).setCallback((index, type, action) -> {
        entity.setInvisible(!entity.isInvisible());
        System.out.println(entity.isInvisible());
        ItemStack stack = new ItemStack(entity.isInvisible() ? Items.GREEN_STAINED_GLASS_PANE : Items.RED_STAINED_GLASS_PANE);
        stack.setCustomName(new TranslatableText("armorstandeditor.gui.name.if-invisible", entity.isInvisible()).setStyle(Style.EMPTY.withItalic(false)));
        ((GuiElement) gui.getSlot(index)).setItemStack(stack);
    }));
    gui.setSlot(4, new GuiElementBuilder(Items.ARROW).setName(new TranslatableText("armorstandeditor.gui.name.if-rotate", entity.getRotation()).setStyle(Style.EMPTY.withItalic(false))).setCallback((index, type, action) -> {
        if (type.isLeft || type.isRight) {
            int rotation = entity.getRotation() + (type.isLeft ? -1 : 1);
            if (rotation < 0) {
                rotation = 8 + rotation;
            }
            entity.setRotation(rotation % 8);
            ItemStack stack = new ItemStack(Items.ARROW);
            stack.setCustomName(new TranslatableText("armorstandeditor.gui.name.if-rotate", rotation).setStyle(Style.EMPTY.withItalic(false)));
            ((GuiElement) gui.getSlot(index)).setItemStack(stack);
        }
    }));
    for (int x = 5; x < 8; x++) {
        gui.setSlot(x, empty);
    }
    gui.setSlot(8, 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) ItemFrameInventory(eu.pb4.armorstandeditor.helpers.ItemFrameInventory) Slot(net.minecraft.screen.slot.Slot) EquipmentSlot(net.minecraft.entity.EquipmentSlot) GuiElementBuilder(eu.pb4.sgui.api.elements.GuiElementBuilder) ItemFrameEntityAccessor(eu.pb4.armorstandeditor.mixin.ItemFrameEntityAccessor) SimpleGui(eu.pb4.sgui.api.gui.SimpleGui) ItemStack(net.minecraft.item.ItemStack) GuiElement(eu.pb4.sgui.api.elements.GuiElement) LiteralText(net.minecraft.text.LiteralText)

Example 12 with Slot

use of net.minecraft.screen.slot.Slot 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)

Example 13 with Slot

use of net.minecraft.screen.slot.Slot in project MCDoom by AzureDoom.

the class GunTableScreenHandler method transferSlot.

public ItemStack transferSlot(PlayerEntity player, int index) {
    ItemStack itemStack = ItemStack.EMPTY;
    Slot slot = this.slots.get(index);
    if (slot != null && slot.hasStack()) {
        ItemStack itemStack2 = slot.getStack();
        itemStack = itemStack2.copy();
        if (index == 2) {
            if (!this.insertItem(itemStack2, 3, 39, true)) {
                return ItemStack.EMPTY;
            }
            slot.onQuickTransfer(itemStack2, itemStack);
        } else if (index != 0 && index != 1) {
            if (index >= 3 && index < 30) {
                if (!this.insertItem(itemStack2, 30, 39, false)) {
                    return ItemStack.EMPTY;
                }
            } else if (index >= 30 && index < 39 && !this.insertItem(itemStack2, 3, 30, false)) {
                return ItemStack.EMPTY;
            }
        } else if (!this.insertItem(itemStack2, 3, 39, false)) {
            return ItemStack.EMPTY;
        }
        if (itemStack2.isEmpty()) {
            slot.setStack(ItemStack.EMPTY);
        } else {
            slot.markDirty();
        }
        if (itemStack2.getCount() == itemStack.getCount()) {
            return ItemStack.EMPTY;
        }
        slot.onTakeItem(player, itemStack2);
    }
    return itemStack;
}
Also used : Slot(net.minecraft.screen.slot.Slot) ItemStack(net.minecraft.item.ItemStack)

Example 14 with Slot

use of net.minecraft.screen.slot.Slot in project MasaGadget by plusls.

the class RestockUtil method tryCraftingRestocking.

public static void tryCraftingRestocking(PlayerEntity player, Hand hand, ItemStack itemStack) {
    if (player.isCreative()) {
        return;
    }
    updateRecipes();
    // TODO: Lazy update (on itemscoller's RecipeStorage updated or config changed)
    MinecraftClient mc = MinecraftClient.getInstance();
    HandledScreen<? extends ScreenHandler> gui = new InventoryScreen(player);
    gui.init(MinecraftClient.getInstance(), 0, 0);
    for (RecipePattern recipe : RestockUtil.recipes) {
        if (ItemStack.canCombine(recipe.getResult(), itemStack)) {
            InventoryUtils.tryMoveItemsToFirstCraftingGrid(recipe, gui, false);
            mc.interactionManager.clickSlot(player.playerScreenHandler.syncId, 0, 0, SlotActionType.PICKUP, player);
            if (player.playerScreenHandler.getCursorStack().isItemEqual(itemStack)) {
                mc.interactionManager.clickSlot(player.playerScreenHandler.syncId, hand == Hand.MAIN_HAND ? player.getInventory().selectedSlot + 36 : 45, 0, SlotActionType.PICKUP, player);
                return;
            } else {
                Slot slot = CraftingHandler.getFirstCraftingOutputSlotForGui(gui);
                CraftingHandler.SlotRange range = CraftingHandler.getCraftingGridSlots(gui, slot);
                for (int s = range.getFirst(); s <= range.getLast(); s++) {
                    mc.interactionManager.clickSlot(gui.getScreenHandler().syncId, s, 0, SlotActionType.QUICK_MOVE, mc.player);
                }
            }
        }
    }
}
Also used : RecipePattern(fi.dy.masa.itemscroller.recipes.RecipePattern) MinecraftClient(net.minecraft.client.MinecraftClient) Slot(net.minecraft.screen.slot.Slot) CraftingHandler(fi.dy.masa.itemscroller.recipes.CraftingHandler) InventoryScreen(net.minecraft.client.gui.screen.ingame.InventoryScreen)

Example 15 with Slot

use of net.minecraft.screen.slot.Slot in project Polymorph by TheIllusiveC4.

the class PolymorphMod method onInitialize.

@Override
public void onInitialize() {
    PolymorphNetwork.setup();
    PolymorphCommands.setup();
    CommonEventsListener.setup();
    PolymorphIntegrations.init();
    PolymorphIntegrations.setup();
    PolymorphCommon commonApi = PolymorphApi.common();
    commonApi.registerBlockEntity2RecipeData(AbstractFurnaceBlockEntity.class, blockEntity -> new FurnaceRecipeData((AbstractFurnaceBlockEntity) blockEntity));
    commonApi.registerScreenHandler2BlockEntity(container -> {
        for (Slot inventorySlot : container.slots) {
            Inventory inventory = inventorySlot.inventory;
            if (inventory instanceof BlockEntity) {
                return (BlockEntity) inventory;
            }
        }
        return null;
    });
}
Also used : AbstractFurnaceBlockEntity(net.minecraft.block.entity.AbstractFurnaceBlockEntity) FurnaceRecipeData(top.theillusivec4.polymorph.common.component.FurnaceRecipeData) Slot(net.minecraft.screen.slot.Slot) PolymorphCommon(top.theillusivec4.polymorph.api.common.base.PolymorphCommon) Inventory(net.minecraft.inventory.Inventory) BlockEntity(net.minecraft.block.entity.BlockEntity) AbstractFurnaceBlockEntity(net.minecraft.block.entity.AbstractFurnaceBlockEntity)

Aggregations

Slot (net.minecraft.screen.slot.Slot)24 ItemStack (net.minecraft.item.ItemStack)14 EquipmentSlot (net.minecraft.entity.EquipmentSlot)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ArmorStandPreset (eu.pb4.armorstandeditor.config.ArmorStandPreset)2 ConfigManager (eu.pb4.armorstandeditor.config.ConfigManager)2 ArmorStandData (eu.pb4.armorstandeditor.helpers.ArmorStandData)2 ArmorStandInventory (eu.pb4.armorstandeditor.helpers.ArmorStandInventory)2 ItemFrameInventory (eu.pb4.armorstandeditor.helpers.ItemFrameInventory)2 SPEInterface (eu.pb4.armorstandeditor.helpers.SPEInterface)2 ArmorStandEntityAccessor (eu.pb4.armorstandeditor.mixin.ArmorStandEntityAccessor)2 ItemFrameEntityAccessor (eu.pb4.armorstandeditor.mixin.ItemFrameEntityAccessor)2 ClickType (eu.pb4.sgui.api.ClickType)2 GuiElement (eu.pb4.sgui.api.elements.GuiElement)2 GuiElementBuilder (eu.pb4.sgui.api.elements.GuiElementBuilder)2 GuiElementInterface (eu.pb4.sgui.api.elements.GuiElementInterface)2 AnvilInputGui (eu.pb4.sgui.api.gui.AnvilInputGui)2 SimpleGui (eu.pb4.sgui.api.gui.SimpleGui)2 Collection (java.util.Collection)2