MC Modding
Please register and join the community!

[1.8.1] Crop

Page 2 of 2 Previous  1, 2

View previous topic View next topic Go down

[1.8.1] Crop

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

First topic message reminder :

Crop

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

public class ItemNamehere extends Item
{

    public ItemNamehere(int i, int j)
    {
        super(i);
        field_318_a = j;
    }

    public boolean onItemUse(ItemStack itemstack, EntityPlayer entityplayer, World world, int i, int j, int k, int l)
    {
        if(l != 1)
        {
            return false;
        }
        if(!entityplayer.func_35190_e(i, j, k) || !entityplayer.func_35190_e(i, j + 1, k))
        {
            return false;
        }
        int i1 = world.getBlockId(i, j, k);
        if(i1 == Block.tilledField.blockID && world.isAirBlock(i, j + 1, k))
        {
            world.setBlockWithNotify(i, j + 1, k, field_318_a);
            itemstack.stackSize--;
            return true;
        } else
        {
            return false;
        }
    }

    private int field_318_a;
}

mod_Namehere
Code:
package net.minecraft.src;

import java.util.*;

public class mod_Namehere extends BaseMod
{
    public static int growNamehere1 = ModLoader.addOverride("/terrain.png", "/growNamehere1.png");
    public static int growNamehere2 = ModLoader.addOverride("/terrain.png", "/growNamehere2.png");
    public static int growNamehere3 = ModLoader.addOverride("/terrain.png", "/growNamehere3.png");
    public static int growNamehere4 = ModLoader.addOverride("/terrain.png", "/growNamehere4.png");
    public static int growNamehere5 = ModLoader.addOverride("/terrain.png", "/growNamehere5.png");
    public static int growNamehere6 = ModLoader.addOverride("/terrain.png", "/growNamehere6.png");
    public static int growNamehere7 = ModLoader.addOverride("/terrain.png", "/growNamehere7.png");
    public static int growNamehere8 = ModLoader.addOverride("/terrain.png", "/growNamehere8.png");
   
    public static final Block Nameherecrop = new BlockNameherecrop(200, 0).setBlockName("Nameherecrop");
    public static final Item Namehere = new ItemNamehere(4000, mod_Namehere.Nameherecrop.blockID).setItemName("Namehere");

    public mod_Namehere()
    {
        ModLoader.AddName(Nameherecrop, "Namehere Crop");
        Nameherecrop.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/Nameherecrop.png");
      
        ModLoader.AddName(Namehere, "Namehere");
        Namehere.iconIndex = ModLoader.addOverride("/gui/items.png", "/Namehere.png");
    }
   
   public String Version()
   {
      return "1.8.1";
   }
}

BlockNameherecrop
Code:
package net.minecraft.src;

import java.util.Random;

public class BlockNameherecrop extends BlockFlower
{

