MC Modding
Please register and join the community!

[1.8.1] Sugarcane-like Plant

View previous topic View next topic Go down

[1.8.1] Sugarcane-like Plant

Post by Strengthowns on Wed Oct 05, 2011 10:50 am

Sugarcane-like Plant

Spoiler:
mod_Namehere
Code:
package net.minecraft.src;

import java.util.Random;

public class mod_Namehere extends BaseMod
{

    public mod_Namehere()
    {
        ModLoader.RegisterBlock(Namehere);
        ModLoader.AddName(Namehere, "Namehere");
        ModLoader.AddRecipe(new ItemStack(Item.redstone, 3), new Object[] {
            "#", Character.valueOf('#'), Namehere
        });
    }

    public void GenerateSurface(World world, Random random, int i, int j)
    {
        if(random.nextInt(20) == 0)
        {
            for(int k = 0; k < 16; k++)
            {
                for(int l = 0; l < 16; l++)
                {
                    int i1 = random.nextInt(200);
                    if(world.getBlockId(i + l, i1, j + k) != Block.grass.blockID || !world.isAirBlock(i + l, i1 + 1, j + k))
                    {
                        continue;
                    }
                    int j1 = random.nextInt(2);
                    if(j1 == 0)
                    {
                        world.setBlock(i + l, i1 + 1, j + k, Namehere.blockID);
                    }
                    if(j1 == 1)
                    {
                        world.setBlock(i + l, i1 + 1, j + k, Namehere.blockID);
                        world.setBlock(i + l, i1 + 2, j + k, Namehere.blockID);
                    }
                    if(j1 == 2)
                    {
                        world.setBlock(i + l, i1 + 1, j + k, Namehere.blockID);
                        world.setBlock(i + l, i1 + 2, j + k, Namehere.blockID);
                        world.setBlock(i + l, i1 + 3, j + k, Namehere.blockID);
                    }
               if(j1 == 3)
                    {
                        world.setBlock(i + l, i1 + 1, j + k, Namehere.blockID);
                        world.setBlock(i + l, i1 + 2, j + k, Namehere.blockID);
                        world.setBlock(i + l, i1 + 3, j + k, Namehere.blockID);
                  world.setBlock(i + l, i1 + 4, j + k, Namehere.blockID);
                    }
                }

            }

        }
    }

    public String Version()
    {
        return "1.7.3";
    }

    public static Block Namehere = (new BlockNamehere(124, ModLoader.addOverride("/terrain.png", "/Namehere.png"))).setHardness(0.0F).setResistance(0.0F).setBlockName("Namehere");

}

BlockNamehere
Code:
package net.minecraft.src;

import java.util.Random;

public class BlockNamehere extends Block
{

    protected BlockNamehere(int i, int j)
    {
        super(i, Material.plants);
        blockIndexInTexture = j;
        float f = 0.375F;
        setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 1.0F, 0.5F + f);
        setTickOnLoad(true);
    }

    public void updateTick(World world, int i, int j, int k, Random random)
    {
        if(world.isAirBlock(i, j + 1, k))
        {
            int l;
            for(l = 1; world.getBlockId(i, j - l, k) == blockID; l++) { }
            if(l < 3)
            {
                int i1 = world.getBlockMetadata(i, j, k);
                if(i1 == 15)
                {
                    world.setBlockWithNotify(i, j + 1, k, blockID);
                    world.setBlockMetadataWithNotify(i, j, k, 0);
                } else
                {
                    world.setBlockMetadataWithNotify(i, j, k, i1 + 1);
                }
            }
        }
    }

    public boolean canPlaceBlockAt(World world, int i, int j, int k)
    {
        int l = world.getBlockId(i, j - 1, k);
        if(l == blockID)
        {
            return true;
        }
        return l == Block.grass.blockID || l == Block.dirt.blockID;
    }

    public void onNeighborBlockChange(World world, int i, int j, int k, int l)
    {
        checkBlockCoordValid(world, i, j, k);
    }

    protected final void checkBlockCoordValid(World world, int i, int j, int k)
    {
        if(!canBlockStay(world, i, j, k))
        {
            dropBlockAsItem(world, i, j, k, world.getBlockMetadata(i, j, k));
            world.setBlockWithNotify(i, j, k, 0);
        }
    }

    public boolean canBlockStay(World world, int i, int j, int k)
    {
        return canPlaceBlockAt(world, i, j, k);
    }

    public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int i, int j, int k)
    {
        return null;
    }

    public int idDropped(int i, Random random)
    {
        return mod_Namehere.Namehere.blockID;
    }

    public boolean isOpaqueCube()
    {
        return false;
    }

    public boolean renderAsNormalBlock()
    {
        return false;
    }

    public int getRenderType()
    {
        return 1;
    }
}

Help: mod_Namehere

1. Where it has all of this stuff, (4 parts to it)
Code:
                    if(j1 == 1)
                    {
                        world.setBlock(i + l, i1 + 1, j + k, Namehere.blockID);
                        world.setBlock(i + l, i1 + 2, j + k, Namehere.blockID);
                    }
You can copy paste more onto the end to make it grow to a bigger height. Of course, you need to change some numbers around. Just look for the pattern.

Help: BlockNamehere

1. At this bit:
Code:
    public boolean canPlaceBlockAt(World world, int i, int j, int k)
    {
        int l = world.getBlockId(i, j - 1, k);
        if(l == blockID)
        {
            return true;
        }
        return l == Block.grass.blockID || l == Block.dirt.blockID;
   
You can change it or add more blocks to what you want it to be able to be placed on.

2. Your sugarcane-like plant will spawn on grass/dirt but for some reason it won't be beside water.
avatar
Strengthowns
Admin

Posts : 79
Join date : 2011-06-14
Location : Right here!

View user profile http://www.mcmodding.4umer.com

Back to top Go down

Re: [1.8.1] Sugarcane-like Plant

Post by megahostile123 on Sat Nov 12, 2011 5:08 pm

how can i get it so it wouldnt generate but it can be placed and will grow
Trying to make a diamond suagrcane

megahostile123
Member

Posts : 4
Join date : 2011-11-06

View user profile

Back to top Go down

Re: [1.8.1] Sugarcane-like Plant

Post by megahostile123 on Sun Nov 13, 2011 3:56 pm

anyone?

megahostile123
Member

Posts : 4
Join date : 2011-11-06

View user profile

Back to top Go down

Re: [1.8.1] Sugarcane-like Plant

Post by lcass on Sun Nov 13, 2011 10:40 pm

remove public void Generate Surface world (world,world

lcass
Member

Posts : 145
Join date : 2011-10-24
Location : england

View user profile http://www.youtube.com/user/thealcasgroup

Back to top Go down

Re: [1.8.1] Sugarcane-like Plant

Post by megahostile123 on Mon Nov 14, 2011 11:31 pm

THanks

megahostile123
Member

Posts : 4
Join date : 2011-11-06

View user profile

Back to top Go down

Re: [1.8.1] Sugarcane-like Plant

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum