Awesome growing trees!
#1
I've set this up to be 100% forwards compatible, for now, trees drop leaves - so when you plant leaves you grow a tree!

Also, when you plant saplings, they grow into trees too.

I decided that it wasn't sensible to have insta-grow trees, but they still grow pretty quickly and can be anywhere up to 8 blocks tall (wood).

I've used a very very very basic implementation for the leaves, but IMO it still looks good Smile

PHP Code:
local TreePlugin = {}
TreePlugin.__index TreePlugin

function TreePlugin:new()
   
local t = {}
   
setmetatable(tTreePlugin)
   
local w Lua__cPlugin:new()
   
tolua.setpeer(wt)
   
w:tolua__set_instance(w)
   return 
w
end

function TreePlugin:OnDisable()
   
LogPlugin:GetName() .. " v." .. Plugin:GetVersion() .. " is shutting down..." )
end

function TreePlugin:Initialize()
   
self:SetName"Tree" )
   
self:SetVersion)

   
PluginManager cRoot:Get():GetPluginManager()
   
PluginManager:AddHookselfcPluginManager.E_PLUGIN_TICK )
   
PluginManager:AddHookselfcPluginManager.E_PLUGIN_BLOCK_DIG )
   
PluginManager:AddHookselfcPluginManager.E_PLUGIN_BLOCK_PLACE )
   
self.TreeBlocks = {};
   
self.TreeBlocks = {};

   
Log"Initialized " .. self:GetName() .. " v." .. self:GetVersion() )
   
self.NumTicks 0;
   return 
true
end

function IsFreeForTree(block)
   return 
block == E_BLOCK_AIR
      
or block == E_BLOCK_TORCH
      
or block == E_BLOCK_MINECART_TRACKS
      
or block == E_BLOCK_REDSTONE_TORCH_ON
      
or block == E_BLOCK_REDSTONE_TORCH_OFF;
end

function IsTree(block)
   return 
block == E_BLOCK_LOG;
end

function IsSapling(block)
   return 
block == E_BLOCK_SAPLING
   
or block == E_BLOCK_LEAVES;
end

function TreePlugin:OnBlockPlacePacketDataPlayer )

   
local X PacketData.m_PosX
   local Y 
PacketData.m_PosY
   local Z 
PacketData.m_PosZ
   X
YAddDirectionXYZPacketData.m_Direction )
   
local t PacketData.m_ItemType; -- the type of item used to call the place command

   local World 
