mirror of
				https://github.com/mt-mods/xcompat.git
				synced 2025-10-31 08:15:28 +01:00 
			
		
		
		
	add stairs api (#56)
This commit is contained in:
		| @@ -1,9 +1,13 @@ | |||||||
| globals = { | globals = { | ||||||
| 	"minetest", | 	"minetest", | ||||||
|  | 	"core", | ||||||
| 	"xcompat", | 	"xcompat", | ||||||
| } | } | ||||||
|  |  | ||||||
| read_globals = { | read_globals = { | ||||||
|  | 	string = {fields = {"split"}}, | ||||||
|  |     table = {fields = {"copy", "getn"}}, | ||||||
|  |  | ||||||
| 	"default", | 	"default", | ||||||
| 	"mcl_sounds", | 	"mcl_sounds", | ||||||
| 	"ks_sounds", | 	"ks_sounds", | ||||||
| @@ -18,4 +22,5 @@ read_globals = { | |||||||
| 	"player_api", | 	"player_api", | ||||||
| 	"mcl_player", | 	"mcl_player", | ||||||
| 	"fl_player", | 	"fl_player", | ||||||
|  | 	"stairs", | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								LICENSE
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								LICENSE
									
									
									
									
									
								
							| @@ -1,5 +1,5 @@ | |||||||
|  |  | ||||||
| MIT Copyright 2021-2024 wsor4035 | MIT Copyright 2021-2025 wsor4035, mt-mods and contributors | ||||||
|  |  | ||||||
| Permission is hereby granted, free of charge, to any person obtaining a copy of | Permission is hereby granted, free of charge, to any person obtaining a copy of | ||||||
| this software and associated documentation files (the "Software"), to deal in | this software and associated documentation files (the "Software"), to deal in | ||||||
|   | |||||||
							
								
								
									
										20
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								README.md
									
									
									
									
									
								
							| @@ -15,16 +15,16 @@ See the respective sub apis doc file in /doc for detailed documentation. | |||||||
|  |  | ||||||
| ## Directly supported games and mods | ## Directly supported games and mods | ||||||
|  |  | ||||||
| | Games             | Sounds    | Materials | Textures  | Player | | | Games             | Sounds    | Materials | Textures  | Player | Stairs | | ||||||
| | ----------------- | --------- | --------- | --------- | ------ | | | ----------------- | --------- | --------- | --------- | ------ | ------ | | ||||||
| | Minetest Game     | x         | x         | x         | x      | | | Minetest Game     | x         | x         | x         | x      | x      | | ||||||
| | MineClone2        | x         | x         |           | x      | | | MineClone2        | x         | x         |           | x      |        | | ||||||
| | Mineclonia        | x         | x         |           | x      | | | Mineclonia        | x         | x         |           | x      |        | | ||||||
| | Hades Revisited   | x         | x         |           |        | | | Hades Revisited   | x         | x         |           |        |        | | ||||||
| | Farlands Reloaded | x         | x         | x         | x      | | | Farlands Reloaded | x         | x         | x         | x      | x      | | ||||||
| | Exile             | x         |           |           |        | | | Exile             | x         |           |           |        |        | | ||||||
| | KSurvive 2        | x         |           |           |        | | | KSurvive 2        | x         |           |           |        |        | | ||||||
| | Forgotten Lands   | x         |           |           |        | | | Forgotten Lands   | x         |           |           |        |        | | ||||||
|  |  | ||||||
| For functions see /doc/functions.md for the specifics relating to the function | For functions see /doc/functions.md for the specifics relating to the function | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										30
									
								
								doc/stairs.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								doc/stairs.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | |||||||
|  | you can use this via `xcompat.stairs.register(nodename, def)` | ||||||
|  |  | ||||||
|  | an example would be:   | ||||||
|  | ```lua | ||||||
|  | xcompat.stairs.register( | ||||||
|  |     "xcompat_stairs_test:fake_node", | ||||||
|  |     core.registered_nodes["xcompat_stairs_test:fake_node"] | ||||||
|  | ) | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | if the game you are running on isnt supported (see readme),  | ||||||
|  | it falls back to using a polyfill. each backend adds aliases  | ||||||
|  | to the polyfill, mainly so that if we add a future backend  | ||||||
|  | that ran on polyfill, everything keeps working (yay) | ||||||
|  |  | ||||||
|  | at this time stairsplus/moreblocks compatibility/upgrading  | ||||||
|  | isnt supported, however should be added in the future. for  | ||||||
|  | now, in your mod code do something like the following: | ||||||
|  |  | ||||||
|  | ```lua | ||||||
|  | if core.registered_modes("moreblocks") then | ||||||
|  |     --call stairs plus | ||||||
|  | else  | ||||||
|  |     xcompat.stairs.register(node, def) | ||||||
|  | end | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | that way in the future nothing will break when support is  | ||||||
|  | added and at your convince the first part of the if can be  | ||||||
|  | removed | ||||||
							
								
								
									
										1
									
								
								init.lua
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								init.lua
									
									
									
									
									
								
							| @@ -12,6 +12,7 @@ xcompat.materials = dofile(modpath .. "/src/materials.lua") | |||||||
| xcompat.textures = dofile(modpath .. "/src/textures.lua") | xcompat.textures = dofile(modpath .. "/src/textures.lua") | ||||||
| xcompat.functions = dofile(modpath .. "/src/functions.lua") | xcompat.functions = dofile(modpath .. "/src/functions.lua") | ||||||
| xcompat.player = dofile(modpath .. "/src/player.lua") | xcompat.player = dofile(modpath .. "/src/player.lua") | ||||||
|  | xcompat.stairs = dofile(modpath .. "/src/stairs.lua") | ||||||
|  |  | ||||||
| local function validate_sound(key) | local function validate_sound(key) | ||||||
|     if key and xcompat.sounds[key] then |     if key and xcompat.sounds[key] then | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								mod.conf
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								mod.conf
									
									
									
									
									
								
							| @@ -1,3 +1,3 @@ | |||||||
| name = xcompat | name = xcompat | ||||||
| description = Provides cross compatibility between mods and games for sounds and crafting materials. | description = Provides cross compatibility between mods and games for sounds and crafting materials. | ||||||
| optional_depends = default, fl_stone, fl_trees, mcl_sounds, hades_sounds, ks_sounds, nodes_nature, fl_topsoil, fl_trees, mcl_core, farming, x_farming, sounds, mtt, player_api, mcl_player, fl_player | optional_depends = default, fl_stone, fl_trees, mcl_sounds, hades_sounds, ks_sounds, nodes_nature, fl_topsoil, fl_trees, mcl_core, farming, x_farming, sounds, mtt, player_api, mcl_player, fl_player, stairs | ||||||
|   | |||||||
							
								
								
									
										8
									
								
								src/stairs.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/stairs.lua
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | |||||||
|  | local filename = xcompat.gameid | ||||||
|  |  | ||||||
|  | --if we dont have a stairs file for the game, use xcompat_agnostic | ||||||
|  | if not xcompat.utilities.file_exists(xcompat.modpath .. "/src/stairs/" .. filename .. ".lua") then | ||||||
|  |     filename = "xcompat_agnostic" | ||||||
|  | end | ||||||
|  |  | ||||||
|  | return dofile(xcompat.modpath .. "/src/stairs/" .. filename .. ".lua") | ||||||
							
								
								
									
										25
									
								
								src/stairs/farlands_reloaded.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								src/stairs/farlands_reloaded.lua
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,25 @@ | |||||||
|  | local function register(name, _) | ||||||
|  |     local splitName = name:split(":") | ||||||
|  |     local sName = splitName[2] | ||||||
|  |  | ||||||
|  |     local groups = core.registered_nodes[name].groups | ||||||
|  |     groups.stairable = 1 | ||||||
|  |  | ||||||
|  |     core.override_item(name, {groups = groups}) | ||||||
|  |  | ||||||
|  |     local flStairNameOverrides = { | ||||||
|  |         ["stair_inner"] = "inner_stair", | ||||||
|  |         ["stair_outer"] = "outer_stair" | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     for _, type in pairs({"slab", "stair", "stair_inner", "stair_outer"}) do | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         minetest.register_alias( | ||||||
|  |             splitName[1] .. ":" .. type .. "_" .. sName, | ||||||
|  |             splitName[1] .. ":" .. sName .. "_" .. (flStairNameOverrides[type] or type) | ||||||
|  |         ) | ||||||
|  |     end | ||||||
|  | end | ||||||
|  |  | ||||||
|  | return {register = register} | ||||||
							
								
								
									
										19
									
								
								src/stairs/minetest.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								src/stairs/minetest.lua
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | |||||||
|  | local function register(name, def) | ||||||
|  |     local splitName = name:split(":") | ||||||
|  |     local sName = splitName[2] | ||||||
|  |  | ||||||
|  |     stairs.register_stair_and_slab( | ||||||
|  |         sName, | ||||||
|  |         nil, | ||||||
|  |         def.groups, | ||||||
|  |         def.tiles, | ||||||
|  |         def.description, | ||||||
|  |         def.sounds | ||||||
|  |     ) | ||||||
|  |  | ||||||
|  |     for _, type in pairs({"slab", "stair", "stair_inner", "stair_outer"}) do | ||||||
|  |         minetest.register_alias(splitName[1] .. ":" .. type .. "_" .. sName, "stairs:" .. type .. "_" .. sName) | ||||||
|  |     end | ||||||
|  | end | ||||||
|  |  | ||||||
|  | return {register = register} | ||||||
							
								
								
									
										48
									
								
								src/stairs/xcompat_agnostic.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								src/stairs/xcompat_agnostic.lua
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,48 @@ | |||||||
|  | local stairtable = { | ||||||
|  |     { | ||||||
|  |         "slab", | ||||||
|  |         {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |         "stair", | ||||||
|  |         { | ||||||
|  |             {-0.5, -0.5, -0.5, 0.5, 0.0, 0.5}, | ||||||
|  |             {-0.5, 0.0, 0.0, 0.5, 0.5, 0.5}, | ||||||
|  |         }, | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |         "stair_inner", | ||||||
|  |         { | ||||||
|  |             {-0.5, -0.5, -0.5, 0.5, 0.0, 0.5}, | ||||||
|  |             {-0.5, 0.0, 0.0, 0.5, 0.5, 0.5}, | ||||||
|  |             {-0.5, 0.0, -0.5, 0.0, 0.5, 0.0}, | ||||||
|  |         }, | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |         "stair_outer", | ||||||
|  |         { | ||||||
|  |             {-0.5, -0.5, -0.5, 0.5, 0.0, 0.5}, | ||||||
|  |             {-0.5, 0.0, 0.0, 0.0, 0.5, 0.5}, | ||||||
|  |         }, | ||||||
|  |     }, | ||||||
|  | } | ||||||
|  |  | ||||||
|  | local function register(name, def) | ||||||
|  |     for _, sdef in pairs(stairtable) do | ||||||
|  |         local split = name:split(":") | ||||||
|  |         local ndef = table.copy(def) | ||||||
|  |         local item_name = ":" .. sdef[1] .. "_" .. split[2] | ||||||
|  |  | ||||||
|  |         ndef.description = def.description .. " " .. string.gsub(sdef[1], "_", " ") | ||||||
|  |         ndef.paramtype, ndef.paramtype2 = "light", "facedir" | ||||||
|  |         ndef.drawtype = "nodebox" | ||||||
|  |         ndef.node_box = { | ||||||
|  |             type = "fixed", | ||||||
|  |             fixed = sdef[2], | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         minetest.register_node(":" .. split[1] .. item_name, ndef) | ||||||
|  |     end | ||||||
|  | end | ||||||
|  |  | ||||||
|  | return {register = register} | ||||||
		Reference in New Issue
	
	Block a user