[1.8.1] Tree
+4
austin56101
the undecided t
bottz2
Strengthowns
8 posters
MC Modding :: Modding :: Singleplayer Modding :: Tutorials
Page 1 of 1
[1.8.1] Tree
Tree
- Spoiler:
- BlockNamehereLeaves
- Code:
package net.minecraft.src;
import java.util.Random;
public class BlockNamehereLeaves extends BlockLeavesBase
{
protected BlockNamehereLeaves(int i, int j)
{
super(i, j, Material.leaves, false);
baseIndexInPNG = j;
setTickOnLoad(true);
}
public int idDropped(int i, Random random)
{
if(random.nextInt(3) == 0)
{
return Item.redstone.shiftedIndex;
} else
{
return -1;
}
}
public void updateTick(World world, int i, int j, int k, Random random)
{
if(world.multiplayerWorld)
{
return;
}
int l = world.getBlockMetadata(i, j, k);
if((l & 8) != 0)
{
byte byte0 = 4;
int i1 = byte0 + 1;
byte byte1 = 32;
int j1 = byte1 * byte1;
int k1 = byte1 / 2;
if(adjacentTreeBlocks == null)
{
adjacentTreeBlocks = new int[byte1 * byte1 * byte1];
}
if(world.checkChunksExist(i - i1, j - i1, k - i1, i + i1, j + i1, k + i1))
{
for(int l1 = -byte0; l1 <= byte0; l1++)
{
for(int k2 = -byte0; k2 <= byte0; k2++)
{
for(int i3 = -byte0; i3 <= byte0; i3++)
{
int k3 = world.getBlockId(i + l1, j + k2, k + i3);
if(k3 == mod_NamehereTree.NamehereWood.blockID)
{
adjacentTreeBlocks[(l1 + k1) * j1 + (k2 + k1) * byte1 + (i3 + k1)] = 0;
continue;
}
if(k3 == mod_NamehereTree.NamehereLeaves.blockID)
{
adjacentTreeBlocks[(l1 + k1) * j1 + (k2 + k1) * byte1 + (i3 + k1)] = -2;
} else
{
adjacentTreeBlocks[(l1 + k1) * j1 + (k2 + k1) * byte1 + (i3 + k1)] = -1;
}
}
}
}
for(int i2 = 1; i2 <= 4; i2++)
{
for(int l2 = -byte0; l2 <= byte0; l2++)
{
for(int j3 = -byte0; j3 <= byte0; j3++)
{
for(int l3 = -byte0; l3 <= byte0; l3++)
{
if(adjacentTreeBlocks[(l2 + k1) * j1 + (j3 + k1) * byte1 + (l3 + k1)] != i2 - 1)
{
continue;
}
if(adjacentTreeBlocks[((l2 + k1) - 1) * j1 + (j3 + k1) * byte1 + (l3 + k1)] == -2)
{
adjacentTreeBlocks[((l2 + k1) - 1) * j1 + (j3 + k1) * byte1 + (l3 + k1)] = i2;
}
if(adjacentTreeBlocks[(l2 + k1 + 1) * j1 + (j3 + k1) * byte1 + (l3 + k1)] == -2)
{
adjacentTreeBlocks[(l2 + k1 + 1) * j1 + (j3 + k1) * byte1 + (l3 + k1)] = i2;
}
if(adjacentTreeBlocks[(l2 + k1) * j1 + ((j3 + k1) - 1) * byte1 + (l3 + k1)] == -2)
{
adjacentTreeBlocks[(l2 + k1) * j1 + ((j3 + k1) - 1) * byte1 + (l3 + k1)] = i2;
}
if(adjacentTreeBlocks[(l2 + k1) * j1 + (j3 + k1 + 1) * byte1 + (l3 + k1)] == -2)
{
adjacentTreeBlocks[(l2 + k1) * j1 + (j3 + k1 + 1) * byte1 + (l3 + k1)] = i2;
}
if(adjacentTreeBlocks[(l2 + k1) * j1 + (j3 + k1) * byte1 + ((l3 + k1) - 1)] == -2)
{
adjacentTreeBlocks[(l2 + k1) * j1 + (j3 + k1) * byte1 + ((l3 + k1) - 1)] = i2;
}
if(adjacentTreeBlocks[(l2 + k1) * j1 + (j3 + k1) * byte1 + (l3 + k1 + 1)] == -2)
{
adjacentTreeBlocks[(l2 + k1) * j1 + (j3 + k1) * byte1 + (l3 + k1 + 1)] = i2;
}
}
}
}
}
}
int j2 = adjacentTreeBlocks[k1 * j1 + k1 * byte1 + k1];
if(j2 >= 0)
{
world.setBlockMetadata(i, j, k, l & -9);
} else
{
removeLeaves(world, i, j, k);
}
}
}
private void removeLeaves(World world, int i, int j, int k)
{
dropBlockAsItem(world, i, j, k, world.getBlockMetadata(i, j, k));
world.setBlockWithNotify(i, j, k, 0);
}
public void setGraphicsLevel(boolean flag)
{
graphicsLevel = flag;
blockIndexInTexture = baseIndexInPNG + (flag ? 0 : 1);
}
public void onEntityWalking(World world, int i, int j, int k, Entity entity)
{
super.onEntityWalking(world, i, j, k, entity);
}
int adjacentTreeBlocks[];
private int baseIndexInPNG;
}
BlockNamehereWood- Code:
package net.minecraft.src;
import java.util.Random;
public class BlockNamehereWood extends Block
{
protected BlockNamehereWood(int i, int j)
{
super(i, j, Material.wood);
baseIndexInPNG = j;
}
public int quantityDropped(Random random)
{
return 1;
}
public int idDropped(int i, Random random)
{
return mod_NamehereTree.NamehereWood.blockID;
}
public int getBlockTextureFromSide(int i)
{
if(i == 1 || i == 0)
{
return 21;
} else
{
return baseIndexInPNG;
}
}
private int baseIndexInPNG;
}
mod_NamehereTree- Code:
package net.minecraft.src;
import java.util.Random;
public class mod_NamehereTree extends BaseMod
{
public String Version()
{
return "1.7.3";
}
public mod_NamehereTree()
{
ModLoader.AddName(NamehereLeaves, "Namehere Leaves");
ModLoader.AddName(NamehereWood, "Namehere Wood");
ModLoader.RegisterBlock(NamehereLeaves);
ModLoader.RegisterBlock(NamehereWood);
ModLoader.AddRecipe(new ItemStack(Block.planks, 4), new Object[] {
"#", Character.valueOf('#'), NamehereWood
});
ModLoader.AddSmelting(NamehereWood.blockID, new ItemStack(Item.coal, 1, 1));
}
public void GenerateSurface(World world, Random random, int i, int j)
{
BiomeGenBase biomegenbase = world.getWorldChunkManager().getBiomeGenAt(i, j);
WorldGenNamehereTrees worldgennameheretrees = new WorldGenNamehereTrees();
if((biomegenbase instanceof BiomeGenForest) || (biomegenbase instanceof BiomeGenForest))
{
int k = i + random.nextInt(16) + 8;
int l = j + random.nextInt(16) + 8;
int i1 = world.getHeightValue(k, l);
worldgennameheretrees.func_517_a(1.0D, 1.0D, 1.0D);
worldgennameheretrees.generate(world, random, k, i1, l);
}
}
public static final Block NamehereLeaves;
public static final Block NamehereWood;
static
{
NamehereLeaves = (new BlockNamehereLeaves(124, ModLoader.addOverride("/terrain.png", "/NamehereLeaves.png"))).setHardness(0.2F).setLightOpacity(1).setStepSound(Block.soundGrassFootstep).setBlockName("NamehereLeaves").disableStats();
NamehereWood = (new BlockNamehereWood(125, ModLoader.addOverride("/terrain.png", "/NamehereWood.png"))).setHardness(2.0F).setStepSound(Block.soundWoodFootstep).setBlockName("NamehereWood");
}
}
WorldGenNamehereTrees- Code:
package net.minecraft.src;
import java.util.Random;
public class WorldGenNamehereTrees extends WorldGenerator
{
public WorldGenNamehereTrees()
{
}
public boolean generate(World world, Random random, int i, int j, int k)
{
int l = random.nextInt(3) + 4;
boolean flag = true;
if(j < 1 || j + l + 1 > 128)
{
return false;
}
for(int i1 = j; i1 <= j + 1 + l; i1++)
{
byte byte0 = 1;
if(i1 == j)
{
byte0 = 0;
}
if(i1 >= (j + 1 + l) - 2)
{
byte0 = 2;
}
for(int i2 = i - byte0; i2 <= i + byte0 && flag; i2++)
{
for(int l2 = k - byte0; l2 <= k + byte0 && flag; l2++)
{
if(i1 >= 0 && i1 < 128)
{
int j3 = world.getBlockId(i2, i1, l2);
if(j3 != 0 && j3 != Block.leaves.blockID)
{
flag = false;
}
} else
{
flag = false;
}
}
}
}
if(!flag)
{
return false;
}
int j1 = world.getBlockId(i, j - 1, k);
if(j1 != Block.grass.blockID && j1 != Block.dirt.blockID || j >= 128 - l - 1)
{
return false;
}
world.setBlock(i, j - 1, k, Block.dirt.blockID);
for(int k1 = (j - 3) + l; k1 <= j + l; k1++)
{
int j2 = k1 - (j + l);
int i3 = 1 - j2 / 2;
for(int k3 = i - i3; k3 <= i + i3; k3++)
{
int l3 = k3 - i;
for(int i4 = k - i3; i4 <= k + i3; i4++)
{
int j4 = i4 - k;
if((Math.abs(l3) != i3 || Math.abs(j4) != i3 || random.nextInt(2) != 0 && j2 != 0) && !Block.opaqueCubeLookup[world.getBlockId(k3, k1, i4)])
{
world.setBlockAndMetadata(k3, k1, i4, mod_NamehereTree.NamehereLeaves.blockID, 3);
}
}
}
}
for(int l1 = 0; l1 < l; l1++)
{
int k2 = world.getBlockId(i, j + l1, k);
if(k2 == 0 || k2 == Block.leaves.blockID)
{
world.setBlockAndMetadata(i, j + l1, k, mod_NamehereTree.NamehereWood.blockID, 3);
}
}
return true;
}
}
Help: BlockNamehereLeaves1. READ THE BLOCK TUTORIAL FIRST!
1.5. For the ID dropped part, change the 3 to how rare you want your block/item to drop from leaves. Leave the rest of that Id dropped part.
2. At the public void updateblabla, fill in all the Namehere's.
3. Leave the rest of this file.Help: BlockNamehereWood1. Just change names that need to be changed.
2. Ignore all the other stuff.Help: mod_NamehereTree1. If you've read the block tutorial, then you will know just about all of this.
2. At the public generate surfacce whatever bit, where it has the int's and the (16)'s
mess around with this to change how it generates, I'm not too sure just yet.Help: WorldGenNamehereTrees1. All you have to do for this is change the Namehere's and so on.
2. More experienced modders can mess with it to try something different.
Re: [1.8.1] Tree
It is hard as crap to make a sapling... I can't figure it out.bottz2 wrote:how do i make a sapling
Re: [1.8.1] Tree
ok so this one is awkward for me.. lol
when i made it, it comes out were the logs only go up to the start of the leaves xD
when i made it, it comes out were the logs only go up to the start of the leaves xD
austin56101- Moderator
- Posts : 85
Join date : 2011-10-22
Age : 28
Location : Cali!
Re: [1.8.1] Tree
the spaling tut on your mcf post doesnt really work... i tried and it grows normal trees... and it doesnt accept bonemeal
Re: [1.8.1] Tree
You should check in the minecraft code for the trees you could probly copy it and change the textures.
breakyorself- Member
- Posts : 60
Join date : 2011-10-19
Re: [1.8.1] Tree
This is the sapling code from the game:
- Code:
package net.minecraft.src;
import java.util.Random;
// Referenced classes of package net.minecraft.src:
// BlockFlower, World, WorldGenTaiga2, WorldGenForest,
// WorldGenTrees, WorldGenBigTree, WorldGenerator
public class BlockSapling extends BlockFlower
{
protected BlockSapling(int i, int j)
{
super(i, j);
float f = 0.4F;
setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f * 2.0F, 0.5F + f);
}
public void updateTick(World world, int i, int j, int k, Random random)
{
if(world.multiplayerWorld)
{
return;
}
super.updateTick(world, i, j, k, random);
if(world.getBlockLightValue(i, j + 1, k) >= 9 && random.nextInt(30) == 0)
{
int l = world.getBlockMetadata(i, j, k);
if((l & 8) == 0)
{
world.setBlockMetadataWithNotify(i, j, k, l | 8);
} else
{
growTree(world, i, j, k, random);
}
}
}
public int getBlockTextureFromSideAndMetadata(int i, int j)
{
j &= 3;
if(j == 1)
{
return 63;
}
if(j == 2)
{
return 79;
} else
{
return super.getBlockTextureFromSideAndMetadata(i, j);
}
}
public void growTree(World world, int i, int j, int k, Random random)
{
int l = world.getBlockMetadata(i, j, k) & 3;
world.setBlock(i, j, k, 0);
Object obj = null;
if(l == 1)
{
obj = new WorldGenTaiga2();
} else
if(l == 2)
{
obj = new WorldGenForest();
} else
{
obj = new WorldGenTrees();
if(random.nextInt(10) == 0)
{
obj = new WorldGenBigTree();
}
}
if(!((WorldGenerator) (obj)).generate(world, random, i, j, k))
{
world.setBlockAndMetadata(i, j, k, blockID, l);
}
}
protected int damageDropped(int i)
{
return i & 3;
}
}
breakyorself- Member
- Posts : 60
Join date : 2011-10-19
Re: [1.8.1] Tree
How do I make the tree taller / thicker?
XenophonWombat- Member
- Posts : 2
Join date : 2011-11-05
Re: [1.8.1] Tree
I think you should change this:
by
- Code:
public void GenerateSurface(World world, Random random, int i, int j)
by
- Code:
public void GenerateNether(World world, Random random, int i, int j)
KiraBee- Member
- Posts : 12
Join date : 2011-11-03
Age : 26
Location : Peru
Re: [1.8.1] Tree
im not sure if boimes work the same way in the nether ..
anyway i might try it out
anyway i might try it out
sammko- Member
- Posts : 5
Join date : 2011-11-01
Re: [1.8.1] Tree
Please somebody, how do you change the dimensions of the tree?
XenophonWombat- Member
- Posts : 2
Join date : 2011-11-05
Re: [1.8.1] Tree
hmm.. i cant get the idDropped workin'. it always drops the actual leaves block
my code:
my code:
- Spoiler:
- Code:
package net.minecraft.src;
import java.util.Random;
public class BlockAppleLeaves extends BlockLeavesBase {
protected BlockAppleLeaves(int i, int j)
{
super(i, j, Material.leaves, false);
baseIndexInPNG = j;
setTickOnLoad(true);
}
public int idDropped(int i, Random random)
{
if(random.nextInt(3) == 0)
{
return Item.appleRed.shiftedIndex;
} else
{
return -1;
}
}
public int quantityDropped(Random random)
{
return 2 + random.nextInt(3);
}
public boolean shouldSideBeRendered(IBlockAccess iblockaccess, int i, int j, int k, int l)
{
return true;
}
public void updateTick(World world, int i, int j, int k, Random random)
{
if(world.multiplayerWorld)
{
return;
}
int l = world.getBlockMetadata(i, j, k);
if((l & 8) != 0)
{
byte byte0 = 4;
int i1 = byte0 + 1;
byte byte1 = 32;
int j1 = byte1 * byte1;
int k1 = byte1 / 2;
if(adjacentTreeBlocks == null)
{
adjacentTreeBlocks = new int[byte1 * byte1 * byte1];
}
if(world.checkChunksExist(i - i1, j - i1, k - i1, i + i1, j + i1, k + i1))
{
for(int l1 = -byte0; l1 <= byte0; l1++)
{
for(int k2 = -byte0; k2 <= byte0; k2++)
{
for(int i3 = -byte0; i3 <= byte0; i3++)
{
int k3 = world.getBlockId(i + l1, j + k2, k + i3);
if(k3 == Block.wood.blockID)
{
adjacentTreeBlocks[(l1 + k1) * j1 + (k2 + k1) * byte1 + (i3 + k1)] = 0;
continue;
}
if(k3 == mod_AppleSauce.AppleLeaves.blockID)
{
adjacentTreeBlocks[(l1 + k1) * j1 + (k2 + k1) * byte1 + (i3 + k1)] = -2;
} else
{
adjacentTreeBlocks[(l1 + k1) * j1 + (k2 + k1) * byte1 + (i3 + k1)] = -1;
}
}
}
}
for(int i2 = 1; i2 <= 4; i2++)
{
for(int l2 = -byte0; l2 <= byte0; l2++)
{
for(int j3 = -byte0; j3 <= byte0; j3++)
{
for(int l3 = -byte0; l3 <= byte0; l3++)
{
if(adjacentTreeBlocks[(l2 + k1) * j1 + (j3 + k1) * byte1 + (l3 + k1)] != i2 - 1)
{
continue;
}
if(adjacentTreeBlocks[((l2 + k1) - 1) * j1 + (j3 + k1) * byte1 + (l3 + k1)] == -2)
{
adjacentTreeBlocks[((l2 + k1) - 1) * j1 + (j3 + k1) * byte1 + (l3 + k1)] = i2;
}
if(adjacentTreeBlocks[(l2 + k1 + 1) * j1 + (j3 + k1) * byte1 + (l3 + k1)] == -2)
{
adjacentTreeBlocks[(l2 + k1 + 1) * j1 + (j3 + k1) * byte1 + (l3 + k1)] = i2;
}
if(adjacentTreeBlocks[(l2 + k1) * j1 + ((j3 + k1) - 1) * byte1 + (l3 + k1)] == -2)
{
adjacentTreeBlocks[(l2 + k1) * j1 + ((j3 + k1) - 1) * byte1 + (l3 + k1)] = i2;
}
if(adjacentTreeBlocks[(l2 + k1) * j1 + (j3 + k1 + 1) * byte1 + (l3 + k1)] == -2)
{
adjacentTreeBlocks[(l2 + k1) * j1 + (j3 + k1 + 1) * byte1 + (l3 + k1)] = i2;
}
if(adjacentTreeBlocks[(l2 + k1) * j1 + (j3 + k1) * byte1 + ((l3 + k1) - 1)] == -2)
{
adjacentTreeBlocks[(l2 + k1) * j1 + (j3 + k1) * byte1 + ((l3 + k1) - 1)] = i2;
}
if(adjacentTreeBlocks[(l2 + k1) * j1 + (j3 + k1) * byte1 + (l3 + k1 + 1)] == -2)
{
adjacentTreeBlocks[(l2 + k1) * j1 + (j3 + k1) * byte1 + (l3 + k1 + 1)] = i2;
}
}
}
}
}
}
int j2 = adjacentTreeBlocks[k1 * j1 + k1 * byte1 + k1];
if(j2 >= 0)
{
world.setBlockMetadata(i, j, k, l & -9);
} else
{
removeLeaves(world, i, j, k);
}
}
}
private void removeLeaves(World world, int i, int j, int k)
{
dropBlockAsItem(world, i, j, k, world.getBlockMetadata(i, j, k), (Integer) null);
world.setBlockWithNotify(i, j, k, 0);
}
public void setGraphicsLevel(boolean flag)
{
graphicsLevel = flag;
blockIndexInTexture = baseIndexInPNG + (flag ? 0 : 1);
}
public void onEntityWalking(World world, int i, int j, int k, Entity entity)
{
super.onEntityWalking(world, i, j, k, entity);
}
int adjacentTreeBlocks[];
private int baseIndexInPNG;
}
sammko- Member
- Posts : 5
Join date : 2011-11-01
MC Modding :: Modding :: Singleplayer Modding :: Tutorials
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum