• S'inscrire
    • Se connecter
    • Recherche
    • Récent
    • Mots-clés
    • Populaire
    • Utilisateurs
    • Groupes

    Résolu OnCreated non appelé

    1.7.x
    1.7.10
    2
    3
    984
    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.
    • JustPingo
      JustPingo dernière édition par

      Salut !

      public class ItemSatelliteIdentifier extends Item implements IMedia {
      
      public void onCreated(ItemStack stack, World world, EntityPlayer player) {
      System.out.println("onCreated");
         stack.stackTagCompound = new NBTTagCompound();
         stack.stackTagCompound.setBoolean("hasSatellite", false);
         stack.stackTagCompound.setBoolean("hasLabel", false);
      }
      
      @SuppressWarnings({ "unchecked", "rawtypes" })
      public void addInformation(ItemStack stack, EntityPlayer player, List info, boolean par4) {
         if (stack.stackTagCompound != null) {
          if (stack.stackTagCompound.getBoolean("hasLabel")) {
          info.add(EnumChatFormatting.WHITE + stack.stackTagCompound.getString("label"));
          }
          if (stack.stackTagCompound.getBoolean("hasSatellite")) {
          info.add(EnumChatFormatting.DARK_GRAY + stack.stackTagCompound.getString("satellite"));
          }
         }
      }
      
      @Override
      public String getLabel(ItemStack stack) {
      if (stack.stackTagCompound != null) if (stack.stackTagCompound.getBoolean("hasLabel")) return stack.stackTagCompound.getString("label");
      return null;
      }
      
      @Override
      public boolean setLabel(ItemStack stack, String label) {
      if (stack.stackTagCompound != null && label != null) {
      if (label == "") { stack.stackTagCompound.setBoolean("hasLabel", false); return true; }
      if (!stack.stackTagCompound.getBoolean("hasLabel")) stack.stackTagCompound.setBoolean("hasLabel", true);
      stack.stackTagCompound.setString("label", label); return true;
      }
      return false;
      }
      
      @Override
      public String getAudioTitle(ItemStack stack) {
      return null;
      }
      
      @Override
      public String getAudioRecordName(ItemStack stack) {
      return null;
      }
      
      @Override
      public IMount createDataMount(ItemStack stack, World world) {
      return null;
      }
      
      }
      

      Cependant, lorsque je sors mon item du créatif, onCreated n’est pas appelé (inutile d’expliquer les crashs que ça provoque).

      Comment puis-je faire que ça marche, qu’ai-je fait de mal ?

      Merci d’avance !


      Über Networking Antennas

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

        onCreated est appelé uniquement lors du craft de l’item, c’est voulu.
        Ce qui faut faire, c’est regardé si stack.getTagCompound() est null, si non tu fais ton action, si oui tu mets la valeur par défaut.

        1 réponse Dernière réponse Répondre Citer 0
        • JustPingo
          JustPingo dernière édition par

          Ok c’est bon, merci. J’ai mis un check de stack.stackTagCompound dans onUpdate.


          Über Networking Antennas

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

          MINECRAFT FORGE FRANCE © 2018

          Powered by NodeBB