summaryrefslogtreecommitdiff
path: root/glooptest/othergen_module/init.lua
blob: 77a6e6641b86ea40e52a95f907faef2ef76f2ca3 (plain)
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
glooptest.extragen_module = {}
glooptest.extragen_module.treasure={}
glooptest.debug("MESSAGE","Loading Extragen Module Now!")

-- {item name, max stack size, item rarity}
glooptest.extragen_module.treasure[1] = {
	{"default:stick", 30, 1},
	{"default:wood", 10, 1},
	{"default:tree", 5, 2},
	{"default:jungletree", 3, 6},
	{"default:cobble", 10, 2},
	{"default:pick_wood", 1, 12},
	{"default:shovel_wood", 1, 12},
	{"default:sword_wood", 1, 12},
	{"default:axe_wood", 1, 12},
	{"default:pick_stone", 1, 24},
	{"default:shovel_stone", 1, 24},
	{"default:sword_stone", 1, 24},
	{"default:axe_stone", 1, 24},
	{"default:furnace", 1, 8},
}

glooptest.extragen_module.treasure[2] = {
	{"default:stick", 40, 1},
	{"default:cobble", 30, 1},
	{"default:glass", 20, 4},
	{"default:stone", 15, 2},
	{"default:desert_stone", 15, 5},
	{"default:coal_lump", 15, 6},
	{"default:steel_ingot", 2, 8},
	{"default:obsidian_shard", 1, 10},
	{"default:pick_stone", 1, 12},
	{"default:shovel_stone", 1, 12},
	{"default:sword_stone", 1, 12},
	{"default:axe_stone", 1, 12},
}

glooptest.extragen_module.treasure[3] = {
	{"default:cobble", 40, 1},
	{"default:stick", 20, 3},
	{"default:torch", 15, 3},
	{"default:coal_lump", 20, 4},
	{"default:iron_lump", 10, 7},
	{"default:copper_lump", 10, 7},
	{"default:obsidian_shard", 5, 24},
	{"default:mese_crystal_fragment", 3, 24},
	{"default:pick_bronze", 1, 12},
	{"default:shovel_bronze", 1, 12},
	{"default:sword_bronze", 1, 12},
	{"default:axe_bronze", 1, 12},
}

glooptest.extragen_module.treasure[4] = {
	{"default:torch", 50, 3},
	{"default:coal_lump", 30, 3},
	{"default:iron_lump", 20, 5},
	{"default:gold_lump", 5, 16},
	{"default:mese_crystal_fragment", 5, 10},
	{"default:mese_crystal", 1, 25},
	{"default:diamond", 1, 100},
	{"default:pick_mese", 1, 18},
	{"default:shovel_mese", 1, 18},
	{"default:sword_mese", 1, 18},
	{"default:axe_mese", 1, 18},
}

glooptest.extragen_module.treasure[5] = {
	{"default:torch", 70, 3},
	{"default:iron_lump", 30, 3},
	{"default:gold_lump", 8, 15},
	{"default:mese_crystal_fragment", 15, 10},
	{"default:mese_crystal", 1, 17},
	{"default:diamond", 1, 24},
	{"default:pick_mese", 1, 12},
	{"default:shovel_mese", 1, 12},
	{"default:sword_mese", 1, 12},
	{"default:axe_mese", 1, 12},
	{"default:pick_diamond", 1, 60},
	{"default:shovel_diamond", 1, 60},
	{"default:sword_diamond", 1, 60},
	{"default:axe_diamond", 1, 60},
}

local treasure_chest_formspec = 
	"size[8,9]"..
	"list[current_name;main;0,0;8,4;]"..
	"list[current_player;main;0,5;8,4;]"
	
local treasure_chest_nodebox = {
	{-7/16, -8/16, -7/16, 7/16, 6/16, 7/16},
	{-8/16, -8/16, -8/16, 8/16, -7/16, 8/16},
	{-8/16, 1/16, -8/16, 8/16, 3/16, 8/16},
}
	