    protected BlockNameherecrop(int i, int j)
    {
        super(i, j);
        blockIndexInTexture = j;
        setTickOnLoad(true);
        float f = 0.5F;
        setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 0.25F, 0.5F + f);
    }

    protected boolean canThisPlantGrowOnThisBlockID(int i)
    {
        return i == Block.tilledField.blockID;
    }

    public void updateTick(World world, int i, int j, int k, Random random)
    {
        super.updateTick(world, i, j, k, random);
        if(world.getBlockLightValue(i, j + 1, k) >= 9)
        {
            int l = world.getBlockMetadata(i, j, k);
            if(l < 7)
            {
                float f = getGrowthRate(world, i, j, k);
                if(random.nextInt((int)(100F / f)) == 0)
                {
                    l++;
                    world.setBlockMetadataWithNotify(i, j, k, l);
                }
            }
        }
    }

    public void fertilize(World world, int i, int j, int k)
    {
        world.setBlockMetadataWithNotify(i, j, k, 7);
    }

    private float getGrowthRate(World world, int i, int j, int k)
    {
        float f = 1.0F;
        int l = world.getBlockId(i, j, k - 1);
        int i1 = world.getBlockId(i, j, k + 1);
        int j1 = world.getBlockId(i - 1, j, k);
        int k1 = world.getBlockId(i + 1, j, k);
        int l1 = world.getBlockId(i - 1, j, k - 1);
        int i2 = world.getBlockId(i + 1, j, k - 1);
        int j2 = world.getBlockId(i + 1, j, k + 1);
        int k2 = world.getBlockId(i - 1, j, k + 1);
        boolean flag = j1 == blockID || k1 == blockID;
        boolean flag1 = l == blockID || i1 == blockID;
        boolean flag2 = l1 == blockID || i2 == blockID || j2 == blockID || k2 == blockID;
        for(int l2 = i - 1; l2 <= i + 1; l2++)
        {
            for(int i3 = k - 1; i3 <= k + 1; i3++)
            {
                int j3 = world.getBlockId(l2, j - 1, i3);
                float f1 = 0.0F;
                if(j3 == Block.tilledField.blockID)
                {
                    f1 = 1.0F;
                    if(world.getBlockMetadata(l2, j - 1, i3) > 0)
                    {
                        f1 = 3F;
                    }
                }
                if(l2 != i || i3 != k)
                {
                    f1 /= 4F;
                }
                f += f1;
            }

        }

        if(flag2 || flag && flag1)
        {
            f /= 2.0F;
        }
        return f;
    }
 
    public int getBlockTextureFromSideAndMetadata(int i, int j)
    {
        if(j == 0)
        {
          return blockIndexInTexture;
        }
        if(j == 1)
        {
          return mod_Namehere.growNamehere1;
        }
        if(j == 2)
        {
          return mod_Namehere.growNamehere2;
        }
        if(j == 3)
        {
          return mod_Namehere.growNamehere3;
        }
        if(j == 4)
        {
          return mod_Namehere.growNamehere4;
        }
        if(j == 5)
        {
          return mod_Namehere.growNamehere5;
        }
        if(j == 6)
        {
          return mod_Namehere.growNamehere6;
        }
        if(j == 7)
        {
          return mod_Namehere.growNamehere7;
        }
        if(j == 8)
        {
          return mod_Namehere.growNamehere8;
        }
      return j;
    }

    public int getRenderType()
    {
        return 6;
    }

    public int idDropped(int i, Random random)
    {
        if(i == 5)
        {
            return Item.redstone.shiftedIndex;
        } else
        {
            return -1;
        }
    }
   

    public int quantityDropped(Random random)
    {
        return 1;
    }
}

Help: ItemNamehere

1. Just leave everything here as is. You can use this exact same code for any different seeds you want to do.

Help: mod_Namehere

1. All of the "public static int" parts at the top for textures means that you are just registering the textures for the stages in the crop's growth.

2. For the "public static final Item Namehere", after the ID you change the "mod_Blabla" to what crop you want it to place when you use it on the tilled field.

3. You should know the rest, refer to "Block" tutorial for more help on the basics.

Help: BlockNameherecrop

1. The "canThisPlantGrowOnThisBlockID" part is self explaining, this is what you want it to be able to grow on.

2. A little bit further down it has this line "if(world.getBlockLightValue(i, j + 1, k) >= 9)", change the ">= 9" to what ever light level you want it to grow in (Highest light level is 15, that's the brightest the sun goes). That part means that it will grow in a light level of either 9 or higher. You could also make it grow in a light value of say 6 or lower ("<= 6").

3. In the "getGrowthRate" you can change this part "float f = 1.0F;" to how fast you want it to grow.

4. The "getBlockTextureFromSideAndMetadata" part is just saying what textures it will use at what growth level.

5. In the "idDropped" bit, the 5 is how rare a chance it is of getting the redstone dust. (Higher the number, more rare of a drop it is)

6. "quantityDropped" is self explanatory, change it to how much of the block/item you want it to drop when it does.

7. That's it! Enjoy making your new crops!
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] Crop

Post by lcass on Sat Oct 29, 2011 1:07 pm

you would set it as an item and then do the same action onitemrightclick (action) copy the code from seeds

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] Crop

Post by MrCreeper07 on Sat Oct 29, 2011 5:08 pm

so this crop tutorial doesn't work?
avatar
MrCreeper07
Member

