Add debug command to acquire a written book

The “getwrittenbook” command gives a player that has the “debug” privilege a book
with a configurable amount of characters. This was added as a debug aid, to help
reproducing situations in which items with lots of metadata trigger issues like
heavy lag or server crashes.
master
Nils Dagsson Moskopp 2021-07-30 01:11:58 +02:00
parent a0c9f11af6
commit ce6d6c26cc
No known key found for this signature in database
GPG Key ID: A3BC671C35191080
1 changed files with 27 additions and 0 deletions

View File

@ -1,3 +1,4 @@
local S = minetest.get_translator("mcl_item_entity")
--basic settings
local item_drop_settings = {} --settings table
item_drop_settings.age = 1.0 --how old a dropped item (_insta_collect==false) has to be before collecting
@ -781,3 +782,29 @@ minetest.register_entity(":__builtin:item", {
-- Note: on_punch intentionally left out. The player should *not* be able to collect items by punching
})
-- The “getwrittenbook” command was added as a debug aid. It can help
-- reproducing situations in which items with lots of metadata trigger
-- issues like heavy lag or server crashes. Do not remove this command
-- unless another easy way of getting items with overlong meta exists!
--
-- “/getwrittenbook 65323” creates an item that creates the largest
-- possible serializable written book item entity when dropped.
--
-- “/getwrittenbook 65324” creates an item that creates the smallest
-- possible non-serializable written book item entity when dropped.
minetest.register_chatcommand("getwrittenbook", {
params = S("<Count>"),
description = S("Get a written book with a configurable amount of characters."),
privs = {debug=true},
func = function(name, param)
local count = tonumber(param)
local itemstack = ItemStack("mcl_books:written_book")
local meta = itemstack:get_meta()
meta:set_string("description", "")
meta:set_string("text", string.rep("x", count))
local player = minetest.get_player_by_name(name)
local inv = player:get_inventory()
inv:add_item("main", itemstack)
end
})