Add rightclick-support and some tweaks

master
BlockMen 2015-02-16 11:14:35 +01:00
parent f1c8b26e3c
commit ce2c162e3d
1 changed files with 26 additions and 16 deletions

View File

@ -1,12 +1,12 @@
-- Reduce particles send to client if on Server -- Reduce particles send to client if on Server
local SERVER = minetest.is_singleplayer() or false local SERVER = minetest.is_singleplayer() or false
SERVER = not SERVER SERVER = not SERVER
local dur = 0 local dur = 2
if SERVER then if SERVER then
dur = 8 -- lowering sends more pakets to clients and let flames faster disappear (not recommended) dur = 9 -- lowering sends more pakets to clients and let flames faster disappear (not recommended)
end end
local VIEW_DISTANCE = 13 -- only if player is near that distance flames are shown local VIEW_DISTANCE = 13 -- from what distance (in nodes) flames are send to player/client
local dirs = { local dirs = {
{-1,0,-1}, {-1,0,0}, {0,0,-1}, {-1,0,-1}, {-1,0,0}, {0,0,-1},
@ -28,9 +28,9 @@ local particle_def = {
--fire_particles --fire_particles
local function add_fire(pos, duration, offset) local function add_fire(pos, duration, offset)
if duration < 1 then --if duration <= 1 then
duration = 1.1 -- duration = 1
end --end
if offset then if offset then
pos.x = pos.x + offset.x pos.x = pos.x + offset.x
pos.z = pos.z + offset.z pos.z = pos.z + offset.z
@ -115,7 +115,7 @@ end
-- abms for flames -- abms for flames
minetest.register_abm({ minetest.register_abm({
nodenames = {"torches:wand"}, nodenames = {"torches:wand"},
interval = 1+dur, interval = dur - 1,
chance = 1, chance = 1,
action = function(pos) action = function(pos)
if player_near(pos) then if player_near(pos) then
@ -124,18 +124,18 @@ minetest.register_abm({
if n and n.param2 then if n and n.param2 then
dir = get_offset(n.param2) dir = get_offset(n.param2)
end end
add_fire(pos, dur, dir) add_fire(pos, dur - .9, dir)
end end
end end
}) })
minetest.register_abm({ minetest.register_abm({
nodenames = {"torches:floor"}, nodenames = {"torches:floor"},
interval = 1 + dur, interval = dur - 1,
chance = 1, chance = 1,
action = function(pos) action = function(pos)
if player_near(pos) then if player_near(pos) then
add_fire(pos, dur) add_fire(pos, dur - .9)
end end
end end
}) })
@ -169,14 +169,28 @@ minetest.register_craftitem(":default:torch", {
wield_scale = {x = 1, y = 1, z = 1 + 1/16}, wield_scale = {x = 1, y = 1, z = 1 + 1/16},
liquids_pointable = false, liquids_pointable = false,
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.type ~= "node" or string.find(minetest.get_node(pointed_thing.above).name, "torch") then if pointed_thing.type ~= "node" then
return itemstack return itemstack
end end
local above = pointed_thing.above local above = pointed_thing.above
local under = pointed_thing.under local under = pointed_thing.under
local wdir = minetest.dir_to_wallmounted({x = under.x - above.x, y = under.y - above.y, z = under.z - above.z}) local wdir = minetest.dir_to_wallmounted({x = under.x - above.x, y = under.y - above.y, z = under.z - above.z})
local u_n = minetest.get_node(under) local u_n = minetest.get_node(under)
local a_n = minetest.get_node(above)
if string.find(u_n.name, "torch") or string.find(a_n.name, "torch") then
return itemstack
end
local udef = minetest.registered_nodes[u_n.name] local udef = minetest.registered_nodes[u_n.name]
-- check for on_rightclick (like doors)
if not placer:get_player_control().sneak then
if u_n and udef and udef.on_rightclick then
return udef.on_rightclick(under, u_n, placer, itemstack, pointed_thing) or itemstack
end
end
if u_n and udef and not udef.walkable then above = under end if u_n and udef and not udef.walkable then above = under end
u_n = minetest.get_node(above) u_n = minetest.get_node(above)
udef = minetest.registered_nodes[u_n.name] udef = minetest.registered_nodes[u_n.name]
@ -192,13 +206,11 @@ minetest.register_craftitem(":default:torch", {
if not wdir == 0 or not minetest.setting_getbool("creative_mode") then if not wdir == 0 or not minetest.setting_getbool("creative_mode") then
itemstack:take_item() itemstack:take_item()
end end
--expect node switch one sever step delayed --expect node switch one sever step (default 0.1) delayed
minetest.after(0.1, add_fire, above, dur, fdir) minetest.after(0.1, add_fire, above, dur, fdir)
return itemstack return itemstack
end end
}) })
minetest.register_node("torches:floor", { minetest.register_node("torches:floor", {
@ -257,8 +269,6 @@ minetest.register_node("torches:wand", {
minetest.dig_node(pos) minetest.dig_node(pos)
end end
end, end,
}) })
minetest.register_on_dignode(function(pos, oldnode, digger) minetest.register_on_dignode(function(pos, oldnode, digger)