HelpNation Tutorials

Would you like to react to this message? Create an account in a few clicks or log in to continue.
HelpNation Tutorials

Learn how to mod, make, read, or just review modding tutorials and mods!


    [Creating Mods]Sugar-Cane Like Block [Windows + Mac][1.0][Intermediate]

    Original
    Original


    Posts : 8
    Join date : 2011-12-11
    Age : 27
    Location : Folsom, CA, USA

    [Creating Mods]Sugar-Cane Like Block [Windows + Mac][1.0][Intermediate] Empty [Creating Mods]Sugar-Cane Like Block [Windows + Mac][1.0][Intermediate]

    Post  Original Sun Dec 11, 2011 10:45 pm

    If you are on a Mac look at my Setup tutorial then you can code away

    This tutorial is more difficult and i'm not the best with these kinds of mods I might not be able to help as much

    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

    At
    Code:
     if(j1 == 1)
                        {
                            world.setBlock(i + l, i1 + 1, j + k, Namehere.blockID);
                            world.setBlock(i + l, i1 + 2, j + k, Namehere.blockID);
                        } 
    if you want it to grow more then add extra lines and just +1 more
    like this

    Code:
     world.setBlock(i + l, i1 + 3, j + k, Namehere.blockID);
    world.setBlock(i + l, i1 + 4, j + k, Namehere.blockID);

    Help: BlockNamehere

    At
    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 or add more blocks that it can spawn on

      Current date/time is Thu May 09, 2024 7:09 am