Skip to content

Commit

Permalink
add clone_wielded command
Browse files Browse the repository at this point in the history
  • Loading branch information
fluxionary committed Nov 5, 2022
1 parent ab09aaf commit 6ab88f7
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 15 deletions.
36 changes: 21 additions & 15 deletions README.md
Expand Up @@ -7,15 +7,15 @@ dependencies:

# commands

* `attach <target1> to <target2>`
* `/attach <target1> to <target2>`

attaches two objects, which might be a player name or an entity name (a random entity of that type is chosen)

* `detach <target>`
* `/detach <target>`

detaches the target from its parent.

* `count_objects`
* `/count_objects`

prints counts of all types of objects currently active.
example output:
Expand All @@ -32,7 +32,7 @@ dependencies:
total = 18
```

* `entity_lag_log_toggle`
* `/entity_lag_log_toggle`

starts (or stops) a log of how much time entities are spending doing their `on_step` callback.
example output:
Expand All @@ -42,7 +42,7 @@ dependencies:
2022-09-03 16:03:52: petz:snow_leopard @ (-2811,74,2283)'s on_step took 377283 us
```

* `/grep_nodes <limit> <pattern>`
* `//grep_nodes <limit> <pattern>`

requires *either* worldedit or areas mod. allows you to search for nodes whose name matches `<pattern>` between
either areas positions (`area_pos1`, `area_pos2`) or worldedit positions (`/1`, `/2`). searching a large area is
Expand All @@ -54,7 +54,8 @@ dependencies:
pipeworks:nodebreaker_off @ (-538,23,-274)
pipeworks:deployer_off @ (-535,23,-274)
```
* `instrument_mod <global_name>`

* `/instrument_mod <global_name>`

recursively finds all functions inside a lua table available as `<global_name>`, and records information about
how often they are executed, and how long they take to run. most mods use their own name as the global value.
Expand All @@ -69,37 +70,42 @@ dependencies:
22:04:06: kitz.get_closest_entity was called 21 times, used 4062036 us
```

* `memory`
* `/memory`

get lua's current memory usage (doesn't include memory managed by the c++ parts of the engine)

* `memory_toggle`
* `/memory_toggle`

reports on the server's memory usage periodically.

* `rectify`
* `/rectify`

sets pitch (look_vertical) to 0 and yaw (look_horizontal) to 0.

* `remove_entities <entity_name>`
* `/remove_entities <entity_name>`

remove all currently active entities w/ the given name. does not affect unloaded entities.

* `whatisthis`
* `/whatisthis`

get the full itemstring of wielded item.

* `/rollback_check [<seconds>] [<limit_per_node>] [<player>] [<node>]`
* note: the initial slash - this does not override the builtin rollback_check command
* `//rollback_check [<seconds>] [<limit_per_node>] [<player>] [<node>]`
* note: the double slash - this does not override the builtin rollback_check command
* note: requires the same privilege(s) as `rollback_check`.
* note: defaults: <seconds> = 1 year; limit_per_node = 5; player = .*; node = .*

checks a region defined via worldedit (`/1`, `/2`) or areas (`area_pos1`, `area_pos2`).

* `/rollback <seconds> <player>`
* note: the initial slash - this does not override the builtin rollback command
* `//rollback <seconds> <player>`
* note: the double slash - this does not override the builtin rollback command
* note: requires the same privilege(s) as `rollback`.
* note: VERY SLOW AND DANGEROUS. BE CAREFUL. MAKE BACKUPS.

requires both arguments. reverts all changes by player in the region to what was there before the earliest
change after <seconds> seconds ago.

* `/clone_wielded [<count>]`

makes extras of the item the player is wielded. for tools, the default is 1 (added to the players inventory),
for non-tools, the default is the item's stack max size. exceeding the stack size is possible, up to 65535
71 changes: 71 additions & 0 deletions chatcommands/clone_wielded.lua
@@ -0,0 +1,71 @@
local f = string.format
local default_stack_max = tonumber(minetest.settings:get("default_stack_max")) or 99

minetest.register_chatcommand("clone_wielded", {
params = "[<quantity>]",
description = "increases the stack size of the wielded item",
privs = {[debuggery.settings.admin_priv] = true},
func = function(name, count)
local player = minetest.get_player_by_name(name)
if not player then
return false, "you're not a player"
end

local wielded = player:get_wielded_item()
if wielded:is_empty() then
return false, "can't dupe nothing"
end

local inv = player:get_inventory()
local def = wielded:get_definition()
count = tonumber(count)

if count and (count >= 65536 or count <= 0 or math.floor(count) ~= count) then
return false, "invalid count"
end

if def.type == "tool" then
count = count or 1
local created = 0
for _ = 1, count do
if inv:room_for_item("main", wielded) then
inv:add_item("main", wielded)
else
break
end
created = created + 1
end

if created == count then
if count == 1 then
return true, f("added %q to inventory", wielded:to_string())

else
return true, f("added %s %qs to inventory", created, wielded:to_string())
end

elseif created == 0 then
return false, "no room in inventory"

else
return true, f("added %s %qs to inventory, then ran out of space", created, wielded:to_string())
end

else
local stack_max = wielded:get_stack_max()
if stack_max == 1 then
stack_max = default_stack_max
end
count = count or stack_max

if count > wielded:get_count() then
wielded:set_count(count)
player:set_wielded_item(wielded)
return true, f("cloned %q", wielded:to_string())

else
return false, f("wielded stack is already larger")
end
end
end,
})
1 change: 1 addition & 0 deletions chatcommands/init.lua
@@ -1,5 +1,6 @@
debuggery.dofile("chatcommands", "attach_detach")
debuggery.dofile("chatcommands", "better_rollback")
debuggery.dofile("chatcommands", "clone_wielded")
debuggery.dofile("chatcommands", "count_objects")
debuggery.dofile("chatcommands", "entity_lag_log")
debuggery.dofile("chatcommands", "grep_nodes")
Expand Down

0 comments on commit 6ab88f7

Please sign in to comment.