Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion development-log.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ Fully completed mapgen.cpp and wrote tests for server.cpp up to remove_player -
Completed server.cpp tests up to show_formspec - 1 hr 5 min
Completed server.cpp tests up to get_worldpath - 41 min
Completed every server.cpp test except for notify_authentication_modified - 3 hr 55 min
Completed notify_authentication_modified - 1 hr 21 min
Completed notify_authentication_modified - 1 hr 21 min
Started server.cpp up to punch - 2 hr
Binary file modified minetest.dmp
Binary file not shown.
Binary file not shown.
Binary file not shown.
229 changes: 229 additions & 0 deletions mods/testingnativeapi_server/object.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
local playerName = "singleplayer"
core.register_on_joinplayer(function(player)
playerName = player:get_player_name()
end)

core.register_entity("testingnativeapi_server:testentity",
{
initial_properties = {
hp_max = 1,
physical = true,
collide_with_objects = true,
collisionbox = {-1, -1, -1, 1, 1, 1},
visual = "mesh",
visual_size = {x = 10, y = 10},
mesh="animalia_reindeer.b3d",
textures={"animalia_reindeer.png"},
spritediv = {x = 10, y = 10},
initial_sprite_basepos = {x = 0, y = 0},
},
get_type=function ()
return "player"
end
})

--helper function that spawns test entity at player's position for debugging
core.register_chatcommand("test_spawn", {
description="Spawns a test entity at player's position",
func = function ()
local player = core.get_player_by_name(playerName)
local entity = core.add_entity(player:get_pos(), "testingnativeapi_server:testentity", "")
return true, "Test entity spawned at: "..dump(entity:get_pos())
end
})
core.register_chatcommand("lua_remove", {
description="Invokes lua_api > remove",
func=function ()
local player = core.get_player_by_name(playerName)
local entity = core.add_entity(player:get_pos(), "testingnativeapi_server:testentity", "")
entity:remove()
if entity:get_pos() == nil then return true, "Entity successfully removed"
else return false, "Entity not removed, punch to remove it" end
end
})

core.register_chatcommand("native_remove", {
description="Invokes native_api > remove",
func=function ()
local player = core.get_player_by_name(playerName)
local entity = core.add_entity(player:get_pos(), "testingnativeapi_server:testentity", "")
entity:native_remove()
if entity:get_pos() == nil then return true, "Entity successfully removed"
else return false, "Entity not removed, punch to remove it" end
end

})

core.register_chatcommand("test_remove", {
description="Invokes both lua and native remove functions",
func=function ()
local player = core.get_player_by_name(playerName)
local luaRemoved, nativeRemoved = false, false

local luaEntity = core.add_entity(player:get_pos(), "testingnativeapi_server:testentity", "")
luaEntity:remove()
if luaEntity:get_pos() == nil then luaRemoved = true end

local nativeEntity = core.add_entity(player:get_pos(), "testingnativeapi_server:testentity", "")
nativeEntity:native_remove()
if nativeEntity:get_pos() == nil then nativeRemoved = true end

if luaRemoved and nativeRemoved then return true, "Lua and native entities removed"
else return false, "Lua entity removed: "..luaRemoved.." Native entity removed: "..nativeRemoved end
end
})

core.register_chatcommand("lua_get_pos", {
description="Invokes lua_api > get_pos",
func = function ()
local player = core.get_player_by_name(playerName)
local pos = player:get_pos()
if pos then return true, "Player position returned"
else return false, "Player position not returned" end
end
})

core.register_chatcommand("native_get_pos", {
description="Invokes native_api > get_pos",
func = function ()
local player = core.get_player_by_name(playerName)
local pos = player:native_get_pos()
if pos then return true, "Player position returned"
else return false, "Player position not returned" end
end
})

core.register_chatcommand("test_get_pos", {
description="Compares output of native and Lua get_pos APIs",
func=function ()
local player = core.get_player_by_name(playerName)
local luaPos = player:get_pos()
local nativePos = player:native_get_pos()
if luaPos ~= nil and dump(luaPos) == dump(nativePos) then return true, "Lua and native positions are the same"
else return false, "Lua pos: "..dump(luaPos).." Native pos: "..dump(nativePos) end
end
})

core.register_chatcommand("lua_set_pos", {
description="Invokes lua_api > set_pos",
func=function ()
local player = core.get_player_by_name(playerName)
local initPos = player:get_pos()
player:set_pos({x=initPos["x"]+1, y=initPos["y"]+1, z=initPos["z"]+1})
local luaPos = player:get_pos()
player:set_pos(initPos)
if dump(initPos) ~= dump(luaPos) then return true, "Player position adjusted"
else return false, "Player position not adjusted" end
end
})

core.register_chatcommand("native_set_pos", {
description="Invokes native_api > set_pos",
func=function ()
local player = core.get_player_by_name(playerName)
local initPos = player:get_pos()
player:native_set_pos({x=initPos["x"]+1, y=initPos["y"]+1, z=initPos["z"]+1})
local nativePos = player:get_pos()
player:native_set_pos(initPos)
if dump(initPos) ~= dump(nativePos) then return true, "Player position adjusted"
else return false, "Player position not adjusted" end
end
})

core.register_chatcommand("test_set_pos", {
description="Invokes both Lua and native set_pos and compares outputs",
func= function ()
local player = core.get_player_by_name(playerName)
local initPos = player:get_pos()

player:set_pos({x=initPos["x"]+1, y=initPos["y"]+1, z=initPos["z"]+1})
local luaPos = player:get_pos()
player:set_pos(initPos)

player:native_set_pos({x=initPos["x"]+1, y=initPos["y"]+1, z=initPos["z"]+1})
local nativePos = player:get_pos()
player:native_set_pos(initPos)

if dump(luaPos) == dump(nativePos) then return true, "Lua and native functions set position to same value"
else return false, dump(luaPos)..dump(nativePos) end
end
})

core.register_chatcommand("lua_move_to", {
description="Invokes lua_api > move_to",
func=function ()
local player = core.get_player_by_name(playerName)
local initPos = player:get_pos()
player:move_to({x=initPos["x"]+1, y=initPos["y"]+1, z=initPos["z"]+1}, false)
local luaPos = player:get_pos()
player:set_pos(initPos)

if dump(initPos) ~= dump(luaPos) then return true, "Player moved"
else return false, "Player position not moved" end
end
})

core.register_chatcommand("native_move_to", {
description="Invokes native_api > move_to",
func=function ()
local player = core.get_player_by_name(playerName)
local initPos = player:get_pos()
player:native_move_to({x=initPos["x"]+1, y=initPos["y"]+1, z=initPos["z"]+1}, false)
local nativePos = player:get_pos()
player:set_pos(initPos)

if dump(initPos) ~= dump(nativePos) then return true, "Player moved"
else return false, "Player position not moved" end
end
})

core.register_chatcommand("test_move_to", {
description="Invokes move_to from native and Lua APIs",
func=function ()
local player = core.get_player_by_name(playerName)
local initPos = player:get_pos()

player:move_to({x=initPos["x"]+1, y=initPos["y"]+1, z=initPos["z"]+1}, false)
local luaPos = player:get_pos()
player:set_pos(initPos)

player:native_move_to({x=initPos["x"]+1, y=initPos["y"]+1, z=initPos["z"]+1}, false)
local nativePos = player:get_pos()
player:set_pos(initPos)

if dump(luaPos) == dump(nativePos) then return true, "Lua and native functions moved player to same position"
else return false, dump(luaPos)..dump(nativePos) end
end
})


local test_tool_caps = {
full_punch_interval = 0.0,
max_drop_level = 3,
groupcaps = {
cracky = {
times = {[1] = 0.1, [2] = 0.1, [3] = 0.1},
uses = 0,
maxlevel = 3,
},
fleshy = {
times = {[1] = 0.1},
uses = 0,
maxlevel = 3,
}
},
damage_groups = {fleshy = 100},
}
core.register_chatcommand("lua_punch", {
description="Invokes lua_api > punch",
func = function ()
local player = core.get_player_by_name(playerName)
local entity = core.add_entity(player:get_pos(), "testingnativeapi_server:testentity", "")
--single punch will always kill entity because it has 1 health
core.chat_send_all(dump(player))
entity:punch(player, 0.0, test_tool_caps, nil)
if entity:get_pos() == nil then return true, "Entity was punched"
else return false, "Entity was not punched" end
end
})

