Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use hidden node to stop placement of blocks in top half of travelnet #2

Merged
merged 8 commits into from
Feb 19, 2021
2 changes: 2 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ travelnet.doors_enabled = true;
-- starts an abm which re-adds travelnet stations to networks in case the savefile got lost
travelnet.abm_enabled = false;

travelnet.block_existing_travelnets = minetest.settings:get_bool("travelnet.block_existing_travelnets", false)

-- change these if you want other receipes for travelnet or elevator
travelnet.travelnet_recipe = {
{"default:glass", "default:steel_ingot", "default:glass", },
Expand Down
1 change: 1 addition & 0 deletions depends.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
mesecons?
mesecons_mvps?
intllib?
12 changes: 8 additions & 4 deletions elevator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ minetest.register_node("travelnet:elevator", {
-- "field[0.3,7.6;6,0.7;owner_name;(optional) owned by:;]"..
"button_exit[6.3,6.2;1.7,0.7;station_set;"..S("Store").."]" );

local p = {x=pos.x, y=pos.y+1, z=pos.z}
local top_pos = vector.add({x=0,y=1,z=0}, pos)
minetest.set_node(top_pos, {name="travelnet:hidden_top"})
local p2 = minetest.dir_to_facedir(placer:get_look_dir())
minetest.add_node(p, {name="travelnet:elevator_top", paramtype2="facedir", param2=p2})
travelnet.show_nearest_elevator( pos, placer:get_player_name(), p2 );
end,

Expand All @@ -162,9 +162,9 @@ minetest.register_node("travelnet:elevator", {
on_place = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.above;
local node = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z});
local def = minetest.registered_nodes[node.name]
-- leftover elevator_top nodes can be removed by placing a new elevator underneath
if not def or not def.buildable_to then
local def = minetest.registered_nodes[node.name]
if (not def or not def.buildable_to) and node.name ~= "travelnet:hidden_top" then
minetest.chat_send_player( placer:get_player_name(), S('Not enough vertical space to place the travelnet box!'))
return;
end
Expand Down Expand Up @@ -195,3 +195,7 @@ minetest.register_alias("travelnet:elevator_top", "air")
})
--end

if minetest.global_exists("mesecon") and mesecon.register_mvps_stopper then
mesecon.register_mvps_stopper("travelnet:elevator")
end

49 changes: 46 additions & 3 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ travelnet = {};
travelnet.targets = {};
travelnet.path = minetest.get_modpath(minetest.get_current_modname())

local hidden_block = "travelnet:hidden_top"

-- Intllib
local S = dofile(travelnet.path .. "/intllib.lua")
Expand Down Expand Up @@ -669,6 +670,14 @@ travelnet.on_receive_fields = function(pos, formname, fields, player)
if( not( pos )) then
return;
end

if travelnet.block_existing_travelnets then
local top_pos = vector.add({x=0,y=1,z=0}, pos)
if minetest.get_node(top_pos).name ~= hidden_block then
minetest.set_node(top_pos, {name=hidden_block})
end
end

local meta = minetest.get_meta(pos);

local name = player:get_player_name();
Expand Down Expand Up @@ -860,7 +869,14 @@ travelnet.on_receive_fields = function(pos, formname, fields, player)
local target_pos = travelnet.targets[ owner_name ][ station_network ][ fields.target ].pos;
player:move_to( target_pos, false);

if( travelnet.travelnet_effect_enabled ) then
if travelnet.block_existing_travelnets then
local top_pos = vector.add({x=0,y=1,z=0}, target_pos)
if minetest.get_node(top_pos).name ~= hidden_block then
minetest.set_node(top_pos, {name=hidden_block})
end
end

if( travelnet.travelnet_effect_enabled ) then
minetest.add_entity( {x=target_pos.x,y=target_pos.y+0.5,z=target_pos.z}, "travelnet:effect"); -- it self-destructs after 20 turns
end

Expand Down Expand Up @@ -927,6 +943,8 @@ end

travelnet.remove_box = function( pos, oldnode, oldmetadata, digger )

minetest.remove_node(vector.add({x=0,y=1,z=0}, pos))

if( not( oldmetadata ) or oldmetadata=="nil" or not(oldmetadata.fields)) then
minetest.chat_send_player( digger:get_player_name(), S("Error")..": "..
S("Could not find information about the station that is to be removed."));
Expand Down Expand Up @@ -1005,8 +1023,33 @@ travelnet.can_dig_old = function( pos, player, description )
end
return true;
end


local hidden_def = {
drawtype = "airlike",
paramtype = "light",
sunlight_propagates = true,
walkable = true,
pointable = false,
diggable = false,
builbable_to = false,
floodable = false,
drop="",
groups = {not_in_creative_inventory = 1},
on_blast = function () end,
collision_box = {
type = "fixed",
fixed = { 0,0,0,0,0,0 },
},
}
-- Make hidden node visible for debugging
-- hidden_def.selection_box = {type="fixed",fixed={-0.3,-0.3,-0.3,0.3,0.3,0.3}}
-- hidden_def.pointable = true
-- hidden_def.drawtype = "glasslike"

minetest.register_node(hidden_block, hidden_def)

if minetest.global_exists("mesecon") and mesecon.register_mvps_stopper then
mesecon.register_mvps_stopper(hidden_block)
end



Expand Down
15 changes: 10 additions & 5 deletions travelnet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ minetest.register_node("travelnet:travelnet", {
light_source = 10,

after_place_node = function(pos, placer, itemstack)
local meta = minetest.get_meta(pos);
travelnet.reset_formspec( meta );
meta:set_string("owner", placer:get_player_name() );
local meta = minetest.get_meta(pos);
travelnet.reset_formspec( meta );
meta:set_string("owner", placer:get_player_name() );
local top_pos = vector.add({x=0,y=1,z=0}, pos)
minetest.set_node(top_pos, {name="travelnet:hidden_top"})
end,

on_receive_fields = travelnet.on_receive_fields,
Expand All @@ -76,8 +78,7 @@ minetest.register_node("travelnet:travelnet", {
local pos = pointed_thing.above;
local node = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z})
local def = minetest.registered_nodes[node.name]
if not def or not def.buildable_to then

if (not def or not def.buildable_to) and node.name ~= "travelnet:hidden_top" then
minetest.chat_send_player( placer:get_player_name(), S('Not enough vertical space to place the travelnet box!'))
return;
end
Expand All @@ -91,3 +92,7 @@ minetest.register_craft({
output = "travelnet:travelnet",
recipe = travelnet.travelnet_recipe,
})

if minetest.global_exists("mesecon") and mesecon.register_mvps_stopper then
mesecon.register_mvps_stopper("travelnet:travelnet")
end