MFF

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

    Problème de Quantité Dropé en fonction d'un outils

    Planifier Épinglé Verrouillé Déplacé Résolu 1.7.x
    1.7.x
    12 Messages 4 Publieurs 2.6k 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.
    • Antoine_A Hors-ligne
      Antoine_
      dernière édition par

      Merci pour ton aide j’ai essayé ceci comme tu ma dit mais sans succès:

      public int quantityDropped(int meta, Random random, int fortune)
      {
      if(Minecraft.getMinecraft().thePlayer.inventory.getCurrentItem() != null && Minecraft.getMinecraft().thePlayer.inventory.getCurrentItem().getItem() == Modbucheron.hachebucheron01)
      {
      return 5;
      }
      if(Minecraft.getMinecraft().thePlayer.inventory.getCurrentItem() != null && Minecraft.getMinecraft().thePlayer.inventory.getCurrentItem().getItem() == Modbucheron.hachebucheron02)
      {
      return 10;
      }
      return fortune;
      }
      

      Je ne drop que 1 bloc à chaque fois.

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

        Salut,

        override cette méthode de la class Block :

        public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
        

        Il faut surtout pas utiliser ça marche en serveur ça, ça à l’air un peu sale

        Minecraft.getMinecraft().thePlayer
        
        1 réponse Dernière réponse Répondre Citer 0
        • DeletedD Hors-ligne
          Deleted
          dernière édition par

          @Spooky : Il est en 1.7

          Sa serait donc plutôt celle-ci

          
          public void onBlockHarvested(World p_149681_1_, int p_149681_2_, int p_149681_3_, int p_149681_4_, int p_149681_5_, EntityPlayer p_149681_6_) {}
          
          

          Mais je ne pense pas que ça fera grand chose

          Au pire t’as soit les event, soit cette méthode

          
          public void breakBlock(World p_149749_1_, int p_149749_2_, int p_149749_3_, int p_149749_4_, Block p_149749_5_, int p_149749_6_)
          
          

          Rajoute juste dedans une boucle for pour faire spawn un Item.

          EDIT = J’ai regardé vite fait, la méthode que je t’ai dite n’est appelée que côté server, du coup ce n’est pas adapté pour get le joueur. Les event restent donc la meilleure idée. Là, en l’occurrence, tu as besoin de l’event BreakEvent. Il est sur le Bus MinecraftForge. Donc fais bien attention quand t’enregistreras ta classe d’event, mets bien ceci

          
          [font=monospaceMinecraftForge][font=monospace.][font=monospaceEVENT_BUS][font=monospace.][font=monospace**register**][font=monospace(][font=monospace**new**] [font=monospaceClasseAvecTousVosEvent][font=monospace());]
          
          
          1 réponse Dernière réponse Répondre Citer 1
          • Antoine_A Hors-ligne
            Antoine_
            dernière édition par

            J’ai voulu passer par un event pour résoudre le problème donc voici ma classe de mon event

            @SubscribeEvent
            public void onBlockDestroyed(BreakEvent event)
            {
            if (event.block == Modbucheron.boisdegris&& Minecraft.getMinecraft().thePlayer.inventory.getCurrentItem() != null && Minecraft.getMinecraft().thePlayer.inventory.getCurrentItem().getItem() == Modbucheron.hachebucheron01)
            {
            event.getPlayer().inventory.addItemStackToInventory(new ItemStack(Modbucheron.boisgris, 10));
            }
            }
            
            

            Donc en solo tout fonctionne l’event give bien 10 bois mais en multi j’ai un beau crash report:

            –-- Minecraft Crash Report ----
            // Everything's going to plan. No, really, that was supposed to happen.
            
            Time: 9/19/15 4:54 PM
            Description: Exception in server tick loop
            
            java.lang.NoClassDefFoundError: net/minecraft/client/Minecraft
            at events.Eventfaim.onBlockDestroyed(Eventfaim.java:33)
            at cpw.mods.fml.common.eventhandler.ASMEventHandler_21_Eventfaim_onBlockDestroyed_BreakEvent.invoke(.dynamic)
            at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54)
            at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:138)
            at net.minecraftforge.common.ForgeHooks.onBlockBreakEvent(ForgeHooks.java:479)
            at net.minecraft.server.management.ItemInWorldManager.func_73084_b(ItemInWorldManager.java:319)
            at net.minecraft.server.management.ItemInWorldManager.func_73074_a(ItemInWorldManager.java:185)
            at net.minecraft.network.NetHandlerPlayServer.func_147345_a(NetHandlerPlayServer.java:732)
            at net.minecraft.network.play.client.C07PacketPlayerDigging.func_148833_a(SourceFile:53)
            at net.minecraft.network.play.client.C07PacketPlayerDigging.func_148833_a(SourceFile:8)
            at net.minecraft.network.NetworkManager.func_74428_b(NetworkManager.java:244)
            at net.minecraft.network.NetworkSystem.func_151269_c(NetworkSystem.java:173)
            at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:991)
            at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:431)
            at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:809)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:669)
            at java.lang.Thread.run(Thread.java:745)
            Caused by: java.lang.ClassNotFoundException: net.minecraft.client.Minecraft
            at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:191)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
            ... 17 more
            Caused by: java.lang.RuntimeException: Attempted to load class bao for invalid side SERVER
            at cpw.mods.fml.common.asm.transformers.SideTransformer.transform(SideTransformer.java:51)
            at net.minecraft.launchwrapper.LaunchClassLoader.runTransformers(LaunchClassLoader.java:279)
            at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:176)
            ... 19 more
            
            
            1 réponse Dernière réponse Répondre Citer 0
            • DeletedD Hors-ligne
              Deleted
              dernière édition par

              Ligne 33 de ta classe Eventfaim ?

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

                ah oui la classe complète sorry

                package events;
                
                import mods.TutoMod;
                import net.minecraft.client.Minecraft;
                import net.minecraft.entity.EntityLivingBase;
                import net.minecraft.init.Items;
                import net.minecraft.item.ItemStack;
                import net.minecraft.potion.Potion;
                import net.minecraft.potion.PotionEffect;
                import net.minecraftforge.client.event.RenderGameOverlayEvent;
                import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
                import net.minecraftforge.event.entity.player.PlayerEvent;
                import net.minecraftforge.event.world.BlockEvent.BreakEvent;
                import cpw.mods.fml.common.eventhandler.SubscribeEvent;
                import cpw.mods.fml.common.network.simpleimpl.IMessage;
                import cpw.mods.fml.relauncher.Side;
                import cpw.mods.fml.relauncher.SideOnly;
                
                public class Eventfaim
                {
                @SideOnly(Side.CLIENT)
                @SubscribeEvent
                public void maskfaimBar(RenderGameOverlayEvent.Pre event)
                {
                if(event.type == ElementType.FOOD)
                {
                event.setCanceled(true);
                }
                }
                @SubscribeEvent
                public void onBlockDestroyed(BreakEvent event)
                {
                if (event.block == TutoMod.boisdegris&& Minecraft.getMinecraft().thePlayer.inventory.getCurrentItem() != null && Minecraft.getMinecraft().thePlayer.inventory.getCurrentItem().getItem() == Modbucheron.hachebucheron01)
                {
                event.getPlayer().inventory.addItemStackToInventory(new ItemStack(Modbucheron.boisgris, 10));
                }
                }
                }
                
                
                1 réponse Dernière réponse Répondre Citer 0
                • DeletedD Hors-ligne
                  Deleted
                  dernière édition par

                  Plutôt comme ça

                  
                  @SubscribeEvent
                  public void onBlockDestroyed(BreakEvent event)
                  {
                  if (event.block == TutoMod.boisdegris&& event.getPlayer().inventory.getCurrentItem() != null && event.getPlayer().inventory.getCurrentItem().getItem() == Modbucheron.hachebucheron01) 
                  {
                  event.getPlayer().inventory.addItemStackToInventory(new ItemStack(Modbucheron.boisgris, 10));
                  }
                  }
                  
                  

                  Après je ne sais pas si la méthode addItemStackToInventory est appelée sur le serveur ou si ce n’est que le client. Au cas où elle présenterait des bugs, fais carrément une instance d’EntityItem, tu set le delayBeforeCanPickup à 0, tu fais une boucle for qui va jusque’à 10 et uqi permettra au code du spawn (qui aura les mêmes coordonnées du joueur) de se répéter. Si tu as dû mal à comprendre, dis-le moi je t’enverrai le code 😉

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

                    Merci Beaucoup je passe sur résolu j’ai un peu de boulot maintenant 😉

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

                      Mais normalement le code actuel n’est pas fonctionnel : casse le block, ensuite tu croies que ça t’as bien donné les 10 items mais déco-reco et reviens dans le monde et tu t’apercevras que le slot est vide…

                      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

                        Non, le dernier code donné est bon.

                        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