maidroid/maidroid_tool/core_writer.lua

218 lines
6.3 KiB
Lua
Raw Normal View History

2016-09-14 02:35:28 +02:00
------------------------------------------------------------
-- Copyright (c) 2016 tacigar. All rights reserved.
-- https://github.com/tacigar/maidroid
------------------------------------------------------------
2016-12-16 10:27:50 +01:00
do -- register core writer
2016-09-14 17:24:48 +02:00
2016-12-16 10:27:50 +01:00
local dye_core_map = {
["dye:red"] = "maidroid_core:basic",
}
local nodebox = {
2016-09-14 04:23:27 +02:00
type = "fixed",
fixed = {
{-0.4375, -0.25, -0.4375, 0.4375, 0.1875, 0.4375},
{ 0.1875, 0.3125, 0.0625, 0.4375, 0.375, 0.125},
{ -0.375, 0.1875, -0.375, 0.375, 0.25, 0.375},
{-0.0625, -0.5, -0.0625, 0.0625, 0.375, 0.0625},
{ 0.375, 0.1875, 0.0625, 0.4375, 0.375, 0.125},
{ -0.375, -0.5, -0.375, 0.375, -0.25, 0.375},
},
2016-09-14 13:04:21 +02:00
}
local selection_box = {
type = "fixed",
fixed = {
{-0.4375, -0.5, -0.4375, 0.4375, 0.25, 0.4375},
},
}
2016-12-16 10:27:50 +01:00
local formspec = {
["inactive"] = "size[8,9]"
2016-09-16 03:13:39 +02:00
.. default.gui_bg
.. default.gui_bg_img
.. default.gui_slots
.. "label[3.75,0;Core]"
.. "list[current_name;core;3.5,0.5;1,1;]"
.. "label[2.75,2;Coal]"
.. "list[current_name;fuel;2.5,2.5;1,1;]"
.. "label[4.75,2;Dye]"
.. "list[current_name;dye;4.5,2.5;1,1;]"
2016-12-16 10:27:50 +01:00
.. "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]"
2016-09-16 03:13:39 +02:00
.. "list[current_player;main;0,5;8,1;]"
2016-12-16 10:27:50 +01:00
.. "list[current_player;main;0,6.2;8,3;8]",
2016-12-16 14:44:48 +01:00
["active"] = function(time)
local arrow_percent = (100 / 40) * time
2016-12-16 10:27:50 +01:00
local merter_percent = 0
2016-12-16 14:44:48 +01:00
if time % 16 >= 8 then
meter_percent = (8 - (time % 8)) * (100 / 8)
2016-12-16 10:27:50 +01:00
else
2016-12-16 14:44:48 +01:00
meter_percent = (time % 8) * (100 / 8)
2016-12-16 10:27:50 +01:00
end
return "size[8,9]"
.. default.gui_bg
.. default.gui_bg_img
.. default.gui_slots
.. "label[3.75,0;Core]"
.. "list[current_name;core;3.5,0.5;1,1;]"
.. "label[2.75,2;Coal]"
.. "list[current_name;fuel;2.5,2.5;1,1;]"
.. "label[4.75,2;Dye]"
.. "list[current_name;dye;4.5,2.5;1,1;]"
.. "image[3.5,1.5;1,2;maidroid_tool_gui_arrow.png^[lowpart:"
.. arrow_percent
.. ":maidroid_tool_gui_arrow_filled.png]"
.. "image[3.1,3.5;2,1;maidroid_tool_gui_meter.png^[lowpart:"
.. meter_percent
.. ":maidroid_tool_gui_meter_filled.png^[transformR270]"
.. "list[current_player;main;0,5;8,1;]"
.. "list[current_player;main;0,6.2;8,3;8]"
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,
},
},
}
}
2016-09-16 03:13:39 +02:00
2016-09-15 02:49:29 +02:00
-- get_nearest_core_entity returns the nearest core entity.
local function get_nearest_core_entity(pos)
local all_objects = minetest.get_objects_inside_radius(pos, 1.0)
for _, object in ipairs(all_objects) do
if object:get_luaentity().name == "maidroid_tool:core_entity" then
return object:get_luaentity()
end
end
return nil
end
2016-12-16 10:27:50 +01:00
local function on_deactivate(pos)
local core_entity = get_nearest_core_entity(pos)
core_entity:stop_rotate()
2016-09-14 13:20:14 +02:00
end
2016-09-14 13:04:21 +02:00
2016-12-16 10:27:50 +01:00
local function on_activate(pos)
local core_entity = get_nearest_core_entity(pos)
core_entity:start_rotate()
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
2016-09-16 10:29:27 +02:00
2016-12-16 10:27:50 +01:00
local function on_metadata_inventory_take_from_main(pos)
local core_entity = get_nearest_core_entity(pos)
core_entity.object:remove()
2016-09-16 10:29:27 +02:00
end
2016-12-16 10:27:50 +01:00
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
2016-09-14 04:23:27 +02:00
-- register a definition of a core entity.
2016-12-16 10:29:07 +01:00
do
2016-09-14 10:34:16 +02:00
local node_box = {
type = "fixed",
fixed = {
{ -0.5, -0.5, -0.125, 0.5, -0.4375, 0.125},
{ -0.125, -0.5, -0.5, 0.125, -0.4375, 0.5},
{ -0.25, -0.5, -0.4375, 0.25, -0.4375, 0.4375},
{ -0.375, -0.5, -0.375, 0.375, -0.4375, 0.375},
{-0.4375, -0.5, -0.25, 0.4375, -0.4375, 0.25},
},
}
2016-09-14 05:33:23 +02:00
2016-09-14 10:34:16 +02:00
local tiles = {
"maidroid_tool_core_top.png",
"maidroid_tool_core_top.png",
"maidroid_tool_core_right.png",
"maidroid_tool_core_right.png",
"maidroid_tool_core_right.png",
"maidroid_tool_core_right.png",
}
2016-09-14 05:33:23 +02:00
2016-09-14 10:34:16 +02:00
minetest.register_node("maidroid_tool:core_node", {
drawtype = "nodebox",
tiles = tiles,
node_box = node_box,
paramtype = "light",
paramtype2 = "facedir",
})
2016-09-14 05:33:23 +02:00
2016-09-15 00:16:25 +02:00
local function on_activate(self, staticdata)
2016-09-15 02:49:29 +02:00
self.object:set_properties{textures = {"maidroid_tool:core_node"}}
2016-09-15 00:16:25 +02:00
end
local function start_rotate(self)
2016-09-15 02:49:29 +02:00
self.object:set_properties{automatic_rotate = 1}
2016-09-15 00:16:25 +02:00
end
local function stop_rotate(self)
2016-09-15 02:49:29 +02:00
self.object:set_properties{automatic_rotate = 0}
2016-09-15 00:16:25 +02:00
end
2016-09-14 05:33:23 +02:00
minetest.register_entity("maidroid_tool:core_entity", {
2016-09-15 02:49:29 +02:00
physical = false,
visual = "wielditem",
visual_size = {x = 0.5, y = 0.5},
collisionbox = {0, 0, 0, 0, 0, 0},
on_activate = on_activate,
start_rotate = start_rotate,
stop_rotate = stop_rotate,
2016-09-14 05:33:23 +02:00
})
2016-12-16 10:29:07 +01:00
end