[SOLVED] add backface culling after node registration?

Post Reply
User avatar
TumeniNodes
Member
Posts: 2943
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes
IRC: tumeninodes
In-game: TumeniNodes
Location: in the dark recesses of the mind
Contact:

[SOLVED] add backface culling after node registration?

by TumeniNodes » Post

How can backface_culling = true be defined after node registration?

I have four models/nodes, which are shared by different textures.
Some of those textures need to use backface culling, and some do not, so I would like to define the ones which do at the end of the code.
Just not sure how it is done. I will put up snippets of the code as an example

this is one of the model/node

Code: Select all

minetest.register_node("c_doors:" ..name.. "_Ldoor", {
	description = desc.. " Door (left)",
	inventory_image = "doors_item_" ..name.. ".png",
	wield_image = "doors_item_" ..name.. ".png",
	drawtype = "mesh",
	mesh = "c_door_L.obj",
	tiles = {{name = "doors_door_" ..name.. ".png",}},
	use_texture_alpha = true,
	paramtype = "light",
	paramtype2 = "facedir",
	on_rotate = screwdriver.rotate_simple,
	sunlight_propogates = true,
	is_ground_content = false,
	groups = mat_groups,
	sounds = mat_sound,
	selection_box = {
		type = "fixed",
		fixed = {
			{-0.5, -0.5, -0.0625, 0.5, 1.5, 0.0625},
		},
	},
	collision_box = {
		type = "fixed",
		fixed = {
			{-0.5, -0.5, -0.0625, 0.5, 1.5, 0.0625},
		},
	},
	on_rightclick = function(pos, node, puncher)
		minetest.swap_node(pos, {name = "c_doors:" ..name.. "_Ldoor_open", param2 = node.param2})
		minetest.sound_play(door_sound.."_open", {gain = 0.20, max_hear_distance = 2})
	end,
})
The wood and steel door textures require backface_culling = true, when they are using the models
Last edited by TumeniNodes on Wed Jan 24, 2018 02:18, edited 1 time in total.
A Wonderful World

User avatar
stu
Member
Posts: 923
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11
Location: United Kingdom

Re: add backface culling after node registration?

by stu » Post

I'm not entirely sure what you are trying to do here but I think you might be looking for `minetest.override_item` ?

https://github.com/minetest/minetest/bl ... .txt#L2551

User avatar
TumeniNodes
Member
Posts: 2943
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes
IRC: tumeninodes
In-game: TumeniNodes
Location: in the dark recesses of the mind
Contact:

Re: add backface culling after node registration?

by TumeniNodes » Post

Ahh, I should have added more of the code, and explained more.

I have been tweaking my c_doors mod (centered doors)

I have failed at my attempts to abuse the doors code to make it take the new positions so, I am sticking to the original code for c_doors..

The 4 models used in c_doors, will be shared by the textures from the default/doors

My only problem is, the steel and wood doors textures require using backface culling - true, the glass doors do not.
But, I do not want to have to register 4 nodes, for each door texture.
Which is why I am hoping that I can, in some way, add code to the end, which will check to see if the steel or wood door textures are being used, and set backface_culling = true to them? (I hope that makes sense, I tend to overcomplicate myself)

Here is the full code for the c_doors

Code: Select all

screwdriver = screwdriver or {}

c_doors = {}

-- Register Door Nodes
c_doors.door = {
    {"steel", "Steel", {cracky = 1, door =1}, default.node_sound_metal_defaults(), "c_doors_metal", "default:steelblock"},
	{"obsidian_glass", "Obsidian Glass", {cracky = 1, door =1}, default.node_sound_glass_defaults(), "c_doors_glass", "default:obsidian_glass"},
	{"glass", "Glass", {cracky = 3, door =1}, default.node_sound_glass_defaults(), "c_doors_glass", "default:glass"},
	{"wood", "Wood", {choppy = 2, door =1}, default.node_sound_wood_defaults(), "doors_door", "default:wood"},
}

for _, row in ipairs(c_doors.door) do
	local name = row[1]
	local desc = row[2]
	local mat_groups = row[3]
	local mat_sound = row[4]
	local door_sound = row[5]
	local craft_material = row[6]

