Affichage message centre d'écran
-
Bonsoir j’ai fais un mod pour afficher des text au centre de l’écran tous fonctionne correctement en solo mais sur mon serveur ça n’a pas l’air de marcher j’ai l’impression que les variables ne prennent pas de valeur sur le serveur voici mes class:
public class CylrpMessageShow { static String msgPlaying = ""; static int msgPlayingUpFor = 0; public static void renderMsg(String message) { msgPlaying = message; msgPlaying = msgPlaying.replaceAll("&", "\u00a7"); msgPlayingUpFor = 1000; System.out.print(msgPlayingUpFor + " " + msgPlaying); } @SubscribeEvent @SideOnly(Side.CLIENT) public void onGuiIngameRender(RenderGameOverlayEvent.Post event) { if (msgPlayingUpFor > 0) { msgPlayingUpFor–; String str; int x; int y; str = "\u00a76[\u00a7eCYLRP\u00a76] " + msgPlaying; x = 220; y = 15; Minecraft.getMinecraft().fontRenderer.drawStringWithShadow(str, x - Minecraft.getMinecraft().fontRenderer.getStringWidth(str) / 2, y, Integer.MAX_VALUE); } } public static class CylrpCommand implements ICommand{ private final List aliases; CylrpMessageShow instance = new CylrpMessageShow(); public CylrpCommand() { aliases = new ArrayList(); aliases.add("cm"); } @Override public int compareTo(Object arg0) { // TODO Auto-generated method stub return 0; } @Override public String getCommandName() { // TODO Auto-generated method stub return "cylrpm"; } @Override public String getCommandUsage(ICommandSender var1) { // TODO Auto-generated method stub return "cylrpm <text>"; } @Override public List getCommandAliases() { // TODO Auto-generated method stub return this.aliases; } @Override public void processCommand(ICommandSender sender, String[] args) { World world = sender.getEntityWorld(); if(!world.isRemote) { if(args.length > 0) { StringBuilder builder = new StringBuilder(); for (int i = 0; i < args.length; i++) { builder.append(args*).append(" "); } msgPlaying = builder.toString(); JobGui.network.sendToAll(new CylrpPacketHandler("message")); } else { sender.addChatMessage(new ChatComponentText("\u00a7cTu dois entrer un message")); return; } } } @Override public boolean canCommandSenderUseCommand(ICommandSender p_71519_1_) { return true; } @Override public List addTabCompletionOptions(ICommandSender p_71516_1_, String[] p_71516_2_) { return null; } @Override public boolean isUsernameIndex(String[] p_82358_1_, int p_82358_2_) { return false; } } }
package fr.ineoxz.craftyourliferp.init; import io.netty.buffer.ByteBuf; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.world.World; import cpw.mods.fml.common.network.ByteBufUtils; import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import fr.ineoxz.craftyourliferp.gui.JobGui; public class CylrpPacketHandler implements IMessage { private String text; public CylrpPacketHandler() { } public CylrpPacketHandler(String text) { this.text = text; } @Override public void fromBytes(ByteBuf buf) { text = ByteBufUtils.readUTF8String(buf); // this class is very useful in general for writing more complex objects } @Override public void toBytes(ByteBuf buf) { ByteBufUtils.writeUTF8String(buf, text); } public static class Handler implements IMessageHandler <cylrppackethandler, imessage="">{ @Override @SideOnly(Side.CLIENT) public IMessage onMessage(CylrpPacketHandler message, MessageContext ctx) { if(message.text.equals("p")) Minecraft.getMinecraft().displayGuiScreen(new ConnectionGui()); if(message.text.equals("message")) { CylrpMessageShow.renderMsg(CylrpMessageShow.msgPlaying); } return null; } ```</cylrppackethandler,></text>
-
rajoute cette condition et met pas ton event en post
if (event.type == RenderGameOverlayEvent.ElementType.CHAT)
-
Tu peux garder le post, ça ne pause pas de problème.
Le problème viens du packet :CylrpMessageShow.renderMsg(CylrpMessageShow.msgPlaying);
La tu ne change pas le message. Il faut untiliser le message du packet.
(ça donne ça : CylrpMessageShow.renderMsg(message.text);)
Et pour que se soit plus optimiser dans l’event, met bien la condition comme l’a dit SpyMan.