2x1 blocks (horizontal 2 boxes size) overlapping problem

Post Reply
chuia
New member
Posts: 5
Joined: Wed May 27, 2020 16:07
GitHub: ezemar
In-game: chuia

2x1 blocks (horizontal 2 boxes size) overlapping problem

by chuia » Post

Hi everyone!

I'm noob at modding... I need some help.

I'm creating a mod and I have a problem here related with 2x1 blocks (horizontal 2 boxes size).
For some reason, the second box is empty, yep, it contains an "air" node type,
When I put another node one node back from the other, an overlapping problem occurs between both nodes. See attached images for more info.

How can I avoid this overlapping? Can you help me, please?

My code:
Spoiler

Code: Select all


local two_x_four_cbox = {
    type = "fixed",
    fixed = {-0.5, -0.5, 1.5, 0.5, 0.5, -0.5}	
}

function make_node_def(name, model, tiles, selbox, colbox, not_in_creative_inventory)
	not_in_creative_inventory = not_in_creative_inventory or 1
	
	return {
		description = name,
		tiles = {
			tiles
		},
		drawtype = "mesh",
		paramtype = "light",
		paramtype2 = "facedir",
		sunlight_propagates = true,
		mesh = model,
		visual_scale = 0.5,
		wield_scale = {x = 0.5, y = 0.5, z = 0.5},
		groups = { snappy = 3 },
		selection_box = selbox,
		node_box = selbox,
		collision_box = colbox,
		sounds = node_sound_zeca_bricks_defaults()
	}
end

--register a brick-node for each texture on texture directory
for _, file_name in ipairs(files) do
	
	color_name = string.gsub(file_name, ".png", "")
	color_name_first_cap = firstToUpper(color_name)

	minetest.register_node("zeca_bricks:2x4_".. color_name .. "_brick", make_node_def( color_name_first_cap .." Brick 2x4","2x4_brick.obj", file_name, two_x_four_cbox, two_x_four_cbox))
end

Attached images:
Spoiler
screenshot_20221004_114438.png
screenshot_20221004_114438.png (246.71 KiB) Viewed 894 times
screenshot_20221004_114442.png
screenshot_20221004_114442.png (257.55 KiB) Viewed 894 times
Same occurs with another nodes:
Spoiler
screenshot_20221004_121240.png
screenshot_20221004_121240.png (446.68 KiB) Viewed 887 times
Thanks.

User avatar
Nathan.S
Member
Posts: 1147
Joined: Wed Sep 24, 2014 17:47
GitHub: NathanSalapat
IRC: NathanS21
In-game: NathanS21
Location: Bigsby Texas
Contact:

Re: 2x1 blocks (horizontal 2 boxes size) overlapping problem

by Nathan.S » Post

You need to check the second space manually when placing the node, and place an invisible node there as well to prevent any node from being placed in that location.
I use a function like this;

Code: Select all

fdir_table = {
   {  1,  0 },
   {  0, -1 },
   { -1,  0 },
   {  0,  1 },
   {  1,  0 },
   {  0, -1 },
   { -1,  0 },
   {  0,  1 },
}

function epic.space_to_side(pos, placed_node)
   local node = minetest.get_node(pos)
   local fdir = node.param2 % 32
   local pos2 = {x = pos.x + fdir_table[fdir+1][1], y=pos.y, z = pos.z + fdir_table[fdir+1][2]}
   local node2 = minetest.get_node(pos2)
   local node2def = minetest.registered_nodes[node2.name] or nil
   if not node2def.buildable_to then
      return false
   else
      local placed_node = placed_node or 'epic:empty'
      minetest.set_node(pos2,{name = placed_node, param2=fdir})
      return true
   end
end

function epic.remove_side_node(pos, oldnode)
   local fdir = oldnode.param2 % 32
   local pos2 = {x = pos.x + fdir_table[fdir+1][1], y=pos.y, z = pos.z + fdir_table[fdir+1][2]}
   local node2 = minetest.get_node(pos2).name
   if minetest.get_item_group(node2, 'empty_node') > 0 then
      minetest.remove_node(pos2)
   end
end
and call it in the node definition like this;

Code: Select all

after_place_node = function(pos, placer, itemstack)
      if not epic.space_to_side(pos) then
         minetest.remove_node(pos)
         return itemstack
      end
   end,
   after_dig_node = function(pos, oldnode, oldmetadata, digger)
      epic.remove_side_node(pos, oldnode)
   end,
This code checks the space to the side of the node when placing it, if it has something that isn't def_buildable_to it doesn't allow the node to be placed. If the node is successfully placed it also places a second invisible node. When the node is dug/removed the inverse is called, and the invisible node is removed.
I record Minetest videos, Mod reviews, Modding tutorials, and Lets plays.
Check out my website, and brand new Minetest Modding Course

chuia
New member
Posts: 5
Joined: Wed May 27, 2020 16:07
GitHub: ezemar
In-game: chuia

Re: 2x1 blocks (horizontal 2 boxes size) overlapping problem

by chuia » Post

Thank you very much, Nathan! now It works! :D

chuia
New member
Posts: 5
Joined: Wed May 27, 2020 16:07
GitHub: ezemar
In-game: chuia

Re: 2x1 blocks (horizontal 2 boxes size) overlapping problem

by chuia » Post

Nathan.S wrote:
Tue Oct 04, 2022 16:44
You need to check the second space manually when placing the node, and place an invisible node there as well to prevent any node from being placed in that location.
I use a function like this;

Code: Select all

fdir_table = {
   {  1,  0 },
   {  0, -1 },
   { -1,  0 },
   {  0,  1 },
   {  1,  0 },
   {  0, -1 },
   { -1,  0 },
   {  0,  1 },
}

function epic.space_to_side(pos, placed_node)
   local node = minetest.get_node(pos)
   local fdir = node.param2 % 32
   local pos2 = {x = pos.x + fdir_table[fdir+1][1], y=pos.y, z = pos.z + fdir_table[fdir+1][2]}
   local node2 = minetest.get_node(pos2)
   local node2def = minetest.registered_nodes[node2.name] or nil
   if not node2def.buildable_to then
      return false
   else
      local placed_node = placed_node or 'epic:empty'
      minetest.set_node(pos2,{name = placed_node, param2=fdir})
      return true
   end
end

function epic.remove_side_node(pos, oldnode)
   local fdir = oldnode.param2 % 32
   local pos2 = {x = pos.x + fdir_table[fdir+1][1], y=pos.y, z = pos.z + fdir_table[fdir+1][2]}
   local node2 = minetest.get_node(pos2).name
   if minetest.get_item_group(node2, 'empty_node') > 0 then
      minetest.remove_node(pos2)
   end
end
and call it in the node definition like this;

Code: Select all

after_place_node = function(pos, placer, itemstack)
      if not epic.space_to_side(pos) then
         minetest.remove_node(pos)
         return itemstack
      end
   end,
   after_dig_node = function(pos, oldnode, oldmetadata, digger)
      epic.remove_side_node(pos, oldnode)
   end,
This code checks the space to the side of the node when placing it, if it has something that isn't def_buildable_to it doesn't allow the node to be placed. If the node is successfully placed it also places a second invisible node. When the node is dug/removed the inverse is called, and the invisible node is removed.

Thank you very much, Nathan! now It works! :D

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest