Search in sources :

Example 21 with Component

use of net.minecraft.network.chat.Component in project Denizen-For-Bukkit by DenizenScript.

the class ProfileEditorImpl method handleAlteredProfiles.

public static boolean handleAlteredProfiles(ClientboundPlayerInfoPacket packet, DenizenNetworkManagerImpl manager) {
    if (ProfileEditor.mirrorUUIDs.isEmpty() && !RenameCommand.hasAnyDynamicRenames()) {
        return true;
    }
    ClientboundPlayerInfoPacket.Action action = packet.getAction();
    if (action != ClientboundPlayerInfoPacket.Action.ADD_PLAYER && action != ClientboundPlayerInfoPacket.Action.UPDATE_DISPLAY_NAME) {
        return true;
    }
    List<ClientboundPlayerInfoPacket.PlayerUpdate> dataList = packet.getEntries();
    if (dataList == null) {
        return true;
    }
    try {
        boolean any = false;
        for (ClientboundPlayerInfoPacket.PlayerUpdate data : dataList) {
            if (ProfileEditor.mirrorUUIDs.contains(data.getProfile().getId()) || RenameCommand.customNames.containsKey(data.getProfile().getId())) {
                any = true;
            }
        }
        if (!any) {
            return true;
        }
        GameProfile ownProfile = manager.player.getGameProfile();
        for (ClientboundPlayerInfoPacket.PlayerUpdate data : dataList) {
            if (!ProfileEditor.mirrorUUIDs.contains(data.getProfile().getId()) && !RenameCommand.customNames.containsKey(data.getProfile().getId())) {
                ClientboundPlayerInfoPacket newPacket = new ClientboundPlayerInfoPacket(action);
                List<ClientboundPlayerInfoPacket.PlayerUpdate> newPacketDataList = newPacket.getEntries();
                newPacketDataList.add(data);
                manager.oldManager.send(newPacket);
            } else {
                String rename = RenameCommand.getCustomNameFor(data.getProfile().getId(), manager.player.getBukkitEntity(), false);
                ClientboundPlayerInfoPacket newPacket = new ClientboundPlayerInfoPacket(action);
                List<ClientboundPlayerInfoPacket.PlayerUpdate> newPacketDataList = newPacket.getEntries();
                GameProfile patchedProfile = new GameProfile(data.getProfile().getId(), rename != null ? (rename.length() > 16 ? rename.substring(0, 16) : rename) : data.getProfile().getName());
                if (ProfileEditor.mirrorUUIDs.contains(data.getProfile().getId())) {
                    patchedProfile.getProperties().putAll(ownProfile.getProperties());
                } else {
                    patchedProfile.getProperties().putAll(data.getProfile().getProperties());
                }
                String listRename = RenameCommand.getCustomNameFor(data.getProfile().getId(), manager.player.getBukkitEntity(), true);
                Component displayName = listRename != null ? Handler.componentToNMS(FormattedTextHelper.parse(listRename, ChatColor.WHITE)) : data.getDisplayName();
                ClientboundPlayerInfoPacket.PlayerUpdate newData = new ClientboundPlayerInfoPacket.PlayerUpdate(patchedProfile, data.getLatency(), data.getGameMode(), displayName);
                newPacketDataList.add(newData);
                manager.oldManager.send(newPacket);
            }
        }
        return false;
    } catch (Exception e) {
        Debug.echoError(e);
        return true;
    }
}
Also used : GameProfile(com.mojang.authlib.GameProfile) Component(net.minecraft.network.chat.Component) ClientboundPlayerInfoPacket(net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket)

Example 22 with Component

use of net.minecraft.network.chat.Component in project Tropicraft by Tropicraft.

the class ScubaHUD method drawHUDStrings.

private static void drawHUDStrings(PoseStack matrixStack, Component... components) {
    Font fr = Minecraft.getInstance().font;
    Window mw = Minecraft.getInstance().getWindow();
    int startY = mw.getGuiScaledHeight() - 5 - (fr.lineHeight * components.length);
    int startX = mw.getGuiScaledWidth() - 5;
    for (Component text : components) {
        String s = text.getString();
        fr.drawShadow(matrixStack, s, startX - fr.width(s), startY, -1);
        startY += fr.lineHeight;
    }
}
Also used : Window(com.mojang.blaze3d.platform.Window) Component(net.minecraft.network.chat.Component) Font(net.minecraft.client.gui.Font)

Example 23 with Component

use of net.minecraft.network.chat.Component in project MC-Prefab by Brian-Wuest.

the class CustomButton method renderButton.

/**
 * Draws this button to the screen.
 */
