From a39b70a90a530d95b66b39b16512733ec094bd14 Mon Sep 17 00:00:00 2001 From: cheapie Date: Fri, 11 Aug 2023 21:32:24 -0500 Subject: Handle entities unloading If the car disappears while moving (someone did /clearobjects, the server restarted, the mapblock unloaded, etc.), simulate the rest of the motion and spawn a new car upon arrival --- car.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'car.lua') diff --git a/car.lua b/car.lua index 5211ecb..a391bf7 100644 --- a/car.lua +++ b/car.lua @@ -1,3 +1,5 @@ +celevator.car = {} + local pieces = { { _position = "000", @@ -344,3 +346,24 @@ for _,def in ipairs(pieces) do def.light_source = 9 minetest.register_node("celevator:car_"..def._position,def) end + +function celevator.car.spawncar(origin,yaw) + local right = vector.rotate_around_axis(vector.new(1,0,0),vector.new(0,1,0),yaw) + local back = vector.rotate_around_axis(vector.new(0,0,1),vector.new(0,1,0),yaw) + local up = vector.new(0,1,0) + for x=0,1,1 do + for y=0,2,1 do + for z=0,2,1 do + local pos = vector.copy(origin) + pos = vector.add(pos,vector.multiply(right,x)) + pos = vector.add(pos,vector.multiply(back,z)) + pos = vector.add(pos,vector.multiply(up,y)) + local node = { + name = string.format("celevator:car_%d%d%d",x,y,z), + param2 = minetest.dir_to_fourdir(minetest.yaw_to_dir(yaw)), + } + minetest.set_node(pos,node) + end + end + end +end -- cgit v1.2.3