Builder wasn't saving manually-entered facing value. Also, make metadata movement more robust.

This commit is contained in:
FaceDeer 2017-01-07 10:53:25 -07:00
parent e43c5d3974
commit c6a63cb4d4
2 changed files with 11 additions and 28 deletions

@ -77,6 +77,7 @@ minetest.register_node("digtron:builder", {
local meta = minetest.get_meta(pos)
local period = tonumber(fields.period)
local offset = tonumber(fields.offset)
local build_facing = tonumber(fields.build_facing)
if period and period > 0 then
meta:set_int("period", math.floor(tonumber(fields.period)))
else
@ -87,6 +88,9 @@ minetest.register_node("digtron:builder", {
else
offset = meta:get_int("offset")
end
if build_facing and build_facing >= 0 and build_facing < 24 then
meta:set_int("build_facing", math.floor(build_facing))
end
if fields.set then
local buildpos = digtron.find_new_pos(pos, minetest.get_node(pos).param2)
@ -122,11 +126,6 @@ minetest.register_node("digtron:builder", {
local facing = minetest.get_node(pos).param2
local buildpos = digtron.find_new_pos(pos, facing)
meta:set_int("build_facing", minetest.get_node(buildpos).param2)
else
local build_facing = tonumber(fields.build_facing)
if build_facing and build_facing >= 0 and build_facing < 24 then
meta:set_int("build_facing", math.floor(build_facing))
end
end
digtron.update_builder_item(pos)

@ -5,35 +5,19 @@ digtron.move_node = function(pos, newpos, player_name)
local oldnode = minetest.get_node(newpos)
minetest.log("action", string.format("%s moves %s from (%d, %d, %d) to (%d, %d, %d), displacing %s", player_name, node.name, pos.x, pos.y, pos.z, newpos.x, newpos.y, newpos.z, oldnode.name))
minetest.add_node(newpos, { name=node.name, param1=node.param1, param2=node.param2 })
if node_def.after_place_node then
node_def.after_place_node(newpos)
end
-- copy the metadata
local oldmeta = minetest.get_meta(pos):to_table()
minetest.get_meta(newpos):from_table(oldmeta)
local oldmeta = minetest.get_meta(pos)
local oldinv = oldmeta:get_inventory()
local list = oldinv:get_list("main")
local fuel = oldinv:get_list("fuel")
local oldformspec = oldmeta:get_string("formspec")
local newmeta = minetest.get_meta(newpos)
local newinv = newmeta:get_inventory()
newinv:set_list("main", list)
newinv:set_list("fuel", fuel)
newmeta:set_string("formspec", oldformspec)
newmeta:set_string("triggering_player", oldmeta:get_string("triggering_player")) -- for auto-controllers
newmeta:set_int("offset", oldmeta:get_int("offset"))
newmeta:set_int("period", oldmeta:get_int("period"))
newmeta:set_int("build_facing", oldmeta:get_int("build_facing"))
newmeta:set_float("fuel_burning", oldmeta:get_float("fuel_burning"))
newmeta:set_string("infotext", oldmeta:get_string("infotext"))
-- Move the little floaty entity inside the builders
if minetest.get_item_group(node.name, "digtron") == 4 then
digtron.update_builder_item(newpos)
end
if node_def.after_place_node then
node_def.after_place_node(newpos)
end
-- remove node from old position
minetest.remove_node(pos)
if node_def.after_dig_node then