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

    Résolu Crash lors d'un give via la casse d'un bloc

    1.7.x
    1.7.10
    3
    10
    1066
    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.
    • S
      Spiiry24 dernière édition par

      Bonjour, en fait sa fais un moment j’essaye de chercher comment un bloc peut me give un item quand je le casse j’ai trouver mais quand je le fais un test serveur quand je casse le bloc le serveur crash 😕 Tenez la class du block:

      
      package fr.unitylife.spiiry24.blocks;
      
      import java.util.ArrayList;
      import java.util.Random;
      
      import fr.unitylife.spiiry24.common.UnityLifeRP;
      import net.minecraft.block.BlockBush;
      import net.minecraft.block.material.Material;
      import net.minecraft.client.Minecraft;
      import net.minecraft.init.Items;
      import net.minecraft.item.ItemStack;
      import net.minecraft.world.IBlockAccess;
      import net.minecraft.world.World;
      import net.minecraftforge.common.IShearable;
      
      public class BlockPoire extends BlockBush implements IShearable
      {
      
          public Random rand = new Random();
      
          public void onBlockDestroyedByPlayer(World world, int x, int y, int z, int l){
              if(!world.isRemote){
                  Minecraft.getMinecraft().thePlayer.inventory.addItemStackToInventory(new ItemStack(UnityLifeRP.Poire, 1 + rand.nextInt(2)));
      
                  world.setBlock(x, y, z, UnityLifeRP.BlockPoire, 0, 2);
              }
          }
      
          public BlockPoire(Material material)
          {
              super(material);
              setCreativeTab(UnityLifeRP.unitylifeCreativeTabs);
              setBlockBounds(0.1F, 0.0F, 0.1F, 0.9F, 0.8F, 0.9F);
          }
      
          @Override
          public boolean isShearable(ItemStack paramItemStack, IBlockAccess paramIBlockAccess, int xparamInt1, int xparamInt2, int xparamInt3)
          {
              return false;
          }
      
          @Override
          public ArrayList <itemstack>onSheared(ItemStack paramItemStack, IBlockAccess paramIBlockAccess, int xparamInt1, int xparamInt2, int xparamInt3, int paramInt4)
          {
              return null;
          }
      
      }
      
      

      Et voilà merci de me répondre ua plus vite :D</itemstack>

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

        Le problème est que “Minecraft.getMinecraft().thePlayer” n’existe pas coté serveur. Il faut donc que tu utilise une autre méthode ou un event. (Tu devrai essayer la méthode harvestBlock ou l’event “BlockEvent.BreakEvent”)

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

          Avec le harvestBlock je ne peut pas faire se que je veux faire…___Et comment puis-je utiliser un event pour faire se que je veut faire ?

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

            Attention au double poste. (règlement : règle 7 )
            Tu peut peut-être utiliser la méthode “onHarvestBlock”.
            Sinon, pour l’event, il y a des tutoriels (il y as même une sous-section rien que pour ça) donc je te laisse chercher.

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

              J’ai essayé avec la méthode “onHarvestBlock” et le bloc ne réapparaît pas et ne give plus l’item… j’aimerais bien le faire sans event mais si c’est impossible j’utiliserais des events

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

                Utilises cette fonction :

                public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean willHarvest)
                {
                
                }
                
                1 réponse Dernière réponse Répondre Citer 0
                • S
                  Spiiry24 dernière édition par

                  Le serveur crash toujour….

                  
                  package fr.unitylife.spiiry24.blocks;
                  
                  import java.util.ArrayList;
                  import java.util.Random;
                  
                  import fr.unitylife.spiiry24.common.UnityLifeRP;
                  import net.minecraft.block.BlockBush;
                  import net.minecraft.block.material.Material;
                  import net.minecraft.client.Minecraft;
                  import net.minecraft.entity.player.EntityPlayer;
                  import net.minecraft.init.Items;
                  import net.minecraft.item.ItemStack;
                  import net.minecraft.world.IBlockAccess;
                  import net.minecraft.world.World;
                  import net.minecraftforge.common.IShearable;
                  
                  public class BlockPoire extends BlockBush implements IShearable
                  {
                  
                  public Random rand = new Random();
                  
                  public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean willHarvest)
                  {
                  if(!world.isRemote){
                  Minecraft.getMinecraft().thePlayer.inventory.addItemStackToInventory(new ItemStack(UnityLifeRP.Poire, 1 + rand.nextInt(2)));
                  
                  world.setBlock(x, y, z, UnityLifeRP.BlockPoire, 0, 2);
                  }
                  return willHarvest;
                  }
                  
                  public BlockPoire(Material material)
                  {
                  super(material);
                  setCreativeTab(UnityLifeRP.unitylifeCreativeTabs);
                  setBlockBounds(0.1F, 0.0F, 0.1F, 0.9F, 0.8F, 0.9F);
                  }
                  
                  @Override
                  public boolean isShearable(ItemStack paramItemStack, IBlockAccess paramIBlockAccess, int xparamInt1, int xparamInt2, int xparamInt3)
                  {
                  return false;
                  }
                  
                  @Override
                  public ArrayList <itemstack>onSheared(ItemStack paramItemStack, IBlockAccess paramIBlockAccess, int xparamInt1, int xparamInt2, int xparamInt3, int paramInt4)
                  {
                  return null;
                  }
                  
                  }
                  
                  ```</itemstack>
                  1 réponse Dernière réponse Répondre Citer 0
                  • LeBossMax2
                    LeBossMax2 dernière édition par

                    @‘Spiiry24’:

                    Le serveur crash toujour….

                    
                    package fr.unitylife.spiiry24.blocks;
                    
                    import java.util.ArrayList;
                    import java.util.Random;
                    
                    import fr.unitylife.spiiry24.common.UnityLifeRP;
                    import net.minecraft.block.BlockBush;
                    import net.minecraft.block.material.Material;
                    import net.minecraft.client.Minecraft;
                    import net.minecraft.entity.player.EntityPlayer;
                    import net.minecraft.init.Items;
                    import net.minecraft.item.ItemStack;
                    import net.minecraft.world.IBlockAccess;
                    import net.minecraft.world.World;
                    import net.minecraftforge.common.IShearable;
                    
                    public class BlockPoire extends BlockBush implements IShearable
                    {
                       
                       public Random rand = new Random();
                       
                       public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean willHarvest)
                       {
                           if(!world.isRemote){
                               Minecraft.getMinecraft().thePlayer.inventory.addItemStackToInventory(new ItemStack(UnityLifeRP.Poire, 1 + rand.nextInt(2)));
                               
                               world.setBlock(x, y, z, UnityLifeRP.BlockPoire, 0, 2);
                           }
                           return willHarvest;
                       }
                       
                       
                       public BlockPoire(Material material)
                       {
                           super(material);
                           setCreativeTab(UnityLifeRP.unitylifeCreativeTabs);
                           setBlockBounds(0.1F, 0.0F, 0.1F, 0.9F, 0.8F, 0.9F);
                       }
                    
                       @Override
                       public boolean isShearable(ItemStack paramItemStack, IBlockAccess paramIBlockAccess, int xparamInt1, int xparamInt2, int xparamInt3)
                       {
                           return false;
                       }
                    
                       @Override
                       public ArrayList <itemstack>onSheared(ItemStack paramItemStack, IBlockAccess paramIBlockAccess, int xparamInt1, int xparamInt2, int xparamInt3, int paramInt4)
                       {
                           return null;
                       }
                       
                    }
                    
                    ```</itemstack>
                    

                    Le méthode “removedByPlayer” permet d’avoir directement le joueur sans passer par “Minecraft.getMinecraft().thePlayer” qui fait craché le jeu il faut donc que tu utilise “player” à la place.
                    (Ps, merci robin, tu viens de m’apprendre une nouvelle fonction !)

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

                      Minecraft.getMinecraft() ne doit JAMAIS être utilisé dans une classe commune ou serveur.
                      Tu as player en argument dans la fonction, donc pas besoin de Minecraft.getMinecraft().thePlayer

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

                        Merci sa fonctionne !

                        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