Skip to content

Commit

Permalink
Merge branch 'master' into bed-compat-ng
Browse files Browse the repository at this point in the history
  • Loading branch information
SwissalpS authored Dec 22, 2024
2 parents 3a53876 + 9b36a7a commit 59ceb74
Show file tree
Hide file tree
Showing 51 changed files with 719 additions and 8,578 deletions.
14 changes: 0 additions & 14 deletions .github/workflows/integration-test.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/luacheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@master
- name: apt
run: sudo apt-get install -y luarocks
- name: luacheck install
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: test

on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: buckaroobanzay/mtt@main
with:
modname: jumpdrive
git_dependencies: |
https://github.com/minetest-mods/areas.git
10 changes: 5 additions & 5 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
unused_args = false
allow_defined_top = true

ignore = {"512"}

globals = {
"jumpdrive",
Expand Down Expand Up @@ -35,5 +31,9 @@ read_globals = {
"ropes",
"sethome",
"drawers",
"player_monoids"
"player_monoids",
"vizlib",
"mcl_sounds",
"mcl_formspec",
"mtt"
}
7 changes: 5 additions & 2 deletions backbone.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ minetest.register_node("jumpdrive:backbone", {
description = "Jumpdrive Backbone",

tiles = {"jumpdrive_backbone.png"},
groups = {cracky=3,oddly_breakable_by_hand=3},
sounds = default.node_sound_glass_defaults(),
groups = {cracky=3,oddly_breakable_by_hand=3,handy=1,pickaxey=1},
_mcl_blast_resistance = 2,
_mcl_hardness = 0.9,
sounds = jumpdrive.sounds.node_sound_glass_defaults(),
is_ground_content = false,
light_source = 13
})
19 changes: 15 additions & 4 deletions bookmark.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@

local book_item, book_written = ""

if minetest.get_modpath("default") then
book_item = "default:book"
book_written = "default:book_written"
end

if minetest.get_modpath("mcl_books") then
book_item = "mcl_books:book"
book_written = "mcl_books:written_book"
end

jumpdrive.write_to_book = function(pos, sender)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()

if inv:contains_item("main", {name="default:book", count=1}) then
local stack = inv:remove_item("main", {name="default:book", count=1})
if inv:contains_item("main", {name=book_item, count=1}) then
local stack = inv:remove_item("main", {name=book_item, count=1})

local new_stack = ItemStack("default:book_written")
local new_stack = ItemStack(book_written)

local data = {}

Expand Down Expand Up @@ -63,7 +74,7 @@ jumpdrive.read_from_book = function(pos)
for i = inv_size, 1, -1 do
stack = inv:get_stack("main", i)
stack_name = stack:get_name()
if "default:book_written" == stack_name then
if book_written == stack_name then
-- remove item from inventory
inv:set_stack("main", i, ItemStack())
stack_meta = stack:get_meta()
Expand Down
46 changes: 39 additions & 7 deletions common.lua
Original file line number Diff line number Diff line change
@@ -1,40 +1,72 @@

jumpdrive.sanitize_coord = function(coord)
local c_air = minetest.get_content_id("air")

function jumpdrive.clear_area(pos1, pos2)
local manip = minetest.get_voxel_manip()
local e1, e2 = manip:read_from_map(pos1, pos2)
local source_area = VoxelArea:new({MinEdge=e1, MaxEdge=e2})
local source_data = manip:get_data()


for z=pos1.z, pos2.z do
for y=pos1.y, pos2.y do
for x=pos1.x, pos2.x do

local source_index = source_area:index(x, y, z)
source_data[source_index] = c_air
end
end
end

manip:set_data(source_data)
manip:write_to_map()

-- remove metadata
local target_meta_pos_list = minetest.find_nodes_with_meta(pos1, pos2)
for _,target_pos in pairs(target_meta_pos_list) do
local target_meta = minetest.get_meta(target_pos)
target_meta:from_table(nil)
end
end

function jumpdrive.sanitize_coord(coord)
return math.max( math.min( coord, 31000 ), -31000 )
end

-- get pos object from pos
jumpdrive.get_meta_pos = function(pos)
function jumpdrive.get_meta_pos(pos)
local meta = minetest.get_meta(pos);
return {x=meta:get_int("x"), y=meta:get_int("y"), z=meta:get_int("z")}
end

-- set pos object from pos
jumpdrive.set_meta_pos = function(pos, target)
function jumpdrive.set_meta_pos(pos, target)
local meta = minetest.get_meta(pos);
meta:set_int("x", target.x)
meta:set_int("y", target.y)
meta:set_int("z", target.z)
end

-- get offset from meta
jumpdrive.get_radius = function(pos)
function jumpdrive.get_radius(pos)
local meta = minetest.get_meta(pos);
return math.max(math.min(meta:get_int("radius"), jumpdrive.config.max_radius), 1)
end

-- calculates the power requirements for a jump
jumpdrive.calculate_power = function(radius, distance, sourcePos, targetPos)
-- params: radius, distance, sourcePos, targetPos
function jumpdrive.calculate_power(radius, distance)
return 10 * distance * radius
end


-- preflight check, for overriding
jumpdrive.preflight_check = function(source, destination, radius, playername)
-- params: source, destination, radius, playername
function jumpdrive.preflight_check()
return { success=true }
end

jumpdrive.reset_coordinates = function(pos)
function jumpdrive.reset_coordinates(pos)
local meta = minetest.get_meta(pos)

meta:set_int("x", pos.x)
Expand Down
5 changes: 2 additions & 3 deletions compat/compat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ end

if has_technic_mod then
dofile(MP.."/compat/anchor.lua")
dofile(MP.."/compat/technic_networks.lua")
end

if has_locator_mod then
Expand Down Expand Up @@ -75,7 +76,5 @@ jumpdrive.node_compat = function(name, source_pos, target_pos, source_pos1, sour
end

jumpdrive.commit_node_compat = function()
if has_pipeworks_mod then
jumpdrive.teleporttube_compat_commit()
end
-- Nothing to do here
end
2 changes: 1 addition & 1 deletion compat/elevator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
local nodedef = minetest.registered_nodes["elevator:motor"]

minetest.override_item("elevator:motor", {
on_movenode = function(from_pos, to_pos)
on_movenode = function(_, to_pos)
minetest.log("action", "[jumpdrive] Restoring elevator @ " .. to_pos.x .. "/" .. to_pos.y .. "/" .. to_pos.z)
nodedef.after_place_node(to_pos, nil, nil)
end
Expand Down
57 changes: 57 additions & 0 deletions compat/technic_networks.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
--
-- Compatibility hacks for technic plus new network system
--
-- More information:
-- https://github.com/mt-mods/technic/issues/100
--
-- See also proposal draft to actually move networks instead of rebuilding:
-- https://github.com/mt-mods/jumpdrive/pull/79
--

-- Check for technic mod version compatibility
if technic.remove_network and technic.pos2network and technic.machines then

local function on_movenode(from_pos, to_pos, info)
-- Destroy network caches at source location, inside jump area
local src_net_id = technic.pos2network(from_pos)
if src_net_id then
technic.remove_network(src_net_id)
end

-- Destroy network caches at target location, outside jump area
local edge = info.edge
for axis, value in pairs(edge) do
if value ~= 0 then
local axis_dir = {x=0,y=0,z=0}
axis_dir[axis] = value
local edge_pos = vector.add(to_pos, axis_dir)
local dst_net_id = technic.pos2network(edge_pos)
if dst_net_id then
technic.remove_network(dst_net_id)
end
end
end
end

-- Collect groups for registered technic cables
local cable_groups = {}
for tier,_ in pairs(technic.machines) do
cable_groups[("technic_%s_cable"):format(tier:lower())] = 1
end

local function is_network_node(_, def)
if not def.groups then return end
for group,_ in pairs(cable_groups) do
if def.groups[group] then return true end
end
return def.groups["technic_machine"]
end

-- Inject on_movenode functionality but only if node does not already implement it
for name, def in pairs(minetest.registered_nodes) do
if not def.on_movenode and is_network_node(name, def) then
minetest.override_item(name, { on_movenode = on_movenode })
end
end

end
26 changes: 11 additions & 15 deletions compat/teleporttube.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ if not pipeworks.tptube then
minetest.log("warning", "[jumpdrive] pipeworks teleport patch not applied, tp-tubes don't work as expected!")
end

local is_compatible = pipeworks.tptube and pipeworks.tptube.remove_tube
if not is_compatible then
minetest.log("warning", "[jumpdrive] tp-tube api not comptible, consider upgrading the pipeworks mod")
end

-- https://gitlab.com/VanessaE/pipeworks/blob/master/teleport_tube.lua
jumpdrive.teleporttube_compat = function(from, to)
if not pipeworks.tptube then
-- only works with the patch from "./patches/pipeworks.patch"
function jumpdrive.teleporttube_compat(from, to)
if not is_compatible then
return
end

Expand All @@ -32,16 +34,10 @@ jumpdrive.teleporttube_compat = function(from, to)
data.y = to.y
data.z = to.z

db[from_hash] = nil
db[to_hash] = data

end

jumpdrive.teleporttube_compat_commit = function()
if not pipeworks.tptube then
-- only works with the patch from "./patches/pipeworks.patch"
return
end
-- remove source-entry
pipeworks.tptube.remove_tube(from)

pipeworks.tptube.save_tube_db()
-- set target entry
db[to_hash] = data
pipeworks.tptube.save_tube(to_hash)
end
12 changes: 8 additions & 4 deletions compat/textline.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@

local textline_def = minetest.registered_nodes["textline:lcd"]
assert(textline_def)
assert(textline_def.after_place_node)

-- refresh textline entities after the jump
minetest.override_item("textline:lcd", {
on_movenode = function(from_pos, to_pos)
minetest.after(1, function()
textline_def.after_place_node(to_pos)
end)
local delta_vector = vector.subtract(to_pos, from_pos)
local objects = minetest.get_objects_inside_radius(from_pos, 0.5)
for _,object in ipairs(objects) do
local entity = object:get_luaentity()
if entity and entity.name == "textline:text" then
object:set_pos(vector.add(object:get_pos(), delta_vector))
end
end
end
})
34 changes: 22 additions & 12 deletions compat/travelnet.lua
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@

minetest.override_item("travelnet:travelnet", {
on_movenode = function(from_pos, to_pos)
local meta = minetest.get_meta(to_pos);
minetest.log("action", "[jumpdrive] Restoring travelnet @ " .. to_pos.x .. "/" .. to_pos.y .. "/" .. to_pos.z)
assert(type(travelnet.get_travelnets) == "function", "old travelnet-api found, please update the travelnet mod")

local owner_name = meta:get_string( "owner" );
local station_name = meta:get_string( "station_name" );
local station_network = meta:get_string( "station_network" );
minetest.register_on_mods_loaded(function()
for node, def in pairs(minetest.registered_nodes) do
if def.groups and def.groups.travelnet == 1 then
minetest.override_item(node, {
on_movenode = function(_, to_pos)
local meta = minetest.get_meta(to_pos);
minetest.log("action", "[jumpdrive] Restoring travelnet @ " .. to_pos.x .. "/" .. to_pos.y .. "/" .. to_pos.z)

if (travelnet.targets[owner_name]
and travelnet.targets[owner_name][station_network]
and travelnet.targets[owner_name][station_network][station_name]) then
travelnet.targets[owner_name][station_network][station_name].pos = to_pos
local owner_name = meta:get_string( "owner" );
local station_name = meta:get_string( "station_name" );
local station_network = meta:get_string( "station_network" );

local stations = travelnet.get_travelnets(owner_name)
if (stations[station_network]
and stations[station_network][station_name]) then
-- update station with new position
stations[station_network][station_name].pos = to_pos
travelnet.set_travelnets(owner_name, stations)
end
end
})
end
end
})
end)

jumpdrive.register_after_jump(function()
if travelnet.save_data ~= nil then
Expand Down
Loading

0 comments on commit 59ceb74

Please sign in to comment.