Add new node: cardtable, craftable from 2x2 any wood.

Cardtable TODOs:

- Easy way to add card from player and pile inventories to
a free place on a table without explicitly choosing the place on the table.

- Formspec to cardtable for various functions affecting all cards
on the table. For example: Take visible cards, take all cards.
This commit is contained in:
Mikko Tuumanen 2020-06-14 21:06:49 +03:00
parent 2d42f06d86
commit 708c4a390d
2 changed files with 80 additions and 1 deletions

View File

@ -8,7 +8,7 @@ function describe(prefix,stuff)
elseif(t=="nil" or t=="userdata") then
minetest.log(prefix.." "..t)
elseif(t=="number" or t=="string" or t=="boolean") then
minetest.log(prefix.." "..value)
minetest.log(prefix.." "..t..": "..stuff)
else
minetest.log(t)
end
@ -424,6 +424,73 @@ local function after_place_pile(pos,placer,itemstack,pointed_thing)
stackmeta:set_string("description",string.sub(descr,3))
end
local function describe_cardtable(pos)
local meta=minetest.get_meta(pos)
local positions=minetest.deserialize(meta:get_string("cardtable_positions"))
for key,p in ipairs(positions) do
minetest.log("cardtable piece in "..minetest.pos_to_string(p))
end
end
local function add_node_to_cardtable(main_pos,new_pos)
minetest.log("add "..minetest.pos_to_string(new_pos).." to old cardtable with main pos="..minetest.pos_to_string(main_pos))
local new_meta=minetest.get_meta(new_pos)
local main_meta=minetest.get_meta(main_pos)
local positions=minetest.deserialize(main_meta:get_string("cardtable_positions"))
table.insert(positions,new_pos)
main_meta:set_string("cardtable_positions",minetest.serialize(positions))
new_meta:set_string("cardtable_main_x",main_pos.x)
new_meta:set_string("cardtable_main_y",main_pos.y)
new_meta:set_string("cardtable_main_z",main_pos.z)
describe_cardtable(main_pos)
end
local function on_construct_cardtable(pos)
minetest.log("construct cardtable")
local around={
{x=pos.x-1, y=pos.y, z=pos.z-1},{x=pos.x,y=pos.y,z=pos.z-1},{x=pos.x+1,y=pos.y,z=pos.z-1},
{x=pos.x-1, y=pos.y, z=pos.z}, {x=pos.x+1,y=pos.y,z=pos.z},
{x=pos.x-1, y=pos.y, z=pos.z+1},{x=pos.x,y=pos.y,z=pos.z+1},{x=pos.x+1,y=pos.y,z=pos.z+1}
}
for key,p in ipairs(around) do
local n=minetest.get_node(p)
if n.name == "deck:cardtable" then
local meta=minetest.get_meta(p)
local tmx=meta:get_string("cardtable_main_x")
local tmz=meta:get_string("cardtable_main_z")
add_node_to_cardtable({x=tmx,y=pos.y,z=tmz},pos)
return
end
end
-- this is a new cardtable
minetest.log("new cardtable")
local meta=minetest.get_meta(pos)
meta:set_string("cardtable_main_x",pos.x)
meta:set_string("cardtable_main_y",pos.y)
meta:set_string("cardtable_main_z",pos.z)
meta:set_string("cardtable_positions",minetest.serialize({pos}))
describe_cardtable(pos)
end
local function after_dig_cardtable(pos, oldnode, oldmeta, digger)
minetest.log("after dig")
describe("after_dig_meta",oldmeta)
local meta=oldmeta["fields"]
local tmx=meta["cardtable_main_x"]
local tmy=meta["cardtable_main_y"]
local tmz=meta["cardtable_main_z"]
if(pos.x==tonumber(tmx) and pos.y==tonumber(tmy) and pos.z==tonumber(tmz)) then
minetest.log("digged main node of cardtable at "..minetest.pos_to_string(pos))
local positions=minetest.deserialize(meta["cardtable_positions"])
for i,pos in ipairs(positions) do
minetest.remove_node(pos)
minetest.log("removing at "..minetest.pos_to_string(pos).." too.")
end
else
minetest.log("digged non-main node of cardtable. main="..tmx..","..tmy..","..tmz.." digged="..minetest.pos_to_string(pos))
end
end
minetest.register_node("deck:chestpile", {
description = "Card pile that user has full access to. Works also like a minetest chest.",
tiles = { "deck_back.png","deck_side.png" },
@ -473,6 +540,14 @@ minetest.register_node("deck:stockpile", {
on_receive_fields = draw_card
})
minetest.register_node("deck:cardtable", {
description = "Table where cards can be easily dealt",
tiles = { "deck_table.png" },
on_construct = on_construct_cardtable,
groups = {crumbly=1, dig_immediate=3},
after_dig_node = after_dig_cardtable
})
-- minetest.register_on_player_receive_fields(function(player, formname, fields)
-- minetest.log("xformname="..formname)
-- if fields.draw then
@ -526,6 +601,10 @@ minetest.register_craft({
output = "deck:chestpile",
recipe = {{ "default:paper" },{ "default:paper" }}
})
minetest.register_craft({
output = "deck:cardtable 99",
recipe = {{ "group:wood", "group:wood"},{"group:wood","group:wood"}}
})
local function craft_pile(itemstack,player,old_craft_grid,craft_inv,really)
--describe("craft",old_craft_grid)

BIN
textures/deck_table.xcf Normal file

Binary file not shown.