Merge pull request #5 from VanessaE/master

Rewrite slightly to use the new 6d facedir prediction code in builtin
This commit is contained in:
Calinou 2013-11-24 10:32:32 -08:00
commit 92e4dc8e29
7 changed files with 89 additions and 213 deletions

View File

@ -1,3 +1,13 @@
--[[
****
More Blocks
by Calinou
Licensed under the zlib/libpng license for code and CC BY-SA for textures, see LICENSE.txt for info.
****
--]]
moreblocks = {}
-- Load translation library if intllib is installed
local S
@ -7,9 +17,11 @@ if (minetest.get_modpath("intllib")) then
else
S = function ( s ) return s end
end
moreblocks.gettext = S
dofile(minetest.get_modpath("moreblocks").."/_config.txt")
dofile(minetest.get_modpath("moreblocks").."/ownership.lua")
dofile(minetest.get_modpath("moreblocks").."/redefinitions.lua")
dofile(minetest.get_modpath("moreblocks").."/crafting.lua")
dofile(minetest.get_modpath("moreblocks").."/aliases.lua")
@ -22,14 +34,6 @@ dofile(minetest.get_modpath("moreblocks").."/stairsplus/aliases.lua")
dofile(minetest.get_modpath("moreblocks").."/stairsplus.lua")
dofile(minetest.get_modpath("moreblocks").."/circular_saw.lua")
--[[
****
More Blocks
by Calinou
Licensed under the zlib/libpng license for code and CC BY-SA for textures, see LICENSE.txt for info.
****
--]]
-- Blocks
minetest.register_node("moreblocks:wood_tile", {

35
ownership.lua Normal file
View File

@ -0,0 +1,35 @@
local S = moreblocks.gettext
function moreblocks.node_is_owned(pos, placer)
local ownername = false
if type(IsPlayerNodeOwner) == "function" then -- node_ownership mod
if HasOwner(pos, placer) then -- returns true if the node is owned
if not IsPlayerNodeOwner(pos, placer:get_player_name()) then
if type(getLastOwner) == "function" then -- ...is an old version
ownername = getLastOwner(pos)
elseif type(GetNodeOwnerName) == "function" then -- ...is a recent version
ownername = GetNodeOwnerName(pos)
else
ownername = S("someone")
end
end
end
elseif type(isprotect)=="function" then -- glomie's protection mod
if not isprotect(5, pos, placer) then
ownername = S("someone")
end
elseif type(protector)=="table" and type(protector.can_dig)=="function" then -- Zeg9's protection mod
if not protector.can_dig(5, pos, placer) then
ownername = S("someone")
end
end
if ownername ~= false then
minetest.chat_send_player( placer:get_player_name(), S("Sorry, %s owns that spot."):format(ownername) )
return true
else
return false
end
end

View File

@ -14,22 +14,6 @@ local dirs1 = { 21, 20, 23, 22, 21 }
local dirs2 = { 15, 8, 17, 6, 15 }
local dirs3 = { 14, 11, 16, 5, 14 }
stairsplus_players_onwall = {}
minetest.register_chatcommand("st", {
params = "",
description = "Toggle stairsplus between placing wall/vertical stairs/panels and normal.",
func = function(name, param)
stairsplus_players_onwall[name] = not stairsplus_players_onwall[name]
if stairsplus_players_onwall[name] then
minetest.chat_send_player(name, "Stairsplus: Placing wall stairs/vertical panels.")
else
minetest.chat_send_player(name, "Stairsplus: Placing floor/ceiling stairs/panels.")
end
end
})
stairsplus_can_it_stack = function(itemstack, placer, pointed_thing)
return false
--[[
@ -100,54 +84,23 @@ local function get_nodedef_field(nodename, fieldname)
return minetest.registered_nodes[nodename][fieldname]
end
function stairsplus_rotate_and_place(itemstack, placer, pointed_thing, onwall)
--[[
local node = minetest.env:get_node(pointed_thing.under)
if not minetest.registered_nodes[node.name] or not minetest.registered_nodes[node.name].on_rightclick then
local above = pointed_thing.above
local under = pointed_thing.under
local top = {x=under.x, y=under.y+1, z=under.z}
local pitch = placer:get_look_pitch()
local node = minetest.env:get_node(above)
local fdir = minetest.dir_to_facedir(placer:get_look_dir())
local wield_name = itemstack:get_name()
local slab = string.find(wield_name, "slab")
local panel = string.find(wield_name, "panel")
local micro = string.find(wield_name, "micro")
local iswall = (above.x ~= under.x) or (above.z ~= under.z)
local isceiling = (above.x == under.x) and (above.z == under.z) and (pitch > 0)
if get_nodedef_field(minetest.env:get_node(under).name, "buildable_to") then
if slab then fdir = 0 end
minetest.env:add_node(under, {name = wield_name, param2 = fdir }) -- place right side up
elseif not get_nodedef_field(minetest.env:get_node(above).name, "buildable_to") then
return
elseif onwall or (iswall and (slab or panel)) then
if slab then
minetest.env:add_node(above, {name = wield_name, param2 = dirs2[fdir+2] }) -- place with wall slab rotation
else
minetest.env:add_node(above, {name = wield_name, param2 = dirs3[fdir+2] }) -- place with wall panel/micro rotation
end
elseif isceiling then
local nfdir = dirs1[fdir+2]
if slab then nfdir = 22 end
minetest.env:add_node(above, {name = wield_name, param2 = nfdir }) -- place upside down variant
else
if slab then fdir = 0 end
minetest.env:add_node(above, {name = wield_name, param2 = fdir }) -- place right side up
end
if not stairsplus_expect_infinite_stacks then
itemstack:take_item()
function(itemstack, placer, pointed_thing)
local keys=placer:get_player_control()
stairsplus_rotate_and_place(itemstack, placer, pointed_thing, keys["sneak"])
return itemstack
end
else
minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer)
]]--
function stairsplus_rotate_and_place(itemstack, placer, pointed_thing)
if not moreblocks.node_is_owned(pointed_thing.under, placer) then
local keys=placer:get_player_control()
minetest.rotate_and_place(itemstack, placer, pointed_thing,
stairsplus_expect_infinite_stacks, {force_wall = keys.sneak})
end
return itemstack
end
function register_stair_slab_panel_micro(modname, subname, recipeitem, groups, images, description, drop, light)

View File

@ -31,11 +31,7 @@ function register_micro(modname, subname, recipeitem, groups, images, descriptio
fixed = {-0.5, -0.5, 0, 0, 0, 0.5},
},
sounds = default.node_sound_stone_defaults(),
on_place = function(itemstack, placer, pointed_thing)
local keys=placer:get_player_control()
stairsplus_rotate_and_place(itemstack, placer, pointed_thing, keys["sneak"])
return itemstack
end
on_place = stairsplus_rotate_and_place
})
minetest.register_node(":"..modname .. ":micro_" .. subname .. "_1", {
@ -57,11 +53,7 @@ function register_micro(modname, subname, recipeitem, groups, images, descriptio
fixed = {-0.5, -0.5, 0, 0, -0.4375, 0.5},
},
sounds = default.node_sound_stone_defaults(),
on_place = function(itemstack, placer, pointed_thing)
local keys=placer:get_player_control()
stairsplus_rotate_and_place(itemstack, placer, pointed_thing, keys["sneak"])
return itemstack
end
on_place = stairsplus_rotate_and_place
})
minetest.register_node(":"..modname .. ":micro_" .. subname .. "_2", {
@ -83,11 +75,7 @@ function register_micro(modname, subname, recipeitem, groups, images, descriptio
fixed = {-0.5, -0.5, 0, 0, -0.375, 0.5},
},
sounds = default.node_sound_stone_defaults(),
on_place = function(itemstack, placer, pointed_thing)
local keys=placer:get_player_control()
stairsplus_rotate_and_place(itemstack, placer, pointed_thing, keys["sneak"])
return itemstack
end
on_place = stairsplus_rotate_and_place
})
minetest.register_node(":"..modname .. ":micro_" .. subname .. "_4", {
@ -109,11 +97,7 @@ function register_micro(modname, subname, recipeitem, groups, images, descriptio
fixed = {-0.5, -0.5, 0, 0, -0.25, 0.5},
},
sounds = default.node_sound_stone_defaults(),
on_place = function(itemstack, placer, pointed_thing)
local keys=placer:get_player_control()
stairsplus_rotate_and_place(itemstack, placer, pointed_thing, keys["sneak"])
return itemstack
end
on_place = stairsplus_rotate_and_place
})
minetest.register_node(":"..modname .. ":micro_" .. subname .. "_12", {
@ -135,11 +119,7 @@ function register_micro(modname, subname, recipeitem, groups, images, descriptio
fixed = {-0.5, -0.5, 0, 0, 0.25, 0.5},
},
sounds = default.node_sound_stone_defaults(),
on_place = function(itemstack, placer, pointed_thing)
local keys=placer:get_player_control()
stairsplus_rotate_and_place(itemstack, placer, pointed_thing, keys["sneak"])
return itemstack
end
on_place = stairsplus_rotate_and_place
})
minetest.register_node(":"..modname .. ":micro_" .. subname .. "_14", {
@ -161,11 +141,7 @@ function register_micro(modname, subname, recipeitem, groups, images, descriptio
fixed = {-0.5, -0.5, 0, 0, 0.375, 0.5},
},
sounds = default.node_sound_stone_defaults(),
on_place = function(itemstack, placer, pointed_thing)
local keys=placer:get_player_control()
stairsplus_rotate_and_place(itemstack, placer, pointed_thing, keys["sneak"])
return itemstack
end
on_place = stairsplus_rotate_and_place
})
minetest.register_node(":"..modname .. ":micro_" .. subname .. "_15", {
@ -187,11 +163,7 @@ function register_micro(modname, subname, recipeitem, groups, images, descriptio
fixed = {-0.5, -0.5, 0, 0, 0.4375, 0.5},
},
sounds = default.node_sound_stone_defaults(),
on_place = function(itemstack, placer, pointed_thing)
local keys=placer:get_player_control()
stairsplus_rotate_and_place(itemstack, placer, pointed_thing, keys["sneak"])
return itemstack
end
on_place = stairsplus_rotate_and_place
})
minetest.register_alias(modname..":micro_"..subname.."_bottom", modname..":micro_"..subname)

View File

@ -30,11 +30,7 @@ function register_panel(modname, subname, recipeitem, groups, images, descriptio
type = "fixed",
fixed = {-0.5, -0.5, 0, 0.5, 0, 0.5},
},
on_place = function(itemstack, placer, pointed_thing)
local keys=placer:get_player_control()
stairsplus_rotate_and_place(itemstack, placer, pointed_thing, keys["sneak"])
return itemstack
end
on_place = stairsplus_rotate_and_place
})
minetest.register_node(":" .. modname .. ":panel_" .. subname .. "_1", {
@ -55,11 +51,7 @@ function register_panel(modname, subname, recipeitem, groups, images, descriptio
type = "fixed",
fixed = {-0.5, -0.5, 0, 0.5, -0.4375, 0.5},
},
on_place = function(itemstack, placer, pointed_thing)
local keys=placer:get_player_control()
stairsplus_rotate_and_place(itemstack, placer, pointed_thing, keys["sneak"])
return itemstack
end
on_place = stairsplus_rotate_and_place
})
minetest.register_node(":" .. modname .. ":panel_" .. subname .. "_2", {
@ -80,11 +72,7 @@ function register_panel(modname, subname, recipeitem, groups, images, descriptio
type = "fixed",
fixed = {-0.5, -0.5, 0, 0.5, -0.375, 0.5},
},
on_place = function(itemstack, placer, pointed_thing)
local keys=placer:get_player_control()
stairsplus_rotate_and_place(itemstack, placer, pointed_thing, keys["sneak"])
return itemstack
end
on_place = stairsplus_rotate_and_place
})
minetest.register_node(":" .. modname .. ":panel_" .. subname .. "_4", {
@ -105,11 +93,7 @@ function register_panel(modname, subname, recipeitem, groups, images, descriptio
type = "fixed",
fixed = {-0.5, -0.5, 0, 0.5, -0.25, 0.5},
},
on_place = function(itemstack, placer, pointed_thing)
local keys=placer:get_player_control()
stairsplus_rotate_and_place(itemstack, placer, pointed_thing, keys["sneak"])
return itemstack
end
on_place = stairsplus_rotate_and_place
})
minetest.register_node(":" .. modname .. ":panel_" .. subname .. "_12", {
@ -130,11 +114,7 @@ function register_panel(modname, subname, recipeitem, groups, images, descriptio
type = "fixed",
fixed = {-0.5, -0.5, 0, 0.5, 0.25, 0.5},
},
on_place = function(itemstack, placer, pointed_thing)
local keys=placer:get_player_control()
stairsplus_rotate_and_place(itemstack, placer, pointed_thing, keys["sneak"])
return itemstack
end
on_place = stairsplus_rotate_and_place
})
minetest.register_node(":" .. modname .. ":panel_" .. subname .. "_14", {
@ -155,11 +135,7 @@ function register_panel(modname, subname, recipeitem, groups, images, descriptio
type = "fixed",
fixed = {-0.5, -0.5, 0, 0.5, 0.375, 0.5},
},
on_place = function(itemstack, placer, pointed_thing)
local keys=placer:get_player_control()
stairsplus_rotate_and_place(itemstack, placer, pointed_thing, keys["sneak"])
return itemstack
end
on_place = stairsplus_rotate_and_place
})
minetest.register_node(":" .. modname .. ":panel_" .. subname .. "_15", {
@ -180,11 +156,7 @@ function register_panel(modname, subname, recipeitem, groups, images, descriptio
type = "fixed",
fixed = {-0.5, -0.5, 0, 0.5, 0.4375, 0.5},
},
on_place = function(itemstack, placer, pointed_thing)
local keys=placer:get_player_control()
stairsplus_rotate_and_place(itemstack, placer, pointed_thing, keys["sneak"])
return itemstack
end
on_place = stairsplus_rotate_and_place
})
minetest.register_alias(modname..":panel_"..subname.."_bottom", modname..":panel_"..subname)

