[Mod] Flyingships

User avatar
neko259
Member
 
Posts: 769
Joined: Sun Jun 19, 2011 06:51

[Mod] Flyingships

by neko259 » Sat Mar 21, 2015 21:08

This mod allows you to connect nodes into a structure that can fly as a whole. The code was originally taken from technic' frames but changed a lot.

You connect a node by placing a motor, connecting any blocks to it (no frames!) and punching it with a configurator. If there are no too many blocks in the structure (e.g. if you forgot to disconnect it from the ground), all blocks will be saved in the motor. Then if you craft a beautiful pink key, you punch the motor with it and the structure flies in the punch direction.

Image
Image

The recipes can be found by the crafting guide. Briefly, they are:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_craft({
    output = "flyingships:frame_motor",
    recipe = {
        {"mesecons:mesecon", "mesecons_materials:glue", "mesecons:mesecon"},
        {"mesecons:mesecon", "default:copperblock", "mesecons:mesecon"},
        {"mesecons:mesecon", "mesecons_materials:glue", "mesecons:mesecon"}
    }
})

minetest.register_craft({
    output = "flyingships:frame_motor_directed",
    recipe = {
        {"mesecons:mesecon", "mesecons_materials:glue", "mesecons:mesecon"},
        {"mesecons:mesecon", "default:goldblock", "mesecons:mesecon"},
        {"mesecons:mesecon", "mesecons_materials:glue", "mesecons:mesecon"}
    }
})

minetest.register_craft({
    output = "flyingships:key",
    recipe = {
        {"", "default:diamond", ""},
        {"", "default:stick", ""},
        {"", "mesecons_materials:glue", ""}
    }
})

minetest.register_craft({
    output = "flyingships:configurator",
    recipe = {
        {"default:diamond", "default:diamond", "default:diamond"},
        {"", "default:stick", ""},
        {"", "mesecons_materials:glue", ""}
    }
})


The directed motor is a motor that works similar to the one in technic: you connect mesecon to it and make a signal. It can be used as a simple one with the key too,

Repo and download: https://bitbucket.org/neko259/flyingships
 

User avatar
neko259
Member
 
Posts: 769
Joined: Sun Jun 19, 2011 06:51

Re: [Mod] Flyingships

by neko259 » Sat Mar 21, 2015 21:09

Version 1.0 seems to be stable but I've tested it only for several minutes. So feel free to write about any bugs.
 

User avatar
Krock
Member
 
Posts: 3598
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker

Re: [Mod] Flyingships

by Krock » Sun Mar 22, 2015 11:02

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
12:00:09: ACTION[ServerThread]: singleplayer uses flyingships:key, pointing at [node under=-429,21,-
213 above=-429,22,-213]
12:00:09: ERROR[main]: ServerError: E:\Programme\minetest\bin\..\mods\flyingships/functions.lua:140:
 bad argument #1 to 'ipairs' (table expected, got nil)
12:00:09: ERROR[main]: stack traceback:
12:00:09: ERROR[main]:  [C]: in function 'ipairs'
12:00:09: ERROR[main]:  E:\Programme\minetest\bin\..\mods\flyingships/functions.lua:140: in function
 'move_nodes_vect'
12:00:09: ERROR[main]:  E:\Programme\minetest\bin\..\mods\flyingships/functions.lua:207: in function
 'move_by_motor'
12:00:09: ERROR[main]:  E:\Programme\minetest\bin\..\mods\flyingships/functions.lua:247: in function
 <E:\Programme\minetest\bin\..\mods\flyingships/functions.lua:241>
Newest Win32 builds - Find a mod - All my mods
ALL YOUR DONATION ARE BELONG TO PARAMAT (Please support him and Minetest)
New DuckDuckGo !bang: !mtmod <keyword here>
 

User avatar
neko259
Member
 
Posts: 769
Joined: Sun Jun 19, 2011 06:51

Re: [Mod] Flyingships

by neko259 » Sun Mar 22, 2015 11:05

Krock wrote:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
12:00:09: ACTION[ServerThread]: singleplayer uses flyingships:key, pointing at [node under=-429,21,-
213 above=-429,22,-213]
12:00:09: ERROR[main]: ServerError: E:\Programme\minetest\bin\..\mods\flyingships/functions.lua:140:
 bad argument #1 to 'ipairs' (table expected, got nil)
12:00:09: ERROR[main]: stack traceback:
12:00:09: ERROR[main]:  [C]: in function 'ipairs'
12:00:09: ERROR[main]:  E:\Programme\minetest\bin\..\mods\flyingships/functions.lua:140: in function
 'move_nodes_vect'
12:00:09: ERROR[main]:  E:\Programme\minetest\bin\..\mods\flyingships/functions.lua:207: in function
 'move_by_motor'
12:00:09: ERROR[main]:  E:\Programme\minetest\bin\..\mods\flyingships/functions.lua:247: in function
 <E:\Programme\minetest\bin\..\mods\flyingships/functions.lua:241>

I don't really understand why this happens, but added a condition. Try to update and check now.
 

User avatar
Krock
Member
 
