Replace deprecated method

This commit is contained in:
bri cassa 2021-04-04 16:42:55 +02:00
parent 453b6c7400
commit 59fcc6875e
5 changed files with 50 additions and 50 deletions

View File

@ -78,12 +78,12 @@ end
-- is the nearest to the maidroid.
function maidroid.maidroid.get_nearest_player(self, range_distance)
local player, min_distance = nil, range_distance
local position = self.object:getpos()
local position = self.object:get_pos()
local all_objects = minetest.get_objects_inside_radius(position, range_distance)
for _, object in pairs(all_objects) do
if object:is_player() then
local player_position = object:getpos()
local player_position = object:get_pos()
local distance = vector.distance(position, player_position)
if distance < min_distance then
@ -110,7 +110,7 @@ function maidroid.maidroid.get_front(self)
direction.z = 0
end
return vector.add(vector.round(self.object:getpos()), direction)
return vector.add(vector.round(self.object:get_pos()), direction)
end
-- maidroid.maidroid.get_front_node returns a node that exists in front of the maidroid.
@ -195,12 +195,12 @@ end
-- maidroid.maidroid.change_direction change direction to destination and velocity vector.
function maidroid.maidroid.change_direction(self, destination)
local position = self.object:getpos()
local position = self.object:get_pos()
local direction = vector.subtract(destination, position)
direction.y = 0
local velocity = vector.multiply(vector.normalize(direction), 1.5)
self.object:setvelocity(velocity)
self.object:set_velocity(velocity)
self:set_yaw_by_direction(direction)
end
@ -212,7 +212,7 @@ function maidroid.maidroid.change_direction_randomly(self)
z = math.random(0, 5) * 2 - 5,
}
local velocity = vector.multiply(vector.normalize(direction), 1.5)
self.object:setvelocity(velocity)
self.object:set_velocity(velocity)
self:set_yaw_by_direction(direction)
end
@ -336,7 +336,7 @@ function maidroid.register_egg(egg_name, def)
-- set maidroid's direction.
local new_maidroid = minetest.add_entity(pointed_thing.above, def.product_name)
new_maidroid:get_luaentity():set_yaw_by_direction(
vector.subtract(user:getpos(), new_maidroid:getpos())
vector.subtract(user:get_pos(), new_maidroid:get_pos())
)
new_maidroid:get_luaentity().owner_name = user:get_player_name()
new_maidroid:get_luaentity():update_infotext()
@ -482,7 +482,7 @@ function maidroid.register_maidroid(product_name, def)
}
-- attach dummy item to new maidroid.
local dummy_item = minetest.add_entity(self.object:getpos(), "maidroid:dummy_item")
local dummy_item = minetest.add_entity(self.object:get_pos(), "maidroid:dummy_item")
dummy_item:set_attach(self.object, "Arm_R", {x = 0.065, y = 0.50, z = -0.15}, {x = -45, y = 0, z = 0})
dummy_item:get_luaentity().maidroid_object = self.object
@ -490,7 +490,7 @@ function maidroid.register_maidroid(product_name, def)
if core ~= nil then
core.on_start(self)
else
self.object:setvelocity{x = 0, y = 0, z = 0}
self.object:set_velocity{x = 0, y = 0, z = 0}
self.object:setacceleration{x = 0, y = -10, z = 0}
end
end
@ -519,7 +519,7 @@ function maidroid.register_maidroid(product_name, def)
-- maidroid.maidroid.pickup_item pickup items placed and put it to main slot.
local function pickup_item(self)
local pos = self.object:getpos()
local pos = self.object:get_pos()
local radius = 1.0
local all_objects = minetest.get_objects_inside_radius(pos, radius)
@ -532,7 +532,7 @@ function maidroid.register_maidroid(product_name, def)
local stack = ItemStack(itemstring)
local leftover = inv:add_item("main", stack)
minetest.add_item(obj:getpos(), leftover)
minetest.add_item(obj:get_pos(), leftover)
obj:get_luaentity().itemstring = ""
obj:remove()
end

