[Mod] X-Ray for Minetest [xray]

User avatar
Max1Truc
New member
 
Posts: 8
Joined: Sat Jul 21, 2018 12:32
Location: France
GitHub: Max1Truc
IRC: Max1Truc
In-game: Max1Truc

[Mod] X-Ray for Minetest [xray]

by Max1Truc » Sun Jul 22, 2018 10:13

Provides a chat command that allows the player(s) to see through stone.

Version: 2.0
License: GNU GPL v3 for code and CC0 for texture
Dependencies: default mod (found in minetest_game)
Download page: https://notabug.org/Max1Truc/minetest-xray/releases
Latest direct download: https://notabug.org/Max1Truc/minetest-x ... master.zip
Source code: https://notabug.org/Max1Truc/minetest-xray

This version of the minetest's xray mod was downloaded from
https://github.com/cornernote/minetest-xray because code from
InfinityProject on Dropbox wasn't available (404), some fixes were
then made to make this mod work on minetest 0.4.16 without much bugs
and to improve user experience.

Screenshots


Before activating xray :
Image
After activating xray :
Image

Installation



Unzip the archive, copy the folder and
place it in minetest/mods/

( GNU/Linux: If you use a system-wide installation place
it in ~/.minetest/mods/. )

( If you only want this to be used in a single world, place
the folder in worldmods/ in your worlddirectory. )

For further information or help see:
http://wiki.minetest.com/wiki/Installing_Mods
Attachments
screenshot_20180725_232033.png
With xray
(168.88 KiB) Not downloaded yet
screenshot_20180725_232025.png
Before xray
(153.13 KiB) Not downloaded yet
Last edited by Max1Truc on Wed Aug 15, 2018 20:12, edited 3 times in total.
 

User avatar
Max1Truc
New member
 
Posts: 8
Joined: Sat Jul 21, 2018 12:32
Location: France
GitHub: Max1Truc
IRC: Max1Truc
In-game: Max1Truc
 

User avatar
Krock
Developer
 
Posts: 4096
Joined: Thu Oct 03, 2013 07:48
Location: Switzerland
GitHub: SmallJoker

Re: [Mod] X-Ray for Minetest [xray]

by Krock » Sun Jul 22, 2018 10:45

Thanks for your contribution. The mod works, but it's somewhat slow. You could use the Lua VoxelManipulator to speed up the node replacement a bit. If that's a bit complicated, then consider replacing `set_node` with `swap_node`, which also improves the performance a bit by skipping the Lua callbacks.

Also replace `minetest.env:` with `minetest.`. That notation is deprecated for a long time already, but is used in old (and recycled) mods.
Mod Search Engine - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>
 

User avatar
Max1Truc
New member
 
Posts: 8
Joined: Sat Jul 21, 2018 12:32
Location: France
GitHub: Max1Truc
IRC: Max1Truc
In-game: Max1Truc

Re: [Mod] X-Ray for Minetest [xray]

by Max1Truc » Mon Jul 23, 2018 08:26

Ok, thanks, I have just fixed the deprecated notation.
I am now working on using the Lua Voxel Manipulator.

EDIT : Added screenshots
Last edited by Max1Truc on Wed Jul 25, 2018 21:31, edited 1 time in total.
 

User avatar
ManElevation
Member
 
Posts: 887
Joined: Tue Aug 02, 2016 22:04
Location: Madrid,Spain
GitHub: ManElevation
IRC: ManElevation
In-game: ManElevation

Re: [Mod] X-Ray for Minetest [xray]

by ManElevation » Mon Jul 23, 2018 14:46

sounds good!
screenshot?
My Public Mods! Discord: Rottweiler Games#3368
 

User avatar
Max1Truc
New member
 
Posts: 8
Joined: Sat Jul 21, 2018 12:32
Location: France
GitHub: Max1Truc
IRC: Max1Truc
In-game: Max1Truc

Re: [Mod] X-Ray for Minetest [xray]

by Max1Truc » Thu Jul 26, 2018 17:49

@ Krock
Could you help me to find out what's going wrong with my implementation of the Lua Voxel Manipulator on the "use_lvm" branch ?
User have to move after activating xray with the command and sometimes some stone isn't converted.
URL : https://notabug.org/Max1Truc/minetest-xray/src/use_lvm
 

User avatar
Krock
Developer
 
Posts: 4096
Joined: Thu Oct 03, 2013 07:48
Location: Switzerland
GitHub: SmallJoker

Re: [Mod] X-Ray for Minetest [xray]

by Krock » Thu Jul 26, 2018 18:09

Max1Truc wrote:@ Krock
Could you help me to find out what's going wrong with my implementation of the Lua Voxel Manipulator on the "use_lvm" branch ?

The Lua Voxel Manipulator expects whole numbers as input. `player:get_pos()` however returns fractional coordinates. It's fixed quite easily:

Code: Select all
xray.replace = function(player_pos)
  -- Gen pos1 and pos2
  player_pos = vector.round(player_pos)
  local pos1 = vector.subtract(player_pos, xray.range)
  local pos2 = vector.add(player_pos, xray.range)

  -- Read data into LVM
  local vm = minetest.get_voxel_manip()


Now that replacing works, you might also want adapt this to the restore function :)
Mod Search Engine - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>
 

User avatar
Max1Truc
New member
 
Posts: 8
Joined: Sat Jul 21, 2018 12:32
Location: France
GitHub: Max1Truc
IRC: Max1Truc
In-game: Max1Truc

Re: [Mod] X-Ray for Minetest [xray]

by Max1Truc » Thu Jul 26, 2018 19:22

Thanks !
Now it is working.
But I didn't understand how using the LuaVoxelManipulator would speed up the restore function because it uses an "abm" which handles the xray nodes one by one.
 

User avatar
Max1Truc
New member
 
Posts: 8
Joined: Sat Jul 21, 2018 12:32
Location: France
GitHub: Max1Truc
IRC: Max1Truc
In-game: Max1Truc

Re: [Mod] X-Ray for Minetest [xray]

by Max1Truc » Sun Aug 05, 2018 19:29

Hey @Krock could you help me to figure out how to use the Lua Voxel Manipulators with the restore function?
Last edited by Max1Truc on Wed Aug 15, 2018 16:12, edited 1 time in total.
 

User avatar
Krock
Developer
 
Posts: 4096
Joined: Thu Oct 03, 2013 07:48
Location: Switzerland
GitHub: SmallJoker

Re: [Mod] X-Ray for Minetest [xray]

by Krock » Sun Aug 05, 2018 21:23

Alright. We can do a bulk update by doing basically the same as in the "replace" function. Except that each position has to be checked whether a player is nearby. If that check is omitted, LVM will just restore the xray nodes next to the player.
What we want is basically this:
Code: Select all
2018-08-05 23:17:33: ACTION[Server]: [xray] Replaced 116 default:stone nodes with xray:stone near (75,-4,223)
2018-08-05 23:17:33: ACTION[Server]: [xray] Replaced 203 default:stone nodes with xray:stone near (73,-4,223)
2018-08-05 23:17:34: ACTION[Server]: [xray] Replaced 113 default:stone nodes with xray:stone near (72,-4,223)
2018-08-05 23:17:34: ACTION[Server]: [xray] Replaced 230 default:stone nodes with xray:stone near (71,-4,224)
2018-08-05 23:17:35: ACTION[Server]: [xray] Restored 589 xray:stone nodes near (79,-9,207)
2018-08-05 23:17:35: ACTION[Server]: [xray] Restored 223 xray:stone nodes near (79,-1,207)
2018-08-05 23:17:35: ACTION[Server]: [xray] Restored 88 xray:stone nodes near (66,-9,219)
2018-08-05 23:17:35: ACTION[Server]: [xray] Restored 45 xray:stone nodes near (66,-1,219)
2018-08-05 23:17:35: ACTION[Server]: [xray] Restored 373 xray:stone nodes near (74,-9,216)

Replace as many nodes at once to reduce client lag. The upper part already works, but now we need a function to easily check whether we may replace a coordinate:
Code: Select all
local function player_in_range(pos)
   for _, object in ipairs(minetest.get_objects_inside_radius(pos, xray.range + 2)) do
      if object:is_player() and xray.mode[object:get_player_name()] == 1 then
         return true
      end
   end
   return false
end


And now copy&paste the "replace" function, get the content ID of our xray stone and add a counter to see how efficient it is:
Code: Select all
-- restore xray to stone
xray.restore = function(pos)
   if player_in_range(pos) then
      return
   end
   local count = 0

   -- Bulk update nodes around
   local c_xray = minetest.get_content_id("xray:stone")
   local pos1 = vector.subtract(pos, xray.range + 2)
    local pos2 = vector.add(pos, xray.range + 2)

   -- Read data into LVM
   local vm = minetest.get_voxel_manip()
   local emin, emax = vm:read_from_map(pos1, pos2)
   local a = VoxelArea:new{
      MinEdge = emin,
      MaxEdge = emax
   }
   local data = vm:get_data()

   -- Modify data
   for z = pos1.z, pos2.z do
   for y = pos1.y, pos2.y do
   for x = pos1.x, pos2.x do
      local vi = a:index(x, y, z)
      if data[vi] == c_xray and not player_in_range({x = x, y = y, z = z}) then
         data[vi] = c_stone
         count = count + 1
      end
   end
   end
   end
   vm:set_data(data)
   vm:write_to_map(true)
   xray.log("Restored " .. count .. " xray:stone nodes near " .. minetest.pos_to_string(pos))
end

Boom. That's it.
Mod Search Engine - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>
 

User avatar
Max1Truc
New member
 
Posts: 8
Joined: Sat Jul 21, 2018 12:32
Location: France
GitHub: Max1Truc
IRC: Max1Truc
In-game: Max1Truc

Re: [Mod] X-Ray for Minetest [xray]

by Max1Truc » Wed Aug 15, 2018 16:39

Okay @Krock, so we still use an abm but we optimize it, right ?

Post-Scriptum: Sorry for my late answer
 

User avatar
Max1Truc
New member
 
Posts: 8
Joined: Sat Jul 21, 2018 12:32
Location: France
GitHub: Max1Truc
IRC: Max1Truc
In-game: Max1Truc

Re: [Mod] X-Ray for Minetest [xray]

by Max1Truc » Wed Aug 15, 2018 19:24

Okay, did it.
Now merging.

Really, thanks, you did almost all the work.
 


Return to Mod Releases



Who is online

Users browsing this forum: Bing [Bot] and 4 guests