From e7ae9a01cf4d986332bcf5d7523dc768e18cca0a Mon Sep 17 00:00:00 2001 From: upsilon Date: Thu, 12 Jan 2017 19:17:51 +0100 Subject: [PATCH] Fix arrow placing issues --- README.md | 2 ++ init.lua | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1e74037..fb26499 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ throwing.enable_build_arrow = true throwing.velocity_factor = 19 throwing.horizontal_acceleration_factor = -3 throwing.vertical_acceleration = -10 + +throwing.allow_arrow_placing = false ``` ## API diff --git a/init.lua b/init.lua index 322a407..df79835 100644 --- a/init.lua +++ b/init.lua @@ -109,8 +109,15 @@ No log message is needed in this function (a generic log message is automaticall function throwing.register_arrow(name, itemcraft, craft_quantity, description, tiles, on_hit_sound, on_hit, groups) table.insert(throwing.arrows, modname..":"..name) + local _groups = {dig_immediate = 3} + if groups then + for k, v in pairs(groups) do + _groups[k] = v + end + end minetest.register_node(modname..":"..name, { drawtype = "nodebox", + paramtype = "light", node_box = { type = "fixed", fixed = { @@ -134,7 +141,22 @@ function throwing.register_arrow(name, itemcraft, craft_quantity, description, t tiles = tiles, inventory_image = tiles[1], description = description, - groups = groups + groups = _groups, + on_place = function(itemstack, placer, pointed_thing) + if minetest.setting_getbool("throwing.allow_arrow_placing") and pointed_thing.above then + if not minetest.is_protected(pointed_thing.above) then + minetest.log("action", "Player "..placer:get_player_name().." placed arrow "..modname..":"..name.." into a protected area at ("..pointed_thing.above.x..","..pointed_thing.above.y..","..pointed_thing.above.z..")") + minetest.set_node(pointed_thing.above, {name = modname..":"..name}) + itemstack:take_item() + return itemstack + else + minetest.log("warning", "Player "..placer:get_player_name().." tried to place arrow "..modname..":"..name.." into a protected area at ("..pointed_thing.above.x..","..pointed_thing.above.y..","..pointed_thing.above.z..")") + return itemstack + end + else + return itemstack + end + end }) minetest.register_entity(modname..":"..name.."_entity", {