The Tree in this example uses a custom texture for the sapling and the leaves, but the standard logs.
For this tree the map generator spawns saplings on grass everywhere in the world(cherryblossomsapling.oregen) and after a random time the tree grows out of it. Destroying the tree has a 5% chance per leaf to drop a new sapling.
/.minecraft/config/CustomStuff/mods/modname/mod.js
config.addBlockIdProperty("cherryBlossomLeafID", 1030); config.addBlockIdProperty("cherryBlossomSaplingID", 1031); config.addBlockIdProperty("cherryBlossomSaplingWildID", 1032); mod.addBlock("cherryblossomleaves.js", "normal"); mod.addBlock("cherryblossomsapling.js", "crossTexture"); mod.addBlock("cherryblossomsaplingwild.js", "crossTexture"); mod.addWorldGen("cherryblossomsapling.js", "flower"); //Generates the sapling that grows instantly in the wild, to make up for not being able to spawn the tree in.
/.minecraft/config/CustomStuff/mods/modname/blocks/cherryblossomleaves.js
name = "cherryBlossomLeaves"; id = config.getBlockId("cherryBlossomLeafID"); displayName[0] = "Cherry Blossom Leaves"; material = "leaves"; stepSound = "grass"; hardness[0] = 0.3; resistance[0] = 0; drop[0] = "3:0 0"; transparent = true; tileTransparent = true; textureFileXP[0] = "cherryleaf.png";; textureFileXN[0] = "cherryleaf.png";; textureFileYP[0] = "cherryleaf.png";; textureFileYN[0] = "cherryleaf.png";; textureFileZP[0] = "cherryleaf.png";; textureFileZN[0] = "cherryleaf.png"; addToCreative[0] = true; creativeTab = "decorations"; onUpdate[0] = "if(Math.floor(Math.random()*200)==0){mod.loadScript('leafdecay.js');}"; onBreak[0] = "if(Math.floor(Math.random()*20)==0){world.spawnItem(position, config.getBlockId('cherryBlossomSaplingID'), 1, 0);}";
/.minecraft/config/CustomStuff/mods/modname/blocks/cherryblossomsapling.js
name = "cherryBlossomSapling"; id = config.getBlockId("cherryBlossomSaplingID"); displayName[0] = "Cherry Blossom Sapling"; material = "plants"; stepSound = "grass"; hasCollision[0] = false; hardness[0] = 0.3; resistance[0] = 0; opacity = 0; light[0] = 1; textureFile = "customstuff.png"; textureIndexYN[0] = 19; addToCreative[0] = true; creativeTab = "decorations"; onUpdate[0] = "if(Math.floor(Math.random()*1000)==0) {var leafid=config.getBlockId('cherryBlossomLeafID');var leafdamage=0;var trunkid=17;trunkdamage=0;mod.loadScript('treegrow.js');}"; onBonemeal[0] = "var leafid=config.getBlockId('cherryBlossomLeafID');var leafdamage=0;var trunkid=17;trunkdamage=0;mod.loadScript('treegrow.js');player.removeFromSlot(player.getCurrentSlot(), 1);";
/.minecraft/config/CustomStuff/mods/modname/scripts/treegrow.js
var cnti; var cntj; var ok; ok=0; for(cnti=0;cnti<7;cnti++) { position.y++; ok=world.getBlockId(position); if(ok) break; } if(!ok) { position.x-=2; position.y-=3; position.z-=2; for(cnti=0;cnti<5;cnti++) { for(cntj=0;cntj<5;cntj++) { world.setBlockIdAndMetadata(position, leafid, leafdamage); position.x++; } position.x-=5; position.z++; } position.y--; position.z-=5; for(cnti=0;cnti<5;cnti++) { for(cntj=0;cntj<5;cntj++) { world.setBlockIdAndMetadata(position, leafid, leafdamage); position.x++; } position.x-=5; position.z++; } position.z-=3; position.x+=2; position.y++; for(cnti=0;cnti<5;cnti++) { world.setBlockIdAndMetadata(position, trunkid, trunkdamage); position.y--; } position.y+=6; position.x--; position.z--; for(cnti=0;cnti<3;cnti++) { for(cntj=0;cntj<3;cntj++) { world.setBlockIdAndMetadata(position, leafid, leafdamage); position.x++; } position.x-=3; position.z++; } position.y++; position.z-=2; world.setBlockIdAndMetadata(position, leafid, leafdamage); position.x++; world.setBlockIdAndMetadata(position, leafid, leafdamage); position.x++; world.setBlockIdAndMetadata(position, leafid, leafdamage); position.x--; position.z--; world.setBlockIdAndMetadata(position, leafid, leafdamage); position.z+=2; world.setBlockIdAndMetadata(position, leafid, leafdamage); }
/.minecraft/config/CustomStuff/mods/modname/scripts/leafdecay.js
var x; var y; var z; var logNear; position.x-=2; position.z-=2; position.y-=2; for(x=0;x<5;x++) { for(z=0;z<5;z++) { for(y=0;y<5;y++) { if(world.getBlockId(position) == 17) { logNear=1; } position.y++; } position.z++; position.y-=5; } position.x++; position.z-=5; } if(logNear != 1) { position.x-=3; position.z+=2; position.y+=2; world.setBlockId(position, 0); }
/.minecraft/config/CustomStuff/mods/modname/worldGeneration/cherryblossomsaplingwild.js
generationsPerChunk = 5.0; minHeight = 40; maxHeight = 70; generateInNether = false; blockId = 1032; blockMeta = 0; numberOfBlocks = 15;
/.minecraft/config/CustomStuff/mods/modname/blocks/cherryblossomsaplingwild.js
name = "cherryBlossomSaplingWild";
id = config.getBlockId("cherryBlossomSaplingWildID");
displayName[0] = "Cherry Blossom Sapling";
material = "plants";
stepSound = "grass";
hasCollision[0] = false;
hardness[0] = 0.3;
resistance[0] = 0;
opacity = 0;
light[0] = 1;
textureFile = "customstuff.png";
textureIndexYN[0] = 19;
//This is a hidden "Work block" that will not be added to the creative menu
onUpdate[0] = "var leafid=config.getBlockId('cherryBlossomLeafID');var leafdamage=0;var trunkid=17;trunkdamage=0;mod.loadScript('treegrow.js');"; //No random testing here so that it grows instantly
Older Examples and Information for Custom Stuff 1.
It use 5 Configfiles:
/.minecraft/config/customBlocks/171-cherryblossomleafs.block
id=171; damagevalues=2; name="Cherry Blossom Leaf"; texturefile="customstuff.png"; textureindex=29; type="normal"; material="cloth"; stepsound="cloth"; hardness=0.3; resistance=0; quantitydropped="0"; update="var sapling=172;if(Math.floor(Math.random()*20)==0){customstuff.loadScript('leafdecay.script');}"; destroyed="if(Math.floor(Math.random()*20)==0){world.spawnItem(origin,172,1,0);}";
/.minecraft/config/customFunctions/leafdecay.script
var x; var y; var z; var logNear; origin.x-=2; origin.z-=2; origin.y-=2; for(x=0;x<5;x++) { for(z=0;z<5;z++) { for(y=0;y<5;y++) { if(world.getBlockId(origin) == 17) { logNear=1; } origin.y++; } origin.z++; origin.y-=5; } origin.x++; origin.z-=5; } If(logNear != 1) { origin.x-=3; origin.z+=2; origin.y+=2; world.harvestBlock(origin); if(Math.floor(Math.random()*20)==0) { world.spawnItem(origin,sapling,1,0); } }
This script uses code from the simple cuboid page as a search function so look there for more information about how this works. This setup, unfortunately, allows leaves to float if they are close enough to a log (1 block of space between) but should hopefully be a simple method for detecting if the leaf should decay. The harvestBlock currently does not activate the destroyed event. To make up for this, the code for the destroyed event has been included after the block is broken. The 172 has been switch with sapling to keep the leaf decay script modular.
/.minecraft/config/customBlocks/172-cherryblossomsapling.block
name="Cherry Blossom Sapling"; id=172; texturefile="customstuff.png"; textureindex=19; type="crosstexture"; material="cloth"; stepsound="cloth"; collision=false; hardness=0.3; resistance=0; opacity=0; light=1; update="if(Math.floor(Math.random()*1000)==0) {var leafid=171,leafdamage=0,trunkid=17,trunkdamage=0; customstuff.loadScript('treegrow.script');}"; rightclicked="if(player.getItemId(player.getCurrentSlot()) == 351 && player.getItemDamage(player.getCurrentSlot()) == 15) { var leafid=171,leafdamage=0,trunkid=17,trunkdamage=0,leafid2=57,leafdamage=0,chance=10; customstuff.loadScript('treegrow.script'); }";
The rightclick event is for the use with bonemeal as fertilizer.
/.minecraft/config/customOreGeneration/cherryblossomsapling.oregen
id=172; type="flower" size=3; rate=4; generationblocks=2; heightmin=1; heightmax=127;
/.minecraft/config/customStuffFunctions/treegrow.script
var cnti; var cntj; origin.x-=2; origin.y+=4; origin.z-=2; var ok; ok=0; for(cnti=0;cnti<7;cnti++) { origin.y++; ok=world.getBlockId(origin); if(ok) break; } if(!ok) { origin.y-=7; for(cnti=0;cnti<5;cnti++) { for(cntj=0;cntj<5;cntj++) { world.setBlockIdAndMetadata( origin, leafid,leafdamage); origin.x++; } origin.x-=5; origin.z++; } origin.y--; origin.z-=5; for(cnti=0;cnti<5;cnti++) { for(cntj=0;cntj<5;cntj++) { world.setBlockIdAndMetadata( origin, leafid,leafdamage); origin.x++; } origin.x-=5; origin.z++; } origin.z-=3; origin.x+=2; for(cnti=0;cnti<4;cnti++) { world.setBlockIdAndMetadata( origin, trunkid,trunkdamage); origin.y--; } origin.y+=6; origin.x--; origin.z--; for(cnti=0;cnti<3;cnti++) { for(cntj=0;cntj<3;cntj++) { world.setBlockIdAndMetadata( origin, leafid,leafdamage); origin.x++; } origin.x-=3; origin.z++; } origin.y++; origin.z-=2; world.setBlockIdAndMetadata( origin, leafid,leafdamage); origin.x++; world.setBlockIdAndMetadata( origin, leafid,leafdamage); origin.x++; world.setBlockIdAndMetadata( origin, leafid,leafdamage); origin.x--; origin.z--; world.setBlockIdAndMetadata( origin, leafid,leafdamage); origin.z+=2; world.setBlockIdAndMetadata( origin, leafid,leafdamage); }