Basic Flowers
Flowers are a two step process. First, declare your new plant as so:
public final static BlockFlower TutFlower= (BlockFlower) new BlockTutFlower(174, 3).setBlockName("TutFlower");
Just like before, TutFlower is the code name of your new plant. new BlockTutFlower is the class that will be called. (174, 3) is the id and then the icon index, respectively.
Now on to the BlockTutFlower class:
package tutorial.package;
import java.util.Random;
import net.minecraft.block.BlockFlower;
public class BlockBrocFlower extends BlockFlower
{
public BlockBrocFlower(int id, int iconindex)
{
super(id, iconindex);
}
public int idDropped(int i, Random random, int j)
{
return TutorialMain.bTutFlower.itemID;
}
public String getTextureFile()
{
return "/tutorial/textures/blocks.png"; //Textures for these are the same as blocks, ignore this line and use block textures. I'll change it soon :P
}
}
Now you might be wondering what bTutFlower is. Flowers can't be placed like blocks. They must be placed through items, similar to redstone. Anyway, declare a new item in your main file, but instead of calling it as Item, declare it as a new class you will make. Mine is called bTutFlower and it's code is:
package tutorial.package;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public class ItembTutFlower extends Item
{
public ItembTutFlower(int par1, int par2, float par3, boolean par4){
super(par1);
this.setCreativeTab(CreativeTabs.tabDecorations);
}
@Override
public String getTextureFile()
{
return "/tutorial/textures/items.png";
}
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
{
if (par3World.getBlockId(par4, par5, par6) != Block.snow.blockID)
{
if (par7 == 0)
{
--par5;
}
if (par7 == 1)
{
++par5;
}
if (par7 == 2)
{
--par6;
}
if (par7 == 3)
{
++par6;
}
if (par7 == 4)
{
--par4;
}
if (par7 == 5)
{
++par4;
}
if (!par3World.isAirBlock(par4, par5, par6))
{
return false;
}
}
if (!par2EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack))
{
return false;
}
else
{
if (TutorialMain.TutFlower.canPlaceBlockAt(par3World, par4, par5, par6))
{
--par1ItemStack.stackSize;
par3World.setBlock(par4, par5, par6, TutorialMain.TutFlower.blockID);
}
return true;
}}
}
This end line of code right above this text will tell you what block will be placed if the bTutFlower, the item, is right clicked on the ground.
That should do it for a flower tutorial, now on to creative tabs!
public final static BlockFlower TutFlower= (BlockFlower) new BlockTutFlower(174, 3).setBlockName("TutFlower");
Just like before, TutFlower is the code name of your new plant. new BlockTutFlower is the class that will be called. (174, 3) is the id and then the icon index, respectively.
Now on to the BlockTutFlower class:
package tutorial.package;
import java.util.Random;
import net.minecraft.block.BlockFlower;
public class BlockBrocFlower extends BlockFlower
{
public BlockBrocFlower(int id, int iconindex)
{
super(id, iconindex);
}
public int idDropped(int i, Random random, int j)
{
return TutorialMain.bTutFlower.itemID;
}
public String getTextureFile()
{
return "/tutorial/textures/blocks.png"; //Textures for these are the same as blocks, ignore this line and use block textures. I'll change it soon :P
}
}
Now you might be wondering what bTutFlower is. Flowers can't be placed like blocks. They must be placed through items, similar to redstone. Anyway, declare a new item in your main file, but instead of calling it as Item, declare it as a new class you will make. Mine is called bTutFlower and it's code is:
package tutorial.package;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public class ItembTutFlower extends Item
{
public ItembTutFlower(int par1, int par2, float par3, boolean par4){
super(par1);
this.setCreativeTab(CreativeTabs.tabDecorations);
}
@Override
public String getTextureFile()
{
return "/tutorial/textures/items.png";
}
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
{
if (par3World.getBlockId(par4, par5, par6) != Block.snow.blockID)
{
if (par7 == 0)
{
--par5;
}
if (par7 == 1)
{
++par5;
}
if (par7 == 2)
{
--par6;
}
if (par7 == 3)
{
++par6;
}
if (par7 == 4)
{
--par4;
}
if (par7 == 5)
{
++par4;
}
if (!par3World.isAirBlock(par4, par5, par6))
{
return false;
}
}
if (!par2EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack))
{
return false;
}
else
{
if (TutorialMain.TutFlower.canPlaceBlockAt(par3World, par4, par5, par6))
{
--par1ItemStack.stackSize;
par3World.setBlock(par4, par5, par6, TutorialMain.TutFlower.blockID);
}
return true;
}}
}
This end line of code right above this text will tell you what block will be placed if the bTutFlower, the item, is right clicked on the ground.
That should do it for a flower tutorial, now on to creative tabs!