local function treasure_chest_populate(rank, pos)
	for i = 1,32 do
		for _ = 1,math.random(1,2) do
			item = glooptest.extragen_module.treasure[rank][math.random(1, #glooptest.extragen_module.treasure[rank])]
			item_rarity = item[3]
			if math.random(1, item_rarity+math.random(1,3)) == 1 then
				item_name = item[1]
				item_stacksize = item[2]-math.random(0,item[2]-1)
				minetest.get_inventory({type="node",pos={x=pos.x,y=pos.y,z=pos.z}}):set_stack("main", i, ItemStack({name=item_name,count=item_stacksize}))
				break
			else
			end
		end
	end
end

function glooptest.extragen_module.register_chest_loot(rank, entry)
	if minetest.registered_items[entry[1]] ~= nil then
		table.insert(glooptest.extragen_module.treasure[rank], entry)
	end
end

glooptest.extragen_module.register_chest_loot(1, {"glooptest:handsaw_wood", 1, 12})
glooptest.extragen_module.register_chest_loot(1, {"glooptest:hammer_wood", 1, 12})
glooptest.extragen_module.register_chest_loot(1, {"glooptest:handsaw_stone", 1, 24})
glooptest.extragen_module.register_chest_loot(1, {"glooptest:hammer_stone", 1, 24})

glooptest.extragen_module.register_chest_loot(2, {"glooptest:handsaw_stone", 1, 12})
glooptest.extragen_module.register_chest_loot(2, {"glooptest:hammer_stone", 1, 12})

glooptest.extragen_module.register_chest_loot(3, {"glooptest:handsaw_bronze", 1, 12})
glooptest.extragen_module.register_chest_loot(3, {"glooptest:hammer_bronze", 1, 12})

glooptest.extragen_module.register_chest_loot(4, {"glooptest:handsaw_mese", 1, 18})
glooptest.extragen_module.register_chest_loot(4, {"glooptest:hammer_mese", 1, 18})

glooptest.extragen_module.register_chest_loot(5, {"glooptest:handsaw_mese", 1, 12})
glooptest.extragen_module.register_chest_loot(5, {"glooptest:hammer_mese", 1, 12})
glooptest.extragen_module.register_chest_loot(5, {"glooptest:handsaw_diamond", 1, 60})
glooptest.extragen_module.register_chest_loot(5, {"glooptest:hammer_diamond", 1, 60})

minetest.register_node("glooptest:treasure_chest_1", {
	description = "Treasure Chest Rank 1",
	drawtype = "nodebox",
	tiles = {"default_chest_top.png", "default_chest_top.png", "default_chest_side.png",
		"default_chest_side.png", "default_chest_side.png", "default_chest_front.png"},
	paramtype = "light",
	paramtype2 = "facedir",
	drop = "",
	groups = {choppy=2,oddly_breakable_by_hand=2},
	legacy_facedir_simple = true,
	sounds = default.node_sound_wood_defaults(),
	node_box = {
		type = "fixed",
		fixed = treasure_chest_nodebox,
	},
	on_construct = function(pos)
		local meta = minetest.get_meta(pos)
		meta:set_string("formspec",treasure_chest_formspec)
		meta:set_string("infotext", "Treasure Chest Rank I")
		local inv = meta:get_inventory()
		inv:set_size("main", 32)
		treasure_chest_populate(1, pos)
	end,
	can_dig = function(pos,player)
		local meta = minetest.get_meta(pos);
		local inv = meta:get_inventory()
		return inv:is_empty("main")
	end,
	on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
		glooptest.debug("ACTION", player:get_player_name().." moves items in R1 treasure chest at "..minetest.pos_to_string(pos)..".")
	end,
    on_metadata_inventory_put = function(pos, listname, index, stack, player)
		glooptest.debug("ACTION", player:get_player_name().." moves items in R1 treasure chest at "..minetest.pos_to_string(pos)..".")
	end,
    on_metadata_inventory_take = function(pos, listname, index, stack, player)
		glooptest.debug("ACTION", player:get_player_name().." takes items from R1 treasure chest at "..minetest.pos_to_string(pos)..".")
	end,
})

minetest.register_node("glooptest:treasure_chest_2", {
	description = "Treasure Chest Rank 2",
	drawtype = "nodebox",
	tiles = {"default_chest_top.png", "default_chest_top.png", "default_chest_side.png",
		"default_chest_side.png", "default_chest_side.png", "default_chest_front.png"},
	paramtype = "light",
	paramtype2 = "facedir",
	drop = "",
	groups = {choppy=2,oddly_breakable_by_hand=2},
	legacy_facedir_simple = true,
	sounds = default.node_sound_wood_defaults(),
	node_box = {
		type = "fixed",
		fixed = treasure_chest_nodebox,
	},
	on_construct = function(pos)
		local meta = minetest.get_meta(pos)
		meta:set_string("formspec",treasure_chest_formspec)
		meta:set_string("infotext", "Treasure Chest Rank II")
		local inv = meta:get_inventory()
		inv:set_size("main", 32)
		treasure_chest_populate(2, pos)
	end,
	can_dig = function(pos,player)
		local meta = minetest.get_meta(pos);
		local inv = meta:get_inventory()
		return inv:is_empty("main")
	end,
	on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
		glooptest.debug("ACTION", player:get_player_name().." moves items in R1 treasure chest at "..minetest.pos_to_string(pos)..".")
	end,
    on_metadata_inventory_put = function(pos, listname, index, stack, player)
		glooptest.debug("ACTION", player:get_player_name().." moves items in R1 treasure chest at "..minetest.pos_to_string(pos)..".")
	end,
    on_metadata_inventory_take = function(pos, listname, index, stack, player)
		glooptest.debug("ACTION", player:get_player_name().." takes items from R1 treasure chest at "..minetest.pos_to_string(pos)..".")
	end,
})

minetest.register_node("glooptest:treasure_chest_3", {
	description = "Treasure Chest Rank 3",
	drawtype = "nodebox",
	tiles = {"default_chest_top.png", "default_chest_top.png", "default_chest_side.png",
		"default_chest_side.png", "default_chest_side.png", "default_chest_front.png"},
	paramtype = "light",
	paramtype2 = "facedir",
	drop = "",
	groups = {choppy=2,oddly_breakable_by_hand=2},
	legacy_facedir_simple = true,
	sounds = default.node_sound_wood_defaults(),
	node_box = {
		type = "fixed",
		fixed = treasure_chest_nodebox,
	},
	on_construct = function(pos)
		local meta = minetest.get_meta(pos)
		meta:set_string("formspec",treasure_chest_formspec)
		meta:set_string("infotext", "Treasure Chest Rank III")
		local inv = meta:get_inventory()
		inv:set_size("main", 32)
		treasure_chest_populate(3, pos)
	end,
	can_dig = function(pos,player)
		local meta = minetest.get_meta(pos);
		local inv = meta:get_inventory()
		return inv:is_empty("main")
	end,
	on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
		glooptest.debug("ACTION", player:get_player_name().." moves items in R1 treasure chest at "..minetest.pos_to_string(pos)..".")
	end,
    on_metadata_inventory_put = function(pos, listname, index, stack, player)
		glooptest.debug("ACTION", player:get_player_name().." moves items in R1 treasure chest at "..minetest.pos_to_string(pos)..".")
	end,
    on_metadata_inventory_take = function(pos, listname, index, stack, player)
		glooptest.debug("ACTION", player:get_player_name().." takes items from R1 treasure chest at "..minetest.pos_to_string(pos)..".")
	end,
})

minetest.register_node("glooptest:treasure_chest_4", {
	description = "Treasure Chest Rank 4",
	drawtype = "nodebox",
	tiles = {"default_chest_top.png", "default_chest_top.png", "default_chest_side.png",
		"default_chest_side.png", "default_chest_side.png", "default_chest_front.png"},
	paramtype = "light",
	paramtype2 = "facedir",
	drop = "",
	groups = {choppy=2,oddly_breakable_by_hand=2},
	node_box = {
		type = "fixed",
		fixed = treasure_chest_nodebox,
	},
	legacy_facedir_simple = true,
	sounds = default.node_sound_wood_defaults(),
	on_construct = function(pos)
		local meta = minetest.get_meta(pos)
		meta:set_string("formspec",treasure_chest_formspec)
		meta:set_string("infotext", "Treasure Chest Rank IV")
		local inv = meta:get_inventory()
		inv:set_size("main", 32)
		treasure_chest_populate(4, pos)
	end,
	can_dig = function(pos,player)
		local meta = minetest.get_meta(pos);
		local inv = meta:get_inventory()
		return inv:is_empty("main")
	end,
	on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
		glooptest.debug("ACTION", player:get_player_name().." moves items in R1 treasure chest at "..minetest.pos_to_string(pos)..".")
	end,
    on_metadata_inventory_put = function(pos, listname, index, stack, player)
		glooptest.debug("ACTION", player:get_player_name().." moves items in R1 treasure chest at "..minetest.pos_to_string(pos)..".")
	end,
    on_metadata_inventory_take = function(pos, listname, index, stack, player)
		glooptest.debug("ACTION", player:get_player_name().." takes items from R1 treasure chest at "..minetest.pos_to_string(pos)..".")
	end,
})

minetest.register_node("glooptest:treasure_chest_5", {
	description = "Treasure Chest Rank 5",
	drawtype = "nodebox",
	tiles = {"default_chest_top.png", "default_chest_top.png", "default_chest_side.png",
		"default_chest_side.png", "default_chest_side.png", "default_chest_front.png"},
	paramtype = "light",
	paramtype2 = "facedir",
	drop = "",
	groups = {choppy=2,oddly_breakable_by_hand=2},
	legacy_facedir_simple = true,
	sounds = default.node_sound_wood_defaults(),
	node_box = {
		type = "fixed",
		fixed = treasure_chest_nodebox,
	},
	on_construct = function(pos)
		local meta = minetest.get_meta(pos)
		meta:set_string("formspec",treasure_chest_formspec)
		meta:set_string("infotext", "Treasure Chest Rank V")
		local inv = meta:get_inventory()
		inv:set_size("main", 32)
		treasure_chest_populate(5, pos)
	end,
	can_dig = function(pos,player)
		local meta = minetest.get_meta(pos);
		local inv = meta:get_inventory()
		return inv:is_empty("main")
	end,
	on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
		glooptest.debug("ACTION", player:get_player_name().." moves items in R1 treasure chest at "..minetest.pos_to_string(pos)..".")
	end,
    on_metadata_inventory_put = function(pos, listname, index, stack, player)
		glooptest.debug("ACTION", player:get_player_name().." moves items in R1 treasure chest at "..minetest.pos_to_string(pos)..".")
	end,
    on_metadata_inventory_take = function(pos, listname, index, stack, player)
		glooptest.debug("ACTION", player:get_player_name().." takes items from R1 treasure chest at "..minetest.pos_to_string(pos)..".")
	end,
})

minetest.register_on_generated(function(minp, maxp)
	coords = {}
	coords.x = {}
	coords.y = {}
	coords.z = {}
	for i = minp.x,maxp.x do
		table.insert(coords.x, i)
	end
	for i = minp.y,maxp.y do
		table.insert(coords.y, i)
	end
	for i = minp.z,maxp.z do
		table.insert(coords.z, i)
	end
	for x = 1,#coords.x do
	for y = 1,#coords.y do
	for z = 1,#coords.z do
		if minetest.get_node({x=coords.x[x],y=coords.y[y]+1,z=coords.z[z]}).name == "air" and minetest.get_node({x=coords.x[x],y=coords.y[y],z=coords.z[z]}).name ~= "air" and minetest.registered_nodes[minetest.get_node({x=coords.x[x],y=coords.y[y],z=coords.z[z]}).name].drawtype == "normal" then
			if coords.y[y] >=0 then
				if math.random(1,5000) == 1 then
					minetest.place_node({x=coords.x[x],y=coords.y[y]+1,z=coords.z[z]}, {name="glooptest:treasure_chest_1", param2=math.random(1,4)})
				elseif math.random(1,8000) == 1 then
					minetest.place_node({x=coords.x[x],y=coords.y[y]+1,z=coords.z[z]}, {name="glooptest:treasure_chest_2", param2=math.random(1,4)})
				end
			elseif coords.y[y] <=-30 then
				if math.random(1,1000) == 1 then
					minetest.place_node({x=coords.x[x],y=coords.y[y]+1,z=coords.z[z]}, {name="glooptest:treasure_chest_3", param2=math.random(1,4)})
				elseif coords.y[y] <=-1000 then
					if math.random(1,1300) == 1 then
						minetest.place_node({x=coords.x[x],y=coords.y[y]+1,z=coords.z[z]}, {name="glooptest:treasure_chest_4", param2=math.random(1,4)})
					elseif coords.y[y] <=-2500 then
						if math.random(1,2000) == 1 then
							minetest.place_node({x=coords.x[x],y=coords.y[y]+1,z=coords.z[z]}, {name="glooptest:treasure_chest_5", param2=math.random(1,4)})
						end
					end
				end
			end
		end
	end
	end
	end
end)

--minetest.register_on_generated(glooptest.extragen_module.spawn_chests(minp, maxp))