Use node hashes as position identifiers

This commit is contained in:
Wuzzy 2017-09-02 23:28:07 +02:00
parent 16e2b86f94
commit 897395b1ec
1 changed files with 13 additions and 11 deletions

View File

@ -145,8 +145,8 @@ advschem.scan_metadata = function(pos1, pos2)
end end
end end
local ostrpos = minetest.pos_to_string(scanpos) local hashpos = minetest.hash_node_position(scanpos)
prob_list[ostrpos] = { prob_list[hashpos] = {
pos = scanpos, pos = scanpos,
prob = prob, prob = prob,
force_place = force_place, force_place = force_place,
@ -220,9 +220,10 @@ advschem.add_form("main", {
get = function(self, pos, name) get = function(self, pos, name)
local meta = minetest.get_meta(pos):to_table().fields local meta = minetest.get_meta(pos):to_table().fields
local strpos = minetest.pos_to_string(pos) local strpos = minetest.pos_to_string(pos)
local hashpos = minetest.hash_node_position(pos)
local border_button local border_button
if meta.schem_border == "true" and advschem.markers[strpos] then if meta.schem_border == "true" and advschem.markers[hashpos] then
border_button = "button[3.5,7.5;3,1;border;Hide border]" border_button = "button[3.5,7.5;3,1;border;Hide border]"
else else
border_button = "button[3.5,7.5;3,1;border;Show border]" border_button = "button[3.5,7.5;3,1;border;Show border]"
@ -256,11 +257,11 @@ advschem.add_form("main", {
handle = function(self, pos, name, fields) handle = function(self, pos, name, fields)
local realmeta = minetest.get_meta(pos) local realmeta = minetest.get_meta(pos)
local meta = realmeta:to_table().fields local meta = realmeta:to_table().fields
local strpos = minetest.pos_to_string(pos) local hashpos = minetest.hash_node_position(pos)
-- Toggle border -- Toggle border
if fields.border then if fields.border then
if meta.schem_border == "true" and advschem.markers[strpos] then if meta.schem_border == "true" and advschem.markers[hashpos] then
advschem.unmark(pos) advschem.unmark(pos)
meta.schem_border = "false" meta.schem_border = "false"
else else
@ -302,16 +303,16 @@ advschem.add_form("main", {
local plist = advschem.scan_metadata(pos1, pos2) local plist = advschem.scan_metadata(pos1, pos2)
local probability_list = {} local probability_list = {}
for _, i in pairs(plist) do for hash, i in pairs(plist) do
local prob = i.prob local prob = i.prob
if i.force_place == true then if i.force_place == true then
prob = prob + 128 prob = prob + 128
end end
probability_list[#probability_list + 1] = { table.insert(probability_list, {
pos = minetest.string_to_pos(_), pos = minetest.get_position_from_hash(hash),
prob = prob, prob = prob,
} })
end end
local slist = minetest.deserialize(meta.slices) local slist = minetest.deserialize(meta.slices)
@ -596,7 +597,7 @@ end
function advschem.mark(pos) function advschem.mark(pos)
advschem.unmark(pos) advschem.unmark(pos)
local id = minetest.pos_to_string(pos) local id = minetest.hash_node_position(pos)
local owner = minetest.get_meta(pos):get_string("owner") local owner = minetest.get_meta(pos):get_string("owner")
local pos1, pos2 = advschem.size(pos) local pos1, pos2 = advschem.size(pos)
pos1, pos2 = advschem.sort_pos(pos1, pos2) pos1, pos2 = advschem.sort_pos(pos1, pos2)
@ -654,7 +655,7 @@ end
-- [function] Unmark region -- [function] Unmark region
function advschem.unmark(pos) function advschem.unmark(pos)
local id = minetest.pos_to_string(pos) local id = minetest.hash_node_position(pos)
if advschem.markers[id] then if advschem.markers[id] then
local retval local retval
for _, entity in ipairs(advschem.markers[id]) do for _, entity in ipairs(advschem.markers[id]) do
@ -823,6 +824,7 @@ minetest.register_tool("advschem:probtool", {
"Note that this tool only has an effect on the nodes with regards to schematics. The node behaviour itself is not changed at all.", "Note that this tool only has an effect on the nodes with regards to schematics. The node behaviour itself is not changed at all.",
wield_image = "advschem_probtool.png", wield_image = "advschem_probtool.png",
inventory_image = "advschem_probtool.png", inventory_image = "advschem_probtool.png",
liquids_pointable = true,
on_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
-- Open dialog to change the probability to apply to nodes. -- Open dialog to change the probability to apply to nodes.
advschem.show_formspec(user:getpos(), user, "probtool", true) advschem.show_formspec(user:getpos(), user, "probtool", true)