mirror of
https://github.com/FaceDeer/dfcaverns.git
synced 2024-12-25 02:10:37 +01:00
missing callbacks for farmables
This commit is contained in:
parent
dd962f04a1
commit
c74e9316ef
@ -93,6 +93,15 @@ df_farming.plant_timer = function(pos, plantname, elapsed)
|
||||
end
|
||||
end
|
||||
|
||||
local function copy_pointed_thing(pointed_thing)
|
||||
return {
|
||||
type = pointed_thing.type,
|
||||
above = pointed_thing.above and vector.copy(pointed_thing.above),
|
||||
under = pointed_thing.under and vector.copy(pointed_thing.under),
|
||||
ref = pointed_thing.ref,
|
||||
}
|
||||
end
|
||||
|
||||
local place_seed = function(itemstack, placer, pointed_thing, plantname)
|
||||
local pt = pointed_thing
|
||||
-- check if pointing at a node
|
||||
@ -134,13 +143,30 @@ local place_seed = function(itemstack, placer, pointed_thing, plantname)
|
||||
end
|
||||
|
||||
-- add the node and remove 1 item from the itemstack
|
||||
local newnode= {name = itemstack:get_name(), param2 = 1, param1=0}
|
||||
local oldnode= minetest.get_node(pt.above)
|
||||
minetest.add_node(pt.above, {name = plantname, param2 = 1})
|
||||
|
||||
local growth_permitted_function = df_farming.growth_permitted[plantname]
|
||||
if not growth_permitted_function or growth_permitted_function(pt.above) then
|
||||
df_farming.plant_timer(pt.above, plantname)
|
||||
else
|
||||
minetest.get_node_timer(pt.above):stop() -- make sure no old timers are running on this node
|
||||
end
|
||||
|
||||
-- Run script hook
|
||||
local take_item = true
|
||||
for _, callback in ipairs(core.registered_on_placenodes) do
|
||||
-- Deepcopy pos, node and pointed_thing because callback can modify them
|
||||
local place_to_copy = vector.copy(pt.above)
|
||||
local newnode_copy = {name=newnode.name, param1=newnode.param1, param2=newnode.param2}
|
||||
local oldnode_copy = {name=oldnode.name, param1=oldnode.param1, param2=oldnode.param2}
|
||||
local pointed_thing_copy = copy_pointed_thing(pointed_thing)
|
||||
if callback(place_to_copy, newnode_copy, placer, oldnode_copy, itemstack, pointed_thing_copy) then
|
||||
take_item = false
|
||||
end
|
||||
end
|
||||
|
||||
if not minetest.settings:get_bool("creative_mode", false) then
|
||||
itemstack:take_item()
|
||||
end
|
||||
|
@ -5,6 +5,15 @@ local displace_z = 0.125
|
||||
|
||||
local plump_helmet_grow_time = df_farming.config.plant_growth_time * df_farming.config.plump_helmet_delay_multiplier / 4
|
||||
|
||||
local function copy_pointed_thing(pointed_thing)
|
||||
return {
|
||||
type = pointed_thing.type,
|
||||
above = pointed_thing.above and vector.copy(pointed_thing.above),
|
||||
under = pointed_thing.under and vector.copy(pointed_thing.under),
|
||||
ref = pointed_thing.ref,
|
||||
}
|
||||
end
|
||||
|
||||
local plump_helmet_on_place = function(itemstack, placer, pointed_thing, plantname)
|
||||
local pt = pointed_thing
|
||||
-- check if pointing at a node
|
||||
@ -46,6 +55,8 @@ local plump_helmet_on_place = function(itemstack, placer, pointed_thing, plantn
|
||||
end
|
||||
|
||||
-- add the node and remove 1 item from the itemstack
|
||||
local newnode= {name = itemstack:get_name(), param2 = new_param2, param1=0}
|
||||
local oldnode= minetest.get_node(pt.above)
|
||||
minetest.add_node(pt.above, {name = plantname, param2 = math.random(0,3)})
|
||||
|
||||
local growth_permitted_function = df_farming.growth_permitted["df_farming:plump_helmet_spawn"] -- use the same permitted function for all plump helmets
|
||||
@ -53,6 +64,19 @@ local plump_helmet_on_place = function(itemstack, placer, pointed_thing, plantn
|
||||
df_farming.plant_timer(pt.above, plantname)
|
||||
end
|
||||
|
||||
-- Run script hook
|
||||
local take_item = true
|
||||
for _, callback in ipairs(core.registered_on_placenodes) do
|
||||
-- Deepcopy pos, node and pointed_thing because callback can modify them
|
||||
local place_to_copy = vector.copy(pt.above)
|
||||
local newnode_copy = {name=newnode.name, param1=newnode.param1, param2=newnode.param2}
|
||||
local oldnode_copy = {name=oldnode.name, param1=oldnode.param1, param2=oldnode.param2}
|
||||
local pointed_thing_copy = copy_pointed_thing(pointed_thing)
|
||||
if callback(place_to_copy, newnode_copy, placer, oldnode_copy, itemstack, pointed_thing_copy) then
|
||||
take_item = false
|
||||
end
|
||||
end
|
||||
|
||||
if not minetest.settings:get_bool("creative_mode", false) then
|
||||
itemstack:take_item()
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user