Jump to content

[1.7.10]Plant Seed not placing plant.


mysticpenguin

Recommended Posts

In my mod I made a seed item for a plant. When I right click with the seed the player animation goes to placing a block but no plant is planted. Please help.

 

Seed Code:

 

                package com.mystic.cucumbers;

 

import net.minecraft.block.Block;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.init.Blocks;

import net.minecraft.item.Item;

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;

 

 

public class ItemCucumberSeed extends Item implements IPlantable

 

{

private Block plant;

private String name = "CucumberSeed";

 

public ItemCucumberSeed(Block plant)

{

this.plant = plant;

setUnlocalizedName(CucumbersMod.MODID + "_" + "cucumberseed");

setTextureName(CucumbersMod.MODID + ":" + "cucumberseed");

setCreativeTab(CreativeTabs.tabMaterials);

}

 

 

public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)

{

if (par7 != 1)

{

return false;

}

else if (par2EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack) && par2EntityPlayer.canPlayerEdit(par4, par5 + 1, par6, par7, par1ItemStack))

{

if(par3World.getBlock(par4, par5, par6) == Blocks.dirt || par3World.getBlock(par4, par5, par6) == Blocks.grass)

{

if (par3World.isAirBlock(par4, par5 + 1, par6))

{

par3World.setBlock(par4, par5 + 1, par6, this.plant);

--par1ItemStack.stackSize;

return true;

}

else

{

return false;

}

}

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 plant;

}

@Override

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

return 0;

}

}

 

 

Plant Code:

 

                package com.mystic.cucumbers;

 

import java.util.Random;

 

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import net.minecraft.block.Block;

import net.minecraft.block.BlockBush;

import net.minecraft.block.IGrowable;

import net.minecraft.block.material.Material;

import net.minecraft.client.renderer.texture.IIconRegister;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.util.IIcon;

import net.minecraft.world.World;

 

public class BlockCucumberPlant extends BlockBush implements IGrowable

{

@SideOnly(Side.CLIENT)

private IIcon[] icons;

 

public BlockCucumberPlant()

{

super(Material.plants);

setBlockName(CucumbersMod.MODID + "_" + "cucumberplant");

setHardness(0.0F);

setBlockBounds(0F, 0.0F, 0F, 1F, 0.25F, 1F);

setStepSound(soundTypeGrass);

}

@Override

@SideOnly(Side.CLIENT)

public void registerBlockIcons(IIconRegister par1IconRegister)

{

icons = new IIcon[3];

for (int i = 0; i < icons.length; i++)

{

icons = par1IconRegister.registerIcon(CucumbersMod.MODID + ":" + "cucumberplant" + i);

}

}

 

@Override

@SideOnly(Side.CLIENT)

public IIcon getIcon(int par1, int par2)

{

if(par2 < 0 || par2 >= 3)

{

System.out.println("Something is wrong with the metadata for BlockCucumberPlant!");

return icons[0];

}

else

return icons[par2];

}

@Override

public int getRenderType()

{

return 6;

}

@Override

public boolean func_149851_a(World world, int x, int y, int z, boolean var5)

{

return world.getBlockMetadata(x, y, z) != 2;

}

@Override

public boolean func_149852_a(World world, Random rand, int x, int y, int z)

{

return true;

}

@Override

public void func_149853_b(World world, Random rand, int x, int y, int z)

{

int next = world.getBlockMetadata(x, y, z) + 1;

 

if(next > 2)

next = 2;

 

world.setBlockMetadataWithNotify(x, y, z, next, 2);

}

public void updateTick(World world, int x, int y, int z, Random rand)

{

super.updateTick(world, x, y, z, rand);

 

if (world.getBlockLightValue(x, y + 1, z) >=9)

{

int l = world.getBlockMetadata(x, y, z);

 

if (1 < 2)

{

if (rand.nextInt(5) == 0)

{

++l;

world.setBlockMetadataWithNotify(x, y, z, 1, 2);

}

}

}

}

 

}

 

Link to comment
Share on other sites

public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)

 

For the love of god, rename those parameters to something meaningful.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Are you trying to plant in dirt or grass?  or farmland?

 

Can you show your code for registering the item seed and plant block?

 

Generally the code looks like it should work, but it looks like it will only plant on dirt or grass and also with item seeds it is important to construct it to properly reference the plant block.

 

One other possibility is that maybe it is placing the plant but it is not rendering?  Do you have a custom texture?

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

It is possible something is just wrong with the rendering or position of the block when placed.

 

However, the built-in crops have some things to consider.  Interestingly, other blocks may have a canSustainPlant() method and that checks for the plant type.  So you can quickly run into trouble if you make a custom block type that you want to plant on different blocks than usual. In other words, your ability to plant on a block is actually also dependent on the other block.

 

I've recently found that if I want to do any unusual custom crops that I tend to no longer implement IGrowable, but just make my own code to handle it all.

 

Anyway, my only other suggestion is you should trace through the code by putting in useful System.out.println() statements at each point.  That way you can tell what code path is being followed and if that matches your expectation.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Could the texture/icon be the problem? In the code for the plant icons texture names I have this:  icons = par1IconRegister.registerIcon(CucumbersMod.MODID + ":" + "cucumberplant" + i);

 

And in resources I named them cucumberplant1 , cucumberplant2, cucumberplant3

 

Could I naming the textures wrong?

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.

Announcements



×
×
  • Create New...

Important Information

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