master
ShadowNinja 2013-12-14 13:36:46 -05:00
parent 85b6c8ede8
commit eb19667231
48 changed files with 2651 additions and 7002 deletions

View File

@ -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'},
}
})
@ -468,9 +468,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'},
}
})

View File

@ -3,6 +3,7 @@
minetest.register_craftitem("default:stick", {
description = "Stick",
inventory_image = "default_stick.png",
groups = {stick=1},
})
minetest.register_craftitem("default:paper", {

View File

@ -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
})

View File

@ -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")

View File

@ -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")
@ -363,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
@ -372,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

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

File diff suppressed because it is too large Load Diff

View File

@ -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 = = <default>
@ -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",
@ -600,7 +652,7 @@ minetest.register_node("default:sign_wall", {
--print("Sign at "..minetest.pos_to_string(pos).." got "..dump(fields))
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 +681,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 +723,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 +827,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 +898,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 +960,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 +1010,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 +1020,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 +1040,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 +1048,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 +1139,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 +1159,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 +1183,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 +1201,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 +1224,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 +1245,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(),

View File

@ -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.
^ <name> is the model filename such as "character.x", "foo.b3d", etc.
^ See Model Definition below for format of <def>.
default.registered_player_models[name]
^ See Model Definition below for format.
default.player_set_model(player, model_name)
^ <player> is a PlayerRef.
^ <model_name> is a model registered with player_register_model.
default.player_set_animation(player, anim_name [, speed])
^ <player> is a PlayerRef.
^ <anim_name> is the name of the animation.
^ <speed> is in frames per second. If nil, default from the model is used
default.player_set_textures(player, textures)
^ <player> is a PlayerRef.
^ <textures> is an array of textures
^ If <textures> is nil, the default textures from the model def are used
default.player_get_animation(player)
^ <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 = {
-- <anim_name> = { x=<start_frame>, y=<end_frame>, },
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)

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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},
}

150
mods/default/trees.lua Normal file
View File

@ -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

@ -1 +1 @@
Subproject commit 3afc06dda5b99d3c628a76ec98f46130d2a25c50
Subproject commit 8c5e3c6f8ff685f458b7c0dfac5f34d9ed125c8e

View File

@ -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)

View File

@ -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,

@ -1 +1 @@
Subproject commit 1a5c583507e5f7c5f4126492e37fc041753e4db5
Subproject commit cb316c45b587b99b21b58ea49d32527f320b18a7

@ -1 +1 @@
Subproject commit bdd27a68b4a8ab25934701f96636beb2d7e28332
Subproject commit 67c7336a321e18f87ff946b92c82baed84aa8006

View File

@ -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')

@ -1 +1 @@
Subproject commit 9ab0d9deb2ac0801f38b9291ef8c8e3fb6ef5745
Subproject commit 85f2f3f74217cb6a9a04eb8a2d953484d0821c46

@ -1 +1 @@
Subproject commit 621948c70a6f07a39765ebd360dccd4261173e21
Subproject commit 0e63715989db020d0dbd837250f7ec1ebd602407

@ -1 +1 @@
Subproject commit 76b04dd3bea51b9224c102c781055c2836966d1d
Subproject commit 57f68dd202fb740e886410b2aa19defb4d13475f

@ -1 +1 @@
Subproject commit fa64297c0916d11ce0f4ad23fba08a8e1f4d8bd3
Subproject commit d8752b308e46286cdfd43a5bfb5a0bc2ed9d3841

@ -1 +1 @@
Subproject commit 12eb772d18a4fef809e025751d813a6a514f8821
Subproject commit b43a1036cae2fda49453a2c0a97b9ed2f6d16023

@ -1 +1 @@
Subproject commit 54a507fad00302725fbc200812cdae8f1c79cd8f
Subproject commit de10533759fceb37223b71796fca1e3cd0a6fd25

View File

@ -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
if minetest.is_protected(pos, user:get_player_name()) then
minetest.record_protection_violation(pos, user:get_player_name())
return
end
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
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

View File

@ -25,11 +25,11 @@ 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 = {
@ -39,7 +39,7 @@ function stairs.register_stair(subname, recipeitem, groups, images, description,
}
param2 = minetest.dir_to_facedir(dir)
end
if p0.y-1 == p1.y then
param2 = param2 + 20
if param2 == 21 then
@ -48,11 +48,11 @@ function stairs.register_stair(subname, recipeitem, groups, images, description,
param2 = 21
end
end
return minetest.item_place(itemstack, placer, pointed_thing, param2)
end,
})
-- for replace ABM
minetest.register_node(":stairs:stair_" .. subname.."upside_down", {
replace_name = "stairs:stair_" .. subname,
@ -108,10 +108,10 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
local n0 = minetest.get_node(p0)
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
@ -125,7 +125,7 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
-- 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
local success
fakestack, success = minetest.item_place(fakestack, placer, pointed_thing)
@ -148,7 +148,7 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
-- 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
local success
fakestack, success = minetest.item_place(fakestack, placer, pointed_thing)
@ -161,20 +161,20 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
end
return itemstack
end
-- Place upside down slab
param2 = 20
end
-- If pointing at the side of a upside down slab
if n0_is_upside_down and p0.y+1 ~= p1.y then
param2 = 20
end
return minetest.item_place(itemstack, placer, pointed_thing, param2)
end,
})
-- for replace ABM
minetest.register_node(":stairs:slab_" .. subname.."upside_down", {
replace_name = "stairs:slab_"..subname,

@ -1 +1 @@
Subproject commit 808d3828673937772dbddf985e677ba31258bcb9
Subproject commit f3d8b47b20feac740057984a70f93f38252619eb

@ -1 +1 @@
Subproject commit 2b5bf5fe95e388c28a81debfacdb0e8b14ddf355
Subproject commit d5f60ed136848e20f5ff620afe2901e246231e0b