[1.8.1] Crop
+3
lcass
austin56101
Strengthowns
7 posters
MC Modding :: Modding :: Singleplayer Modding :: Tutorials
Page 1 of 2
Page 1 of 2 • 1, 2
[1.8.1] Crop
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!
Re: [1.8.1] Crop
Do you think you can make a video on this? I've tried several times, and I failed lol
austin56101- Moderator
- Posts : 85
Join date : 2011-10-22
Age : 28
Location : Cali!
Re: [1.8.1] Crop
hey mannn can you comment on this?
also make bonemeal work?
also make bonemeal work?
austin56101- Moderator
- Posts : 85
Join date : 2011-10-22
Age : 28
Location : Cali!
Re: [1.8.1] Crop
well we dont get an error all that happens is it dosn't grow and bone meal dosn't work on it and then when you destroy it it dosn't return the item that was said in the namhere.java return method. DANG lots of dosn't
Re: [1.8.1] Crop
It should. I test all of the code for my tutorials and it works fine. I don't know what the problem is then. Show me your mod_ files.
Re: [1.8.1] Crop
well i deleted it (clean up) since it didnt work
also i just copied pasted and renamed
and it worked but they didnt grow
also didnt work with bone meal
also i just copied pasted and renamed
and it worked but they didnt grow
also didnt work with bone meal
austin56101- Moderator
- Posts : 85
Join date : 2011-10-22
Age : 28
Location : Cali!
Re: [1.8.1] Crop
austin56101 wrote:well i deleted it (clean up) since it didnt work
also i just copied pasted and renamed
and it worked but they didnt grow
also didnt work with bone meal
Well it's garenteed not to work with bonemeal because the code for how bonemeal reacts to plants is in ItemDye.java not in the blocks it effects.
groxmapper- Member
- Posts : 27
Join date : 2011-10-24
Re: [1.8.1] Crop
well can it be restated to work here as well?
austin56101- Moderator
- Posts : 85
Join date : 2011-10-22
Age : 28
Location : Cali!
Re: [1.8.1] Crop
[code]package net.minecraft.src;
import java.util.*;
public class mod_superwheat extends BaseMod
{
public static int growsuperwheat1 = ModLoader.addOverride("/terrain.png", "/crystal/1wheat.png");
public static int growsuperwheat2 = ModLoader.addOverride("/terrain.png", "/crystal/2wheat.png");
public static int growsuperwheat3 = ModLoader.addOverride("/terrain.png", "/crystal/3wheat.png");
public static int growsuperwheat4 = ModLoader.addOverride("/terrain.png", "/crystal/4wheat.png");
public static int growsuperwheat5 = ModLoader.addOverride("/terrain.png", "/crystal/5wheat.png");
public static int growsuperwheat6 = ModLoader.addOverride("/terrain.png", "/crystal/6wheat.png");
public static int growsuperwheat7 = ModLoader.addOverride("/terrain.png", "/crystal/7wheat.png");
public static int growsuperwheat8 = ModLoader.addOverride("/terrain.png", "/crystal/8wheat.png");
public static final Block superwheatblock = new superwheatblock(200, 0).setBlockName("superwheat");
public static final Item superwheat = new superwheat(4000, mod_superwheat.superwheatblock.blockID).setItemName("superwheatblock");
public mod_superwheat()
{
ModLoader.AddName(superwheat, "superwheat");
superwheatblock.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/crystal/wheatblock.png");
ModLoader.AddName(superwheat, "superwheat");
superwheat.iconIndex = ModLoader.addOverride("/gui/items.png", "/crystal/wheatitem.png");
}
public String Version()
{
return "1.8.1";
}
}
import java.util.*;
public class mod_superwheat extends BaseMod
{
public static int growsuperwheat1 = ModLoader.addOverride("/terrain.png", "/crystal/1wheat.png");
public static int growsuperwheat2 = ModLoader.addOverride("/terrain.png", "/crystal/2wheat.png");
public static int growsuperwheat3 = ModLoader.addOverride("/terrain.png", "/crystal/3wheat.png");
public static int growsuperwheat4 = ModLoader.addOverride("/terrain.png", "/crystal/4wheat.png");
public static int growsuperwheat5 = ModLoader.addOverride("/terrain.png", "/crystal/5wheat.png");
public static int growsuperwheat6 = ModLoader.addOverride("/terrain.png", "/crystal/6wheat.png");
public static int growsuperwheat7 = ModLoader.addOverride("/terrain.png", "/crystal/7wheat.png");
public static int growsuperwheat8 = ModLoader.addOverride("/terrain.png", "/crystal/8wheat.png");
public static final Block superwheatblock = new superwheatblock(200, 0).setBlockName("superwheat");
public static final Item superwheat = new superwheat(4000, mod_superwheat.superwheatblock.blockID).setItemName("superwheatblock");
public mod_superwheat()
{
ModLoader.AddName(superwheat, "superwheat");
superwheatblock.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/crystal/wheatblock.png");
ModLoader.AddName(superwheat, "superwheat");
superwheat.iconIndex = ModLoader.addOverride("/gui/items.png", "/crystal/wheatitem.png");
}
public String Version()
{
return "1.8.1";
}
}
Re: [1.8.1] Crop
austin56101 wrote:well can it be restated to work here as well?
In terms of bonemeal, unless you edit ItemDye.java you'll need to make a new item or use blockActivated like so:
- Code:
public boolean blockActivated(World world, int i, int j, int k, EntityPlayer entityplayer)
{
if(entityplayer.inventory.getCurrentItem() != null && entityplayer.inventory.getCurrentItem().itemID == Item.bonemeal.shiftedIndex) // guessing on bonemeal, check Item.java if this doesn't work
{
//put sapling grow code here
}else
{
super.blockActivated(world, i, j, k, entityplayer);
}
}
Last edited by groxmapper on Wed Oct 26, 2011 9:41 pm; edited 1 time in total
groxmapper- Member
- Posts : 27
Join date : 2011-10-24
Re: [1.8.1] Crop
Icass use code tags please, thanks:)
austin56101- Moderator
- Posts : 85
Join date : 2011-10-22
Age : 28
Location : Cali!
Re: [1.8.1] Crop
I know it messed up GRATS on becoming mod ALSO austin I will be adding some tutorials aswell I finally know how to do the furnace like item thing making anything you want so many I will put it up tonight (hopefully) I just spent the past to hours eating kit kats and meringues editing mojangs code to get it to function as a diffrent item!!!!!
Re: [1.8.1] Crop
Good aha I've been the only one adding tuts aha
And lolz
And lolz
austin56101- Moderator
- Posts : 85
Join date : 2011-10-22
Age : 28
Location : Cali!
Re: [1.8.1] Crop
Sweet. Looking forward to it!
austin56101- Moderator
- Posts : 85
Join date : 2011-10-22
Age : 28
Location : Cali!
Re: [1.8.1] Crop
oh and how to make a bow and arrow I tried one on zidmc that was copyied from someone else by this kid like 7 years old and guess what IT didn't work so I will do one here hopefull people will like it. yay i might be doing the coco mod I do love my s there epic
Re: [1.8.1] Crop
lol yeah
well all working tuts are welcome!
well all working tuts are welcome!
austin56101- Moderator
- Posts : 85
Join date : 2011-10-22
Age : 28
Location : Cali!
Re: [1.8.1] Crop
Wait... if I used this exact code, pretty much, what would I use for seeds, if you know what I mean
jesshankin22- Member
- Posts : 47
Join date : 2011-10-24
Re: [1.8.1] Crop
idk i couldnt get it o work :/
like mine wouldnt grow
like mine wouldnt grow
austin56101- Moderator
- Posts : 85
Join date : 2011-10-22
Age : 28
Location : Cali!
Re: [1.8.1] Crop
yeah but what did you use as seeds?
jesshankin22- Member
- Posts : 47
Join date : 2011-10-24
Re: [1.8.1] Crop
not sure :/
austin56101- Moderator
- Posts : 85
Join date : 2011-10-22
Age : 28
Location : Cali!
Page 1 of 2 • 1, 2
MC Modding :: Modding :: Singleplayer Modding :: Tutorials
Page 1 of 2
Permissions in this forum:
You cannot reply to topics in this forum