Search in sources :

Example 11 with TextComponent

use of net.minecraft.network.chat.TextComponent in project MinecraftForge by MinecraftForge.

the class UnicodeGlyphButton method render.

@Override
public void render(PoseStack mStack, int mouseX, int mouseY, float partial) {
    if (this.visible) {
        Minecraft mc = Minecraft.getInstance();
        this.isHovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
        int k = this.getYImage(this.isHovered);
        GuiUtils.drawContinuousTexturedBox(mStack, WIDGETS_LOCATION, this.x, this.y, 0, 46 + k * 20, this.width, this.height, 200, 20, 2, 3, 2, 2, this.getBlitOffset());
        this.renderBg(mStack, mc, mouseX, mouseY);
        Component buttonText = this.createNarrationMessage();
        int glyphWidth = (int) (mc.font.width(glyph) * glyphScale);
        int strWidth = mc.font.width(buttonText);
        int ellipsisWidth = mc.font.width("...");
        int totalWidth = strWidth + glyphWidth;
        if (totalWidth > width - 6 && totalWidth > ellipsisWidth)
            buttonText = new TextComponent(mc.font.substrByWidth(buttonText, width - 6 - ellipsisWidth).getString().trim() + "...");
        strWidth = mc.font.width(buttonText);
        totalWidth = glyphWidth + strWidth;
        mStack.pushPose();
        mStack.scale(glyphScale, glyphScale, 1.0F);
        this.drawCenteredString(mStack, mc.font, new TextComponent(glyph), (int) (((this.x + (this.width / 2) - (strWidth / 2)) / glyphScale) - (glyphWidth / (2 * glyphScale)) + 2), (int) (((this.y + ((this.height - 8) / glyphScale) / 2) - 1) / glyphScale), getFGColor());
        mStack.popPose();
        this.drawCenteredString(mStack, mc.font, buttonText, (int) (this.x + (this.width / 2) + (glyphWidth / glyphScale)), this.y + (this.height - 8) / 2, getFGColor());
    }
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) TextComponent(net.minecraft.network.chat.TextComponent) Component(net.minecraft.network.chat.Component) Minecraft(net.minecraft.client.Minecraft)

Example 12 with TextComponent

use of net.minecraft.network.chat.TextComponent in project MyPet by xXKeyleXx.

the class CustomInventory method open.

@Override
public void open(Player player) {
    ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle();
    AbstractContainerMenu container = new CraftContainer(getBukkitInventory(), entityPlayer, entityPlayer.nextContainerCounter());
    container = CraftEventFactory.callInventoryOpenEvent(entityPlayer, container);
    if (container != null) {
        MenuType<?> customSize = MenuType.GENERIC_9x1;
        switch(this.getContainerSize()) {
            case 18:
                customSize = MenuType.GENERIC_9x2;
                break;
            case 27:
                customSize = MenuType.GENERIC_9x3;
                break;
            case 36:
                customSize = MenuType.GENERIC_9x4;
                break;
            case 45:
                customSize = MenuType.GENERIC_9x5;
                break;
            case 54:
                customSize = MenuType.GENERIC_9x6;
                break;
        }
        entityPlayer.connection.send(new ClientboundOpenScreenPacket(container.containerId, customSize, new TextComponent(this.getName())));
        entityPlayer.containerMenu = container;
        entityPlayer.initMenu(container);
    }
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) AbstractContainerMenu(net.minecraft.world.inventory.AbstractContainerMenu) ServerPlayer(net.minecraft.server.level.ServerPlayer) ClientboundOpenScreenPacket(net.minecraft.network.protocol.game.ClientboundOpenScreenPacket) CraftPlayer(org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer) CraftContainer(org.bukkit.craftbukkit.v1_17_R1.inventory.CraftContainer)

Example 13 with TextComponent

use of net.minecraft.network.chat.TextComponent in project MyPet by xXKeyleXx.

the class CustomInventory method open.

