Système de rang



  • Bonjour,

    Comme l'indique le titre je cherche a faire un système de rang "grade" dans le jeu comme par exemple mettre un joueur Guerrier, Archer etc..

    J'ai commencer la base mais je suis bloqué donc je viens vous voir !

    Extended:

    
    public class LegacyModExtendedProperties implements IExtendedEntityProperties{
    
    public final static String EXT_PROP = "LegacyModProperties";
    
    private final EntityPlayer player;
    
    public EntityPlayer guerrier;
    
    public EntityPlayer mage;
    
    public EntityPlayer archer;
    
        public LegacyModExtendedProperties(EntityPlayer player)
        {
        this.player = player;
    
        this.archer = player;
    
        this.guerrier = player;
    
        this.mage = player;
    
        }
    
    @Override
    public void saveNBTData(NBTTagCompound compound) {
    // TODO Auto-generated method stub
    
    }
    
    @Override
    public void loadNBTData(NBTTagCompound compound) {
    // TODO Auto-generated method stub
    
    }
    
    @Override
    public void init(Entity entity, World world) {
    // TODO Auto-generated method stub
    
    }
    
    }
    
    

    Merci 🙂



  • Tu es bloqué où ?


  • Rédacteurs

    Personnellement je n'utiliserai pas des EEP, d'autant plus que tu es très mal parti. Crée un Enum contenant tes rangs, puis une HashMap <uuid, tonenumderang="">dans laquelle tu stockera les UUID des joueurs ainsi que leurs rang, je ne sais pas comment tu va changer de rang ton joueur mais si cela s'effectue à partir d'une commande les changements seront serveurs seulement, si tu as besoin que le client connaisse son rang il te suffit de lui envoyer un packet lorsque son rang change (et à sa connexion aussi)</uuid,>



  • L'idée de BrokenSwing est meilleure, je pense, sachant qu'avec les EEP il sera impossible (enfin difficile, pas impossible) de voir ou modifier son rang si il est déconnecté.



  • Ok donc j'ai fais sa dite moi si c'est pas mal :
    Au passage pour le changement de grade en gros je fais avec un gui et des boutons donc je pense que le changement va se faire avec des packets a vous de me dire la meilleure solution.

    class:

    
    package net.legacymod.properties;
    
    import java.util.HashMap;
    import java.util.UUID;
    
    import net.minecraft.entity.Entity;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.nbt.NBTTagCompound;
    import net.minecraft.world.World;
    import net.minecraftforge.common.IExtendedEntityProperties;
    
    public class EnumRank{
    
    HashMap <uuid, enumrank="">rank = new HashMap<uuid, enumrank="">();
    
    private final EntityPlayer player;
    
    public EntityPlayer guerrier;
    
    public EntityPlayer mage;
    
    public EntityPlayer archer;
    
        public EnumRank(EntityPlayer player)
        {
        this.player = player;
    
        this.archer = player;
    
        this.guerrier = player;
    
        this.mage = player;
    
        }
    
    }
    
    

    ps: je suis bloqué genre je voudrais faire une fonction setgrade quelle puisse grade le joueur.</uuid,></uuid,>


  • Administrateurs

    Tu ne sais pas ce qu'est un enum.

    package net.legacymod.properties;
    
    import java.util.HashMap;
    import java.util.UUID;
    
    public enum EnumRank
    {
    GUERRIER,
    MAGE,
    ARCHER;
    
    public static final HashMap <uuid, enumrank="">RANK = new HashMap<uuid, enumrank="">();
    }
    ```</uuid,></uuid,>

  • Rédacteurs

    Ton Enum :

    
    public enum EnumRank {
    
    GUERRIER,
    MAGE,
    ARCHER;
    
    }
    
    

    Après il faut que tu crée la HashMap dans le proxy serveur par exemple :

    
    HashMap <uuid, enumrank="">rank = new HashMap<uuid, enumrank="">();
    
    

    Quand je joueur se connecte tu lui envoie son rang avec un paquet, et quand il change aussi tu lui envoie avec le même paquet, vu que tu va changer le rang des joueurs via un Gui, effectivement il va falloir envoyer un paquet au serveur lui disant de modifier le rang, entraînant une update du client concerné</uuid,></uuid,>



  • Ok j'ai compris je crois



  • Je viens de finir  d'apprendre les enum et les hashmap et je vois déjà a quoi il servent  t j'en déduit qu'il sont trés utille c'est pour ça que je t'invite à les comprende 😉



  • Donc la j'ai fais se que tu m'as dis j'ai fais mon enum j'ai créer le hashmap dans le serverproxy .
    Pas de besoin d'envoyer un packet lors de la connexion car moi le joueur dès que il se connecte ça va lui ouvrir un gui et il aura 3 choix de grade et une fois le grade choisis il pourra pas changer.
    Mais le truc c'est que dans mon packet pour passer le joueur par Archer je dois procédé comment ?
    EnumRank.ARCHER me met une erreur et de plus je vois pas comment ça peut grade le joueur^^.


  • Rédacteurs

    En gros tu fais un paquet envoyant un String correspondant à ton rang (ex. EnumRank.ARCHER.name())
    Puis tu récupère côté serveur l'énumération dans le paquet avec EnumRank.valueOf(le String du paquet) et tu le place dans la HashMap, quand tu veux savoir quel est le rang du joueur tu récupère la valeur dans la HashMap



  • Ok j'ai a peu près compris dis moi si c'est bon par contre quand tu me dis de placer l'énumération dans la hashmap je vois pas se que tu veux dire du coup je te passe se que j'ai fais:

    ServerProxy:

    import java.util.HashMap;
    import java.util.UUID;
    
    import net.legacymod.packets.PacketGuerrier;
    import net.legacymod.properties.EnumRank;
    
    public class ServerProxy {
    
    public static final HashMap <uuid, enumrank="">RANK = new HashMap<uuid, enumrank="">();
    
    public ServerProxy(){
    EnumRank.valueOf(PacketGuerrier.name);
    }
    
    }
    

    Packet:

    
    public class PacketGuerrier implements IMessage {
    
    private boolean police;
    public static Minecraft mc;
    public static String name;
    public PacketGuerrier(){
    
    }
    public PacketGuerrier(boolean police, String name, int x, int y, int z){
    this.police = police;
    this.name = name;
    }
    
    @Override
    public void fromBytes(ByteBuf buf) {
    this.police = buf.readBoolean();
    this.name = buf.toString();
    
    }
    
    @Override
    public void toBytes(ByteBuf buf) {
    buf.writeBoolean(this.police);
    this.name = buf.toString();
    
    }
    
    public static class Handler implements IMessageHandler <packetguerrier, imessage="">{
       public IMessage onMessage(PacketGuerrier message, MessageContext ctx) {
    
            EntityPlayer player = mc.thePlayer;
            EnumRank.GUERRIER.name();
            System.out.println("Vous êtes guerrier!");
            return message;
           }
       }
    
    }
    
    ```</packetguerrier,></uuid,></uuid,>

  • Rédacteurs

    Non, c'est pas du tout ça, tu ne sais pas utiliser les paquets, d'autant plus que tu n'utilises pas ta HashMap. Je te conseille de bien lire le tutoriel sur les paquets et lire aussi le sujet sur comment marche minecraft, parce que là, tu va crash et en plus ça va rien faire



  • C'est mieux ?

    
    public class PacketGuerrier implements IMessage {
    
    public static String name;
    
    public PacketGuerrier(){
    
    }
    public PacketGuerrier(String name){
    this.name = name;
    }
    
    @Override
    public void fromBytes(ByteBuf buf) {
    this.name = ByteBufUtils.readUTF8String(buf);
    
    }
    
    @Override
    public void toBytes(ByteBuf buf) {
    ByteBufUtils.writeUTF8String(buf, name);
    
    }
    
    public static class Handler implements IMessageHandler <packetguerrier, imessage="">{
    @Override
       public IMessage onMessage(PacketGuerrier message, MessageContext ctx) {
            EnumRank.GUERRIER.name();
            return message;
           }
       }
    
    ```</packetguerrier,>

  • Rédacteurs

    Presque, il faut que dans la fonction onMessage tu ajoutes le rang à la HashMap avec l'UUID du joueur et tu pourra me montrer comment tu as enregistré ton paquets ?



  • Alors
    J'ai fais ça:

    
    public class PacketGuerrier implements IMessage {
    
    public static String name;
    public static Minecraft mc;
    
    public PacketGuerrier(){
    
    }
    public PacketGuerrier(String name){
    this.name = name;
    }
    
    @Override
    public void fromBytes(ByteBuf buf) {
    this.name = ByteBufUtils.readUTF8String(buf);
    
    }
    
    @Override
    public void toBytes(ByteBuf buf) {
    ByteBufUtils.writeUTF8String(buf, name);
    
    }
    
    public static class Handler implements IMessageHandler <packetguerrier, imessage="">{
    @Override
       public IMessage onMessage(PacketGuerrier message, MessageContext ctx) {
    EntityPlayer player = mc.thePlayer;
            EnumRank.GUERRIER.name();
            ServerProxy.RANK.put(player.getUniqueID(), EnumRank.GUERRIER);
            return message;
           }
       }
    
    }
    
    

    Le packet est enregistrer côté serveur:

    network.registerMessage(PacketGuerrier.Handler.class, PacketGuerrier.class, 1, Side.SERVER);
    

    Et mon ServerProxy qui a mon avis n'est pas bon:

    
    package net.legacymod.proxy;
    
    import java.util.HashMap;
    import java.util.UUID;
    
    import net.legacymod.packets.PacketGuerrier;
    import net.legacymod.properties.EnumRank;
    
    public class ServerProxy {
    
    public static final HashMap <uuid, enumrank="">RANK = new HashMap<uuid, enumrank="">();
    
    public ServerProxy(){
    EnumRank.valueOf(PacketGuerrier.name);
    
    }
    
    }
    
    ```</uuid,></uuid,></packetguerrier,>

  • Rédacteurs

    J'ai la flemme de te faire les bonnes classes, donc je vais essayer de t'expliquer :
    Dans ton paquet tu enlève l'attibut static la variable name et tu enlève la variable mc, pour ce qui est du constructeur tu met ça

    
    public PacketGuerrier(){
    
    }
    
    public PacketGuerrier(EnumRank rank) {
    this.name = rank.name();
    }
    
    

    dans la fonction onMessage tu met ça

    
    public IMessage onMessage(PacketGuerrier message, MessageContext ctx) {
    
    ServerProxy.RANK.put(ctx.getServerHandler().playerEntity.getUniqueID(), EnumRank.valueOf(message.name));
    return null;
    }
    }
    
    

    Et tu enlèves ce que tu as mis dans le constructeur de ton ServerProxy



  • Ok j'ai essayer ça mais j'ai eu un crash:

    
    [17:54:54] [main/INFO] [GradleStart]: Extra: []
    [17:54:54] [main/INFO] [GradleStart]: Running with arguments: [–userProperties, {}, --assetsDir, C:/Users/Admin/.gradle/caches/minecraft/assets, --assetIndex, 1.7.10, --accessToken, {REDACTED}, --version, 1.7.10, --tweakClass, cpw.mods.fml.common.launcher.FMLTweaker, --tweakClass, net.minecraftforge.gradle.tweakers.CoremodTweaker]
    [17:54:54] [main/INFO] [LaunchWrapper]: Loading tweak class name cpw.mods.fml.common.launcher.FMLTweaker
    [17:54:54] [main/INFO] [LaunchWrapper]: Using primary tweak class name cpw.mods.fml.common.launcher.FMLTweaker
    [17:54:54] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.gradle.tweakers.CoremodTweaker
    [17:54:54] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.common.launcher.FMLTweaker
    [17:54:54] [main/INFO] [FML]: Forge Mod Loader version 7.10.85.1291 for Minecraft 1.7.10 loading
    [17:54:54] [main/INFO] [FML]: Java is Java HotSpot(TM) Client VM, version 1.8.0_45, running on Windows 7:x86:6.1, installed at C:\Program Files (x86)\Java\jdk1.8.0_45\jre
    [17:54:54] [main/INFO] [FML]: Managed to load a deobfuscated Minecraft name- we are in a deobfuscated environment. Skipping runtime deobfuscation
    [17:54:54] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.gradle.tweakers.CoremodTweaker
    [17:54:54] [main/INFO] [GradleStart]: Injecting location in coremod cpw.mods.fml.relauncher.FMLCorePlugin
    [17:54:54] [main/INFO] [GradleStart]: Injecting location in coremod net.minecraftforge.classloading.FMLForgePlugin
    [17:54:54] [main/INFO] [LaunchWrapper]: Loading tweak class name cpw.mods.fml.common.launcher.FMLInjectionAndSortingTweaker
    [17:54:54] [main/INFO] [LaunchWrapper]: Loading tweak class name cpw.mods.fml.common.launcher.FMLDeobfTweaker
    [17:54:54] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.gradle.tweakers.AccessTransformerTweaker
    [17:54:54] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.common.launcher.FMLInjectionAndSortingTweaker
    [17:54:54] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.common.launcher.FMLInjectionAndSortingTweaker
    [17:54:54] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.relauncher.CoreModManager$FMLPluginWrapper
    [17:54:54] [main/ERROR] [FML]: The binary patch set is missing. Either you are in a development environment, or things are not going to work!
    [17:54:55] [main/ERROR] [FML]: FML appears to be missing any signature data. This is not a good thing
    [17:54:55] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.relauncher.CoreModManager$FMLPluginWrapper
    [17:54:55] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.common.launcher.FMLDeobfTweaker
    [17:54:55] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.gradle.tweakers.AccessTransformerTweaker
    [17:54:55] [main/INFO] [LaunchWrapper]: Loading tweak class name cpw.mods.fml.common.launcher.TerminalTweaker
    [17:54:55] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.common.launcher.TerminalTweaker
    [17:54:55] [main/INFO] [LaunchWrapper]: Launching wrapped minecraft {net.minecraft.client.main.Main}
    [17:54:55] [main/INFO]: Setting user: Player604
    [17:54:56] [Client thread/INFO]: LWJGL Version: 2.9.1
    [17:54:56] [Client thread/INFO] [MinecraftForge]: Attempting early MinecraftForge initialization
    [17:54:56] [Client thread/INFO] [FML]: MinecraftForge v10.13.2.1291 Initialized
    [17:54:56] [Client thread/INFO] [FML]: Replaced 183 ore recipies
    [17:54:56] [Client thread/INFO] [MinecraftForge]: Completed early MinecraftForge initialization
    [17:54:56] [Client thread/INFO] [FML]: Searching C:\Users\Admin\Documents\Modding\LegacyMod\eclipse\mods for mods
    [17:54:56] [Client thread/INFO] [lc]: Mod lc is missing the required element 'name'. Substituting lc
    [17:54:58] [Client thread/INFO] [FML]: Forge Mod Loader has identified 4 mods to load
    [17:54:58] [Client thread/INFO] [FML]: Attempting connection with missing mods [mcp, FML, Forge, lc] at CLIENT
    [17:54:58] [Client thread/INFO] [FML]: Attempting connection with missing mods [mcp, FML, Forge, lc] at SERVER
    [17:54:58] [Client thread/INFO]: Reloading ResourceManager: Default, FMLFileResourcePack:Forge Mod Loader, FMLFileResourcePack:Minecraft Forge, FMLFileResourcePack:lc, [1.10] Firewolf v1.36.zip
    [17:54:58] [Client thread/INFO] [FML]: Processing ObjectHolder annotations
    [17:54:58] [Client thread/INFO] [FML]: Found 341 ObjectHolder annotations
    [17:54:58] [Client thread/INFO] [FML]: Configured a dormant chunk cache size of 0
    [17:54:58] [Client thread/INFO] [FML]: Applying holder lookups
    [17:54:58] [Client thread/INFO] [FML]: Holder lookups applied
    [17:54:58] [Sound Library Loader/INFO] [STDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: 
    [17:54:58] [Sound Library Loader/INFO] [STDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: Starting up SoundSystem…
    [17:54:58] [Thread-5/INFO] [STDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: Initializing LWJGL OpenAL
    [17:54:58] [Thread-5/INFO] [STDOUT]: [paulscode.sound.SoundSystemLogger:message:69]:     (The LWJGL binding of OpenAL.  For more information, see http://www.lwjgl.org)
    [17:54:58] [Thread-5/INFO] [STDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: OpenAL initialized.
    [17:54:59] [Sound Library Loader/INFO] [STDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: 
    [17:54:59] [Sound Library Loader/INFO]: Sound engine started
    [17:55:01] [Client thread/INFO]: Created: 2048x2048 textures/blocks-atlas
    [17:55:01] [Client thread/INFO]: Created: 256x256 textures/items-atlas
    [17:55:01] [Client thread/INFO] [FML]: Forge Mod Loader has successfully loaded 4 mods
    [17:55:01] [Client thread/INFO]: Reloading ResourceManager: Default, FMLFileResourcePack:Forge Mod Loader, FMLFileResourcePack:Minecraft Forge, FMLFileResourcePack:lc, [1.10] Firewolf v1.36.zip
    [17:55:03] [Client thread/INFO]: Created: 2048x2048 textures/blocks-atlas
    [17:55:03] [Client thread/INFO]: Created: 256x256 textures/items-atlas
    [17:55:03] [Client thread/INFO] [STDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: 
    [17:55:03] [Client thread/INFO] [STDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: SoundSystem shutting down…
    [17:55:03] [Client thread/INFO] [STDOUT]: [paulscode.sound.SoundSystemLogger:importantMessage:90]:     Author: Paul Lamb, www.paulscode.com
    [17:55:03] [Client thread/INFO] [STDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: 
    [17:55:03] [Sound Library Loader/INFO] [STDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: 
    [17:55:03] [Sound Library Loader/INFO] [STDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: Starting up SoundSystem…
    [17:55:04] [Thread-7/INFO] [STDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: Initializing LWJGL OpenAL
    [17:55:04] [Thread-7/INFO] [STDOUT]: [paulscode.sound.SoundSystemLogger:message:69]:     (The LWJGL binding of OpenAL.  For more information, see http://www.lwjgl.org)
    [17:55:04] [Thread-7/INFO] [STDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: OpenAL initialized.
    [17:55:04] [Sound Library Loader/INFO] [STDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: 
    [17:55:04] [Sound Library Loader/INFO]: Sound engine started
    [17:55:08] [Server thread/INFO]: Starting integrated minecraft server version 1.7.10
    [17:55:08] [Server thread/INFO]: Generating keypair
    [17:55:08] [Server thread/INFO] [FML]: Injecting existing block and item data into this server instance
    [17:55:08] [Server thread/INFO] [FML]: Applying holder lookups
    [17:55:08] [Server thread/INFO] [FML]: Holder lookups applied
    [17:55:08] [Server thread/INFO] [FML]: Loading dimension 0 (New World) (net.minecraft.server.integrated.IntegratedServer@1e30337)
    [17:55:08] [Server thread/INFO] [FML]: Loading dimension 1 (New World) (net.minecraft.server.integrated.IntegratedServer@1e30337)
    [17:55:08] [Server thread/INFO] [FML]: Loading dimension -1 (New World) (net.minecraft.server.integrated.IntegratedServer@1e30337)
    [17:55:08] [Server thread/INFO]: Preparing start region for level 0
    [17:55:09] [Server thread/INFO]: Changing view distance to 8, from 10
    [17:55:09] [Netty Client IO #0/INFO] [FML]: Server protocol version 1
    [17:55:09] [Netty IO #1/INFO] [FML]: Client protocol version 1
    [17:55:09] [Netty IO #1/INFO] [FML]: Client attempting to join with 4 mods : FML@7.10.85.1291,lc@1.0,Forge@10.13.2.1291,mcp@9.05
    [17:55:09] [Netty IO #1/INFO] [FML]: Attempting connection with missing mods [] at CLIENT
    [17:55:09] [Netty Client IO #0/INFO] [FML]: Attempting connection with missing mods [] at SERVER
    [17:55:09] [Client thread/INFO] [FML]: [Client thread] Client side modded connection established
    [17:55:09] [Server thread/INFO] [FML]: [Server thread] Server side modded connection established
    [17:55:09] [Server thread/INFO]: Player604[local:E:a526ab7a] logged in with entity id 356 at (-140.53934696846642, 86.27882464665369, 238.05525667116646)
    [17:55:09] [Server thread/INFO]: Player604 joined the game
    [17:55:11] [Server thread/INFO]: Saving and pausing game…
    [17:55:11] [Server thread/INFO]: Saving chunks for level 'New World'/Overworld
    [17:55:11] [Server thread/INFO]: Saving chunks for level 'New World'/Nether
    [17:55:11] [Server thread/INFO]: Saving chunks for level 'New World'/The End
    [17:55:12] [Client thread/ERROR] [FML]: FMLIndexedMessageCodec exception caught
    io.netty.handler.codec.EncoderException: java.lang.NullPointerException
    at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:107) ~[MessageToMessageEncoder.class:?]
    at io.netty.handler.codec.MessageToMessageCodec.write(MessageToMessageCodec.java:116) ~[MessageToMessageCodec.class:?]
    at io.netty.channel.DefaultChannelHandlerContext.invokeWrite(DefaultChannelHandlerContext.java:644) ~[DefaultChannelHandlerContext.class:?]
    at io.netty.channel.DefaultChannelHandlerContext.write(DefaultChannelHandlerContext.java:698) ~[DefaultChannelHandlerContext.class:?]
    at io.netty.channel.DefaultChannelHandlerContext.writeAndFlush(DefaultChannelHandlerContext.java:688) ~[DefaultChannelHandlerContext.class:?]
    at io.netty.channel.DefaultChannelHandlerContext.writeAndFlush(DefaultChannelHandlerContext.java:717) ~[DefaultChannelHandlerContext.class:?]
    at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:893) ~[DefaultChannelPipeline.class:?]
    at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:239) ~[AbstractChannel.class:?]
    at cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper.sendToServer(SimpleNetworkWrapper.java:236) [SimpleNetworkWrapper.class:?]
    at net.legacymod.gui.ClassesGUI.actionPerformed(ClassesGUI.java:86) [ClassesGUI.class:?]
    at net.minecraft.client.gui.GuiScreen.mouseClicked(GuiScreen.java:252) [GuiScreen.class:?]
    at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:344) [GuiScreen.class:?]
    at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:313) [GuiScreen.class:?]
    at net.minecraft.client.Minecraft.runTick(Minecraft.java:1720) [Minecraft.class:?]
    at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1028) [Minecraft.class:?]
    at net.minecraft.client.Minecraft.run(Minecraft.java:951) [Minecraft.class:?]
    at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_45]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_45]
    at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_45]
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]
    at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?]
    at GradleStart.main(Unknown Source) [start/:?]
    Caused by: java.lang.NullPointerException
    at cpw.mods.fml.common.network.ByteBufUtils.writeUTF8String(ByteBufUtils.java:132) ~[ByteBufUtils.class:?]
    at net.legacymod.packets.PacketGuerrier.toBytes(PacketGuerrier.java:36) ~[PacketGuerrier.class:?]
    at cpw.mods.fml.common.network.simpleimpl.SimpleIndexedCodec.encodeInto(SimpleIndexedCodec.java:11) ~[SimpleIndexedCodec.class:?]
    at cpw.mods.fml.common.network.simpleimpl.SimpleIndexedCodec.encodeInto(SimpleIndexedCodec.java:7) ~[SimpleIndexedCodec.class:?]
    at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.encode(FMLIndexedMessageToMessageCodec.java:51) ~[FMLIndexedMessageToMessageCodec.class:?]
    at io.netty.handler.codec.MessageToMessageCodec$1.encode(MessageToMessageCodec.java:67) ~[MessageToMessageCodec$1.class:?]
    at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:89) ~[MessageToMessageEncoder.class:?]
    … 24 more
    [17:55:12] [Client thread/INFO]: [CHAT] §7blablabla: [] §8!
    [17:55:12] [Client thread/ERROR] [FML]: There was a critical exception handling a packet on channel lc:
    io.netty.handler.codec.EncoderException: java.lang.NullPointerException
    at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:107) ~[MessageToMessageEncoder.class:?]
    at io.netty.handler.codec.MessageToMessageCodec.write(MessageToMessageCodec.java:116) ~[MessageToMessageCodec.class:?]
    at io.netty.channel.DefaultChannelHandlerContext.invokeWrite(DefaultChannelHandlerContext.java:644) ~[DefaultChannelHandlerContext.class:?]
    at io.netty.channel.DefaultChannelHandlerContext.write(DefaultChannelHandlerContext.java:698) ~[DefaultChannelHandlerContext.class:?]
    at io.netty.channel.DefaultChannelHandlerContext.writeAndFlush(DefaultChannelHandlerContext.java:688) ~[DefaultChannelHandlerContext.class:?]
    at io.netty.channel.DefaultChannelHandlerContext.writeAndFlush(DefaultChannelHandlerContext.java:717) ~[DefaultChannelHandlerContext.class:?]
    at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:893) ~[DefaultChannelPipeline.class:?]
    at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:239) ~[AbstractChannel.class:?]
    at cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper.sendToServer(SimpleNetworkWrapper.java:236) ~[SimpleNetworkWrapper.class:?]
    at net.legacymod.gui.ClassesGUI.actionPerformed(ClassesGUI.java:86) ~[ClassesGUI.class:?]
    at net.minecraft.client.gui.GuiScreen.mouseClicked(GuiScreen.java:252) ~[GuiScreen.class:?]
    at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:344) ~[GuiScreen.class:?]
    at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:313) ~[GuiScreen.class:?]
    at net.minecraft.client.Minecraft.runTick(Minecraft.java:1720) [Minecraft.class:?]
    at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1028) [Minecraft.class:?]
    at net.minecraft.client.Minecraft.run(Minecraft.java:951) [Minecraft.class:?]
    at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_45]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_45]
    at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_45]
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]
    at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?]
    at GradleStart.main(Unknown Source) [start/:?]
    Caused by: java.lang.NullPointerException
    at cpw.mods.fml.common.network.ByteBufUtils.writeUTF8String(ByteBufUtils.java:132) ~[ByteBufUtils.class:?]
    at net.legacymod.packets.PacketGuerrier.toBytes(PacketGuerrier.java:36) ~[PacketGuerrier.class:?]
    at cpw.mods.fml.common.network.simpleimpl.SimpleIndexedCodec.encodeInto(SimpleIndexedCodec.java:11) ~[SimpleIndexedCodec.class:?]
    at cpw.mods.fml.common.network.simpleimpl.SimpleIndexedCodec.encodeInto(SimpleIndexedCodec.java:7) ~[SimpleIndexedCodec.class:?]
    at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.encode(FMLIndexedMessageToMessageCodec.java:51) ~[FMLIndexedMessageToMessageCodec.class:?]
    at io.netty.handler.codec.MessageToMessageCodec$1.encode(MessageToMessageCodec.java:67) ~[MessageToMessageCodec$1.class:?]
    at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:89) ~[MessageToMessageEncoder.class:?]
    … 24 more
    [17:55:12] [Server thread/INFO]: Player604 lost connection: TextComponent{text='Disconnected', siblings=[], style=Style{hasParent=false, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null}}
    [17:55:12] [Server thread/INFO]: Player604 left the game
    [17:55:12] [Server thread/INFO]: Stopping singleplayer server as player logged out
    [17:55:12] [Server thread/INFO]: Stopping server
    [17:55:12] [Server thread/INFO]: Saving players
    [17:55:12] [Server thread/INFO]: Saving worlds
    [17:55:12] [Server thread/INFO]: Saving chunks for level 'New World'/Overworld
    [17:55:12] [Server thread/INFO]: Saving chunks for level 'New World'/Nether
    [17:55:12] [Server thread/INFO]: Saving chunks for level 'New World'/The End
    [17:55:12] [Server thread/INFO] [FML]: Unloading dimension 0
    [17:55:12] [Server thread/INFO] [FML]: Unloading dimension -1
    [17:55:12] [Server thread/INFO] [FML]: Unloading dimension 1
    [17:55:12] [Server thread/INFO] [FML]: Applying holder lookups
    [17:55:12] [Server thread/INFO] [FML]: Holder lookups applied
    
    

    PacketGuerrier:

    
    public class PacketGuerrier implements IMessage {
    
    public String name;
    
    public PacketGuerrier(){
    
    }
    public PacketGuerrier(EnumRank rank){
    this.name = rank.name();
    }
    
    @Override
    public void fromBytes(ByteBuf buf) {
    this.name = ByteBufUtils.readUTF8String(buf);
    
    }
    
    @Override
    public void toBytes(ByteBuf buf) {
    ByteBufUtils.writeUTF8String(buf, name);//ligne 36
    
    }
    
    public static class Handler implements IMessageHandler <packetguerrier, imessage="">{
    @Override
       public IMessage onMessage(PacketGuerrier message, MessageContext ctx) {
            ServerProxy.RANK.put(ctx.getServerHandler().playerEntity.getUniqueID(), EnumRank.valueOf(message.name));
            return null;
           }
       }
    
    }
    
    

    ClasseGUI:

    
    case 1:
    LegacyMod.network.sendToServer(new PacketGuerrier());//ligne 86
    this.mc.thePlayer.closeScreen();
    break;
    
    ```</packetguerrier,>

  • Rédacteurs

    Il faut que tu mette ça :

    
    LegacyMod.network.sendToServer(new PacketGuerrier(EnumRank.LERANG));
    
    


  • Ok merci c'est nickel !

    EDIT:

    Par contre j'ai un soucis comment je peux faire?
    En gros je voudrais faire que une fois que le joueur a choisis sont rang il ne puisse plus changer.

    J'ai fais ça:

    case 1:
    if(ServerProxy.RANK.values() == null){
    LegacyMod.network.sendToServer(new PacketGuerrier(EnumRank.GUERRIER));
    this.mc.thePlayer.closeScreen();
    EntityPlayer player1 = Minecraft.getMinecraft().thePlayer;
    ChatComponentText text1 = new ChatComponentText("§7blablabla: " + ServerProxy.RANK.values() +" §8!");
    player1.addChatComponentMessage(text1);
    }else{
    this.mc.thePlayer.closeScreen();
    }
    

    Le problème est que quand le joueur n'a pas de grade sa ne return pas null du coup je sais pas comment faire..