Improve Silverin Plate placing logic

This commit is contained in:
Zenon Seth 2023-11-18 10:47:37 +00:00
parent 6a501bcf6b
commit 5b96c87cc0
2 changed files with 62 additions and 23 deletions

View File

@ -11,22 +11,22 @@ local sounds = default.node_sound_glass_defaults()
items["logistica:silverin"] = {
tiles = {
"logistica_silverin_nodebox.png",
"logistica_silverin_nodebox.png",
"logistica_silverin_nodebox.png^[transformFX",
"logistica_silverin_nodebox.png^[transformFX",
"logistica_silverin_nodebox.png",
"logistica_silverin_nodebox.png",
},
drawtype = "nodebox",
paramtype = "light",
"logistica_silverin_nodebox.png",
"logistica_silverin_nodebox.png",
"logistica_silverin_nodebox.png^[transformFX",
"logistica_silverin_nodebox.png^[transformFX",
"logistica_silverin_nodebox.png",
"logistica_silverin_nodebox.png",
},
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
node_box = {
type = "fixed",
fixed = {
{-0.25, -0.50, -0.25, 0.25, 0.50, 0.25}
}
},
node_box = {
type = "fixed",
fixed = {
{-0.25, -0.50, -0.25, 0.25, 0.50, 0.25}
}
},
use_texture_alpha = "blend",
groups = crystalGroups,
sounds = sounds,
@ -37,20 +37,43 @@ items["logistica:silverin"] = {
items["logistica:silverin_plate"] = {
tiles = { "logistica_silverin_plate.png" },
drawtype = "nodebox",
paramtype = "light",
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
node_box = {
type = "fixed",
fixed = {
{-0.50, -0.50, -0.50, 0.50, -7/16, 0.50}
}
},
node_box = {
type = "fixed",
fixed = {
{-0.50, -0.50, -0.50, 0.50, -7/16, 0.50}
}
},
groups = { cracky = 2 },
sounds = logistica.node_sound_metallic(),
description = S("Silverin Plate"),
inventory_image = "logistica_silverin_plate_inv.png",
wield_image = "logistica_silverin_plate_inv.png",
stack_max = 99,
after_place_node = function(pos, placer, itemstack, pointed_thing)
local rotNeeded = true
local node = minetest.get_node(pos)
if pointed_thing.type == "node" then
local pointedNode = minetest.get_node(pointed_thing.under)
if pointedNode.name == "logistica:silverin_plate" then
node.param2 = pointedNode.param2
minetest.swap_node(pos, node)
rotNeeded = false
end
end
if rotNeeded then
if placer:is_player() then
local lookDir = placer:get_look_dir()
if placer:get_player_control().sneak then
lookDir = vector.multiply(lookDir, -1)
end
node.param2 = logistica.dir_to_facedir(lookDir)
minetest.swap_node(pos, node)
end
end
end,
}
-- items["logistica:silverin_block"] = {

View File

@ -82,4 +82,20 @@ function logistica.get_front_face_object_info(param2)
rot.y = pos.forward.y
rot.z = pos.forward.z
return rot
end
-- given a direction tries to return a facedir int such that the bottom of block would be facing that direction
function logistica.dir_to_facedir(dir)
local x,y,z = dir.x, dir.y, dir.z
local absX, absY, absZ = math.abs(x), math.abs(y), math.abs(z)
local mostlyX = absX > absY and absX > absZ
local mostlyZ = absZ > absX and absZ > absY
if mostlyX then
if x > 0 then return 15 else return 12 end
elseif mostlyZ then
if z > 0 then return 8 else return 4 end
else -- mostlyY
if y > 0 then return 20 else return 0 end
end
end