MFF

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

    Erreurs dans mon code ExtendedEntityProp et Packet 1.7.10

    Planifier Épinglé Verrouillé Déplacé Non résolu Sans suite
    1.7.10
    2 Messages 2 Publieurs 229 Vues 2 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.
    • BinaireB Hors-ligne
      Binaire
      dernière édition par

      Bonjour,
      j’ai des erreurs dans mes 2 classes ExtendedEntityPropThirst et PacketThirst après avoir suivi le tutoriel en 1.7.2, voici mes classes :

      ExtendedEntityPropThirst :

      package fr.minecraft.reality.common;
      
      import cpw.mods.fml.common.eventhandler.SubscribeEvent;
      import fr.minecraft.reality.proxy.ClientProxy;
      import fr.minecraft.reality.proxy.CommonProxy;
      import net.minecraft.entity.Entity;
      import net.minecraft.entity.player.EntityPlayer;
      import net.minecraft.entity.player.EntityPlayerMP;
      import net.minecraft.nbt.NBTTagCompound;
      import net.minecraft.world.World;
      import net.minecraftforge.common.IExtendedEntityProperties;
      import net.minecraftforge.event.entity.EntityEvent.EntityConstructing;
      import net.minecraftforge.event.entity.EntityJoinWorldEvent;
      import net.minecraftforge.event.entity.living.LivingDeathEvent;
      
      public class ExtendedEntityPropThirst implements IExtendedEntityProperties
      {   
      	public final static String EXT_PROP_NAME = "ExtPropThirst";
          private final EntityPlayer player;
          public long thirst;
          public long minThirst;
          public long maxThirst;
       
          public ExtendedEntityPropThirst(EntityPlayer player)
          {
              this.player = player;
              this.thirst = 20;
              this.minThirst = 0;
              this.maxThirst = 20;
          }
          
          @Override
          public void saveNBTData(NBTTagCompound compound)
          {
              NBTTagCompound properties = new NBTTagCompound();
              properties.setLong("Thirst", this.thirst);
              properties.setLong("MinThirst", this.minThirst);
              properties.setLong("MaxThirst", this.maxThirst);
              compound.setTag(EXT_PROP_NAME, properties);
          }
      
          @Override
          public void loadNBTData(NBTTagCompound compound)
          {
              NBTTagCompound properties = (NBTTagCompound) compound
                      .getTag(EXT_PROP_NAME);
              this.thirst = properties.getLong("Thirst");
              this.minThirst = properties.getLong("MinThirst");
              this.maxThirst = properties.getLong("MaxThirst");
          }
      
       
      
          @Override
      
          public void init(Entity entity, World world) {
      
              // TODO Auto-generated method stub
      
          }
          
          public static final void register(EntityPlayer player)
          {
          	player.registerExtendedProperties(ExtendedEntityPropThirst.EXT_PROP_NAME,
          	new ExtendedEntityPropThirst(player));
          }
         
          public static final ExtendedEntityPropThirst get(EntityPlayer player)
          {
          	return (ExtendedEntityPropThirst) player.getExtendedProperties(EXT_PROP_NAME);
          }
          
          public final void sync()
          {
              PacketThirst packetThirst = new PacketThirst(this.minThirst, this.maxThirst, this.thirst);
              ModReality.modRealityPacketHandler.sendToServer(packetThirst);
      
              if (!player.worldObj.isRemote)
              {
                  EntityPlayerMP player1 = (EntityPlayerMP) player;
                  ModReality.modRealityPacketHandler.sendTo(packetThirst, player1);
              }
          }
          
          private static String getSaveKey(EntityPlayer player)
          {
              return player.getDisplayName() + ":" + EXT_PROP_NAME;
          }
          
          public static void saveProxyData(EntityPlayer player) {
      
              ExtendedEntityPropThirst playerData = ExtendedEntityPropThirst.get(player);
      
              NBTTagCompound savedData = new NBTTagCompound();
      
       
      
              playerData.saveNBTData(savedData);
      
              CommonProxy.storeEntityData(getSaveKey(player), savedData);
      
          }
      
       
      
          public static void loadProxyData(EntityPlayer player) {
      
              ExtendedEntityPropThirst playerData = ExtendedEntityPropThirst.get(player);
      
              NBTTagCompound savedData = CommonProxy
                      .getEntityData(getSaveKey(player));
              
              if (savedData != null)
              {
              	playerData.loadNBTData(savedData);
              }
              playerData.sync();
          }
          
          @SubscribeEvent
          public void onEntityConstructing(EntityConstructing event)
          {
              if (event.entity instanceof EntityPlayer && ExtendedEntityPropThirst.get((EntityPlayer) event.entity) == null)
              {
                  ExtendedEntityPropThirst.register((EntityPlayer) event.entity);
              }
          }
          
          @SubscribeEvent
      
          public void onLivingDeathEvent(LivingDeathEvent event) {
      
              if (!event.entity.worldObj.isRemote && event.entity instanceof EntityPlayer)
              {
                  NBTTagCompound playerData = new NBTTagCompound();
                  ((ExtendedEntityPropThirst) (event.entity
                          .getExtendedProperties(ExtendedEntityPropThirst.EXT_PROP_NAME)))
                          .saveNBTData(playerData);
                  ClientProxy.storeEntityData(
                          ((EntityPlayer) event.entity).getDisplayName(), playerData);
                  ExtendedEntityPropThirst.saveProxyData((EntityPlayer) event.entity);
              }
              
              else
              {
      
              }
          }
          
          @SubscribeEvent
      
          public void onEntityJoinWorld(EntityJoinWorldEvent event)
          {
              if (!event.entity.worldObj.isRemote && event.entity instanceof EntityPlayer)
              {
                  NBTTagCompound playerData = ClientProxy
                          .getEntityData(((EntityPlayer) event.entity)
                                  .getDisplayName());
                  if (playerData != null)
                  {
                      ((ExtendedEntityPropThirst) (event.entity
                              .getExtendedProperties(ExtendedEntityPropThirst.EXT_PROP_NAME)))
                              .loadNBTData(playerData);
                  }
      
                  ((ExtendedEntityPropThirst) (event.entity
                          .getExtendedProperties(ExtendedEntityPropThirst.EXT_PROP_NAME)))
                          .sync();
              }
          }
      }
      

      PacketThirst :

      package fr.minecraft.reality.common;
      
      import io.netty.buffer.ByteBuf;
      import io.netty.channel.ChannelHandlerContext;
      import net.minecraft.entity.player.EntityPlayer;
      import net.minecraft.network.Packet;
      
      public abstract class PacketThirst extends Packet{
      
          private long minThirst, maxThirst, thirst;
          
          public PacketThirst()
          {
          	
          }
      
          public PacketThirst(long maxMoney, long money)
          {
          	this.minThirst = minThirst;
              this.maxThirst = maxThirst;
              this.thirst = thirst;
      
          }
      
          public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer)
          {
              buffer.writeLong(minThirst);
              buffer.writeLong(maxThirst);
              buffer.writeLong(thirst);
          }
      
       
      
          public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer)
          {
              this.minThirst = buffer.readLong();
              this.maxThirst = buffer.readLong();
              this.thirst = buffer.readLong();
          }
      
          public void handleClientSide(EntityPlayer player)
          {
              ExtendedEntityPropThirst props = ExtendedEntityPropThirst.get(player);	
              props.minThirst = this.minThirst;
              props.maxThirst = this.maxThirst;
              props.thirst = this.thirst;
      
          }
      
       
          public void handleServerSide(EntityPlayer player) {
      
              ExtendedEntityPropThirst props = ExtendedEntityPropThirst.get(player);
              props.minThirst = this.minThirst;
              props.maxThirst = this.maxThirst;
              props.thirst = this.thirst;
          }
      }
      

      Mes erreurs sont :

      Pour la première classe :

      • ligne 75 (PacketThirst, explication selon eclipse : “Cannot instantiate the type PacketThirst”)

      • ligne 76 (modRealityPacketHandler, explication selon Eclipse : “modRealityPacketHandler cannot be resolved or is not a field”)

      • ligne 81 (modRealityPacketHandler, explication selon Eclipse : “modRealityPacketHandler cannot be resolved or is not a field”)

      Pour la deuxième classe :

      • lignes 19, 20 et 21 (toute la ligne, explication selon Eclipse : “The assignment to variable minThirst has no effect”)

      Merci d’avance

      Ps: pour les erreurs “modRealityPacketHandler” de la première classe Je sais qu’il faut que je créer des méthodes mais je ne sais pas lesquelles.

      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

        Bonsoir,

        Suis plutôt ce tutoriel pour les paquets : https://www.minecraftforgefrance.fr/topic/1000/1-7-2-le-network

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

        MINECRAFT FORGE FRANCE © 2024

        Powered by NodeBB