View File

@ -31,11 +31,7 @@ function register_slab(modname, subname, recipeitem, groups, images, description
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
},
sounds = default.node_sound_stone_defaults(),
on_place = function(itemstack, placer, pointed_thing)
local keys=placer:get_player_control()
stairsplus_rotate_and_place(itemstack, placer, pointed_thing, keys["sneak"])
return itemstack
end
on_place = stairsplus_rotate_and_place
})
minetest.register_node(":stairs:slab_" .. subname, {
@ -56,11 +52,7 @@ function register_slab(modname, subname, recipeitem, groups, images, description
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
},
sounds = default.node_sound_stone_defaults(),
on_place = function(itemstack, placer, pointed_thing)
local keys=placer:get_player_control()
stairsplus_rotate_and_place(itemstack, placer, pointed_thing, keys["sneak"])
return itemstack
end
on_place = stairsplus_rotate_and_place
})
minetest.register_node(":"..modname .. ":slab_" .. subname .. "_quarter", {
@ -82,11 +74,7 @@ function register_slab(modname, subname, recipeitem, groups, images, description
fixed = {-0.5, -0.5, -0.5, 0.5, -0.25, 0.5},
},
sounds = default.node_sound_stone_defaults(),
on_place = function(itemstack, placer, pointed_thing)
local keys=placer:get_player_control()
stairsplus_rotate_and_place(itemstack, placer, pointed_thing, keys["sneak"])
return itemstack
end
on_place = stairsplus_rotate_and_place
})
minetest.register_node(":"..modname .. ":slab_" .. subname .. "_three_quarter", {
@ -108,11 +96,7 @@ function register_slab(modname, subname, recipeitem, groups, images, description
fixed = {-0.5, -0.5, -0.5, 0.5, 0.25, 0.5},
},
sounds = default.node_sound_stone_defaults(),
on_place = function(itemstack, placer, pointed_thing)
local keys=placer:get_player_control()
stairsplus_rotate_and_place(itemstack, placer, pointed_thing, keys["sneak"])
return itemstack
end
on_place = stairsplus_rotate_and_place
})
minetest.register_node(":"..modname .. ":slab_" .. subname .. "_1", {
@ -134,11 +118,7 @@ function register_slab(modname, subname, recipeitem, groups, images, description
fixed = {-0.5, -0.5, -0.5, 0.5, -0.4375, 0.5},
},
sounds = default.node_sound_stone_defaults(),
on_place = function(itemstack, placer, pointed_thing)
local keys=placer:get_player_control()
stairsplus_rotate_and_place(itemstack, placer, pointed_thing, keys["sneak"])
return itemstack
end
on_place = stairsplus_rotate_and_place
})
minetest.register_node(":"..modname .. ":slab_" .. subname .. "_2", {
@ -160,11 +140,7 @@ function register_slab(modname, subname, recipeitem, groups, images, description
fixed = {-0.5, -0.5, -0.5, 0.5, -0.375, 0.5},
},
sounds = default.node_sound_stone_defaults(),
on_place = function(itemstack, placer, pointed_thing)
local keys=placer:get_player_control()
stairsplus_rotate_and_place(itemstack, placer, pointed_thing, keys["sneak"])
return itemstack
end
on_place = stairsplus_rotate_and_place
})
minetest.register_node(":"..modname .. ":slab_" .. subname .. "_14", {
@ -186,11 +162,7 @@ function register_slab(modname, subname, recipeitem, groups, images, description
fixed = {-0.5, -0.5, -0.5, 0.5, 0.375, 0.5},
},
sounds = default.node_sound_stone_defaults(),
on_place = function(itemstack, placer, pointed_thing)
local keys=placer:get_player_control()
stairsplus_rotate_and_place(itemstack, placer, pointed_thing, keys["sneak"])
return itemstack
end
on_place = stairsplus_rotate_and_place
})
minetest.register_node(":"..modname .. ":slab_" .. subname .. "_15", {
@ -212,11 +184,7 @@ function register_slab(modname, subname, recipeitem, groups, images, description
fixed = {-0.5, -0.5, -0.5, 0.5, 0.4375, 0.5},
},
sounds = default.node_sound_stone_defaults(),
on_place = function(itemstack, placer, pointed_thing)
local keys=placer:get_player_control()
stairsplus_rotate_and_place(itemstack, placer, pointed_thing, keys["sneak"])
return itemstack
end
on_place = stairsplus_rotate_and_place
})
-- Unregister default recipes, optional, see _config.txt

