Skip to content

Commit

Permalink
Fix banister replacing blocks; Fixes #1493 (#1663)
Browse files Browse the repository at this point in the history
fix banister placement next to another one by updating
the placement function from the source (the old function used to
place the banister type that next to it, not one in the player's
hand). Closes #1493
  • Loading branch information
Doloment authored Sep 14, 2024
1 parent 299ec1c commit 26c95a8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
28 changes: 15 additions & 13 deletions mods/lord/Blocks/lord_homedecor/handlers/expansion.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local S = minetest.get_translator("lord_homedecor")

-- vectors to place one node next to or behind another

lord_homedecor.fdir_to_right = {
Expand Down Expand Up @@ -244,7 +246,6 @@ local function is_same_banister_at(pos, compared_name)
return def_name == node_name
end


--- @param itemstack ItemStack
--- @param placer Player
--- @param pointed_thing pointed_thing
Expand All @@ -254,22 +255,32 @@ function lord_homedecor.place_banister(itemstack, placer, pointed_thing)

local pos = select_node(pointed_thing)
if not pos then return itemstack end
local node = minetest.get_node(pos)
local def = minetest.registered_nodes[node.name]


local fdir = minetest.dir_to_facedir(placer:get_look_dir())
local meta = itemstack:get_meta()
local pindex = meta:get_int("palette_index")

local abovepos = { x=pos.x, y=pos.y+1, z=pos.z }
local abovenode = minetest.get_node(abovepos)

local adef = minetest.registered_nodes[abovenode.name]
local placer_name = placer:get_player_name()

if not (def and def.buildable_to) and not is_same_banister_at(pos, itemstack:get_name()) then
minetest.chat_send_player(placer_name, S("Cannot place - the space is occupied by another block!"))
return itemstack
end

if not (adef and adef.buildable_to) then
minetest.chat_send_player(placer_name, "Not enough room - the upper space is occupied!" )
minetest.chat_send_player(placer_name, S("Not enough room - the upper space is occupied!"))
return itemstack
end

if minetest.is_protected(abovepos, placer_name) then
minetest.chat_send_player(placer_name, "Someone already owns that spot." )
minetest.chat_send_player(placer_name, S("Someone already owns that spot."))
return itemstack
end

Expand Down Expand Up @@ -356,14 +367,6 @@ function lord_homedecor.place_banister(itemstack, placer, pointed_thing)
fdir = right_fwd_node.param2
pos = fwd_pos
new_place_name = string.replace(right_fwd_node.name, "_diagonal_.-$", "_horizontal")

-- try to follow a horizontal with another of the same
elseif left_node and string.find(left_node.name, "lord_homedecor:banister_.*_horizontal") then
fdir = left_node.param2
new_place_name = left_node.name
elseif right_node and string.find(right_node.name, "lord_homedecor:banister_.*_horizontal") then
fdir = right_node.param2
new_place_name = right_node.name
end

-- manually invert left-right orientation
Expand All @@ -376,11 +379,10 @@ function lord_homedecor.place_banister(itemstack, placer, pointed_thing)
end

local take_item = not is_same_banister_at(pos, new_place_name)
minetest.set_node(pos, {name = new_place_name, param2 = fdir})
if take_item then
itemstack:take_item()
end

minetest.set_node(pos, {name = new_place_name, param2 = fdir+pindex})
return itemstack
end

3 changes: 3 additions & 0 deletions mods/lord/Blocks/lord_homedecor/locale/lord_homedecor.ru.tr
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,6 @@ Wooden Shutter (Grey)=Деревянные ставни @n(Серые)
Wooden Shutter (White)=Деревянные ставни @n(Белые)
Stained Glass=Витраж
Window flowerbox=Цветочный ящик для окна
Cannot place - the space is occupied by another block!=Невозможно установить: здесь находится другой блок!
Not enough room - the upper space is occupied!=Недостаточно места: сверху находится блок!
Someone already owns that spot.=Это место защищено.

0 comments on commit 26c95a8

Please sign in to comment.