Search in sources :

Example 16 with Component

use of net.minecraft.network.chat.Component in project SpongeCommon by SpongePowered.

the class SignBlockEntityMixin_API method toContainer.

// @formatter:on
@Override
public DataContainer toContainer() {
    DataContainer container = super.toContainer();
    List<String> lines = Lists.newArrayList();
    for (Component line : this.messages) {
        lines.add(Component.Serializer.toJson(line));
    }
    container.set(Constants.TileEntity.SIGN_LINES, lines);
    return container;
}
Also used : DataContainer(org.spongepowered.api.data.persistence.DataContainer) Component(net.minecraft.network.chat.Component)

Example 17 with Component

use of net.minecraft.network.chat.Component in project SpongeCommon by SpongePowered.

the class TranslatableComponentMixin method impl$translateForRendering.

@Inject(method = "visitSelf(Lnet/minecraft/network/chat/FormattedText$StyledContentConsumer;Lnet/minecraft/network/chat/Style;)Ljava/util/Optional;", at = @At("HEAD"), cancellable = true)
private <T> void impl$translateForRendering(final FormattedText.StyledContentConsumer<T> visitor, final Style style, final CallbackInfoReturnable<Optional<T>> ci) {
    final String currentLocale = Minecraft.getInstance().options.languageCode;
    if (!Objects.equals(currentLocale, this.impl$lastLocale)) {
        // retranslate
        this.impl$lastLocale = currentLocale;
        final Locale actualLocale = Locales.of(currentLocale);
        // Only do a deep copy if actually necessary
        if (GlobalTranslator.get().translate(this.key, actualLocale) != null) {
            this.impl$translated = NativeComponentRenderer.apply((Component) this, Locales.of(currentLocale));
        } else {
            this.impl$translated = (Component) this;
        }
    }
    // If the result is a non-translated component, then Adventure found a translation that we should use
    if (!(this.impl$translated instanceof TranslatableComponent)) {
        ci.setReturnValue(this.impl$translated.visitSelf(visitor, style));
    }
}
Also used : Locale(java.util.Locale) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) Component(net.minecraft.network.chat.Component) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 18 with Component

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

the class ContainerTypeTest method onRightClick.

private void onRightClick(PlayerInteractEvent.RightClickBlock event) {
    if (!event.getWorld().isClientSide && event.getHand() == InteractionHand.MAIN_HAND) {
        if (event.getWorld().getBlockState(event.getPos()).getBlock() == Blocks.SPONGE) {
            String text = "Hello World!";
            NetworkHooks.openGui((ServerPlayer) event.getPlayer(), new MenuProvider() {

                @Override
                public AbstractContainerMenu createMenu(int p_createMenu_1_, Inventory p_createMenu_2_, Player p_createMenu_3_) {
                    SimpleContainer inv = new SimpleContainer(9);
                    for (int i = 0; i < inv.getContainerSize(); i++) {
                        inv.setItem(i, new ItemStack(Items.DIAMOND));
                    }
                    return new TestContainer(p_createMenu_1_, inv, text);
                }

                @Override
                public Component getDisplayName() {
                    return new TextComponent("Test");
                }
            }, extraData -> {
                extraData.writeUtf(text);
            });
        }
    }
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) ServerPlayer(net.minecraft.server.level.ServerPlayer) Player(net.minecraft.world.entity.player.Player) AbstractContainerMenu(net.minecraft.world.inventory.AbstractContainerMenu) SimpleContainer(net.minecraft.world.SimpleContainer) ItemStack(net.minecraft.world.item.ItemStack) Component(net.minecraft.network.chat.Component) TextComponent(net.minecraft.network.chat.TextComponent) MenuProvider(net.minecraft.world.MenuProvider) Inventory(net.minecraft.world.entity.player.Inventory)

Example 19 with Component

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

the class PacketHelperImpl method showTabListHeaderFooter.

@Override
public void showTabListHeaderFooter(Player player, String header, String footer) {
    Component cHeader = Handler.componentToNMS(FormattedTextHelper.parse(header, ChatColor.WHITE));
    Component cFooter = Handler.componentToNMS(FormattedTextHelper.parse(footer, ChatColor.WHITE));
    ClientboundTabListPacket packet = new ClientboundTabListPacket(cHeader, cFooter);
    send(player, packet);
}
Also used : Component(net.minecraft.network.chat.Component)

Example 20 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)

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