@Override
public void renderButton(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;
        ResourceLocation buttonTexture = this.isHovered ? this.buttonTextureHover : this.buttonTexture;
        RenderSystem.setShader(GameRenderer::getPositionTexShader);
        RenderSystem.setShaderTexture(0, buttonTexture);
        RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, this.alpha);
        GuiUtils.bindAndDrawScaledTexture(mStack, this.x, this.y, this.width, this.height, 90, 20, 90, 20);
        int color = 14737632;
        Component buttonText = this.getMessage();
        int strWidth = mc.font.width(buttonText);
        int ellipsisWidth = mc.font.width("...");
        if (strWidth > width - 6 && strWidth > ellipsisWidth)
            buttonText = Utils.createTextComponent(mc.font.substrByWidth(buttonText, width - 6 - ellipsisWidth).getString() + "...");
        GuiComponent.drawCenteredString(mStack, mc.font, buttonText, this.x + this.width / 2, this.y + (this.height - 8) / 2, color);
    }
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) GameRenderer(net.minecraft.client.renderer.GameRenderer) GuiComponent(net.minecraft.client.gui.GuiComponent) TextComponent(net.minecraft.network.chat.TextComponent) Component(net.minecraft.network.chat.Component) Minecraft(net.minecraft.client.Minecraft)

Example 24 with Component

use of net.minecraft.network.chat.Component in project MC-Prefab by Brian-Wuest.

the class ExtendedButton method renderButton.

/**
 * Draws this button to the screen.
 */
@Override
public void renderButton(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;
        RenderSystem.setShader(GameRenderer::getPositionTexShader);
        RenderSystem.setShaderTexture(0, WIDGETS_LOCATION);
        RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, this.alpha);
        int i = this.getYImage(this.isHoveredOrFocused());
        RenderSystem.enableBlend();
        RenderSystem.defaultBlendFunc();
        RenderSystem.enableDepthTest();
        this.blit(mStack, this.x, this.y, 0, 46 + i * 20, this.width / 2, this.height);
        this.blit(mStack, this.x + this.width / 2, this.y, 200 - this.width / 2, 46 + i * 20, this.width / 2, this.height);
        this.renderBg(mStack, mc, mouseX, mouseY);
        Component buttonText = this.getMessage();
        int strWidth = mc.font.width(buttonText);
        int ellipsisWidth = mc.font.width("...");
        if (strWidth > width - 6 && strWidth > ellipsisWidth) {
            buttonText = Utils.createTextComponent(mc.font.substrByWidth(buttonText, width - 6 - ellipsisWidth).getString() + "...");
        }
        PoseStack originalStack = new PoseStack();
        originalStack.pushPose();
        originalStack.scale(this.fontScale, this.fontScale, this.fontScale);
        int xPosition = (int) ((this.x + this.width / 2) / this.fontScale);
        int yPosition = (int) ((this.y + (this.height - (8 * this.fontScale)) / 2) / this.fontScale);
        GuiComponent.drawCenteredString(originalStack, mc.font, buttonText, xPosition, yPosition, this.getFGColor());
        originalStack.popPose();
    }
}
Also used : PoseStack(com.mojang.blaze3d.vertex.PoseStack) GameRenderer(net.minecraft.client.renderer.GameRenderer) GuiComponent(net.minecraft.client.gui.GuiComponent) TextComponent(net.minecraft.network.chat.TextComponent) Component(net.minecraft.network.chat.Component) MutableComponent(net.minecraft.network.chat.MutableComponent) Minecraft(net.minecraft.client.Minecraft)

Aggregations

Component (net.minecraft.network.chat.Component)24 TextComponent (net.minecraft.network.chat.TextComponent)13 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)7 Minecraft (net.minecraft.client.Minecraft)5 GuiComponent (net.minecraft.client.gui.GuiComponent)4 MutableComponent (net.minecraft.network.chat.MutableComponent)4 ItemStack (net.minecraft.world.item.ItemStack)4 GameProfile (com.mojang.authlib.GameProfile)2 Window (com.mojang.blaze3d.platform.Window)2 TagCompound (de.keyle.knbt.TagCompound)2 TagList (de.keyle.knbt.TagList)2 TagShort (de.keyle.knbt.TagShort)2 TagString (de.keyle.knbt.TagString)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Font (net.minecraft.client.gui.Font)2 GameRenderer (net.minecraft.client.renderer.GameRenderer)2 CompoundTag (net.minecraft.nbt.CompoundTag)2 ListTag (net.minecraft.nbt.ListTag)2 ClientboundPlayerInfoPacket (net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket)2 ResourceLocation (net.minecraft.resources.ResourceLocation)2