@Override
public void open(Player player) {
    ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle();
    AbstractContainerMenu container = new CraftContainer(getBukkitInventory(), entityPlayer, entityPlayer.nextContainerCounter());
    container = CraftEventFactory.callInventoryOpenEvent(entityPlayer, container);
    if (container != null) {
        MenuType<?> customSize = MenuType.GENERIC_9x1;
        switch(this.getContainerSize()) {
            case 18:
                customSize = MenuType.GENERIC_9x2;
                break;
            case 27:
                customSize = MenuType.GENERIC_9x3;
                break;
            case 36:
                customSize = MenuType.GENERIC_9x4;
                break;
            case 45:
                customSize = MenuType.GENERIC_9x5;
                break;
            case 54:
                customSize = MenuType.GENERIC_9x6;
                break;
        }
        entityPlayer.connection.send(new ClientboundOpenScreenPacket(container.containerId, customSize, new TextComponent(this.getName())));
        entityPlayer.containerMenu = container;
        entityPlayer.initMenu(container);
    }
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) AbstractContainerMenu(net.minecraft.world.inventory.AbstractContainerMenu) ServerPlayer(net.minecraft.server.level.ServerPlayer) ClientboundOpenScreenPacket(net.minecraft.network.protocol.game.ClientboundOpenScreenPacket) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) CraftContainer(org.bukkit.craftbukkit.v1_18_R1.inventory.CraftContainer)

Example 14 with TextComponent

use of net.minecraft.network.chat.TextComponent in project MinecraftForge by MinecraftForge.

the class AddPackFinderEventTest method addPackFinders.

