Skip to content

Commit

Permalink
Weather support
Browse files Browse the repository at this point in the history
  • Loading branch information
proller committed Jul 27, 2013
1 parent e65d8ad commit 3aedfac
Show file tree
Hide file tree
Showing 23 changed files with 552 additions and 91 deletions.
34 changes: 18 additions & 16 deletions builtin/falling.lua
Expand Up @@ -14,11 +14,11 @@ minetest.register_entity("__builtin:falling_node", {
visual_size = {x=0.667, y=0.667},
},

nodename = "",
node = {},

set_node = function(self, nodename)
self.nodename = nodename
local stack = ItemStack(nodename)
set_node = function(self, node)
self.node = node
local stack = ItemStack(node.name)
local itemtable = stack:to_table()
local itemname = nil
if itemtable then
Expand All @@ -32,20 +32,19 @@ minetest.register_entity("__builtin:falling_node", {
end
prop = {
is_visible = true,
textures = {nodename},
textures = {node.name},
}
self.object:set_properties(prop)
end,

get_staticdata = function(self)
return self.nodename
return self.node.name
end,

on_activate = function(self, staticdata)
self.nodename = staticdata
self.object:set_armor_groups({immortal=1})
--self.object:setacceleration({x=0, y=-10, z=0})
self:set_node(self.nodename)
self:set_node({name=staticdata})
end,

on_step = function(self, dtime)
Expand All @@ -57,8 +56,10 @@ minetest.register_entity("__builtin:falling_node", {
local bcn = minetest.get_node(bcp)
-- Note: walkable is in the node definition, not in item groups
if minetest.registered_nodes[bcn.name] and
minetest.registered_nodes[bcn.name].walkable then
if minetest.registered_nodes[bcn.name].buildable_to then
minetest.registered_nodes[bcn.name].walkable or
(minetest.get_node_group(self.node.name, "float") ~= 0 and minetest.registered_nodes[bcn.name].liquidtype ~= "none")
then
if minetest.registered_nodes[bcn.name].buildable_to and (minetest.get_node_group(self.node.name, "float") == 0 or minetest.registered_nodes[bcn.name].liquidtype == "none") then
minetest.remove_node(bcp)
return
end
Expand All @@ -83,7 +84,7 @@ minetest.register_entity("__builtin:falling_node", {
end
end
-- Create node and remove entity
minetest.add_node(np, {name=self.nodename})
minetest.add_node(np, self.node)
self.object:remove()
nodeupdate(np)
else
Expand All @@ -92,9 +93,9 @@ minetest.register_entity("__builtin:falling_node", {
end
})

function spawn_falling_node(p, nodename)
function spawn_falling_node(p, node)
obj = minetest.add_entity(p, "__builtin:falling_node")
obj:get_luaentity():set_node(nodename)
obj:get_luaentity():set_node(node)
end

function drop_attached_node(p)
Expand Down Expand Up @@ -150,13 +151,14 @@ function nodeupdate_single(p, delay)
n_bottom = minetest.get_node(p_bottom)
-- Note: walkable is in the node definition, not in item groups
if minetest.registered_nodes[n_bottom.name] and
(minetest.get_node_group(n.name, "float") == 0 or minetest.registered_nodes[n_bottom.name].liquidtype == "none") and
(not minetest.registered_nodes[n_bottom.name].walkable or
minetest.registered_nodes[n_bottom.name].buildable_to) then
if delay then
minetest.after(0.1, nodeupdate_single, {x=p.x, y=p.y, z=p.z}, false)
else
minetest.remove_node(p)
spawn_falling_node(p, n.name)
spawn_falling_node(p, n)
nodeupdate(p)
end
end
Expand All @@ -170,7 +172,7 @@ function nodeupdate_single(p, delay)
end
end

function nodeupdate(p)
function nodeupdate(p, delay)
-- Round p to prevent falling entities to get stuck
p.x = math.floor(p.x+0.5)
p.y = math.floor(p.y+0.5)
Expand All @@ -179,7 +181,7 @@ function nodeupdate(p)
for x = -1,1 do
for y = -1,1 do
for z = -1,1 do
nodeupdate_single({x=p.x+x, y=p.y+y, z=p.z+z}, not (x==0 and y==0 and z==0))
nodeupdate_single({x=p.x+x, y=p.y+y, z=p.z+z}, delay or not (x==0 and y==0 and z==0))
end
end
end
Expand Down
20 changes: 19 additions & 1 deletion doc/lua_api.txt
Expand Up @@ -322,6 +322,8 @@ param2 is reserved for the engine when any of these are used:
facedir modulo 4 = axisdir
0 = y+ 1 = z+ 2 = z- 3 = x+ 4 = x- 5 = y-
facedir's two less significant bits are rotation around the axis
paramtype2 == "leveled"
^ The drawn node level is read from param2, like flowingliquid

Nodes can also contain extra data. See "Node Metadata".

Expand Down Expand Up @@ -353,7 +355,7 @@ Node selection boxes are defined using "node boxes"

The "nodebox" node drawtype allows defining visual of nodes consisting of
arbitrary number of boxes. It allows defining stuff like stairs. Only the
"fixed" box type is supported for these.
"fixed" and "leveled" box type is supported for these.
^ Please note that this is still experimental, and may be incompatibly
changed in the future.

Expand Down Expand Up @@ -381,6 +383,8 @@ A box is defined as:
A box of a regular node would look like:
{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},

type = "leveled" is same as "fixed", but y2 will be automaticaly setted to level from param2

Ore types
---------------
These tell in what manner the ore is generated.
Expand Down Expand Up @@ -1258,6 +1262,18 @@ minetest.find_path(pos1,pos2,searchdistance,max_jump,max_drop,algorithm)
^ algorithm: A*_noprefetch(default), A*, Dijkstra
minetest.spawn_tree (pos, {treedef})
^ spawns L-System tree at given pos with definition in treedef table
minetest.transforming_liquid_add(pos)
^ add node to liquid update queue
minetest.get_node_max_level(pos)
^ get max available level for leveled node
minetest.get_node_level(pos)
^ get level of leveled node (water, snow)
minetest.add_node_level(pos, level)
^ increase level of leveled node by level, default level = 1, if totallevel > maxlevel returns rest (total-max). can be negative for decreasing
minetest.get_heat(pos)
^ heat at pos
minetest.get_humidity(pos)
^ humidity at pos

Inventory:
minetest.get_inventory(location) -> InvRef
Expand Down Expand Up @@ -1965,6 +1981,8 @@ Node definition (register_node)
liquid_alternative_source = "", -- Source version of flowing liquid
liquid_viscosity = 0, -- Higher viscosity = slower flow (max. 7)
liquid_renewable = true, -- Can new liquid source be created by placing
freezemelt = "", -- water for snow/ice, ice/snow for water
leveled = 0, -- Block contain level in param2. value - default level, used for snow. Dont forget use "leveled" type nodebox
liquid_range = 8, -- number of flowing nodes arround source (max. 8)
drowning = true, -- Player will drown in these
two or more sources nearly?
Expand Down
6 changes: 5 additions & 1 deletion minetest.conf.example
Expand Up @@ -107,6 +107,8 @@
#liquid_fast_flood = 1
# Underground water and lava springs, its infnity sources if liquid_finite enabled
#underground_springs = 1
# Enable weather (cold-hot, water freeze-melt). use only with liquid_finite=1
#weather = false
# Enable nice leaves; disable for speed
#new_style_leaves = true
# Enable smooth lighting with simple ambient occlusion;
Expand Down Expand Up @@ -268,7 +270,9 @@
# Interval of sending time of day to clients
#time_send_interval = 5
# Length of day/night cycle. 72=20min, 360=4min, 1=24hour, 0=day/night/whatever stays unchanged
#time_speed = 96
#time_speed = 72
# Length of year in days for seasons change. With default time_speed 365 days = 5 real days for year. 30 days = 10 real hours
#year_days = 30
#server_unload_unused_data_timeout = 29
# Interval of saving important changes in the world
#server_map_save_interval = 5.3
Expand Down

0 comments on commit 3aedfac

Please sign in to comment.