Fixed and improved opening/closing doors. Fixed bounding boxes of corner dark rusty fence

master
Andrey2470T 2022-08-22 00:31:20 +03:00
parent 18f8757e26
commit d8740e1773
8 changed files with 80 additions and 68 deletions

View File

@ -29,7 +29,6 @@ function helpers.upper_first_letters(s)
local new_s = ""
for substr in s:gmatch("%a+") do
--minetest.debug("substr: " .. substr)
new_s = new_s .. substr:sub(1, 1):upper() .. substr:sub(2) .. " "
end

View File

@ -7,9 +7,6 @@ function connecting.are_nodes_identical(pos1, pos2)
local add_props1 = minetest.registered_nodes[minetest.get_node(pos1).name].add_properties
local add_props2 = minetest.registered_nodes[minetest.get_node(pos2).name].add_properties
minetest.debug("cmn1: " .. dump(add_props1 and add_props1.common_name or nil))
minetest.debug("cmn2: " .. dump(add_props2 and add_props2.common_name or nil))
return add_props1 and add_props2 and add_props1.common_name == add_props2.common_name
end
@ -45,19 +42,16 @@ function connecting.replace_node_to(pos, disconnect, cmn_name)
local rel_rot = 0
if connecting.are_nodes_identical(ord_shifts[1], pos) then
minetest.debug("identical")
target_node = "edge"
rel_rot = 180
end
if connecting.are_nodes_identical(ord_shifts[2], pos) then
minetest.debug("identical")
target_node = target_node == "edge" and "corner" or "edge"
rel_rot = 90
end
if connecting.are_nodes_identical(ord_shifts[3], pos) then
minetest.debug("identical")
if target_node == "corner" then
target_node = "edge_middle"
elseif target_node == "edge" then
@ -69,7 +63,6 @@ function connecting.replace_node_to(pos, disconnect, cmn_name)
end
if connecting.are_nodes_identical(ord_shifts[4], pos) then
minetest.debug("identical")
if target_node == "edge_middle" then
target_node = "off_edge"
rel_rot = 0
@ -87,7 +80,7 @@ function connecting.replace_node_to(pos, disconnect, cmn_name)
rel_rot = -90
end
end
--minetest.debug("target_node: " .. target_node)
target_node = target_node ~= "" and "_" .. target_node or ""
if not disconnect and target_node == "" then
@ -173,7 +166,7 @@ function connecting.directional_replace_node_to(pos, dir, side, disconnect, cmn_
target_node = "middle"
end
end
--minetest.debug("target_node: " .. target_node)
target_node = target_node ~= "" and "_" .. target_node or ""
if not disconnect and target_node == "" then
@ -188,7 +181,7 @@ end
-- *type* can be "horizontal", "vertical", "pair", "sofa"
function connecting.update_adjacent_nodes_connection(pos, type, disconnect, old_node)
local node = minetest.get_node(pos)
--minetest.debug("update_adjacent_nodes_connection()")
if not disconnect then
local add_props = minetest.registered_nodes[node.name].add_properties
local modname = node.name:find("multidecor:")
@ -279,6 +272,9 @@ function connecting.register_connect_parts(def)
c_def.groups = {not_in_creative_inventory=1}
end
if name == "corner" and def.add_properties.corner_bounding_boxes then
c_def.bounding_boxes = def.add_properties.corner_bounding_boxes
end
c_def.callbacks.on_construct = nil
register.register_furniture_unit(def.add_properties.common_name .. "_" .. name, c_def)

View File

@ -2,58 +2,44 @@ multidecor.doors = {}
doors = multidecor.doors
-- Rotates an entity corresponding to the 'dir'
function doors.rotate(obj, dir, rotate_p)
if not obj:get_luaentity() then
return
end
-- Returns new position rotated around 'rotate_p' and rotation correponding to "dir"
function doors.rotate(pos, dir, rotate_p)
local y_rot = vector.dir_to_rotation(dir).y
local rel_pos = pos - rotate_p
local p = vector.copy(rotate_p)
local rel_pos = obj:get_pos() - p
local y_rel_pos_r = vector.dir_to_rotation(rel_pos).y
rel_pos = vector.rotate_around_axis(rel_pos, {x=0, y=1, z=0}, y_rot)
obj:set_pos(rotate_p + rel_pos)
local obj_rot = obj:get_rotation()
obj:set_rotation({x=obj_rot.x, y=y_rot, z=obj_rot.z})
return rotate_p + rel_pos, {x=0, y=y_rot, z=0}
end
-- Rotates obj's collision/selection boxes corresponding to the 'dir'
function doors.rotate_bbox(obj, dir, rotate_cbox)
if not obj:get_luaentity() then
return
end
-- Returns rotated collisionbox and selectionbox corresponding to "dir"
function doors.rotate_bbox(sbox, cbox, dir)
local y_rot = vector.dir_to_rotation(dir).y
local sel_box = minetest.registered_entities[obj:get_luaentity().name].selectionbox
local box = {
min = {x=sel_box[1], y=sel_box[2], z=sel_box[3]},
max = {x=sel_box[4], y=sel_box[5], z=sel_box[6]}
min = {x=sbox[1], y=sbox[2], z=sbox[3]},
max = {x=sbox[4], y=sbox[5], z=sbox[6]}
}
box.min = vector.rotate_around_axis(box.min, {x=0, y=1, z=0}, y_rot)
box.max = vector.rotate_around_axis(box.max, {x=0, y=1, z=0}, y_rot)
local sbox = {box.min.x, box.min.y, box.min.z, box.max.x, box.max.y, box.max.z}
obj:set_properties({selectionbox=sbox})
obj:get_luaentity().bbox = sbox
local new_sbox = {box.min.x, box.min.y, box.min.z, box.max.x, box.max.y, box.max.z}
local new_cbox
if rotate_cbox then
local col_box = minetest.registered_entities[obj:get_luaentity().name].collisionbox
local cbox = {
min = {x=col_box[1], y=col_box[2], z=col_box[3]},
max = {x=col_box[4], y=col_box[5], z=col_box[6]}
if cbox then
box = {
min = {x=cbox[1], y=cbox[2], z=cbox[3]},
max = {x=cbox[4], y=cbox[5], z=cbox[6]}
}
cbox.min = vector.rotate_around_axis(cbox.min, {x=0, y=1, z=0}, y_rot)
cbox.max = vector.rotate_around_axis(cbox.max, {x=0, y=1, z=0}, y_rot)
box.min = vector.rotate_around_axis(box.min, {x=0, y=1, z=0}, y_rot)
box.max = vector.rotate_around_axis(box.max, {x=0, y=1, z=0}, y_rot)
obj:set_properties({collisionbox={cbox.min.x, cbox.min.y, cbox.min.z, cbox.max.x, cbox.max.y, cbox.max.z}})
new_cbox = {box.min.x, box.min.y, box.min.z, box.max.x, box.max.y, box.max.z}
end
return new_sbox, new_cbox
end
-- Activates obj rotation from 'self.start_v' to 'self.end_v' or vice versa depending on 'dir_sign' value
@ -79,7 +65,6 @@ function doors.smooth_rotate_step(self, dtime, vel, acc)
rot.y = helpers.clamp(self.start_v, self.end_v, rot.y)
if math.abs(target_rot-rot.y) <= math.rad(10) then
minetest.debug("the door is rotated!")
self.dir = 0
self.step_c = nil
self.object:set_rotation({x=rot.x, y=target_rot, z=rot.z})
@ -89,7 +74,7 @@ function doors.smooth_rotate_step(self, dtime, vel, acc)
self.step_c = self.step_c and self.step_c+acc or 1
-- Rotation speed is 60 degrees/sec
local sign = self.start_v > self.end_v and -1 or 1
local new_rot = self.dir*sign*math.rad(vel)*dtime*0.5*self.step_c
local new_rot = self.dir*sign*math.rad(vel)*dtime*self.step_c
self.object:set_rotation({x=rot.x, y=rot.y+new_rot, z=rot.z})
end
@ -104,28 +89,36 @@ function doors.convert_to_entity(pos)
local obj_name = is_open and node.name:gsub("_open", "") or node.name
local shift = {x=pos.x+0.495, y=pos.y, z=pos.z+0.45}
local obj = minetest.add_entity(shift, obj_name)
if is_open then
dir = vector.rotate_around_axis(dir, {x=0, y=1, z=0}, -math.pi/2)
end
doors.rotate(obj, dir, pos)
doors.rotate_bbox(obj, dir, true)
local shift = {x=pos.x+0.495, y=pos.y, z=pos.z+0.45}
local new_pos, rot = doors.rotate(shift, dir, pos)
local def = minetest.registered_entities[obj_name]
local sbox, cbox = doors.rotate_bbox(def.selectionbox, def.collisionbox, dir)
local y_rot = vector.dir_to_rotation(dir).y
local self = obj:get_luaentity()
self.start_v = y_rot
self.end_v = y_rot+math.pi/2
local start_r, end_r = y_rot, y_rot+math.pi/2
if is_open then
dir = vector.rotate_around_axis(dir, {x=0, y=1, z=0}, math.pi/2)
doors.rotate(obj, dir, shift)
doors.rotate_bbox(obj, dir, true)
local new_pos2, rot2 = doors.rotate(new_pos, dir, shift)
rot = rot2
end
local obj = minetest.add_entity(new_pos, obj_name)
obj:set_rotation(rot)
obj:set_properties({
collisionbox = cbox,
selectionbox = sbox
})
local self = obj:get_luaentity()
self.start_v = start_r
self.end_v = end_r
return obj
end
@ -161,7 +154,16 @@ local function default_door_on_rightclick(pos)
end
local function default_entity_door_on_rightclick(self)
self.dir = self.dir * -1
local dir_sign = 0
if self.action == "open" then
dir_sign = -1
self.action = "close"
else
dir_sign = 1
self.action = "open"
end
doors.smooth_rotate(self.object, dir_sign)
end
local function default_entity_door_on_activate(self, staticdata)
@ -234,13 +236,21 @@ function register.register_door(name, base_def, add_def, craft_def)
register.register_furniture_unit(name .. "_open", c_def2)
local bbox = table.copy(base_def.bounding_boxes[1])
local z_center = (bbox[3]+bbox[6])/2
bbox[3] = bbox[3] - z_center
bbox[6] = bbox[6] - z_center
bbox[1] = bbox[1] - 0.5
bbox[4] = bbox[4] - 0.5
minetest.register_entity(":multidecor:" .. name, {
visual = "mesh",
visual_size = {x=5, y=5, z=5},
textures = base_def.tiles,
mesh = c_def2.add_properties.door.mesh_activated,
collisionbox = base_def.bounding_boxes[1],
selectionbox = base_def.bounding_boxes[1],
physical = true,
collisionbox = bbox,
selectionbox = bbox,
use_texture_alpha = base_def.use_texture_alpha == "blend",
backface_culling = false,
static_save = true,

View File

@ -33,7 +33,10 @@ end
-- Rotates the shelf 'obj' around 'pos' position of the node
function shelves.rotate_shelf(pos, obj, is_drawer, move_dist)
local dir = helpers.get_dir(pos)
doors.rotate(obj, dir, pos)
--doors.rotate(obj, dir, pos)
local new_pos, rot = doors.rotate(obj:get_pos(), dir, pos)
obj:set_pos(new_pos)
obj:set_rotation(rot)
local self = obj:get_luaentity()
if is_drawer then
@ -59,7 +62,12 @@ function shelves.rotate_shelf_bbox(obj)
vector.round(vector.subtract(obj:get_pos(), self.connected_to.pos)) == vector.round(shelf.pos2) or self.is_flip_x_scale then
dir = vector.rotate_around_axis(dir, {x=0, y=1, z=0}, math.pi)
end
doors.rotate_bbox(obj, dir, false)
local def = minetest.registered_entities[self.name]
local sbox, cbox = doors.rotate_bbox(def.selectionbox, nil, dir)
obj:set_properties({
collisionbox = cbox,
selectionbox = sbox
})
end
-- Animates opening or closing the shelf 'obj'. The action directly depends on 'dir_sign' value ('1' is open, '-1' is close)

View File

@ -16,7 +16,7 @@ register.register_door("high_dark_rusty_gate", {
door = {
mesh_open = "multidecor_high_dark_rusty_gate_open.b3d",
mesh_activated = "multidecor_high_dark_rusty_gate_activated.b3d",
vel = 90 -- degrees per sec
vel = 100 -- degrees per sec
}
},
{

View File

@ -20,6 +20,10 @@ register.register_hedge("dark_rusty_fence", {
["right_side"] = "multidecor_dark_rusty_fence_1.b3d",
["middle"] = "multidecor_dark_rusty_fence_3.b3d",
["corner"] = "multidecor_dark_rusty_fence_4.b3d"
},
corner_bounding_boxes = {
{-0.5, -0.5, 0.4, 0.5, 0.5, 0.5},
{-0.5, -0.5, -0.5, -0.4, 0.5, 0.4}
}
},
{

View File

@ -49,7 +49,6 @@ minetest.register_node(":multidecor:modern_floor_clock", {
local meta = minetest.get_meta(pos)
if meta:get_string("is_activated") == "false" then
minetest.debug("activate")
wheel:set_animation({x=1, y=40}, 25.0, 0.0, true)
meta:set_string("is_activated", "true")
else
@ -199,8 +198,6 @@ local on_rightclick_flowerpot = function(pos, node, clicker, itemstack)
local itemname = itemstack:get_name()
local is_flowers_mod_i, is_flowers_mod_i2 = itemname:find("flowers:")
minetest.debug("is_flowers_mod_i: " .. dump(is_flowers_mod_i))
minetest.debug("group: " .. minetest.get_item_group(itemname, "flower"))
if not is_flowers_mod_i or minetest.get_item_group(itemname, "flower") == 0 then
return
end
@ -230,7 +227,6 @@ local on_rightclick_flowerpot_with_flower = function(pos, node, clicker, itemsta
minetest.set_node(pos, {name=node.name:gsub("_with_flower_" .. current_flower, ""), param2=node.param2})
end
minetest.debug("current_flower: " .. current_flower)
clicker:get_inventory():add_item("main", "flowers:" .. current_flower)
return itemstack

View File

@ -12,7 +12,6 @@ register.register_table("kitchen_modern_wooden_table", {
connecting.update_adjacent_nodes_connection(pos, "horizontal")
end,
after_dig_node = function(pos, oldnode)
minetest.debug("1.2")
connecting.update_adjacent_nodes_connection(pos, "horizontal", true, oldnode)
end
}