Initial commit
61
games/devtest/mods/testentities/armor.lua
Normal file
@@ -0,0 +1,61 @@
|
||||
-- Armorball: Test entity for testing armor groups
|
||||
-- Rightclick to change armor group
|
||||
|
||||
local phasearmor = {
|
||||
[0]={icy=100},
|
||||
[1]={fiery=100},
|
||||
[2]={icy=100, fiery=100},
|
||||
[3]={fleshy=-100},
|
||||
[4]={fleshy=1},
|
||||
[5]={fleshy=10},
|
||||
[6]={fleshy=50},
|
||||
[7]={fleshy=100},
|
||||
[8]={fleshy=200},
|
||||
[9]={fleshy=1000},
|
||||
[10]={fleshy=32767},
|
||||
[11]={immortal=1},
|
||||
[12]={punch_operable=1},
|
||||
}
|
||||
local max_phase = 12
|
||||
|
||||
minetest.register_entity("testentities:armorball", {
|
||||
initial_properties = {
|
||||
hp_max = 20,
|
||||
physical = false,
|
||||
collisionbox = {-0.4,-0.4,-0.4, 0.4,0.4,0.4},
|
||||
visual = "sprite",
|
||||
visual_size = {x=1, y=1},
|
||||
textures = {"testentities_armorball.png"},
|
||||
spritediv = {x=1, y=max_phase+1},
|
||||
initial_sprite_basepos = {x=0, y=0},
|
||||
},
|
||||
|
||||
_phase = 7,
|
||||
|
||||
on_activate = function(self, staticdata)
|
||||
minetest.log("action", "[testentities] armorball.on_activate")
|
||||
self.object:set_armor_groups(phasearmor[self._phase])
|
||||
self.object:set_sprite({x=0, y=self._phase})
|
||||
end,
|
||||
|
||||
on_rightclick = function(self, clicker)
|
||||
-- Change armor group and sprite
|
||||
self._phase = self._phase + 1
|
||||
if self._phase >= max_phase + 1 then
|
||||
self._phase = 0
|
||||
end
|
||||
self.object:set_sprite({x=0, y=self._phase})
|
||||
self.object:set_armor_groups(phasearmor[self._phase])
|
||||
end,
|
||||
|
||||
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir, damage)
|
||||
if not puncher then
|
||||
return
|
||||
end
|
||||
local name = puncher:get_player_name()
|
||||
if not name then
|
||||
return
|
||||
end
|
||||
minetest.chat_send_player(name, "time_from_last_punch="..string.format("%.3f", time_from_last_punch).."; damage="..tostring(damage))
|
||||
end,
|
||||
})
|
||||
78
games/devtest/mods/testentities/callbacks.lua
Normal file
@@ -0,0 +1,78 @@
|
||||
-- Entities that test their callbacks
|
||||
|
||||
local message = function(msg)
|
||||
minetest.log("action", msg)
|
||||
minetest.chat_send_all(msg)
|
||||
end
|
||||
|
||||
local get_object_name = function(obj)
|
||||
local name = "<nil>"
|
||||
if obj then
|
||||
if obj:is_player() then
|
||||
name = obj:get_player_name()
|
||||
else
|
||||
name = "<entity>"
|
||||
end
|
||||
end
|
||||
return name
|
||||
end
|
||||
|
||||
local spos = function(self)
|
||||
return minetest.pos_to_string(vector.round(self.object:get_pos()))
|
||||
end
|
||||
|
||||
-- Callback test entity (all callbacks except on_step)
|
||||
minetest.register_entity("testentities:callback", {
|
||||
initial_properties = {
|
||||
visual = "upright_sprite",
|
||||
textures = { "testentities_callback.png" },
|
||||
},
|
||||
|
||||
on_activate = function(self, staticdata, dtime_s)
|
||||
message("Callback entity: on_activate! pos="..spos(self).."; dtime_s="..dtime_s)
|
||||
end,
|
||||
on_deactivate = function(self, removal)
|
||||
message("Callback entity: on_deactivate! pos="..spos(self) .. "; removal=" .. tostring(removal))
|
||||
end,
|
||||
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir, damage)
|
||||
local name = get_object_name(puncher)
|
||||
message(
|
||||
"Callback entity: on_punch! "..
|
||||
"pos="..spos(self).."; puncher="..name.."; "..
|
||||
"time_from_last_punch="..time_from_last_punch.."; "..
|
||||
"tool_capabilities="..tostring(dump(tool_capabilities)).."; "..
|
||||
"dir="..tostring(dump(dir)).."; damage="..damage)
|
||||
end,
|
||||
on_rightclick = function(self, clicker)
|
||||
local name = get_object_name(clicker)
|
||||
message("Callback entity: on_rightclick! pos="..spos(self).."; clicker="..name)
|
||||
end,
|
||||
on_death = function(self, killer)
|
||||
local name = get_object_name(killer)
|
||||
message("Callback entity: on_death! pos="..spos(self).."; killer="..name)
|
||||
end,
|
||||
on_attach_child = function(self, child)
|
||||
local name = get_object_name(child)
|
||||
message("Callback entity: on_attach_child! pos="..spos(self).."; child="..name)
|
||||
end,
|
||||
on_detach_child = function(self, child)
|
||||
local name = get_object_name(child)
|
||||
message("Callback entity: on_detach_child! pos="..spos(self).."; child="..name)
|
||||
end,
|
||||
on_detach = function(self, parent)
|
||||
local name = get_object_name(parent)
|
||||
message("Callback entity: on_detach! pos="..spos(self).."; parent="..name)
|
||||
end,
|
||||
get_staticdata = function(self)
|
||||
message("Callback entity: get_staticdata! pos="..spos(self))
|
||||
end,
|
||||
})
|
||||
|
||||
-- Only test on_step callback
|
||||
minetest.register_entity("testentities:callback_step", {
|
||||
visual = "upright_sprite",
|
||||
textures = { "testentities_callback_step.png" },
|
||||
on_step = function(self, dtime)
|
||||
message("on_step callback entity: on_step! pos="..spos(self).."; dtime="..dtime)
|
||||
end,
|
||||
})
|
||||
3
games/devtest/mods/testentities/init.lua
Normal file
@@ -0,0 +1,3 @@
|
||||
dofile(minetest.get_modpath("testentities").."/visuals.lua")
|
||||
dofile(minetest.get_modpath("testentities").."/armor.lua")
|
||||
dofile(minetest.get_modpath("testentities").."/callbacks.lua")
|
||||
2
games/devtest/mods/testentities/mod.conf
Normal file
@@ -0,0 +1,2 @@
|
||||
name = testentities
|
||||
description = Example entities for testing
|
||||
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 156 B |
|
After Width: | Height: | Size: 166 B |
BIN
games/devtest/mods/testentities/textures/testentities_cube1.png
Normal file
|
After Width: | Height: | Size: 130 B |
BIN
games/devtest/mods/testentities/textures/testentities_cube2.png
Normal file
|
After Width: | Height: | Size: 128 B |
BIN
games/devtest/mods/testentities/textures/testentities_cube3.png
Normal file
|
After Width: | Height: | Size: 124 B |
BIN
games/devtest/mods/testentities/textures/testentities_cube4.png
Normal file
|
After Width: | Height: | Size: 126 B |
BIN
games/devtest/mods/testentities/textures/testentities_cube5.png
Normal file
|
After Width: | Height: | Size: 126 B |
BIN
games/devtest/mods/testentities/textures/testentities_cube6.png
Normal file
|
After Width: | Height: | Size: 126 B |
|
After Width: | Height: | Size: 2.8 KiB |
BIN
games/devtest/mods/testentities/textures/testentities_sprite.png
Normal file
|
After Width: | Height: | Size: 120 B |
|
After Width: | Height: | Size: 114 B |
|
After Width: | Height: | Size: 119 B |
137
games/devtest/mods/testentities/visuals.lua
Normal file
@@ -0,0 +1,137 @@
|
||||
-- Minimal test entities to test visuals
|
||||
|
||||
minetest.register_entity("testentities:sprite", {
|
||||
initial_properties = {
|
||||
visual = "sprite",
|
||||
textures = { "testentities_sprite.png" },
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_entity("testentities:upright_sprite", {
|
||||
initial_properties = {
|
||||
visual = "upright_sprite",
|
||||
textures = {
|
||||
"testentities_upright_sprite1.png",
|
||||
"testentities_upright_sprite2.png",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_entity("testentities:cube", {
|
||||
initial_properties = {
|
||||
visual = "cube",
|
||||
textures = {
|
||||
"testentities_cube1.png",
|
||||
"testentities_cube2.png",
|
||||
"testentities_cube3.png",
|
||||
"testentities_cube4.png",
|
||||
"testentities_cube5.png",
|
||||
"testentities_cube6.png",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_entity("testentities:item", {
|
||||
initial_properties = {
|
||||
visual = "item",
|
||||
wield_item = "testnodes:normal",
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_entity("testentities:wielditem", {
|
||||
initial_properties = {
|
||||
visual = "wielditem",
|
||||
wield_item = "testnodes:normal",
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_entity("testentities:mesh", {
|
||||
initial_properties = {
|
||||
visual = "mesh",
|
||||
mesh = "testnodes_pyramid.obj",
|
||||
textures = {
|
||||
"testnodes_mesh_stripes2.png"
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_entity("testentities:mesh_unshaded", {
|
||||
initial_properties = {
|
||||
visual = "mesh",
|
||||
mesh = "testnodes_pyramid.obj",
|
||||
textures = {
|
||||
"testnodes_mesh_stripes2.png"
|
||||
},
|
||||
shaded = false,
|
||||
},
|
||||
})
|
||||
|
||||
-- Advanced visual tests
|
||||
|
||||
-- An entity for testing animated and yaw-modulated sprites
|
||||
minetest.register_entity("testentities:yawsprite", {
|
||||
initial_properties = {
|
||||
selectionbox = {-0.3, -0.5, -0.3, 0.3, 0.3, 0.3},
|
||||
visual = "sprite",
|
||||
visual_size = {x=0.6666, y=1},
|
||||
textures = {"testentities_dungeon_master.png^[makealpha:128,0,0^[makealpha:128,128,0"},
|
||||
spritediv = {x=6, y=5},
|
||||
initial_sprite_basepos = {x=0, y=0},
|
||||
},
|
||||
on_activate = function(self, staticdata)
|
||||
self.object:set_sprite({x=0, y=0}, 3, 0.5, true)
|
||||
end,
|
||||
})
|
||||
|
||||
-- An entity for testing animated upright sprites
|
||||
minetest.register_entity("testentities:upright_animated", {
|
||||
initial_properties = {
|
||||
visual = "upright_sprite",
|
||||
textures = {"testnodes_anim.png"},
|
||||
spritediv = {x = 1, y = 4},
|
||||
},
|
||||
on_activate = function(self)
|
||||
self.object:set_sprite({x=0, y=0}, 4, 1.0, false)
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_entity("testentities:nametag", {
|
||||
initial_properties = {
|
||||
visual = "sprite",
|
||||
textures = { "testentities_sprite.png" },
|
||||
},
|
||||
|
||||
on_activate = function(self, staticdata)
|
||||
if staticdata ~= "" then
|
||||
local data = minetest.deserialize(staticdata)
|
||||
self.color = data.color
|
||||
self.bgcolor = data.bgcolor
|
||||
else
|
||||
self.color = {
|
||||
r = math.random(0, 255),
|
||||
g = math.random(0, 255),
|
||||
b = math.random(0, 255),
|
||||
}
|
||||
|
||||
if math.random(0, 10) > 5 then
|
||||
self.bgcolor = {
|
||||
r = math.random(0, 255),
|
||||
g = math.random(0, 255),
|
||||
b = math.random(0, 255),
|
||||
a = math.random(0, 255),
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
assert(self.color)
|
||||
self.object:set_properties({
|
||||
nametag = tostring(math.random(1000, 10000)),
|
||||
nametag_color = self.color,
|
||||
nametag_bgcolor = self.bgcolor,
|
||||
})
|
||||
end,
|
||||
|
||||
get_staticdata = function(self)
|
||||
return minetest.serialize({ color = self.color, bgcolor = self.bgcolor })
|
||||
end,
|
||||
})
|
||||