Posts : 18
Join date : 2011-10-23

View user profile

Back to top Go down

Re: [1.8.1] Crop

Post by austin56101 on Sat Oct 29, 2011 7:49 pm

MrCreeper07 wrote:so this crop tutorial doesn't work?

well not for me
i think it needs to be remade Mad
avatar
austin56101
Moderator
Moderator

Posts : 85
Join date : 2011-10-22
Age : 21
Location : Cali!

View user profile

Back to top Go down

Re: [1.8.1] Crop

Post by MrCreeper07 on Sat Oct 29, 2011 9:41 pm

oh dang it!! I need to add one more thing before i update my mod and I'm just having so much trouble! I get errors on the torch and the on and off light recompiles fine but crashes my minecraft!!! UGH!! IM SO ANNOYED!!!
avatar
MrCreeper07
Member

Posts : 18
Join date : 2011-10-23

View user profile

Back to top Go down

Re: [1.8.1] Crop

Post by jesshankin22 on Sat Oct 29, 2011 11:43 pm

could you possibly make the tall grass drop two blocks and have the crop come out of it without making a whole new code?

jesshankin22
Member

Posts : 47
Join date : 2011-10-24

View user profile

Back to top Go down

Re: [1.8.1] Crop

Post by jesshankin22 on Sun Oct 30, 2011 3:32 am

I figured it out. the code DOES in fact work, but you need a way to get the seeds. For mine, I made it so that you can craft the seeds/crop

jesshankin22
Member

Posts : 47
Join date : 2011-10-24

View user profile

Back to top Go down

Re: [1.8.1] Crop

Post by austin56101 on Sun Oct 30, 2011 4:10 am

Does it grow?
avatar
austin56101
Moderator
Moderator

Posts : 85
Join date : 2011-10-22
Age : 21
Location : Cali!

View user profile

Back to top Go down

Re: [1.8.1] Crop

Post by jesshankin22 on Sun Oct 30, 2011 4:19 am

sure does

jesshankin22
Member

Posts : 47
Join date : 2011-10-24

View user profile

Back to top Go down

Re: [1.8.1] Crop

Post by jesshankin22 on Sun Oct 30, 2011 8:11 am

except, there's some weird thing going on where it only gives me stone and grass blocks no matter what i type. there is nothing in the code that says that so im a little perplexed

jesshankin22
Member

Posts : 47
Join date : 2011-10-24

View user profile

Back to top Go down

Re: [1.8.1] Crop

Post by xx0m3gaxx on Fri Nov 11, 2011 4:42 pm

I have gotten it so I can plant the seeds( has to be wet soil or it goes back to dirt from farmland) but some other problems is that it seems my textures wont load thru out the growing proses and I'm not sure why, any ideas?

EDIT
found my texture problem, any idea why it allows the farmland that is not wet to turn back into dirt?

xx0m3gaxx
Member

Posts : 2
Join date : 2011-11-11

View user profile

Back to top Go down

Re: [1.8.1] Crop

Post by jesshankin22 on Fri Nov 11, 2011 10:02 pm

that is part of the game... it turns to dirt unless it's hydrated.....

jesshankin22
Member

Posts : 47
Join date : 2011-10-24

View user profile

Back to top Go down

Re: [1.8.1] Crop

Post by xx0m3gaxx on Sat Nov 12, 2011 1:41 pm

with normal grass seeds it stays as farmland even without water, water just makes it grow faster, guess its in the coding of the farmland block.

Only other problem I am having now is my plants never reach stage 8 even when i have them grow 50X normal speed they never reach the last stage any idea?

xx0m3gaxx
Member

Posts : 2
Join date : 2011-11-11

View user profile

Back to top Go down

Re: [1.8.1] Crop

Post by jesshankin22 on Sun Nov 13, 2011 2:24 am

yeah same problem with mine, but I would suggest putting it in the help section

jesshankin22
Member

Posts : 47
Join date : 2011-10-24

View user profile

Back to top Go down

Re: [1.8.1] Crop

Post by Sponsored content


Sponsored content


Back to top Go down

Page 2 of 2 Previous  1, 2

View previous topic View next topic Back to top


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