MFF

    Minecraft Forge France
    • Récent
    • Mots-clés
    • Populaire
    • Utilisateurs
    • Groupes
    • Forge Events
      • Automatique
      • Foncé
      • Clair
    • S'inscrire
    • Se connecter

    Recuper la variable lorsque le joueur spawn pour la tout première fois.

    Planifier Épinglé Verrouillé Déplacé Résolu 1.7.x
    1.7.x
    39 Messages 5 Publieurs 6.1k Vues 1 Watching
    Charger plus de messages
    • Du plus ancien au plus récent
    • Du plus récent au plus ancien
    • Les plus votés
    Répondre
    • Répondre à l'aide d'un nouveau sujet
    Se connecter pour répondre
    Ce sujet a été supprimé. Seuls les utilisateurs avec les droits d'administration peuvent le voir.
    • robin4002R Hors-ligne
      robin4002 Moddeurs confirmés Rédacteurs Administrateurs
      dernière édition par

      Je ne sais pas nom plus 😕 J’ai jamais vu ce type d’erreur, je ne vois pas d’où ça peut venir. Au pire as-tu vraiment besoin des paquets ?
      Si tu fais juste l’action en serveur, le paquet ne sert à rien. Et sinon tu peux toujours passer par les DataWatcher

      1 réponse Dernière réponse Répondre Citer 0
      • P Hors-ligne
        Portuar
        dernière édition par

        Ouai j’en ai vraiment besoin c’est sa le problème.

        1 réponse Dernière réponse Répondre Citer 0
        • robin4002R Hors-ligne
          robin4002 Moddeurs confirmés Rédacteurs Administrateurs
          dernière édition par

          Dans ce cas passe au DataWatcher.

          1 réponse Dernière réponse Répondre Citer 0
          • P Hors-ligne
            Portuar
            dernière édition par

            et comment je connais pas non plus. Après j’ai trouvé ceci https://github.com/coolAlias/Forge_Tutorials/blob/master/IExtendedEntityPropertiesTutorial.java mais c’est en 1.6.4 et des choses sont inexistantes en 1.7

            1 réponse Dernière réponse Répondre Citer 0
            • robin4002R Hors-ligne
              robin4002 Moddeurs confirmés Rédacteurs Administrateurs
              dernière édition par

              EntityPlayer.getDataWatcher() fonctionne très bien en 1.7, on l’utilise dans nanotech hunger game

              1 réponse Dernière réponse Répondre Citer 0
              • P Hors-ligne
                Portuar
                dernière édition par

                Il y a un tutoriel ? et esque c’est assez simple, c’est à dire qu’on peut créer des fonction comme AddXp() etc?

                1 réponse Dernière réponse Répondre Citer 0
                • robin4002R Hors-ligne
                  robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                  dernière édition par

                  Simple a utiliser, et non il n’y a pas de tuto. Tiens un exemple :

                  package fr.mcnanotech.nhg.common;
                  
                  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 CustomPlayerProperties implements IExtendedEntityProperties
                  {
                  private EntityPlayer player;
                  private int kitId;
                  public static final int KIT_WATCHER = 30;
                  
                  public static final String NAME = "ngh_prop";
                  
                  public CustomPlayerProperties(EntityPlayer player)
                  {
                  this.player = player;
                  this.player.getDataWatcher().addObject(KIT_WATCHER, this.kitId);
                  }
                  
                  @Override
                  public void saveNBTData(NBTTagCompound compound)
                  {
                  compound.setInteger("PlayerKit", this.player.getDataWatcher().getWatchableObjectInt(KIT_WATCHER));
                  }
                  
                  @Override
                  public void loadNBTData(NBTTagCompound compound)
                  {
                  this.player.getDataWatcher().updateObject(KIT_WATCHER, compound.getInteger("PlayerKit"));
                  }
                  
                  @Override
                  public void init(Entity entity, World world)
                  {
                  
                  }
                  
                  public static CustomPlayerProperties get(EntityPlayer player)
                  {
                  return (CustomPlayerProperties)player.getExtendedProperties(NAME);
                  }
                  
                  public int getKitIndex()
                  {
                  return this.player.getDataWatcher().getWatchableObjectInt(KIT_WATCHER);
                  }
                  
                  public void setKit(int kitId)
                  {
                  this.player.getDataWatcher().updateObject(KIT_WATCHER, kitId);
                  }
                  }
                  
                  1 réponse Dernière réponse Répondre Citer 0
                  • P Hors-ligne
                    Portuar
                    dernière édition par

                    et quand le perso meurt il ne restart pas ?


                    Bon j’ai testé et donc j’ai voulut l’utilisé dans un item en faisant props.KIT_WATCHER++; juste pour teste mais il me dise d’enlever final dans : public static final int KIT_WATCHER = 30; mais si je le fait quand je me suicide le jeu crash

                    1 réponse Dernière réponse Répondre Citer 0
                    • robin4002R Hors-ligne
                      robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                      dernière édition par

                      Pour monter de un, setMachin(getMachin + 1)
                      Les setter et getter son la pour ça.
                      KIT_WATCHER n’est pas à modifier, c’est l’id du WATCHER, il faut modifier la valeur du watcher.

                      1 réponse Dernière réponse Répondre Citer 0
                      • P Hors-ligne
                        Portuar
                        dernière édition par

                        ok j’ai testé mais quand je meurt sa reset…

                        1 réponse Dernière réponse Répondre Citer 0
                        • robin4002R Hors-ligne
                          robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                          dernière édition par

                          Alors la je ne sais pas 😕
                          Faudrait demander sur le forum anglais de forge.

                          1 réponse Dernière réponse Répondre Citer 0
                          • P Hors-ligne
                            Portuar
                            dernière édition par

                            JAI ENFIN REUSSI YESSSSSS !

                            1 réponse Dernière réponse Répondre Citer 0
                            • Superloup10S Hors-ligne
                              Superloup10 Modérateurs
                              dernière édition par

                              Tu peux donner la solution pour les autres membres qui auraient le même problème?

                              Si vous souhaitez me faire un don, il vous suffit de cliquer sur le bouton situé en dessous.

                              Je suis un membre apprécié et joueur, j'ai déjà obtenu 17 points de réputation.

                              1 réponse Dernière réponse Répondre Citer 0
                              • P Hors-ligne
                                Portuar
                                dernière édition par

                                ouai :

                                package portuar.otherWorld.client.alteration;
                                
                                import java.util.*;
                                
                                import io.netty.buffer.ByteBuf;
                                import io.netty.buffer.Unpooled;
                                import io.netty.channel.ChannelHandler;
                                import io.netty.channel.ChannelHandlerContext;
                                import io.netty.handler.codec.MessageToMessageCodec;
                                
                                import net.minecraft.client.Minecraft;
                                import net.minecraft.entity.player.EntityPlayer;
                                import net.minecraft.entity.player.EntityPlayerMP;
                                import net.minecraft.network.INetHandler;
                                import net.minecraft.network.NetHandlerPlayServer;
                                
                                import cpw.mods.fml.common.FMLCommonHandler;
                                import cpw.mods.fml.common.network.FMLEmbeddedChannel;
                                import cpw.mods.fml.common.network.FMLOutboundHandler;
                                import cpw.mods.fml.common.network.NetworkRegistry;
                                import cpw.mods.fml.common.network.internal.FMLProxyPacket;
                                import cpw.mods.fml.relauncher.Side;
                                import cpw.mods.fml.relauncher.SideOnly;
                                
                                /**
                                * Packet pipeline class. Directs all registered packet data to be handled by the packets themselves.
                                * @author sirgingalot
                                * some code from: cpw
                                */
                                @ChannelHandler.Sharable
                                public class PacketHandler extends MessageToMessageCodec <fmlproxypacket, abstractpacket="">{
                                
                                private EnumMap <side, fmlembeddedchannel="">channels;
                                private LinkedList<class<? extends="" abstractpacket="">> packets = new LinkedList<class<? extends="" abstractpacket="">>();
                                private boolean isPostInitialised = false;
                                
                                /**
                                * Register your packet with the pipeline. Discriminators are automatically set.
                                *
                                * @param clazz the class to register
                                *
                                * @return whether registration was successful. Failure may occur if 256 packets have been registered or if the registry already contains this packet
                                */
                                public boolean registerPacket(Class clazz) {
                                if (this.packets.size() > 256)
                                {
                                return false;
                                }
                                
                                if (this.packets.contains(clazz))
                                {
                                return false;
                                }
                                
                                if (this.isPostInitialised)
                                {
                                return false;
                                }
                                
                                this.packets.add(clazz);
                                return true;
                                }
                                
                                @Override
                                protected void encode(ChannelHandlerContext ctx, AbstractPacket msg, List <object>out) throws Exception {
                                ByteBuf buffer = Unpooled.buffer();
                                Class clazz = msg.getClass();
                                if (!this.packets.contains(msg.getClass())) {
                                throw new NullPointerException("No Packet Registered for: " + msg.getClass().getCanonicalName());
                                }
                                
                                byte discriminator = (byte) this.packets.indexOf(clazz);
                                buffer.writeByte(discriminator);
                                msg.encodeInto(ctx, buffer);
                                FMLProxyPacket proxyPacket = new FMLProxyPacket(buffer.copy(), ctx.channel().attr(NetworkRegistry.FML_CHANNEL).get());
                                out.add(proxyPacket);
                                }
                                
                                @Override
                                protected void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List <object>out) throws Exception {
                                ByteBuf payload = msg.payload();
                                byte discriminator = payload.readByte();
                                Class clazz = this.packets.get(discriminator);
                                if (clazz == null) {
                                throw new NullPointerException("No packet registered for discriminator: " + discriminator);
                                }
                                
                                AbstractPacket pkt = clazz.newInstance();
                                pkt.decodeInto(ctx, payload.slice());
                                
                                EntityPlayer player;
                                switch (FMLCommonHandler.instance().getEffectiveSide()) {
                                case CLIENT:
                                player = this.getClientPlayer();
                                pkt.handleClientSide(player);
                                break;
                                
                                case SERVER:
                                INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
                                player = ((NetHandlerPlayServer) netHandler).playerEntity;
                                pkt.handleServerSide(player);
                                break;
                                
                                default:
                                }
                                
                                out.add(pkt);
                                }
                                
                                public void initialise() {
                                this.channels = NetworkRegistry.INSTANCE.newChannel("TUT", this);
                                }
                                
                                public void postInitialise() {
                                if (this.isPostInitialised) {
                                return;
                                }
                                
                                this.isPostInitialised = true;
                                Collections.sort(this.packets, new Comparator<class<? extends="" abstractpacket="">>() {
                                
                                @Override
                                public int compare(Class clazz1, Class clazz2) {
                                int com = String.CASE_INSENSITIVE_ORDER.compare(clazz1.getCanonicalName(), clazz2.getCanonicalName());
                                if (com == 0) {
                                com = clazz1.getCanonicalName().compareTo(clazz2.getCanonicalName());
                                }
                                
                                return com;
                                }
                                });
                                }
                                
                                @SideOnly(Side.CLIENT)
                                private EntityPlayer getClientPlayer() {
                                return Minecraft.getMinecraft().thePlayer;
                                }
                                
                                /**
                                * Send this message to everyone.
                                *
                                
                                * Adapted from CPW's code in cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper
                                *
                                * @param message The message to send
                                */
                                public void sendToAll(AbstractPacket message) {
                                this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALL);
                                this.channels.get(Side.SERVER).writeAndFlush(message);
                                }
                                
                                /**
                                * Send this message to the specified player.
                                *
                                
                                * Adapted from CPW's code in cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper
                                *
                                * @param message The message to send
                                * @param player The player to send it to
                                */
                                public void sendTo(AbstractPacket message, EntityPlayerMP player) {
                                this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER);
                                this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(player);
                                this.channels.get(Side.SERVER).writeAndFlush(message);
                                }
                                
                                /**
                                * Send this message to everyone within a certain range of a point.
                                *
                                
                                * Adapted from CPW's code in cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper
                                *
                                * @param message The message to send
                                * @param point The {@link cpw.mods.fml.common.network.NetworkRegistry.TargetPoint} around which to send
                                */
                                public void sendToAllAround(AbstractPacket message, NetworkRegistry.TargetPoint point) {
                                this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALLAROUNDPOINT);
                                this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(point);
                                this.channels.get(Side.SERVER).writeAndFlush(message);
                                }
                                
                                /**
                                * Send this message to everyone within the supplied dimension.
                                *
                                
                                * Adapted from CPW's code in cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper
                                *
                                * @param message The message to send
                                * @param dimensionId The dimension id to target
                                */
                                public void sendToDimension(AbstractPacket message, int dimensionId) {
                                this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.DIMENSION);
                                this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(dimensionId);
                                this.channels.get(Side.SERVER).writeAndFlush(message);
                                }
                                
                                /**
                                * Send this message to the server.
                                *
                                
                                * Adapted from CPW's code in cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper
                                *
                                * @param message The message to send
                                */
                                public void sendToServer(AbstractPacket message) {
                                this.channels.get(Side.CLIENT).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.TOSERVER);
                                this.channels.get(Side.CLIENT).writeAndFlush(message);
                                }
                                }
                                
                                package portuar.otherWorld.client.alteration;
                                
                                import io.netty.buffer.ByteBuf;
                                import io.netty.channel.ChannelHandlerContext;
                                import net.minecraft.entity.player.EntityPlayer;
                                import net.minecraft.nbt.NBTTagCompound;
                                import cpw.mods.fml.common.network.ByteBufUtils;
                                
                                public class PacketAlteration extends AbstractPacket
                                {
                                private NBTTagCompound data;
                                
                                public PacketAlteration() {}
                                
                                public PacketAlteration(EntityPlayer player)
                                {
                                data = new NBTTagCompound();
                                ExtendedEntityPropAlteration.get(player).saveNBTData(data);
                                }
                                
                                @Override
                                public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer)
                                {
                                ByteBufUtils.writeTag(buffer, data);
                                }
                                
                                @Override
                                public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer)
                                {
                                data = ByteBufUtils.readTag(buffer);
                                }
                                
                                @Override
                                public void handleClientSide(EntityPlayer player)
                                {
                                ExtendedEntityPropAlteration.get(player).loadNBTData(data);
                                }
                                
                                @Override
                                public void handleServerSide(EntityPlayer player)
                                {
                                }
                                }
                                

                                Dans la MainClass :

                                @EventHandler
                                public void init(FMLInitializationEvent event)
                                {
                                MinecraftForge.EVENT_BUS.register(new EventAlteration());
                                packetHandler.initialise();
                                }
                                
                                @EventHandler
                                public void postInit(FMLPostInitializationEvent event)
                                {
                                packetHandler.postInitialise();
                                }
                                
                                package portuar.otherWorld.client.alteration;
                                
                                import net.minecraft.entity.player.EntityPlayer;
                                import net.minecraft.nbt.NBTTagCompound;
                                import net.minecraftforge.event.entity.EntityEvent.EntityConstructing;
                                import net.minecraftforge.event.entity.EntityJoinWorldEvent;
                                import net.minecraftforge.event.entity.living.LivingDeathEvent;
                                import portuar.otherWorld.proxy.CommonProxy;
                                import cpw.mods.fml.common.eventhandler.SubscribeEvent;
                                
                                public class EventAlteration
                                {
                                
                                @SubscribeEvent
                                public void onEntityConstructing(EntityConstructing event)
                                {
                                
                                if (event.entity instanceof EntityPlayer && ExtendedEntityPropAlteration.get((EntityPlayer) event.entity) == null)
                                ExtendedEntityPropAlteration.register((EntityPlayer) event.entity);
                                
                                if (event.entity instanceof EntityPlayer && event.entity.getExtendedProperties(ExtendedEntityPropAlteration.EXT_PROP_NAME) == null)
                                event.entity.registerExtendedProperties(ExtendedEntityPropAlteration.EXT_PROP_NAME, new ExtendedEntityPropAlteration((EntityPlayer) event.entity));
                                }
                                
                                public static void register(EntityPlayer player)
                                {
                                player.registerExtendedProperties(ExtendedEntityPropAlteration.EXT_PROP_NAME, new ExtendedEntityPropAlteration(player));
                                }
                                
                                @SubscribeEvent
                                public void onLivingDeathEvent(LivingDeathEvent event)
                                {
                                if (!event.entity.worldObj.isRemote && event.entity instanceof EntityPlayer)
                                {
                                NBTTagCompound playerData = new NBTTagCompound();
                                
                                ((ExtendedEntityPropAlteration)(event.entity.getExtendedProperties(ExtendedEntityPropAlteration.EXT_PROP_NAME))).saveNBTData(playerData);
                                
                                CommonProxy.storeEntityData(((EntityPlayer) event.entity).getCommandSenderName(), playerData);
                                
                                ExtendedEntityPropAlteration.saveProxyData((EntityPlayer) event.entity);
                                }
                                }
                                
                                // we already have this event, but we need to modify it some
                                @SubscribeEvent
                                public void onEntityJoinWorld(EntityJoinWorldEvent event)
                                {
                                if (!event.entity.worldObj.isRemote && event.entity instanceof EntityPlayer)
                                {
                                
                                NBTTagCompound playerData = CommonProxy.getEntityData(((EntityPlayer) event.entity).getCommandSenderName());
                                
                                if (playerData != null)
                                {
                                ((ExtendedEntityPropAlteration)(event.entity.getExtendedProperties(ExtendedEntityPropAlteration.EXT_PROP_NAME))).loadNBTData(playerData);
                                }
                                ((ExtendedEntityPropAlteration)(event.entity.getExtendedProperties(ExtendedEntityPropAlteration.EXT_PROP_NAME))).sync();
                                }
                                }
                                }
                                

                                puis l’extendproperties que vous prenez dans le tuto de ce forum.</class<?></object></object></class<?></class<?></side,></fmlproxypacket,>

                                1 réponse Dernière réponse Répondre Citer 0
                                • 1
                                • 2
                                • 2 / 2
                                • Premier message
                                  Dernier message
                                Design by Woryk
                                ContactMentions Légales

                                MINECRAFT FORGE FRANCE © 2024

                                Powered by NodeBB