MFF

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

    Houe de repantation

    Planifier Épinglé Verrouillé Déplacé Résolu 1.12.x
    1.12.2
    5 Messages 2 Publieurs 301 Vues 2 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.
    • FeedBackF Hors-ligne
      FeedBack
      dernière édition par

      Bonjour,
      J’essaie de créer une houe qui replante en faisant clic droit mais l’item ne spawn pas et le block reste comme tel.

      public class ItemMagicHoe extends ItemHoe implements IHasModel
      {
          public ItemMagicHoe(String name, ToolMaterial material)
          {
              super(material);
              setUnlocalizedName(name);
              setRegistryName(name);
              setCreativeTab(CreativeTabs.MATERIALS);
              ItemInit.ITEMS.add(this);
          }
          
          @Override
          public void registerModels()
          {
              Main.proxy.registerItemRederer(this, 0);
          }
          
          @Override
          public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
          {
              IBlockState iblockstate = worldIn.getBlockState(pos);
              Block block = iblockstate.getBlock();
              
              if(block instanceof BlockCrops && !worldIn.isRemote)
              {
                  if(block.equals(Blocks.POTATOES) && block.getBlockState().getBaseState() == block.getStateById(7))
                  {
                      worldIn.setBlockState(pos, ((BlockCrops)block).withAge(0));
                      worldIn.spawnEntity(new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.POTATO, 4)));
                  }
                  else if(block.equals(Blocks.BEETROOTS) && block.getBlockState().getBaseState() == block.getStateById(3))
                  {
                      worldIn.setBlockState(pos, ((BlockCrops)block).withAge(0));  
                      worldIn.spawnEntity(new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.BEETROOT, 3)));
                      worldIn.spawnEntity(new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.BEETROOT_SEEDS, 1)));
                  }
                  else if(block.equals(Blocks.CARROTS) && block.getBlockState().getBaseState() == block.getStateById(7))
                  {
                      worldIn.setBlockState(pos, ((BlockCrops)block).withAge(0));  
                      worldIn.spawnEntity(new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.CARROT, 4)));
                  }
                  else if(block.equals(Blocks.WHEAT) && block.getBlockState().getBaseState() == block.getStateById(7))
                  {
                      worldIn.setBlockState(pos, ((BlockCrops)block).withAge(0)); 
                      worldIn.spawnEntity(new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.WHEAT, 3)));
                      worldIn.spawnEntity(new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.WHEAT_SEEDS, 1)));
                  }
                  return EnumActionResult.SUCCESS;
              }
              else
              {
                  return EnumActionResult.PASS;
              }
          }
      }
      
      1 réponse Dernière réponse Répondre Citer 0
      • FeedBackF Hors-ligne
        FeedBack
        dernière édition par

        Désolé de répondre tardivement mais j’ai trouvé la solution :

        public class ItemMagicHoe extends ItemHoe implements IHasModel
        {
            public ItemMagicHoe(String name, ToolMaterial material)
            {
                super(material);
                setUnlocalizedName(name);
                setRegistryName(name);
                setCreativeTab(CreativeTabs.MATERIALS);
                ItemInit.ITEMS.add(this);
            }
            
            @Override
            public void registerModels()
            {
                Main.proxy.registerItemRederer(this, 0);
            }
            
            @SuppressWarnings("incomplete-switch")
            @Override
            public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
            {
                IBlockState iblockstate = worldIn.getBlockState(pos);
                Block block = iblockstate.getBlock();
                
                Random rand = new Random();
                ItemStack itemstack = player.getHeldItem(hand);
        
                if(block instanceof BlockCrops && !worldIn.isRemote)
                {
                    if(block.equals(Blocks.POTATOES) && ((BlockCrops)block).isMaxAge(iblockstate))
                    {
                        worldIn.setBlockState(pos, ((BlockCrops)block).withAge(0));
                        worldIn.spawnEntity(new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.POTATO, rand.nextInt(6))));
                    }
                    else if(block.equals(Blocks.BEETROOTS) && ((BlockCrops)block).isMaxAge(iblockstate))
                    {
                        worldIn.setBlockState(pos, ((BlockCrops)block).withAge(0));  
                        worldIn.spawnEntity(new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.BEETROOT, rand.nextInt(5))));
                        worldIn.spawnEntity(new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.BEETROOT_SEEDS, rand.nextInt(3))));
                    }
                    else if(block.equals(Blocks.CARROTS) && ((BlockCrops)block).isMaxAge(iblockstate))
                    {
                        worldIn.setBlockState(pos, ((BlockCrops)block).withAge(0));  
                        worldIn.spawnEntity(new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.CARROT, rand.nextInt(6))));
                    }
                    else if(block.equals(Blocks.WHEAT) && ((BlockCrops)block).isMaxAge(iblockstate))
                    {
                        worldIn.setBlockState(pos, ((BlockCrops)block).withAge(0)); 
                        worldIn.spawnEntity(new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.WHEAT, rand.nextInt(5))));
                        worldIn.spawnEntity(new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.WHEAT_SEEDS, rand.nextInt(3))));
                    }
                    
                    itemstack.damageItem(1, player);
                    
                    return EnumActionResult.SUCCESS;
                }
                
                else if(block instanceof BlockGrass || block instanceof BlockDirt || block instanceof BlockGrassPath)
                {
                    int hook = net.minecraftforge.event.ForgeEventFactory.onHoeUse(itemstack, player, worldIn, pos);
                    if (hook != 0) return hook > 0 ? EnumActionResult.SUCCESS : EnumActionResult.FAIL;
        
                    if (facing != EnumFacing.DOWN && worldIn.isAirBlock(pos.up()))
                    {
                        if (block == Blocks.GRASS || block == Blocks.GRASS_PATH)
                        {
                            this.setBlock(itemstack, player, worldIn, pos, Blocks.FARMLAND.getDefaultState());
                            return EnumActionResult.SUCCESS;
                        }
        
                        if (block == Blocks.DIRT)
                        {
                            switch ((BlockDirt.DirtType)iblockstate.getValue(BlockDirt.VARIANT))
                            {
                                case DIRT:
                                    this.setBlock(itemstack, player, worldIn, pos, Blocks.FARMLAND.getDefaultState());
                                    return EnumActionResult.SUCCESS;
                                case COARSE_DIRT:
                                    this.setBlock(itemstack, player, worldIn, pos, Blocks.DIRT.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.DIRT));
                                    return EnumActionResult.SUCCESS;
                            }
                        }
                    }
        
                    return EnumActionResult.PASS;
                }
                return EnumActionResult.PASS;
            }
        }
        
        
        1 réponse Dernière réponse Répondre Citer 1
        • P Hors-ligne
          PlagueZ
          dernière édition par PlagueZ

          ca ca peut pas fonctionner block.getBlockState().getBaseState() == block.getStateById(7) ca va toujour te donner un age de 0 parce que dans ce cas la le block est pas défini pour faire simple quel bloc tu regarde? réponse je sait pas tu ma pas dit après je dit peut être un connerie je suis en train de versifier

          ensuite faudrait surement supprimer le bloc de culture encore la avant d’essayer d’en placer 1 ou je te propose un truc plus simple changer son Age par 0 ce qui reviendrait a le faire pousser a l’envers pour le remettre a 0 😜 et de drop le résultat avant de faire ca pour pas la condition disparaisse

          if
          reset culture state
          drop item

          “Imagination is more important than knowledge. For knowledge is limited to all we now know and understand, while imagination embraces the entire wo…

          1 réponse Dernière réponse Répondre Citer 1
          • FeedBackF Hors-ligne
            FeedBack
            dernière édition par

            Désolé de répondre tardivement mais j’ai trouvé la solution :

            public class ItemMagicHoe extends ItemHoe implements IHasModel
            {
                public ItemMagicHoe(String name, ToolMaterial material)
                {
                    super(material);
                    setUnlocalizedName(name);
                    setRegistryName(name);
                    setCreativeTab(CreativeTabs.MATERIALS);
                    ItemInit.ITEMS.add(this);
                }
                
                @Override
                public void registerModels()
                {
                    Main.proxy.registerItemRederer(this, 0);
                }
                
                @SuppressWarnings("incomplete-switch")
                @Override
                public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
                {
                    IBlockState iblockstate = worldIn.getBlockState(pos);
                    Block block = iblockstate.getBlock();
                    
                    Random rand = new Random();
                    ItemStack itemstack = player.getHeldItem(hand);
            
                    if(block instanceof BlockCrops && !worldIn.isRemote)
                    {
                        if(block.equals(Blocks.POTATOES) && ((BlockCrops)block).isMaxAge(iblockstate))
                        {
                            worldIn.setBlockState(pos, ((BlockCrops)block).withAge(0));
                            worldIn.spawnEntity(new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.POTATO, rand.nextInt(6))));
                        }
                        else if(block.equals(Blocks.BEETROOTS) && ((BlockCrops)block).isMaxAge(iblockstate))
                        {
                            worldIn.setBlockState(pos, ((BlockCrops)block).withAge(0));  
                            worldIn.spawnEntity(new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.BEETROOT, rand.nextInt(5))));
                            worldIn.spawnEntity(new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.BEETROOT_SEEDS, rand.nextInt(3))));
                        }
                        else if(block.equals(Blocks.CARROTS) && ((BlockCrops)block).isMaxAge(iblockstate))
                        {
                            worldIn.setBlockState(pos, ((BlockCrops)block).withAge(0));  
                            worldIn.spawnEntity(new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.CARROT, rand.nextInt(6))));
                        }
                        else if(block.equals(Blocks.WHEAT) && ((BlockCrops)block).isMaxAge(iblockstate))
                        {
                            worldIn.setBlockState(pos, ((BlockCrops)block).withAge(0)); 
                            worldIn.spawnEntity(new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.WHEAT, rand.nextInt(5))));
                            worldIn.spawnEntity(new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.WHEAT_SEEDS, rand.nextInt(3))));
                        }
                        
                        itemstack.damageItem(1, player);
                        
                        return EnumActionResult.SUCCESS;
                    }
                    
                    else if(block instanceof BlockGrass || block instanceof BlockDirt || block instanceof BlockGrassPath)
                    {
                        int hook = net.minecraftforge.event.ForgeEventFactory.onHoeUse(itemstack, player, worldIn, pos);
                        if (hook != 0) return hook > 0 ? EnumActionResult.SUCCESS : EnumActionResult.FAIL;
            
                        if (facing != EnumFacing.DOWN && worldIn.isAirBlock(pos.up()))
                        {
                            if (block == Blocks.GRASS || block == Blocks.GRASS_PATH)
                            {
                                this.setBlock(itemstack, player, worldIn, pos, Blocks.FARMLAND.getDefaultState());
                                return EnumActionResult.SUCCESS;
                            }
            
                            if (block == Blocks.DIRT)
                            {
                                switch ((BlockDirt.DirtType)iblockstate.getValue(BlockDirt.VARIANT))
                                {
                                    case DIRT:
                                        this.setBlock(itemstack, player, worldIn, pos, Blocks.FARMLAND.getDefaultState());
                                        return EnumActionResult.SUCCESS;
                                    case COARSE_DIRT:
                                        this.setBlock(itemstack, player, worldIn, pos, Blocks.DIRT.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.DIRT));
                                        return EnumActionResult.SUCCESS;
                                }
                            }
                        }
            
                        return EnumActionResult.PASS;
                    }
                    return EnumActionResult.PASS;
                }
            }
            
            
            1 réponse Dernière réponse Répondre Citer 1
            • P Hors-ligne
              PlagueZ
              dernière édition par

              j’allais te l’envoyer vérifiait que ça fonctionnait xD

              “Imagination is more important than knowledge. For knowledge is limited to all we now know and understand, while imagination embraces the entire wo…

              FeedBackF 1 réponse Dernière réponse Répondre Citer 1
              • FeedBackF Hors-ligne
                FeedBack @PlagueZ
                dernière édition par

                @PlagueZ En tt cas mrc de ton aide même si elle est arrivée un peut tard x)

                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