Browse code

update walking_light from emorrp1/any_tool

Phil Morrell authored on 2018-09-06 09:06:01
Showing 3 changed files
... ...
@@ -17,7 +17,7 @@ walking_light = {}
17 17
 
18 18
 -- list of items that use walking light
19 19
 local light_items = {
20
-	"default:torch", "walking_light:pick_mese",
20
+	"default:torch",
21 21
 	"walking_light:helmet_diamond", "walking_light:megatorch"
22 22
 }
23 23
 
... ...
@@ -36,6 +36,25 @@ function walking_light.getLightItems()
36 36
 	return light_items
37 37
 end
38 38
 
39
+function walking_light.register_tool(tool)
40
+	item = 'walking_light:' .. tool .. '_mese'
41
+	default = 'default:' .. tool .. '_mese'
42
+
43
+	definition = table.copy(minetest.registered_items[default])
44
+	definition.description = definition.description .. ' with light'
45
+	definition.inventory_image = 'walking_light_mese' .. tool .. '.png'
46
+
47
+	minetest.register_tool(item, definition)
48
+	minetest.register_craft({
49
+		output = item,
50
+		recipe = {
51
+			{'default:torch'},
52
+			{ default },
53
+		}
54
+	})
55
+
56
+	walking_light.addLightItem(item)
57
+end
39 58
 
40 59
 -- from http://lua-users.org/wiki/IteratorsTutorial
41 60
 -- useful for removing things from a table because removing from the middle makes it skip elements otherwise
... ...
@@ -523,20 +542,7 @@ function update_walking_light_node()
523 542
 end
524 543
 update_walking_light_node()
525 544
 
526
-minetest.register_tool("walking_light:pick_mese", {
527
-	description = "Mese Pickaxe with light",
528
-	inventory_image = "walking_light_mesepick.png",
529
-	wield_image = "default_tool_mesepick.png",
530
-	tool_capabilities = {
531
-		full_punch_interval = 1.0,
532
-		max_drop_level=3,
533
-		groupcaps={
534
-			cracky={times={[1]=2.0, [2]=1.0, [3]=0.5}, uses=20, maxlevel=3},
535
-			crumbly={times={[1]=2.0, [2]=1.0, [3]=0.5}, uses=20, maxlevel=3},
536
-			snappy={times={[1]=2.0, [2]=1.0, [3]=0.5}, uses=20, maxlevel=3}
537
-		}
538
-	},
539
-})
545
+walking_light.register_tool('pick')
540 546
 
541 547
 minetest.register_tool("walking_light:helmet_diamond", {
542 548
 	description = "Diamond Helmet with light",
... ...
@@ -597,14 +603,6 @@ minetest.register_node("walking_light:megatorch", {
597 603
     --sounds = default.node_sound_defaults(),
598 604
 })
599 605
 
600
-minetest.register_craft({
601
-	output = 'walking_light:pick_mese',
602
-	recipe = {
603
-		{'default:torch'},
604
-		{'default:pick_mese'},
605
-	}
606
-})
607
-
608 606
 minetest.register_craft({
609 607
 	output = 'walking_light:helmet_diamond',
610 608
 	recipe = {
611 609
new file mode 100644
... ...
@@ -0,0 +1 @@
1
+default
... ...
@@ -17,7 +17,7 @@ walking_light = {}
17 17
 
18 18
 -- list of items that use walking light
19 19
 local light_items = {
20
-	"default:torch", "walking_light:pick_mese",
20
+	"default:torch",
21 21
 	"walking_light:helmet_diamond", "walking_light:megatorch"
22 22
 }
23 23
 
... ...
@@ -36,6 +36,25 @@ function walking_light.getLightItems()
36 36
 	return light_items
37 37
 end
38 38
 
39
+function walking_light.register_tool(tool)
40
+	item = 'walking_light:' .. tool .. '_mese'
41
+	default = 'default:' .. tool .. '_mese'
42
+
43
+	definition = table.copy(minetest.registered_items[default])
44
+	definition.description = definition.description .. ' with light'
45
+	definition.inventory_image = 'walking_light_mese' .. tool .. '.png'
46
+
47
+	minetest.register_tool(item, definition)
48
+	minetest.register_craft({
49
+		output = item,
50
+		recipe = {
51
+			{'default:torch'},
52
+			{ default },
53
+		}
54
+	})
55
+
56
+	walking_light.addLightItem(item)
57
+end
39 58
 
40 59
 -- from http://lua-users.org/wiki/IteratorsTutorial
41 60
 -- useful for removing things from a table because removing from the middle makes it skip elements otherwise
... ...
@@ -523,20 +542,7 @@ function update_walking_light_node()
523 542
 end
524 543
 update_walking_light_node()
525 544
 
526
-minetest.register_tool("walking_light:pick_mese", {
527
-	description = "Mese Pickaxe with light",
528
-	inventory_image = "walking_light_mesepick.png",
529
-	wield_image = "default_tool_mesepick.png",
530
-	tool_capabilities = {
531
-		full_punch_interval = 1.0,
532
-		max_drop_level=3,
533
-		groupcaps={
534
-			cracky={times={[1]=2.0, [2]=1.0, [3]=0.5}, uses=20, maxlevel=3},
535
-			crumbly={times={[1]=2.0, [2]=1.0, [3]=0.5}, uses=20, maxlevel=3},
536
-			snappy={times={[1]=2.0, [2]=1.0, [3]=0.5}, uses=20, maxlevel=3}
537
-		}
538
-	},
539
-})
545
+walking_light.register_tool('pick')
540 546
 
541 547
 minetest.register_tool("walking_light:helmet_diamond", {
542 548
 	description = "Diamond Helmet with light",
... ...
@@ -597,14 +603,6 @@ minetest.register_node("walking_light:megatorch", {
597 603
     --sounds = default.node_sound_defaults(),
598 604
 })
599 605
 
600
-minetest.register_craft({
601
-	output = 'walking_light:pick_mese',
602
-	recipe = {
603
-		{'default:torch'},
604
-		{'default:pick_mese'},
605
-	}
606
-})
607
-
608 606
 minetest.register_craft({
609 607
 	output = 'walking_light:helmet_diamond',
610 608
 	recipe = {