Massive update (#6)

* Refactor some of the code, multiple bug fixes

* Fix something stupid

* More bug fixes

* LOTS OF STUFF

* Make the sniper alot stronger and other changes

* Prevent Players from respawning in the middle of a match

* Fix stupid mistake

* Small update

* More updates

* Remove minimap access.. and downgrade the sniper class
This commit is contained in:
IonicCheese 2025-12-10 19:17:42 -08:00 committed by GitHub
commit 17eeae8937
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
499 changed files with 616 additions and 225 deletions

View file

@ -0,0 +1,16 @@
# Functions API
## `can_interact_with_node(player, pos)`
returns `bool`
checks for the ability to interact with a node via:
* if a player
* owner metadata key
* `protection_bypass`
supports
* minetest game default if present
* else polyfill

View file

@ -0,0 +1,12 @@
# GameId API
## minetest versions >= 5.7
simply returns `minetest.get_game_info().id`
## minetest versions < 5.7
approximates the gameid value via a hardcoded table of gameid =\> modname,
and then checks via `minetest.get_modpath()`. If it fails, it falls
back to using `xcompat_unknown_gameid` as the id. See the chart in the
readme for which games are supported

View file

@ -0,0 +1,26 @@
# Materials API
## Usage
The materials can be accessed anywhere in your mod with `xcompat.materials.material_name`.
Behind the scenes, xcompat automatically changes the `xcompat.materials`
variable to contain the correct materials for whichever game the mod is
launched in.
## Game support
See the [the support table in the readme](https://github.com/mt-mods/xcompat/tree/master?tab=readme-ov-file#directly-supported-games-and-mods)
for an overview of supported games, and see the contents of `/src/materials/`
for the supported materials and their names.
## Examples
Writing `xcompat.materials.steel_ingot` returns the string of whichever item
would closest represent the `steel_ingot` material in the current game.
The `/src/materials/mineclonia.lua` file shows what the keys of
`xcompat.materials` resolve to when playing Mineclonia, such as
`xcompat.materials.steel_ingot` resolving to `mcl_core:iron_ingot`, and
`xcompat.materials.mesa_crystal` resolving to `mcl_redstone:redstone` if
supported.

View file

@ -0,0 +1,21 @@
# Player API
## Usage
The player api can be accessed in your script through `xcompat.player`.
This object mimics the `player_api` from Minetest Game, and should be a drop-in
replacement in most cases. You should be able to simply replace instances
of `player_api` in your script with `xcompat.player`.
## Note on `xcompat.player.player_attached`
Reading & writing to this object works, but because it's a proxy table it can't
be looped over.
Looping over this object would require lua5.2 `__pairs`/`__ipairs` metamethod support.
It would be possible to implement support for this through polyfill,
using [this method](https://stackoverflow.com/a/77354254)
(luajit supports this via 5.2 extensions), but it's not implemented as of now.
Additionally see [this engine issue](https://github.com/minetest/minetest/issues/15133).

View file

@ -0,0 +1,45 @@
# Sound API
## Option 1: Agnostically depend
You can do this by using a custom field in your node def instead of the `sounds` key.
```lua
minetest.register_node(nodename, {
...
_sound_def = {
key = "",
input = {},
},
...
})
```
where:
* key: string name of the field from the sound api you want to use, for example `node_sound_stone_defaults`
* input: table input of fields you want passed to the key field, used to override specific sounds.
## Option 2: Hard depend
add this mod to your mod.confs depends and directly call the `sound_api` as follows
```lua
minetest.register_node(nodename, {
...
sounds = xcompat.sounds.node_sound_stone_defaults(input)
...
})
```
* input: optional table to override some or all of returned values
## Note
In some instances, when sounds are defined by strings and the sound doesn't
belong to a block or anything mod-specific, xcompat may not be needed. E.g.
the sound `"default_dig_choppy"` is accessed in the same way in both Mineclonia
and Minetest Game, without xcompat.

View 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

View file

@ -0,0 +1,20 @@
# Textures API
## Usage
To use a texture in your mod, find the texture you want by looking at one of
the files in `/src/texture`, and append its path to `xcompat.textures`.
If a texture isn't supported for the current game, xcompat creates a solid
color texture using texture modifiers as a fallback, ensuring compatibility.
## Example
| Path | Result in Minetest Game |
| - | - |
| xcompat.textures.wool.white | `"wool_white.png"` |
| xcompat.textures.wood.apple.planks | `"default_wood.png"` |
| xcompat.textures.wood.jungle.leaves | `"default_jungleleaves.png"` |
| xcompat.textures.glass.pane | `"default_glass.png"` |
For games like Minetest and Mineclonia, see the file `/src/textures/minetest.lua`.