View File

@ -8,12 +8,12 @@ local state = {IDLE = 0, ACCOMPANY = 1}
local function on_start(self)
self.state = state.IDLE
self.object:setacceleration{x = 0, y = -10, z = 0}
self.object:setvelocity{x = 0, y = 0, z = 0}
self.object:set_velocity{x = 0, y = 0, z = 0}
end
local function on_stop(self)
self.state = nil
self.object:setvelocity{x = 0, y = 0, z = 0}
self.object:set_velocity{x = 0, y = 0, z = 0}
self:set_animation(maidroid.animation_frames.STAND)
end
@ -24,23 +24,23 @@ local function on_step(self, dtime)
return
end
local position = self.object:getpos()
local player_position = player:getpos()
local position = self.object:get_pos()
local player_position = player:get_pos()
local direction = vector.subtract(player_position, position)
local velocity = self.object:getvelocity()
local velocity = self.object:get_velocity()
if vector.length(direction) < 3 then
if self.state == state.ACCOMPANY then
self:set_animation(maidroid.animation_frames.STAND)
self.state = state.IDLE
self.object:setvelocity{x = 0, y = velocity.y, z = 0}
self.object:set_velocity{x = 0, y = velocity.y, z = 0}
end
else
if self.state == state.IDLE then
self:set_animation(maidroid.animation_frames.WALK)
self.state = state.ACCOMPANY
end
self.object:setvelocity{x = direction.x, y = velocity.y, z = direction.z} -- TODO
self.object:set_velocity{x = direction.x, y = velocity.y, z = direction.z} -- TODO
end
self:set_yaw_by_direction(direction)
@ -49,7 +49,7 @@ local function on_step(self, dtime)
local front_node = self:get_front_node()
if front_node.name ~= "air" and minetest.registered_nodes[front_node.name] ~= nil
and minetest.registered_nodes[front_node.name].walkable then
self.object:setvelocity{x = direction.x, y = 5, z = direction.z}
self.object:set_velocity{x = direction.x, y = 5, z = direction.z}
end
end
end

View File

