Résolu Indicateur de chat
-
Avec l’aide de ce cher Plaigon j’ai enfin réussi a finir l’indicateur de chat (reste plus que le tesselator a configurer pour un résultat propre). Voici le code :
Packets :
:::network = NetworkRegistry.INSTANCE.newSimpleChannel("chatChannel"); network.registerMessage(com.heimnor.packet.IMessageChat.IMessageHandlerChat.class, IMessageChat.class, 1, Side.SERVER); network.registerMessage(com.heimnor.packet.IMessageChatReponse.IMessageHandlerChatReponse.class, IMessageChatReponse.class, 2, Side.CLIENT); network.registerMessage(com.heimnor.packet.IMessageChatClose.IMessageHandlerChatClose.class, IMessageChatClose.class, 3, Side.SERVER); network.registerMessage(com.heimnor.packet.IMessageChatCloseReponse.IMessageHandlerChatReponseClose.class, IMessageChatCloseReponse.class, 4, Side.CLIENT);
:::
IMessageChat :
:::public class IMessageChat implements IMessage { private boolean LivingEventHandler; public IMessageChat() { } public IMessageChat(boolean LivingEventHandler) { this.LivingEventHandler = LivingEventHandler; } @Override public void fromBytes(ByteBuf buf) { this.LivingEventHandler = buf.readBoolean(); } @Override public void toBytes(ByteBuf buf) { buf.writeBoolean(this.LivingEventHandler); } public static class IMessageHandlerChat implements IMessageHandler <imessagechat, imessage="">{ @Override public IMessage onMessage(IMessageChat message, MessageContext ctx) { EntityPlayerMP player = ctx.getServerHandler().playerEntity; Heimnor.network.sendToAll(new IMessageChatReponse(Minecraft.getMinecraft().getSession().getUsername())); return null; } } }
:::
IMessageChatReponse :
:::
public class IMessageChatReponse implements IMessage { private String username; public IMessageChatReponse() { } public IMessageChatReponse(String text) { this.username = text; } @Override public void fromBytes(ByteBuf buf) { ByteBufUtils.readUTF8String(buf); } @Override public void toBytes(ByteBuf buf) { ByteBufUtils.writeUTF8String(buf, username); } public static class IMessageHandlerChatReponse implements IMessageHandler <imessagechatreponse, imessage="">{ @Override public IMessage onMessage(IMessageChatReponse message, MessageContext ctx) { ClientProxy.CHATTING_PLAYERS_USERNAME.add(Minecraft.getMinecraft().getSession().getUsername()); EntityPlayer player = Minecraft.getMinecraft().thePlayer; LivingEventHandler onEvent = new LivingEventHandler(); System.out.print(ClientProxy.CHATTING_PLAYERS_USERNAME); return null; } } }
:::
IMessageChatClose :
:::
public class IMessageChatClose implements IMessage { private boolean ChatGui; public IMessageChatClose() { } public IMessageChatClose(boolean ChatGui) { this.ChatGui = ChatGui; } @Override public void fromBytes(ByteBuf buf) { this.ChatGui = buf.readBoolean(); } @Override public void toBytes(ByteBuf buf) { buf.writeBoolean(this.ChatGui); } public static class IMessageHandlerChatClose implements IMessageHandler <imessagechatclose, imessage="">{ @Override public IMessage onMessage(IMessageChatClose message, MessageContext ctx) { EntityPlayerMP player = ctx.getServerHandler().playerEntity; Heimnor.network .sendToAll(new IMessageChatCloseReponse(Minecraft.getMinecraft().getSession().getUsername())); return null; } } }
:::
IMessagechatCloseReponse :
:::public class IMessageChatCloseReponse implements IMessage { private String username; public IMessageChatCloseReponse() { } public IMessageChatCloseReponse(String text) { this.username = text; } @Override public void fromBytes(ByteBuf buf) { ByteBufUtils.readUTF8String(buf); } @Override public void toBytes(ByteBuf buf) { ByteBufUtils.writeUTF8String(buf, username); } public static class IMessageHandlerChatReponseClose implements IMessageHandler <imessagechatclosereponse, imessage="">{ @Override public IMessage onMessage(IMessageChatCloseReponse message, MessageContext ctx) { ClientProxy.CHATTING_PLAYERS_USERNAME.remove(Minecraft.getMinecraft().getSession().getUsername()); EntityPlayer player = Minecraft.getMinecraft().thePlayer; System.out.println("Message Reçu !"); return null; } } }
:::
L’ArrayList dans le ClientProxy :
public static ArrayList <string>CHATTING_PLAYERS_USERNAME = new ArrayList<string>();
La classe LivingEventHandler :
:::
public class LivingEventHandler { @SubscribeEvent @SideOnly(Side.CLIENT) public void onPlayersChatOpened(KeyInputEvent event) { if (!(Minecraft.getMinecraft().currentScreen instanceof GuiChat) && Keyboard.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindChat.getKeyCode())) { if (Minecraft.getMinecraft().theWorld != null) { Heimnor.network.sendToServer(new IMessageChat(true)); // Packet à envoyer System.out.println("chat ouvert !"); } } } @SubscribeEvent @SideOnly(Side.CLIENT) public void openChatGui(GuiOpenEvent event) { if (event.gui != null && event.gui.getClass().equals(GuiChat.class)) { event.gui = new ChatGui(); System.out.println(event.gui); } } @SideOnly(Side.CLIENT) @SubscribeEvent public void playerRender(RenderPlayerEvent.Pre event) { if (ClientProxy.CHATTING_PLAYERS_USERNAME.contains(event.entityPlayer.getDisplayName())) { RenderManager renderManager = (RenderManager) ObfuscationReflectionHelper.getPrivateValue(Render.class, event.renderer, 1); float x; float scaleFactor = 0.15F / 1.5F; float yOffsetFactor = -0.05F; GL11.glPushMatrix(); GL11.glTranslatef(0.0F, 0.0F - yOffsetFactor, 2.92F); GL11.glNormal3f(0.0F, 1.0F, 0.0F); GL11.glRotatef(renderManager.playerViewY, 0.0F, 1.0F, 0.0F); GL11.glScalef(-scaleFactor, -scaleFactor, scaleFactor); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); Minecraft.getMinecraft().renderEngine .bindTexture(new ResourceLocation("heimnormod", "textures/items/bulle.png")); Tessellator tessellator = Tessellator.instance; tessellator.startDrawingQuads(); tessellator.addVertexWithUV(-16 + 0, -56 + 32, 0.0D, 0.1F, 0.1F); tessellator.addVertexWithUV(-16 + 32, -56 + 32, 0.0D, 0.1F, 0.0F); tessellator.addVertexWithUV(-16 + 32, -56 + 0, 0.0D, 0.0F, 0.0F); tessellator.addVertexWithUV(-16 + 0, -56 + 0, 0.0D, 0.0F, 0.1F); tessellator.draw(); GL11.glPopMatrix(); } } }
:::
ChatGui :
:::
@Override public void onGuiClosed() { Heimnor.network.sendToServer(new IMessageChatClose(true)); } }
:::
Voilà comme je le disais il ne manque qu’a centrer l’image sur le joueur mais sinon c’est parfaitement fonctionnel.
PS: Encore merci à Plaigon pour sa patience et pour avoir pris le temps de m’aider pendant plusieurs heures et d’avoir plusieurs fois frôlé la crise cardiaque lors de mes nombreuses questions. ;)</string></string></imessagechatclosereponse,></imessagechatclose,></imessagechatreponse,></imessagechat,>
-
Aucun problèmes, j’ai bien aimé t’aider surtout que j’avais réalisé un mod très similaire il y a plusieurs semaines.
Au cas où quelqu’un d’autre aurait une question, n’hésitez pas à redemanderPS: mon VDD, c’est Plaigon et non Playgon
ÉDIT: Il y a encore des erreurs qui traînent dans cet extrait de classes, on s’arrangera pour les fix ensemble!
-
Excuse pour le pseudo c’est corrigé