Navigation

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

    SOLVED TickHandler, effet en portant une armure complète ou avec un bloc en main

    Anciennes versions
    1.6.4
    2
    5
    1705
    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.
    • F
      fireblade51 last edited by

      Bonjours j’aimerai savoir comment faire pour que quand on porte (ex.: une armure complète, juste les bottes, etc…) on est un effet style potion. Aussi, quand on tien un bloc en main on est aussi un effet style potion.

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

        Dans la fonction init de ta classe principale :
        TickRegistry.registerTickHandler(new TonTickHandler(), Side.SERVER);
        Créé la classe ajoute implémentations de la classe ITickHandler (public TaClasse implements ITickHandler), passe la souris sur l’erreur de ta classe, add unimplemented method.
        Dans la fonction getLabel tu mets ce que tu veux (par exemple “modid - ce que le tick handler fait”)
        Dans la fonction public EnumSet <ticktype>ticks() tu mets : return EnumSet.of(TickType.PLAYER);

        Et dans la fonction tickEnd tu ajoutes :
        EntityPlayer player = (EntityPlayer)tickData[0];
        pour avoir l’instance du joueur.
        À partir de ça tu peux faire des conditions du genre if(player.getCurrentItem() != null && player.getCurrentItem().itemID == ClassePrincipale.item.itemID) alors je fais ….
        pense à toujours vérifier en premier que l’itemStack n’est pas null, sinon tu vas avoir un joli crash avec un NPE (NullPointerException)
        Exemple de tick handler ici :
        https://github.com/FFMT/nanotech_mod/blob/master/common/fr/mcnanotech/kevin_68/nanotechmod/main/utils/NanotechServerTickHandler.java
        Il y a même l’exemple avec l’armure, la seul différence c’est que l’effet est fait si le joueur n’a pas l’armure (donc l’inverse de ce que tu cherches à faire).</ticktype>

        1 Reply Last reply Reply Quote 0
        • F
          fireblade51 last edited by

          Merci robin4002 sa marche super bien pour les items en main. Mais j’essaye avec les armures mais sa ne marche pas, je ne comprend pas pourquoi. Voici ma classe TickHandler:

          
          package tuto;
          
          import java.util.EnumSet;
          import java.util.Random;
          
          import net.minecraft.entity.player.EntityPlayer;
          import net.minecraft.item.Item;
          import net.minecraft.item.ItemStack;
          import net.minecraft.potion.Potion;
          import net.minecraft.potion.PotionEffect;
          import net.minecraft.util.MathHelper;
          import net.minecraft.world.WorldServer;
          import cpw.mods.fml.common.FMLCommonHandler;
          import cpw.mods.fml.common.ITickHandler;
          import cpw.mods.fml.common.Loader;
          import cpw.mods.fml.common.TickType;
          
          public class TickHandlerTuto implements ITickHandler {
          
          @Override
          public void tickStart(EnumSet <ticktype>type, Object… tickData) {
          
          }
          
          @Override
          public void tickEnd(EnumSet <ticktype>type, Object... tickData) {
          EntityPlayer player = (EntityPlayer)tickData[0];
          for(int i = 0; i < player.inventory.getSizeInventory(); i++)
          {
          if(player.inventory.getStackInSlot(i) != null)
          {
          if(player.inventory.getStackInSlot(i).itemID == tutomain.block1.blockID)
          {
          player.setFire(1);
          }
          if(player.getCurrentItemOrArmor(0) != null){
          ItemStack hand = player.getCurrentItemOrArmor(0);
          
          if(hand.getItem() == Item.appleRed){
          player.setFire(1);
          }
          if (player.getCurrentArmor(4) != null){
          ItemStack helmet = player.getCurrentArmor(4);
          if (helmet.getItem() == Item.helmetDiamond){
          player.addPotionEffect(new PotionEffect(Potion.blindness.getId(), 500, 10));
          }
          }
          }
          }
          }
          }
          @Override
          public EnumSet <ticktype>ticks() {
          return EnumSet.of(TickType.PLAYER);
          }
          
          @Override
          public String getLabel() {
          return "tuto - bad english";
          }
          
          }
          
          

          Si quelqu’un pourrai me trouvez mon erreur ou une solution se serai parfait. Merci :)</ticktype></ticktype></ticktype>

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

            Utilise player.getCurrentItemOrArmor(4) avec player.getCurrentArmor(int) c’est pas 4, je crois que c’est 0 ou 3.

            1 Reply Last reply Reply Quote 0
            • F
              fireblade51 last edited by

              Super sa marche, il fallait simplement mettre le “TickRegistry.registerTickHandler(new TonTickHandler(), Side.SERVER);” dans le CommonProxy et mettre “proxy.registerServerTickHandler();” dans la classe principal et tout marche maintenant. Merci pour ton aide robin4002 🙂

              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