diff options
author | cheapie <no-email-for-you@example.com> | 2023-08-12 23:36:00 -0500 |
---|---|---|
committer | cheapie <no-email-for-you@example.com> | 2023-08-12 23:36:00 -0500 |
commit | e35e98148acff3c7da7b9b70619ae625fef0bbef (patch) | |
tree | 0678a34b8aca08de95ab8219d6474fdd6176855a | |
parent | a72dc1ff70cda30dcaa8ea23193795bee508bc9b (diff) | |
download | celevator-e35e98148acff3c7da7b9b70619ae625fef0bbef.tar celevator-e35e98148acff3c7da7b9b70619ae625fef0bbef.tar.gz celevator-e35e98148acff3c7da7b9b70619ae625fef0bbef.tar.bz2 celevator-e35e98148acff3c7da7b9b70619ae625fef0bbef.tar.xz celevator-e35e98148acff3c7da7b9b70619ae625fef0bbef.zip |
Initial in-car PI work
PI is now spawned and moves with the car, no actual display yet
-rw-r--r-- | car.lua | 23 | ||||
-rw-r--r-- | drive_entity.lua | 26 | ||||
-rw-r--r-- | pilantern.lua | 32 | ||||
-rw-r--r-- | textures/celevator_pi_background_incar.png | bin | 0 -> 9055 bytes |
4 files changed, 64 insertions, 17 deletions
@@ -367,3 +367,26 @@ function celevator.car.spawncar(origin,yaw) end end end + +minetest.register_abm({ + label = "Respawn in-car PI displays", + nodenames = {"celevator:car_020"}, + interval = 1, + chance = 1, + action = function(pos) + local entitiesnearby = minetest.get_objects_inside_radius(pos,0.5) + for _,i in pairs(entitiesnearby) do + if i:get_luaentity() and i:get_luaentity().name == "celevator:incar_pi_entity" then + return + end + end + local entity = minetest.add_entity(pos,"celevator:incar_pi_entity") + local fdir = vector.rotate_around_axis(minetest.facedir_to_dir(minetest.get_node(pos).param2),vector.new(0,1,0),math.pi/2) + local etex = celevator.pi.generatetexture(" --",false,false,false,true) + entity:set_properties({ + textures = {etex}, + }) + entity:set_yaw(minetest.dir_to_yaw(fdir)) + entity:set_pos(vector.add(pos,vector.multiply(fdir,0.44))) + end, +}) diff --git a/drive_entity.lua b/drive_entity.lua index 6438f40..6f4f988 100644 --- a/drive_entity.lua +++ b/drive_entity.lua @@ -137,21 +137,27 @@ function celevator.drives.entity.nodestoentities(nodes,ename) local refs = {} for _,pos in ipairs(nodes) do local node = minetest.get_node(pos) - local attachobjs = minetest.get_objects_inside_radius(pos,0.9) + local attach = minetest.get_objects_inside_radius(pos,0.9) local eref = minetest.add_entity(pos,(ename or "celevator:car_moving")) eref:set_properties({ wield_item = node.name, }) eref:set_yaw(minetest.dir_to_yaw(minetest.fourdir_to_dir(node.param2))) + table.insert(refs,eref) if not ename then --If ename is set, something other than the car is moving - for _,attachref in ipairs(attachobjs) do - local attachpos = attachref:get_pos() - local attachoffset = vector.multiply(vector.subtract(pos,attachpos),1/0.667) - attachref:set_attach(eref,"",attachoffset) + for _,attachref in ipairs(attach) do + if attachref:get_luaentity() and attachref:get_luaentity().name == "celevator:incar_pi_entity" then + table.insert(refs,attachref) + else + local attachpos = attachref:get_pos() + local basepos = eref:get_pos() + local attachoffset = vector.multiply(vector.subtract(attachpos,basepos),30) + attachoffset = vector.rotate_around_axis(attachoffset,vector.new(0,-1,0),eref:get_yaw()) + attachref:set_attach(eref,"",attachoffset) + end end end minetest.remove_node(pos) - table.insert(refs,eref) end return refs end @@ -160,7 +166,7 @@ function celevator.drives.entity.entitiestonodes(refs) local ok = true for _,eref in ipairs(refs) do local pos = eref:get_pos() - if pos then + if pos and (eref:get_luaentity().name == "celevator:car_moving" or eref:get_luaentity().name == "celevator:hwdoor_moving") then pos = vector.round(pos) local node = { name = eref:get_properties().wield_item, @@ -168,6 +174,9 @@ function celevator.drives.entity.entitiestonodes(refs) } minetest.set_node(pos,node) eref:remove() + elseif pos and eref:get_luaentity().name == "celevator:incar_pi_entity" then + pos = vector.new(pos.x,math.floor(pos.y+0.5),pos.z) + eref:set_pos(pos) else ok = false end @@ -424,6 +433,7 @@ local function updatecarpos(pos) local carpos = carsearch(pos) if carpos then meta:set_string("origin",minetest.pos_to_string(carpos)) + minetest.get_meta(carpos):set_string("machinepos",minetest.pos_to_string(pos)) meta:set_string("infotext",string.format("Using car with origin %s",minetest.pos_to_string(carpos))) else meta:set_string("infotext","No car found! Punch to try again") @@ -444,7 +454,7 @@ minetest.register_node("celevator:machine",{ after_place_node = updatecarpos, on_punch = function(pos) local meta = minetest.get_meta(pos) - if not minetest.pos_to_string(meta:get_string("origin")) then + if not minetest.string_to_pos(meta:get_string("origin")) then updatecarpos(pos) end end, diff --git a/pilantern.lua b/pilantern.lua index 6a88861..55f2867 100644 --- a/pilantern.lua +++ b/pilantern.lua @@ -10,20 +10,34 @@ minetest.register_entity("celevator:pi_entity",{ physical = false, collisionbox = {0,0,0,0,0,0,}, textures = {"celevator_transparent.png",}, + static_save = false, }, }) -local function removeentity(pos) +minetest.register_entity("celevator:incar_pi_entity",{ + initial_properties = { + visual = "upright_sprite", + physical = false, + collisionbox = {0,0,0,0,0,0,}, + textures = {"celevator_transparent.png",}, + _flashtimer = 0, + _machinepos = "", + static_save = false, + }, +}) + +function celevator.pi.removeentity(pos) local entitiesnearby = minetest.get_objects_inside_radius(pos,0.5) for _,i in pairs(entitiesnearby) do - if i:get_luaentity() and i:get_luaentity().name == "celevator:pi_entity" then + if i:get_luaentity() and (i:get_luaentity().name == "celevator:pi_entity" or i:get_luaentity().name == "celevator:incar_pi_entity") then i:remove() end end end -local function generatetexture(text,uparrow,downarrow,lanternoffset) +function celevator.pi.generatetexture(text,uparrow,downarrow,lanternoffset,carbg) local out = "[combine:600x600:0,0=celevator_transparent.png" + if carbg then out = out..":0,0=celevator_pi_background_incar.png" end local yp = 440 if lanternoffset then yp = 290 end for i=1,string.len(text),1 do @@ -36,7 +50,7 @@ local function generatetexture(text,uparrow,downarrow,lanternoffset) end function celevator.pi.updatedisplay(pos) - removeentity(pos) + celevator.pi.removeentity(pos) local meta = minetest.get_meta(pos) local text = meta:get_string("text") local entity = minetest.add_entity(pos,"celevator:pi_entity") @@ -47,12 +61,12 @@ function celevator.pi.updatedisplay(pos) local flash_is = meta:get_int("flash_is") > 0 local flashtimer = meta:get_int("flashtimer") > 0 local islantern = minetest.get_item_group(minetest.get_node(pos).name,"_celevator_lantern") == 1 - local etex = generatetexture(text,uparrow,downarrow,islantern) + local etex = celevator.pi.generatetexture(text,uparrow,downarrow,islantern) if flash_fs then - if flashtimer then etex = generatetexture(" FS",uparrow,downarrow) end + if flashtimer then etex = celevator.pi.generatetexture(" FS",uparrow,downarrow) end entity:set_properties({_flash_fs = true,_flash_is = false,}) elseif flash_is then - if flashtimer then etex = generatetexture(" IS",uparrow,downarrow) end + if flashtimer then etex = celevator.pi.generatetexture(" IS",uparrow,downarrow) end entity:set_properties({_flash_fs = false,_flash_is = true,}) else entity:set_properties({_flash_fs = false,_flash_is = false,}) @@ -122,7 +136,7 @@ minetest.register_node("celevator:pi",{ {-0.25,-0.453,0.475,0.25,-0.125,0.5}, }, }, - on_destruct = removeentity, + on_destruct = celevator.pi.removeentity, on_construct = function(pos) local meta = minetest.get_meta(pos) meta:set_string("text","--") @@ -265,7 +279,7 @@ for _,state in ipairs(validstates) do }, paramtype = "light", paramtype2 = "facedir", - on_destruct = removeentity, + on_destruct = celevator.pi.removeentity, drawtype = "nodebox", node_box = { type = "fixed", diff --git a/textures/celevator_pi_background_incar.png b/textures/celevator_pi_background_incar.png Binary files differnew file mode 100644 index 0000000..dd4b03c --- /dev/null +++ b/textures/celevator_pi_background_incar.png |