Jump to content

[Solved][1.7.10]Custom seed not planting.


skullcrusher1005

Recommended Posts

Hello Everyone, Lately I've been following Jabelar's modding tutorials. I've run into a problem where I can't plant the seed. I can go into NEI and get the crop's block itself and it'll work fine so I know it's not that. If anyone can help I would greatly appreciate it.

 

Coffee Bean class

 

package com.skullcrusher.BetterThings.items;

 

import com.skullcrusher.BetterThings.BetterThings;

import com.skullcrusher.BetterThings.ModSeeds;

 

import net.minecraft.init.Blocks;

import net.minecraftforge.common.IPlantable;

 

public class CoffeeBean extends ModSeeds

{

 

 

    public CoffeeBean()

    {

        super(1, 0.3F, BetterThings.CoffeePlant, Blocks.farmland);

    }

}

 

 

 

Mod Seed Class (Parent Class)

 

 

 

package com.skullcrusher.BetterThings;

 

import net.minecraft.block.Block;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.ItemFood;

import net.minecraft.item.ItemStack;

import net.minecraft.world.IBlockAccess;

import net.minecraft.world.World;

import net.minecraftforge.common.EnumPlantType;

import net.minecraftforge.common.IPlantable;

import net.minecraftforge.common.util.ForgeDirection;

 

public class ModSeeds extends ItemFood implements IPlantable

{

    private final Block theBlockPlant;

    /**

    * Block ID of the soil this seed food should be planted on.

    */

    private final Block soilId;

 

    public ModSeeds(int parHealAmount, float parSaturationModifier,

          Block parBlockPlant, Block parSoilBlock)

    {

        super(parHealAmount, parSaturationModifier, false);

        theBlockPlant = parBlockPlant;

        soilId = parSoilBlock;

    }

 

    @Override

    public boolean onItemUse(ItemStack parItemStack, EntityPlayer parPlayer,

          World parWorld, int parX, int parY, int parZ, int par7, float par8,

          float par9, float par10)

    {

    // not sure what this parameter does, copied it from potato

        if (par7 != 1)

        {

            return false;

        }

        // check if player has capability to edit

        else if (parPlayer.canPlayerEdit(parX, parY+1, parZ, par7, parItemStack))

        {

            // check that the soil block can sustain the plant

            // and that block above is air so there is room for plant to grow

            if (parWorld.getBlock(parX, parY, parZ).canSustainPlant(parWorld,

                  parX, parY, parZ, ForgeDirection.UP, this) && parWorld

                  .isAirBlock(parX, parY+1, parZ))

            {

            // place the plant block

                parWorld.setBlock(parX, parY+1, parZ, theBlockPlant);

                // decrement the stack of seed items

                --parItemStack.stackSize;

                return true;

            }

            else

            {

                return false;

            }

        }

        else

        {

            return false;

        }

    }

 

    @Override

    public EnumPlantType getPlantType(IBlockAccess world, int x, int y, int z)

    {

        return EnumPlantType.Crop;

    }

 

    @Override

    public Block getPlant(IBlockAccess world, int x, int y, int z)

    {

        return theBlockPlant;

    }

 

    @Override

    public int getPlantMetadata(IBlockAccess world, int x, int y, int z)

    {

        return 0;

    }

 

    public Block getSoilId()

    {

        return soilId;

    }

}

 

 

Link to comment
Share on other sites

Make sure your Block is initialized when you use it in the CoffeeBean class constructor.

 

It's initialized correctly, Here's the code in the PreInit handler

 

 

//Crops Stuff

CoffeePlant = new CoffeePlant().setBlockName("CoffeePlant").setCreativeTab(BetterThings).setHardness(0f).setResistance(0f).setBlockTextureName(modid + ":" + "Coffee_stage_0");

GameRegistry.registerBlock(CoffeePlant, "CoffeePlant");

CoffeeBean = new Item().setCreativeTab(BetterThings).setTextureName(modid + ":" + "CoffeeBean").setUnlocalizedName("CoffeeBean");

GameRegistry.registerItem(CoffeeBean, "CoffeeBean");

 

 

 

Also, At the top of the main mod class I have it like this

 

 

//Blocks

public static Block CoffeePlant;

 

//Seeds

public static Item CoffeeBean;

 

 

 

Link to comment
Share on other sites

CoffeeBean = new Item().setCreativeTab(BetterThings).setTextureName(modid + ":" + "CoffeeBean").setUnlocalizedName("CoffeeBean");

 

You use an ordinary Item, not your subclass.

 

Turns out that was the problem, I changed

 

CoffeeBean = new Item().setCreativeTab(BetterThings).setTextureName(modid + ":" + "CoffeeBean").setUnlocalizedName("CoffeeBean");

GameRegistry.registerItem(CoffeeBean, "CoffeeBean");

 

To:

 

CoffeeBean = new CoffeeBean().setCreativeTab(BetterThings).setTextureName(modid + ":" + "CoffeeBean").setUnlocalizedName("CoffeeBean");

GameRegistry.registerItem(CoffeeBean, "CoffeeBean");

 

Thanks alot man! :D

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.