This repository has been archived by the owner on Aug 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathitems.lua
141 lines (132 loc) · 3.89 KB
/
items.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
--more things to craft soon...
local craft_ingreds = {
mossycobble = "default:mossycobble",
}
for name, mat in pairs(craft_ingreds) do
minetest.register_craft({
output = "goblins:pick_".. name,
recipe = {
{mat, mat, mat},
{"", "group:stick", ""},
{"", "group:stick", ""}
}
})
end
minetest.register_tool("goblins:pick_mossycobble", {
description = "Mossycobble Pickaxe",
inventory_image = "default_tool_stonepick.png",
tool_capabilities = {
full_punch_interval = 1.2,
max_drop_level=0,
groupcaps={
cracky = {times={[2]=1.8, [3]=0.90}, uses=25, maxlevel=1},
},
damage_groups = {fleshy=3},
},
sound = {breaks = "default_tool_breaks"},
groups = {pickaxe = 1}
})
local goblin_tool = {}
goblin_tool = {
initial_properties = {
--physical = true,
pointable = false,
collisionbox = {0,0,0,0,0,0},
visual = "wielditem",
visual_size = {x = 0.15, y = 0.15},
wield_item = "default:stick",
},
message = "Default message",
on_step = function(self)
if not self.owner or not self.owner:get_luaentity() then
self.object:remove()
else
if self.owner:get_luaentity().current_tool ~= self.tool_name then
--print("removing old tool: "..self.tool_name.." for "..self.owner:get_luaentity().current_tool)
self.object:set_detach()
self.object:remove()
end
end
end
}
local function tool_check(tool)
if not minetest.registered_entities[tool] and
not minetest.registered_tools[tool] and
not minetest.registered_items[tool] and
not minetest.registered_craftitems[tool] and
not minetest.registered_nodes[tool] then
return
else
return true
end
end
local function tool_gen_engine(tool)
local tool_table = string.split(tool,":")
local tool_string = tool_table[1].."_"..tool_table[2]
--print("tool string 1: "..tool_string)
local gen_tool = table.copy(goblin_tool)
gen_tool.initial_properties.wield_item = tool
--print("goblin tool "..dump(goblin_tool))
--tool_string = "default_stick"
local ent_name = "goblins:goblin_tool_"..tool_string
--print("trying "..ent_name )
if not minetest.registered_entities[ent_name] then
minetest.register_entity(ent_name,gen_tool)
-- print("registered "..ent_name )
else
-- print("*** goblin tool: "..ent_name.." already registered! ***")
end
--return tool_string
end
function goblins.tool_gen(tool)
-- if not tool_check(tool) then
-- tool = "default:stick"
-- end
if type(tool) == "table" then
for k,v in pairs(tool) do
tool_gen_engine(v)
end
else
tool_gen_engine(tool)
end
end
local function tool_attach_engine(self,tool)
local tool_table = string.split(tool,":")
local tool_string = tool_table[1].."_"..tool_table[2]
--print("tool string 2: "..tool_string)
--print("testing attach: "..dump(tool_gen(tool)))
local tool_name = "goblins:goblin_tool_"..tool_string
--..tool_gen(tool)
--print("tool name:"..tool_name)
local item = minetest.add_entity(self.object:get_pos(), tool_name)
item:set_attach(self.object, "Arm_Right", {x=0.15, y=2.0, z=1.75}, {x=-90, y=180, z=90})
--print(dump(self.goblin_tools))
item:get_luaentity().owner = self.object
self.current_tool = tool
item:get_luaentity().tool_name = tool
end
local function wrandom(wtable)
local chance = #wtable
for _,__ in pairs(wtable) do
local test = chance * math.random(chance)
if chance == math.random(test) then
return wtable[chance]
else chance = chance - 1
end
end
end
function goblins.tool_attach(self,tool)
--print(dump(tool))
-- if not tool_check(tool) then
-- tool = "default:stick"
-- end
if type(tool) == "table" then
local rnd_tool = wrandom(tool)
-- print("attaching "..rnd_tool)
-- local rnd_tool = tool[math.random(1,#tool)]
tool_attach_engine(self,rnd_tool)
--print("attaching "..rnd_tool)
else
tool_attach_engine(self,tool)
end
end