Write on Paper 0.1.1 Simpler
Removed letter_empty_2 & letter_written_2. Those aren't lost ingame but look weird (facedir).
This commit is contained in:
parent
02128d6ac2
commit
b6932befb6
@ -1,31 +1,36 @@
|
|||||||
-----------------------------------------------------------------------------------------------
|
-----------------------------------------------------------------------------------------------
|
||||||
local title = "Memorandum"
|
local title = "Memorandum"
|
||||||
local version = "0.1.0"
|
local version = "0.1.1"
|
||||||
local mname = "memorandum"
|
local mname = "memorandum"
|
||||||
-----------------------------------------------------------------------------------------------
|
-----------------------------------------------------------------------------------------------
|
||||||
-- { left , bottom , front , right , top , back }
|
-- { left , bottom , front , right , top , back }
|
||||||
local sheet = { -1/2 , -1/2 , -1/2 , 1/2 , -7/16 , 1/2 }
|
local sheet = { -1/2 , -1/2 , -1/2 , 1/2 , -7/16 , 1/2 }
|
||||||
local info = 'On this piece of paper is written: "'
|
local info = 'On this piece of paper is written: "'
|
||||||
local sign = '" Signed by '
|
local sign = '" Signed by '
|
||||||
|
-- { s, w, n, e }
|
||||||
|
local wdir = { 8, 17, 6, 15 } -- wall direction
|
||||||
|
|
||||||
|
-- For compatibility with older stuff
|
||||||
|
minetest.register_alias("memorandum:letter_empty_2" ,"memorandum:letter_empty" )
|
||||||
|
minetest.register_alias("memorandum:letter_written_2","memorandum:letter_written")
|
||||||
|
|
||||||
minetest.register_craftitem(":default:paper", {
|
minetest.register_craftitem(":default:paper", {
|
||||||
description = "Paper",
|
description = "Paper",
|
||||||
inventory_image = "default_paper.png",
|
inventory_image = "default_paper.png",
|
||||||
on_place = function(itemstack, placer, pointed_thing)
|
on_place = function(itemstack, placer, pointed_thing)
|
||||||
local pt = pointed_thing
|
local pt = pointed_thing
|
||||||
local walldir = minetest.dir_to_wallmounted(placer:get_look_dir())
|
local above = pt.above
|
||||||
local floordir = minetest.dir_to_facedir(placer:get_look_dir())
|
local under = pt.under
|
||||||
local below = {x=pt.above.x, y=pt.above.y-1, z=pt.above.z}
|
local fdir = minetest.dir_to_facedir(placer:get_look_dir())
|
||||||
local node_under = minetest.get_node(pt.under)
|
if minetest.get_node(above).name == "air" then
|
||||||
local node_below = minetest.get_node(below)
|
if (above.x ~= under.x) or (above.z ~= under.z) then
|
||||||
if minetest.get_node(pt.above).name=="air"
|
minetest.add_node(above, {name="memorandum:letter_empty", param2=wdir[fdir+1]})
|
||||||
and not minetest.registered_nodes[node_under.name].buildable_to then
|
|
||||||
if not minetest.registered_nodes[node_below.name].buildable_to then
|
|
||||||
minetest.add_node(pt.above, {name="memorandum:letter_empty", param2=floordir})
|
|
||||||
else
|
else
|
||||||
minetest.add_node(pt.above, {name="memorandum:letter_empty_2", param2=walldir})
|
minetest.add_node(above, {name="memorandum:letter_empty", param2=fdir})
|
||||||
|
end
|
||||||
|
if not minetest.setting_getbool("creative_mode") then
|
||||||
|
itemstack:take_item()
|
||||||
end
|
end
|
||||||
itemstack:take_item()
|
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
@ -61,59 +66,9 @@ minetest.register_node("memorandum:letter_empty", {
|
|||||||
fields.signed = fields.signed
|
fields.signed = fields.signed
|
||||||
--[[print((sender:get_player_name() or "").." wrote \""..fields.text..
|
--[[print((sender:get_player_name() or "").." wrote \""..fields.text..
|
||||||
"\" to paper at "..minetest.pos_to_string(pos))]]
|
"\" to paper at "..minetest.pos_to_string(pos))]]
|
||||||
local direction = minetest.env:get_node(pos).param2
|
local fdir = minetest.get_node(pos).param2
|
||||||
if fields.text ~= "" then
|
if fields.text ~= "" then
|
||||||
minetest.add_node(pos, {name="memorandum:letter_written", param2=direction})
|
minetest.add_node(pos, {name="memorandum:letter_written", param2=fdir})
|
||||||
end
|
|
||||||
meta:set_string("text", fields.text)
|
|
||||||
meta:set_string("signed", "")
|
|
||||||
meta:set_string("infotext", info..fields.text..'" Unsigned')
|
|
||||||
if fields.signed ~= "" then
|
|
||||||
meta:set_string("signed", fields.signed)
|
|
||||||
meta:set_string("infotext", info..fields.text..sign..fields.signed)
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
on_dig = function(pos, node, digger)
|
|
||||||
if digger:is_player() and digger:get_inventory() then
|
|
||||||
digger:get_inventory():add_item("main", {name="default:paper", count=1, wear=0, metadata=""})
|
|
||||||
end
|
|
||||||
minetest.remove_node(pos)
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_node("memorandum:letter_empty_2", {
|
|
||||||
drawtype = "signlike",
|
|
||||||
tiles = {
|
|
||||||
"memorandum_letter_empty.png",
|
|
||||||
"memorandum_letter_empty.png^[transformFY" -- mirror
|
|
||||||
},
|
|
||||||
paramtype = "light",
|
|
||||||
paramtype2 = "wallmounted",
|
|
||||||
sunlight_propagates = true,
|
|
||||||
walkable = false,
|
|
||||||
selection_box = { type = "wallmounted"},
|
|
||||||
groups = {snappy=3,dig_immediate=3,not_in_creative_inventory=1},
|
|
||||||
sounds = default.node_sound_leaves_defaults(),
|
|
||||||
on_construct = function(pos)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
meta:set_string(
|
|
||||||
"formspec",
|
|
||||||
"size[10,7]"..
|
|
||||||
"field[1,1;8.5,1;text; Write a Letter;${text}]"..
|
|
||||||
"field[1,3;4.25,1;signed; Sign Letter (optional);${signed}]"..
|
|
||||||
"button_exit[0.75,5;4.25,1;text,signed;Done]"
|
|
||||||
)
|
|
||||||
meta:set_string("infotext", info..'"')
|
|
||||||
end,
|
|
||||||
on_receive_fields = function(pos, formname, fields, sender)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
fields.text = fields.text
|
|
||||||
fields.signed = fields.signed
|
|
||||||
--[[print((sender:get_player_name() or "").." wrote \""..fields.text..
|
|
||||||
"\" to paper at "..minetest.pos_to_string(pos))]]
|
|
||||||
local direction = minetest.env:get_node(pos).param2
|
|
||||||
if fields.text ~= "" then
|
|
||||||
minetest.add_node(pos, {name="memorandum:letter_written", param2=direction})
|
|
||||||
end
|
end
|
||||||
meta:set_string("text", fields.text)
|
meta:set_string("text", fields.text)
|
||||||
meta:set_string("signed", "")
|
meta:set_string("signed", "")
|
||||||
@ -158,12 +113,10 @@ minetest.register_craftitem("memorandum:letter", {
|
|||||||
end,
|
end,
|
||||||
on_place = function(itemstack, placer, pointed_thing)
|
on_place = function(itemstack, placer, pointed_thing)
|
||||||
local pt = pointed_thing
|
local pt = pointed_thing
|
||||||
local walldir = minetest.dir_to_wallmounted(placer:get_look_dir())
|
local above = pt.above
|
||||||
local floordir = minetest.dir_to_facedir(placer:get_look_dir())
|
local under = pt.under
|
||||||
local below = {x=pt.above.x, y=pt.above.y-1, z=pt.above.z}
|
local fdir = minetest.dir_to_facedir(placer:get_look_dir())
|
||||||
local node_under = minetest.get_node(pt.under)
|
local meta = minetest.get_meta(above)
|
||||||
local node_below = minetest.get_node(below)
|
|
||||||
local meta = minetest.get_meta(pt.above)
|
|
||||||
local text = itemstack:get_metadata()
|
local text = itemstack:get_metadata()
|
||||||
local scnt = string.sub (text, -2, -1)
|
local scnt = string.sub (text, -2, -1)
|
||||||
if scnt == "00" then
|
if scnt == "00" then
|
||||||
@ -176,12 +129,11 @@ minetest.register_craftitem("memorandum:letter", {
|
|||||||
mssg = string.sub (text, 1, -scnt -3)
|
mssg = string.sub (text, 1, -scnt -3)
|
||||||
sgnd = string.sub (text, -scnt-2, -3)
|
sgnd = string.sub (text, -scnt-2, -3)
|
||||||
end
|
end
|
||||||
if minetest.get_node(pt.above).name == "air"
|
if minetest.get_node(above).name == "air" then
|
||||||
and not minetest.registered_nodes[node_under.name].buildable_to then
|
if (above.x ~= under.x) or (above.z ~= under.z) then
|
||||||
if not minetest.registered_nodes[node_below.name].buildable_to then
|
minetest.add_node(above, {name="memorandum:letter_written", param2=wdir[fdir+1]})
|
||||||
minetest.add_node(pt.above, {name="memorandum:letter_written", param2=floordir})
|
|
||||||
else
|
else
|
||||||
minetest.add_node(pt.above, {name="memorandum:letter_written_2", param2=walldir})
|
minetest.add_node(above, {name="memorandum:letter_written", param2=fdir})
|
||||||
end
|
end
|
||||||
if scnt == "00" or tonumber(scnt) == nil then
|
if scnt == "00" or tonumber(scnt) == nil then
|
||||||
meta:set_string("infotext", info..mssg..'" Unsigned')
|
meta:set_string("infotext", info..mssg..'" Unsigned')
|
||||||
@ -217,68 +169,9 @@ minetest.register_node("memorandum:letter_written", {
|
|||||||
fields.signed = fields.signed
|
fields.signed = fields.signed
|
||||||
--[[print((sender:get_player_name() or "").." wrote \""..fields.text..
|
--[[print((sender:get_player_name() or "").." wrote \""..fields.text..
|
||||||
"\" to paper at "..minetest.pos_to_string(pos))]]
|
"\" to paper at "..minetest.pos_to_string(pos))]]
|
||||||
local direction = minetest.env:get_node(pos).param2
|
local fdir = minetest.get_node(pos).param2
|
||||||
if fields.text == "" then
|
if fields.text == "" then
|
||||||
minetest.add_node(pos, {name="memorandum:letter_empty", param2=direction})
|
minetest.add_node(pos, {name="memorandum:letter_empty", param2=fdir})
|
||||||
end
|
|
||||||
meta:set_string("text", fields.text)
|
|
||||||
meta:set_string("signed", "")
|
|
||||||
meta:set_string("infotext", info..fields.text..'" Unsigned')
|
|
||||||
if fields.signed ~= "" then
|
|
||||||
meta:set_string("signed", fields.signed)
|
|
||||||
meta:set_string("infotext", info..fields.text..sign..fields.signed)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
on_dig = function(pos, node, digger)
|
|
||||||
if digger:is_player() and digger:get_inventory() then
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
local text = meta:get_string("text")
|
|
||||||
local signed = meta:get_string("signed")
|
|
||||||
local signcount = string.len(signed)
|
|
||||||
local item = digger:get_wielded_item()
|
|
||||||
local inv = digger:get_inventory()
|
|
||||||
if string.len(signed) < 10 then
|
|
||||||
signcount = "0"..string.len(signed)
|
|
||||||
end
|
|
||||||
if signed == '" Unsigned' then
|
|
||||||
signcount = "00"
|
|
||||||
end
|
|
||||||
if item:get_name() == "vessels:glass_bottle" then
|
|
||||||
inv:remove_item("main", "vessels:glass_bottle")
|
|
||||||
inv:add_item("main", {name="memorandum:message", count=1, wear=0, metadata=text..signed..signcount})
|
|
||||||
else
|
|
||||||
inv:add_item("main", {name="memorandum:letter", count=1, wear=0, metadata=text..signed..signcount})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
minetest.remove_node(pos)
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_node("memorandum:letter_written_2", {
|
|
||||||
drawtype = "signlike",
|
|
||||||
tiles = {
|
|
||||||
"memorandum_letter_empty.png^memorandum_letter_text.png",
|
|
||||||
"memorandum_letter_empty.png^[transformFY" -- mirror
|
|
||||||
},
|
|
||||||
paramtype = "light",
|
|
||||||
paramtype2 = "wallmounted",
|
|
||||||
sunlight_propagates = true,
|
|
||||||
walkable = false,
|
|
||||||
selection_box = { type = "wallmounted"},
|
|
||||||
groups = {snappy=3,dig_immediate=3,not_in_creative_inventory=1},
|
|
||||||
sounds = default.node_sound_leaves_defaults(),
|
|
||||||
on_receive_fields = function(pos, formname, fields, sender)
|
|
||||||
local item = sender:get_wielded_item()
|
|
||||||
if item:get_name() == "memorandum:eraser" then
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
fields.text = fields.text
|
|
||||||
fields.signed = fields.signed
|
|
||||||
--[[print((sender:get_player_name() or "").." wrote \""..fields.text..
|
|
||||||
"\" to paper at "..minetest.pos_to_string(pos))]]
|
|
||||||
local direction = minetest.env:get_node(pos).param2
|
|
||||||
if fields.text == "" then
|
|
||||||
minetest.add_node(pos, {name="memorandum:letter_empty", param2=direction})
|
|
||||||
end
|
end
|
||||||
meta:set_string("text", fields.text)
|
meta:set_string("text", fields.text)
|
||||||
meta:set_string("signed", "")
|
meta:set_string("signed", "")
|
||||||
@ -368,8 +261,7 @@ minetest.register_node("memorandum:message", {
|
|||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
local pt = pointed_thing
|
local pt = pointed_thing
|
||||||
if pt.under then
|
if pt.under then
|
||||||
local there = {x=pt.under.x, y=pt.under.y+1, z=pt.under.z}
|
local meta = minetest.get_meta(pt.above)
|
||||||
local meta = minetest.get_meta(there)
|
|
||||||
local text = itemstack:get_metadata()
|
local text = itemstack:get_metadata()
|
||||||
local scnt = string.sub (text, -2, -1)
|
local scnt = string.sub (text, -2, -1)
|
||||||
if scnt == "00" then
|
if scnt == "00" then
|
||||||
@ -382,8 +274,8 @@ minetest.register_node("memorandum:message", {
|
|||||||
mssg = string.sub (text, 1, -scnt -3)
|
mssg = string.sub (text, 1, -scnt -3)
|
||||||
sgnd = string.sub (text, -scnt-2, -3)
|
sgnd = string.sub (text, -scnt-2, -3)
|
||||||
end
|
end
|
||||||
if minetest.get_node(there).name == "air" then
|
if minetest.get_node(pt.above).name == "air" then
|
||||||
minetest.add_node(there, {name="memorandum:letter_written", param2=math.random(0,3)})
|
minetest.add_node(pt.above, {name="memorandum:letter_written", param2=math.random(0,3)})
|
||||||
if scnt == "00" or tonumber(scnt) == nil then
|
if scnt == "00" or tonumber(scnt) == nil then
|
||||||
meta:set_string("infotext", info..mssg..'" Unsigned')
|
meta:set_string("infotext", info..mssg..'" Unsigned')
|
||||||
else
|
else
|
||||||
@ -399,8 +291,7 @@ minetest.register_node("memorandum:message", {
|
|||||||
end,
|
end,
|
||||||
on_place = function(itemstack, placer, pointed_thing)
|
on_place = function(itemstack, placer, pointed_thing)
|
||||||
local pt = pointed_thing
|
local pt = pointed_thing
|
||||||
local there = {x=pt.under.x, y=pt.under.y+1, z=pt.under.z}
|
local meta = minetest.get_meta(pt.above)
|
||||||
local meta = minetest.get_meta(there)
|
|
||||||
local text = itemstack:get_metadata()
|
local text = itemstack:get_metadata()
|
||||||
local scnt = string.sub (text, -2, -1)
|
local scnt = string.sub (text, -2, -1)
|
||||||
if scnt == "00" then
|
if scnt == "00" then
|
||||||
@ -413,8 +304,8 @@ minetest.register_node("memorandum:message", {
|
|||||||
mssg = string.sub (text, 1, -scnt -3)
|
mssg = string.sub (text, 1, -scnt -3)
|
||||||
sgnd = string.sub (text, -scnt-2, -3)
|
sgnd = string.sub (text, -scnt-2, -3)
|
||||||
end
|
end
|
||||||
if minetest.get_node(there).name == "air" then
|
if minetest.get_node(pt.above).name == "air" then
|
||||||
minetest.add_node(there, {name="memorandum:message"})
|
minetest.add_node(pt.above, {name="memorandum:message"})
|
||||||
meta:set_string("text", mssg)
|
meta:set_string("text", mssg)
|
||||||
meta:set_string("signed", sgnd)
|
meta:set_string("signed", sgnd)
|
||||||
itemstack:take_item()
|
itemstack:take_item()
|
||||||
@ -469,14 +360,6 @@ minetest.register_craft({
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[minetest.register_craft({
|
|
||||||
type = "shapeless",
|
|
||||||
output = "default:paper",
|
|
||||||
recipe = {"memorandum:letter","memorandum:eraser"},
|
|
||||||
replacements = {
|
|
||||||
{"memorandum:eraser", "memorandum:eraser"}
|
|
||||||
},
|
|
||||||
})]]
|
|
||||||
-----------------------------------------------------------------------------------------------
|
-----------------------------------------------------------------------------------------------
|
||||||
print("[Mod] "..title.." ["..version.."] ["..mname.."] Loaded...")
|
print("[Mod] "..title.." ["..version.."] ["..mname.."] Loaded...")
|
||||||
-----------------------------------------------------------------------------------------------
|
-----------------------------------------------------------------------------------------------
|
Loading…
Reference in New Issue
Block a user