minetest.register_node("c_doors:" ..name.. "_Ldoor", {
	description = desc.. " Door (left)",
	inventory_image = "doors_item_" ..name.. ".png",
	wield_image = "doors_item_" ..name.. ".png",
	drawtype = "mesh",
	mesh = "c_door_L.obj",
	tiles = {{name = "doors_door_" ..name.. ".png",}},
	use_texture_alpha = true,
	paramtype = "light",
	paramtype2 = "facedir",
	on_rotate = screwdriver.rotate_simple,
	sunlight_propogates = true,
	is_ground_content = false,
	groups = mat_groups,
	sounds = mat_sound,
	selection_box = {
		type = "fixed",
		fixed = {
			{-0.5, -0.5, -0.0625, 0.5, 1.5, 0.0625},
		},
	},
	collision_box = {
		type = "fixed",
		fixed = {
			{-0.5, -0.5, -0.0625, 0.5, 1.5, 0.0625},
		},
	},
	on_rightclick = function(pos, node, puncher)
		minetest.swap_node(pos, {name = "c_doors:" ..name.. "_Ldoor_open", param2 = node.param2})
		minetest.sound_play(door_sound.."_open", {gain = 0.20, max_hear_distance = 2})
	end,
})

minetest.register_node("c_doors:" ..name.. "_Ldoor_open", {
	drawtype = "mesh",
	mesh = "c_door_L_open.obj",
	tiles = {{name = "doors_door_" ..name.. ".png"}},
	use_texture_alpha = true,
	paramtype = "light",
	paramtype2 = "facedir",
	on_rotate = screwdriver.rotate_simple,
	legacy_facedir_simple = true,
	sunlight_propogates = true,
	is_ground_content = false,
	groups = mat_groups,
	drop = "c_doors:" ..name.. "_Ldoor",
	sounds = mat_sound,
	selection_box = {
		type = "fixed",
		fixed = {
			{-0.5, -0.5, -0.9375, -0.375, 1.5, 0.0625},
		},
	},
	collision_box = {
		type = "fixed",
		fixed = {
			{-0.5, -0.5, -0.9375, -0.375, 1.5, 0.0625},
		},
	},
	on_rightclick = function(pos, node, puncher)
		minetest.swap_node(pos, {name = "c_doors:" ..name.. "_Ldoor", param2 = node.param2})
		minetest.sound_play(door_sound.."_close", {gain = 0.15, max_hear_distance = 2})
	end,
})

minetest.register_node("c_doors:" ..name.. "_Rdoor", {
	description = desc.. " Door (right)",
	inventory_image = "doors_item_" ..name.. ".png",
	wield_image = "doors_item_" ..name.. ".png",
	drawtype = "mesh",
	mesh = "c_door_R.obj",
	tiles = {{name = "doors_door_" ..name.. ".png"}},
	use_texture_alpha = true,
	paramtype = "light",
	paramtype2 = "facedir",
	on_rotate = screwdriver.rotate_simple,
	sunlight_propogates = true,
	is_ground_content = false,
	groups = mat_groups,
	sounds = mat_sound,
	selection_box = {
		type = "fixed",
		fixed = {
			{-0.5, -0.5, -0.0625, 0.5, 1.5, 0.0625},
		},
	},
	collision_box = {
		type = "fixed",
		fixed = {
			{-0.5, -0.5, -0.0625, 0.5, 1.5, 0.0625},
		},
	},
	on_rightclick = function(pos, node, puncher)
		minetest.swap_node(pos, {name = "c_doors:" ..name.. "_Rdoor_open", param2 = node.param2})
		minetest.sound_play(door_sound.."_open", {gain = 0.20, max_hear_distance = 2})
	end,
})

minetest.register_node("c_doors:" ..name.. "_Rdoor_open", {
	drawtype = "mesh",
	mesh = "c_door_R_open.obj",
	tiles = {{name = "doors_door_" ..name.. ".png"}},
	use_texture_alpha = true,
	paramtype = "light",
	paramtype2 = "facedir",
	on_rotate = screwdriver.rotate_simple,
	legacy_facedir_simple = true,
	sunlight_propogates = true,
	is_ground_content = false,
	groups = mat_groups,
	drop = "c_doors:" ..name.. "_Rdoor",
	sounds = mat_sound,
	selection_box = {
		type = "fixed",
		fixed = {
			{0.375, -0.5, -0.9375, 0.5, 1.5, 0.0625},
		},
	},
	collision_box = {
		type = "fixed",
		fixed = {
			{0.375, -0.5, -0.9375, 0.5, 1.5, 0.0625},
		},
	},
	on_rightclick = function(pos, node, puncher)
		minetest.swap_node(pos, {name = "c_doors:" ..name.. "_Rdoor", param2 = node.param2})
		minetest.sound_play(door_sound.."_close", {gain = 0.15, max_hear_distance = 2})
	end,
})

--
-- Crafting
--
minetest.register_craft({
	output = "c_doors:" ..name.. "_Ldoor",
	recipe = {
		{"", craft_material , ""},
		{"", craft_material, ""},
		{"", craft_material , ""},
	}
})

