[1.8.1] Sugarcane-like Plant
3 posters
MC Modding :: Modding :: Singleplayer Modding :: Tutorials
Page 1 of 1
[1.8.1] Sugarcane-like Plant
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);
}
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;
2. Your sugarcane-like plant will spawn on grass/dirt but for some reason it won't be beside water.
Re: [1.8.1] Sugarcane-like Plant
how can i get it so it wouldnt generate but it can be placed and will grow
Trying to make a diamond suagrcane
Trying to make a diamond suagrcane
megahostile123- Member
- Posts : 4
Join date : 2011-11-06
MC Modding :: Modding :: Singleplayer Modding :: Tutorials
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum