[minetest-mod-torches] 03/06: Imported Upstream version 5

Julien Puydt julien.puydt at laposte.net
Sun Jun 12 05:22:08 UTC 2016


This is an automated email from the git hooks/post-receive script.

jpuydt-guest pushed a commit to branch master
in repository minetest-mod-torches.

commit d1b72039a649285253a46fd2c2aa11346887fb5d
Author: Julien Puydt <julien.puydt at laposte.net>
Date:   Sun Jun 12 06:58:41 2016 +0200

    Imported Upstream version 5
---
 README.txt             |  15 ++++--
 init.lua               | 142 ++++++++++++++++++++++++++++++++++++++++++++++++-
 models/torch_floor.obj |   5 +-
 models/torch_wall.obj  |  22 ++++----
 4 files changed, 169 insertions(+), 15 deletions(-)

diff --git a/README.txt b/README.txt
index 583a920..a463b56 100644
--- a/README.txt
+++ b/README.txt
@@ -1,6 +1,5 @@
 Minetest mod "Torches"
 ======================
-Version: 4
 
 (c) Copyright BlockMen (2013-2015)
 (C) Copyright sofar <sofar at foo-projects.org> (2016)
@@ -18,6 +17,15 @@ draw styles.  The alternatives have been removed and instead of
 providing alternate nodes, this mod now directly modifies the existing
 nodes. Conversion from the wallmounted style is done through an LBM.
 
+The wield light part is inspired, but not copied from "walking light",
+a mod by "echo". After looking at the code I decided to implement
+it from scratch as I found it to be too resource intensive and not
+implemented efficiently enough. Still, echo deserves the credit for
+the excellent idea.
+
+Torches is meant for minetest-0.4.14, and does not directly support
+older minetest releases. You'll need a recent git, or nightly build.
+
 
 License:
 ~~~~~~~~
@@ -25,11 +33,12 @@ License:
 
 Textures and Meshes/Models:
 CC-BY 3.0 BlockMen
+Note that the models were entirely done from scratch by sofar.
 
 Code:
 Licensed under the GNU LGPL version 2.1 or higher.
-You can redistribute it and/or modify it under 
-the terms of the GNU Lesser General Public License 
+You can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License
 as published by the Free Software Foundation;
 
 You should have received a copy of the GNU Lesser General Public
diff --git a/init.lua b/init.lua
index 1efdc38..2e52648 100644
--- a/init.lua
+++ b/init.lua
@@ -1,4 +1,8 @@
 
+--
+-- 3d torch part
+--
+
 minetest.register_node(":default:torch", {
 	description = "Torch",
 	drawtype = "mesh",
@@ -22,6 +26,7 @@ minetest.register_node(":default:torch", {
 		wall_top = {-1/16, -2/16, -1/16, 1/16, 0.5, 1/16},
 		wall_bottom = {-1/16, -0.5, -1/16, 1/16, 2/16, 1/16},
 	},
+	sounds = default.node_sound_wood_defaults(),
 	on_place = function(itemstack, placer, pointed_thing)
 		local above = pointed_thing.above
 		local under = pointed_thing.under
@@ -63,15 +68,150 @@ minetest.register_node(":default:torch_wall", {
 		wall_bottom = {-0.1, -0.5, -0.1, 0.1, 0.1, 0.1},
 		wall_side = {-0.5, -0.3, -0.1, -0.2, 0.3, 0.1},
 	},
+	sounds = default.node_sound_wood_defaults(),
 })
 
 minetest.register_lbm({
 	name = "torches:convert_wallmounted",
-	nodenames = "default:torch",
+	nodenames = {"default:torch", "torches:floor", "torches:wall"},
 	action = function(pos, node)
 		if node.param2 >= 2 then
 			minetest.set_node(pos, {name = "default:torch_wall",
 				param2 = node.param2})
+		else
+			minetest.set_node(pos, {name = "default:torch",
+				param2 = node.param2})
 		end
 	end
 })
+
+--
+-- torch wield light
+--
+
+if not minetest.is_yes(minetest.setting_get("torches_wieldlight_enable") or true) then
+	return
+end
+local torchlight_update_interval = minetest.setting_get("torches_wieldlight_interval") or 0.25
+
+minetest.register_node("torches:torchlight", {
+	drawtype = "airlike",
+	groups = {not_in_creative_inventory = 1},
+	walkable = false,
+	paramtype = "light",
+	sunlight_propagates = true,
+	light_source = 11,
+	pointable = false,
+	buildable_to = true,
+	drops = {},
+})
+
+-- state tables
+local torchlight = {}
+local playerlist = {}
+
+local function wields_torch(player)
+	if not player then
+		return false
+	end
+	local item = player:get_wielded_item()
+	if not item then
+		return false
+	end
+	return item:get_name() == "default:torch"
+end
+
+local function wielded_torch(name)
+	if not torchlight[name] then
+		return false
+	end
+	return true
+end
+
+local function is_torchlight(pos)
+	local node = minetest.get_node(pos)
+	return node.name == "torches:torchlight"
+end
+
+local function remove_torchlight(pos)
+	if is_torchlight(pos) then
+		minetest.swap_node(pos, {name = "air"})
+	end
+end
+
+local function place_torchlight(pos)
+	local name = minetest.get_node(pos).name
+	if name == "torches:torchlight" then
+		return true
+	end
+	if (minetest.get_node_light(pos) or 0) > 11 then
+		-- no reason to place torch here, so save a bunch
+		-- of node updates this way
+		return false
+	end
+	if name == "air" then
+		minetest.swap_node(pos, {name = "torches:torchlight"})
+		return true
+	end
+	return false
+end
+
+local function get_torchpos(player)
+	return vector.add({x = 0, y = 1, z = 0}, vector.round(player:getpos()))
+end
+
+minetest.register_on_joinplayer(function(player)
+	local name = player:get_player_name()
+	playerlist[name] = true
+end)
+
+minetest.register_on_leaveplayer(function(player)
+	local name = player:get_player_name()
+	-- don't look at wielded() here, it's likely invalid
+	if torchlight[name] then
+		remove_torchlight(torchlight[name])
+		torchlight[name] = nil
+	end
+	playerlist[name] = nil
+end)
+
+minetest.register_on_shutdown(function()
+	for i, _ in pairs(torchlight) do
+		remove_torchlight(torchlight[i])
+	end
+end)
+
+local function update_torchlight(dtime)
+	for name, _ in pairs(playerlist) do
+		local player = minetest.get_player_by_name(name)
+		local wielded = wielded_torch(name)
+		local wields = wields_torch(player)
+
+		if not wielded and wields then
+			local torchpos = get_torchpos(player)
+			if place_torchlight(torchpos) then
+				torchlight[name] = vector.new(torchpos)
+			end
+		elseif wielded and not wields then
+			remove_torchlight(torchlight[name])
+			torchlight[name] = nil
+		elseif wielded and wields then
+			local torchpos = get_torchpos(player)
+			if not vector.equals(torchpos, torchlight[name]) or
+					not is_torchlight(torchpos) then
+				if place_torchlight(torchpos) then
+					remove_torchlight(torchlight[name])
+					torchlight[name] = vector.new(torchpos)
+				elseif vector.distance(torchlight[name], torchpos) > 2 then
+					-- player went into some node
+					remove_torchlight(torchlight[name])
+					torchlight[name] = nil
+				end
+			end
+		end
+	end
+	minetest.after(torchlight_update_interval, update_torchlight)
+end
+
+minetest.after(torchlight_update_interval, update_torchlight)
+
diff --git a/models/torch_floor.obj b/models/torch_floor.obj
index 5145db2..e2487ef 100644
--- a/models/torch_floor.obj
+++ b/models/torch_floor.obj
@@ -1,4 +1,4 @@
-# Blender v2.76 (sub 11) OBJ File: ''
+# Blender v2.76 (sub 11) OBJ File: 'torch_floor.blend'
 # www.blender.org
 mtllib torch_floor.mtl
 o Cube_Cube.001
@@ -35,6 +35,7 @@ vn 0.000000 0.000000 -1.000000
 vn 1.000000 0.000000 0.000000
 vn -0.707100 0.000000 -0.707100
 vn -0.707100 -0.000000 0.707100
+g Cube_Cube.001_Cube_Cube.001_Material.001
 usemtl Material.001
 s off
 f 3/1/1 1/2/1 5/3/1 7/4/1
@@ -43,5 +44,7 @@ f 3/2/2 4/6/2 8/5/2 7/3/2
 f 1/3/3 3/2/3 4/6/3 2/5/3
 f 5/2/2 1/3/2 2/5/2 6/6/2
 f 7/3/3 8/5/3 6/6/3 5/2/3
+g Cube_Cube.001_Cube_Cube.001_Material.002
+usemtl Material.002
 f 9/9/4 10/10/4 12/11/4 11/12/4
 f 13/12/5 14/9/5 16/10/5 15/11/5
diff --git a/models/torch_wall.obj b/models/torch_wall.obj
index 62780b8..57baa9e 100644
--- a/models/torch_wall.obj
+++ b/models/torch_wall.obj
@@ -34,19 +34,20 @@ vt 0.437500 0.000000
 vt 0.562500 0.000000
 vt 0.562500 0.125000
 vt 0.437500 0.125000
+vt 0.000000 0.562500
+vt 0.000000 -0.000000
+vt 1.000000 0.000000
 vt 1.000000 0.562500
 vt 1.000000 1.000000
 vt 0.000000 1.000000
-vt 0.000000 0.562500
-vt 0.000000 0.000000
-vt 1.000000 -0.000000
 vn -0.000000 0.500000 0.866000
 vn -0.000000 0.866000 -0.500000
 vn 1.000000 0.000000 0.000000
+vn -0.707100 0.612400 -0.353600
+vn -0.707100 -0.612400 0.353600
 vn -0.707100 0.707100 -0.000000
 vn -0.707100 -0.707100 -0.000000
-vn -0.707100 -0.612400 0.353600
-vn -0.707100 0.612400 -0.353600
+g Cube_Cube.001_Cube_Cube.001_Material.001
 usemtl Material.001
 s off
 f 3/1/1 1/2/1 5/3/1 7/4/1
@@ -55,8 +56,9 @@ f 3/2/2 4/6/2 8/5/2 7/3/2
 f 1/3/3 3/2/3 4/6/3 2/5/3
 f 5/2/2 1/3/2 2/5/2 6/6/2
 f 7/3/3 8/5/3 6/6/3 5/2/3
-f 9/9/4 10/10/4 12/11/4 11/12/4
-f 13/12/5 14/9/5 16/10/5 15/11/5
-f 21/12/6 22/13/6 24/14/6 23/9/6
-usemtl Material.001_default_torch.png
-f 17/12/7 18/13/7 20/14/7 19/9/7
+f 17/9/4 18/10/4 20/11/4 19/12/4
+f 21/9/5 22/10/5 24/11/5 23/12/5
+g Cube_Cube.001_Cube_Cube.001_Material.002
+usemtl Material.002
+f 9/12/6 10/13/6 12/14/6 11/9/6
+f 13/9/7 14/12/7 16/13/7 15/14/7

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/minetest-mod-torches.git



More information about the Pkg-games-commits mailing list