@@ -1154,6 +1154,13 @@ minetest.register_on_craft(func(itemstack, player, old_craft_grid, craft_inv))
1154
1154
minetest.register_craft_predict(func(itemstack, player, old_craft_grid, craft_inv))
1155
1155
^ The same as before, except that it is called before the player crafts, to make
1156
1156
^ craft prediction, and it should not change anything.
1157
+ minetest.register_on_protection_violation(func(pos, name))
1158
+ ^ Called by builtin and mods when a player violates protection at a position
1159
+ (eg, digs a node or punches a protected entity).
1160
+ ^ The registered functions can be called using minetest.record_protection_violation
1161
+ ^ The provided function should check that the position is protected by the mod
1162
+ calling this function before it prints a message, if it does, to allow for
1163
+ multiple protection mods.
1157
1164
1158
1165
Other registration functions:
1159
1166
minetest.register_chatcommand(cmd, chatcommand definition)
@@ -1483,6 +1490,22 @@ minetest.deserialize(string) -> table
1483
1490
^ Example: deserialize('return { ["foo"] = "bar" }') -> {foo='bar'}
1484
1491
^ Example: deserialize('print("foo")') -> nil (function call fails)
1485
1492
^ error:[string "print("foo")"]:1: attempt to call global 'print' (a nil value)
1493
+ minetest.is_protected(pos, name) -> bool
1494
+ ^ This function should be overriden by protection mods and should be used to
1495
+ check if a player can interact at a position.
1496
+ ^ This function should call the old version of itself if the position is not
1497
+ protected by the mod.
1498
+ ^ Example:
1499
+ local old_is_protected = minetest.is_protected
1500
+ function minetest.is_protected(pos, name)
1501
+ if mymod:position_protected_from(pos, name) then
1502
+ return true
1503
+ end
1504
+ return old_is_protected(pos, name)
1505
+ end
1506
+ minetest.record_protection_violation(pos, name)
1507
+ ^ This function calls functions registered with
1508
+ minetest.register_on_protection_violation.
1486
1509
1487
1510
Global objects:
1488
1511
minetest.env - EnvRef of the server environment and world.
0 commit comments