Improved Spikes
This commit is contained in:
parent
fe3fefd40a
commit
e9f3acfd84
@ -1,5 +1,30 @@
|
|||||||
spikes = {}
|
spikes = {}
|
||||||
|
|
||||||
|
spikes.intllib_modpath = minetest.get_modpath("intllib")
|
||||||
|
|
||||||
|
if minetest.get_modpath("unified_inventory") or not minetest.setting_getbool("creative_mode") then
|
||||||
|
spikes.expect_infinite_stacks = false
|
||||||
|
else
|
||||||
|
spikes.expect_infinite_stacks = true
|
||||||
|
end
|
||||||
|
|
||||||
|
spikes.modpath = minetest.get_modpath("spikes")
|
||||||
|
|
||||||
|
-- protection wrapper for 6d stuff
|
||||||
|
|
||||||
|
function spikes.protect_and_rotate(itemstack, placer, pointed_thing)
|
||||||
|
if not spikes.node_is_owned(pointed_thing.under, placer)
|
||||||
|
and not spikes.node_is_owned(pointed_thing.above, placer) then
|
||||||
|
minetest.rotate_and_place(itemstack, placer, pointed_thing,
|
||||||
|
spikes.expect_infinite_stacks)
|
||||||
|
end
|
||||||
|
return itemstack
|
||||||
|
end
|
||||||
|
|
||||||
|
-- other components
|
||||||
|
|
||||||
|
dofile(spikes.modpath.."/ownership.lua")
|
||||||
|
|
||||||
for i, tree_name in ipairs(realtest.registered_trees_list) do
|
for i, tree_name in ipairs(realtest.registered_trees_list) do
|
||||||
local tree = realtest.registered_trees[tree_name]
|
local tree = realtest.registered_trees[tree_name]
|
||||||
|
|
||||||
@ -31,6 +56,7 @@ for i, tree_name in ipairs(realtest.registered_trees_list) do
|
|||||||
walkable = false,
|
walkable = false,
|
||||||
damage_per_second = 10,
|
damage_per_second = 10,
|
||||||
fall_damage_add_percent = 200,
|
fall_damage_add_percent = 200,
|
||||||
|
on_place = spikes.protect_and_rotate
|
||||||
}
|
}
|
||||||
|
|
||||||
minetest.register_node("spikes:spike_"..tree.name:remove_modname_prefix(), spikes)
|
minetest.register_node("spikes:spike_"..tree.name:remove_modname_prefix(), spikes)
|
||||||
|
43
mods/spikes/ownership.lua
Normal file
43
mods/spikes/ownership.lua
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
-- simple function to check for ownership of a node before placing it.
|
||||||
|
|
||||||
|
local S
|
||||||
|
if spikes.intllib_modpath then
|
||||||
|
dofile(spikes.intllib_modpath.."/intllib.lua")
|
||||||
|
S = intllib.Getter(minetest.get_current_modname())
|
||||||
|
else
|
||||||
|
S = function ( s ) return s end
|
||||||
|
end
|
||||||
|
|
||||||
|
function spikes: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
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user