forked from mtcontrib/plantlife_modpack
Fix sickle
Fixes a bunch of issues with the sickle: -sickle didnt care of protection -sickle removed filled chests (also locked ones) -when applying to a dirt node thats not "under" a player, the grass got added to the wrong position -everything that was above a dirt_with_grass node got removed Now I am proud to announce, that all these issues got resolved.
This commit is contained in:
parent
4193ffe206
commit
b7d2c9e01e
|
@ -31,6 +31,27 @@ end
|
||||||
-----------------------------------------------------------------------------------------------
|
-----------------------------------------------------------------------------------------------
|
||||||
-- Sickle
|
-- Sickle
|
||||||
-----------------------------------------------------------------------------------------------
|
-----------------------------------------------------------------------------------------------
|
||||||
|
local function sickle_can_break(pos, deff, player)
|
||||||
|
local def = ItemStack({name=deff.name}):get_definition()
|
||||||
|
|
||||||
|
if not def.diggable or (def.can_dig and not def.can_dig(pos,player)) then
|
||||||
|
minetest.log("info", player:get_player_name() .. " tried to sickle "
|
||||||
|
.. def.name .. " which is not diggable "
|
||||||
|
.. minetest.pos_to_string(pos))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if minetest.is_protected(pos, player:get_player_name()) then
|
||||||
|
minetest.log("action", player:get_player_name()
|
||||||
|
.. " tried to sickle " .. def.name
|
||||||
|
.. " at protected position "
|
||||||
|
.. minetest.pos_to_string(pos))
|
||||||
|
minetest.record_protection_violation(pos, player:get_player_name())
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
-- turns nodes with group flora=1 & flower=0 into cut grass
|
-- turns nodes with group flora=1 & flower=0 into cut grass
|
||||||
local function sickle_on_use(itemstack, user, pointed_thing, uses)
|
local function sickle_on_use(itemstack, user, pointed_thing, uses)
|
||||||
local pt = pointed_thing
|
local pt = pointed_thing
|
||||||
|
@ -43,8 +64,8 @@ local function sickle_on_use(itemstack, user, pointed_thing, uses)
|
||||||
end
|
end
|
||||||
|
|
||||||
local under = minetest.get_node(pt.under)
|
local under = minetest.get_node(pt.under)
|
||||||
local p = {x=pt.under.x, y=pt.under.y+1, z=pt.under.z}
|
local above_pos = {x=pt.under.x, y=pt.under.y+1, z=pt.under.z}
|
||||||
local above = minetest.get_node(p)
|
local above = minetest.get_node(above_pos)
|
||||||
|
|
||||||
-- return if any of the nodes is not registered
|
-- return if any of the nodes is not registered
|
||||||
if not minetest.registered_nodes[under.name] then
|
if not minetest.registered_nodes[under.name] then
|
||||||
|
@ -54,29 +75,14 @@ local function sickle_on_use(itemstack, user, pointed_thing, uses)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local node = minetest.get_node(pt.under)
|
|
||||||
-- check if something that can be cut using fine tools
|
-- check if something that can be cut using fine tools
|
||||||
if minetest.get_item_group(under.name, "snappy") > 0 then
|
if minetest.get_item_group(under.name, "snappy") > 0 then
|
||||||
-- check if flora but no flower
|
-- check if flora but no flower
|
||||||
if minetest.get_item_group(under.name, "flora") == 1 and minetest.get_item_group(under.name, "flower") == 0 then
|
if minetest.get_item_group(under.name, "flora") == 1 and minetest.get_item_group(under.name, "flower") == 0 then
|
||||||
-- turn the node into cut grass, wear out item and play sound
|
-- turn the node into cut grass, wear out item and play sound
|
||||||
minetest.set_node(pt.under, {name="dryplants:grass"})
|
minetest.set_node(pt.under, {name="dryplants:grass"})
|
||||||
else -- otherwise get the drop
|
else -- otherwise dig the node
|
||||||
local inv = user:get_inventory()
|
minetest.dig_node(pt.under)
|
||||||
local name = minetest. get_node(pt.under).name
|
|
||||||
|
|
||||||
local the_drop = minetest.registered_nodes[name].drop
|
|
||||||
|
|
||||||
if the_drop ~= nil then
|
|
||||||
if inv:room_for_item("main", the_drop) then
|
|
||||||
inv:add_item("main", the_drop)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if inv:room_for_item("main", name) then
|
|
||||||
inv:add_item("main", name)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
minetest.remove_node(pt.under)
|
|
||||||
end
|
end
|
||||||
minetest.sound_play("default_dig_crumbly", {
|
minetest.sound_play("default_dig_crumbly", {
|
||||||
pos = pt.under,
|
pos = pt.under,
|
||||||
|
@ -84,9 +90,15 @@ local function sickle_on_use(itemstack, user, pointed_thing, uses)
|
||||||
})
|
})
|
||||||
itemstack:add_wear(65535/(uses-1))
|
itemstack:add_wear(65535/(uses-1))
|
||||||
return itemstack
|
return itemstack
|
||||||
elseif string.find(node.name, "default:dirt_with_grass") then
|
elseif string.find(under.name, "default:dirt_with_grass") then
|
||||||
|
if not sickle_can_break(pt.under, under, user) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if minetest.is_protected(above_pos, user:get_player_name()) or above.name ~= "air" then
|
||||||
|
return
|
||||||
|
end
|
||||||
minetest.set_node(pt.under, {name="dryplants:grass_short"})
|
minetest.set_node(pt.under, {name="dryplants:grass_short"})
|
||||||
minetest.set_node(pt.above, {name="dryplants:grass"})
|
minetest.set_node(above_pos, {name="dryplants:grass"})
|
||||||
minetest.sound_play("default_dig_crumbly", {
|
minetest.sound_play("default_dig_crumbly", {
|
||||||
pos = pt.under,
|
pos = pt.under,
|
||||||
gain = 0.5,
|
gain = 0.5,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user