diff options
author | cheapie <no-email-for-you@example.com> | 2021-02-09 18:24:52 -0600 |
---|---|---|
committer | cheapie <no-email-for-you@example.com> | 2021-02-09 18:24:52 -0600 |
commit | ad062495d8188539bb6ac7f558e9ade50076ecd5 (patch) | |
tree | 392c019b666e01c7fdef224350dcf77f78106a1b | |
parent | 68b94cc366d0f4a8eb3e5072e056a33b4cbfad05 (diff) | |
download | digistuff-ad062495d8188539bb6ac7f558e9ade50076ecd5.tar digistuff-ad062495d8188539bb6ac7f558e9ade50076ecd5.tar.gz digistuff-ad062495d8188539bb6ac7f558e9ade50076ecd5.tar.bz2 digistuff-ad062495d8188539bb6ac7f558e9ade50076ecd5.tar.xz digistuff-ad062495d8188539bb6ac7f558e9ade50076ecd5.zip |
Make newly-placed pistons remember their owner and obey protection
Existing pistons are currently still exempt from protection.
-rw-r--r-- | piston.lua | 17 |
1 files changed, 14 insertions, 3 deletions
@@ -8,7 +8,10 @@ local function extend(pos,node,max,sound) local facedir = minetest.facedir_to_dir(node.param2) local actiondir = vector.multiply(facedir,-1) local ppos = vector.add(pos,actiondir) - local success,stack,oldstack = mesecon.mvps_push(ppos,actiondir,max) + local success,stack,oldstack = mesecon.mvps_push(ppos,actiondir,max,meta.fields.owner) + if stack == "protected" then + minetest.record_protection_violation(pos,meta.fields.owner) + end if not success then return end if sound == "digilines" then minetest.sound_play("digistuff_piston_extend",{pos = pos,max_hear_distance = 20,gain = 0.6}) @@ -39,10 +42,14 @@ local function retract(pos,node,max,allsticky,sound) if type(max) ~= "number" or max <= 0 then return end local pullpos = vector.add(pos,vector.multiply(actiondir,2)) local success,stack,oldstack + local owner = minetest.get_meta(pos):get_string("owner") if allsticky then - success,stack,oldstack = mesecon.mvps_pull_all(pullpos,facedir,max) + success,stack,oldstack = mesecon.mvps_pull_all(pullpos,facedir,max,owner ~= "" and owner) else - success,stack,oldstack = mesecon.mvps_pull_single(pullpos,facedir,max) + success,stack,oldstack = mesecon.mvps_pull_single(pullpos,facedir,max,owner ~= "" and owner) + end + if stack == "protected" then + minetest.record_protection_violation(pos,owner) end if success then mesecon.mvps_move_objects(pullpos,actiondir,oldstack,-1) @@ -57,6 +64,10 @@ minetest.register_node("digistuff:piston", { local meta = minetest.get_meta(pos) meta:set_string("formspec","field[channel;Channel;${channel}") end, + after_place_node = function(pos,placer) + local meta = minetest.get_meta(pos) + meta:set_string("owner",placer:get_player_name()) + end, tiles = { "digistuff_piston_sides.png^[transformR180", "digistuff_piston_sides.png", |