@ -48,7 +48,7 @@ local to_walk_randomly, to_walk_to_plant, to_walk_to_mow, to_plant, to_mow
local function on_start(self)
self.object:setacceleration{x = 0, y = -10, z = 0}
self.object:setvelocity{x = 0, y = 0, z = 0}
self.object:set_velocity{x = 0, y = 0, z = 0}
self.state = state.WALK_RANDOMLY
self.time_counters = {}
self.path = nil
@ -56,7 +56,7 @@ local function on_start(self)
end
local function on_stop(self)
self.object:setvelocity{x = 0, y = 0, z = 0}
self.object:set_velocity{x = 0, y = 0, z = 0}
self.state = nil
self.time_counters = nil
self.path = nil
@ -64,7 +64,7 @@ local function on_stop(self)
end
local function is_near(self, pos, distance)
local p = self.object:getpos()
local p = self.object:get_pos()
-- p.y = p.y + 0.5
return vector.distance(p, pos) < distance
end
@ -79,9 +79,9 @@ walk_randomly = function(self, dtime)
local wield_stack = self:get_wield_item_stack()
if minetest.get_item_group(wield_stack:get_name(), "seed") > 0
or self:has_item_in_main(function(itemname) return (minetest.get_item_group(itemname, "seed") > 0) end) then
local destination = _aux.search_surrounding(self.object:getpos(), is_plantable_place, searching_range)
local destination = _aux.search_surrounding(self.object:get_pos(), is_plantable_place, searching_range)
if destination ~= nil then
local path = minetest.find_path(self.object:getpos(), destination, 10, 1, 1, "A*")
local path = minetest.find_path(self.object:get_pos(), destination, 10, 1, 1, "A*")
if path ~= nil then -- to walk to plant state.
to_walk_to_plant(self, path, destination)
@ -90,9 +90,9 @@ walk_randomly = function(self, dtime)
end
end
-- if couldn't find path to plant, try to mow.
local destination = _aux.search_surrounding(self.object:getpos(), is_mowable_place, searching_range)
local destination = _aux.search_surrounding(self.object:get_pos(), is_mowable_place, searching_range)
if destination ~= nil then
local path = minetest.find_path(self.object:getpos(), destination, 10, 1, 1, "A*")
local path = minetest.find_path(self.object:get_pos(), destination, 10, 1, 1, "A*")
if path ~= nil then -- to walk to mow state.
to_walk_to_mow(self, path, destination)
return
@ -110,7 +110,7 @@ walk_randomly = function(self, dtime)
self.time_counters[1] = self.time_counters[1] + 1
self.time_counters[2] = self.time_counters[2] + 1
local velocity = self.object:getvelocity()
local velocity = self.object:get_velocity()
if velocity.y == 0 then
local front_node = self:get_front_node()
@ -118,7 +118,7 @@ walk_randomly = function(self, dtime)
self:change_direction_randomly()
elseif front_node.name ~= "air" and minetest.registered_nodes[front_node.name] ~= nil
and minetest.registered_nodes[front_node.name].walkable then
self.object:setvelocity{x = velocity.x, y = 6, z = velocity.z}
self.object:set_velocity{x = velocity.x, y = 6, z = velocity.z}
end
end
return
@ -159,9 +159,9 @@ to_plant = function(self)
or self:move_main_to_wield(function(itemname) return (minetest.get_item_group(itemname, "seed") > 0) end) then
self.state = state.PLANT
self.time_counters[1] = 0
self.object:setvelocity{x = 0, y = 0, z = 0}
self.object:set_velocity{x = 0, y = 0, z = 0}
self:set_animation(maidroid.animation_frames.MINE)
self:set_yaw_by_direction(vector.subtract(self.destination, self.object:getpos()))
self:set_yaw_by_direction(vector.subtract(self.destination, self.object:get_pos()))
return
else
to_walk_randomly(self)
@ -172,9 +172,9 @@ end
to_mow = function(self)
self.state = state.MOW
self.time_counters[1] = 0
self.object:setvelocity{x = 0, y = 0, z = 0}
self.object:set_velocity{x = 0, y = 0, z = 0}
self:set_animation(maidroid.animation_frames.MINE)
self:set_yaw_by_direction(vector.subtract(self.destination, self.object:getpos()))
self:set_yaw_by_direction(vector.subtract(self.destination, self.object:get_pos()))
end
walk_to_plant_and_mow_common = function(self, dtime)
@ -198,7 +198,7 @@ walk_to_plant_and_mow_common = function(self, dtime)
if self.time_counters[1] >= FIND_PATH_TIME_INTERVAL then
self.time_counters[1] = 0
local path = minetest.find_path(self.object:getpos(), self.destination, 10, 1, 1, "A*")
local path = minetest.find_path(self.object:get_pos(), self.destination, 10, 1, 1, "A*")
if path == nil then
to_walk_randomly(self)
return
@ -224,13 +224,13 @@ walk_to_plant_and_mow_common = function(self, dtime)
else
-- if maidroid is stopped by obstacles, the maidroid must jump.
local velocity = self.object:getvelocity()
local velocity = self.object:get_velocity()
if velocity.y == 0 then
local front_node = self:get_front_node()
if front_node.name ~= "air" and minetest.registered_nodes[front_node.name] ~= nil
and minetest.registered_nodes[front_node.name].walkable
and not (minetest.get_item_group(front_node.name, "fence") > 0) then
self.object:setvelocity{x = velocity.x, y = 6, z = velocity.z}
self.object:set_velocity{x = velocity.x, y = 6, z = velocity.z}
end
end
end

View File