minetest.register_craft({
	output = "c_doors:" ..name.. "_Rdoor",
	recipe = {
		{"c_doors:" ..name.. "_Ldoor"},
	}
})

minetest.register_craft({
	output = "c_doors:" ..name.. "_Ldoor",
	recipe = {
		{"c_doors:" ..name.. "_Rdoor"},
	}
})

end
I thought I might be able to use some adaptation of this code

Code: Select all

	local i = name:find(":")
	local modname = name:sub(1, i - 1)
	if not def.tiles then
		if def.protected then
			def.tiles = {{name = "doors_door_steel.png", backface_culling = true}}
		else
			def.tiles = {{name = "doors_door_wood.png", backface_culling = true}}
		end
		minetest.log("warning", modname .. " registered door \"" .. name .. "\" " ..
				"using deprecated API method \"doors.register_door()\" but " ..
				"did not provide the \"tiles\" parameter. A fallback tiledef " ..
				"will be used instead.")
	end
(which is in default/doors) to achieve this but my coding skills are.... (pht lets be serious.... what coding skills???)
But I have failed miserably with each attempt

If I set backface_culling = true when registering these nodes, it poses a visual problem with glass doors
If I do not, then wood and steel doors suffer visual problems
So I am hoping it can be set to those specific textures only when they are used
A Wonderful World

User avatar
TumeniNodes
Member
Posts: 2943
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes
IRC: tumeninodes
In-game: TumeniNodes
Location: in the dark recesses of the mind
Contact:

Re: add backface culling after node registration?

by TumeniNodes » Post

If this can hopefully be resolved, I also plan to add support for other mods with doors (such as My Doors)
A Wonderful World

User avatar
paramat
Developer
Posts: 3700
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat
IRC: paramat
Location: UK

Re: add backface culling after node registration?

by paramat » Post


User avatar
TumeniNodes
Member
Posts: 2943
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes
IRC: tumeninodes
In-game: TumeniNodes
Location: in the dark recesses of the mind
Contact:

Re: add backface culling after node registration?

by TumeniNodes » Post

Hmm, that should work, I'll give that method a try. Thank you
A Wonderful World

User avatar
TumeniNodes
Member
Posts: 2943
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes
IRC: tumeninodes
In-game: TumeniNodes
Location: in the dark recesses of the mind
Contact:

Re: add backface culling after node registration?

by TumeniNodes » Post

meh, that did not work but, hurray..., I figured it out, phew
it was so easy..., why did it take me this long to figure out? : /

Code: Select all

c_doors = {}

-- Register Door Nodes
c_doors.door = {
    {"steel", "Steel", {cracky = 1, door =1}, default.node_sound_metal_defaults(), "c_doors_metal", {name = "doors_door_steel.png",backface_culling = true}, "default:steelblock"},
	{"obsidian_glass", "Obsidian Glass", {cracky = 1, door =1}, default.node_sound_glass_defaults(), "c_doors_glass", {name = "doors_door_obsidian_glass.png"},"default:obsidian_glass"},
	{"glass", "Glass", {cracky = 3, door =1}, default.node_sound_glass_defaults(), "c_doors_glass", {name = "doors_door_glass.png"}, "default:glass"},
	{"wood", "Wood", {choppy = 2, door =1}, default.node_sound_wood_defaults(), "doors_door", {name = "doors_door_wood.png",backface_culling = true}, "default:wood"},
}

for _, row in ipairs(c_doors.door) do
	local name = row[1]
	local desc = row[2]
	local mat_groups = row[3]
	local mat_sound = row[4]
	local door_sound = row[5]
    local door_tiles = row[6]
    local craft_material = row[7]

minetest.register_node("c_doors:" ..name.. "_Ldoor", {
	description = desc.. " Door (left)",
	inventory_image = "doors_item_" ..name.. ".png",
	wield_image = "doors_item_" ..name.. ".png",
	drawtype = "mesh",
	mesh = "c_door_L.obj",
	tiles = {door_tiles},
	use_texture_alpha = true,
	paramtype = "light",
	paramtype2 = "facedir",
	on_rotate = screwdriver.rotate_simple,
	sunlight_propogates = true,
	is_ground_content = false,
	groups = mat_groups,
	sounds = mat_sound,
	selection_box = {
		type = "fixed",
		fixed = {
			{-0.5, -0.5, -0.0625, 0.5, 1.5, 0.0625},
		},
	},
	collision_box = {
		type = "fixed",
		fixed = {
			{-0.5, -0.5, -0.0625, 0.5, 1.5, 0.0625},
		},
	},
	on_rightclick = function(pos, node, puncher)
		minetest.swap_node(pos, {name = "c_doors:" ..name.. "_Ldoor_open", param2 = node.param2})
		minetest.sound_play(door_sound.."_open", {gain = 0.20, max_hear_distance = 2})
	end,
})