Posts: 3598
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker

Re: [Mod] Flyingships

by Krock » Sun Mar 22, 2015 11:41

Okay, it works now but it ould be better to use VManip instead of removing/placing each node on another place.

EDIT: After punching a mesecons button, connected to the motor:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
12:48:22: WARNING: Undeclared global variable "move_by_motor" accessed at E:\Programme\minetest\bin\
..\mods\flyingships/functions.lua:194
12:48:22: ERROR[main]: ServerError: E:\Programme\minetest\bin\..\mods\flyingships/functions.lua:194:
 attempt to call global 'move_by_motor' (a nil value)
12:48:22: ERROR[main]: stack traceback:
12:48:22: ERROR[main]:  E:\Programme\minetest\bin\..\mods\flyingships/functions.lua:194: in function
 'action_on'
12:48:22: ERROR[main]:  ...amme\minetest\bin\..\mods\mesecons\mesecons/internal.lua:189: in function
 <...amme\minetest\bin\..\mods\mesecons\mesecons/internal.lua:184>
12:48:22: ERROR[main]:  ...e\minetest\bin\..\mods\mesecons\mesecons/actionqueue.lua:90: in function
'execute'
12:48:22: ERROR[main]:  ...e\minetest\bin\..\mods\mesecons\mesecons/actionqueue.lua:84: in function
<...e\minetest\bin\..\mods\mesecons\mesecons/actionqueue.lua:61>
12:48:22: ERROR[main]:  E:\Programme\minetest\bin\..\builtin\game\register.lua:341: in function <E:\
Programme\minetest\bin\..\builtin\game\register.lua:329>

EDIT2: Fixed after moving the function move_by_motor() above frame_motor_on()
EDIT3:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
13:01:23: ERROR[main]: ServerError: E:\Programme\minetest\bin\..\mods\flyingships/functions.lua:98:
attempt to call field 'is_mvps_unmov' (a nil value)
13:01:23: ERROR[main]: stack traceback:
13:01:23: ERROR[main]:  E:\Programme\minetest\bin\..\mods\flyingships/functions.lua:98: in function
'move_nodes_vect'
13:01:23: ERROR[main]:  E:\Programme\minetest\bin\..\mods\flyingships/functions.lua:201: in function
 'move_by_motor'
13:01:23: ERROR[main]:  E:\Programme\minetest\bin\..\mods\flyingships/functions.lua:249: in function
 <E:\Programme\minetest\bin\..\mods\flyingships/functions.lua:243>
Last edited by Krock on Sun Mar 22, 2015 12:04, edited 4 times in total.
Newest Win32 builds - Find a mod - All my mods
ALL YOUR DONATION ARE BELONG TO PARAMAT (Please support him and Minetest)
New DuckDuckGo !bang: !mtmod <keyword here>
 

User avatar
neko259
Member
 
Posts: 769
Joined: Sun Jun 19, 2011 06:51

Re: [Mod] Flyingships

by neko259 » Sun Mar 22, 2015 11:46

Krock wrote:Okay, it works now but it ould be better to use VManip instead of removing/placing each node on another place.

I could not understand the wiki page about voxel manipulation, and don't see any other tutorial. If anyone can work with it, pull requests are welcome. There is not so many code :)
 

User avatar
neko259
Member
 
Posts: 769
Joined: Sun Jun 19, 2011 06:51

Re: [Mod] Flyingships

by neko259 » Sun Mar 22, 2015 16:41

Added voxel manip. Now I'll test it on a live server and then commit and push to the repo.
 

User avatar
neko259
Member
 
Posts: 769
Joined: Sun Jun 19, 2011 06:51

Re: [Mod] Flyingships

by neko259 » Sun Mar 22, 2015 16:51

neko259 wrote:Added voxel manip. Now I'll test it on a live server and then commit and push to the repo.

Nope, it does not work. Lighting breaks, node facedirs break too.
 

Hybrid Dog
Member
 
Posts: 2460
Joined: Thu Nov 01, 2012 12:46

Re: [Mod] Flyingships

by Hybrid Dog » Wed Mar 25, 2015 14:09

some time ago l tried to make moving flying ships possible, too
http://paste.ubuntu.com/10678054/
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local load_time_start = os.clock()

-- the function to get the hull
local function get_tab(pos, func, max)
   local tab = {pos}
   local tab_avoid = {[pos.x.." "..pos.y.." "..pos.z] = true}
   local tab_done,num = {pos},2
   while tab[1] do
      for n,p in pairs(tab) do
         --[[
         for i = -1,1,2 do
            for _,p2 in pairs({
               {x=p.x+i, y=p.y, z=p.z},
               {x=p.x, y=p.y+i, z=p.z},
               {x=p.x, y=p.y, z=p.z+i},
            }) do]]
         for i = -1,1 do
            for j = -1,1 do
               for k = -1,1 do
                  local p2 = {x=p.x+i, y=p.y+j, z=p.z+k}
                  local pstr = p2.x.." "..p2.y.." "..p2.z
                  if not tab_avoid[pstr]
                  and func(p2) then
                     tab_avoid[pstr] = true
                     tab_done[num] = p2
                     num = num+1
                     table.insert(tab, p2)
                     if max
                     and num > max then
                        return false
                     end
                  end
               end
            end
         end
         tab[n] = nil
      end
   end
   return tab_done
