Navigation

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    SOLVED OnCreated non appelé

    1.7.x
    1.7.10
    2
    3
    922
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • JustPingo
      JustPingo last edited by

      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 !

      1 Reply Last reply Reply Quote 0
      • robin4002
        robin4002 Administrateurs Rédacteurs Moddeurs confirmés last edited by

        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 Reply Last reply Reply Quote 0
        • JustPingo
          JustPingo last edited by

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

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Design by Woryk
          Contact / Mentions Légales / Faire un don

          MINECRAFT FORGE FRANCE © 2018

          Powered by NodeBB