Merge branch 'master' into create_farming_core
67
README-ja.md
@ -1,40 +1,57 @@
|
|||||||
# Maidroid
|
# Overview
|
||||||
|
|
||||||
Maidroidは、Minecraft用のMOD `littleMaidMob` にインスパイアされて開発している、Minetestの世界にメイドロボットを追加するMOD(MOD Pack)です。
|
Maidroid MOD は, Minecraft のMOD `littleMaidMob` にインスパイアされて開発を始めた, 孤独な Minetest の世界にメイドのロボットを追加する MOD です。
|
||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
|
|
||||||
## Overview
|
Maidroid を作り出すには, まず空の卵と卵に命を吹き込むための, Maidroid-Egg Writer を作成しなければなりません.
|
||||||
|
それらのレシピを以下に示します.
|
||||||
|
|
||||||
- MaidroidはCoreと呼ばれるチップを埋め込まれると、そのチップに埋め込まれたプログラムを実行する
|
<img src="http://i.imgur.com/6ZGQF4J.png" />
|
||||||
- CoreはCoreWriterと呼ばれるチップへの書き込みを行う機械を使うことで、様々なチップへ変換することができる
|
<img src="http://i.imgur.com/Y5tzPGM.png" />
|
||||||
|
|
||||||
## Core
|
次に, Maidroid-Egg Writer 設置, 右クリックし, `Egg` と書かれたスロットに先ほど作成した空の卵を置きます.
|
||||||
|
また, `Fuel` と書かれたスロットには石炭を, `Dye` と書かれたスロットには染料を設置します.
|
||||||
|
この染料の色によって, 生成される卵の種類が変化します.
|
||||||
|
以下に染料と, 生成される卵の対応を示します.
|
||||||
|
|
||||||
Coreの種類とその機能の説明を以下に示す。
|
|染料|Egg|
|
||||||
|
|
||||||
|Core|説明|
|
|
||||||
|:--|:--|
|
|:--|:--|
|
||||||
|`maidroid_core:empty`|何もしない。CoreWriterで変換するための材料|
|
|`dye:red`|`maidroid:maidroid_mk1_egg`|
|
||||||
|`maidroid_core:basic`|プレーヤーの後ろを付いてくる。荷物持ちくらいにはなる|
|
|
||||||
|
|
||||||
## Crafting
|
しばらく待つと, 空の卵に命が吹き込まれ, 新しい卵に変換されます.
|
||||||
|
この卵を取り出し地面に投げつけると, Maidroid が誕生します.
|
||||||
|
|
||||||
```
|
この状態では, Maidroid は止まったままです.
|
||||||
"maidroid_tool:core_writer" : {
|
Maidroid を動かすためには, Core, つまり Maidroid の脳を埋め込む必要があります.
|
||||||
{"default:steel_ingot", "default:diamond", "default:steel_ingot"},
|
Core を作り出す手順は Maidroid を作り出す手順と非常に似ています.
|
||||||
{ "default:cobble", "default:steel_ingot", "default:cobble"},
|
まず, 空の Core と Core に情報を書き込む為の Core Writer を作成します.
|
||||||
{ "default:cobble", "default:cobble", "default:cobble"},
|
それらのレシピを以下に示します.
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
CoreWriterを用いてEmptyCoreへの書き込みを行う際には染料が必要であり、染料と生成されるCoreの種類は一対一に対応する。
|
<img src="http://i.imgur.com/Sxnr38Y.png">
|
||||||
その対応関係を以下に列挙する。
|
<img src="http://i.imgur.com/97VENIl.png">
|
||||||
|
|
||||||
|染料|生成されるCore|
|
Core Writer を設置 & 右クリックし, `Core` スロットに空の Core, `Fuel` スロットに石炭, `Dye` スロットに染料を設置します.
|
||||||
|:--|:--|
|
Maidroid-Egg Writer 同様, 設置される染料の種類によって, 生成される Core の種類が変化します.
|
||||||
||`maidroid_core:empty`|
|
以下に染料と, 生成される Core の対応を示します.
|
||||||
|`dye:red`|`maidroid_core:basic`|
|
|
||||||
|
|
||||||
|
|染料|Core|説明|
|
||||||
|
|:--|:--|:--|
|
||||||
|
|`dye:red`|`maidroid_core:basic`|プレーヤーを追いかけてくる. |
|
||||||
|
|
||||||
|
Core が生成されたら早速 Maidroid に埋め込みましょう.
|
||||||
|
Maidroid を右クリックし, Core と書かれたスロットに先ほど作成した Core を設置します.
|
||||||
|
すると, Maidroid が動き始めるでしょう.
|
||||||
|
|
||||||
|
# Dependencies
|
||||||
|
|
||||||
|
- bucket
|
||||||
|
- default
|
||||||
|
- dye
|
||||||
|
|
||||||
|
# Lisense
|
||||||
|
|
||||||
|
- Source Code : [GPLv3](https://www.gnu.org/licenses/gpl-3.0.html) or later
|
||||||
|
- Resources : [CC-BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/) or later
|
||||||
|
|
||||||
|
# Contributers
|
||||||
|
63
README.md
@ -1,26 +1,63 @@
|
|||||||
# Maidroid
|
# Maidroid
|
||||||
Maidroid is a mod for Minetest which adds maid robots that can perform common tasks such as farming and cutting down trees.
|
|
||||||
|
|
||||||

|
## Overview
|
||||||
|
|
||||||
|
Maidroid MOD is a MOD for Minetest which adds maid robots, inspired by littleMaidMob.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
First, in order to create a maidroid, you have to craft an empty egg and an egg writer that convert eggs.
|
||||||
|
Those recipe is as follows.
|
||||||
|
|
||||||
|
<img src="http://i.imgur.com/6ZGQF4J.png" />
|
||||||
|
<img src="http://i.imgur.com/Y5tzPGM.png" />
|
||||||
|
|
||||||
|
After you place an egg writer node, and rightclick it, you have to place an empty egg to the slot labeled `Egg`, a coal to the slot labeled `Fuel`, and a dye to the slot labeled `Dye`.
|
||||||
|
The kind of the dye placed decides a egg produced.
|
||||||
|
The correspondences are as follows.
|
||||||
|
|
||||||
|
|Dye|Egg|
|
||||||
|
|:--|:--|
|
||||||
|
|`dye:red`|`maidroid:maidroid_mk1_egg`|
|
||||||
|
|
||||||
|
After a while, the empty egg will be converted to an new egg.
|
||||||
|
If you take and use it, a new maidroid will be born.
|
||||||
|
|
||||||
|
The maidroid, however, doesn't move now.
|
||||||
|
In order to have them move, you have to put a Core that is their brain.
|
||||||
|
You can create a core in a similar way to a maidroid egg.
|
||||||
|
First, you have to create an empty core and a core writer.
|
||||||
|
Those recipe is as follows.
|
||||||
|
|
||||||
|
<img src="http://i.imgur.com/Sxnr38Y.png">
|
||||||
|
<img src="http://i.imgur.com/97VENIl.png">
|
||||||
|
|
||||||
|
After you place a core writer node, rightclick it, and place a empty core to the slot labeled `Core`, a coal to the slot labeled `Fuel`, and a dye to the slot labeled `Dye`.
|
||||||
|
The correspondences of dyes and cores are as follows.
|
||||||
|
|
||||||
|
|Dye|Core|Description|
|
||||||
|
|:--|:--|:--|
|
||||||
|
|`dye:red`|`maidroid_core:basic`|Following the player.|
|
||||||
|
|
||||||
|
When a new core is created, put it to the maidroid.
|
||||||
|
Rightclick it, and put the core to the slot labeled `Core`.
|
||||||
|
The maidroid will start.
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
* default
|
|
||||||
* dye
|
- bucket
|
||||||
|
- default
|
||||||
|
- dye
|
||||||
|
|
||||||
## Forum Topic
|
## Forum Topic
|
||||||
|
|
||||||
The forum topic for this mod on the Minetest Forums is located at:
|
The forum topic for this mod on the Minetest Forums is located at:
|
||||||
|
|
||||||
* https://forum.minetest.net/viewtopic.php?f=9&t=14808
|
* https://forum.minetest.net/viewtopic.php?f=9&t=14808
|
||||||
|
|
||||||
## License
|
## License
|
||||||
The source code of Maidroid is available under the [GPLv3](https://www.gnu.org/licenses/gpl-3.0.html) or later license.
|
|
||||||
|
|
||||||
The resouces included in Maidroid are available under the [CC-BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/) or later license.
|
- The source code of Maidroid is available under the [GPLv3](https://www.gnu.org/licenses/gpl-3.0.html) or later license.
|
||||||
|
- The resouces included in Maidroid are available under the [CC-BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/) or later license.
|
||||||
|
|
||||||
---
|
## Contributers
|
||||||
|
|
||||||
## `maidroid/maidroid_tool`
|
|
||||||
|
|
||||||
### Core Writer
|
|
||||||
|
|
||||||

|
|
||||||
|
@ -22,6 +22,10 @@ maidroid.registered_maidroids = {}
|
|||||||
-- definitions of core registered by maidroid.register_core.
|
-- definitions of core registered by maidroid.register_core.
|
||||||
maidroid.registered_cores = {}
|
maidroid.registered_cores = {}
|
||||||
|
|
||||||
|
-- maidroid.registered_eggs represents a table that contains
|
||||||
|
-- definition of egg registered by maidroid.register_egg.
|
||||||
|
maidroid.registered_eggs = {}
|
||||||
|
|
||||||
-- maidroid.is_core reports whether a item is a core item by the name.
|
-- maidroid.is_core reports whether a item is a core item by the name.
|
||||||
function maidroid.is_core(item_name)
|
function maidroid.is_core(item_name)
|
||||||
if maidroid.registered_cores[item_name] then
|
if maidroid.registered_cores[item_name] then
|
||||||
@ -139,7 +143,7 @@ end
|
|||||||
function maidroid.maidroid.move_main_to_wield(self, itemname)
|
function maidroid.maidroid.move_main_to_wield(self, itemname)
|
||||||
local inv = self:get_inventory()
|
local inv = self:get_inventory()
|
||||||
local main_size = inv:get_size("main")
|
local main_size = inv:get_size("main")
|
||||||
|
|
||||||
for i = 1, main_size do
|
for i = 1, main_size do
|
||||||
local stack = inv:get_stack("main", i)
|
local stack = inv:get_stack("main", i)
|
||||||
if stack:get_name() == itemname then
|
if stack:get_name() == itemname then
|
||||||
@ -209,7 +213,7 @@ end)
|
|||||||
minetest.register_craftitem("maidroid:dummy_empty_craftitem", {
|
minetest.register_craftitem("maidroid:dummy_empty_craftitem", {
|
||||||
wield_image = "maidroid_dummy_empty_craftitem.png",
|
wield_image = "maidroid_dummy_empty_craftitem.png",
|
||||||
})
|
})
|
||||||
|
|
||||||
local function on_activate(self, staticdata)
|
local function on_activate(self, staticdata)
|
||||||
-- attach to the nearest maidroid.
|
-- attach to the nearest maidroid.
|
||||||
local all_objects = minetest.get_objects_inside_radius(self.object:getpos(), 0.1)
|
local all_objects = minetest.get_objects_inside_radius(self.object:getpos(), 0.1)
|
||||||
@ -246,15 +250,15 @@ end)
|
|||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_entity("maidroid:dummy_item", {
|
minetest.register_entity("maidroid:dummy_item", {
|
||||||
hp_max = 1,
|
hp_max = 1,
|
||||||
visual = "wielditem",
|
visual = "wielditem",
|
||||||
visual_size = {x = 0.025, y = 0.025},
|
visual_size = {x = 0.025, y = 0.025},
|
||||||
collisionbox = {0, 0, 0, 0, 0, 0},
|
collisionbox = {0, 0, 0, 0, 0, 0},
|
||||||
physical = false,
|
physical = false,
|
||||||
textures = {"air"},
|
textures = {"air"},
|
||||||
on_activate = on_activate,
|
on_activate = on_activate,
|
||||||
on_step = on_step,
|
on_step = on_step,
|
||||||
itemname = "",
|
itemname = "",
|
||||||
})
|
})
|
||||||
end) ()
|
end) ()
|
||||||
|
|
||||||
@ -271,10 +275,29 @@ function maidroid.register_core(core_name, def)
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- maidroid.register_egg registers a definition of a new egg.
|
||||||
|
function maidroid.register_egg(egg_name, def)
|
||||||
|
maidroid.registered_eggs[egg_name] = def
|
||||||
|
|
||||||
|
minetest.register_craftitem(egg_name, {
|
||||||
|
description = def.description,
|
||||||
|
inventory_image = def.inventory_image,
|
||||||
|
stack_max = 1,
|
||||||
|
|
||||||
|
on_use = function(item_stack, user, pointed_thing)
|
||||||
|
if pointed_thing.above ~= nil and def.product_name ~= nil then
|
||||||
|
minetest.add_entity(pointed_thing.above, def.product_name)
|
||||||
|
return itemstack
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
-- maidroid.register_maidroid registers a definition of a new maidroid.
|
-- maidroid.register_maidroid registers a definition of a new maidroid.
|
||||||
function maidroid.register_maidroid(product_name, def)
|
function maidroid.register_maidroid(product_name, def)
|
||||||
maidroid.registered_maidroids[product_name] = def
|
maidroid.registered_maidroids[product_name] = def
|
||||||
|
|
||||||
-- initialize manufacturing number of a new maidroid.
|
-- initialize manufacturing number of a new maidroid.
|
||||||
if maidroid.manufacturing_data[product_name] == nil then
|
if maidroid.manufacturing_data[product_name] == nil then
|
||||||
maidroid.manufacturing_data[product_name] = 0
|
maidroid.manufacturing_data[product_name] = 0
|
||||||
@ -523,18 +546,10 @@ function maidroid.register_maidroid(product_name, def)
|
|||||||
move_main_to_wield = maidroid.maidroid.move_main_to_wield,
|
move_main_to_wield = maidroid.maidroid.move_main_to_wield,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- register a spawner for debugging maidroid mods.
|
-- register maidroid egg.
|
||||||
minetest.register_craftitem(product_name .. "_spawner", {
|
maidroid.register_egg(product_name .. "_egg", {
|
||||||
description = product_name .. " spawner",
|
description = product_name .. " egg",
|
||||||
inventory_image = def.inventory_image,
|
inventory_image = def.egg_image,
|
||||||
stack_max = 1,
|
product_name = product_name,
|
||||||
|
|
||||||
on_use = function(item_stack, user, pointed_thing)
|
|
||||||
if pointed_thing.above ~= nil then
|
|
||||||
minetest.add_entity(pointed_thing.above, product_name)
|
|
||||||
return itemstack
|
|
||||||
end
|
|
||||||
return nil
|
|
||||||
end,
|
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
13
maidroid/crafting.lua
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
------------------------------------------------------------
|
||||||
|
-- Copyright (c) 2016 tacigar. All rights reserved.
|
||||||
|
-- https://github.com/tacigar/maidroid
|
||||||
|
------------------------------------------------------------
|
||||||
|
|
||||||
|
minetest.register_craft{
|
||||||
|
output = "maidroid:empty_egg",
|
||||||
|
recipe = {
|
||||||
|
{"default:bronze_ingot", "default:bronze_ingot", "default:bronze_ingot"},
|
||||||
|
{"default:bronze_ingot", "default:steel_ingot", "default:bronze_ingot"},
|
||||||
|
{"default:bronze_ingot", "default:bronze_ingot", "default:bronze_ingot"},
|
||||||
|
},
|
||||||
|
}
|
@ -10,3 +10,4 @@ maidroid.modpath = minetest.get_modpath(maidroid.modname)
|
|||||||
|
|
||||||
dofile(maidroid.modpath .. "/api.lua")
|
dofile(maidroid.modpath .. "/api.lua")
|
||||||
dofile(maidroid.modpath .. "/register.lua")
|
dofile(maidroid.modpath .. "/register.lua")
|
||||||
|
dofile(maidroid.modpath .. "/crafting.lua")
|
||||||
|
@ -3,26 +3,33 @@
|
|||||||
-- https://github.com/tacigar/maidroid
|
-- https://github.com/tacigar/maidroid
|
||||||
------------------------------------------------------------
|
------------------------------------------------------------
|
||||||
|
|
||||||
maidroid.register_maidroid("maidroid:maidroid_mk1", {
|
maidroid.register_egg("maidroid:empty_egg", {
|
||||||
hp_max = 10,
|
description = "Empty Egg",
|
||||||
weight = 20,
|
inventory_image = "maidroid_empty_egg.png",
|
||||||
mesh = "maidroid.b3d",
|
|
||||||
textures = {"maidroid_mk1.png"},
|
|
||||||
inventory_image = "maidroid_mk1_spawner.png",
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
maidroid.register_maidroid("maidroid:maidroid_mk1", {
|
||||||
|
hp_max = 10,
|
||||||
|
weight = 20,
|
||||||
|
mesh = "maidroid.b3d",
|
||||||
|
textures = {"maidroid_mk1.png"},
|
||||||
|
egg_image = "maidroid_maidroid_mk1_egg.png",
|
||||||
|
})
|
||||||
|
|
||||||
|
--[[
|
||||||
maidroid.register_maidroid("maidroid:maidroid_mk2", {
|
maidroid.register_maidroid("maidroid:maidroid_mk2", {
|
||||||
hp_max = 10,
|
hp_max = 10,
|
||||||
weight = 20,
|
weight = 20,
|
||||||
mesh = "maidroid.b3d",
|
mesh = "maidroid.b3d",
|
||||||
textures = {"maidroid_mk2.png"},
|
textures = {"maidroid_mk2.png"},
|
||||||
inventory_image = "maidroid_mk2_spawner.png",
|
egg_image = "maidroid_mk2_egg.png",
|
||||||
})
|
})
|
||||||
|
|
||||||
maidroid.register_maidroid("maidroid:maidroid_mk3", {
|
maidroid.register_maidroid("maidroid:maidroid_mk3", {
|
||||||
hp_max = 10,
|
hp_max = 10,
|
||||||
weight = 20,
|
weight = 20,
|
||||||
mesh = "maidroid.b3d",
|
mesh = "maidroid.b3d",
|
||||||
textures = {"maidroid_mk3.png"},
|
textures = {"maidroid_mk3.png"},
|
||||||
inventory_image = "maidroid_mk3_spawner.png",
|
egg_image = "maidroid_mk3_egg.png",
|
||||||
})
|
})
|
||||||
|
]]--
|
||||||
|
BIN
maidroid/textures/maidroid_empty_egg.png
Normal file
After Width: | Height: | Size: 337 B |
BIN
maidroid/textures/maidroid_empty_egg.xcf
Normal file
BIN
maidroid/textures/maidroid_maidroid_mk1_egg.png
Normal file
After Width: | Height: | Size: 439 B |
BIN
maidroid/textures/maidroid_maidroid_mk1_egg.xcf
Normal file
216
maidroid_tool/api.lua
Normal file
@ -0,0 +1,216 @@
|
|||||||
|
------------------------------------------------------------
|
||||||
|
-- Copyright (c) 2016 tacigar. All rights reserved.
|
||||||
|
-- https://github.com/tacigar/maidroid
|
||||||
|
------------------------------------------------------------
|
||||||
|
|
||||||
|
maidroid_tool.shared = {}
|
||||||
|
|
||||||
|
-- maidroid_tool.shared.generate_writer is a shared
|
||||||
|
-- function called for registering egg writer and core writer.
|
||||||
|
function maidroid_tool.register_writer(nodename, options)
|
||||||
|
local description = options.description
|
||||||
|
local formspec = options.formspec
|
||||||
|
local tiles = options.tiles
|
||||||
|
local node_box = options.node_box
|
||||||
|
local selection_box = options.selection_box
|
||||||
|
local duration = options.duration
|
||||||
|
local on_activate = options.on_activate
|
||||||
|
local on_deactivate = options.on_deactivate
|
||||||
|
local empty_itemname = options.empty_itemname
|
||||||
|
local dye_item_map = options.dye_item_map
|
||||||
|
local is_mainitem = options.is_mainitem
|
||||||
|
local on_metadata_inventory_put_to_main = options.on_metadata_inventory_put_to_main
|
||||||
|
local on_metadata_inventory_take_from_main = options.on_metadata_inventory_take_from_main
|
||||||
|
|
||||||
|
-- can_dig is a common callback.
|
||||||
|
local function can_dig(pos, player)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local inventory = meta:get_inventory()
|
||||||
|
return (
|
||||||
|
inventory:is_empty("main") and
|
||||||
|
inventory:is_empty("fuel") and
|
||||||
|
inventory:is_empty("dye")
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- swap_node is a helper function that swap two nodes.
|
||||||
|
local function swap_node(pos, name)
|
||||||
|
local node = minetest.get_node(pos)
|
||||||
|
node.name = name
|
||||||
|
minetest.swap_node(pos, node)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- on_timer is a common callback.
|
||||||
|
local function on_timer(pos, elapsed)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local inventory = meta:get_inventory()
|
||||||
|
local main_list = inventory:get_list("main")
|
||||||
|
local fuel_list = inventory:get_list("fuel")
|
||||||
|
local dye_list = inventory:get_list("dye")
|
||||||
|
|
||||||
|
local time = meta:get_float("time")
|
||||||
|
local output = meta:get_string("output")
|
||||||
|
|
||||||
|
-- if time is positive, this node is active.
|
||||||
|
if time >= 0 then
|
||||||
|
if time <= duration then
|
||||||
|
meta:set_float("time", time + 1)
|
||||||
|
meta:set_string("formspec", formspec.active(time))
|
||||||
|
else
|
||||||
|
meta:set_float("time", -1)
|
||||||
|
meta:set_string("output", "")
|
||||||
|
meta:set_string("formspec", formspec.inactive)
|
||||||
|
inventory:set_stack("main", 1, ItemStack(output))
|
||||||
|
|
||||||
|
swap_node(pos, nodename)
|
||||||
|
|
||||||
|
if on_deactivate ~= nil then -- call on_deactivate callback.
|
||||||
|
on_deactivate(pos)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local main_name = main_list[1]:get_name()
|
||||||
|
|
||||||
|
if main_name == empty_itemname and (not fuel_list[1]:is_empty()) and (not dye_list[1]:is_empty()) then
|
||||||
|
local output = dye_item_map[dye_list[1]:get_name()]
|
||||||
|
|
||||||
|
meta:set_string("time", 0)
|
||||||
|
meta:set_string("output", output)
|
||||||
|
|
||||||
|
local fuel_stack = fuel_list[1]
|
||||||
|
fuel_stack:take_item()
|
||||||
|
inventory:set_stack("fuel", 1, fuel_stack)
|
||||||
|
|
||||||
|
local dye_stack = dye_list[1]
|
||||||
|
dye_stack:take_item()
|
||||||
|
inventory:set_stack("dye", 1, dye_stack)
|
||||||
|
|
||||||
|
swap_node(pos, nodename .. "_active")
|
||||||
|
|
||||||
|
if on_activate ~= nil then -- call on_activate callback.
|
||||||
|
on_activate(pos, output)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true -- on_timer should return boolean value.
|
||||||
|
end
|
||||||
|
|
||||||
|
-- allow_metadata_inventory_put is a common callback.
|
||||||
|
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 dye_item_map[itemname] ~= nil then
|
||||||
|
return stack:get_count()
|
||||||
|
elseif listname == "main" and itemname == empty_itemname then
|
||||||
|
return stack:get_count()
|
||||||
|
end
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 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 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
|
||||||
|
|
||||||
|
do -- register a definition of an inactive node.
|
||||||
|
local function on_construct(pos)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
meta:set_string("formspec", formspec.inactive)
|
||||||
|
meta:set_string("output", "")
|
||||||
|
meta:set_string("time", -1)
|
||||||
|
|
||||||
|
local inventory = meta:get_inventory()
|
||||||
|
inventory:set_size("main", 1)
|
||||||
|
inventory:set_size("fuel", 1)
|
||||||
|
inventory:set_size("dye", 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function on_metadata_inventory_put(pos, listname, index, stack, player)
|
||||||
|
local timer = minetest.get_node_timer(pos)
|
||||||
|
timer:start(0.25)
|
||||||
|
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
if listname == "main" then
|
||||||
|
if on_metadata_inventory_put_to_main ~= nil then
|
||||||
|
on_metadata_inventory_put_to_main(pos) -- call on_metadata_inventory_put_to_main callback.
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function on_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)
|
||||||
|
|
||||||
|
on_metadata_inventory_put(pos, listname, to_index, stack, player)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function on_metadata_inventory_take(pos, listname, index, stack, player)
|
||||||
|
if listname == "main" then
|
||||||
|
if on_metadata_inventory_take_from_main ~= nil then
|
||||||
|
on_metadata_inventory_take_from_main(pos) -- call on_metadata_inventory_take_from_main callback.
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function allow_metadata_inventory_take(pos, listname, index, stack, player)
|
||||||
|
return stack:get_count() -- maybe add more.
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_node(nodename, {
|
||||||
|
description = description,
|
||||||
|
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.inactive,
|
||||||
|
can_dig = can_dig,
|
||||||
|
on_timer = on_timer,
|
||||||
|
on_construct = on_construct,
|
||||||
|
on_metadata_inventory_put = on_metadata_inventory_put,
|
||||||
|
on_metadata_inventory_move = on_metadata_inventory_move,
|
||||||
|
on_metadata_inventory_take = on_metadata_inventory_take,
|
||||||
|
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 inactive node.
|
||||||
|
|
||||||
|
do -- register a definition of an active node.
|
||||||
|
local function allow_metadata_inventory_take(pos, listname, index, stack, player)
|
||||||
|
if listname == "main" then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
return stack:get_count()
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_node(nodename .. "_active", {
|
||||||
|
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.active,
|
||||||
|
can_dig = can_dig,
|
||||||
|
on_timer = on_timer,
|
||||||
|
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 active node.
|
||||||
|
end
|
@ -3,12 +3,12 @@
|
|||||||
-- https://github.com/tacigar/maidroid
|
-- https://github.com/tacigar/maidroid
|
||||||
------------------------------------------------------------
|
------------------------------------------------------------
|
||||||
|
|
||||||
local dye_core_map = {
|
do -- register core writer
|
||||||
["dye:red"] = "maidroid_core:basic",
|
|
||||||
}
|
local dye_item_map = {
|
||||||
|
["dye:red"] = "maidroid_core:basic",
|
||||||
|
}
|
||||||
|
|
||||||
-- register a definition of a core writer.
|
|
||||||
;(function()
|
|
||||||
local node_box = {
|
local node_box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = {
|
fixed = {
|
||||||
@ -28,243 +28,62 @@ local dye_core_map = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
local formspec_inactive = "size[8,9]"
|
local formspec = {
|
||||||
.. default.gui_bg
|
["inactive"] = "size[8,9]"
|
||||||
.. 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]"
|
|
||||||
.. "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,6.2;8,3;8]"
|
|
||||||
|
|
||||||
local function generate_formspec_active(writing_time)
|
|
||||||
local arrow_percent = (100 / 40) * writing_time
|
|
||||||
|
|
||||||
local merter_percent = 0
|
|
||||||
if writing_time % 16 >= 8 then
|
|
||||||
meter_percent = (8 - (writing_time % 8)) * (100 / 8)
|
|
||||||
else
|
|
||||||
meter_percent = (writing_time % 8) * (100 / 8)
|
|
||||||
end
|
|
||||||
|
|
||||||
return "size[8,9]"
|
|
||||||
.. default.gui_bg
|
.. default.gui_bg
|
||||||
.. 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]"
|
||||||
.. "list[current_name;dye;4.5,2.5;1,1;]"
|
.. "list[current_name;dye;4.5,2.5;1,1;]"
|
||||||
.. "image[3.5,1.5;1,2;maidroid_tool_gui_arrow.png^[lowpart:"
|
.. "image[3.5,1.5;1,2;maidroid_tool_gui_arrow.png]"
|
||||||
.. arrow_percent
|
.. "image[3.1,3.5;2,1;maidroid_tool_gui_meter.png^[transformR270]"
|
||||||
.. ":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,5;8,1;]"
|
||||||
.. "list[current_player;main;0,6.2;8,3;8]"
|
.. "list[current_player;main;0,6.2;8,3;8]",
|
||||||
end
|
|
||||||
|
|
||||||
-- get_nearest_core_entity returns the nearest core entity.
|
["active"] = function(time)
|
||||||
local function get_nearest_core_entity(pos)
|
local arrow_percent = (100 / 40) * time
|
||||||
local all_objects = minetest.get_objects_inside_radius(pos, 1.0)
|
local merter_percent = 0
|
||||||
for _, object in ipairs(all_objects) do
|
if time % 16 >= 8 then
|
||||||
if object:get_luaentity().name == "maidroid_tool:core_entity" then
|
meter_percent = (8 - (time % 8)) * (100 / 8)
|
||||||
return object:get_luaentity()
|
else
|
||||||
|
meter_percent = (time % 8) * (100 / 8)
|
||||||
end
|
end
|
||||||
end
|
return "size[8,9]"
|
||||||
return nil
|
.. default.gui_bg
|
||||||
end
|
.. default.gui_bg_img
|
||||||
|
.. default.gui_slots
|
||||||
|
.. "label[3.75,0;Core]"
|
||||||
|
.. "list[current_name;main;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,
|
||||||
|
}
|
||||||
|
|
||||||
-- can_dig is a common callback for the core writer.
|
local tiles = {
|
||||||
local function can_dig(pos, player)
|
["inactive"] = {
|
||||||
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
|
|
||||||
|
|
||||||
-- swap_node is a helper function that swap two nodes.
|
|
||||||
local function swap_node(pos, name)
|
|
||||||
local node = minetest.get_node(pos)
|
|
||||||
node.name = name
|
|
||||||
|
|
||||||
minetest.swap_node(pos, node)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- on_timer is a common callback for the core writer.
|
|
||||||
local function on_timer(pos, elapsed)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
local inventory = meta:get_inventory()
|
|
||||||
|
|
||||||
local core_list = inventory:get_list("core")
|
|
||||||
local fuel_list = inventory:get_list("fuel")
|
|
||||||
local dye_list = inventory:get_list("dye")
|
|
||||||
|
|
||||||
local writing_time = meta:get_float("writing_time")
|
|
||||||
local writing_total_time = 40
|
|
||||||
local output_core = meta:get_string("output_core")
|
|
||||||
|
|
||||||
-- if writing time is positive, the core writer is active.
|
|
||||||
if writing_time >= 0 then
|
|
||||||
if writing_time <= writing_total_time then
|
|
||||||
meta:set_float("writing_time", writing_time + 1)
|
|
||||||
meta:set_string("formspec", generate_formspec_active(writing_time))
|
|
||||||
|
|
||||||
else -- else place output core to core list.
|
|
||||||
meta:set_float("writing_time", -1)
|
|
||||||
meta:set_string("output_core", "")
|
|
||||||
meta:set_string("formspec", formspec_inactive)
|
|
||||||
inventory:set_stack("core", 1, ItemStack(output_core))
|
|
||||||
swap_node(pos, "maidroid_tool:core_writer")
|
|
||||||
|
|
||||||
local core_entity = get_nearest_core_entity(pos)
|
|
||||||
core_entity:stop_rotate()
|
|
||||||
end
|
|
||||||
|
|
||||||
else -- else the core writer is inactive.
|
|
||||||
local core_name = core_list[1]:get_name()
|
|
||||||
|
|
||||||
if core_name == "maidroid_core:empty" and (not fuel_list[1]:is_empty()) and (not dye_list[1]:is_empty()) then
|
|
||||||
meta:set_float("writing_time", 0)
|
|
||||||
meta:set_string("output_core", dye_core_map[dye_list[1]:get_name()])
|
|
||||||
|
|
||||||
local fuel_stack = fuel_list[1]
|
|
||||||
fuel_stack:take_item()
|
|
||||||
inventory:set_stack("fuel", 1, fuel_stack)
|
|
||||||
|
|
||||||
local dye_stack = dye_list[1]
|
|
||||||
dye_stack:take_item()
|
|
||||||
inventory:set_stack("dye", 1, dye_stack)
|
|
||||||
|
|
||||||
swap_node(pos, "maidroid_tool:core_writer_active")
|
|
||||||
|
|
||||||
local core_entity = get_nearest_core_entity(pos)
|
|
||||||
core_entity:start_rotate()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
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 dye_core_map[itemname] ~= nil 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_top.png",
|
||||||
"maidroid_tool_core_writer_bottom.png",
|
"maidroid_tool_core_writer_bottom.png",
|
||||||
"maidroid_tool_core_writer_right.png",
|
"maidroid_tool_core_writer_right.png",
|
||||||
"maidroid_tool_core_writer_right.png^[transformFX",
|
"maidroid_tool_core_writer_right.png^[transformFX",
|
||||||
"maidroid_tool_core_writer_front.png^[transformFX",
|
"maidroid_tool_core_writer_front.png^[transformFX",
|
||||||
"maidroid_tool_core_writer_front.png",
|
"maidroid_tool_core_writer_front.png",
|
||||||
}
|
},
|
||||||
|
|
||||||
local function on_construct(pos)
|
["active"] = {
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
meta:set_string("formspec", formspec_inactive)
|
|
||||||
meta:set_string("output_core", "")
|
|
||||||
meta:set_float("writing_time", -1)
|
|
||||||
|
|
||||||
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_put(pos, listname, index, stack, player)
|
|
||||||
local timer = minetest.get_node_timer(pos)
|
|
||||||
timer:start(0.25)
|
|
||||||
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
if listname == "core" then
|
|
||||||
local entity_position = {
|
|
||||||
x = pos.x, y = pos.y + 0.65, z = pos.z
|
|
||||||
}
|
|
||||||
minetest.add_entity(entity_position, "maidroid_tool:core_entity")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function on_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)
|
|
||||||
|
|
||||||
on_metadata_inventory_put(pos, listname, to_index, stack, player)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function on_metadata_inventory_take(pos, listname, index, stack, player)
|
|
||||||
if listname == "core" then
|
|
||||||
local core_entity = get_nearest_core_entity(pos)
|
|
||||||
core_entity.object:remove()
|
|
||||||
end
|
|
||||||
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_timer = on_timer,
|
|
||||||
on_construct = on_construct,
|
|
||||||
on_metadata_inventory_put = on_metadata_inventory_put,
|
|
||||||
on_metadata_inventory_move = on_metadata_inventory_move,
|
|
||||||
on_metadata_inventory_take = on_metadata_inventory_take,
|
|
||||||
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_top.png",
|
||||||
"maidroid_tool_core_writer_bottom.png",
|
"maidroid_tool_core_writer_bottom.png",
|
||||||
"maidroid_tool_core_writer_right.png",
|
"maidroid_tool_core_writer_right.png",
|
||||||
@ -291,36 +110,61 @@ local dye_core_map = {
|
|||||||
length = 1.5,
|
length = 1.5,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
|
}
|
||||||
|
|
||||||
local function allow_metadata_inventory_take(pos, listname, index, stack, player)
|
-- get_nearest_core_entity returns the nearest core entity.
|
||||||
if listname == "core" then
|
local function get_nearest_core_entity(pos)
|
||||||
return 0
|
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 stack:get_count()
|
|
||||||
end
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_node("maidroid_tool:core_writer_active", {
|
local function on_deactivate(pos)
|
||||||
drawtype = "nodebox",
|
local core_entity = get_nearest_core_entity(pos)
|
||||||
paramtype = "light",
|
core_entity:stop_rotate()
|
||||||
paramtype2 = "facedir",
|
end
|
||||||
groups = {cracky = 2},
|
|
||||||
is_ground_content = false,
|
local function on_activate(pos)
|
||||||
sounds = default.node_sound_stone_defaults(),
|
local core_entity = get_nearest_core_entity(pos)
|
||||||
node_box = node_box,
|
core_entity:start_rotate()
|
||||||
selection_box = selection_box,
|
end
|
||||||
tiles = tiles,
|
|
||||||
can_dig = can_dig,
|
local function on_metadata_inventory_put_to_main(pos)
|
||||||
on_timer = on_timer,
|
local entity_position = {
|
||||||
allow_metadata_inventory_put = allow_metadata_inventory_put,
|
x = pos.x, y = pos.y + 0.65, z = pos.z,
|
||||||
allow_metadata_inventory_move = allow_metadata_inventory_move,
|
}
|
||||||
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
minetest.add_entity(entity_position, "maidroid_tool:core_entity")
|
||||||
})
|
end
|
||||||
end) ()
|
|
||||||
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", {
|
||||||
|
description = "maidroid tool : core writer",
|
||||||
|
formspec = formspec,
|
||||||
|
tiles = tiles,
|
||||||
|
node_box = node_box,
|
||||||
|
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,
|
||||||
|
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
|
||||||
|
|
||||||
-- register a definition of a core entity.
|
-- register a definition of a core entity.
|
||||||
;(function()
|
do
|
||||||
local node_box = {
|
local node_box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = {
|
fixed = {
|
||||||
@ -351,23 +195,45 @@ end) ()
|
|||||||
|
|
||||||
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
|
||||||
|
@ -11,3 +11,12 @@ minetest.register_craft{
|
|||||||
{ "default:cobble", "default:cobble", "default:cobble"},
|
{ "default:cobble", "default:cobble", "default:cobble"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
minetest.register_craft{
|
||||||
|
output = "maidroid_tool:egg_writer",
|
||||||
|
recipe = {
|
||||||
|
{ "default:diamond", "bucket:bucket_water", "default:diamond"},
|
||||||
|
{ "default:cobble", "default:steel_ingot", "default:cobble"},
|
||||||
|
{"default:steel_ingot", "default:cobble", "default:steel_ingot"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
bucket
|
||||||
default
|
default
|
||||||
dye
|
dye
|
||||||
maidroid
|
maidroid
|
||||||
|
267
maidroid_tool/egg_writer.lua
Normal file
@ -0,0 +1,267 @@
|
|||||||
|
------------------------------------------------------------
|
||||||
|
-- Copyright (c) 2016 tacigar. All rights reserved.
|
||||||
|
-- https://github.com/tacigar/maidroid
|
||||||
|
------------------------------------------------------------
|
||||||
|
|
||||||
|
do -- register egg writer
|
||||||
|
|
||||||
|
local dye_item_map = {
|
||||||
|
["dye:red"] = "maidroid:maidroid_mk1_egg",
|
||||||
|
}
|
||||||
|
|
||||||
|
local formspec = { -- want to change.
|
||||||
|
["inactive"] = "size[8,9]"
|
||||||
|
.. default.gui_bg
|
||||||
|
.. default.gui_bg_img
|
||||||
|
.. default.gui_slots
|
||||||
|
.. "label[3.75,0;Egg]"
|
||||||
|
.. "list[current_name;main;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]"
|
||||||
|
.. "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,6.2;8,3;8]",
|
||||||
|
|
||||||
|
["active"] = function(time)
|
||||||
|
local arrow_percent = (100 / 40) * time
|
||||||
|
local merter_percent = 0
|
||||||
|
if time % 16 >= 8 then
|
||||||
|
meter_percent = (8 - (time % 8)) * (100 / 8)
|
||||||
|
else
|
||||||
|
meter_percent = (time % 8) * (100 / 8)
|
||||||
|
end
|
||||||
|
return "size[8,9]"
|
||||||
|
.. default.gui_bg
|
||||||
|
.. default.gui_bg_img
|
||||||
|
.. default.gui_slots
|
||||||
|
.. "label[3.75,0;Egg]"
|
||||||
|
.. "list[current_name;main;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 = {
|
||||||
|
["active"] = {
|
||||||
|
"maidroid_tool_egg_writer_top.png",
|
||||||
|
"maidroid_tool_egg_writer_bottom.png",
|
||||||
|
"maidroid_tool_egg_writer_right.png",
|
||||||
|
"maidroid_tool_egg_writer_right.png^[transformFX",
|
||||||
|
{
|
||||||
|
backface_culling = false,
|
||||||
|
image = "maidroid_tool_egg_writer_front_active.png^[transformFX",
|
||||||
|
|
||||||
|
animation = {
|
||||||
|
type = "vertical_frames",
|
||||||
|
aspect_w = 16,
|
||||||
|
aspect_h = 16,
|
||||||
|
length = 1.5,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
backface_culling = false,
|
||||||
|
image = "maidroid_tool_egg_writer_front_active.png",
|
||||||
|
|
||||||
|
animation = {
|
||||||
|
type = "vertical_frames",
|
||||||
|
aspect_w = 16,
|
||||||
|
aspect_h = 16,
|
||||||
|
length = 1.5,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
["inactive"] = {
|
||||||
|
"maidroid_tool_egg_writer_top.png",
|
||||||
|
"maidroid_tool_egg_writer_bottom.png",
|
||||||
|
"maidroid_tool_egg_writer_right.png",
|
||||||
|
"maidroid_tool_egg_writer_right.png^[transformFX",
|
||||||
|
"maidroid_tool_egg_writer_front.png^[transformFX",
|
||||||
|
"maidroid_tool_egg_writer_front.png",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
local node_box = {
|
||||||
|
type = "fixed",
|
||||||
|
fixed = {
|
||||||
|
{-0.4375, -0.3125, -0.4375, -0.375, 0.4375, 0.4375},
|
||||||
|
{-0.4375, -0.3125, -0.4375, 0.4375, 0.4375, -0.375},
|
||||||
|
{ 0.375, -0.3125, -0.4375, 0.4375, 0.4375, 0.4375},
|
||||||
|
{-0.4375, -0.3125, 0.375, 0.4375, 0.4375, 0.4375},
|
||||||
|
{-0.4375, -0.25, -0.375, 0.4375, 0.25, 0.375},
|
||||||
|
{ -0.5, 0, -0.5, 0.5, 0.125, 0.5},
|
||||||
|
{ -0.25, -0.5, -0.3125, 0.25, -0.3125, 0.3125},
|
||||||
|
{-0.3125, -0.5, -0.25, 0.3125, -0.3125, 0.25},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
local selection_box = {
|
||||||
|
type = "fixed",
|
||||||
|
fixed = {
|
||||||
|
{-0.4375, -0.5, -0.4375, 0.4375, 0.4375, 0.4375},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
local function get_nearest_egg_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:egg_entity" then
|
||||||
|
return object:get_luaentity()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local function on_deactivate(pos)
|
||||||
|
local egg_entity = get_nearest_egg_entity(pos)
|
||||||
|
egg_entity:stop_move()
|
||||||
|
end
|
||||||
|
|
||||||
|
local function on_activate(pos, output)
|
||||||
|
local egg_entity = get_nearest_egg_entity(pos)
|
||||||
|
egg_entity.object:set_properties{textures={"maidroid:empty_egg"}}
|
||||||
|
egg_entity:start_move(output)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function on_metadata_inventory_put_to_main(pos)
|
||||||
|
local center_position = {
|
||||||
|
x = pos.x, y = pos.y + 0.25, z = pos.z
|
||||||
|
}
|
||||||
|
local egg_entity = minetest.add_entity(center_position, "maidroid_tool:egg_entity")
|
||||||
|
local lua_entity = egg_entity:get_luaentity()
|
||||||
|
lua_entity:initialize(center_position)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function on_metadata_inventory_take_from_main(pos)
|
||||||
|
local egg_entity = get_nearest_egg_entity(pos)
|
||||||
|
egg_entity.object:remove()
|
||||||
|
end
|
||||||
|
|
||||||
|
maidroid_tool.register_writer("maidroid_tool:egg_writer", {
|
||||||
|
description = "maidroid tool : egg writer",
|
||||||
|
formspec = formspec,
|
||||||
|
tiles = tiles,
|
||||||
|
node_box = node_box,
|
||||||
|
selection_box = selection_box,
|
||||||
|
duration = 40,
|
||||||
|
on_activate = on_activate,
|
||||||
|
on_deactivate = on_deactivate,
|
||||||
|
empty_itemname = "maidroid:empty_egg",
|
||||||
|
dye_item_map = dye_item_map,
|
||||||
|
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 -- register egg writer
|
||||||
|
|
||||||
|
do -- register a definition of an egg entity
|
||||||
|
local function on_activate(self, staticdata)
|
||||||
|
self.object:set_properties{textures={"maidroid:empty_egg"}}
|
||||||
|
self.object:set_properties{automatic_rotate = 1}
|
||||||
|
|
||||||
|
if staticdata ~= "" then
|
||||||
|
local data = minetest.deserialize(staticdata)
|
||||||
|
|
||||||
|
self.is_moving = data["is_moving"]
|
||||||
|
self.center_position = data["center_position"]
|
||||||
|
self.output = data["output"]
|
||||||
|
self.current_egg = data["current_egg"]
|
||||||
|
|
||||||
|
self.object:set_properties{textures={self.current_egg}}
|
||||||
|
self:initialize(self.center_position)
|
||||||
|
|
||||||
|
if self.is_moving then
|
||||||
|
self:start_move()
|
||||||
|
end
|
||||||
|
else
|
||||||
|
self.object:set_properties{textures={"maidroid:empty_egg"}}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function start_move(self, output)
|
||||||
|
self.is_moving = true
|
||||||
|
self.output = output
|
||||||
|
end
|
||||||
|
|
||||||
|
local function stop_move(self)
|
||||||
|
self.object:set_properties{textures={self.output}}
|
||||||
|
self.is_moving = false
|
||||||
|
self.current_egg = self.output
|
||||||
|
self.output = ""
|
||||||
|
end
|
||||||
|
|
||||||
|
local function get_staticdata(self)
|
||||||
|
local data = {
|
||||||
|
["is_moving"] = self.is_moving,
|
||||||
|
["center_position"] = self.center_position,
|
||||||
|
["output"] = self.output,
|
||||||
|
["current_egg"] = self.current_egg,
|
||||||
|
}
|
||||||
|
return minetest.serialize(data)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function on_step(self, dtime)
|
||||||
|
if self.angle >= 360 then
|
||||||
|
self.angle = 0
|
||||||
|
else
|
||||||
|
self.angle = self.angle + 2
|
||||||
|
end
|
||||||
|
|
||||||
|
if self.is_moving then
|
||||||
|
local length = 0.15
|
||||||
|
local new_position = vector.add(self.center_position, {
|
||||||
|
x = length * math.cos(self.angle * math.pi / 180.0),
|
||||||
|
y = math.sin(self.angle * math.pi / 180.0) * 0.025,
|
||||||
|
z = length * math.sin(self.angle * math.pi / 180.0),
|
||||||
|
})
|
||||||
|
self.object:setpos(new_position)
|
||||||
|
else
|
||||||
|
local cur_position = self.object:getpos()
|
||||||
|
local new_position = {
|
||||||
|
x = cur_position.x,
|
||||||
|
y = self.center_position.y + math.sin(self.angle * math.pi / 180.0) * 0.025,
|
||||||
|
z = cur_position.z,
|
||||||
|
}
|
||||||
|
self.object:setpos(new_position)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function initialize(self, pos)
|
||||||
|
self.angle = 0
|
||||||
|
self.center_position = pos
|
||||||
|
local init_pos = vector.add(pos, {x = 0.15, y = 0, z = 0})
|
||||||
|
self.object:setpos(init_pos)
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_entity("maidroid_tool:egg_entity", {
|
||||||
|
hp_max = 1,
|
||||||
|
visual = "wielditem",
|
||||||
|
visual_size = {x = 0.2, y = 0.2},
|
||||||
|
collisionbox = {0, 0, 0, 0, 0, 0},
|
||||||
|
physical = false,
|
||||||
|
on_activate = on_activate,
|
||||||
|
start_move = start_move,
|
||||||
|
stop_move = stop_move,
|
||||||
|
get_staticdata = get_staticdata,
|
||||||
|
on_step = on_step,
|
||||||
|
initialize = initialize,
|
||||||
|
output = "",
|
||||||
|
current_egg = "",
|
||||||
|
center_position = nil,
|
||||||
|
is_moving = false,
|
||||||
|
angle = 0,
|
||||||
|
})
|
||||||
|
end -- register egg entity
|
@ -8,5 +8,7 @@ maidroid_tool = {}
|
|||||||
maidroid_tool.modname = "maidroid_tool"
|
maidroid_tool.modname = "maidroid_tool"
|
||||||
maidroid_tool.modpath = minetest.get_modpath(maidroid_tool.modname)
|
maidroid_tool.modpath = minetest.get_modpath(maidroid_tool.modname)
|
||||||
|
|
||||||
|
dofile(maidroid_tool.modpath .. "/api.lua")
|
||||||
dofile(maidroid_tool.modpath .. "/core_writer.lua")
|
dofile(maidroid_tool.modpath .. "/core_writer.lua")
|
||||||
|
dofile(maidroid_tool.modpath .. "/egg_writer.lua")
|
||||||
dofile(maidroid_tool.modpath .. "/crafting.lua")
|
dofile(maidroid_tool.modpath .. "/crafting.lua")
|
||||||
|
BIN
maidroid_tool/textures/maidroid_tool_egg_writer_bottom.png
Normal file
After Width: | Height: | Size: 603 B |
BIN
maidroid_tool/textures/maidroid_tool_egg_writer_bottom.xcf
Normal file
BIN
maidroid_tool/textures/maidroid_tool_egg_writer_front.png
Normal file
After Width: | Height: | Size: 650 B |
BIN
maidroid_tool/textures/maidroid_tool_egg_writer_front.xcf
Normal file
BIN
maidroid_tool/textures/maidroid_tool_egg_writer_front_active.png
Normal file
After Width: | Height: | Size: 824 B |
BIN
maidroid_tool/textures/maidroid_tool_egg_writer_front_active.xcf
Normal file
BIN
maidroid_tool/textures/maidroid_tool_egg_writer_right.png
Normal file
After Width: | Height: | Size: 637 B |
BIN
maidroid_tool/textures/maidroid_tool_egg_writer_right.xcf
Normal file
BIN
maidroid_tool/textures/maidroid_tool_egg_writer_top.png
Normal file
After Width: | Height: | Size: 728 B |