@SubscribeEvent
public static void addPackFinders(AddPackFindersEvent event) {
    try {
        if (event.getPackType() == PackType.CLIENT_RESOURCES) {
            var resourcePath = ModList.get().getModFileById(MODID).getFile().findResource("test_nested_resource_pack");
            var pack = new PathResourcePack(ModList.get().getModFileById(MODID).getFile().getFileName() + ":" + resourcePath, resourcePath);
            var metadataSection = pack.getMetadataSection(PackMetadataSection.SERIALIZER);
            if (metadataSection != null) {
                event.addRepositorySource((packConsumer, packConstructor) -> packConsumer.accept(packConstructor.create("builtin/add_pack_finders_test", new TextComponent("display name"), false, () -> pack, metadataSection, Pack.Position.BOTTOM, PackSource.BUILT_IN, false)));
            }
        }
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) IOException(java.io.IOException) PathResourcePack(net.minecraftforge.resource.PathResourcePack) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 15 with TextComponent

use of net.minecraft.network.chat.TextComponent in project MinecraftForge by MinecraftForge.

the class ClientCommandTest method init.

private void init(RegisterClientCommandsEvent event) {
    event.getDispatcher().register(Commands.literal("clientcommandtest").then(Commands.literal("rawsuggest").then(Commands.argument("block", ResourceLocationArgument.id()).suggests((c, b) -> SharedSuggestionProvider.suggestResource(ForgeRegistries.BLOCKS.getKeys(), b)).executes(this::testCommand))).then(Commands.literal("registeredsuggest").then(Commands.argument("block", ResourceLocationArgument.id()).suggests(SuggestionProviders.AVAILABLE_BIOMES).executes(this::testCommand))).then(Commands.literal("server").executes((context) -> {
        context.getSource().getServer();
        context.getSource().sendSuccess(new TextComponent("Successfully called getServer should have errored"), false);
        return 1;
    })).then(Commands.literal("level").executes((context) -> {
        context.getSource().getLevel();
        context.getSource().sendSuccess(new TextComponent("Successfully called getLevel should have errored"), false);
        return 1;
    })).then(Commands.literal("get_objective").then(Commands.argument("objective", ObjectiveArgument.objective()).executes((context) -> {
        context.getSource().sendSuccess(new TextComponent("Regular: ").append(ObjectiveArgument.getObjective(context, "objective").getFormattedDisplayName()), false);
        return 1;
    }))).then(Commands.literal("get_advancement").then(Commands.argument("advancement", ResourceLocationArgument.id()).executes((context) -> {
        context.getSource().sendSuccess(ResourceLocationArgument.getAdvancement(context, "advancement").getChatComponent(), false);
        return 1;
    }))).then(Commands.literal("get_recipe").then(Commands.argument("recipe", ResourceLocationArgument.id()).executes((context) -> {
        context.getSource().sendSuccess(ResourceLocationArgument.getRecipe(context, "recipe").getResultItem().getDisplayName(), false);
        return 1;
    }))).then(Commands.literal("get_team").then(Commands.argument("team", TeamArgument.team()).executes((context) -> {
        context.getSource().sendSuccess(TeamArgument.getTeam(context, "team").getFormattedDisplayName(), false);
        return 1;
    }))).then(Commands.literal("get_loaded_blockpos").then(Commands.argument("blockpos", BlockPosArgument.blockPos()).executes((context) -> {
        context.getSource().sendSuccess(new TextComponent(BlockPosArgument.getLoadedBlockPos(context, "blockpos").toString()), false);
        return 1;
    }))).then(Commands.literal("requires").requires((source) -> false).executes((context) -> {
        context.getSource().sendSuccess(new TextComponent("Executed command"), false);
        return 1;
    })));
    // Used for testing that client command redirects can only be used with client commands
    LiteralArgumentBuilder<CommandSourceStack> fork = Commands.literal("clientcommandfork");
    fork.fork(event.getDispatcher().getRoot(), (context) -> List.of(context.getSource(), context.getSource())).executes((context) -> {
        context.getSource().sendSuccess(new TextComponent("Executing forked command"), false);
        return 1;
    });
    event.getDispatcher().register(fork);
}
Also used : RegisterClientCommandsEvent(net.minecraftforge.client.event.RegisterClientCommandsEvent) SharedSuggestionProvider(net.minecraft.commands.SharedSuggestionProvider) CommandContext(com.mojang.brigadier.context.CommandContext) CommandSourceStack(net.minecraft.commands.CommandSourceStack) Commands(net.minecraft.commands.Commands) TeamArgument(net.minecraft.commands.arguments.TeamArgument) LiteralArgumentBuilder(com.mojang.brigadier.builder.LiteralArgumentBuilder) ResourceLocationArgument(net.minecraft.commands.arguments.ResourceLocationArgument) ObjectiveArgument(net.minecraft.commands.arguments.ObjectiveArgument) TextComponent(net.minecraft.network.chat.TextComponent) MinecraftForge(net.minecraftforge.common.MinecraftForge) List(java.util.List) SuggestionProviders(net.minecraft.commands.synchronization.SuggestionProviders) BlockPosArgument(net.minecraft.commands.arguments.coordinates.BlockPosArgument) Mod(net.minecraftforge.fml.common.Mod) ForgeRegistries(net.minecraftforge.registries.ForgeRegistries) TextComponent(net.minecraft.network.chat.TextComponent) CommandSourceStack(net.minecraft.commands.CommandSourceStack)

Aggregations

TextComponent (net.minecraft.network.chat.TextComponent)19 Component (net.minecraft.network.chat.Component)4 List (java.util.List)3 Minecraft (net.minecraft.client.Minecraft)3 CommandSourceStack (net.minecraft.commands.CommandSourceStack)3 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)3 ServerPlayer (net.minecraft.server.level.ServerPlayer)3 AbstractContainerMenu (net.minecraft.world.inventory.AbstractContainerMenu)3 Commands (net.minecraft.commands.Commands)2 ClientboundOpenScreenPacket (net.minecraft.network.protocol.game.ClientboundOpenScreenPacket)2 ClientboundLoginDisconnectPacket (net.minecraft.network.protocol.login.ClientboundLoginDisconnectPacket)2 ResourceLocation (net.minecraft.resources.ResourceLocation)2 Player (net.minecraft.world.entity.player.Player)2 ForgeI18n (net.minecraftforge.common.ForgeI18n)2 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)2 Strings (com.google.common.base.Strings)1 Maps (com.google.common.collect.Maps)1 Multimap (com.google.common.collect.Multimap)1 PoseStack (com.mojang.blaze3d.vertex.PoseStack)1 ArgumentBuilder (com.mojang.brigadier.builder.ArgumentBuilder)1