end

-- everything not air belongs to the hull
local function is_solid(pos)
   return minetest.get_node(pos).name ~= "air"
end

-- gets the ship with e.g. floating stuff inside
local function get_ship(pos)
   local hull = get_tab(pos, is_solid, 3000)
   if not hull then
      return
   end
   local min = vector.new(pos)
   local max = vector.new(pos)
   local ps = {}
   for _,pos in pairs(hull) do
      local pstr = pos.x.." "..pos.z
      local mm = ps[pstr]
      if not mm then
         ps[pstr] = {pos.y, pos.y}
      else
         ps[pstr][1] = math.min(mm[1], pos.y)
         ps[pstr][2] = math.max(mm[2], pos.y)
      end
      for _,i in pairs({"x", "y", "z"}) do
         min[i] = math.min(min[i], pos[i])
         max[i] = math.max(max[i], pos[i])
      end
   end
   return ps, min, max
end

local log = minetest.chat_send_all   --minetest.log

-- moves it
local c_air = minetest.get_content_id("air")
local function move_ship(dif, ps, min, max)
   local manip = minetest.get_voxel_manip()
   local emerged_pos1, emerged_pos2 = manip:read_from_map(min, max)
   local area = VoxelArea:new({MinEdge=emerged_pos1, MaxEdge=emerged_pos2})
   local nodes = manip:get_data()
   local param2s = manip:get_param2_data()

   local nmin = vector.add(min, dif)
   local nmax = vector.add(max, dif)

   local manip2 = minetest.get_voxel_manip()
   local emerged_pos1, emerged_pos2 = manip2:read_from_map(nmin, nmax)
   local area2 = VoxelArea:new({MinEdge=emerged_pos1, MaxEdge=emerged_pos2})
   local nodes2 = manip2:get_data()
   local param2s2 = manip:get_param2_data()

   for xz,y in pairs(ps) do
      local x,z = unpack(string.split(xz, " "))
      for y = y[1], y[2] do
         local index = area:index(x,y,z)
         local index2 = area2:index(x+dif.x,y+dif.y,z+dif.z)
         if nodes2[index2] ~= c_air then
            log("[as_transport] error: "..minetest.get_name_from_content_id(nodes2[index2]).." was blocking.")
            return
         end
         nodes2[index2] = nodes[index]
         param2s2[index2] = param2s[index]
         nodes[index] = c_air
      end
   end

   manip:set_data(nodes)
   manip:write_to_map()
   manip:update_map()

   manip2:set_data(nodes2)
   manip:set_param2_data(param2s2)
   manip2:write_to_map()
   manip2:update_map()
   return true
end

-- moves a ship
local function transport_ship(pos, dif)
   local ps, min, max = get_ship(pos)
   if not ps then
      log("[as_transport] error: hull couldn't become detected, maybe the as is too big or connected to sth")
      return
   end
   local worked = move_ship(dif, ps, min, max)
   if not worked then
      log("[as_transport] error: as couldn't become teleported, maybe you tried to move it into not air nodes")
      return
   end
   log("[as_transport] as succesfully teleported")
   return true
end

minetest.register_node("as_transport:teleport", {
   description = "asirs telwer",
   tiles = {"as_transport.png"},
   groups = {snappy=2},
   on_place = function(_, puncher, pos)
      local t1 = os.clock()
      if not pos
      or not puncher then
         return
      end
      local pos = pos.under
      transport_ship(pos, {x=0, y=20, z=0})
      log(string.format("[as_transport] ended after ca. %.2fs", os.clock() - t1))
   end
})

minetest.log("info", string.format("[as_transport] loaded after ca. %.2fs", os.clock() - load_time_start))
 

User avatar
neko259
Member
 
Posts: 769
Joined: Sun Jun 19, 2011 06:51

Re: [Mod] Flyingships

by neko259 » Wed Mar 25, 2015 21:21

Done&pushed VoxelManip. Can't say they are faster because I have a constant 3-10 second lag on the server (not sure why though, minetest was always super-slow for me since 0.4 was introduced).
 

amadin
Member
 
Posts: 471
Joined: Tue Jun 16, 2015 16:23
GitHub: Amadin

Re: [Mod] Flyingships

by amadin » Sat Jan 02, 2016 10:52

I think the good way if player will stay in flying ship and will control it moving.
 

User avatar
DS-minetest
Member
 
Posts: 707
Joined: Thu Jun 19, 2014 19:49
GitHub: DS-Minetest
In-game: DS

Re: [Mod] Flyingships

by DS-minetest » Sun Jan 03, 2016 12:31

I like the mod.
it works very well with u-boats:
Image

but its annoying when you drive with a door, which makes sound on using
Do not call me -minetest.
Call me DS or DS-minetest.
I am German, so you don't have to pm me English if you are also German.
The background is a lie.
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 4 guests

cron