fix farming achievements, fix spindlestem callbacks on place

This commit is contained in:
FaceDeer 2022-08-19 01:05:57 -06:00
parent d7656c5ace
commit 4a7215f7a7
2 changed files with 30 additions and 4 deletions

View File

@ -70,8 +70,8 @@ awards.register_on_unlock(function(player_name, def)
test_list(player_name, "dfcaverns_plant_all_upper_trees", unlocked, all_upper_trees)
end)
for achievement, def in pairs(plant_node_achievements) do
awards.register_achievement(achievement, {
for _, def in pairs(plant_node_achievements) do
awards.register_achievement(def.achievement, {
title = def.title,
description = def.desc,
--icon = def.icon,

View File

@ -7,6 +7,16 @@ local get_spindlestem_cap_type
-- Copied from subterrane's features.lua
-- Figured that was nicer than adding a dependency for just this little bit
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 stem_on_place = function(itemstack, placer, pointed_thing)
local pt = pointed_thing
-- check if pointing at a node
@ -43,8 +53,24 @@ local stem_on_place = function(itemstack, placer, pointed_thing)
end
-- add the node and remove 1 item from the itemstack
minetest.add_node(pt.above, {name = itemstack:get_name(), param2 = new_param2})
if not minetest.settings:get_bool("creative_mode", false) then
local newnode= {name = itemstack:get_name(), param2 = new_param2, param1=0}
local oldnode= minetest.get_node(pt.above)
minetest.add_node(pt.above, newnode)
-- 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)) and take_item then
itemstack:take_item()
end
return itemstack