cRoot:Get():GetWorld();
   if(
== or t==18then -- sapling
   Log
("sapling: " .. .. "," .. .. "," .. .. " -- adding due to Place... " .. t);
   
World:SetBlock(XYZE_BLOCK_LOG0);
   
end
   self
:AddSurroundings(XYZ);
   
self:AddBlock(XYZ);
   return 
false
end

function TreePlugin:AddSurroundings(XYZ)
   
local level_points = {
      {
XY+1Z},
      };
   for 
key,val in pairs(level_points) do
      
self:AddBlock(val[1], val[2], val[3]);
   
end
end

function TreePlugin:AddBlock(XYZ)
   
local World cRoot:Get():GetWorld();
   
local t World:GetBlock(XYZ);
   if(
== E_BLOCK_LOGthen
         Log
("addblock adding");
         
table.insert(self.TreeBlocks, {XYZ});
      
end
   end

function TreePlugin:OnBlockDigPacketDataPlayer )

end

function TreePlugin:TickDeltaTime )
   if( 
self.NumTicks 30 then   -- Visible tree growthbut still awesome.
      
self.NumTicks self.NumTicks 1
      
return
   
end
   local debug 
true;
   
self.NumTicks 0

   local World 
cRoot:Get():GetWorld()

   
local OldBlocks self.TreeBlocks;
   
self.TreeBlocks = {};
   for 
key,val in pairs(OldBlocks) do
      
local X val[1]
      
local Y val[2]
      
local Z val[3]
      
local t World:GetBlock(XYZ);
      
Log("processing: " .. .. "," .. .. "," .. .. " -- " .. t);
         
countValue math.random(4,7)
         
Yvalue Y-countValue
         local down 
World:GetBlock(XYvalueZ);
         
local up World:GetBlock(XY+1Z);
         
local sSelf World:GetBlock(XYZ);
         if((
IsTree(down))) then

-- treetop
World
:SetBlock(XY+2ZE_BLOCK_LEAVES8);
self:AddBlock(XY+2Z);         
World:SetBlock(XY+1ZE_BLOCK_LEAVES8);
self:AddBlock(XY+1Z);

-- 
z index plane 0
World
:SetBlock(XY+1Z-1E_BLOCK_LEAVES8);
self:AddBlock(XY+1Z-1);
World:SetBlock(XY+1Z+1E_BLOCK_LEAVES8);
self:AddBlock(XY+1Z+1);
-- 
x index plane 0
World
:SetBlock(X-1Y+1ZE_BLOCK_LEAVES8);
self:AddBlock(X-1Y+1Z);
World:SetBlock(X+1Y+1ZE_BLOCK_LEAVES8);
self:AddBlock(X+1Y+1Z);
           
-- 
z index plane 1
World
:SetBlock(XYZ-1E_BLOCK_LEAVES8);
self:AddBlock(XYZ-1);
World:SetBlock(XYZ+1E_BLOCK_LEAVES8);
self:AddBlock(XYZ+1);
-- 
x index plane 1
World
:SetBlock(X-1YZE_BLOCK_LEAVES8);
self:AddBlock(X-1YZ);
World:SetBlock(X+1YZE_BLOCK_LEAVES8);
self:AddBlock(X+1YZ);
-- 
xz index plane 1
World
:SetBlock(X-1YZ-1E_BLOCK_LEAVES8);
self:AddBlock(X-1YZ-1);
World:SetBlock(X+1YZ+1E_BLOCK_LEAVES8);
self:AddBlock(X+1YZ+1);
-- 
zx index plane 1
World
:SetBlock(X-1YZ+1E_BLOCK_LEAVES8);
self:AddBlock(X-1YZ+1);
World:SetBlock(X+1YZ-1E_BLOCK_LEAVES8);
self:AddBlock(X+1YZ-1);    


-- 
z index plane 2
World
:SetBlock(XY-1Z-1E_BLOCK_LEAVES8);
self:AddBlock(XY-1Z-1);
World:SetBlock(XY-1Z+1E_BLOCK_LEAVES8);
self:AddBlock(XY-1Z+1);
-- 
x index plane 2
World
:SetBlock(X-1Y-1ZE_BLOCK_LEAVES8);
self:AddBlock(X-1Y-1Z);
World:SetBlock(X+1Y-1ZE_BLOCK_LEAVES8);
self:AddBlock(X+1Y-1Z);
-- 
xz index plane 2
World
:SetBlock(X-1Y-1Z-1E_BLOCK_LEAVES8);
self:AddBlock(X-1Y-1Z-1);
World:SetBlock(X+1Y-1Z+1E_BLOCK_LEAVES8);
self:AddBlock(X+1Y-1Z+1);
-- 
zx index plane 2
World
:SetBlock(X-1Y-1Z+1E_BLOCK_LEAVES8);
self:AddBlock(X-1Y-1Z+1);
World:SetBlock(X+1Y-1Z-1E_BLOCK_LEAVES8);
self:AddBlock(X+1Y-1Z-1);               
               

         
Log(" stopping growth!");

         else
               
Log("  up");
               
World:SetBlock(XY+1ZE_BLOCK_LOG8);
               
self:AddBlock(XY+1Z);
        if(
IsSapling(sSelf)) then
Log
("is Sapling! :D");
               
World:SetBlock(XYZE_BLOCK_LOG8);
               
self:AddBlock(XYZ);
end        
               
end
end
end

Plugin 
TreePlugin:new()
cRoot:Get():GetPluginManager():AddPluginPlugin 

I hope to see another update of this awesome software soon Smile
This was created by planting the trees in a 5x5 rectangle then hollowing out a door and adding stairs Smile

[Image: sndx7b.png]
Reply
Thanks given by: TheJansonD


Messages In This Thread
Awesome growing trees! - by codename_B - 02-28-2011, 02:42 AM
RE: Awesome growing trees! - by Tybor - 02-28-2011, 03:41 AM
RE: Awesome growing trees! - by codename_B - 02-28-2011, 03:48 AM
RE: Awesome growing trees! - by Tybor - 02-28-2011, 03:52 AM
RE: Awesome growing trees! - by NiLSPACE - 07-09-2012, 08:19 PM



Users browsing this thread: 1 Guest(s)