diff --git a/maidroid/api.lua b/maidroid/api.lua index 9813bd5..77d0424 100644 --- a/maidroid/api.lua +++ b/maidroid/api.lua @@ -165,7 +165,7 @@ function maidroid.register_maidroid(product_name, def) end -- create_inventory creates a new inventory, and returns it. - function create_inventory(self) + local function create_inventory(self) self.inventory_name = self.product_name .. tostring(self.manufacturing_number) local inventory = minetest.create_detached_inventory(self.inventory_name, { on_put = function(inv, listname, index, stack, player) @@ -202,7 +202,7 @@ function maidroid.register_maidroid(product_name, def) end -- create_formspec_string returns a string that represents a formspec definition. - function create_formspec_string(self) + local function create_formspec_string(self) return "size[8,9]" .. "list[detached:"..self.inventory_name..";main;0,0;4,4;]" .. "label[5,0;core]" @@ -212,7 +212,7 @@ function maidroid.register_maidroid(product_name, def) end -- on_activate is a callback function that is called when the object is created or recreated. - function on_activate(self, staticdata) + local function on_activate(self, staticdata) -- parse the staticdata, and compose a inventory. if staticdata == "" then self.product_name = product_name @@ -256,7 +256,7 @@ function maidroid.register_maidroid(product_name, def) end -- get_staticdata is a callback function that is called when the object is destroyed. - function get_staticdata(self) + local function get_staticdata(self) local inventory = self:get_inventory() local data = { ["product_name"] = self.product_name, @@ -279,7 +279,7 @@ function maidroid.register_maidroid(product_name, def) end -- on_step is a callback function that is called every delta times. - function on_step(self, dtime) + local function on_step(self, dtime) if (not self.pause) and self.core_name ~= "" then local core = maidroid.registered_cores[self.core_name] core.on_step(self, dtime) @@ -287,7 +287,7 @@ function maidroid.register_maidroid(product_name, def) end -- on_rightclick is a callback function that is called when a player right-click them. - function on_rightclick(self, clicker) + local function on_rightclick(self, clicker) minetest.show_formspec( clicker:get_player_name(), self.inventory_name, @@ -296,7 +296,7 @@ function maidroid.register_maidroid(product_name, def) end -- on_punch is a callback function that is called when a player punch then. - function on_punch(self, puncher, time_from_last_punch, tool_capabilities, dir) + local function on_punch(self, puncher, time_from_last_punch, tool_capabilities, dir) if self.pause == true then self.pause = false if self.core_name ~= "" then diff --git a/maidroid_core/cores/empty.lua b/maidroid_core/cores/empty.lua index 163fd05..18f19f9 100644 --- a/maidroid_core/cores/empty.lua +++ b/maidroid_core/cores/empty.lua @@ -12,3 +12,14 @@ maidroid.register_core("maidroid_core:empty", { on_pause = function(self) end, on_step = function(self, dtime) end, }) + +-- only a recipe of the empty core is registered. +-- other cores is created by writing on the empty core. +minetest.register_craft{ + output = "maidroid_core:empty", + recipe = { + {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}, + {"default:steel_ingot", "default:obsidian", "default:steel_ingot"}, + {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}, + }, +} diff --git a/maidroid_tool/core_writer.lua b/maidroid_tool/core_writer.lua new file mode 100644 index 0000000..43c94a2 --- /dev/null +++ b/maidroid_tool/core_writer.lua @@ -0,0 +1,225 @@ +------------------------------------------------------------ +-- Copyright (c) 2016 tacigar. All rights reserved. +-- https://github.com/tacigar/maidroid +------------------------------------------------------------ + +-- register a definition of a core writer. +(function() + local node_box = { + 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}, + }, + } + + local selection_box = { + type = "fixed", + fixed = { + {-0.4375, -0.5, -0.4375, 0.4375, 0.25, 0.4375}, + }, + } + + -- can_dig is a common callback for the core writer. + local function can_dig(pos, player) + local meta = minetest.get_meta(pos) + local inventory = meta:get_inventory() + return ( + inventory:is_empty("core") and + inventory:is_empty("fuel") and + inventory:is_empty("dye") + ) + end + + -- on_timer is a common callback for the core writer. + local function on_timer(pos, elapsed) + + end + + -- allow_metadata_inventory_put is a common callback for the core writer. + local function allow_metadata_inventory_put(pos, listname, index, stack, player) + local meta = minetest.get_meta(pos) + local inventory = meta:get_inventory() + local itemname = stack:get_name() + + if (listname == "fuel" and itemname == "default:coal_lump") then + return stack:get_count() + elseif listname == "dye" and minetest.get_item_group(itemname, "dye") > 0 then + return stack:get_count() + elseif listname == "core" and maidroid.is_core(itemname) then + return stack:get_count() + end + return 0 + end + + -- allow_metadata_inventory_move is a common callback for the core writer. + local function allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player) + local meta = minetest.get_meta(pos) + local inventory = meta:get_inventory() + local stack = inventory:get_stack(from_list, from_index) + + return allow_metadata_inventory_put(pos, listname, to_index, stack, player) + end + + -------------------------------------------------------------------- + + ;(function() -- register a definition of an inactive core writer. + local tiles = { + "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", + } + + local formspec_string = "size[8,9]" + .. "list[current_player;main;0,5;8,1;]" + .. "list[current_player;main;0,6.2;8,3;8]" + + local function on_construct(pos) + local meta = minetest.get_meta(pos) + meta:set_string("formspec", formspec_string) + + local inventory = meta:get_inventory() + inventory:set_size("core", 1) + inventory:set_size("fuel", 1) + inventory:set_size("dye", 1) + end + + local function on_metadata_inventory_move(pos) + + end + + local function allow_metadata_inventory_take(pos, listname, index, stack, player) + return stack:get_count() -- maybe add more. + end + + minetest.register_node("maidroid_tool:core_writer", { + description = "maidroid tool : core writer", + drawtype = "nodebox", + paramtype = "light", + paramtype2 = "facedir", + groups = {cracky = 2}, + is_ground_content = false, + sounds = default.node_sound_stone_defaults(), + node_box = node_box, + selection_box = selection_box, + tiles = tiles, + can_dig = can_dig, + on_construct = on_construct, + on_metadata_inventory_move = on_metadata_inventory_move, + allow_metadata_inventory_put = allow_metadata_inventory_put, + allow_metadata_inventory_move = allow_metadata_inventory_move, + allow_metadata_inventory_take = allow_metadata_inventory_take, + }) + end) () + + -------------------------------------------------------------------- + + ;(function () -- register a definition of an active core writer. + local tiles = { + "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, + }, + }, + } + + local function allow_metadata_inventory_take(pos, listname, index, stack, player) + if listname == "core" then + return 0 + end + return stack:get_count() + end + + minetest.register_node("maidroid_tool:core_writer_active", { + description = "test", + drawtype = "nodebox", + paramtype = "light", + paramtype2 = "facedir", + groups = {cracky = 2}, + is_ground_content = false, + sounds = default.node_sound_stone_defaults(), + node_box = node_box, + selection_box = selection_box, + tiles = tiles, + can_dig = can_dig, + allow_metadata_inventory_put = allow_metadata_inventory_put, + allow_metadata_inventory_move = allow_metadata_inventory_move, + allow_metadata_inventory_take = allow_metadata_inventory_take, + }) + end) () +end) () + +-- register a definition of a core entity. +;(function() + 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}, + }, + } + + 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", + } + + minetest.register_node("maidroid_tool:core_node", { + drawtype = "nodebox", + tiles = tiles, + node_box = node_box, + paramtype = "light", + paramtype2 = "facedir", + }) + + minetest.register_entity("maidroid_tool:core_entity", { + physical = false, + visual = "wielditem", + visual_size = {x = 0.5, y = 0.5}, + collisionbox = {0, 0, 0, 0, 0, 0}, + + on_activate = function(self, staticdata) + self.object:set_properties{textures = {"maidroid_tool:core_node"}} + end, + + on_step = function(self, dtime) + local yaw = self.object:getyaw() + self.object:setyaw(yaw + 0.1) + end, + }) +end) () diff --git a/maidroid_tool/depends.txt b/maidroid_tool/depends.txt new file mode 100644 index 0000000..bac044c --- /dev/null +++ b/maidroid_tool/depends.txt @@ -0,0 +1,4 @@ +default +dye +maidroid +maidroid_core diff --git a/maidroid_tool/init.lua b/maidroid_tool/init.lua new file mode 100644 index 0000000..a304258 --- /dev/null +++ b/maidroid_tool/init.lua @@ -0,0 +1,11 @@ +------------------------------------------------------------ +-- Copyright (c) 2016 tacigar. All rights reserved. +-- https://github.com/tacigar/maidroid +------------------------------------------------------------ + +maidroid_tool = {} + +maidroid_tool.modname = "maidroid_tool" +maidroid_tool.modpath = minetest.get_modpath(maidroid_tool.modname) + +dofile(maidroid_tool.modpath .. "/core_writer.lua") diff --git a/maidroid_tool/textures/maidroid_tool_core_right.png b/maidroid_tool/textures/maidroid_tool_core_right.png new file mode 100644 index 0000000..dc20489 Binary files /dev/null and b/maidroid_tool/textures/maidroid_tool_core_right.png differ diff --git a/maidroid_tool/textures/maidroid_tool_core_right.xcf b/maidroid_tool/textures/maidroid_tool_core_right.xcf new file mode 100644 index 0000000..60f0b2c Binary files /dev/null and b/maidroid_tool/textures/maidroid_tool_core_right.xcf differ diff --git a/maidroid_tool/textures/maidroid_tool_core_top.png b/maidroid_tool/textures/maidroid_tool_core_top.png new file mode 100644 index 0000000..71a5f37 Binary files /dev/null and b/maidroid_tool/textures/maidroid_tool_core_top.png differ diff --git a/maidroid_tool/textures/maidroid_tool_core_top.xcf b/maidroid_tool/textures/maidroid_tool_core_top.xcf new file mode 100644 index 0000000..5868e8c Binary files /dev/null and b/maidroid_tool/textures/maidroid_tool_core_top.xcf differ diff --git a/maidroid_tool/textures/maidroid_tool_core_writer_bottom.png b/maidroid_tool/textures/maidroid_tool_core_writer_bottom.png new file mode 100644 index 0000000..df552d6 Binary files /dev/null and b/maidroid_tool/textures/maidroid_tool_core_writer_bottom.png differ diff --git a/maidroid_tool/textures/maidroid_tool_core_writer_bottom.xcf b/maidroid_tool/textures/maidroid_tool_core_writer_bottom.xcf new file mode 100644 index 0000000..e5b8267 Binary files /dev/null and b/maidroid_tool/textures/maidroid_tool_core_writer_bottom.xcf differ diff --git a/maidroid_tool/textures/maidroid_tool_core_writer_front.png b/maidroid_tool/textures/maidroid_tool_core_writer_front.png new file mode 100644 index 0000000..dd843a1 Binary files /dev/null and b/maidroid_tool/textures/maidroid_tool_core_writer_front.png differ diff --git a/maidroid_tool/textures/maidroid_tool_core_writer_front.xcf b/maidroid_tool/textures/maidroid_tool_core_writer_front.xcf new file mode 100644 index 0000000..3d72e8d Binary files /dev/null and b/maidroid_tool/textures/maidroid_tool_core_writer_front.xcf differ diff --git a/maidroid_tool/textures/maidroid_tool_core_writer_front_active.png b/maidroid_tool/textures/maidroid_tool_core_writer_front_active.png new file mode 100644 index 0000000..c5815b7 Binary files /dev/null and b/maidroid_tool/textures/maidroid_tool_core_writer_front_active.png differ diff --git a/maidroid_tool/textures/maidroid_tool_core_writer_front_active.xcf b/maidroid_tool/textures/maidroid_tool_core_writer_front_active.xcf new file mode 100644 index 0000000..dcb61b0 Binary files /dev/null and b/maidroid_tool/textures/maidroid_tool_core_writer_front_active.xcf differ diff --git a/maidroid_tool/textures/maidroid_tool_core_writer_right.png b/maidroid_tool/textures/maidroid_tool_core_writer_right.png new file mode 100644 index 0000000..6629698 Binary files /dev/null and b/maidroid_tool/textures/maidroid_tool_core_writer_right.png differ diff --git a/maidroid_tool/textures/maidroid_tool_core_writer_right.xcf b/maidroid_tool/textures/maidroid_tool_core_writer_right.xcf new file mode 100644 index 0000000..d7306b7 Binary files /dev/null and b/maidroid_tool/textures/maidroid_tool_core_writer_right.xcf differ diff --git a/maidroid_tool/textures/maidroid_tool_core_writer_top.png b/maidroid_tool/textures/maidroid_tool_core_writer_top.png new file mode 100644 index 0000000..7f55240 Binary files /dev/null and b/maidroid_tool/textures/maidroid_tool_core_writer_top.png differ diff --git a/maidroid_tool/textures/maidroid_tool_core_writer_top.xcf b/maidroid_tool/textures/maidroid_tool_core_writer_top.xcf new file mode 100644 index 0000000..d6cffb0 Binary files /dev/null and b/maidroid_tool/textures/maidroid_tool_core_writer_top.xcf differ