From 9dbdf72c216a0d2aa9e8ce41c16ab5b8babd36c8 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sun, 5 Jan 2014 19:03:54 +0000 Subject: [PATCH] Update mods from minetest_game --- mods/bucket/init.lua | 79 +++++-- mods/creative/init.lua | 20 +- mods/default/crafting.lua | 100 ++++----- mods/default/craftitems.lua | 1 + mods/default/functions.lua | 52 +++++ mods/default/init.lua | 1 + mods/default/mapgen.lua | 6 +- mods/default/nodes.lua | 99 +++++++-- mods/default/player.lua | 267 ++++++++++++++--------- mods/default/tools.lua | 2 +- mods/default/trees.lua | 150 +++++++++++++ mods/doors/init.lua | 8 +- mods/farming/init.lua | 33 +-- mods/give_initial_stuff/init.lua | 4 +- mods/screwdriver/depends.txt | 1 - mods/screwdriver/init.lua | 352 +++++++++++++------------------ mods/stairs/init.lua | 142 +++++++------ 17 files changed, 828 insertions(+), 489 deletions(-) create mode 100644 mods/default/trees.lua delete mode 100644 mods/screwdriver/depends.txt diff --git a/mods/bucket/init.lua b/mods/bucket/init.lua index c3f20b3..eeff992 100644 --- a/mods/bucket/init.lua +++ b/mods/bucket/init.lua @@ -18,6 +18,19 @@ minetest.register_craft({ bucket = {} bucket.liquids = {} +local function check_protection(pos, name, text) + if minetest.is_protected(pos, name) then + minetest.log("action", (name ~= "" and name or "A mod") + .. " tried to " .. text + .. " at protected position " + .. minetest.pos_to_string(pos) + .. " with a bucket") + minetest.record_protection_violation(pos, name) + return true + end + return false +end + -- Register a new liquid -- source = name of the source node -- flowing = name of the flowing node @@ -45,18 +58,30 @@ function bucket.register_liquid(source, flowing, itemname, inventory_image, name return end + local node = minetest.get_node_or_nil(pointed_thing.under) + local ndef + if node then + ndef = minetest.registered_nodes[node.name] + end -- Call on_rightclick if the pointed node defines it - if user and not user:get_player_control().sneak then - local n = minetest.get_node(pointed_thing.under) - local nn = n.name - if minetest.registered_nodes[nn] and minetest.registered_nodes[nn].on_rightclick then - return minetest.registered_nodes[nn].on_rightclick(pointed_thing.under, n, user, itemstack) or itemstack - end + if ndef and ndef.on_rightclick and + user and not user:get_player_control().sneak then + return ndef.on_rightclick( + pointed_thing.under, + node, user, + itemstack) or itemstack end local place_liquid = function(pos, node, source, flowing, fullness) - if math.floor(fullness/128) == 1 or (not minetest.setting_getbool("liquid_finite")) then - minetest.add_node(pos, {name=source, param2=fullness}) + if check_protection(pos, + user and user:get_player_name() or "", + "place "..source) then + return + end + if math.floor(fullness/128) == 1 or + not minetest.setting_getbool("liquid_finite") then + minetest.add_node(pos, {name=source, + param2=fullness}) return elseif node.name == flowing then fullness = fullness + node.param2 @@ -65,26 +90,30 @@ function bucket.register_liquid(source, flowing, itemname, inventory_image, name end if fullness >= LIQUID_MAX then - minetest.add_node(pos, {name=source, param2=LIQUID_MAX}) + minetest.add_node(pos, {name=source, + param2=LIQUID_MAX}) else - minetest.add_node(pos, {name=flowing, param2=fullness}) + minetest.add_node(pos, {name=flowing, + param2=fullness}) end end -- Check if pointing to a buildable node - local node = minetest.get_node(pointed_thing.under) local fullness = tonumber(itemstack:get_metadata()) if not fullness then fullness = LIQUID_MAX end - if minetest.registered_nodes[node.name].buildable_to then + if ndef and ndef.buildable_to then -- buildable; replace the node - place_liquid(pointed_thing.under, node, source, flowing, fullness) + place_liquid(pointed_thing.under, node, + source, flowing, fullness) else -- not buildable to; place the liquid above -- check if the node above can be replaced - local node = minetest.get_node(pointed_thing.above) - if minetest.registered_nodes[node.name].buildable_to then - place_liquid(pointed_thing.above, node, source, flowing, fullness) + local node = minetest.get_node_or_nil(pointed_thing.above) + if node and minetest.registered_nodes[node.name].buildable_to then + place_liquid(pointed_thing.above, + node, source, + flowing, fullness) else -- do not remove the bucket with the liquid return @@ -109,13 +138,23 @@ minetest.register_craftitem("bucket:bucket_empty", { -- Check if pointing to a liquid source node = minetest.get_node(pointed_thing.under) liquiddef = bucket.liquids[node.name] - if liquiddef ~= nil and liquiddef.itemname ~= nil and (node.name == liquiddef.source or - (node.name == liquiddef.flowing and minetest.setting_getbool("liquid_finite"))) then + if liquiddef ~= nil and liquiddef.itemname ~= nil and + (node.name == liquiddef.source or + (node.name == liquiddef.flowing and + minetest.setting_getbool("liquid_finite"))) then + if check_protection(pointed_thing.under, + user:get_player_name(), + "take ".. node.name) then + return + end minetest.add_node(pointed_thing.under, {name="air"}) - if node.name == liquiddef.source then node.param2 = LIQUID_MAX end - return ItemStack({name = liquiddef.itemname, metadata = tostring(node.param2)}) + if node.name == liquiddef.source then + node.param2 = LIQUID_MAX + end + return ItemStack({name = liquiddef.itemname, + metadata = tostring(node.param2)}) end end, }) diff --git a/mods/creative/init.lua b/mods/creative/init.lua index 45b7a22..fa26348 100644 --- a/mods/creative/init.lua +++ b/mods/creative/init.lua @@ -28,9 +28,10 @@ minetest.after(0, function() on_put = function(inv, listname, index, stack, player) end, on_take = function(inv, listname, index, stack, player) - print(player:get_player_name().." takes item from creative inventory; listname="..dump(listname)..", index="..dump(index)..", stack="..dump(stack)) + --print(player:get_player_name().." takes item from creative inventory; listname="..dump(listname)..", index="..dump(index)..", stack="..dump(stack)) if stack then - print("stack:get_name()="..dump(stack:get_name())..", stack:get_count()="..dump(stack:get_count())) + minetest.log("action", player:get_player_name().." takes "..dump(stack:get_name()).." from creative inventory") + --print("stack:get_name()="..dump(stack:get_name())..", stack:get_count()="..dump(stack:get_count())) end end, }) @@ -47,7 +48,7 @@ minetest.after(0, function() inv:add_item("main", ItemStack(itemstring)) end creative_inventory.creative_inventory_size = #creative_list - print("creative inventory size: "..dump(creative_inventory.creative_inventory_size)) + --print("creative inventory size: "..dump(creative_inventory.creative_inventory_size)) end) -- Create the trash field @@ -122,20 +123,21 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end) if minetest.setting_getbool("creative_mode") then - + local digtime = 0.5 minetest.register_item(":", { type = "none", wield_image = "wieldhand.png", wield_scale = {x=1,y=1,z=2.5}, + range = 10, tool_capabilities = { full_punch_interval = 0.5, max_drop_level = 3, groupcaps = { - crumbly = {times={[1]=0.5, [2]=0.5, [3]=0.5}, uses=0, maxlevel=3}, - cracky = {times={[1]=0.5, [2]=0.5, [3]=0.5}, uses=0, maxlevel=3}, - snappy = {times={[1]=0.5, [2]=0.5, [3]=0.5}, uses=0, maxlevel=3}, - choppy = {times={[1]=0.5, [2]=0.5, [3]=0.5}, uses=0, maxlevel=3}, - oddly_breakable_by_hand = {times={[1]=0.5, [2]=0.5, [3]=0.5}, uses=0, maxlevel=3}, + crumbly = {times={[1]=digtime, [2]=digtime, [3]=digtime}, uses=0, maxlevel=3}, + cracky = {times={[1]=digtime, [2]=digtime, [3]=digtime}, uses=0, maxlevel=3}, + snappy = {times={[1]=digtime, [2]=digtime, [3]=digtime}, uses=0, maxlevel=3}, + choppy = {times={[1]=digtime, [2]=digtime, [3]=digtime}, uses=0, maxlevel=3}, + oddly_breakable_by_hand = {times={[1]=digtime, [2]=digtime, [3]=digtime}, uses=0, maxlevel=3}, }, damage_groups = {fleshy = 10}, } diff --git a/mods/default/crafting.lua b/mods/default/crafting.lua index 868623f..c4f353a 100644 --- a/mods/default/crafting.lua +++ b/mods/default/crafting.lua @@ -24,8 +24,8 @@ minetest.register_craft({ minetest.register_craft({ output = 'default:fence_wood 2', recipe = { - {'default:stick', 'default:stick', 'default:stick'}, - {'default:stick', 'default:stick', 'default:stick'}, + {'group:stick', 'group:stick', 'group:stick'}, + {'group:stick', 'group:stick', 'group:stick'}, } }) @@ -34,7 +34,7 @@ minetest.register_craft({ recipe = { {'group:wood', 'group:wood', 'group:wood'}, {'group:wood', 'group:wood', 'group:wood'}, - {'', 'default:stick', ''}, + {'', 'group:stick', ''}, } }) @@ -42,7 +42,7 @@ minetest.register_craft({ output = 'default:torch 4', recipe = { {'default:coal_lump'}, - {'default:stick'}, + {'group:stick'}, } }) @@ -50,8 +50,8 @@ minetest.register_craft({ output = 'default:pick_wood', recipe = { {'group:wood', 'group:wood', 'group:wood'}, - {'', 'default:stick', ''}, - {'', 'default:stick', ''}, + {'', 'group:stick', ''}, + {'', 'group:stick', ''}, } }) @@ -59,8 +59,8 @@ minetest.register_craft({ output = 'default:pick_stone', recipe = { {'group:stone', 'group:stone', 'group:stone'}, - {'', 'default:stick', ''}, - {'', 'default:stick', ''}, + {'', 'group:stick', ''}, + {'', 'group:stick', ''}, } }) @@ -68,8 +68,8 @@ minetest.register_craft({ output = 'default:pick_steel', recipe = { {'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'}, - {'', 'default:stick', ''}, - {'', 'default:stick', ''}, + {'', 'group:stick', ''}, + {'', 'group:stick', ''}, } }) @@ -77,8 +77,8 @@ minetest.register_craft({ output = 'default:pick_bronze', recipe = { {'default:bronze_ingot', 'default:bronze_ingot', 'default:bronze_ingot'}, - {'', 'default:stick', ''}, - {'', 'default:stick', ''}, + {'', 'group:stick', ''}, + {'', 'group:stick', ''}, } }) @@ -86,8 +86,8 @@ minetest.register_craft({ output = 'default:pick_mese', recipe = { {'default:mese_crystal', 'default:mese_crystal', 'default:mese_crystal'}, - {'', 'default:stick', ''}, - {'', 'default:stick', ''}, + {'', 'group:stick', ''}, + {'', 'group:stick', ''}, } }) @@ -95,8 +95,8 @@ minetest.register_craft({ output = 'default:pick_diamond', recipe = { {'default:diamond', 'default:diamond', 'default:diamond'}, - {'', 'default:stick', ''}, - {'', 'default:stick', ''}, + {'', 'group:stick', ''}, + {'', 'group:stick', ''}, } }) @@ -104,8 +104,8 @@ minetest.register_craft({ output = 'default:shovel_wood', recipe = { {'group:wood'}, - {'default:stick'}, - {'default:stick'}, + {'group:stick'}, + {'group:stick'}, } }) @@ -113,8 +113,8 @@ minetest.register_craft({ output = 'default:shovel_stone', recipe = { {'group:stone'}, - {'default:stick'}, - {'default:stick'}, + {'group:stick'}, + {'group:stick'}, } }) @@ -122,8 +122,8 @@ minetest.register_craft({ output = 'default:shovel_steel', recipe = { {'default:steel_ingot'}, - {'default:stick'}, - {'default:stick'}, + {'group:stick'}, + {'group:stick'}, } }) @@ -131,8 +131,8 @@ minetest.register_craft({ output = 'default:shovel_bronze', recipe = { {'default:bronze_ingot'}, - {'default:stick'}, - {'default:stick'}, + {'group:stick'}, + {'group:stick'}, } }) @@ -140,8 +140,8 @@ minetest.register_craft({ output = 'default:shovel_mese', recipe = { {'default:mese_crystal'}, - {'default:stick'}, - {'default:stick'}, + {'group:stick'}, + {'group:stick'}, } }) @@ -149,8 +149,8 @@ minetest.register_craft({ output = 'default:shovel_diamond', recipe = { {'default:diamond'}, - {'default:stick'}, - {'default:stick'}, + {'group:stick'}, + {'group:stick'}, } }) @@ -158,8 +158,8 @@ minetest.register_craft({ output = 'default:axe_wood', recipe = { {'group:wood', 'group:wood'}, - {'group:wood', 'default:stick'}, - {'', 'default:stick'}, + {'group:wood', 'group:stick'}, + {'', 'group:stick'}, } }) @@ -167,8 +167,8 @@ minetest.register_craft({ output = 'default:axe_stone', recipe = { {'group:stone', 'group:stone'}, - {'group:stone', 'default:stick'}, - {'', 'default:stick'}, + {'group:stone', 'group:stick'}, + {'', 'group:stick'}, } }) @@ -176,8 +176,8 @@ minetest.register_craft({ output = 'default:axe_steel', recipe = { {'default:steel_ingot', 'default:steel_ingot'}, - {'default:steel_ingot', 'default:stick'}, - {'', 'default:stick'}, + {'default:steel_ingot', 'group:stick'}, + {'', 'group:stick'}, } }) @@ -185,8 +185,8 @@ minetest.register_craft({ output = 'default:axe_bronze', recipe = { {'default:bronze_ingot', 'default:bronze_ingot'}, - {'default:bronze_ingot', 'default:stick'}, - {'', 'default:stick'}, + {'default:bronze_ingot', 'group:stick'}, + {'', 'group:stick'}, } }) @@ -194,8 +194,8 @@ minetest.register_craft({ output = 'default:axe_mese', recipe = { {'default:mese_crystal', 'default:mese_crystal'}, - {'default:mese_crystal', 'default:stick'}, - {'', 'default:stick'}, + {'default:mese_crystal', 'group:stick'}, + {'', 'group:stick'}, } }) @@ -203,8 +203,8 @@ minetest.register_craft({ output = 'default:axe_diamond', recipe = { {'default:diamond', 'default:diamond'}, - {'default:diamond', 'default:stick'}, - {'', 'default:stick'}, + {'default:diamond', 'group:stick'}, + {'', 'group:stick'}, } }) @@ -213,7 +213,7 @@ minetest.register_craft({ recipe = { {'group:wood'}, {'group:wood'}, - {'default:stick'}, + {'group:stick'}, } }) @@ -222,7 +222,7 @@ minetest.register_craft({ recipe = { {'group:stone'}, {'group:stone'}, - {'default:stick'}, + {'group:stick'}, } }) @@ -231,7 +231,7 @@ minetest.register_craft({ recipe = { {'default:steel_ingot'}, {'default:steel_ingot'}, - {'default:stick'}, + {'group:stick'}, } }) @@ -240,7 +240,7 @@ minetest.register_craft({ recipe = { {'default:bronze_ingot'}, {'default:bronze_ingot'}, - {'default:stick'}, + {'group:stick'}, } }) @@ -249,7 +249,7 @@ minetest.register_craft({ recipe = { {'default:mese_crystal'}, {'default:mese_crystal'}, - {'default:stick'}, + {'group:stick'}, } }) @@ -258,7 +258,7 @@ minetest.register_craft({ recipe = { {'default:diamond'}, {'default:diamond'}, - {'default:stick'}, + {'group:stick'}, } }) @@ -266,7 +266,7 @@ minetest.register_craft({ output = 'default:rail 15', recipe = { {'default:steel_ingot', '', 'default:steel_ingot'}, - {'default:steel_ingot', 'default:stick', 'default:steel_ingot'}, + {'default:steel_ingot', 'group:stick', 'default:steel_ingot'}, {'default:steel_ingot', '', 'default:steel_ingot'}, } }) @@ -474,9 +474,9 @@ minetest.register_craft({ minetest.register_craft({ output = 'default:ladder', recipe = { - {'default:stick', '', 'default:stick'}, - {'default:stick', 'default:stick', 'default:stick'}, - {'default:stick', '', 'default:stick'}, + {'group:stick', '', 'group:stick'}, + {'group:stick', 'group:stick', 'group:stick'}, + {'group:stick', '', 'group:stick'}, } }) diff --git a/mods/default/craftitems.lua b/mods/default/craftitems.lua index 5826d66..2d3652e 100644 --- a/mods/default/craftitems.lua +++ b/mods/default/craftitems.lua @@ -3,6 +3,7 @@ minetest.register_craftitem("default:stick", { description = "Stick", inventory_image = "default_stick.png", + groups = {stick=1}, }) minetest.register_craftitem("default:paper", { diff --git a/mods/default/functions.lua b/mods/default/functions.lua index e62b3d6..4f5f85d 100644 --- a/mods/default/functions.lua +++ b/mods/default/functions.lua @@ -126,6 +126,57 @@ function on_punchnode(p, node) end minetest.register_on_punchnode(on_punchnode) + +-- +-- Grow trees +-- + +minetest.register_abm({ + nodenames = {"default:sapling"}, + interval = 10, + chance = 50, + action = function(pos, node) + local nu = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name + local is_soil = minetest.get_item_group(nu, "soil") + if is_soil == 0 then + return + end + + minetest.log("action", "A sapling grows into a tree at "..minetest.pos_to_string(pos)) + local vm = minetest.get_voxel_manip() + local minp, maxp = vm:read_from_map({x=pos.x-16, y=pos.y, z=pos.z-16}, {x=pos.x+16, y=pos.y+16, z=pos.z+16}) + local a = VoxelArea:new{MinEdge=minp, MaxEdge=maxp} + local data = vm:get_data() + default.grow_tree(data, a, pos, math.random(1, 4) == 1, math.random(1,100000)) + vm:set_data(data) + vm:write_to_map(data) + vm:update_map() + end +}) + +minetest.register_abm({ + nodenames = {"default:junglesapling"}, + interval = 10, + chance = 50, + action = function(pos, node) + local nu = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name + local is_soil = minetest.get_item_group(nu, "soil") + if is_soil == 0 then + return + end + + minetest.log("action", "A jungle sapling grows into a tree at "..minetest.pos_to_string(pos)) + local vm = minetest.get_voxel_manip() + local minp, maxp = vm:read_from_map({x=pos.x-16, y=pos.y-1, z=pos.z-16}, {x=pos.x+16, y=pos.y+16, z=pos.z+16}) + local a = VoxelArea:new{MinEdge=minp, MaxEdge=maxp} + local data = vm:get_data() + default.grow_jungletree(data, a, pos, math.random(1,100000)) + vm:set_data(data) + vm:write_to_map(data) + vm:update_map() + end +}) + -- -- Lavacooling -- @@ -313,3 +364,4 @@ minetest.register_abm({ end end }) + diff --git a/mods/default/init.lua b/mods/default/init.lua index 61d5e1f..968cacd 100644 --- a/mods/default/init.lua +++ b/mods/default/init.lua @@ -19,3 +19,4 @@ dofile(minetest.get_modpath("default").."/craftitems.lua") dofile(minetest.get_modpath("default").."/crafting.lua") dofile(minetest.get_modpath("default").."/mapgen.lua") dofile(minetest.get_modpath("default").."/player.lua") +dofile(minetest.get_modpath("default").."/trees.lua") diff --git a/mods/default/mapgen.lua b/mods/default/mapgen.lua index 6bde5e0..4907cf7 100644 --- a/mods/default/mapgen.lua +++ b/mods/default/mapgen.lua @@ -4,7 +4,6 @@ -- Aliases for map generator outputs -- -minetest.register_alias("mapgen_air", "air") minetest.register_alias("mapgen_stone", "default:stone") minetest.register_alias("mapgen_tree", "default:tree") minetest.register_alias("mapgen_leaves", "default:leaves") @@ -26,6 +25,7 @@ minetest.register_alias("mapgen_stone_with_iron", "default:stone_with_iron") minetest.register_alias("mapgen_mese", "default:mese") minetest.register_alias("mapgen_desert_sand", "default:desert_sand") minetest.register_alias("mapgen_desert_stone", "default:desert_stone") +minetest.register_alias("mapgen_stair_cobble", "stairs:stair_cobble") -- -- Ore generation @@ -362,7 +362,7 @@ function default.make_nyancat(pos, facedir, length) elseif facedir == 3 then tailvec.x = -1 else - print("default.make_nyancat(): Invalid facedir: "+dump(facedir)) + --print("default.make_nyancat(): Invalid facedir: "+dump(facedir)) facedir = 0 tailvec.z = 1 end @@ -371,7 +371,7 @@ function default.make_nyancat(pos, facedir, length) for i=1,length do p.x = p.x + tailvec.x p.z = p.z + tailvec.z - minetest.set_node(p, {name="default:nyancat_rainbow"}) + minetest.set_node(p, {name="default:nyancat_rainbow", param2=facedir}) end end diff --git a/mods/default/nodes.lua b/mods/default/nodes.lua index b1fd312..34b873e 100644 --- a/mods/default/nodes.lua +++ b/mods/default/nodes.lua @@ -120,7 +120,6 @@ minetest.register_node("default:dirt_with_snow", { footstep = {name="default_snow_footstep", gain=0.25}, }), }) -minetest.register_alias("dirt_with_snow", "default:dirt_with_snow") minetest.register_node("default:dirt", { description = "Dirt", @@ -130,6 +129,42 @@ minetest.register_node("default:dirt", { sounds = default.node_sound_dirt_defaults(), }) +minetest.register_abm({ + nodenames = {"default:dirt"}, + interval = 2, + chance = 200, + action = function(pos, node) + local above = {x=pos.x, y=pos.y+1, z=pos.z} + local name = minetest.get_node(above).name + local nodedef = minetest.registered_nodes[name] + if nodedef and (nodedef.sunlight_propagates or nodedef.paramtype == "light") + and nodedef.liquidtype == "none" + and (minetest.get_node_light(above) or 0) >= 13 then + if name == "default:snow" or name == "default:snowblock" then + minetest.set_node(pos, {name = "default:dirt_with_snow"}) + else + minetest.set_node(pos, {name = "default:dirt_with_grass"}) + end + end + end +}) + +minetest.register_abm({ + nodenames = {"default:dirt_with_grass"}, + interval = 2, + chance = 20, + action = function(pos, node) + local above = {x=pos.x, y=pos.y+1, z=pos.z} + local name = minetest.get_node(above).name + local nodedef = minetest.registered_nodes[name] + if name ~= "ignore" and nodedef + and not ((nodedef.sunlight_propagates or nodedef.paramtype == "light") + and nodedef.liquidtype == "none") then + minetest.set_node(pos, {name = "default:dirt"}) + end + end +}) + minetest.register_node("default:sand", { description = "Sand", tiles = {"default_sand.png"}, @@ -185,6 +220,7 @@ minetest.register_node("default:clay", { minetest.register_node("default:brick", { description = "Brick Block", tiles = {"default_brick.png"}, + is_ground_content = false, groups = {cracky=3}, sounds = default.node_sound_stone_defaults(), }) @@ -192,15 +228,21 @@ minetest.register_node("default:brick", { minetest.register_node("default:tree", { description = "Tree", tiles = {"default_tree_top.png", "default_tree_top.png", "default_tree.png"}, + paramtype2 = "facedir", + is_ground_content = false, groups = {tree=1,choppy=2,oddly_breakable_by_hand=1,flammable=2}, sounds = default.node_sound_wood_defaults(), + on_place = minetest.rotate_node }) minetest.register_node("default:jungletree", { description = "Jungle Tree", tiles = {"default_jungletree_top.png", "default_jungletree_top.png", "default_jungletree.png"}, + paramtype2 = "facedir", + is_ground_content = false, groups = {tree=1,choppy=2,oddly_breakable_by_hand=1,flammable=2}, sounds = default.node_sound_wood_defaults(), + on_place = minetest.rotate_node }) minetest.register_node("default:junglewood", { @@ -216,6 +258,8 @@ minetest.register_node("default:jungleleaves", { visual_scale = 1.3, tiles = {"default_jungleleaves.png"}, paramtype = "light", + waving = 1, + is_ground_content = false, groups = {snappy=3, leafdecay=3, flammable=2, leaves=1}, drop = { max_items = 1, @@ -251,9 +295,6 @@ minetest.register_node("default:junglesapling", { groups = {snappy=2,dig_immediate=3,flammable=2,attached_node=1}, sounds = default.node_sound_leaves_defaults(), }) --- aliases for tree growing abm in content_abm.cpp -minetest.register_alias("sapling", "default:sapling") -minetest.register_alias("junglesapling", "default:junglesapling") minetest.register_node("default:junglegrass", { description = "Jungle Grass", @@ -280,6 +321,8 @@ minetest.register_node("default:leaves", { visual_scale = 1.3, tiles = {"default_leaves.png"}, paramtype = "light", + waving = 1, + is_ground_content = false, groups = {snappy=3, leafdecay=3, flammable=2, leaves=1}, drop = { max_items = 1, @@ -302,9 +345,11 @@ minetest.register_node("default:leaves", { minetest.register_node("default:cactus", { description = "Cactus", tiles = {"default_cactus_top.png", "default_cactus_top.png", "default_cactus_side.png"}, + paramtype2 = "facedir", is_ground_content = true, groups = {snappy=1,choppy=3,flammable=2}, sounds = default.node_sound_wood_defaults(), + on_place = minetest.rotate_node }) minetest.register_node("default:papyrus", { @@ -327,6 +372,7 @@ minetest.register_node("default:papyrus", { minetest.register_node("default:bookshelf", { description = "Bookshelf", tiles = {"default_wood.png", "default_wood.png", "default_bookshelf.png"}, + is_ground_content = false, groups = {choppy=3,oddly_breakable_by_hand=2,flammable=3}, sounds = default.node_sound_wood_defaults(), }) @@ -338,6 +384,7 @@ minetest.register_node("default:glass", { inventory_image = minetest.inventorycube("default_glass.png"), paramtype = "light", sunlight_propagates = true, + is_ground_content = false, groups = {cracky=3,oddly_breakable_by_hand=3}, sounds = default.node_sound_glass_defaults(), }) @@ -349,6 +396,7 @@ minetest.register_node("default:fence_wood", { inventory_image = "default_fence.png", wield_image = "default_fence.png", paramtype = "light", + is_ground_content = false, selection_box = { type = "fixed", fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7}, @@ -365,6 +413,7 @@ minetest.register_node("default:rail", { wield_image = "default_rail.png", paramtype = "light", walkable = false, + is_ground_content = false, selection_box = { type = "fixed", -- but how to specify the dimensions for curved and sideways rails? @@ -383,6 +432,7 @@ minetest.register_node("default:ladder", { paramtype2 = "wallmounted", walkable = false, climbable = true, + is_ground_content = false, selection_box = { type = "wallmounted", --wall_top = = @@ -558,6 +608,7 @@ minetest.register_node("default:torch", { paramtype = "light", paramtype2 = "wallmounted", sunlight_propagates = true, + is_ground_content = false, walkable = false, light_source = LIGHT_MAX-1, selection_box = { @@ -580,6 +631,7 @@ minetest.register_node("default:sign_wall", { paramtype = "light", paramtype2 = "wallmounted", sunlight_propagates = true, + is_ground_content = false, walkable = false, selection_box = { type = "wallmounted", @@ -598,9 +650,13 @@ minetest.register_node("default:sign_wall", { end, on_receive_fields = function(pos, formname, fields, sender) --print("Sign at "..minetest.pos_to_string(pos).." got "..dump(fields)) + if minetest.is_protected(pos, sender:get_player_name()) then + minetest.record_protection_violation(pos, sender:get_player_name()) + return + end local meta = minetest.get_meta(pos) fields.text = fields.text or "" - print((sender:get_player_name() or "").." wrote \""..fields.text.. + minetest.log("action", (sender:get_player_name() or "").." wrote \""..fields.text.. "\" to sign at "..minetest.pos_to_string(pos)) meta:set_string("text", fields.text) meta:set_string("infotext", '"'..fields.text..'"') @@ -629,6 +685,7 @@ minetest.register_node("default:chest", { paramtype2 = "facedir", groups = {choppy=2,oddly_breakable_by_hand=2}, legacy_facedir_simple = true, + is_ground_content = false, sounds = default.node_sound_wood_defaults(), on_construct = function(pos) local meta = minetest.get_meta(pos) @@ -670,6 +727,7 @@ minetest.register_node("default:chest_locked", { paramtype2 = "facedir", groups = {choppy=2,oddly_breakable_by_hand=2}, legacy_facedir_simple = true, + is_ground_content = false, sounds = default.node_sound_wood_defaults(), after_place_node = function(pos, placer) local meta = minetest.get_meta(pos) @@ -773,6 +831,7 @@ minetest.register_node("default:furnace", { paramtype2 = "facedir", groups = {cracky=2}, legacy_facedir_simple = true, + is_ground_content = false, sounds = default.node_sound_stone_defaults(), on_construct = function(pos) local meta = minetest.get_meta(pos) @@ -843,6 +902,7 @@ minetest.register_node("default:furnace_active", { drop = "default:furnace", groups = {cracky=2, not_in_creative_inventory=1,hot=1}, legacy_facedir_simple = true, + is_ground_content = false, sounds = default.node_sound_stone_defaults(), on_construct = function(pos) local meta = minetest.get_meta(pos) @@ -904,18 +964,13 @@ minetest.register_node("default:furnace_active", { end, }) -function hacky_swap_node(pos,name) +local function swap_node(pos,name) local node = minetest.get_node(pos) - local meta = minetest.get_meta(pos) - local meta0 = meta:to_table() if node.name == name then return end node.name = name - local meta0 = meta:to_table() - minetest.set_node(pos,node) - meta = minetest.get_meta(pos) - meta:from_table(meta0) + minetest.swap_node(pos,node) end minetest.register_abm({ @@ -959,7 +1014,7 @@ minetest.register_abm({ -- take stuff from "src" list inv:set_stack("src", 1, aftercooked.items[1]) else - print("Could not insert '"..cooked.item:to_string().."'") + --print("Could not insert '"..cooked.item:to_string().."'") end meta:set_string("src_time", 0) end @@ -969,7 +1024,7 @@ minetest.register_abm({ local percent = math.floor(meta:get_float("fuel_time") / meta:get_float("fuel_totaltime") * 100) meta:set_string("infotext","Furnace active: "..percent.."%") - hacky_swap_node(pos,"default:furnace_active") + swap_node(pos,"default:furnace_active") meta:set_string("formspec",default.get_furnace_active_formspec(pos, percent)) return end @@ -989,7 +1044,7 @@ minetest.register_abm({ if fuel.time <= 0 then meta:set_string("infotext","Furnace out of fuel") - hacky_swap_node(pos,"default:furnace") + swap_node(pos,"default:furnace") meta:set_string("formspec", default.furnace_inactive_formspec) return end @@ -997,7 +1052,7 @@ minetest.register_abm({ if cooked.item:is_empty() then if was_active then meta:set_string("infotext","Furnace is empty") - hacky_swap_node(pos,"default:furnace") + swap_node(pos,"default:furnace") meta:set_string("formspec", default.furnace_inactive_formspec) end return @@ -1088,6 +1143,7 @@ minetest.register_node("default:obsidian_glass", { drawtype = "glasslike", tiles = {"default_obsidian_glass.png"}, paramtype = "light", + is_ground_content = false, sunlight_propagates = true, sounds = default.node_sound_glass_defaults(), groups = {cracky=3,oddly_breakable_by_hand=3}, @@ -1107,14 +1163,18 @@ minetest.register_node("default:nyancat", { "default_nc_side.png", "default_nc_back.png", "default_nc_front.png"}, paramtype2 = "facedir", groups = {cracky=2}, + is_ground_content = false, legacy_facedir_simple = true, sounds = default.node_sound_defaults(), }) minetest.register_node("default:nyancat_rainbow", { description = "Nyan Cat Rainbow", - tiles = {"default_nc_rb.png"}, + tiles = {"default_nc_rb.png^[transformR90", "default_nc_rb.png^[transformR90", + "default_nc_rb.png", "default_nc_rb.png"}, + paramtype2 = "facedir", groups = {cracky=2}, + is_ground_content = false, sounds = default.node_sound_defaults(), }) @@ -1127,6 +1187,7 @@ minetest.register_node("default:sapling", { wield_image = "default_sapling.png", paramtype = "light", walkable = false, + is_ground_content = true, selection_box = { type = "fixed", fixed = {-0.3, -0.5, -0.3, 0.3, 0.35, 0.3} @@ -1144,6 +1205,7 @@ minetest.register_node("default:apple", { paramtype = "light", sunlight_propagates = true, walkable = false, + is_ground_content = true, selection_box = { type = "fixed", fixed = {-0.2, -0.5, -0.2, 0.2, 0, 0.2} @@ -1166,7 +1228,9 @@ minetest.register_node("default:dry_shrub", { inventory_image = "default_dry_shrub.png", wield_image = "default_dry_shrub.png", paramtype = "light", + waving = 1, walkable = false, + is_ground_content = true, buildable_to = true, groups = {snappy=3,flammable=3,attached_node=1}, sounds = default.node_sound_leaves_defaults(), @@ -1185,6 +1249,7 @@ minetest.register_node("default:grass_1", { wield_image = "default_grass_3.png", paramtype = "light", walkable = false, + is_ground_content = true, buildable_to = true, groups = {snappy=3,flammable=3,flora=1,attached_node=1}, sounds = default.node_sound_leaves_defaults(), diff --git a/mods/default/player.lua b/mods/default/player.lua index bf08149..d7426d8 100644 --- a/mods/default/player.lua +++ b/mods/default/player.lua @@ -1,132 +1,197 @@ -- Minetest 0.4 mod: player -- See README.txt for licensing and other information. --- --- Start of configuration area: --- +--[[ --- Player animation speed -animation_speed = 30 +API +--- + +default.player_register_model(name, def) +^ Register a new model to be used by players. +^ is the model filename such as "character.x", "foo.b3d", etc. +^ See Model Definition below for format of . + +default.registered_player_models[name] +^ See Model Definition below for format. + +default.player_set_model(player, model_name) +^ is a PlayerRef. +^ is a model registered with player_register_model. + +default.player_set_animation(player, anim_name [, speed]) +^ is a PlayerRef. +^ is the name of the animation. +^ is in frames per second. If nil, default from the model is used + +default.player_set_textures(player, textures) +^ is a PlayerRef. +^ is an array of textures +^ If is nil, the default textures from the model def are used + +default.player_get_animation(player) +^ is a PlayerRef. +^ Returns a table containing fields "model", "textures" and "animation". +^ Any of the fields of the returned table may be nil. + +Model Definition +---------------- + +model_def = { + animation_speed = 30, -- Default animation speed, in FPS. + textures = {"character.png", }, -- Default array of textures. + visual_size = {x=1, y=1,}, -- Used to scale the model. + animations = { + -- = { x=, y=, }, + foo = { x= 0, y=19, }, + bar = { x=20, y=39, }, + -- ... + }, +} + +]] -- Player animation blending -- Note: This is currently broken due to a bug in Irrlicht, leave at 0 -animation_blend = 0 +local animation_blend = 0 --- Default player appearance -default_model = "character.x" -default_textures = {"character.png", } +default.registered_player_models = { } --- Frame ranges for each player model -function player_get_animations(model) - if model == "character.x" then - return { - stand_START = 0, - stand_END = 79, - sit_START = 81, - sit_END = 160, - lay_START = 162, - lay_END = 166, - walk_START = 168, - walk_END = 187, - mine_START = 189, - mine_END = 198, - walk_mine_START = 200, - walk_mine_END = 219 - } - end +-- Local for speed. +local models = default.registered_player_models + +function default.player_register_model(name, def) + models[name] = def end --- --- End of configuration area. --- +-- Default player appearance +default.player_register_model("character.x", { + animation_speed = 30, + textures = {"character.png", }, + animations = { + -- Standard animations. + stand = { x= 0, y= 79, }, + lay = { x=162, y=166, }, + walk = { x=168, y=187, }, + mine = { x=189, y=198, }, + walk_mine = { x=200, y=219, }, + -- Extra animations (not currently used by the game). + sit = { x= 81, y=160, }, + }, +}) -- Player stats and animations local player_model = {} +local player_textures = {} local player_anim = {} local player_sneak = {} -local ANIM_STAND = 1 -local ANIM_SIT = 2 -local ANIM_LAY = 3 -local ANIM_WALK = 4 -local ANIM_WALK_MINE = 5 -local ANIM_MINE = 6 + +function default.player_get_animation(player) + local name = player:get_player_name() + return { + model = player_model[name], + textures = player_textures[name], + animation = player_anim[name], + } +end -- Called when a player's appearance needs to be updated -function player_update_visuals(pl) - local name = pl:get_player_name() +function default.player_set_model(player, model_name) + local name = player:get_player_name() + local model = models[model_name] + if model then + if player_model[name] == model_name then + return + end + player:set_properties({ + mesh = model_name, + textures = player_textures[name] or model.textures, + visual = "mesh", + visual_size = model.visual_size or {x=1, y=1}, + }) + default.player_set_animation(player, "stand") + else + player:set_properties({ + textures = { "player.png", "player_back.png", }, + visual = "upright_sprite", + }) + end + player_model[name] = model_name +end - player_model[name] = default_model - player_anim[name] = 0 -- Animation will be set further below immediately - player_sneak[name] = false - prop = { - mesh = default_model, - textures = default_textures, - visual = "mesh", - visual_size = {x=1, y=1}, - } - pl:set_properties(prop) +function default.player_set_textures(player, textures) + local name = player:get_player_name() + player_textures[name] = textures + player:set_properties({textures = textures,}) +end + +function default.player_set_animation(player, anim_name, speed) + local name = player:get_player_name() + if player_anim[name] == anim_name then + return + end + local model = player_model[name] and models[player_model[name]] + if not (model and model.animations[anim_name]) then + return + end + local anim = model.animations[anim_name] + player_anim[name] = anim_name + player:set_animation(anim, speed or model.animation_speed, animation_blend) end -- Update appearance when the player joins -minetest.register_on_joinplayer(player_update_visuals) +minetest.register_on_joinplayer(function(player) + default.player_set_model(player, "character.x") +end) + +minetest.register_on_leaveplayer(function(player) + local name = player:get_player_name() + player_model[name] = nil + player_anim[name] = nil + player_textures[name] = nil +end) + +-- Localize for better performance. +local player_set_animation = default.player_set_animation -- Check each player and apply animations -function player_step(dtime) - for _, pl in pairs(minetest.get_connected_players()) do - local name = pl:get_player_name() - local anim = player_get_animations(player_model[name]) - local controls = pl:get_player_control() - local walking = false - local animation_speed_mod = animation_speed +minetest.register_globalstep(function(dtime) + for _, player in pairs(minetest.get_connected_players()) do + local name = player:get_player_name() + local model_name = player_model[name] + local model = model_name and models[model_name] + if model then + local controls = player:get_player_control() + local walking = false + local animation_speed_mod = model.animation_speed or 30 - -- Determine if the player is walking - if controls.up or controls.down or controls.left or controls.right then - walking = true - end + -- Determine if the player is walking + if controls.up or controls.down or controls.left or controls.right then + walking = true + end - -- Determine if the player is sneaking, and reduce animation speed if so - if controls.sneak and pl:get_hp() ~= 0 and (walking or controls.LMB) then - animation_speed_mod = animation_speed_mod / 2 - -- Refresh player animation below if sneak state changed - if not player_sneak[name] then - player_anim[name] = 0 - player_sneak[name] = true + -- Determine if the player is sneaking, and reduce animation speed if so + if controls.sneak then + animation_speed_mod = animation_speed_mod / 2 end - else - -- Refresh player animation below if sneak state changed - if player_sneak[name] then - player_anim[name] = 0 - player_sneak[name] = false - end - end - -- Apply animations based on what the player is doing - if pl:get_hp() == 0 then - if player_anim[name] ~= ANIM_LAY then - pl:set_animation({x=anim.lay_START, y=anim.lay_END}, animation_speed_mod, animation_blend) - player_anim[name] = ANIM_LAY + -- Apply animations based on what the player is doing + if player:get_hp() == 0 then + player_set_animation(player, "lay") + elseif walking then + if player_sneak[name] ~= controls.sneak then + player_anim[name] = nil + player_sneak[name] = controls.sneak + end + if controls.LMB then + player_set_animation(player, "walk_mine", animation_speed_mod) + else + player_set_animation(player, "walk", animation_speed_mod) + end + elseif controls.LMB then + player_set_animation(player, "mine") + else + player_set_animation(player, "stand", animation_speed_mod) end - elseif walking and controls.LMB then - if player_anim[name] ~= ANIM_WALK_MINE then - pl:set_animation({x=anim.walk_mine_START, y=anim.walk_mine_END}, animation_speed_mod, animation_blend) - player_anim[name] = ANIM_WALK_MINE - end - elseif walking then - if player_anim[name] ~= ANIM_WALK then - pl:set_animation({x=anim.walk_START, y=anim.walk_END}, animation_speed_mod, animation_blend) - player_anim[name] = ANIM_WALK - end - elseif controls.LMB then - if player_anim[name] ~= ANIM_MINE then - pl:set_animation({x=anim.mine_START, y=anim.mine_END}, animation_speed_mod, animation_blend) - player_anim[name] = ANIM_MINE - end - elseif player_anim[name] ~= ANIM_STAND then - pl:set_animation({x=anim.stand_START, y=anim.stand_END}, animation_speed_mod, animation_blend) - player_anim[name] = ANIM_STAND end end -end -minetest.register_globalstep(player_step) - --- END +end) diff --git a/mods/default/tools.lua b/mods/default/tools.lua index 480eed2..25cf81b 100644 --- a/mods/default/tools.lua +++ b/mods/default/tools.lua @@ -11,7 +11,7 @@ minetest.register_item(":", { groupcaps = { crumbly = {times={[2]=3.00, [3]=0.70}, uses=0, maxlevel=1}, snappy = {times={[3]=0.40}, uses=0, maxlevel=1}, - oddly_breakable_by_hand = {times={[1]=7.00,[2]=4.00,[3]=1.40}, uses=0, maxlevel=3} + oddly_breakable_by_hand = {times={[1]=3.50,[2]=2.00,[3]=0.70}, uses=0} }, damage_groups = {fleshy=1}, } diff --git a/mods/default/trees.lua b/mods/default/trees.lua new file mode 100644 index 0000000..e68c055 --- /dev/null +++ b/mods/default/trees.lua @@ -0,0 +1,150 @@ +local c_air = minetest.get_content_id("air") +local c_ignore = minetest.get_content_id("ignore") +local c_tree = minetest.get_content_id("default:tree") +local c_leaves = minetest.get_content_id("default:leaves") +local c_apple = minetest.get_content_id("default:apple") + +function default.grow_tree(data, a, pos, is_apple_tree, seed) + --[[ + NOTE: Tree-placing code is currently duplicated in the engine + and in games that have saplings; both are deprecated but not + replaced yet + ]]-- + local pr = PseudoRandom(seed) + local th = pr:next(4, 5) + local x, y, z = pos.x, pos.y, pos.z + for yy = y, y+th-1 do + local vi = a:index(x, yy, z) + if a:contains(x, yy, z) and (data[vi] == c_air or yy == y) then + data[vi] = c_tree + end + end + y = y+th-1 -- (x, y, z) is now last piece of trunk + local leaves_a = VoxelArea:new{MinEdge={x=-2, y=-1, z=-2}, MaxEdge={x=2, y=2, z=2}} + local leaves_buffer = {} + + -- Force leaves near the trunk + local d = 1 + for xi = -d, d do + for yi = -d, d do + for zi = -d, d do + leaves_buffer[leaves_a:index(xi, yi, zi)] = true + end + end + end + + -- Add leaves randomly + for iii = 1, 8 do + local d = 1 + local xx = pr:next(leaves_a.MinEdge.x, leaves_a.MaxEdge.x - d) + local yy = pr:next(leaves_a.MinEdge.y, leaves_a.MaxEdge.y - d) + local zz = pr:next(leaves_a.MinEdge.z, leaves_a.MaxEdge.z - d) + + for xi = 0, d do + for yi = 0, d do + for zi = 0, d do + leaves_buffer[leaves_a:index(xx+xi, yy+yi, zz+zi)] = true + end + end + end + end + + -- Add the leaves + for xi = leaves_a.MinEdge.x, leaves_a.MaxEdge.x do + for yi = leaves_a.MinEdge.y, leaves_a.MaxEdge.y do + for zi = leaves_a.MinEdge.z, leaves_a.MaxEdge.z do + if a:contains(x+xi, y+yi, z+zi) then + local vi = a:index(x+xi, y+yi, z+zi) + if data[vi] == c_air or data[vi] == c_ignore then + if leaves_buffer[leaves_a:index(xi, yi, zi)] then + if is_apple_tree and pr:next(1, 100) <= 10 then + data[vi] = c_apple + else + data[vi] = c_leaves + end + end + end + end + end + end + end +end + +local c_jungletree = minetest.get_content_id("default:jungletree") +local c_jungleleaves = minetest.get_content_id("default:jungleleaves") + +function default.grow_jungletree(data, a, pos, seed) + --[[ + NOTE: Tree-placing code is currently duplicated in the engine + and in games that have saplings; both are deprecated but not + replaced yet + ]]-- + local pr = PseudoRandom(seed) + local x, y, z = pos.x, pos.y, pos.z + for xi = -1, 1 do + for zi = -1, 1 do + if pr:next(1, 3) >= 2 then + local vi1 = a:index(x+xi, y, z+zi) + local vi2 = a:index(x+xi, y-1, z+zi) + if a:contains(x+xi, y-1, z+zi) and data[vi2] == c_air then + data[vi2] = c_jungletree + elseif a:contains(x+xi, y, z+zi) and data[vi1] == c_air then + data[vi1] = c_jungletree + end + end + end + end + + local th = pr:next(8, 12) + for yy = y, y+th-1 do + local vi = a:index(x, yy, z) + if a:contains(x, yy, z) and (data[vi] == c_air or yy == y) then + data[vi] = c_jungletree + end + end + y = y+th-1 -- (x, y, z) is now last piece of trunk + local leaves_a = VoxelArea:new{MinEdge={x=-3, y=-2, z=-3}, MaxEdge={x=3, y=2, z=3}} + local leaves_buffer = {} + + -- Force leaves near the trunk + local d = 1 + for xi = -d, d do + for yi = -d, d do + for zi = -d, d do + leaves_buffer[leaves_a:index(xi, yi, zi)] = true + end + end + end + + -- Add leaves randomly + for iii = 1, 30 do + local d = 1 + local xx = pr:next(leaves_a.MinEdge.x, leaves_a.MaxEdge.x - d) + local yy = pr:next(leaves_a.MinEdge.y, leaves_a.MaxEdge.y - d) + local zz = pr:next(leaves_a.MinEdge.z, leaves_a.MaxEdge.z - d) + + for xi = 0, d do + for yi = 0, d do + for zi = 0, d do + leaves_buffer[leaves_a:index(xx+xi, yy+yi, zz+zi)] = true + end + end + end + end + + -- Add the leaves + for xi = leaves_a.MinEdge.x, leaves_a.MaxEdge.x do + for yi = leaves_a.MinEdge.y, leaves_a.MaxEdge.y do + for zi = leaves_a.MinEdge.z, leaves_a.MaxEdge.z do + if a:contains(x+xi, y+yi, z+zi) then + local vi = a:index(x+xi, y+yi, z+zi) + if data[vi] == c_air or data[vi] == c_ignore then + if leaves_buffer[leaves_a:index(xi, yi, zi)] then + data[vi] = c_jungleleaves + end + end + end + end + end + end +end diff --git a/mods/doors/init.lua b/mods/doors/init.lua index 4093899..46ab539 100644 --- a/mods/doors/init.lua +++ b/mods/doors/init.lua @@ -113,14 +113,10 @@ function doors:register_door(name, def) local p2 = minetest.get_node(pos).param2 p2 = params[p2+1] - local meta = minetest.get_meta(pos):to_table() - minetest.set_node(pos, {name=replace_dir, param2=p2}) - minetest.get_meta(pos):from_table(meta) + minetest.swap_node(pos, {name=replace_dir, param2=p2}) pos.y = pos.y-dir - meta = minetest.get_meta(pos):to_table() - minetest.set_node(pos, {name=replace, param2=p2}) - minetest.get_meta(pos):from_table(meta) + minetest.swap_node(pos, {name=replace, param2=p2}) end local function check_player_priv(pos, player) diff --git a/mods/farming/init.lua b/mods/farming/init.lua index 9508596..9c3bf5b 100644 --- a/mods/farming/init.lua +++ b/mods/farming/init.lua @@ -1,6 +1,8 @@ -- Minetest 0.4 mod: farming -- See README.txt for licensing and other information. +farming = {} + -- -- Soil -- @@ -62,7 +64,7 @@ minetest.register_abm({ -- Hoes -- -- turns nodes with group soil=1 into soil -local function hoe_on_use(itemstack, user, pointed_thing, uses) +function farming.hoe_on_use(itemstack, user, pointed_thing, uses) local pt = pointed_thing -- check if pointing at a node if not pt then @@ -109,7 +111,7 @@ minetest.register_tool("farming:hoe_wood", { inventory_image = "farming_tool_woodhoe.png", on_use = function(itemstack, user, pointed_thing) - return hoe_on_use(itemstack, user, pointed_thing, 30) + return farming.hoe_on_use(itemstack, user, pointed_thing, 30) end, }) @@ -118,7 +120,7 @@ minetest.register_tool("farming:hoe_stone", { inventory_image = "farming_tool_stonehoe.png", on_use = function(itemstack, user, pointed_thing) - return hoe_on_use(itemstack, user, pointed_thing, 90) + return farming.hoe_on_use(itemstack, user, pointed_thing, 90) end, }) @@ -127,7 +129,7 @@ minetest.register_tool("farming:hoe_steel", { inventory_image = "farming_tool_steelhoe.png", on_use = function(itemstack, user, pointed_thing) - return hoe_on_use(itemstack, user, pointed_thing, 200) + return farming.hoe_on_use(itemstack, user, pointed_thing, 200) end, }) @@ -136,7 +138,7 @@ minetest.register_tool("farming:hoe_bronze", { inventory_image = "farming_tool_bronzehoe.png", on_use = function(itemstack, user, pointed_thing) - return hoe_on_use(itemstack, user, pointed_thing, 220) + return farming.hoe_on_use(itemstack, user, pointed_thing, 220) end, }) @@ -144,8 +146,8 @@ minetest.register_craft({ output = "farming:hoe_wood", recipe = { {"group:wood", "group:wood"}, - {"", "default:stick"}, - {"", "default:stick"}, + {"", "group:stick"}, + {"", "group:stick"}, } }) @@ -153,8 +155,8 @@ minetest.register_craft({ output = "farming:hoe_stone", recipe = { {"group:stone", "group:stone"}, - {"", "default:stick"}, - {"", "default:stick"}, + {"", "group:stick"}, + {"", "group:stick"}, } }) @@ -162,8 +164,8 @@ minetest.register_craft({ output = "farming:hoe_steel", recipe = { {"default:steel_ingot", "default:steel_ingot"}, - {"", "default:stick"}, - {"", "default:stick"}, + {"", "group:stick"}, + {"", "group:stick"}, } }) @@ -171,8 +173,8 @@ minetest.register_craft({ output = "farming:hoe_bronze", recipe = { {"default:bronze_ingot", "default:bronze_ingot"}, - {"", "default:stick"}, - {"", "default:stick"}, + {"", "group:stick"}, + {"", "group:stick"}, } }) @@ -187,6 +189,7 @@ minetest.register_node(":default:grass_1", { inventory_image = "default_grass_3.png", wield_image = "default_grass_3.png", paramtype = "light", + waving = 1, walkable = false, buildable_to = true, drop = { @@ -218,6 +221,7 @@ for i=2,5 do inventory_image = "default_grass_"..i..".png", wield_image = "default_grass_"..i..".png", paramtype = "light", + waving = 1, walkable = false, buildable_to = true, is_ground_content = true, @@ -245,6 +249,7 @@ minetest.register_node(":default:junglegrass", { inventory_image = "default_junglegrass.png", wield_image = "default_junglegrass.png", paramtype = "light", + waving = 1, walkable = false, buildable_to = true, is_ground_content = true, @@ -363,6 +368,7 @@ for i=1,8 do drawtype = "plantlike", tiles = {"farming_wheat_"..i..".png"}, paramtype = "light", + waving = 1, walkable = false, buildable_to = true, is_ground_content = true, @@ -448,6 +454,7 @@ for i=1,8 do drawtype = "plantlike", tiles = {"farming_cotton_"..i..".png"}, paramtype = "light", + waving = 1, walkable = false, buildable_to = true, is_ground_content = true, diff --git a/mods/give_initial_stuff/init.lua b/mods/give_initial_stuff/init.lua index 9cf6b51..c65ddea 100644 --- a/mods/give_initial_stuff/init.lua +++ b/mods/give_initial_stuff/init.lua @@ -1,7 +1,7 @@ minetest.register_on_newplayer(function(player) - print("on_newplayer") + --print("on_newplayer") if minetest.setting_getbool("give_initial_stuff") then - print("giving give_initial_stuff to player") + minetest.log("action", "Giving initial stuff to player "..player:get_player_name()) player:get_inventory():add_item('main', 'default:pick_steel') player:get_inventory():add_item('main', 'default:torch 99') player:get_inventory():add_item('main', 'default:axe_steel') diff --git a/mods/screwdriver/depends.txt b/mods/screwdriver/depends.txt deleted file mode 100644 index 4ad96d5..0000000 --- a/mods/screwdriver/depends.txt +++ /dev/null @@ -1 +0,0 @@ -default diff --git a/mods/screwdriver/init.lua b/mods/screwdriver/init.lua index 1a11b92..6f99aa5 100644 --- a/mods/screwdriver/init.lua +++ b/mods/screwdriver/init.lua @@ -1,210 +1,162 @@ + +local mode_text = { + {"Change rotation, Don't change axisdir."}, + {"Keep choosen face in front then rotate it."}, + {"Change axis dir, Reset rotation."}, + {"Bring top in front then rotate it."}, +} + +local opposite_faces = { + [0] = 5, + [1] = 2, + [2] = 1, + [3] = 4, + [4] = 3, + [5] = 0, +} + +local function screwdriver_setmode(user,itemstack) + local player_name = user:get_player_name() + local item = itemstack:to_table() + local mode = tonumber(itemstack:get_metadata()) + if not mode then + minetest.chat_send_player(player_name, "Hold shift and use to change screwdriwer modes.") + mode = 0 + end + mode = mode + 1 + if mode == 5 then + mode = 1 + end + minetest.chat_send_player(player_name, "Screwdriver mode : "..mode.." - "..mode_text[mode][1] ) + itemstack:set_name("screwdriver:screwdriver"..mode) + itemstack:set_metadata(mode) + return itemstack +end + +local function get_node_face(pointed_thing) + local ax, ay, az = pointed_thing.above.x, pointed_thing.above.y, pointed_thing.above.z + local ux, uy, uz = pointed_thing.under.x, pointed_thing.under.y, pointed_thing.under.z + if ay > uy then return 0 -- Top + elseif az > uz then return 1 -- Z+ side + elseif az < uz then return 2 -- Z- side + elseif ax > ux then return 3 -- X+ side + elseif ax < ux then return 4 -- X- side + elseif ay < uy then return 5 -- Bottom + else + error("pointed_thing.above and under are the same!") + end +end + +local function nextrange(x, max) + x = x + 1 + if x > max then + x = 0 + end + return x +end + +local function screwdriver_handler(itemstack, user, pointed_thing) + if pointed_thing.type ~= "node" then + return + end + local pos = pointed_thing.under + local keys = user:get_player_control() + local player_name = user:get_player_name() + local mode = tonumber(itemstack:get_metadata()) + if not mode or keys["sneak"] == true then + return screwdriver_setmode(user, itemstack) + end + if minetest.is_protected(pos, user:get_player_name()) then + minetest.record_protection_violation(pos, user:get_player_name()) + return + end + local node = minetest.get_node(pos) + local node_name = node.name + local ndef = minetest.registered_nodes[node.name] + if ndef.paramtype2 == "facedir" then + if ndef.drawtype == "nodebox" and ndef.node_box.type ~= "fixed" then + return + end + if node.param2 == nil then + return + end + -- Get ready to set the param2 + local n = node.param2 + local axisdir = math.floor(n / 4) + local rotation = n - axisdir * 4 + if mode == 1 then + n = axisdir * 4 + nextrange(rotation, 3) + elseif mode == 2 then + -- If you are pointing at the axisdir face or the + -- opposite one then you can just rotate the node. + -- Otherwise change the axisdir, avoiding the facing + -- and opposite axes. + local face = get_node_face(pointed_thing) + if axisdir == face or axisdir == opposite_faces[face] then + n = axisdir * 4 + nextrange(rotation, 3) + else + axisdir = nextrange(axisdir, 5) + -- This is repeated because switching from the face + -- can move to to the opposite and vice-versa + if axisdir == face or axisdir == opposite_faces[face] then + axisdir = nextrange(axisdir, 5) + end + if axisdir == face or axisdir == opposite_faces[face] then + axisdir = nextrange(axisdir, 5) + end + n = axisdir * 4 + end + elseif mode == 3 then + n = nextrange(axisdir, 5) * 4 + elseif mode == 4 then + local face = get_node_face(pointed_thing) + if axisdir == face then + n = axisdir * 4 + nextrange(rotation, 3) + else + n = face * 4 + end + end + --print (dump(axisdir..", "..rotation)) + node.param2 = n + minetest.swap_node(pos, node) + local item_wear = tonumber(itemstack:get_wear()) + item_wear = item_wear + 327 + if item_wear > 65535 then + itemstack:clear() + return itemstack + end + itemstack:set_wear(item_wear) + return itemstack + end +end + +minetest.register_craft({ + output = "screwdriver:screwdriver", + recipe = { + {"default:steel_ingot"}, + {"group:stick"} + } +}) + minetest.register_tool("screwdriver:screwdriver", { description = "Screwdriver", inventory_image = "screwdriver.png", on_use = function(itemstack, user, pointed_thing) - screwdriver_handler(itemstack,user,pointed_thing) - return itemstack + screwdriver_handler(itemstack, user, pointed_thing) + return itemstack end, }) -for i=1,4,1 do -minetest.register_tool("screwdriver:screwdriver"..i, { - description = "Screwdriver in Mode "..i, - inventory_image = "screwdriver.png^tool_mode"..i..".png", - wield_image = "screwdriver.png", - groups = {not_in_creative_inventory=1}, - on_use = function(itemstack, user, pointed_thing) - screwdriver_handler(itemstack,user,pointed_thing) - return itemstack - end, -}) -end -faces_table= -{ ---look dir +X +Y +Z -Z -Y -X - 2 , 0 , 4 , 5 , 1 , 3 , -- rotate around y+ 0 - 3 - 4 , 0 , 3 , 2 , 1 , 5 , - 3 , 0 , 5 , 4 , 1 , 2 , - 5 , 0 , 2 , 3 , 1 , 4 , - - 2 , 5 , 0 , 1 , 4 , 3 , -- rotate around z+ 4 - 7 - 4 , 2 , 0 , 1 , 3 , 5 , - 3 , 4 , 0 , 1 , 5 , 2 , - 5 , 3 , 0 , 1 , 2 , 4 , - - 2 , 4 , 1 , 0 , 5 , 3 , -- rotate around z- 8 - 11 - 4 , 3 , 1 , 0 , 2 , 5 , - 3 , 5 , 1 , 0 , 4 , 2 , - 5 , 2 , 1 , 0 , 3 , 4 , - - 0 , 3 , 4 , 5 , 2 , 1 , -- rotate around x+ 12 - 15 - 0 , 5 , 3 , 2 , 4 , 1 , - 0 , 2 , 5 , 4 , 3 , 1 , - 0 , 4 , 2 , 3 , 5 , 1 , - - 1 , 2 , 4 , 5 , 3 , 0 , -- rotate around x- 16 - 19 - 1 , 4 , 3 , 2 , 5 , 0 , - 1 , 3 , 5 , 4 , 2 , 0 , - 1 , 5 , 2 , 3 , 4 , 0 , - - 3 , 1 , 4 , 5 , 0 , 2 , -- rotate around y- 20 - 23 - 5 , 1 , 3 , 2 , 0 , 4 , - 2 , 1 , 5 , 4 , 0 , 3 , - 4 , 1 , 2 , 3 , 0 , 5 -} - -function screwdriver_handler (itemstack,user,pointed_thing) - local keys=user:get_player_control() - local player_name=user:get_player_name() - local item=itemstack:to_table() - if item["metadata"]=="" or keys["sneak"]==true then return screwdriver_setmode(user,itemstack) end - local mode=tonumber((item["metadata"])) - if pointed_thing.type~="node" then return end - local pos=minetest.get_pointed_thing_position(pointed_thing,above) - local node=minetest.get_node(pos) - local node_name=node.name - if minetest.registered_nodes[node_name].paramtype2 == "facedir" then - if minetest.registered_nodes[node_name].drawtype == "nodebox" then - if minetest.registered_nodes[node_name].node_box["type"]~="fixed" then return end - end - if node.param2==nil then return end - -- Get ready to set the param2 - local n = node.param2 - local axisdir=math.floor(n/4) - local rotation=n-axisdir*4 - if mode==1 then - rotation=rotation+1 - if rotation>3 then rotation=0 end - n=axisdir*4+rotation - end - - if mode==2 then - local ppos=user:getpos() - local pvect=user:get_look_dir() - local face=get_node_face(pos,ppos,pvect) - if face == nil then return end - local index=convertFaceToIndex(face) - local face1=faces_table[n*6+index+1] - local found = 0 - while found == 0 do - n=n+1 - if n>23 then n=0 end - if faces_table[n*6+index+1]==face1 then found=1 end - end - end - - if mode==3 then - axisdir=axisdir+1 - if axisdir>5 then axisdir=0 end - n=axisdir*4 - end - - if mode==4 then - local ppos=user:getpos() - local pvect=user:get_look_dir() - local face=get_node_face(pos,ppos,pvect) - if face == nil then return end - if axisdir == face then - rotation=rotation+1 - if rotation>3 then rotation=0 end - n=axisdir*4+rotation - else - n=face*4 - end - end - --print (dump(axisdir..", "..rotation)) - local meta = minetest.get_meta(pos) - local meta0 = meta:to_table() - node.param2 = n - minetest.set_node(pos,node) - meta = minetest.get_meta(pos) - meta:from_table(meta0) - local item=itemstack:to_table() - local item_wear=tonumber((item["wear"])) - item_wear=item_wear+327 - if item_wear>65535 then itemstack:clear() return itemstack end - item["wear"]=tostring(item_wear) - itemstack:replace(item) +for i = 1, 4 do + minetest.register_tool("screwdriver:screwdriver"..i, { + description = "Screwdriver in Mode "..i, + inventory_image = "screwdriver.png^tool_mode"..i..".png", + wield_image = "screwdriver.png", + groups = {not_in_creative_inventory=1}, + on_use = function(itemstack, user, pointed_thing) + screwdriver_handler(itemstack, user, pointed_thing) return itemstack - end -end - -mode_text={ -{"Change rotation, Don't change axisdir."}, -{"Keep choosen face in front then rotate it."}, -{"Change axis dir, Reset rotation."}, -{"Bring top in front then rotate it."}, -} - -function screwdriver_setmode(user,itemstack) -local player_name=user:get_player_name() -local item=itemstack:to_table() -local mode -if item["metadata"]=="" then - minetest.chat_send_player(player_name,"Hold shift and use to change screwdriwer modes.") - mode=0 -else mode=tonumber((item["metadata"])) -end -mode=mode+1 -if mode==5 then mode=1 end -minetest.chat_send_player(player_name, "Screwdriver mode : "..mode.." - "..mode_text[mode][1] ) -item["name"]="screwdriver:screwdriver"..mode -item["metadata"]=tostring(mode) -itemstack:replace(item) -return itemstack -end - -minetest.register_craft({ -output = "screwdriver:screwdriver", -recipe = { -{"default:steel_ingot"}, -{"default:stick"} -} -}) - -function get_node_face(pos,ppos,pvect) - ppos={x=ppos.x-pos.x,y=ppos.y-pos.y+1.5,z=ppos.z-pos.z} - if pvect.x>0 then - local t=(-0.5-ppos.x)/pvect.x - local y_int=ppos.y+t*pvect.y - local z_int=ppos.z+t*pvect.z - if y_int>-0.4 and y_int<0.4 and z_int>-0.4 and z_int<0.4 then return 4 end - elseif pvect.x<0 then - local t=(0.5-ppos.x)/pvect.x - local y_int=ppos.y+t*pvect.y - local z_int=ppos.z+t*pvect.z - if y_int>-0.4 and y_int<0.4 and z_int>-0.4 and z_int<0.4 then return 3 end - end - if pvect.y>0 then - local t=(-0.5-ppos.y)/pvect.y - local x_int=ppos.x+t*pvect.x - local z_int=ppos.z+t*pvect.z - if x_int>-0.4 and x_int<0.4 and z_int>-0.4 and z_int<0.4 then return 5 end - elseif pvect.y<0 then - local t=(0.5-ppos.y)/pvect.y - local x_int=ppos.x+t*pvect.x - local z_int=ppos.z+t*pvect.z - if x_int>-0.4 and x_int<0.4 and z_int>-0.4 and z_int<0.4 then return 0 end - end - if pvect.z>0 then - local t=(-0.5-ppos.z)/pvect.z - local x_int=ppos.x+t*pvect.x - local y_int=ppos.y+t*pvect.y - if x_int>-0.4 and x_int<0.4 and y_int>-0.4 and y_int<0.4 then return 2 end - elseif pvect.z<0 then - local t=(0.5-ppos.z)/pvect.z - local x_int=ppos.x+t*pvect.x - local y_int=ppos.y+t*pvect.y - if x_int>-0.4 and x_int<0.4 and y_int>-0.4 and y_int<0.4 then return 1 end - end -end - -function convertFaceToIndex (face) -if face==0 then return 1 end -if face==1 then return 2 end -if face==2 then return 3 end -if face==3 then return 0 end -if face==4 then return 5 end -if face==5 then return 4 end + end, + }) end diff --git a/mods/stairs/init.lua b/mods/stairs/init.lua index 0dbc40c..179cf15 100644 --- a/mods/stairs/init.lua +++ b/mods/stairs/init.lua @@ -25,39 +25,38 @@ function stairs.register_stair(subname, recipeitem, groups, images, description, if pointed_thing.type ~= "node" then return itemstack end - + local p0 = pointed_thing.under local p1 = pointed_thing.above + local param2 = 0 + + local placer_pos = placer:getpos() + if placer_pos then + local dir = { + x = p1.x - placer_pos.x, + y = p1.y - placer_pos.y, + z = p1.z - placer_pos.z + } + param2 = minetest.dir_to_facedir(dir) + end + if p0.y-1 == p1.y then - local fakestack = ItemStack("stairs:stair_" .. subname.."upside_down") - local ret = minetest.item_place(fakestack, placer, pointed_thing) - if ret:is_empty() then - itemstack:take_item() - return itemstack + param2 = param2 + 20 + if param2 == 21 then + param2 = 23 + elseif param2 == 23 then + param2 = 21 end end - - -- Otherwise place regularly - return minetest.item_place(itemstack, placer, pointed_thing) + + return minetest.item_place(itemstack, placer, pointed_thing, param2) end, }) - + + -- for replace ABM minetest.register_node(":stairs:stair_" .. subname.."upside_down", { - drop = "stairs:stair_" .. subname, - drawtype = "nodebox", - tiles = images, - paramtype = "light", - paramtype2 = "facedir", - is_ground_content = true, - groups = groups, - sounds = sounds, - node_box = { - type = "fixed", - fixed = { - {-0.5, 0, -0.5, 0.5, 0.5, 0.5}, - {-0.5, -0.5, 0, 0.5, 0, 0.5}, - }, - }, + replace_name = "stairs:stair_" .. subname, + groups = {slabs_replace=1}, }) minetest.register_craft({ @@ -87,6 +86,7 @@ function stairs.register_slab(subname, recipeitem, groups, images, description, drawtype = "nodebox", tiles = images, paramtype = "light", + paramtype2 = "facedir", is_ground_content = true, groups = groups, sounds = sounds, @@ -106,21 +106,32 @@ function stairs.register_slab(subname, recipeitem, groups, images, description, local p0 = pointed_thing.under local p1 = pointed_thing.above local n0 = minetest.get_node(p0) - if n0.name == "stairs:slab_" .. subname and - p0.y+1 == p1.y then + local n1 = minetest.get_node(p1) + local param2 = 0 + + local n0_is_upside_down = (n0.name == "stairs:slab_" .. subname and + n0.param2 >= 20) + + if n0.name == "stairs:slab_" .. subname and not n0_is_upside_down and p0.y+1 == p1.y then slabpos = p0 slabnode = n0 + elseif n1.name == "stairs:slab_" .. subname then + slabpos = p1 + slabnode = n1 end if slabpos then -- Remove the slab at slabpos minetest.remove_node(slabpos) -- Make a fake stack of a single item and try to place it local fakestack = ItemStack(recipeitem) + fakestack:set_count(itemstack:get_count()) + pointed_thing.above = slabpos - fakestack = minetest.item_place(fakestack, placer, pointed_thing) + local success + fakestack, success = minetest.item_place(fakestack, placer, pointed_thing) -- If the item was taken from the fake stack, decrement original - if not fakestack or fakestack:is_empty() then - itemstack:take_item(1) + if success then + itemstack:set_count(fakestack:get_count()) -- Else put old node back else minetest.set_node(slabpos, slabnode) @@ -131,61 +142,43 @@ function stairs.register_slab(subname, recipeitem, groups, images, description, -- Upside down slabs if p0.y-1 == p1.y then -- Turn into full block if pointing at a existing slab - if n0.name == "stairs:slab_" .. subname.."upside_down" then + if n0_is_upside_down then -- Remove the slab at the position of the slab minetest.remove_node(p0) -- Make a fake stack of a single item and try to place it local fakestack = ItemStack(recipeitem) + fakestack:set_count(itemstack:get_count()) + pointed_thing.above = p0 - fakestack = minetest.item_place(fakestack, placer, pointed_thing) + local success + fakestack, success = minetest.item_place(fakestack, placer, pointed_thing) -- If the item was taken from the fake stack, decrement original - if not fakestack or fakestack:is_empty() then - itemstack:take_item(1) + if success then + itemstack:set_count(fakestack:get_count()) -- Else put old node back else minetest.set_node(p0, n0) end return itemstack end - + -- Place upside down slab - local fakestack = ItemStack("stairs:slab_" .. subname.."upside_down") - local ret = minetest.item_place(fakestack, placer, pointed_thing) - if ret:is_empty() then - itemstack:take_item() - return itemstack - end + param2 = 20 end - + -- If pointing at the side of a upside down slab - if n0.name == "stairs:slab_" .. subname.."upside_down" and - p0.y+1 ~= p1.y then - -- Place upside down slab - local fakestack = ItemStack("stairs:slab_" .. subname.."upside_down") - local ret = minetest.item_place(fakestack, placer, pointed_thing) - if ret:is_empty() then - itemstack:take_item() - return itemstack - end + if n0_is_upside_down and p0.y+1 ~= p1.y then + param2 = 20 end - - -- Otherwise place regularly - return minetest.item_place(itemstack, placer, pointed_thing) + + return minetest.item_place(itemstack, placer, pointed_thing, param2) end, }) - + + -- for replace ABM minetest.register_node(":stairs:slab_" .. subname.."upside_down", { - drop = "stairs:slab_"..subname, - drawtype = "nodebox", - tiles = images, - paramtype = "light", - is_ground_content = true, - groups = groups, - sounds = sounds, - node_box = { - type = "fixed", - fixed = {-0.5, 0, -0.5, 0.5, 0.5, 0.5}, - }, + replace_name = "stairs:slab_"..subname, + groups = {slabs_replace=1}, }) minetest.register_craft({ @@ -196,6 +189,23 @@ function stairs.register_slab(subname, recipeitem, groups, images, description, }) end +-- Replace old "upside_down" nodes with new param2 versions +minetest.register_abm({ + nodenames = {"group:slabs_replace"}, + interval = 1, + chance = 1, + action = function(pos, node) + node.name = minetest.registered_nodes[node.name].replace_name + node.param2 = node.param2 + 20 + if node.param2 == 21 then + node.param2 = 23 + elseif node.param2 == 23 then + node.param2 = 21 + end + minetest.set_node(pos, node) + end, +}) + -- Nodes will be called stairs:{stair,slab}_ function stairs.register_stair_and_slab(subname, recipeitem, groups, images, desc_stair, desc_slab, sounds) stairs.register_stair(subname, recipeitem, groups, images, desc_stair, sounds)