@ -6,7 +6,7 @@
local maidroid_instruction_set = {
-- popular (similars in lua_api) information gathering functions
getpos = function(_, thread)
local pos = thread.droid.object:getpos()
local pos = thread.droid.object:get_pos()
return true, {pos.x, pos.y, pos.z}
end,
@ -57,7 +57,7 @@ local maidroid_instruction_set = {
end
-- play sound
local p = droid.object:getpos()
local p = droid.object:get_pos()
p.y = p.y - 1
local node_under = minetest.get_node(p).name
local def = minetest.registered_nodes[node_under]
@ -72,12 +72,12 @@ local maidroid_instruction_set = {
-- perform jump
droid.vel.y = math.sqrt(-2 * h * droid.object:getacceleration().y)
droid.object:setvelocity(droid.vel)
droid.object:set_velocity(droid.vel)
return true, true
end,
beep = function(_, thread)
minetest.sound_play("maidroid_beep", {pos = thread.droid.object:getpos()})
minetest.sound_play("maidroid_beep", {pos = thread.droid.object:get_pos()})
return true
end,
}
@ -111,7 +111,7 @@ end
local function on_start(self)
self.object:setacceleration{x = 0, y = -10, z = 0}
self.object:setvelocity{x = 0, y = 0, z = 0}
self.object:set_velocity{x = 0, y = 0, z = 0}
self.vel = {x = 0, y = 0, z = 0}
self.vel_prev = self.vel
@ -134,7 +134,7 @@ local function on_step(self)
return
end
self.vel_prev = self.vel
self.vel = self.object:getvelocity()
self.vel = self.object:get_velocity()
thread:try_rebirth()
end
@ -151,7 +151,7 @@ local function on_stop(self)
self.thread:exit()
self.thread = nil
self.object:setvelocity{x = 0, y = 0, z = 0}
self.object:set_velocity{x = 0, y = 0, z = 0}
end
-- register a definition of a new core.

View File

@ -10,14 +10,14 @@ local PLACE_TIME = 4
local function on_start(self)
self.state = state.IDLE
self.object:setacceleration{x = 0, y = -10, z = 0}
self.object:setvelocity{x = 0, y = 0, z = 0}
self.object:set_velocity{x = 0, y = 0, z = 0}
self.time_counter = -1
self.is_placing = false
end
local function on_stop(self)
self.state = nil
self.object:setvelocity{x = 0, y = 0, z = 0}
self.object:set_velocity{x = 0, y = 0, z = 0}
self:set_animation(maidroid.animation_frames.STAND)
self.time_counter = nil
self.is_placing = nil
@ -67,16 +67,16 @@ local function on_step(self, dtime)
return
end
local position = self.object:getpos()
local player_position = player:getpos()
local position = self.object:get_pos()
local player_position = player:get_pos()
local direction = vector.subtract(player_position, position)
local velocity = self.object:getvelocity()
local velocity = self.object:get_velocity()
if vector.length(direction) < 3 then
if self.state == state.ACCOMPANY then
self:set_animation(maidroid.animation_frames.STAND)
self.state = state.IDLE
self.object:setvelocity{x = 0, y = velocity.y, z = 0}
self.object:set_velocity{x = 0, y = velocity.y, z = 0}
end
if not self.is_placing then
@ -97,7 +97,7 @@ local function on_step(self, dtime)
self:set_animation(maidroid.animation_frames.WALK)
self.state = state.ACCOMPANY
end
self.object:setvelocity{x = direction.x, y = velocity.y, z = direction.z} -- TODO
self.object:set_velocity{x = direction.x, y = velocity.y, z = direction.z} -- TODO
if not self.is_placing then
local front = self:get_front() -- if it is dark, set touch.
@ -119,7 +119,7 @@ local function on_step(self, dtime)
local front_node = self:get_front_node()
if front_node.name ~= "air" and minetest.registered_nodes[front_node.name] ~= nil
and minetest.registered_nodes[front_node.name].walkable then
self.object:setvelocity{x = direction.x, y = 5, z = direction.z}
self.object:set_velocity{x = direction.x, y = 5, z = direction.z}
end
end
end