Moretrees' trunks can now be turned sideways when placing,
authorVanessa Ezekowitz <vanessaezekowitz@gmail.com>
Fri, 8 Nov 2013 01:59:50 +0000 (20:59 -0500)
committerVanessa Ezekowitz <vanessaezekowitz@gmail.com>
Fri, 8 Nov 2013 02:01:09 +0000 (21:01 -0500)
using minetest.rotate_and_place()

Requires Minetest git commit 1d856b73 or later.

init.lua
node_defs.lua
ownership.lua [new file with mode: 0644]

index 0dec9e501831d07efc04301cae5c74d4a6efc354..dc7d73397d61b3f7c517c74609ba14771efe0c4e 100644 (file)
--- a/init.lua
+++ b/init.lua
@@ -44,6 +44,27 @@ else
        dofile(worldpath.."/moretrees_settings.txt")
 end
 
+-- Boilerplate to support localized strings if intllib mod is installed.
+
+local S
+if moretrees.intllib_modpath then
+    dofile(moretrees.intllib_modpath.."/intllib.lua")
+    S = intllib.Getter(minetest.get_current_modname())
+else
+    S = function ( s ) return s end
+end
+moretrees.gettext = S
+
+-- infinite stacks checking
+
+if minetest.get_modpath("unified_inventory") or not minetest.setting_getbool("creative_mode") then
+       moretrees.expect_infinite_stacks = false
+else
+       moretrees.expect_infinite_stacks = true
+end
+
+-- tables, load other files
+
 moretrees.cutting_tools = {
        "default:axe_bronze",
        "default:axe_diamond",
@@ -56,6 +77,7 @@ moretrees.cutting_tools = {
        "titanium:axe",
 }
 
+dofile(modpath.."/ownership.lua")
 dofile(modpath.."/tree_models.lua")
 dofile(modpath.."/node_defs.lua")
 dofile(modpath.."/biome_defs.lua")
index 897a3c7c90241ab8b781098144883b377613e179..a4f13463a494a4d8dc4cc70c287a1193cf2dff43 100644 (file)
@@ -40,6 +40,14 @@ for i in ipairs(moretrees.treelist) do
                        is_ground_content = true,
                        groups = {tree=1,snappy=1,choppy=2,oddly_breakable_by_hand=1,flammable=2},
                        sounds = default.node_sound_wood_defaults(),
+                       on_place = function(itemstack, placer, pointed_thing)
+                               local keys=placer:get_player_control()
+                               local pos = pointed_thing.under
+                               if not moretrees:node_is_owned(pos, placer) then
+                                       minetest.rotate_and_place(itemstack, placer, pointed_thing,
+                                               moretrees.expect_infinite_stacks, { invert_wall = keys.sneak })
+                               end
+                       end
                })
 
                minetest.register_node("moretrees:"..treename.."_planks", {
@@ -378,6 +386,14 @@ minetest.register_node("moretrees:rubber_tree_trunk_empty", {
        groups = {tree=1,snappy=1,choppy=2,oddly_breakable_by_hand=1,flammable=2},
        sounds = default.node_sound_wood_defaults(),
        paramtype2 = "facedir",
+       on_place = function(itemstack, placer, pointed_thing)
+               local keys=placer:get_player_control()
+               local pos = pointed_thing.under
+               if not moretrees:node_is_owned(pos, placer) then
+                       minetest.rotate_and_place(itemstack, placer, pointed_thing,
+                               moretrees.expect_infinite_stacks, { invert_wall = keys.sneak })
+               end
+       end
 })
 
 minetest.register_abm({
diff --git a/ownership.lua b/ownership.lua
new file mode 100644 (file)
index 0000000..e075888
--- /dev/null
@@ -0,0 +1,35 @@
+
+local S = moretrees.gettext
+
+function moretrees: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