Posted July 20, 20232 yr well good days form the bedblock class i extract code and made this public static void texto( Player pe, String mensaje){ //Style st = new Style(); pe.displayClientMessage(Component.translatable(mensaje), true); } only works on client side for reasons the plan is to extend this to make a network message to send text from the server side to client side and in the client side change text size and font color for that looks like the format is made using this class Style st = new Style(); i dont find example of this class usage to apply format to the text, the size and color thing thaks for your att
July 20, 20232 yr Author package done Spoiler package mercblk.networking; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.ClickEvent; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Style; import net.minecraft.world.entity.Pose; import net.minecraft.world.entity.player.Player; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class send_display_mensage_locally { String mensaje = ""; int color = 0; int tipo = 0; public send_display_mensage_locally(String mensaje) { this.mensaje = mensaje; } public send_display_mensage_locally(String mensaje, int color) { this.mensaje = mensaje; this.color = color; } public send_display_mensage_locally(String mensaje, int color, int tipo) { this.mensaje = mensaje; this.color = color; this.tipo = tipo; } public send_display_mensage_locally(FriendlyByteBuf buf) { CompoundTag nbt = buf.readNbt(); this.mensaje = nbt.getString("m"); this.color = nbt.getInt("c"); this.tipo = nbt.getInt("t"); } public void toBytes(FriendlyByteBuf buf) { CompoundTag nbt = new CompoundTag(); nbt.putString("m", this.mensaje); nbt.putInt("c", this.color); nbt.putInt("t", this.tipo); buf.writeNbt(nbt); } //ModMessage.sendToPlayer(new send_display_mensage_locally("Mensaje de Prueba" ), (ServerPlayer)pe ); public boolean handle(Supplier<NetworkEvent.Context> supplier) { NetworkEvent.Context context = supplier.get(); context.enqueueWork(() -> { // HERE WE ARE ON THE LOCAL! //Text.translable().fillStyle(Style.EMPTY.withColor(ChatFormatting.RED )); Player pe = Minecraft.getInstance().player;//context.getSender(); //pe.displayClientMessage(Component.translatable(this.mensaje), true);//.fillStyle(Style.EMPTY.withColor(ChatFormatting.RED) ); //Text.translable().fillStyle(Style.EMPTY.withColor(ChatFormatting.RED) ChatFormatting tcolor = ChatFormatting.WHITE; switch(this.color) { case 1: tcolor = ChatFormatting.RED; break; case 2: tcolor = ChatFormatting.GREEN; break; case 3: tcolor = ChatFormatting.BLUE; break; } Boolean bold = (0 == (byte) ((tipo & 1)) ); Boolean underl = (0 == (byte) ((tipo & 2) >> 1) ); //System.out.println( this.mensaje ); //System.out.println( this.tipo + ", bold " + bold ); //System.out.println( this.tipo + ", underl " + underl ); pe.displayClientMessage(Component.translatable(this.mensaje).setStyle(Style.EMPTY.withColor(tcolor).withUnderlined(underl).withBold(bold) ), false); }); return true; } } naa i find a working example and fix it in a the netowrk message package
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.