Merge pull request #14 from tacigar/tacigar/maidroid/maidroid_tool

[ADD] Add tools
This commit is contained in:
Tacigar 2016-09-14 23:15:31 +09:00 committed by GitHub
commit 45de44bb27
19 changed files with 258 additions and 7 deletions

View File

@ -165,7 +165,7 @@ function maidroid.register_maidroid(product_name, def)
end end
-- create_inventory creates a new inventory, and returns it. -- 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) self.inventory_name = self.product_name .. tostring(self.manufacturing_number)
local inventory = minetest.create_detached_inventory(self.inventory_name, { local inventory = minetest.create_detached_inventory(self.inventory_name, {
on_put = function(inv, listname, index, stack, player) on_put = function(inv, listname, index, stack, player)
@ -202,7 +202,7 @@ function maidroid.register_maidroid(product_name, def)
end end
-- create_formspec_string returns a string that represents a formspec definition. -- 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]" return "size[8,9]"
.. "list[detached:"..self.inventory_name..";main;0,0;4,4;]" .. "list[detached:"..self.inventory_name..";main;0,0;4,4;]"
.. "label[5,0;core]" .. "label[5,0;core]"
@ -212,7 +212,7 @@ function maidroid.register_maidroid(product_name, def)
end end
-- on_activate is a callback function that is called when the object is created or recreated. -- 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. -- parse the staticdata, and compose a inventory.
if staticdata == "" then if staticdata == "" then
self.product_name = product_name self.product_name = product_name
@ -256,7 +256,7 @@ function maidroid.register_maidroid(product_name, def)
end end
-- get_staticdata is a callback function that is called when the object is destroyed. -- 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 inventory = self:get_inventory()
local data = { local data = {
["product_name"] = self.product_name, ["product_name"] = self.product_name,
@ -279,7 +279,7 @@ function maidroid.register_maidroid(product_name, def)
end end
-- on_step is a callback function that is called every delta times. -- 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 if (not self.pause) and self.core_name ~= "" then
local core = maidroid.registered_cores[self.core_name] local core = maidroid.registered_cores[self.core_name]
core.on_step(self, dtime) core.on_step(self, dtime)
@ -287,7 +287,7 @@ function maidroid.register_maidroid(product_name, def)
end end
-- on_rightclick is a callback function that is called when a player right-click them. -- 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( minetest.show_formspec(
clicker:get_player_name(), clicker:get_player_name(),
self.inventory_name, self.inventory_name,
@ -296,7 +296,7 @@ function maidroid.register_maidroid(product_name, def)
end end
-- on_punch is a callback function that is called when a player punch then. -- 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 if self.pause == true then
self.pause = false self.pause = false
if self.core_name ~= "" then if self.core_name ~= "" then

View File

@ -12,3 +12,14 @@ maidroid.register_core("maidroid_core:empty", {
on_pause = function(self) end, on_pause = function(self) end,
on_step = function(self, dtime) 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"},
},
}

View File

@ -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) ()

View File

@ -0,0 +1,4 @@
default
dye
maidroid
maidroid_core

11
maidroid_tool/init.lua Normal file
View File

@ -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")

Binary file not shown.

After

Width:  |  Height:  |  Size: 676 B

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 996 B

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 282 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 384 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 265 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 233 B