1
0
mirror of https://github.com/minetest/minetest_game.git synced 2025-06-28 20:56:02 +02:00

11 Commits
0.4.8 ... 0.4.9

7 changed files with 260 additions and 237 deletions

View File

@ -18,6 +18,19 @@ minetest.register_craft({
bucket = {} bucket = {}
bucket.liquids = {} 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 -- Register a new liquid
-- source = name of the source node -- source = name of the source node
-- flowing = name of the flowing node -- flowing = name of the flowing node
@ -45,18 +58,30 @@ function bucket.register_liquid(source, flowing, itemname, inventory_image, name
return return
end end
-- Call on_rightclick if the pointed node defines it local node = minetest.get_node_or_nil(pointed_thing.under)
if user and not user:get_player_control().sneak then local ndef
local n = minetest.get_node(pointed_thing.under) if node then
local nn = n.name ndef = minetest.registered_nodes[node.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 end
-- Call on_rightclick if the pointed node defines it
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 end
local place_liquid = function(pos, node, source, flowing, fullness) local place_liquid = function(pos, node, source, flowing, fullness)
if math.floor(fullness/128) == 1 or (not minetest.setting_getbool("liquid_finite")) then if check_protection(pos,
minetest.add_node(pos, {name=source, param2=fullness}) 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 return
elseif node.name == flowing then elseif node.name == flowing then
fullness = fullness + node.param2 fullness = fullness + node.param2
@ -65,26 +90,30 @@ function bucket.register_liquid(source, flowing, itemname, inventory_image, name
end end
if fullness >= LIQUID_MAX then if fullness >= LIQUID_MAX then
minetest.add_node(pos, {name=source, param2=LIQUID_MAX}) minetest.add_node(pos, {name=source,
param2=LIQUID_MAX})
else else
minetest.add_node(pos, {name=flowing, param2=fullness}) minetest.add_node(pos, {name=flowing,
param2=fullness})
end end
end end
-- Check if pointing to a buildable node -- Check if pointing to a buildable node
local node = minetest.get_node(pointed_thing.under)
local fullness = tonumber(itemstack:get_metadata()) local fullness = tonumber(itemstack:get_metadata())
if not fullness then fullness = LIQUID_MAX end 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 -- buildable; replace the node
place_liquid(pointed_thing.under, node, source, flowing, fullness) place_liquid(pointed_thing.under, node,
source, flowing, fullness)
else else
-- not buildable to; place the liquid above -- not buildable to; place the liquid above
-- check if the node above can be replaced -- check if the node above can be replaced
local node = minetest.get_node(pointed_thing.above) local node = minetest.get_node_or_nil(pointed_thing.above)
if minetest.registered_nodes[node.name].buildable_to then if node and minetest.registered_nodes[node.name].buildable_to then
place_liquid(pointed_thing.above, node, source, flowing, fullness) place_liquid(pointed_thing.above,
node, source,
flowing, fullness)
else else
-- do not remove the bucket with the liquid -- do not remove the bucket with the liquid
return return
@ -109,13 +138,23 @@ minetest.register_craftitem("bucket:bucket_empty", {
-- Check if pointing to a liquid source -- Check if pointing to a liquid source
node = minetest.get_node(pointed_thing.under) node = minetest.get_node(pointed_thing.under)
liquiddef = bucket.liquids[node.name] liquiddef = bucket.liquids[node.name]
if liquiddef ~= nil and liquiddef.itemname ~= nil and (node.name == liquiddef.source or if liquiddef ~= nil and liquiddef.itemname ~= nil and
(node.name == liquiddef.flowing and minetest.setting_getbool("liquid_finite"))) then (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"}) minetest.add_node(pointed_thing.under, {name="air"})
if node.name == liquiddef.source then node.param2 = LIQUID_MAX end if node.name == liquiddef.source then
return ItemStack({name = liquiddef.itemname, metadata = tostring(node.param2)}) node.param2 = LIQUID_MAX
end
return ItemStack({name = liquiddef.itemname,
metadata = tostring(node.param2)})
end end
end, end,
}) })

View File

@ -220,6 +220,7 @@ minetest.register_node("default:clay", {
minetest.register_node("default:brick", { minetest.register_node("default:brick", {
description = "Brick Block", description = "Brick Block",
tiles = {"default_brick.png"}, tiles = {"default_brick.png"},
is_ground_content = false,
groups = {cracky=3}, groups = {cracky=3},
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
}) })
@ -228,6 +229,7 @@ minetest.register_node("default:tree", {
description = "Tree", description = "Tree",
tiles = {"default_tree_top.png", "default_tree_top.png", "default_tree.png"}, tiles = {"default_tree_top.png", "default_tree_top.png", "default_tree.png"},
paramtype2 = "facedir", paramtype2 = "facedir",
is_ground_content = false,
groups = {tree=1,choppy=2,oddly_breakable_by_hand=1,flammable=2}, groups = {tree=1,choppy=2,oddly_breakable_by_hand=1,flammable=2},
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
on_place = minetest.rotate_node on_place = minetest.rotate_node
@ -237,6 +239,7 @@ minetest.register_node("default:jungletree", {
description = "Jungle Tree", description = "Jungle Tree",
tiles = {"default_jungletree_top.png", "default_jungletree_top.png", "default_jungletree.png"}, tiles = {"default_jungletree_top.png", "default_jungletree_top.png", "default_jungletree.png"},
paramtype2 = "facedir", paramtype2 = "facedir",
is_ground_content = false,
groups = {tree=1,choppy=2,oddly_breakable_by_hand=1,flammable=2}, groups = {tree=1,choppy=2,oddly_breakable_by_hand=1,flammable=2},
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
on_place = minetest.rotate_node on_place = minetest.rotate_node
@ -255,6 +258,8 @@ minetest.register_node("default:jungleleaves", {
visual_scale = 1.3, visual_scale = 1.3,
tiles = {"default_jungleleaves.png"}, tiles = {"default_jungleleaves.png"},
paramtype = "light", paramtype = "light",
waving = 1,
is_ground_content = false,
groups = {snappy=3, leafdecay=3, flammable=2, leaves=1}, groups = {snappy=3, leafdecay=3, flammable=2, leaves=1},
drop = { drop = {
max_items = 1, max_items = 1,
@ -316,6 +321,8 @@ minetest.register_node("default:leaves", {
visual_scale = 1.3, visual_scale = 1.3,
tiles = {"default_leaves.png"}, tiles = {"default_leaves.png"},
paramtype = "light", paramtype = "light",
waving = 1,
is_ground_content = false,
groups = {snappy=3, leafdecay=3, flammable=2, leaves=1}, groups = {snappy=3, leafdecay=3, flammable=2, leaves=1},
drop = { drop = {
max_items = 1, max_items = 1,
@ -365,6 +372,7 @@ minetest.register_node("default:papyrus", {
minetest.register_node("default:bookshelf", { minetest.register_node("default:bookshelf", {
description = "Bookshelf", description = "Bookshelf",
tiles = {"default_wood.png", "default_wood.png", "default_bookshelf.png"}, tiles = {"default_wood.png", "default_wood.png", "default_bookshelf.png"},
is_ground_content = false,
groups = {choppy=3,oddly_breakable_by_hand=2,flammable=3}, groups = {choppy=3,oddly_breakable_by_hand=2,flammable=3},
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
}) })
@ -376,6 +384,7 @@ minetest.register_node("default:glass", {
inventory_image = minetest.inventorycube("default_glass.png"), inventory_image = minetest.inventorycube("default_glass.png"),
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
is_ground_content = false,
groups = {cracky=3,oddly_breakable_by_hand=3}, groups = {cracky=3,oddly_breakable_by_hand=3},
sounds = default.node_sound_glass_defaults(), sounds = default.node_sound_glass_defaults(),
}) })
@ -387,6 +396,7 @@ minetest.register_node("default:fence_wood", {
inventory_image = "default_fence.png", inventory_image = "default_fence.png",
wield_image = "default_fence.png", wield_image = "default_fence.png",
paramtype = "light", paramtype = "light",
is_ground_content = false,
selection_box = { selection_box = {
type = "fixed", type = "fixed",
fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7}, fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7},
@ -403,6 +413,7 @@ minetest.register_node("default:rail", {
wield_image = "default_rail.png", wield_image = "default_rail.png",
paramtype = "light", paramtype = "light",
walkable = false, walkable = false,
is_ground_content = false,
selection_box = { selection_box = {
type = "fixed", type = "fixed",
-- but how to specify the dimensions for curved and sideways rails? -- but how to specify the dimensions for curved and sideways rails?
@ -421,6 +432,7 @@ minetest.register_node("default:ladder", {
paramtype2 = "wallmounted", paramtype2 = "wallmounted",
walkable = false, walkable = false,
climbable = true, climbable = true,
is_ground_content = false,
selection_box = { selection_box = {
type = "wallmounted", type = "wallmounted",
--wall_top = = <default> --wall_top = = <default>
@ -596,6 +608,7 @@ minetest.register_node("default:torch", {
paramtype = "light", paramtype = "light",
paramtype2 = "wallmounted", paramtype2 = "wallmounted",
sunlight_propagates = true, sunlight_propagates = true,
is_ground_content = false,
walkable = false, walkable = false,
light_source = LIGHT_MAX-1, light_source = LIGHT_MAX-1,
selection_box = { selection_box = {
@ -618,6 +631,7 @@ minetest.register_node("default:sign_wall", {
paramtype = "light", paramtype = "light",
paramtype2 = "wallmounted", paramtype2 = "wallmounted",
sunlight_propagates = true, sunlight_propagates = true,
is_ground_content = false,
walkable = false, walkable = false,
selection_box = { selection_box = {
type = "wallmounted", type = "wallmounted",
@ -636,6 +650,10 @@ minetest.register_node("default:sign_wall", {
end, end,
on_receive_fields = function(pos, formname, fields, sender) on_receive_fields = function(pos, formname, fields, sender)
--print("Sign at "..minetest.pos_to_string(pos).." got "..dump(fields)) --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) local meta = minetest.get_meta(pos)
fields.text = fields.text or "" fields.text = fields.text or ""
minetest.log("action", (sender:get_player_name() or "").." wrote \""..fields.text.. minetest.log("action", (sender:get_player_name() or "").." wrote \""..fields.text..
@ -667,6 +685,7 @@ minetest.register_node("default:chest", {
paramtype2 = "facedir", paramtype2 = "facedir",
groups = {choppy=2,oddly_breakable_by_hand=2}, groups = {choppy=2,oddly_breakable_by_hand=2},
legacy_facedir_simple = true, legacy_facedir_simple = true,
is_ground_content = false,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
on_construct = function(pos) on_construct = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
@ -708,6 +727,7 @@ minetest.register_node("default:chest_locked", {
paramtype2 = "facedir", paramtype2 = "facedir",
groups = {choppy=2,oddly_breakable_by_hand=2}, groups = {choppy=2,oddly_breakable_by_hand=2},
legacy_facedir_simple = true, legacy_facedir_simple = true,
is_ground_content = false,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
@ -811,6 +831,7 @@ minetest.register_node("default:furnace", {
paramtype2 = "facedir", paramtype2 = "facedir",
groups = {cracky=2}, groups = {cracky=2},
legacy_facedir_simple = true, legacy_facedir_simple = true,
is_ground_content = false,
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
on_construct = function(pos) on_construct = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
@ -881,6 +902,7 @@ minetest.register_node("default:furnace_active", {
drop = "default:furnace", drop = "default:furnace",
groups = {cracky=2, not_in_creative_inventory=1,hot=1}, groups = {cracky=2, not_in_creative_inventory=1,hot=1},
legacy_facedir_simple = true, legacy_facedir_simple = true,
is_ground_content = false,
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
on_construct = function(pos) on_construct = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
@ -942,18 +964,13 @@ minetest.register_node("default:furnace_active", {
end, end,
}) })
function hacky_swap_node(pos,name) local function swap_node(pos,name)
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
local meta = minetest.get_meta(pos)
local meta0 = meta:to_table()
if node.name == name then if node.name == name then
return return
end end
node.name = name node.name = name
local meta0 = meta:to_table() minetest.swap_node(pos,node)
minetest.set_node(pos,node)
meta = minetest.get_meta(pos)
meta:from_table(meta0)
end end
minetest.register_abm({ minetest.register_abm({
@ -1007,7 +1024,7 @@ minetest.register_abm({
local percent = math.floor(meta:get_float("fuel_time") / local percent = math.floor(meta:get_float("fuel_time") /
meta:get_float("fuel_totaltime") * 100) meta:get_float("fuel_totaltime") * 100)
meta:set_string("infotext","Furnace active: "..percent.."%") 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)) meta:set_string("formspec",default.get_furnace_active_formspec(pos, percent))
return return
end end
@ -1027,7 +1044,7 @@ minetest.register_abm({
if fuel.time <= 0 then if fuel.time <= 0 then
meta:set_string("infotext","Furnace out of fuel") 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) meta:set_string("formspec", default.furnace_inactive_formspec)
return return
end end
@ -1035,7 +1052,7 @@ minetest.register_abm({
if cooked.item:is_empty() then if cooked.item:is_empty() then
if was_active then if was_active then
meta:set_string("infotext","Furnace is empty") 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) meta:set_string("formspec", default.furnace_inactive_formspec)
end end
return return
@ -1126,6 +1143,7 @@ minetest.register_node("default:obsidian_glass", {
drawtype = "glasslike", drawtype = "glasslike",
tiles = {"default_obsidian_glass.png"}, tiles = {"default_obsidian_glass.png"},
paramtype = "light", paramtype = "light",
is_ground_content = false,
sunlight_propagates = true, sunlight_propagates = true,
sounds = default.node_sound_glass_defaults(), sounds = default.node_sound_glass_defaults(),
groups = {cracky=3,oddly_breakable_by_hand=3}, groups = {cracky=3,oddly_breakable_by_hand=3},
@ -1145,6 +1163,7 @@ minetest.register_node("default:nyancat", {
"default_nc_side.png", "default_nc_back.png", "default_nc_front.png"}, "default_nc_side.png", "default_nc_back.png", "default_nc_front.png"},
paramtype2 = "facedir", paramtype2 = "facedir",
groups = {cracky=2}, groups = {cracky=2},
is_ground_content = false,
legacy_facedir_simple = true, legacy_facedir_simple = true,
sounds = default.node_sound_defaults(), sounds = default.node_sound_defaults(),
}) })
@ -1155,6 +1174,7 @@ minetest.register_node("default:nyancat_rainbow", {
"default_nc_rb.png", "default_nc_rb.png"}, "default_nc_rb.png", "default_nc_rb.png"},
paramtype2 = "facedir", paramtype2 = "facedir",
groups = {cracky=2}, groups = {cracky=2},
is_ground_content = false,
sounds = default.node_sound_defaults(), sounds = default.node_sound_defaults(),
}) })
@ -1167,6 +1187,7 @@ minetest.register_node("default:sapling", {
wield_image = "default_sapling.png", wield_image = "default_sapling.png",
paramtype = "light", paramtype = "light",
walkable = false, walkable = false,
is_ground_content = true,
selection_box = { selection_box = {
type = "fixed", type = "fixed",
fixed = {-0.3, -0.5, -0.3, 0.3, 0.35, 0.3} fixed = {-0.3, -0.5, -0.3, 0.3, 0.35, 0.3}
@ -1184,6 +1205,7 @@ minetest.register_node("default:apple", {
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
walkable = false, walkable = false,
is_ground_content = true,
selection_box = { selection_box = {
type = "fixed", type = "fixed",
fixed = {-0.2, -0.5, -0.2, 0.2, 0, 0.2} fixed = {-0.2, -0.5, -0.2, 0.2, 0, 0.2}
@ -1206,7 +1228,9 @@ minetest.register_node("default:dry_shrub", {
inventory_image = "default_dry_shrub.png", inventory_image = "default_dry_shrub.png",
wield_image = "default_dry_shrub.png", wield_image = "default_dry_shrub.png",
paramtype = "light", paramtype = "light",
waving = 1,
walkable = false, walkable = false,
is_ground_content = true,
buildable_to = true, buildable_to = true,
groups = {snappy=3,flammable=3,attached_node=1}, groups = {snappy=3,flammable=3,attached_node=1},
sounds = default.node_sound_leaves_defaults(), sounds = default.node_sound_leaves_defaults(),
@ -1225,6 +1249,7 @@ minetest.register_node("default:grass_1", {
wield_image = "default_grass_3.png", wield_image = "default_grass_3.png",
paramtype = "light", paramtype = "light",
walkable = false, walkable = false,
is_ground_content = true,
buildable_to = true, buildable_to = true,
groups = {snappy=3,flammable=3,flora=1,attached_node=1}, groups = {snappy=3,flammable=3,flora=1,attached_node=1},
sounds = default.node_sound_leaves_defaults(), sounds = default.node_sound_leaves_defaults(),

View File

@ -143,6 +143,13 @@ minetest.register_on_joinplayer(function(player)
default.player_set_model(player, "character.x") default.player_set_model(player, "character.x")
end) 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. -- Localize for better performance.
local player_set_animation = default.player_set_animation local player_set_animation = default.player_set_animation

View File

@ -113,14 +113,10 @@ function doors:register_door(name, def)
local p2 = minetest.get_node(pos).param2 local p2 = minetest.get_node(pos).param2
p2 = params[p2+1] p2 = params[p2+1]
local meta = minetest.get_meta(pos):to_table() minetest.swap_node(pos, {name=replace_dir, param2=p2})
minetest.set_node(pos, {name=replace_dir, param2=p2})
minetest.get_meta(pos):from_table(meta)
pos.y = pos.y-dir pos.y = pos.y-dir
meta = minetest.get_meta(pos):to_table() minetest.swap_node(pos, {name=replace, param2=p2})
minetest.set_node(pos, {name=replace, param2=p2})
minetest.get_meta(pos):from_table(meta)
end end
local function check_player_priv(pos, player) local function check_player_priv(pos, player)

View File

@ -189,6 +189,7 @@ minetest.register_node(":default:grass_1", {
inventory_image = "default_grass_3.png", inventory_image = "default_grass_3.png",
wield_image = "default_grass_3.png", wield_image = "default_grass_3.png",
paramtype = "light", paramtype = "light",
waving = 1,
walkable = false, walkable = false,
buildable_to = true, buildable_to = true,
drop = { drop = {
@ -220,6 +221,7 @@ for i=2,5 do
inventory_image = "default_grass_"..i..".png", inventory_image = "default_grass_"..i..".png",
wield_image = "default_grass_"..i..".png", wield_image = "default_grass_"..i..".png",
paramtype = "light", paramtype = "light",
waving = 1,
walkable = false, walkable = false,
buildable_to = true, buildable_to = true,
is_ground_content = true, is_ground_content = true,
@ -247,6 +249,7 @@ minetest.register_node(":default:junglegrass", {
inventory_image = "default_junglegrass.png", inventory_image = "default_junglegrass.png",
wield_image = "default_junglegrass.png", wield_image = "default_junglegrass.png",
paramtype = "light", paramtype = "light",
waving = 1,
walkable = false, walkable = false,
buildable_to = true, buildable_to = true,
is_ground_content = true, is_ground_content = true,
@ -365,6 +368,7 @@ for i=1,8 do
drawtype = "plantlike", drawtype = "plantlike",
tiles = {"farming_wheat_"..i..".png"}, tiles = {"farming_wheat_"..i..".png"},
paramtype = "light", paramtype = "light",
waving = 1,
walkable = false, walkable = false,
buildable_to = true, buildable_to = true,
is_ground_content = true, is_ground_content = true,
@ -450,6 +454,7 @@ for i=1,8 do
drawtype = "plantlike", drawtype = "plantlike",
tiles = {"farming_cotton_"..i..".png"}, tiles = {"farming_cotton_"..i..".png"},
paramtype = "light", paramtype = "light",
waving = 1,
walkable = false, walkable = false,
buildable_to = true, buildable_to = true,
is_ground_content = true, is_ground_content = true,

View File

@ -1 +0,0 @@
default

View File

@ -1,3 +1,143 @@
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", { minetest.register_tool("screwdriver:screwdriver", {
description = "Screwdriver", description = "Screwdriver",
inventory_image = "screwdriver.png", inventory_image = "screwdriver.png",
@ -7,7 +147,7 @@ minetest.register_tool("screwdriver:screwdriver", {
end, end,
}) })
for i=1,4,1 do for i = 1, 4 do
minetest.register_tool("screwdriver:screwdriver"..i, { minetest.register_tool("screwdriver:screwdriver"..i, {
description = "Screwdriver in Mode "..i, description = "Screwdriver in Mode "..i,
inventory_image = "screwdriver.png^tool_mode"..i..".png", inventory_image = "screwdriver.png^tool_mode"..i..".png",
@ -19,192 +159,4 @@ minetest.register_tool("screwdriver:screwdriver"..i, {
end, end,
}) })
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)
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"},
{"group: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