Skip to content

Commit

Permalink
DevTest: Move experimental items to other mods
Browse files Browse the repository at this point in the history
  • Loading branch information
Wuzzy2 authored and sfan5 committed Oct 23, 2022
1 parent 3a7fffc commit 68df0fb
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 107 deletions.
51 changes: 51 additions & 0 deletions games/devtest/mods/callbacks/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
local function print_to_everything(msg)
minetest.log("action", msg)
minetest.chat_send_all(msg)
end

minetest.register_node("callbacks:callback_node", {
description = "Callback Test Node (construct/destruct/timer)".."\n"..
"Tests callbacks: on_construct, after_place_node, on_destruct, after_destruct, after_dig_node, on_timer",
tiles = {"callbacks_callback_node.png"},
groups = {dig_immediate=3},
-- This was known to cause a bug in minetest.item_place_node() when used
-- via minetest.place_node(), causing a placer with no position
paramtype2 = "facedir",
drop = "",

on_construct = function(pos)
print_to_everything("callbacks:callback_node:on_construct("..minetest.pos_to_string(pos)..")")
local meta = minetest.get_meta(pos)
meta:set_string("mine", "test")
local timer = minetest.get_node_timer(pos)
timer:start(4, 3)
end,

after_place_node = function(pos, placer)
print_to_everything("callbacks:callback_node:after_place_node("..minetest.pos_to_string(pos)..")")
local meta = minetest.get_meta(pos)
if meta:get_string("mine") == "test" then
print_to_everything("correct metadata found")
else
print_to_everything("incorrect metadata found")
end
end,

on_destruct = function(pos)
print_to_everything("callbacks:callback_node:on_destruct("..minetest.pos_to_string(pos)..")")
end,

after_destruct = function(pos)
print_to_everything("callbacks:callback_node:after_destruct("..minetest.pos_to_string(pos)..")")
end,

after_dig_node = function(pos, oldnode, oldmetadata, digger)
print_to_everything("callbacks:callback_node:after_dig_node("..minetest.pos_to_string(pos)..")")
end,

on_timer = function(pos, elapsed)
print_to_everything("callbacks:callback_node:on_timer(): elapsed="..dump(elapsed))
return true
end,
})

2 changes: 2 additions & 0 deletions games/devtest/mods/callbacks/mod.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name = callbacks
description = Adds various callback-related stuff
1 change: 0 additions & 1 deletion games/devtest/mods/experimental/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
experimental = {}

dofile(minetest.get_modpath("experimental").."/detached.lua")
dofile(minetest.get_modpath("experimental").."/items.lua")
dofile(minetest.get_modpath("experimental").."/commands.lua")

function experimental.print_to_everything(msg)
Expand Down
15 changes: 15 additions & 0 deletions games/devtest/mods/testtools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,24 @@ Usage:
* Punch entity to increase visual size
* Sneak+punch entity to decrease visual size

## Note Meta Privatizer
Sets the 'formspec' and 'infotext' metadata fields of a node
to private. This means that clients can no longer access these
fields.
This only works for chests [`chest:chest`] at the moment.

Usage:
* Punch: Set metadata of pointed node to private

## Light Tool
Show light level of node.

Usage:
* Punch: Show light info of node in front of the punched node's side
* Place: Show light info of the node that you touched

## Particle Spawner
Spawn a random animated particle.

Usage:
* Punch: Spawn particle
2 changes: 2 additions & 0 deletions games/devtest/mods/testtools/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ local S = minetest.get_translator("testtools")
local F = minetest.formspec_escape

dofile(minetest.get_modpath("testtools") .. "/light.lua")
dofile(minetest.get_modpath("testtools") .. "/privatizer.lua")
dofile(minetest.get_modpath("testtools") .. "/particles.lua")

minetest.register_tool("testtools:param2tool", {
description = S("Param2 Tool") .."\n"..
Expand Down
106 changes: 0 additions & 106 deletions games/devtest/mods/testtools/items.lua

This file was deleted.

36 changes: 36 additions & 0 deletions games/devtest/mods/testtools/particles.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
minetest.register_tool("testtools:particle_spawner", {
description = "Particle Spawner".."\n"..
"Punch: Spawn random test particle",
inventory_image = "testtools_particle_spawner.png",
groups = { testtool = 1, disable_repair = 1 },
on_use = function(itemstack, user, pointed_thing)
local pos = minetest.get_pointed_thing_position(pointed_thing, true)
if pos == nil then
if user then
pos = user:get_pos()
end
end
pos = vector.add(pos, {x=0, y=0.5, z=0})
local tex, anim
if math.random(0, 1) == 0 then
tex = "testtools_particle_sheet.png"
anim = {type="sheet_2d", frames_w=3, frames_h=2, frame_length=0.5}
else
tex = "testtools_particle_vertical.png"
anim = {type="vertical_frames", aspect_w=16, aspect_h=16, length=3.3}
end

minetest.add_particle({
pos = pos,
velocity = {x=0, y=0, z=0},
acceleration = {x=0, y=0.04, z=0},
expirationtime = 6,
collisiondetection = true,
texture = tex,
animation = anim,
size = 4,
glow = math.random(0, 5),
})
end,
})

24 changes: 24 additions & 0 deletions games/devtest/mods/testtools/privatizer.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
minetest.register_tool("testtools:privatizer", {
description = "Node Meta Privatizer".."\n"..
"Punch: Marks 'infotext' and 'formspec' meta fields of chest as private",
inventory_image = "testtools_privatizer.png",
groups = { testtool = 1, disable_repair = 1 },
on_use = function(itemstack, user, pointed_thing)
if pointed_thing.type == "node" then
local node = minetest.get_node(pointed_thing.under)
if node.name == "chest:chest" then
local p = pointed_thing.under
minetest.log("action", "[testtools] Privatizer used at "..minetest.pos_to_string(p))
minetest.get_meta(p):mark_as_private({"infotext", "formspec"})
if user and user:is_player() then
minetest.chat_send_player(user:get_player_name(), "Chest metadata (infotext, formspec) set private!")
end
return
end
end
if user and user:is_player() then
minetest.chat_send_player(user:get_player_name(), "Privatizer can only be used on chest!")
end
end,
})

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified games/devtest/mods/testtools/textures/testtools_privatizer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 68df0fb

Please sign in to comment.