mirror of
git://repo.or.cz/minetest_schemedit.git
synced 2025-01-10 01:50:29 +01:00
Fix probability-related items
* Fix force placement * Improve item descriptions
This commit is contained in:
parent
e0941b8f61
commit
a3658af5f9
59
init.lua
59
init.lua
@ -208,9 +208,14 @@ advschem.add_form("main", {
|
|||||||
local plist = minetest.deserialize(meta.prob_list)
|
local plist = minetest.deserialize(meta.prob_list)
|
||||||
local probability_list = {}
|
local probability_list = {}
|
||||||
for _, i in pairs(plist) do
|
for _, i in pairs(plist) do
|
||||||
|
local prob = i.prob
|
||||||
|
if i.force_place == true then
|
||||||
|
prob = prob + 128
|
||||||
|
end
|
||||||
|
|
||||||
probability_list[#probability_list + 1] = {
|
probability_list[#probability_list + 1] = {
|
||||||
pos = minetest.string_to_pos(_),
|
pos = minetest.string_to_pos(_),
|
||||||
prob = i.prob,
|
prob = prob,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -270,31 +275,34 @@ advschem.add_form("prob", {
|
|||||||
local stack = inventory:get_stack("probability", 1)
|
local stack = inventory:get_stack("probability", 1)
|
||||||
local stringpos = pos.x..","..pos.y..","..pos.z
|
local stringpos = pos.x..","..pos.y..","..pos.z
|
||||||
|
|
||||||
local probchange = ""
|
local form = [[
|
||||||
|
size[8,6]
|
||||||
|
list[nodemeta:]]..stringpos..[[;probability;0,0;1,1;]
|
||||||
|
label[0,1;Probability is a number between 0 and 127.]
|
||||||
|
list[current_player;main;0,1.5;8,4;]
|
||||||
|
listring[nodemeta:]]..stringpos..[[;probability]
|
||||||
|
listring[current_player;main]
|
||||||
|
]]
|
||||||
|
|
||||||
if stack:get_name() ~= "" then
|
if stack:get_name() ~= "" then
|
||||||
local smeta = stack:get_meta():to_table().fields
|
local smeta = stack:get_meta():to_table().fields
|
||||||
|
|
||||||
probchange = [[
|
form = form .. [[
|
||||||
field[1.3,0.4;2,1;probability;Probability:;]]..(smeta.advschem_prob or "255")..[[]
|
field[1.3,0.4;2,1;probability;Probability:;]]..
|
||||||
|
(smeta.advschem_prob or "127").."]" ..
|
||||||
|
[[
|
||||||
field_close_on_enter[probability;false]
|
field_close_on_enter[probability;false]
|
||||||
checkbox[3.1,0.1;force_place;Force Place;]]..(smeta.advschem_force_place or "false")..[[]
|
checkbox[3.1,0.1;force_place;Force Place;]]..(smeta.advschem_force_place or "false")..[[]
|
||||||
button[5,0.1;1.5,1;rst;Reset]
|
button[5,0.1;1.5,1;rst;Reset]
|
||||||
button[6.5,0.1;1.5,1;save;Save]
|
button[6.5,0.1;1.5,1;save;Save]
|
||||||
]]
|
]]
|
||||||
else
|
else
|
||||||
probchange = [[
|
form = form .. [[
|
||||||
label[1,0.2;Insert item in slot.]
|
label[1,0.2;Insert item in slot.]
|
||||||
]]
|
]]
|
||||||
end
|
end
|
||||||
|
|
||||||
return [[
|
return form
|
||||||
size[8,6]
|
|
||||||
list[nodemeta:]]..stringpos..[[;probability;0,0;1,1;]
|
|
||||||
label[0,1;Probability is a number between 0 and 255.]
|
|
||||||
list[current_player;main;0,1.5;8,4;]
|
|
||||||
listring[nodemeta:]]..stringpos..[[;probability]
|
|
||||||
listring[current_player;main]
|
|
||||||
]]..probchange
|
|
||||||
end,
|
end,
|
||||||
handle = function(self, pos, name, fields)
|
handle = function(self, pos, name, fields)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
@ -316,19 +324,27 @@ advschem.add_form("prob", {
|
|||||||
smeta:set_string("description", original_desc)
|
smeta:set_string("description", original_desc)
|
||||||
elseif fields.force_place or fields.save or
|
elseif fields.force_place or fields.save or
|
||||||
fields.key_enter_field == "probability" then
|
fields.key_enter_field == "probability" then
|
||||||
|
|
||||||
|
local prob_desc = "\nProbability: "..(fields.probability or
|
||||||
|
smeta:get_string("advschem_prob") or "Not Set")
|
||||||
|
-- Update probability
|
||||||
if fields.probability ~= "" then
|
if fields.probability ~= "" then
|
||||||
local prob = tonumber(fields.probability)
|
local prob = tonumber(fields.probability)
|
||||||
if prob and prob >= 0 and prob <= 255 then
|
if prob and prob >= 0 and prob <= 127 then
|
||||||
smeta:set_string("advschem_prob", fields.probability)
|
smeta:set_string("advschem_prob", fields.probability)
|
||||||
else
|
else
|
||||||
|
prob_desc = "\nProbability: "..(smeta:get_string("advschem_prob") or
|
||||||
|
"Not Set")
|
||||||
advschem.show_formspec(pos, minetest.get_player_by_name(name), "prob")
|
advschem.show_formspec(pos, minetest.get_player_by_name(name), "prob")
|
||||||
return
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
smeta:set_string("advschem_prob", nil)
|
smeta:set_string("advschem_prob", nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Update force place if fields value is not nil
|
||||||
|
if fields.force_place ~= nil then
|
||||||
smeta:set_string("advschem_force_place", fields.force_place)
|
smeta:set_string("advschem_force_place", fields.force_place)
|
||||||
|
end
|
||||||
|
|
||||||
-- Update description
|
-- Update description
|
||||||
local desc = minetest.registered_items[stack:get_name()].description
|
local desc = minetest.registered_items[stack:get_name()].description
|
||||||
@ -344,16 +360,21 @@ advschem.add_form("prob", {
|
|||||||
smeta:set_string("original_description", desc)
|
smeta:set_string("original_description", desc)
|
||||||
end
|
end
|
||||||
|
|
||||||
desc = desc.."\n"..minetest.colorize("grey", "Probability: "..
|
local force_desc = ""
|
||||||
fields.probability.."\nForce Place: "..(fields.force_place or "false"))
|
if smeta:get_string("advschem_force_place") == "true" then
|
||||||
|
force_desc = "\n".."Force Place"
|
||||||
|
end
|
||||||
|
|
||||||
|
desc = desc..minetest.colorize("grey", prob_desc..force_desc)
|
||||||
|
|
||||||
smeta:set_string("description", desc)
|
smeta:set_string("description", desc)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Update itemstack
|
-- Update itemstack
|
||||||
inventory:set_stack("probability", 1, stack)
|
inventory:set_stack("probability", 1, stack)
|
||||||
|
|
||||||
-- Refresh formspec
|
-- Refresh formspec on reset or force placement change
|
||||||
if fields.rst then
|
if fields.rst or fields.force_place then
|
||||||
advschem.show_formspec(pos, minetest.get_player_by_name(name), "prob")
|
advschem.show_formspec(pos, minetest.get_player_by_name(name), "prob")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user