mirror of
https://github.com/tacigar/maidroid.git
synced 2025-01-10 08:10:17 +01:00
Fix core writer, etc...
This commit is contained in:
parent
fa92b56652
commit
f7c363f953
@ -277,7 +277,7 @@ end
|
|||||||
|
|
||||||
-- maidroid.register_egg registers a definition of a new egg.
|
-- maidroid.register_egg registers a definition of a new egg.
|
||||||
function maidroid.register_egg(egg_name, def)
|
function maidroid.register_egg(egg_name, def)
|
||||||
maidroid.register_eggs[egg_name] = def
|
maidroid.registered_eggs[egg_name] = def
|
||||||
|
|
||||||
minetest.register_craftitem(egg_name, {
|
minetest.register_craftitem(egg_name, {
|
||||||
description = def.description,
|
description = def.description,
|
||||||
@ -547,8 +547,8 @@ function maidroid.register_maidroid(product_name, def)
|
|||||||
})
|
})
|
||||||
|
|
||||||
-- register maidroid egg.
|
-- register maidroid egg.
|
||||||
maidroid.register_egg(production_name .. "_egg", {
|
maidroid.register_egg(product_name .. "_egg", {
|
||||||
description = production_name .. " egg",
|
description = product_name .. " egg",
|
||||||
inventory_image = def.egg_image,
|
inventory_image = def.egg_image,
|
||||||
product_name = product_name,
|
product_name = product_name,
|
||||||
})
|
})
|
||||||
|
@ -8,9 +8,10 @@ maidroid_tool.shared = {}
|
|||||||
-- maidroid_tool.shared.generate_writer is a shared
|
-- maidroid_tool.shared.generate_writer is a shared
|
||||||
-- function called for registering egg writer and core writer.
|
-- function called for registering egg writer and core writer.
|
||||||
function maidroid_tool.register_writer(nodename, options)
|
function maidroid_tool.register_writer(nodename, options)
|
||||||
local formspecs = options.formspecs
|
local description = options.description
|
||||||
|
local formspec = options.formspec
|
||||||
local tiles = options.tiles
|
local tiles = options.tiles
|
||||||
local nodebox = options.nodebox
|
local node_box = options.node_box
|
||||||
local selection_box = options.selection_box
|
local selection_box = options.selection_box
|
||||||
local duration = options.duration
|
local duration = options.duration
|
||||||
local on_activate = options.on_activate
|
local on_activate = options.on_activate
|
||||||
@ -52,7 +53,7 @@ function maidroid_tool.register_writer(nodename, options)
|
|||||||
|
|
||||||
-- if time is positive, this node is active.
|
-- if time is positive, this node is active.
|
||||||
if time >= 0 then
|
if time >= 0 then
|
||||||
if time <= max_time then
|
if time <= duration then
|
||||||
meta:set_float("time", time + 1)
|
meta:set_float("time", time + 1)
|
||||||
meta:set_string("formspec", formspec.active(time))
|
meta:set_string("formspec", formspec.active(time))
|
||||||
else
|
else
|
||||||
@ -100,15 +101,15 @@ function maidroid_tool.register_writer(nodename, options)
|
|||||||
|
|
||||||
if (listname == "fuel" and itemname == "default:coal_lump") then
|
if (listname == "fuel" and itemname == "default:coal_lump") then
|
||||||
return stack:get_count()
|
return stack:get_count()
|
||||||
elseif listname == "dye" and dye_core_map[itemname] ~= nil then
|
elseif listname == "dye" and dye_item_map[itemname] ~= nil then
|
||||||
return stack:get_count()
|
return stack:get_count()
|
||||||
elseif listname == "main" and is_mainitem(itemname) then
|
elseif listname == "main" and itemname == empty_itemname then
|
||||||
return stack:get_count()
|
return stack:get_count()
|
||||||
end
|
end
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
-- allow_metadata_inventory_move is a common callback for the core writer.
|
-- allow_metadata_inventory_move is a common callback for the node.
|
||||||
local function allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
|
local function allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local inventory = meta:get_inventory()
|
local inventory = meta:get_inventory()
|
||||||
@ -116,10 +117,10 @@ function maidroid_tool.register_writer(nodename, options)
|
|||||||
return allow_metadata_inventory_put(pos, listname, to_index, stack, player)
|
return allow_metadata_inventory_put(pos, listname, to_index, stack, player)
|
||||||
end
|
end
|
||||||
|
|
||||||
do -- register a definition of an inactive core writer.
|
do -- register a definition of an inactive node.
|
||||||
local function on_construct(pos)
|
local function on_construct(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_string("formspec", formspec_inactive)
|
meta:set_string("formspec", formspec.inactive)
|
||||||
meta:set_string("output", "")
|
meta:set_string("output", "")
|
||||||
meta:set_string("time", -1)
|
meta:set_string("time", -1)
|
||||||
|
|
||||||
@ -161,8 +162,8 @@ function maidroid_tool.register_writer(nodename, options)
|
|||||||
return stack:get_count() -- maybe add more.
|
return stack:get_count() -- maybe add more.
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_node("maidroid_tool:core_writer", {
|
minetest.register_node(nodename, {
|
||||||
description = "maidroid tool : core writer",
|
description = description,
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
@ -185,15 +186,15 @@ function maidroid_tool.register_writer(nodename, options)
|
|||||||
|
|
||||||
end -- end register inactive node.
|
end -- end register inactive node.
|
||||||
|
|
||||||
do -- register a definition of an active core writer.
|
do -- register a definition of an active node.
|
||||||
local function allow_metadata_inventory_take(pos, listname, index, stack, player)
|
local function allow_metadata_inventory_take(pos, listname, index, stack, player)
|
||||||
if listname == "core" then
|
if listname == "main" then
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
return stack:get_count()
|
return stack:get_count()
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_node("maidroid_tool:core_writer_active", {
|
minetest.register_node(nodename .. "_active", {
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
|
@ -5,11 +5,11 @@
|
|||||||
|
|
||||||
do -- register core writer
|
do -- register core writer
|
||||||
|
|
||||||
local dye_core_map = {
|
local dye_item_map = {
|
||||||
["dye:red"] = "maidroid_core:basic",
|
["dye:red"] = "maidroid_core:basic",
|
||||||
}
|
}
|
||||||
|
|
||||||
local nodebox = {
|
local node_box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = {
|
fixed = {
|
||||||
{-0.4375, -0.25, -0.4375, 0.4375, 0.1875, 0.4375},
|
{-0.4375, -0.25, -0.4375, 0.4375, 0.1875, 0.4375},
|
||||||
@ -34,7 +34,7 @@ do -- register core writer
|
|||||||
.. default.gui_bg_img
|
.. default.gui_bg_img
|
||||||
.. default.gui_slots
|
.. default.gui_slots
|
||||||
.. "label[3.75,0;Core]"
|
.. "label[3.75,0;Core]"
|
||||||
.. "list[current_name;core;3.5,0.5;1,1;]"
|
.. "list[current_name;main;3.5,0.5;1,1;]"
|
||||||
.. "label[2.75,2;Coal]"
|
.. "label[2.75,2;Coal]"
|
||||||
.. "list[current_name;fuel;2.5,2.5;1,1;]"
|
.. "list[current_name;fuel;2.5,2.5;1,1;]"
|
||||||
.. "label[4.75,2;Dye]"
|
.. "label[4.75,2;Dye]"
|
||||||
@ -57,7 +57,7 @@ do -- register core writer
|
|||||||
.. default.gui_bg_img
|
.. default.gui_bg_img
|
||||||
.. default.gui_slots
|
.. default.gui_slots
|
||||||
.. "label[3.75,0;Core]"
|
.. "label[3.75,0;Core]"
|
||||||
.. "list[current_name;core;3.5,0.5;1,1;]"
|
.. "list[current_name;main;3.5,0.5;1,1;]"
|
||||||
.. "label[2.75,2;Coal]"
|
.. "label[2.75,2;Coal]"
|
||||||
.. "list[current_name;fuel;2.5,2.5;1,1;]"
|
.. "list[current_name;fuel;2.5,2.5;1,1;]"
|
||||||
.. "label[4.75,2;Dye]"
|
.. "label[4.75,2;Dye]"
|
||||||
@ -110,7 +110,7 @@ do -- register core writer
|
|||||||
length = 1.5,
|
length = 1.5,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
-- get_nearest_core_entity returns the nearest core entity.
|
-- get_nearest_core_entity returns the nearest core entity.
|
||||||
@ -136,7 +136,7 @@ do -- register core writer
|
|||||||
|
|
||||||
local function on_metadata_inventory_put_to_main(pos)
|
local function on_metadata_inventory_put_to_main(pos)
|
||||||
local entity_position = {
|
local entity_position = {
|
||||||
x = pos.x, y = pos.y + 0.65, z = pos.z
|
x = pos.x, y = pos.y + 0.65, z = pos.z,
|
||||||
}
|
}
|
||||||
minetest.add_entity(entity_position, "maidroid_tool:core_entity")
|
minetest.add_entity(entity_position, "maidroid_tool:core_entity")
|
||||||
end
|
end
|
||||||
@ -147,19 +147,19 @@ do -- register core writer
|
|||||||
end
|
end
|
||||||
|
|
||||||
maidroid_tool.register_writer("maidroid_tool:core_writer", {
|
maidroid_tool.register_writer("maidroid_tool:core_writer", {
|
||||||
|
description = "maidroid tool : core writer",
|
||||||
formspec = formspec,
|
formspec = formspec,
|
||||||
tiles = tiles,
|
tiles = tiles,
|
||||||
nodebox = nodebox,
|
node_box = node_box,
|
||||||
selection_box = selection_box,
|
selection_box = selection_box,
|
||||||
duration = 40,
|
duration = 40,
|
||||||
on_activate = on_activate,
|
on_activate = on_activate,
|
||||||
on_deactivate = on_deactivate,
|
on_deactivate = on_deactivate,
|
||||||
empty_itemname = "maidroid_core:empty",
|
empty_itemname = "maidroid_core:empty",
|
||||||
dye_item_map = dye_item_map,
|
dye_item_map = dye_item_map,
|
||||||
is_mainitem = maidroid.is_core,
|
|
||||||
on_metadata_inventory_put_to_main = on_metadata_inventory_put_to_main,
|
on_metadata_inventory_put_to_main = on_metadata_inventory_put_to_main,
|
||||||
on_metadata_inventory_take_from_main = on_metadata_inventory_take_from_main,
|
on_metadata_inventory_take_from_main = on_metadata_inventory_take_from_main,
|
||||||
}
|
})
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -195,23 +195,45 @@ do
|
|||||||
|
|
||||||
local function on_activate(self, staticdata)
|
local function on_activate(self, staticdata)
|
||||||
self.object:set_properties{textures = {"maidroid_tool:core_node"}}
|
self.object:set_properties{textures = {"maidroid_tool:core_node"}}
|
||||||
|
|
||||||
|
print(staticdata)
|
||||||
|
|
||||||
|
if staticdata ~= "" then
|
||||||
|
local data = minetest.deserialize(staticdata)
|
||||||
|
self.is_rotating = data["is_rotating"]
|
||||||
|
|
||||||
|
if self.is_rotating then
|
||||||
|
self:start_rotate()
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function start_rotate(self)
|
local function start_rotate(self)
|
||||||
self.object:set_properties{automatic_rotate = 1}
|
self.object:set_properties{automatic_rotate = 1}
|
||||||
|
self.is_rotating = true
|
||||||
end
|
end
|
||||||
|
|
||||||
local function stop_rotate(self)
|
local function stop_rotate(self)
|
||||||
self.object:set_properties{automatic_rotate = 0}
|
self.object:set_properties{automatic_rotate = 0}
|
||||||
|
self.is_rotating = false
|
||||||
|
end
|
||||||
|
|
||||||
|
local function get_staticdata(self)
|
||||||
|
local data = {
|
||||||
|
["is_rotating"] = self.is_rotating,
|
||||||
|
}
|
||||||
|
return minetest.serialize(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_entity("maidroid_tool:core_entity", {
|
minetest.register_entity("maidroid_tool:core_entity", {
|
||||||
physical = false,
|
physical = false,
|
||||||
visual = "wielditem",
|
visual = "wielditem",
|
||||||
visual_size = {x = 0.5, y = 0.5},
|
visual_size = {x = 0.5, y = 0.5},
|
||||||
collisionbox = {0, 0, 0, 0, 0, 0},
|
collisionbox = {0, 0, 0, 0, 0, 0},
|
||||||
on_activate = on_activate,
|
on_activate = on_activate,
|
||||||
start_rotate = start_rotate,
|
start_rotate = start_rotate,
|
||||||
stop_rotate = stop_rotate,
|
stop_rotate = stop_rotate,
|
||||||
|
get_staticdata = get_staticdata,
|
||||||
|
is_rotating = false,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
@ -54,15 +54,15 @@ local formspec = { -- want to change.
|
|||||||
|
|
||||||
local tiles = {
|
local tiles = {
|
||||||
["active"] = {
|
["active"] = {
|
||||||
"default:stone",
|
"default_stone.png",
|
||||||
},
|
},
|
||||||
|
|
||||||
["inactive"] = {
|
["inactive"] = {
|
||||||
"default:stone",
|
"default_stone.png",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
local nodebox = {
|
local node_box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = {
|
fixed = {
|
||||||
{ -0.5, -0.375, -0.4375, 0.5, 0.3125, 0.4375},
|
{ -0.5, -0.375, -0.4375, 0.5, 0.3125, 0.4375},
|
||||||
@ -82,12 +82,12 @@ local selection_box = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
maidroid_tool.register_writer("maidroid_tool:egg_writer", {
|
maidroid_tool.register_writer("maidroid_tool:egg_writer", {
|
||||||
|
description = "maidroid tool : egg writer",
|
||||||
formspec = formspec,
|
formspec = formspec,
|
||||||
tiles = tiles,
|
tiles = tiles,
|
||||||
nodebox = nodebox,
|
node_box = node_box,
|
||||||
selection_box = selection_box,
|
selection_box = selection_box,
|
||||||
duration = 30,
|
duration = 30,
|
||||||
empty_itemname = "maidroid:empty_egg",
|
empty_itemname = "maidroid:empty_egg",
|
||||||
dye_item_map = dye_item_map,
|
dye_item_map = dye_item_map,
|
||||||
is_mainitem = maidroid.is_egg,
|
})
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user