109 changes: 109 additions & 0 deletions src/script/lua_api/l_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4517,5 +4517,114 @@ luaL_Reg ObjectRef::methods[] = {
luamethod(ObjectRef, get_eye_offset),
luamethod(ObjectRef, send_mapblock),
luamethod(ObjectRef, set_minimap_modes),

/*Native functions*/
luamethod(ObjectRef, native_remove),
luamethod_aliased(ObjectRef, native_get_pos, native_getpos),
luamethod_aliased(ObjectRef, native_set_pos, native_setpos),
luamethod_aliased(ObjectRef, native_move_to, native_moveto),
luamethod(ObjectRef, native_punch),
luamethod(ObjectRef, native_right_click),
luamethod(ObjectRef, native_set_hp),
luamethod(ObjectRef, native_get_hp),
luamethod(ObjectRef, native_get_inventory),
luamethod(ObjectRef, native_get_wield_list),
luamethod(ObjectRef, native_get_wield_index),
luamethod(ObjectRef, native_get_wielded_item),
luamethod(ObjectRef, native_set_wielded_item),
luamethod(ObjectRef, native_set_armor_groups),
luamethod(ObjectRef, native_get_armor_groups),
luamethod(ObjectRef, native_set_animation),
luamethod(ObjectRef, native_get_animation),
luamethod(ObjectRef, native_set_animation_frame_speed),
luamethod(ObjectRef, native_set_bone_position),
luamethod(ObjectRef, native_get_bone_position),
luamethod(ObjectRef, native_set_attach),
luamethod(ObjectRef, native_get_attach),
luamethod(ObjectRef, native_get_children),
luamethod(ObjectRef, native_set_detach),
luamethod(ObjectRef, native_set_properties),
luamethod(ObjectRef, native_get_properties),
luamethod(ObjectRef, native_set_nametag_attributes),
luamethod(ObjectRef, native_get_nametag_attributes),

luamethod_aliased(ObjectRef, native_set_velocity, setvelocity),
luamethod_aliased(ObjectRef, native_add_velocity, add_player_velocity),
luamethod_aliased(ObjectRef, native_get_velocity, getvelocity),
luamethod_dep(ObjectRef, native_get_velocity, native_get_player_velocity),
//register new native alias to test native function
luamethod_dep_native(ObjectRef, get_velocity, native_get_player_velocity),

// LuaEntitySAO-only
luamethod_aliased(ObjectRef, native_set_acceleration, native_setacceleration),
luamethod_aliased(ObjectRef, native_get_acceleration, native_getacceleration),
luamethod_aliased(ObjectRef, native_set_yaw, setyaw),
luamethod_aliased(ObjectRef, native_get_yaw, getyaw),
luamethod(ObjectRef, native_set_rotation),
luamethod(ObjectRef, native_get_rotation),
luamethod_aliased(ObjectRef, native_set_texture_mod, native_settexturemod),
luamethod(ObjectRef, native_get_texture_mod),
luamethod_aliased(ObjectRef, native_set_sprite, native_setsprite),
luamethod(ObjectRef, native_get_entity_name),
luamethod(ObjectRef, native_get_luaentity),

// Player-only
luamethod(ObjectRef, native_is_player),
luamethod(ObjectRef, native_get_player_name),
luamethod(ObjectRef, native_get_look_dir),
luamethod(ObjectRef, native_get_look_pitch),
luamethod(ObjectRef, native_get_look_yaw),
luamethod(ObjectRef, native_get_look_vertical),
luamethod(ObjectRef, native_get_look_horizontal),
luamethod(ObjectRef, native_set_look_horizontal),
luamethod(ObjectRef, native_set_look_vertical),
luamethod(ObjectRef, native_set_look_yaw),
luamethod(ObjectRef, native_set_look_pitch),
luamethod(ObjectRef, native_get_fov),
luamethod(ObjectRef, native_set_fov),
luamethod(ObjectRef, native_get_breath),
luamethod(ObjectRef, native_set_breath),
luamethod(ObjectRef, native_get_attribute),
luamethod(ObjectRef, native_set_attribute),
luamethod(ObjectRef, native_get_meta),
luamethod(ObjectRef, native_set_inventory_formspec),
luamethod(ObjectRef, native_get_inventory_formspec),
luamethod(ObjectRef, native_set_formspec_prepend),
luamethod(ObjectRef, native_get_formspec_prepend),
luamethod(ObjectRef, native_get_player_control),
luamethod(ObjectRef, native_get_player_control_bits),
luamethod(ObjectRef, native_set_physics_override),
luamethod(ObjectRef, native_get_physics_override),
luamethod(ObjectRef, native_hud_add),
luamethod(ObjectRef, native_hud_remove),
luamethod(ObjectRef, native_hud_change),
luamethod(ObjectRef, native_hud_get),
luamethod(ObjectRef, native_hud_set_flags),
luamethod(ObjectRef, native_hud_get_flags),
luamethod(ObjectRef, native_hud_set_hotbar_itemcount),
luamethod(ObjectRef, native_hud_get_hotbar_itemcount),
luamethod(ObjectRef, native_hud_set_hotbar_image),
luamethod(ObjectRef, native_hud_get_hotbar_image),
luamethod(ObjectRef, native_hud_set_hotbar_selected_image),
luamethod(ObjectRef, native_hud_get_hotbar_selected_image),
luamethod(ObjectRef, native_set_sky),
luamethod(ObjectRef, native_get_sky),
luamethod(ObjectRef, native_get_sky_color),
luamethod(ObjectRef, native_set_sun),
luamethod(ObjectRef, native_get_sun),
luamethod(ObjectRef, native_set_moon),
luamethod(ObjectRef, native_get_moon),
luamethod(ObjectRef, native_set_stars),
luamethod(ObjectRef, native_get_stars),
luamethod(ObjectRef, native_set_clouds),
luamethod(ObjectRef, native_get_clouds),
luamethod(ObjectRef, native_override_day_night_ratio),
luamethod(ObjectRef, native_get_day_night_ratio),
luamethod(ObjectRef, native_set_local_animation),
luamethod(ObjectRef, native_get_local_animation),
luamethod(ObjectRef, native_set_eye_offset),
luamethod(ObjectRef, native_get_eye_offset),
luamethod(ObjectRef, native_send_mapblock),
luamethod(ObjectRef, native_set_minimap_modes),
{0,0}
};
Loading
Loading