Cuberite Forum
Very Basic Lava - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Plugins (https://forum.cuberite.org/forum-1.html)
+--- Forum: Plugin Releases (https://forum.cuberite.org/forum-2.html)
+---- Forum: Archived Plugins (https://forum.cuberite.org/forum-18.html)
+---- Thread: Very Basic Lava (/thread-27.html)



Very Basic Lava - codename_B - 02-27-2011

This is basically the water plugin slowed down, and with lava.

Once I've figured out how to detect what's burnable and set it on fire, and also damage the player, I'll make sure to do that. For now, it's just epic flowing lava that will be very dangerous when damage is added Wink

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

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

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

function LavaPlugin:Initialize()
   
self:SetName"Lava" )
   
self:SetVersion)

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

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

function IsFreeForLava(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 IsBurnable(block)
    return 
block == E_BLOCK_LOG
      
or block == E_BLOCK_LEAVES;
end

function LavaPlugin: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
   Log
("lava: " .. .. "," .. .. "," .. .. " -- adding due to Place... " .. t);

   
local World cRoot:Get():GetWorld();
   if(
== 327then -- lava bucket
      World
:SetBlock(XYZE_BLOCK_LAVA0);
   elseif(
== 10then
      World
:SetBlock(XYZE_BLOCK_LAVA0);
   
end
   self
:AddSurroundings(XYZ);
   
self:AddBlock(XYZ);
   return 
false
end

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

function LavaPlugin:AddBlock(XYZ)
   
local World cRoot:Get():GetWorld();
   
local t World:GetBlock(XYZ);
   if(
== E_BLOCK_LAVA or == E_BLOCK_STATIONARY_LAVAthen
      local found 
false;
      for 
key,val in pairs(self.LavaBlocks) do
         if(
val[1] == and val[2] == and val[3] == Zthen
            found 
true;
            
Log("addblock found");
            break;
         
end
      end
      end
    
      
if(not foundthen
         Log
("addblock adding");
         
table.insert(self.LavaBlocks, {XYZ});
      
end
   end

function LavaPlugin:OnBlockDigPacketDataPlayer )
   
local X PacketData.m_PosX
   local Y 
PacketData.m_PosY
   local Z 
PacketData.m_PosZ
   
if(PacketData.m_Status == 3then -- block broken
      Log
("lava: " .. .. "," .. .. "," .. .. " -- adding due to dig... status is: " .. PacketData.m_Status);
      
self:AddSurroundings(XYZ);
   
end
   
return false
end

function LavaPlugin:TickDeltaTime )
   if( 
self.NumTicks 50 then   -- Only spread every 50 ticksto make sure it doesnt happen too fast
      self
.NumTicks self.NumTicks 1
      
return
   
end
   local debug 
true;
   
self.NumTicks 0

   local World 
cRoot:Get():GetWorld()

   
local OldBlocks self.LavaBlocks;
   
self.LavaBlocks = {};
   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);
      if(
== E_BLOCK_LAVAthen
         local isFed 
false;
         
local f World:GetBlockMeta(XYZ);
         
local f2 f;
         if(
== 8then
            local t2 
World:GetBlock(XY+1Z);
            if(
t2 == E_BLOCK_LAVAthen
               isFed 
true;
               
local t3 World:GetBlock(XY-1Z);
               
local f3 World:GetBlockMeta(XY-1Z);
               if(
t3 == E_BLOCK_LAVA and f3 == 8then
                  
-- I'm falling, don't spread sideways
               
else
                  
0;
               
end
            end
         
elseif(== 0then
            isFed 
true;
         else
            
f2 GetMaximumLavaAround(XYZ);
            if(
f2 fthen
               isFed 
true;
            
end
         end
         
if(isFedthen
            Log
(" isFed");
            
local down World:GetBlock(XY-1Z);
            if(
IsFreeForLava(down)) then
               Log
("  down");
               
World:SetBlock(XY-1ZE_BLOCK_LAVA8);
               
self:AddBlock(XY-1Z);
            else
               
Log("  around");
               if(
== 8then
                  
-- I'm falling
               elseif(f2+1 < f) then
                  World:SetBlock(X, Y, Z, E_BLOCK_LAVA, f2+1);
                  self:AddBlock(X, Y, Z);
               elseif(f < 7) then
                  Log("   enough power");
                  local points = GetLowestPoints(X, Y, Z);
                  for k,v in pairs(points) do
                     local t2 = World:GetBlock(v[1], v[2], v[3]);
                     if(t2 ~= E_BLOCK_LAVA) then
                        if(v[2] == Y) then
                           World:SetBlock(v[1], v[2], v[3], E_BLOCK_LAVA, f+1);
                        else
                           World:SetBlock(v[1], v[2], v[3], E_BLOCK_LAVA, 8);
                        end
                        self:AddBlock(v[1], v[2], v[3]);
                     else -- is lava
                        local f3 = World:GetBlockMeta(v[1], v[2], v[3]);
                        if(f3 ~= 8 and f3 > f+1) then
                           self:AddBlock(v[1], v[2], v[3]);
                        end
                     end
                  end
               end
            end
         else
            Log(" not isFed");
            World:SetBlock(X, Y, Z, E_BLOCK_AIR, 0);
            self:AddSurroundings(X, Y, Z);
         end
      else
                  if(IsBurnable(down)) then
               Log("Burnable");
             else
         Log("changed before tick, not processing none-lava");
         end
      end
   end
end

function GetMaximumLavaAround(X, Y, Z)
   local mx = 8;
   local level_points = {
      {X-1, Y, Z},
      {X+1, Y, Z},
      {X, Y, Z-1},
      {X, Y, Z+1},
      };
   local World = cRoot:Get():GetWorld();
   for key,val in pairs(level_points) do
      local t = World:GetBlock(val[1], val[2], val[3]);
      if(t == E_BLOCK_STATIONARY_LAVA) then
         mx = 0;
         break;
      elseif(t == E_BLOCK_LAVA) then
         local f = World:GetBlockMeta(val[1], val[2], val[3]);
         if(f < mx) then
            mx = f;
         elseif(f == 8) then
            mx = 0;
         end
         if(mx == 0) then
            break;
         end
      end
   end
   return mx;
end

function GetLowestPoints(X, Y, Z)
   local World = cRoot:Get():GetWorld()
   local t = World:GetBlock(X, Y-1, Z);
   local points = {};
   if(IsFreeForLava(t)) then
      table.insert(points, {X, Y-1, Z});
      return points;
   end
   local lower_points = {
      {X-1, Y-1, Z},
      {X+1, Y-1, Z},
      {X, Y-1, Z-1},
      {X, Y-1, Z+1},
      };
   local lavaFound = false;
   for key,val in pairs(lower_points) do
      local t = World:GetBlock(val[1], val[2], val[3]);
      local t2 = World:GetBlock(val[1], Y, val[3]);
      if(IsFreeForLava(t) and IsFreeForLava(t2)) then
         table.insert(points, val);
         val[2] = Y;
         table.insert(points, val);
      elseif(t2 == E_BLOCK_LAVA and (IsFreeForLava(t) or t == E_BLOCK_LAVA)) then
         lavaFound = true;
      end
   end
   if(#points == 0 and not lavaFound) then
      local level_points = {
         {X-1, Y, Z},
         {X+1, Y, Z},
         {X, Y, Z-1},
         {X, Y, Z+1},
         };
      for key,val in pairs(level_points) do
         local t = World:GetBlock(val[1], val[2], val[3]);
         if(IsFreeForLava(t) or t == E_BLOCK_LAVA) then
            table.insert(points, val);
         end
      end
   end
   return points;
end

Plugin = LavaPlugin:new()
cRoot:Get():GetPluginManager():AddPlugin( Plugin ) 

If anyone has any snippets to detect wood and things and make it work with this plugin, please let me know.


RE: Very Basic Lava - FakeTruth - 02-27-2011

It doesn't flow Sad
It's the fire plugin, but with lava that acts like fire


RE: Very Basic Lava - codename_B - 02-27-2011

Haha, I copy pasted the wrong one!!! :L
There we go, it should be fixed and flow now Smile the flow path is identical to water, but that's satisfactory as I actually prefer the way water flows in this server.


RE: Very Basic Lava - FakeTruth - 02-28-2011

Cool Smile Now make it form obsidian and cobblestone! hehe


RE: Very Basic Lava - codename_B - 02-28-2011

SureTongue Let me in on the world generator Wink


RE: Very Basic Lava - Tybor - 02-28-2011

Nice one, too!

greets,
Tybor


RE: Very Basic Lava - Revolucas - 03-01-2011

Doesn't flow for me is there anything special I have to do like enable physics like I did for water?

Edit: Nevermind doesn't look like the plugin is loading according to /pluginlist XD Forgot to add it to the ini...