From b16d25c8280c4316b95c6b2bbb73bdd49a65b7c3 Mon Sep 17 00:00:00 2001 From: cheapie Date: Sun, 21 Feb 2021 18:36:09 -0600 Subject: [PATCH] Convert game controller to use entity attachment instead of a physics override This should make it get along better with other mods that affect physics overrides, and also prevent the "walking in place" when using it. --- controller.lua | 41 ++++++++++++++++++++--------- docs/game-controller.txt | 1 - textures/digistuff_transparent.png | Bin 0 -> 526 bytes 3 files changed, 28 insertions(+), 14 deletions(-) create mode 100644 textures/digistuff_transparent.png diff --git a/controller.lua b/controller.lua index 4d2fdf7..f0fbced 100644 --- a/controller.lua +++ b/controller.lua @@ -14,6 +14,15 @@ local players_on_controller = {} local last_seen_inputs = {} +local function 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 == "digistuff:controller_entity" then + i:remove() + end + end +end + local function process_inputs(pos) local meta = minetest.get_meta(pos) local hash = minetest.hash_node_position(pos) @@ -36,14 +45,6 @@ local function process_inputs(pos) players_on_controller[hash] = nil return end - local distance = vector.distance(pos,player:get_pos()) - if distance > 1 then - digiline:receptor_send(pos,digiline_rules,meta:get_string("channel"),"player_left") - minetest.get_meta(pos):set_string("infotext","Digilines Game Controller Ready\n(right-click to use)") - player:set_physics_override({speed = 1,jump = 1,}) - players_on_controller[hash] = nil - return - end local inputs = player:get_player_control() inputs.pitch = player:get_look_vertical() inputs.yaw = player:get_look_horizontal() @@ -71,11 +72,15 @@ end local function release_player(pos) local hash = minetest.hash_node_position(pos) local player = minetest.get_player_by_name(players_on_controller[hash]) - if player then - player:set_physics_override({speed = 1,jump = 1,}) - player:set_pos(vector.add(pos,vector.new(0.25,0,0.25))) + if player and player:get_properties()._is_gamecontroller then + local parent = player:get_attach() + print(dump(parent:get_properties())) + if parent then + player:set_detach() + end minetest.chat_send_player(players_on_controller[hash],"You are now free to move.") end + removeEntity(pos) local meta = minetest.get_meta(pos) meta:set_string("infotext","Digilines Game Controller Ready\n(right-click to use)") last_seen_inputs[players_on_controller[hash]] = nil @@ -92,8 +97,8 @@ local function trap_player(pos,player) return else players_on_controller[hash] = newname - player:set_pos(vector.add(pos,vector.new(0,-0.4,0))) - player:set_physics_override({speed = 0,jump = 0,}) + local entity = minetest.add_entity(pos,"digistuff:controller_entity") + player:set_attach(entity,"",vector.new(0,0,0),vector.new(0,0,0)) minetest.chat_send_player(newname,"You are now using a digilines game controller. Right-click the controller again to be released.") local meta = minetest.get_meta(pos) meta:set_string("infotext","Digilines Game Controller\nIn use by: "..newname) @@ -202,6 +207,16 @@ minetest.register_node("digistuff:controller_programmed", { }, }) +minetest.register_entity("digistuff:controller_entity",{ + initial_properties = { + visual = "sprite", + physical = false, + collisionbox = {0,0,0,0,0,0,}, + textures = {"digistuff_transparent.png",}, + _is_gamecontroller = true, + }, +}) + local acc_dtime = 0 minetest.register_globalstep(function(dtime) diff --git a/docs/game-controller.txt b/docs/game-controller.txt index bd63dc8..7e2e378 100644 --- a/docs/game-controller.txt +++ b/docs/game-controller.txt @@ -5,5 +5,4 @@ When a player leaves a controller, the string "player_left" is sent. In addition to right-clicking the controller in use to stop using it, the following will also cause a player to stop using the controller: * The controller is moved or removed * The player leaves the game -* The player is teleported away from the controller * The controller receives the string "release" on its digilines channel diff --git a/textures/digistuff_transparent.png b/textures/digistuff_transparent.png new file mode 100644 index 0000000000000000000000000000000000000000..aa4056be8857be6f4d7a372262abd1708052d50c GIT binary patch literal 526 zcmV+p0`dKcP)EX>4Tx04R}tkv&MmKpe$iQ>7vmL5qk8W~fdUL`B3&t5Adrp;lu?Dk!1^3lUm1QcNUhKkDHhaQqUv6mk{8 z$gzMjRLG7W{11M2Yvv}#-K1a?Xn(Qok6|FN3)HK&{e5iP^%KDV3|whVf4K%sf0ABp zYT+ZGdmFg8ZfeRNaJd8YKk2d|JCdKKkjnw@XY@^Jp!XK&TyuMC?BnzSNK#kv8{ps& z7|B!iy2raaT6_EVOryUav*mKZ26KBU00006VoOIv0Ez&N008Pb@u&a*010qNS#tmY z3ljhU3ljkVnw%H_000McNliru