View File

@ -36,11 +36,7 @@ function register_stair(modname, subname, recipeitem, groups, images, descriptio
},
},
sounds = default.node_sound_stone_defaults(),
on_place = function(itemstack, placer, pointed_thing)
local keys=placer:get_player_control()
stairsplus_rotate_and_place(itemstack, placer, pointed_thing, keys["sneak"])
return itemstack
end
on_place = stairsplus_rotate_and_place
})
minetest.register_node(":stairs:stair_" .. subname, {
@ -66,11 +62,7 @@ function register_stair(modname, subname, recipeitem, groups, images, descriptio
},
},
sounds = default.node_sound_stone_defaults(),
on_place = function(itemstack, placer, pointed_thing)
local keys=placer:get_player_control()
stairsplus_rotate_and_place(itemstack, placer, pointed_thing, keys["sneak"])
return itemstack
end
on_place = stairsplus_rotate_and_place
})
minetest.register_node(":" .. modname .. ":stair_" .. subname .. "_half", {
@ -97,11 +89,7 @@ function register_stair(modname, subname, recipeitem, groups, images, descriptio
},
},
sounds = default.node_sound_stone_defaults(),
on_place = function(itemstack, placer, pointed_thing)
local keys=placer:get_player_control()
stairsplus_rotate_and_place(itemstack, placer, pointed_thing, keys["sneak"])
return itemstack
end
on_place = stairsplus_rotate_and_place
})
minetest.register_node(":"..modname .. ":stair_" .. subname .. "_right_half", {
@ -128,11 +116,7 @@ function register_stair(modname, subname, recipeitem, groups, images, descriptio
},
},
sounds = default.node_sound_stone_defaults(),
on_place = function(itemstack, placer, pointed_thing)
local keys=placer:get_player_control()
stairsplus_rotate_and_place(itemstack, placer, pointed_thing, keys["sneak"])
return itemstack
end
on_place = stairsplus_rotate_and_place
})
minetest.register_node(":"..modname .. ":stair_" .. subname .. "_inner", {
@ -162,11 +146,7 @@ function register_stair(modname, subname, recipeitem, groups, images, descriptio
},
},
sounds = default.node_sound_stone_defaults(),
on_place = function(itemstack, placer, pointed_thing)
local keys=placer:get_player_control()
stairsplus_rotate_and_place(itemstack, placer, pointed_thing, keys["sneak"])
return itemstack
end
on_place = stairsplus_rotate_and_place
})
minetest.register_node(":"..modname .. ":stair_" .. subname .. "_outer", {
@ -194,11 +174,7 @@ function register_stair(modname, subname, recipeitem, groups, images, descriptio
},
},
sounds = default.node_sound_stone_defaults(),
on_place = function(itemstack, placer, pointed_thing)
local keys=placer:get_player_control()
stairsplus_rotate_and_place(itemstack, placer, pointed_thing, keys["sneak"])
return itemstack
end
on_place = stairsplus_rotate_and_place
})
minetest.register_node(":" .. modname .. ":stair_" .. subname .. "_alt", {
@ -218,11 +194,7 @@ function register_stair(modname, subname, recipeitem, groups, images, descriptio
},
},
sounds = default.node_sound_stone_defaults(),
on_place = function(itemstack, placer, pointed_thing)
local keys=placer:get_player_control()
stairsplus_rotate_and_place(itemstack, placer, pointed_thing, keys["sneak"])
return itemstack
end
on_place = stairsplus_rotate_and_place
})
-- Unregister default recipes, optional, see _config.txt