forked from mtcontrib/maidroid
Rewriter core_writer with api
This commit is contained in:
parent
1e5c0ff62f
commit
8d5799a1d0
@ -3,13 +3,13 @@
|
|||||||
-- https://github.com/tacigar/maidroid
|
-- https://github.com/tacigar/maidroid
|
||||||
------------------------------------------------------------
|
------------------------------------------------------------
|
||||||
|
|
||||||
|
do -- register core writer
|
||||||
|
|
||||||
local dye_core_map = {
|
local dye_core_map = {
|
||||||
["dye:red"] = "maidroid_core:basic",
|
["dye:red"] = "maidroid_core:basic",
|
||||||
}
|
}
|
||||||
|
|
||||||
-- register a definition of a core writer.
|
local nodebox = {
|
||||||
;(function()
|
|
||||||
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},
|
||||||
@ -28,7 +28,8 @@ local dye_core_map = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
local formspec_inactive = "size[8,9]"
|
local formspec = {
|
||||||
|
["inactive"] = "size[8,9]"
|
||||||
.. default.gui_bg
|
.. default.gui_bg
|
||||||
.. default.gui_bg_img
|
.. default.gui_bg_img
|
||||||
.. default.gui_slots
|
.. default.gui_slots
|
||||||
@ -41,18 +42,16 @@ local dye_core_map = {
|
|||||||
.. "image[3.5,1.5;1,2;maidroid_tool_gui_arrow.png]"
|
.. "image[3.5,1.5;1,2;maidroid_tool_gui_arrow.png]"
|
||||||
.. "image[3.1,3.5;2,1;maidroid_tool_gui_meter.png^[transformR270]"
|
.. "image[3.1,3.5;2,1;maidroid_tool_gui_meter.png^[transformR270]"
|
||||||
.. "list[current_player;main;0,5;8,1;]"
|
.. "list[current_player;main;0,5;8,1;]"
|
||||||
.. "list[current_player;main;0,6.2;8,3;8]"
|
.. "list[current_player;main;0,6.2;8,3;8]",
|
||||||
|
|
||||||
local function generate_formspec_active(writing_time)
|
["active"] = function(t)
|
||||||
local arrow_percent = (100 / 40) * writing_time
|
local arrow_percent = (100 / 40) * writing_time
|
||||||
|
|
||||||
local merter_percent = 0
|
local merter_percent = 0
|
||||||
if writing_time % 16 >= 8 then
|
if writing_time % 16 >= 8 then
|
||||||
meter_percent = (8 - (writing_time % 8)) * (100 / 8)
|
meter_percent = (8 - (writing_time % 8)) * (100 / 8)
|
||||||
else
|
else
|
||||||
meter_percent = (writing_time % 8) * (100 / 8)
|
meter_percent = (writing_time % 8) * (100 / 8)
|
||||||
end
|
end
|
||||||
|
|
||||||
return "size[8,9]"
|
return "size[8,9]"
|
||||||
.. default.gui_bg
|
.. default.gui_bg
|
||||||
.. default.gui_bg_img
|
.. default.gui_bg_img
|
||||||
@ -71,7 +70,48 @@ local dye_core_map = {
|
|||||||
.. ":maidroid_tool_gui_meter_filled.png^[transformR270]"
|
.. ":maidroid_tool_gui_meter_filled.png^[transformR270]"
|
||||||
.. "list[current_player;main;0,5;8,1;]"
|
.. "list[current_player;main;0,5;8,1;]"
|
||||||
.. "list[current_player;main;0,6.2;8,3;8]"
|
.. "list[current_player;main;0,6.2;8,3;8]"
|
||||||
end
|
end,
|
||||||
|
}
|
||||||
|
|
||||||
|
local tiles = {
|
||||||
|
["inactive"] = {
|
||||||
|
"maidroid_tool_core_writer_top.png",
|
||||||
|
"maidroid_tool_core_writer_bottom.png",
|
||||||
|
"maidroid_tool_core_writer_right.png",
|
||||||
|
"maidroid_tool_core_writer_right.png^[transformFX",
|
||||||
|
"maidroid_tool_core_writer_front.png^[transformFX",
|
||||||
|
"maidroid_tool_core_writer_front.png",
|
||||||
|
},
|
||||||
|
|
||||||
|
["active"] = {
|
||||||
|
"maidroid_tool_core_writer_top.png",
|
||||||
|
"maidroid_tool_core_writer_bottom.png",
|
||||||
|
"maidroid_tool_core_writer_right.png",
|
||||||
|
"maidroid_tool_core_writer_right.png^[transformFX",
|
||||||
|
{
|
||||||
|
backface_culling = false,
|
||||||
|
image = "maidroid_tool_core_writer_front_active.png^[transformFX",
|
||||||
|
|
||||||
|
animation = {
|
||||||
|
type = "vertical_frames",
|
||||||
|
aspect_w = 16,
|
||||||
|
aspect_h = 16,
|
||||||
|
length = 1.5,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
backface_culling = false,
|
||||||
|
image = "maidroid_tool_core_writer_front_active.png",
|
||||||
|
|
||||||
|
animation = {
|
||||||
|
type = "vertical_frames",
|
||||||
|
aspect_w = 16,
|
||||||
|
aspect_h = 16,
|
||||||
|
length = 1.5,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
-- get_nearest_core_entity returns the nearest core entity.
|
-- get_nearest_core_entity returns the nearest core entity.
|
||||||
local function get_nearest_core_entity(pos)
|
local function get_nearest_core_entity(pos)
|
||||||
@ -84,25 +124,51 @@ local dye_core_map = {
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- can_dig is a common callback for the core writer.
|
local function on_deactivate(pos)
|
||||||
local function can_dig(pos, player)
|
local core_entity = get_nearest_core_entity(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
core_entity:stop_rotate()
|
||||||
local inventory = meta:get_inventory()
|
|
||||||
return (
|
|
||||||
inventory:is_empty("core") and
|
|
||||||
inventory:is_empty("fuel") and
|
|
||||||
inventory:is_empty("dye")
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- swap_node is a helper function that swap two nodes.
|
local function on_activate(pos)
|
||||||
local function swap_node(pos, name)
|
local core_entity = get_nearest_core_entity(pos)
|
||||||
local node = minetest.get_node(pos)
|
core_entity:start_rotate()
|
||||||
node.name = name
|
|
||||||
|
|
||||||
minetest.swap_node(pos, node)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function on_metadata_inventory_put_to_main(pos)
|
||||||
|
local entity_position = {
|
||||||
|
x = pos.x, y = pos.y + 0.65, z = pos.z
|
||||||
|
}
|
||||||
|
minetest.add_entity(entity_position, "maidroid_tool:core_entity")
|
||||||
|
end
|
||||||
|
|
||||||
|
local function on_metadata_inventory_take_from_main(pos)
|
||||||
|
local core_entity = get_nearest_core_entity(pos)
|
||||||
|
core_entity.object:remove()
|
||||||
|
end
|
||||||
|
|
||||||
|
maidroid_tool.register_writer("maidroid_tool:core_writer", {
|
||||||
|
formspec = formspec,
|
||||||
|
tiles = tiles,
|
||||||
|
nodebox = nodebox,
|
||||||
|
selection_box = selection_box,
|
||||||
|
duration = 40,
|
||||||
|
on_activate = on_activate,
|
||||||
|
on_deactivate = on_deactivate,
|
||||||
|
empty_itemname = "maidroid_core:empty",
|
||||||
|
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_take_from_main = on_metadata_inventory_take_from_main,
|
||||||
|
}
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- on_timer is a common callback for the core writer.
|
-- on_timer is a common callback for the core writer.
|
||||||
local function on_timer(pos, elapsed)
|
local function on_timer(pos, elapsed)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
|
Loading…
Reference in New Issue
Block a user