diff options
author | tenplus1 <kinsellaja@yahoo.com> | 2015-05-29 10:25:35 +0100 |
---|---|---|
committer | tenplus1 <kinsellaja@yahoo.com> | 2015-05-29 10:25:35 +0100 |
commit | 87316b50837e82d22a7cc21b5e583f47f00b1be5 (patch) | |
tree | 4a90b10ca39953ad7d620e4226ba002e9f2d1f42 | |
parent | f438eadeb98c75252fe550ac2366b06db5022406 (diff) |
Code Tidy (thanks HybridDog)
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | extra.lua | 37 | ||||
-rw-r--r-- | gates.lua | 27 | ||||
-rw-r--r-- | leaves.lua | 18 | ||||
-rw-r--r-- | mushroom.lua | 102 | ||||
-rw-r--r-- | onion.lua | 127 | ||||
-rw-r--r-- | plantlife.lua | 61 | ||||
-rw-r--r-- | screenshot.png | bin | 1626171 -> 518795 bytes |
9 files changed, 134 insertions, 242 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..215bb37 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ ++## Generic ignorable patterns and files ++*~ ++debug.txt
\ No newline at end of file @@ -13,6 +13,7 @@ Ethereal v7 Mapgen mod for Minetest - Changed frost dirt so that it no longer freezes water (saves lag) - Torches cannot be placed next to water, otherwise they drop as items - Added latest farming redo Bean Bushes to mapgen +- Code tidy (thanks HybridDog) ### 1.15 @@ -267,12 +267,15 @@ minetest.register_tool("ethereal:light_staff", { stack_max = 1, on_use = function(itemstack, user, pointed_thing) - local pos = pointed_thing.under + if pointed_thing.type ~= "node" then + return + end - if pointed_thing.type ~= "node" then return end + local pos = pointed_thing.under + local pname = user:get_player_name() - if minetest.is_protected(pos, user:get_player_name()) then - minetest.record_protection_violation(pos, user:get_player_name()) + if minetest.is_protected(pos, pname) then + minetest.record_protection_violation(pos, pname) return end @@ -286,29 +289,29 @@ minetest.register_tool("ethereal:light_staff", { if not minetest.setting_getbool("creative_mode") then itemstack:add_wear(65535 / (USES - 1)) - end - return itemstack + end + return itemstack end, }) minetest.register_craft({ output = "ethereal:light_staff", - recipe = { - {"ethereal:illumishroom", "default:mese_crystal", "ethereal:illumishroom"}, - {"ethereal:illumishroom2", "default:steel_ingot", "ethereal:illumishroom2"}, - {"ethereal:illumishroom3", "default:steel_ingot", "ethereal:illumishroom3"} - } + recipe = { + {"ethereal:illumishroom", "default:mese_crystal", "ethereal:illumishroom"}, + {"ethereal:illumishroom2", "default:steel_ingot", "ethereal:illumishroom2"}, + {"ethereal:illumishroom3", "default:steel_ingot", "ethereal:illumishroom3"} + } }) -- Generate Illumishroom in caves next to coal -minetest.register_on_generated(function(minp, maxp, seed) - - local coal_nodes = minetest.find_nodes_in_area(minp, maxp, "default:stone_with_coal") +minetest.register_on_generated(function(minp, maxp) + if minp.y > -30 + or maxp.y < -3000 then + return + end local bpos - for key, pos in pairs(coal_nodes) do - + for key, pos in pairs(minetest.find_nodes_in_area(minp, maxp, "default:stone_with_coal")) do bpos = { x=pos.x, y=pos.y + 1, z=pos.z } - if minetest.get_node(bpos).name == "air" then if bpos.y > -3000 and bpos.y < -2000 then minetest.add_node(bpos, {name = "ethereal:illumishroom3"}) @@ -15,18 +15,20 @@ local nb_pil = { -- Open/Close Gates function gate_rightclick(pos, node) - local data = nil - data = string.split(node.name, "_", 2) - local gate = data[1].."_" - local open = data[2] - + local gate, open = unpack(string.split(node.name, "_", 2)) + local gate = gate.."_" + + local sound, name if open == "open" then - minetest.sound_play("doors_door_close", {pos=pos, gain = 0.3, max_hear_distance = 10}) - minetest.set_node(pos, {name=gate.."closed", param2=node.param2}) + sound = "close" + name = "closed" else - minetest.sound_play("doors_door_open", {pos=pos, gain = 0.3, max_hear_distance = 10}) - minetest.set_node(pos, {name=gate.."open", param2=node.param2}) + sound = "open" + name = "open" end + node.name = gate..name + minetest.set_node(pos, node) + minetest.sound_play("doors_door_"..sound, {pos=pos, gain = 0.3, max_hear_distance = 10}) end local gate = {} @@ -46,11 +48,8 @@ gate.type = { {"pine", "Pine Wood", "default_pinewood.png", "default:pinewood"}, } -for _, row in ipairs(gate.type) do - local name = row[1] - local desc = row[2] - local texture = row[3] - local nod = row[4] +for _, row in pairs(gate.type) do + local name, desc, texture, nod = unpack(row) minetest.register_node("ethereal:"..name.."gate_open", { tiles = {texture}, @@ -74,16 +74,11 @@ minetest.register_node("ethereal:redwood_leaves", { }) -- Default Apple Tree Leaves -minetest.register_node(":default:leaves", { - description = "Leaves", +minetest.override_item("default:leaves", { drawtype = leaftype, visual_scale = 1.2, - tiles = {"default_leaves.png"}, inventory_image = "default_leaves.png", - paramtype = "light", walkable = false, - waving = 1, - groups = {snappy=3, leafdecay=3, leaves=1, flammable=2}, drop = { max_items = 1, items = { @@ -91,8 +86,6 @@ minetest.register_node(":default:leaves", { { items = {"default:leaves"}} } }, - sounds = default.node_sound_leaves_defaults(), - after_place_node = default.after_place_leaves, }) -- Default Orange Tree Leaves @@ -118,16 +111,11 @@ minetest.register_node("ethereal:orange_leaves", { }) -- Default Jungle Tree Leaves -minetest.register_node(":default:jungleleaves", { - description = "Jungle Leaves", +minetest.override_item("default:jungleleaves", { drawtype = leaftype, visual_scale = 1.2, - tiles = {"default_jungleleaves.png"}, inventory_image = "default_jungleleaves.png", - paramtype = "light", walkable = false, - waving = 1, - groups = {snappy=3, leafdecay=3, leaves=1, flammable=2}, drop = { max_items = 1, items = { @@ -135,8 +123,6 @@ minetest.register_node(":default:jungleleaves", { { items = {"default:jungleleaves"}} } }, - sounds = default.node_sound_leaves_defaults(), - after_place_node = default.after_place_leaves, }) -- Default Banana Tree Leaves diff --git a/mushroom.lua b/mushroom.lua index f052b73..a09060e 100644 --- a/mushroom.lua +++ b/mushroom.lua @@ -56,7 +56,7 @@ minetest.register_craft({ })
-- Define Mushroom growth stages
-minetest.register_node("ethereal:mushroom_1", {
+local ndef = {
drawtype = "plantlike",
tiles = {"ethereal_mushroom_garden_1.png"},
paramtype = "light",
@@ -65,73 +65,32 @@ minetest.register_node("ethereal:mushroom_1", { buildable_to = true,
drop = {
items = {
- {items = {"ethereal:mushroom_craftingitem 1"},rarity=1},
- {items = {"ethereal:mushroom_plant 1"},rarity=14},
+ {items = {"ethereal:mushroom_craftingitem"},rarity=1},
+ {items = {"ethereal:mushroom_plant"},rarity=14},
}
},
selection_box = {type = "fixed",fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},},
groups = {snappy=3,flammable=2,plant=1,mushroom=1,attached_node=1,growing=1,not_in_creative_inventory=1},
sounds = default.node_sound_leaves_defaults(),
-})
-minetest.register_alias("ethereal:mushroom_garden_1", "ethereal:mushroom_1")
+}
+minetest.register_node("ethereal:mushroom_1", table.copy(ndef))
-minetest.register_node("ethereal:mushroom_2", {
- drawtype = "plantlike",
- tiles = {"ethereal_mushroom_garden_2.png"},
- paramtype = "light",
- sunlight_propagates = true,
- walkable = false,
- drop = {
- items = {
- {items = {"ethereal:mushroom_craftingitem 1"},rarity=1},
- {items = {"ethereal:mushroom_plant 1"},rarity=7},
- }
- },
- buildable_to = true,
- selection_box = {type = "fixed",fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},},
- groups = {snappy=3,flammable=2,plant=1,mushroom=2,attached_node=1,growing=1,not_in_creative_inventory=1},
- sounds = default.node_sound_leaves_defaults(),
-})
-minetest.register_alias("ethereal:mushroom_garden_2", "ethereal:mushroom_2")
+ndef.tiles[1] = "ethereal_mushroom_garden_2.png"
+ndef.drop.items[2].rarity = 7
+ndef.groups.mushroom = 2
+minetest.register_node("ethereal:mushroom_2", table.copy(ndef))
-minetest.register_node("ethereal:mushroom_3", {
- drawtype = "plantlike",
- tiles = {"ethereal_mushroom_garden_3.png"},
- paramtype = "light",
- sunlight_propagates = true,
- walkable = false,
- drop = {
- items = {
- {items = {"ethereal:mushroom_craftingitem 1"},rarity=1},
- {items = {"ethereal:mushroom_plant 3"},rarity=3},
- }
- },
- buildable_to = true,
- selection_box = {type = "fixed",fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},},
- groups = {snappy=3,flammable=2,plant=1,mushroom=3,attached_node=1,growing=1,not_in_creative_inventory=1},
- sounds = default.node_sound_leaves_defaults(),
-})
-minetest.register_alias("ethereal:mushroom_garden_3", "ethereal:mushroom_3")
+ndef.tiles[1] = "ethereal_mushroom_garden_3.png"
+ndef.drop.items[2] = {items = {"ethereal:mushroom_plant 3"},rarity=3}
+ndef.groups.mushroom = 3
+minetest.register_node("ethereal:mushroom_3", table.copy(ndef))
-minetest.register_node("ethereal:mushroom_4", {
- drawtype = "plantlike",
- tiles = {"ethereal_mushroom_garden_4.png"},
- paramtype = "light",
- sunlight_propagates = true,
- walkable = false,
- buildable_to = true,
- drop = {
- items = {
- {items = {"ethereal:mushroom_craftingitem 1"},rarity=1},
- {items = {"ethereal:mushroom_plant 3"},rarity=1},
- {items = {"ethereal:mushroom_plant 3"},rarity=7},
- }
- },
- selection_box = {type = "fixed",fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},},
- groups = {snappy=3,flammable=2,plant=1,mushroom=4,attached_node=1,not_in_creative_inventory=1},
- sounds = default.node_sound_leaves_defaults(),
-})
-minetest.register_alias("ethereal:mushroom_garden_4", "ethereal:mushroom_4")
+ndef.tiles[1] = "ethereal_mushroom_garden_4.png"
+ndef.drop.items[2].rarity = 1
+ndef.drop.items[3] = {items = {"ethereal:mushroom_plant 3"},rarity=7}
+ndef.groups.mushroom = 4
+ndef.groups.growing = nil
+minetest.register_node("ethereal:mushroom_4", table.copy(ndef))
-- Abm for growing Mushroom
if farming.mod ~= "redo" then
@@ -143,34 +102,39 @@ minetest.register_abm({ chance = 2,
action = function(pos, node)
-- return if already full grown
- if minetest.get_item_group(node.name, "mushroom") == 4 then
+ if minetest.get_item_group(node.name, "growing") < 1 then
return
end
-- check if on wet soil
pos.y = pos.y-1
- local n = minetest.get_node(pos)
- if minetest.get_item_group(n.name, "soil") < 3 then
+ if minetest.get_item_group(minetest.get_node(pos).name, "soil") < 3 then
return
end
pos.y = pos.y+1
-- check light
- if not minetest.get_node_light(pos) then
- return
- end
- if minetest.get_node_light(pos) < 5 then
+ local light = minetest.get_node_light(pos)
+ if not light
+ or light < 5 then
return
end
-- grow
- local height = minetest.get_item_group(node.name, "mushroom") + 1
- minetest.set_node(pos, {name="ethereal:mushroom_garden_"..height})
+ node.name = "ethereal:mushroom_garden_" .. minetest.get_item_group(node.name, "mushroom") + 1
+ minetest.set_node(pos, node)
end
})
end
+
+-- legacy
+
+for i = 1,4 do
+ minetest.register_alias("ethereal:mushroom_garden_"..i, "ethereal:mushroom_"..i)
+end
+
-- Temporary compatibility lines for Xanadu server
minetest.register_alias("ethereal:mushroom_7", "ethereal:mushroom_3")
minetest.register_alias("ethereal:mushroom_8", "ethereal:mushroom_4")
@@ -11,7 +11,7 @@ minetest.register_craftitem("ethereal:wild_onion_plant", { minetest.register_alias("ethereal:wild_onion_craftingitem", "ethereal:wild_onion_plant")
-- Define Onion growth stages
-minetest.register_node("ethereal:onion_1", {
+local onion_def = {
drawtype = "plantlike",
tiles = {"ethereal_wild_onion_1.png"},
paramtype = "light",
@@ -20,90 +20,41 @@ minetest.register_node("ethereal:onion_1", { buildable_to = true,
drop = {
items = {
- {items = {"ethereal:wild_onion_plant 1"},rarity=1},
+ {items = {"ethereal:wild_onion_plant"},rarity=1},
}
},
selection_box = {type = "fixed",fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},},
groups = {snappy=3,flammable=2,plant=1,attached_node=1,onion=1,growing=1,not_in_creative_inventory=1},
sounds = default.node_sound_leaves_defaults(),
-})
-minetest.register_alias("ethereal:wild_onion_1", "ethereal:onion_1")
+}
+minetest.register_node("ethereal:onion_1", table.copy(onion_def))
-minetest.register_node("ethereal:onion_2", {
- drawtype = "plantlike",
- tiles = {"ethereal_wild_onion_2.png"},
- paramtype = "light",
- sunlight_propagates = true,
- walkable = false,
- buildable_to = true,
- drop = {
- items = {
- {items = {"ethereal:wild_onion_plant 1"},rarity=1},
- }
- },
- selection_box = {type = "fixed",fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},},
- groups = {snappy=3,flammable=2,plant=1,attached_node=1,onion=2,growing=1,not_in_creative_inventory=1},
- sounds = default.node_sound_leaves_defaults(),
-})
-minetest.register_alias("ethereal:wild_onion_2", "ethereal:onion_2")
+onion_def.tiles[1] = "ethereal_wild_onion_2.png"
+onion_def.groups.onion = 2
+minetest.register_node("ethereal:onion_2", table.copy(onion_def))
-minetest.register_node("ethereal:onion_3", {
- drawtype = "plantlike",
- tiles = {"ethereal_wild_onion_3.png"},
- paramtype = "light",
- sunlight_propagates = true,
- walkable = false,
- buildable_to = true,
- is_ground_content = true,
- drop = {
- items = {
- {items = {"ethereal:wild_onion_plant 1"},rarity=1},
- {items = {"ethereal:wild_onion_plant 2"},rarity=3},
- }
- },
- selection_box = {type = "fixed",fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},},
- groups = {snappy=3,flammable=2,plant=1,attached_node=1,onion=3,growing=1,not_in_creative_inventory=1},
- sounds = default.node_sound_leaves_defaults(),
-})
-minetest.register_alias("ethereal:wild_onion_3", "ethereal:onion_3")
+onion_def.tiles[1] = "ethereal_wild_onion_3.png"
+onion_def.groups.onion = 3
+onion_def.drop.items[2] = {
+ items = {"ethereal:wild_onion_plant 2"}, rarity=3
+}
+minetest.register_node("ethereal:onion_3", table.copy(onion_def))
-minetest.register_node("ethereal:onion_4", {
- drawtype = "plantlike",
- tiles = {"ethereal_wild_onion_4.png"},
- paramtype = "light",
- sunlight_propagates = true,
- walkable = false,
- buildable_to = true,
- drop = {
- items = {
- {items = {"ethereal:wild_onion_plant 1"},rarity=1},
- {items = {"ethereal:wild_onion_plant 3"},rarity=3},
- }
- },
- selection_box = {type = "fixed",fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},},
- groups = {snappy=3,flammable=2,plant=1,attached_node=1,onion=4,growing=1,not_in_creative_inventory=1},
- sounds = default.node_sound_leaves_defaults(),
-})
-minetest.register_alias("ethereal:wild_onion_4", "ethereal:onion_4")
+onion_def.tiles[1] = "ethereal_wild_onion_4.png"
+onion_def.groups.onion = 4
+onion_def.drop.items[2] = {
+ items = {"ethereal:wild_onion_plant 3"}, rarity=3
+}
+minetest.register_node("ethereal:onion_4", table.copy(onion_def))
-minetest.register_node("ethereal:onion_5", {
- drawtype = "plantlike",
- tiles = {"ethereal_wild_onion_5.png"},
- paramtype = "light",
- sunlight_propagates = true,
- walkable = false,
- buildable_to = true,
- drop = {
- items = {
- {items = {"ethereal:wild_onion_plant 2"},rarity=1},
- {items = {"ethereal:wild_onion_plant 3"},rarity=2},
- }
- },
- selection_box = {type = "fixed",fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},},
- groups = {snappy=3,flammable=2,plant=1,attached_node=1,onion=5,not_in_creative_inventory=1},
- sounds = default.node_sound_leaves_defaults(),
-})
-minetest.register_alias("ethereal:wild_onion_5", "ethereal:onion_5")
+onion_def.tiles[1] = "ethereal_wild_onion_5.png"
+onion_def.groups.onion = 5
+onion_def.groups.growing = nil
+onion_def.drop.items = {
+ {items = {"ethereal:wild_onion_plant 2"},rarity=1},
+ {items = {"ethereal:wild_onion_plant 3"},rarity=2},
+}
+minetest.register_node("ethereal:onion_5", table.copy(onion_def))
-- Abm for growing Wild Onion
if farming.mod ~= "redo" then
@@ -115,34 +66,40 @@ minetest.register_abm({ chance = 3,
action = function(pos, node)
-- return if already full grown
- if minetest.get_item_group(node.name, "onion") == 5 then
+ if minetest.get_item_group(node.name, "growing") < 1 then
return
end
-- check if on wet soil
pos.y = pos.y-1
- local n = minetest.get_node(pos)
- if minetest.get_item_group(n.name, "soil") < 3 then
+ if minetest.get_item_group(minetest.get_node(pos).name, "soil") < 3 then
return
end
pos.y = pos.y+1
-- check light
- if not minetest.get_node_light(pos) then
- return
- end
- if minetest.get_node_light(pos) < 13 then
+ local light = minetest.get_node_light(pos)
+ if not light
+ or light < 13 then
return
end
-- grow
- local height = minetest.get_item_group(node.name, "onion") + 1
- minetest.set_node(pos, {name="ethereal:wild_onion_"..height})
+ node.name = "ethereal:onion_" .. minetest.get_item_group(node.name, "onion") + 1
+ minetest.set_node(pos, node)
end
})
end
+
+-- Legacy
+
+minetest.register_alias("ethereal:wild_onion_craftingitem", "ethereal:wild_onion_plant")
+for i = 1,5 do
+ minetest.register_alias("ethereal:wild_onion_"..i, "ethereal:onion_"..i)
+end
+
-- Temporary compatibility lines for Xanadu server
minetest.register_alias("ethereal:onion_7", "ethereal:onion_4")
minetest.register_alias("ethereal:onion_8", "ethereal:onion_5")
diff --git a/plantlife.lua b/plantlife.lua index df700e8..e01244d 100644 --- a/plantlife.lua +++ b/plantlife.lua @@ -138,7 +138,7 @@ minetest.register_node("ethereal:banana", { groups = {fleshy=3,dig_immediate=3,flammable=2,leafdecay=1,leafdecay_drop=1}, on_use = minetest.item_eat(2), sounds = default.node_sound_leaves_defaults(), - after_place_node = function(pos, placer, itemstack) + after_place_node = function(pos, placer) if placer:is_player() then minetest.set_node(pos, {name="ethereal:banana", param2=1}) end @@ -181,7 +181,7 @@ minetest.register_node("ethereal:orange", { groups = {fleshy=3,dig_immediate=3,flammable=2,leafdecay=3,leafdecay_drop=1}, on_use = minetest.item_eat(4), sounds = default.node_sound_leaves_defaults(), - after_place_node = function(pos, placer, itemstack) + after_place_node = function(pos, placer) if placer:is_player() then minetest.set_node(pos, {name="ethereal:orange", param2=1}) end @@ -398,45 +398,24 @@ minetest.register_craft({ } }) --- Gravel (5x cobble in X pattern gives 5 gravel) -minetest.register_craft({ - output = "default:gravel 5", - recipe = { - {"default:cobble", "", "default:cobble"}, - {"", "default:cobble", ""}, - {"default:cobble", "", "default:cobble"}, - } -}) - --- Dirt (5x gravel in X pattern gives 5 dirt) -minetest.register_craft({ - output = "default:dirt 5", - recipe = { - {"default:gravel", "", "default:gravel"}, - {"", "default:gravel", ""}, - {"default:gravel", "", "default:gravel"}, - } -}) - --- Sand (5x dirt in X pattern gives 5 sand) -minetest.register_craft({ - output = "default:sand 5", - recipe = { - {"default:dirt", "", "default:dirt"}, - {"", "default:dirt", ""}, - {"default:dirt", "", "default:dirt"}, - } -}) - --- Snow (5x ice in X pattern gives 5 snow) -minetest.register_craft({ - output = "default:snow 5", - recipe = { - {"default:ice", "", "default:ice"}, - {"", "default:ice", ""}, - {"default:ice", "", "default:ice"}, - } -}) +-- X pattern craft recipes (5x a in X pattern gives 5 b) +for _,items in pairs({ + {"cobble", "gravel"}, + {"gravel", "dirt"}, + {"dirt", "sand"}, + {"ice", "snow"}, +}) do + local a,b = unpack(items) + a = "default:"..a + minetest.register_craft({ + output = "default:"..b.." 5", + recipe = { + {a, "", a}, + {"", a, ""}, + {a, "", a}, + } + }) +end -- Paper (2x3 string = 4 paper) minetest.register_craft({ diff --git a/screenshot.png b/screenshot.png Binary files differindex d94885c..9f405be 100644 --- a/screenshot.png +++ b/screenshot.png |