minetest.register_node("c_doors:" ..name.. "_Ldoor_open", {
	drawtype = "mesh",
	mesh = "c_door_L_open.obj",
	tiles = {door_tiles},
	use_texture_alpha = true,
	paramtype = "light",
	paramtype2 = "facedir",
	on_rotate = screwdriver.rotate_simple,
	legacy_facedir_simple = true,
	sunlight_propogates = true,
	is_ground_content = false,
	groups = mat_groups,
	drop = "c_doors:" ..name.. "_Ldoor",
	sounds = mat_sound,
	selection_box = {
		type = "fixed",
		fixed = {
			{-0.5, -0.5, -0.9375, -0.375, 1.5, 0.0625},
		},
	},
	collision_box = {
		type = "fixed",
		fixed = {
			{-0.5, -0.5, -0.9375, -0.375, 1.5, 0.0625},
		},
	},
	on_rightclick = function(pos, node, puncher)
		minetest.swap_node(pos, {name = "c_doors:" ..name.. "_Ldoor", param2 = node.param2})
		minetest.sound_play(door_sound.."_close", {gain = 0.15, max_hear_distance = 2})
	end,
})

minetest.register_node("c_doors:" ..name.. "_Rdoor", {
	description = desc.. " Door (right)",
	inventory_image = "doors_item_" ..name.. ".png",
	wield_image = "doors_item_" ..name.. ".png",
	drawtype = "mesh",
	mesh = "c_door_R.obj",
	tiles = {door_tiles},
	use_texture_alpha = true,
	paramtype = "light",
	paramtype2 = "facedir",
	on_rotate = screwdriver.rotate_simple,
	sunlight_propogates = true,
	is_ground_content = false,
	groups = mat_groups,
	sounds = mat_sound,
	selection_box = {
		type = "fixed",
		fixed = {
			{-0.5, -0.5, -0.0625, 0.5, 1.5, 0.0625},
		},
	},
	collision_box = {
		type = "fixed",
		fixed = {
			{-0.5, -0.5, -0.0625, 0.5, 1.5, 0.0625},
		},
	},
	on_rightclick = function(pos, node, puncher)
		minetest.swap_node(pos, {name = "c_doors:" ..name.. "_Rdoor_open", param2 = node.param2})
		minetest.sound_play(door_sound.."_open", {gain = 0.20, max_hear_distance = 2})
	end,
})

minetest.register_node("c_doors:" ..name.. "_Rdoor_open", {
	drawtype = "mesh",
	mesh = "c_door_R_open.obj",
	tiles = {door_tiles},
	use_texture_alpha = true,
	paramtype = "light",
	paramtype2 = "facedir",
	on_rotate = screwdriver.rotate_simple,
	legacy_facedir_simple = true,
	sunlight_propogates = true,
	is_ground_content = false,
	groups = mat_groups,
	drop = "c_doors:" ..name.. "_Rdoor",
	sounds = mat_sound,
	selection_box = {
		type = "fixed",
		fixed = {
			{0.375, -0.5, -0.9375, 0.5, 1.5, 0.0625},
		},
	},
	collision_box = {
		type = "fixed",
		fixed = {
			{0.375, -0.5, -0.9375, 0.5, 1.5, 0.0625},
		},
	},
	on_rightclick = function(pos, node, puncher)
		minetest.swap_node(pos, {name = "c_doors:" ..name.. "_Rdoor", param2 = node.param2})
		minetest.sound_play(door_sound.."_close", {gain = 0.15, max_hear_distance = 2})
	end,
})

--
-- Crafting
--
minetest.register_craft({
	output = "c_doors:" ..name.. "_Ldoor",
	recipe = {
		{"", craft_material , ""},
		{"", craft_material, ""},
		{"", craft_material , ""},
	}
})

minetest.register_craft({
	output = "c_doors:" ..name.. "_Rdoor",
	recipe = {
		{"c_doors:" ..name.. "_Ldoor"},
	}
})

minetest.register_craft({
	output = "c_doors:" ..name.. "_Ldoor",
	recipe = {
		{"c_doors:" ..name.. "_Rdoor"},
	}
})

end
Now I can finally push these changes to my repo.
Thank you stu and paramat for taking the time to help, it is very much appreciated.
A Wonderful World

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests