Search in sources :

Example 81 with TranslatableText

use of net.minecraft.text.TranslatableText 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 82 with TranslatableText

use of net.minecraft.text.TranslatableText in project ArmorStandEditor by Patbox.

the class EditorGuis method createIconCustomPower.

private static void createIconCustomPower(ServerPlayerEntity player, SimpleGui gui, int index, Item item) {
    ItemStack itemStack = item.getDefaultStack();
    itemStack.setCustomName(new TranslatableText("armorstandeditor.gui.name.custom_change").setStyle(Style.EMPTY.withItalic(false)));
    SPEInterface spe = (SPEInterface) player;
    float power = spe.getArmorStandEditorPower();
    ListTag lore = new ListTag();
    lore.add(StringTag.of(Text.Serializer.toJson(new TranslatableText("armorstandeditor.gui.blocksdeg", (Math.round(power * 100) / 100f), Math.floor(power * 3000) / 100).setStyle(Style.EMPTY.withItalic(false).withColor(Formatting.GRAY)))));
    itemStack.getOrCreateTag().getCompound("display").put("Lore", lore);
    itemStack.addHideFlag(ItemStack.TooltipSection.ENCHANTMENTS);
    itemStack.addHideFlag(ItemStack.TooltipSection.MODIFIERS);
    if (power != 1f && power != 0.01f && power != 0.1f) {
        itemStack.addEnchantment(Enchantments.POWER, 1);
    }
    gui.setSlot(index, itemStack, (index2, type, actionType) -> {
        if (!type.isMiddle) {
            float tmp = power + (0.01f * (type.shift ? 10 : 1) * (type.isLeft ? -1 : 1));
            float value = (Math.round(tmp * 100) / 100f);
            if (value > 0 && value < 5) {
                spe.setArmorStandEditorPower(value);
            }
        }
    });
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) SPEInterface(eu.pb4.armorstandeditor.helpers.SPEInterface) ItemStack(net.minecraft.item.ItemStack) ListTag(net.minecraft.nbt.ListTag)

Example 83 with TranslatableText

use of net.minecraft.text.TranslatableText in project ArmorStandEditor by Patbox.

the class EditorGuis method setIcons.

private static void setIcons(ServerPlayerEntity player, SimpleGui gui) {
    createIcon(player, gui, 0, Items.RED_WOOL, "x", 0);
    createIcon(player, gui, 1, Items.GREEN_WOOL, "y", 1);
    createIcon(player, gui, 2, Items.BLUE_WOOL, "z", 2);
    createIconCustomPower(player, gui, 5, Items.GOLD_INGOT);
    createIcon(player, gui, 6, Items.IRON_NUGGET, "small", 0.01f);
    createIcon(player, gui, 7, Items.IRON_INGOT, "medium", 0.1f);
    createIcon(player, gui, 8, Items.IRON_BLOCK, "big", 1f);
    createIcon(player, gui, 9, Items.MINECART, "move", EditorActions.MOVE);
    createIcon(player, gui, 10, Items.COMPASS, "rotate", EditorActions.ROTATE);
    createIcon(player, gui, 24, Items.PUFFERFISH, "size", EditorActions.TOGGLE_SIZE);
    createIcon(player, gui, 25, Items.APPLE, "gravity", EditorActions.TOGGLE_GRAVITY);
    createIcon(player, gui, 26, Items.GLASS, "visibility", EditorActions.TOGGLE_VISIBILITY);
    createIcon(player, gui, 34, Items.STICK, "arms", EditorActions.TOGGLE_ARMS);
    createIcon(player, gui, 35, Items.STONE_SLAB, "base", EditorActions.TOGGLE_BASE);
    createIcon(player, gui, 19, Items.LEATHER_HELMET, "head", EditorActions.MODIFY_HEAD);
    createIcon(player, gui, 27, Items.STICK, "left_arm", EditorActions.MODIFY_LEFT_ARM);
    createIcon(player, gui, 28, Items.LEATHER_CHESTPLATE, "body", EditorActions.MODIFY_BODY);
    createIcon(player, gui, 29, Items.STICK, "right_arm", EditorActions.MODIFY_RIGHT_ARM);
    createIcon(player, gui, 21, Items.GLISTERING_MELON_SLICE, "flip_pose", EditorActions.FLIP_POSE);
    createIcon(player, gui, 30, Items.LEVER, "reset_pose", EditorActions.RESET_POSE);
    createIcon(player, gui, 36, Items.LEATHER_BOOTS, "left_leg", EditorActions.MODIFY_LEFT_LEG);
    createIcon(player, gui, 37, Items.CHEST, "inventory", EditorActions.INVENTORY);
    createIcon(player, gui, 38, Items.LEATHER_BOOTS, "right_leg", EditorActions.MODIFY_RIGHT_LEG);
    createIcon(player, gui, 39, Items.NAME_TAG, "rename", EditorActions.RENAME);
    createIcon(player, gui, 43, Items.SLIME_BALL, "copy", EditorActions.COPY);
    createIcon(player, gui, 44, Items.MAGMA_CREAM, "paste", EditorActions.PASTE);
    gui.setSlot(42, new GuiElementBuilder(Items.MOJANG_BANNER_PATTERN).setName(new TranslatableText("armorstandeditor.gui.name.presets").setStyle(Style.EMPTY.withItalic(false))).setCallback((x, y, z) -> openPresetSelector(player)));
}
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) GuiElementBuilder(eu.pb4.sgui.api.elements.GuiElementBuilder)

Example 84 with TranslatableText

use of net.minecraft.text.TranslatableText in project ArmorStandEditor by Patbox.

the class EditorGuis method createIcon.

private static void createIcon(ServerPlayerEntity player, SimpleGui gui, int index, Item item, String text, int xyz) {
    ItemStack itemStack = item.getDefaultStack();
    itemStack.setCustomName(new TranslatableText("armorstandeditor.gui.name." + text).setStyle(Style.EMPTY.withItalic(false)));
    itemStack.addHideFlag(ItemStack.TooltipSection.ENCHANTMENTS);
    itemStack.addHideFlag(ItemStack.TooltipSection.MODIFIERS);
    if (((SPEInterface) player).getArmorStandEditorXYZ() == xyz) {
        itemStack.addEnchantment(Enchantments.POWER, 1);
    }
    gui.setSlot(index, itemStack, (index2, type, actionType) -> {
        ((SPEInterface) player).setArmorStandEditorXYZ(xyz);
    });
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) SPEInterface(eu.pb4.armorstandeditor.helpers.SPEInterface) ItemStack(net.minecraft.item.ItemStack)

Example 85 with TranslatableText

use of net.minecraft.text.TranslatableText in project ArmorStandEditor by Patbox.

the class EditorGuis method openRenaming.

public static void openRenaming(ServerPlayerEntity player, Entity entity) {
    ItemStack stack = Items.MAGMA_CREAM.getDefaultStack();
    stack.setCustomName(new TranslatableText("armorstandeditor.gui.clearname").setStyle(Style.EMPTY.withItalic(false)));
    ItemStack stack2 = Items.SLIME_BALL.getDefaultStack();
    stack2.setCustomName(new TranslatableText("armorstandeditor.gui.setname").setStyle(Style.EMPTY.withItalic(false)));
    AnvilInputGui gui = new AnvilInputGui(player, false) {

        @Override
        public void onInput(String input) {
            super.onInput(input);
            stack2.setCustomName(new TranslatableText("armorstandeditor.gui.setname", this.getInput()).setStyle(Style.EMPTY.withItalic(false)));
            this.setSlot(2, stack2, (index, type, action) -> {
                entity.setCustomName(new LiteralText(this.getInput()));
                entity.setCustomNameVisible(true);
                this.close(false);
            });
        }
    };
    gui.setTitle(new TranslatableText("armorstandeditor.gui.rename_title"));
    gui.setDefaultInputValue(entity.getCustomName() != null ? entity.getCustomName().getString() : "");
    gui.setSlot(1, stack, (index, type, action) -> {
        entity.setCustomName(new LiteralText(""));
        entity.setCustomNameVisible(false);
        gui.close(false);
    });
    gui.setSlot(2, stack2, (index, type, action) -> {
        entity.setCustomName(new LiteralText(gui.getInput()));
        entity.setCustomNameVisible(true);
        gui.close(false);
    });
    gui.open();
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) AnvilInputGui(eu.pb4.sgui.api.gui.AnvilInputGui) ItemStack(net.minecraft.item.ItemStack) LiteralText(net.minecraft.text.LiteralText)

Aggregations

TranslatableText (net.minecraft.text.TranslatableText)161 LiteralText (net.minecraft.text.LiteralText)30 Text (net.minecraft.text.Text)19 ItemStack (net.minecraft.item.ItemStack)16 ArrayList (java.util.ArrayList)15 ButtonWidget (net.minecraft.client.gui.widget.ButtonWidget)14 List (java.util.List)12 MinecraftClient (net.minecraft.client.MinecraftClient)12 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)12 SPEInterface (eu.pb4.armorstandeditor.helpers.SPEInterface)9 LivingEntity (net.minecraft.entity.LivingEntity)9 PlayerEntity (net.minecraft.entity.player.PlayerEntity)8 ListTag (net.minecraft.nbt.ListTag)8 Formatting (net.minecraft.util.Formatting)8 BlockPos (net.minecraft.util.math.BlockPos)8 Environment (net.fabricmc.api.Environment)7 AbstractButtonWidget (net.minecraft.client.gui.widget.AbstractButtonWidget)7 Entity (net.minecraft.entity.Entity)7 Collection (java.util.Collection)6 ArmorStandPreset (eu.pb4.armorstandeditor.config.ArmorStandPreset)5