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

    Résolu Problème avec un item plantable

    1.8.x
    1.8.9
    2
    7
    1064
    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.
    • ph1823
      ph1823 dernière édition par

      Bonjour, excusé si je dois éditer mon autres poste, mais c’est un sujet différent, et aussi un problème différent, donc je pense devoir reposté un sujet ^^, donc voila, j’ai un problème j’ai crée une graine de canabis plantable,s auf quelle ne se plante pas, et je ne sais pas comment faire pour quelle drops du canabis aussi 😕
      voici ma classe BlockCannabis: 
      :::

      [font=Courier Newpackage ]fr.ph1823.MyLife.Block.illegal%(#cc7832)[;
      ]
      
      import java.util.Random%(#cc7832)[;
      ]
      import fr.ph1823.MyLife.GloryRP%(#cc7832)[;
      ]import fr.ph1823.MyLife.PPlant%(#cc7832)[;
      ]import net.minecraft.block.Block%(#cc7832)[;
      ]import net.minecraft.block.material.Material%(#cc7832)[;
      ]import net.minecraft.block.state.IBlockState%(#cc7832)[;
      ]import net.minecraft.init.Blocks%(#cc7832)[;
      ]import net.minecraft.init.Items%(#cc7832)[;
      ]import net.minecraft.item.Item%(#cc7832)[;
      ]import net.minecraft.item.ItemStack%(#cc7832)[;
      ]import net.minecraft.util.BlockPos%(#cc7832)[;
      ]import net.minecraft.world.World%(#cc7832)[;
      ]
      public class BlockCannabis
       extends PPlant
      {
      
       private int ticks = 0%(#cc7832)[;
      ] 
       public BlockCannabis()
       {
      
         setUnlocalizedName("cannabisb")%(#cc7832)[;
      ]   
         %(#808080)[//setDefaultState();
      ]
      
       }
      
       public void breakBlock(World w, BlockPos pos,IBlockState blockState )
       {
         super.breakBlock(w, pos, blockState)%(#cc7832)[;
      ]   if (w.getBlockState(pos.add(0,-1,0)).getBlock() == Blocks.*grass*) {
           w.setBlockState(pos, GloryRP.*cannabisPlant*.getDefaultState())%(#cc7832)[;
      ]   }
         if (blockState.getBlock().getMetaFromState(blockState) == 7) {
         %(#808080)[//  dropBlockAsItem(w, pos, new ItemStack(GloryRP.cannabisItem), 1);
      ]
         }
       }
       protected boolean canPlaceBlockOn(Block ground)
       {
         return ground == Blocks.*grass*%(#cc7832)[;
      ] }
      
       public Item getItemDropped(int parMetadata, Random parRand, int parFortune)
       {
         return GloryRP.*cannabisItem*%(#cc7832)[;
      ] }
      
       public void updateTick(World parWorld, BlockPos pos, IBlockState blockState, Random r)
       {
         super.updateTick(parWorld, pos, blockState, r)%(#cc7832)[;
      ]   parWorld.scheduleBlockUpdate(pos,blockState.getBlock() ,20,2)%(#cc7832)[;
      ]   ticks++%(#cc7832)[;
      ]   if (this.ticks > 2400)
         {
           int growStage = blockState.getBlock().getMetaFromState(blockState) + 1%(#cc7832)[;
      ]     if (growStage > 7) {
             growStage = 7%(#cc7832)[;
      ]     }
           parWorld.setBlockState(pos,blockState.getBlock().getStateFromMeta(growStage))%(#cc7832)[;
      ]    %(#808080)[// parWorld.setBlockMetadataWithNotify(parX, parY, parZ, growStage, 2);
      ]     this.ticks = 0%(#cc7832)[;
      ]   }
      
       }
      }
      

      :::

      et voici la classe PPLant :
      :::

      [font=Courier Newpackage ]fr.ph1823.MyLife%(#cc7832)[;
      ]
      
      import java.util.Random%(#cc7832)[;
      ]
      import net.minecraft.block.*%(#cc7832)[;
      ]
      import net.minecraft.block.material.Material%(#cc7832)[;
      ]import net.minecraft.block.properties.PropertyInteger%(#cc7832)[;
      ]import net.minecraft.block.state.BlockState%(#cc7832)[;
      ]import net.minecraft.block.state.IBlockState%(#cc7832)[;
      ]import net.minecraft.init.Blocks%(#cc7832)[;
      ]import net.minecraft.item.Item%(#cc7832)[;
      ]
      import net.minecraft.server.v1_7_R4.IIcon%(#cc7832)[;
      ]
      import net.minecraft.util.BlockPos%(#cc7832)[;
      ]import net.minecraft.util.MathHelper%(#cc7832)[;
      ]import net.minecraft.world.World%(#cc7832)[;
      ]import net.minecraftforge.common.IPlantable%(#cc7832)[;
      ]import net.minecraftforge.fml.relauncher.Side%(#cc7832)[;
      ]import net.minecraftforge.fml.relauncher.SideOnly%(#cc7832)[;
      ]
      public class PPlant
       extends BlockBush
       implements IGrowable,IPlantable
      {
      
       protected int maxGrowthStage = 7%(#cc7832)[;
      ]  @SideOnly(Side.*CLIENT*)
      
       public PPlant()
       {
      
         setTickRandomly(true)%(#cc7832)[;
      ]    float f = 0.5F%(#cc7832)[;
      ]    setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 0.25F, 0.5F + f)%(#cc7832)[;
      ]    setCreativeTab(null)%(#cc7832)[;
      ]    setHardness(0.0F)%(#cc7832)[;
      ]    setStepSound(*soundTypeGrass*)%(#cc7832)[;
      ]    disableStats()%(#cc7832)[;
      ]    tickRate()%(#cc7832)[;
      ]
      
       }
       public int tickRate() {
         return 20%(#cc7832)[;
      ]  }
      
       protected boolean canPlaceBlockOn(Block parBlock)
       {
         return parBlock == Blocks.*grass*%(#cc7832)[;
      ]  }
      
       public void incrementGrowStage(World parWorld, Random parRand, BlockPos pos)
       {
         IBlockState blockState = parWorld.getBlockState(pos)%(#cc7832)[;
      ]    int growStage = blockState.getBlock().getMetaFromState(blockState) + MathHelper.*getRandomIntegerInRange*(parRand, 2, 5)%(#cc7832)[;
      ]    if (growStage > this.maxGrowthStage) {
           growStage = this.maxGrowthStage%(#cc7832)[;
      ]    }
      
         parWorld.setBlockState(pos, blockState.getBlock().getStateFromMeta(growStage), 2)%(#cc7832)[;
      ]  }
      
       public Item getItemDropped(int parMetadata, Random parRand, int parFortune)
       {
         return Item.*getItemFromBlock*(this)%(#cc7832)[;
      ]  }
      
       public int getRenderType()
       {
         return 1%(#cc7832)[;
      ]  }
      
       %(#bbb529)[@Override
      ]  public boolean canGrow(World worldIn, BlockPos pos, IBlockState state, boolean isClient) {
         return worldIn.getBlockState(pos).getBlock().getMetaFromState(state) != 7%(#cc7832)[;
      ]  }
      
       %(#bbb529)[@Override
      ]  public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockState state) {
         %(#cc7832)[return false;
      ]  }
      
       %(#bbb529)[@Override
      ]  public void grow(World parworld, Random parRand, BlockPos pos, IBlockState state) {
         incrementGrowStage(parworld, parRand,pos)%(#cc7832)[;
      ]  }
      }
      

      :::
      merci de votre aide 😃

      Cordialement, le membre ayant le pseudo "ph1823"

      Ma chaîne YouTube: https://www.youtube.com/c/ph1823
      Mon Twitter : https://twitter.com/ph1823
      Des jeux vidéo moin chers? Alors check ici : http://bit.ly/instaceph ou ici : http://bit.ly/g2aph

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

        public Item getItemDropped(int parMetadata, Random parRand, int parFortune)
        devrait être
        public Item getItemDropped(IBlockState state, Random rand, int fortune)

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

          Bonjour, je les changé, j’ai re-test le code, mais cela ne plante toujours pas la graine 😕 J’ai fais des recherche mais rien trouvée, une solution pour le fait que ca ce plante pas?

          Cordialement, le membre ayant le pseudo "ph1823"

          Ma chaîne YouTube: https://www.youtube.com/c/ph1823
          Mon Twitter : https://twitter.com/ph1823
          Des jeux vidéo moin chers? Alors check ici : http://bit.ly/instaceph ou ici : http://bit.ly/g2aph

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

            Pas possible de la poser sur de l’herbe ?

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

              J’ai tenter de le poser sur le l’herbe, sur la terre, et la terre labouré impossible, ca ne met rien au sol

              Cordialement, le membre ayant le pseudo "ph1823"

              Ma chaîne YouTube: https://www.youtube.com/c/ph1823
              Mon Twitter : https://twitter.com/ph1823
              Des jeux vidéo moin chers? Alors check ici : http://bit.ly/instaceph ou ici : http://bit.ly/g2aph

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

                Je ne vois pourtant rien qui l’empêche …
                Peux-tu m’envoyer un zip de ton dossier src ?

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

                  Bonjour, problème résolue, voici le code final pour ce qu’il veulent :
                  :::

                  package fr.ph1823.MyLife;
                  
                  import java.util.Random;
                  
                  import net.minecraft.block.*;
                  
                  import net.minecraft.block.material.Material;
                  import net.minecraft.block.properties.IProperty;
                  import net.minecraft.block.properties.PropertyInteger;
                  import net.minecraft.block.state.BlockState;
                  import net.minecraft.block.state.IBlockState;
                  import net.minecraft.init.Blocks;
                  import net.minecraft.item.Item;
                  
                  import net.minecraft.util.BlockPos;
                  import net.minecraft.util.MathHelper;
                  import net.minecraft.world.World;
                  import net.minecraftforge.common.EnumPlantType;
                  import net.minecraftforge.fml.relauncher.Side;
                  import net.minecraftforge.fml.relauncher.SideOnly;
                  
                  public class PPlant
                    extends BlockBush
                    implements IGrowable
                  {
                  
                    public static final PropertyInteger AGE = PropertyInteger.create("age", 0, 7);
                    protected int maxGrowthStage = 7;
                    @SideOnly(Side.CLIENT)
                  
                    public PPlant(Material p)
                    {
                      super(p);
                      setTickRandomly(true);
                      float f = 0.5F;
                      setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 0.25F, 0.5F + f);
                      setHardness(0.0F);
                      setStepSound(soundTypeGrass);
                      disableStats();
                      tickRate();
                  
                    }
                    public int tickRate() {
                      return 20;
                    }
                  
                    protected boolean canPlaceBlockOn(Block parBlock)
                    {
                      return parBlock == Blocks.grass;
                    }
                  
                    public void incrementGrowStage(World parWorld, Random parRand, BlockPos pos)
                    {
                      IBlockState blockState = parWorld.getBlockState(pos);
                      int growStage = blockState.getBlock().getMetaFromState(blockState) + MathHelper.getRandomIntegerInRange(parRand, 2, 5);
                      if (growStage > this.maxGrowthStage) {
                        growStage = this.maxGrowthStage;
                      }
                  
                      parWorld.setBlockState(pos, blockState.getBlock().getStateFromMeta(growStage), 2);
                    }
                  
                    public Item getItemDropped(IBlockState
                                                       blockState, Random parRand, int parFortune)
                    {
                      return Item.getItemFromBlock(this);
                    }
                  
                    @Override
                    public boolean canGrow(World worldIn, BlockPos pos, IBlockState state, boolean isClient) {
                      return worldIn.getBlockState(pos).getBlock().getMetaFromState(state) != 7;
                    }
                  
                    @Override
                    public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockState state) {
                      return false;
                    }
                  
                    @Override
                    public void grow(World parworld, Random parRand, BlockPos pos, IBlockState state) {
                      incrementGrowStage(parworld, parRand,pos);
                    }
                    @Override
                    protected BlockState createBlockState() {
                      return new BlockState(this); // this works just fine
                    }
                    @Override
                    public IBlockState  getPlant(net.minecraft.world.IBlockAccess world, BlockPos blockPos)
                    {
                      IBlockState state = world.getBlockState(blockPos);
                      if (state.getBlock() != this) return getDefaultState();
                      return state;
                    }
                    @Override
                    public  net.minecraftforge.common.EnumPlantType getPlantType(net.minecraft.world.IBlockAccess world, BlockPos blockPos)
                    {
                      return  EnumPlantType.Plains;
                    }
                  
                  }
                  
                  

                  :::
                  :::

                  package fr.ph1823.MyLife.Item.legal;
                  
                  import net.minecraft.block.Block;
                  import net.minecraft.block.BlockCrops;
                  import net.minecraft.block.BlockStem;
                  import net.minecraft.block.state.IBlockState;
                  import net.minecraft.entity.player.EntityPlayer;
                  import net.minecraft.item.Item;
                  import net.minecraft.item.ItemSeeds;
                  import net.minecraft.item.ItemStack;
                  import net.minecraft.util.BlockPos;
                  import net.minecraft.util.ChatComponentText;
                  import net.minecraft.util.EnumFacing;
                  import net.minecraft.world.IBlockAccess;
                  import net.minecraft.world.World;
                  import net.minecraftforge.common.EnumPlantType;
                  import net.minecraftforge.common.IPlantable;
                  import org.bukkit.material.Crops;
                  
                  public class PItem
                    extends Item
                    implements IPlantable
                  {
                    private  Block theBlockPlant;
                    private Block soilId;
                  
                    public PItem(Block parBlockPlant, Block parSoilBlock)
                    {
                      this.theBlockPlant = parBlockPlant;
                      this.soilId = parSoilBlock;
                  
                    }
                  
                    public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
                    {
                      if (side != EnumFacing.UP) {
                        return false;
                      }
                  
                      /*
                      if (playerIn.canPlayerEdit(pos.add(0,1,0), side, stack))
                      {
                        if ((worldIn.getBlockState(pos).getBlock() == this.soilId) &&
                          (worldIn.isAirBlock(pos.add(0,1,0))))
                        {
                  
                          playerIn.addChatComponentMessage(new ChatComponentText("000000000" ));
                        //  worldIn.setBlockState(pos.add(0,1,0), this.theBlockPlant.getDefaultState());
                          stack.stackSize -= 1;
                          return true;
                        }
                        return false;
                      }
                      return false;*/
                      else if (!playerIn.canPlayerEdit(pos.offset(side), side, stack))
                      {
                        return false;
                      }
                      else if (/*worldIn.getBlockState(pos).getBlock().canSustainPlant(worldIn, pos, EnumFacing.UP, this) &&*/ worldIn.isAirBlock(pos.up()) && worldIn.getBlockState(pos).getBlock()==soilId)
                      {
                        worldIn.setBlockState(pos.up(), this.theBlockPlant.getDefaultState());
                        –stack.stackSize;
                        return true;
                      }
                      else
                      {
                        return false;
                      }
                    }
                  
                    public EnumPlantType getPlantType(IBlockAccess world, BlockPos pos)
                    {
                      return EnumPlantType.Crop;
                    }
                  
                      @Override
                      public net.minecraft.block.state.IBlockState getPlant(net.minecraft.world.IBlockAccess world, BlockPos pos)
                      {
                          return this.theBlockPlant.getDefaultState();
                      }
                  
                  }
                  
                  

                  :::
                  :::
                  package fr.ph1823.MyLife.Block.illegal;

                  import java.util.Random;

                  import com.google.common.base.Predicate;
                  import fr.ph1823.MyLife.GloryRP;
                  import fr.ph1823.MyLife.PPlant;
                  import net.minecraft.block.Block;
                  import net.minecraft.block.material.Material;
                  import net.minecraft.block.properties.PropertyDirection;
                  import net.minecraft.block.properties.PropertyInteger;
                  import net.minecraft.block.state.BlockState;
                  import net.minecraft.block.state.IBlockState;
                  import net.minecraft.init.Blocks;
                  import net.minecraft.item.Item;
                  import net.minecraft.util.BlockPos;

                  import net.minecraft.util.EnumFacing;

                  import net.minecraft.world.World;

                  public class BlockCannabis
                    extends PPlant
                  {
                    public static final PropertyInteger AGE = PropertyInteger.create(“age”, 0, 7);

                  private int ticks = 0;

                  public BlockCannabis(Material m)
                    {
                    super(m);
                      createBlockState();
                      setDefaultState(this.blockState.getBaseState().withProperty(AGE, 0));
                      setUnlocalizedName(“cannabisb”);

                  //super(Material.air);
                      //setDefaultState();
                  //net.minecraft.item.ItemStack.

                  }

                  @Override
                    public void breakBlock(World w, BlockPos pos,IBlockState blockState)
                    {
                      super.breakBlock(w, pos, blockState);
                      if (w.getBlockState(pos.add(0,-1,0)).getBlock() == Blocks.grass) {
                        w.setBlockState(pos, GloryRP.cannabisPlant.getDefaultState());
                      }
                      if (blockState.getBlock().getMetaFromState(blockState) == 7) {
                      //  dropBlockAsItem(w, pos, new ItemStack(GloryRP.cannabisItem), 1);

                  }
                    }

                  @Override
                    protected boolean canPlaceBlockOn(Block ground)
                    {
                      return ground == Blocks.grass;
                    }

                  @Override
                    public Item getItemDropped(IBlockState state, Random parRand, int parFortune)
                    {
                      return GloryRP.cannabisSeed;
                    }

                  public void updateTick(World parWorld, BlockPos pos, IBlockState blockState, Random r)
                    {
                      super.updateTick(parWorld, pos, blockState, r);
                      parWorld.scheduleBlockUpdate(pos,blockState.getBlock() ,20,2);
                      ticks++;
                      if (this.ticks > 2400)
                      {
                        int growStage = blockState.getValue(AGE) + 1;
                        if (growStage > 7) {
                          growStage = 7;
                        }
                        parWorld.setBlockState(pos,blockState.withProperty(AGE,growStage));
                       // parWorld.setBlockMetadataWithNotify(parX, parY, parZ, growStage, 2);
                        this.ticks = 0;
                      }

                  }
                    @Override
                    public IBlockState getStateFromMeta(int meta)
                    {

                  return this.getDefaultState().withProperty(AGE, meta);
                    }

                  @Override
                    public int getMetaFromState(IBlockState state)
                    {

                  int grow = state.getValue(AGE);
                      //EnumColour colour = (EnumColour)state.getValue(PROPERTYCOLOUR);

                  //int facingbits = facing.getHorizontalIndex();
                      //int colourbits = colour.getMetadata() << 2;
                      return grow;// | colourbits;
                    }

                  @Override
                    protected BlockState createBlockState() {
                      return new BlockState(this, AGE); // this works just fine
                    }
                    @Override
                    public IBlockState  getPlant(net.minecraft.world.IBlockAccess world, BlockPos blockPos)
                    {
                      IBlockState state = world.getBlockState(blockPos);
                      if (state.getBlock() != this) return getDefaultState();
                      return state;
                    }

                  /* @Override
                    public IBlockState getPlant(IBlockAccess world, BlockPos blockPos)
                    {
                      return GloryRP.cannabisPlant.getDefaultState();
                    }

                  */

                  }

                  :::
                  :::

                  package fr.ph1823.MyLife.Seed;
                  
                  import fr.ph1823.MyLife.GloryRP;
                  import fr.ph1823.MyLife.Item.legal.PItem;
                  import net.minecraft.init.Blocks;
                  
                  public class SeedCannabis
                    extends PItem
                  {
                    public SeedCannabis()
                    {
                  
                     super(GloryRP.cannabisPlant, Blocks.grass);
                  
                     setUnlocalizedName("cannabis_seed");
                  
                     setCreativeTab(GloryRP.plantTab);
                    }
                  }
                  
                  

                  :::
                  P.S Je fichier JSON : (ou j’ai rempalcé le “crops” “cross”

                  {
                     "parent": "block/cross",
                     "textures": {
                         "cross": "plants:blocks/cannabis_stage_0"
                     }
                  }
                  

                  Cordialement, le membre ayant le pseudo "ph1823"

                  Ma chaîne YouTube: https://www.youtube.com/c/ph1823
                  Mon Twitter : https://twitter.com/ph1823
                  Des jeux vidéo moin chers? Alors check ici : http://bit.ly/instaceph ou ici : http://bit.ly/g2aph

                  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