techage.is_ocean(pos) for waterpump added

This commit is contained in:
Joachim Stolberg 2020-02-13 22:44:58 +01:00
parent d4bd5118b0
commit 7790101254
4 changed files with 143 additions and 20 deletions

View File

@ -173,6 +173,16 @@ end
determine_ocean_ids() determine_ocean_ids()
-- check if natural water is on given position (water placed by player has param2 = 1)
function techage.is_ocean(pos)
if pos.y ~= 1 then return false end
local node = techage.get_node_lvm(pos)
if node.name ~= "default:water_source" then return false end
if node.param2 == 1 then return false end
return true
end
local function tooltip(name) local function tooltip(name)
name = string.split(name, " ")[1] name = string.split(name, " ")[1]

View File

@ -9,6 +9,7 @@
See LICENSE.txt for more information See LICENSE.txt for more information
Meltingpot recipes Meltingpot recipes
Bucket redefinitions
]]-- ]]--
@ -37,6 +38,101 @@ minetest.register_craftitem("techage:iron_ingot", {
use_texture_alpha = true, use_texture_alpha = true,
}) })
local function check_protection(pos, name, text)
if minetest.is_protected(pos, name) then
minetest.log("action", (name ~= "" and name or "A mod")
.. " tried to " .. text
.. " at protected position "
.. minetest.pos_to_string(pos)
.. " with a bucket")
minetest.record_protection_violation(pos, name)
return true
end
return false
end
-- derived from bucket/init.lua
local function register_liquid(source, flowing, itemname, inventory_image, name,
groups, force_renew)
bucket.liquids[source] = {
source = source,
flowing = flowing,
itemname = itemname,
force_renew = force_renew,
}
bucket.liquids[flowing] = bucket.liquids[source]
if itemname ~= nil then
minetest.unregister_item(itemname)
minetest.register_craftitem(":"..itemname, {
description = name,
inventory_image = inventory_image,
stack_max = 1,
liquids_pointable = true,
groups = groups,
on_place = function(itemstack, user, pointed_thing)
-- Must be pointing to node
if pointed_thing.type ~= "node" then
return
end
local node = minetest.get_node_or_nil(pointed_thing.under)
local ndef = node and minetest.registered_nodes[node.name]
-- Call on_rightclick if the pointed node defines it
if ndef and ndef.on_rightclick and
not (user and user:is_player() and
user:get_player_control().sneak) then
return ndef.on_rightclick(
pointed_thing.under,
node, user,
itemstack)
end
local lpos
-- Check if pointing to a buildable node
if ndef and ndef.buildable_to then
-- buildable; replace the node
lpos = pointed_thing.under
else
-- not buildable to; place the liquid above
-- check if the node above can be replaced
lpos = pointed_thing.above
node = minetest.get_node_or_nil(lpos)
local above_ndef = node and minetest.registered_nodes[node.name]
if not above_ndef or not above_ndef.buildable_to then
-- do not remove the bucket with the liquid
return itemstack
end
end
if check_protection(lpos, user
and user:get_player_name()
or "", "place "..source) then
return
end
-------------------------------- Start Modification
-- minetest.set_node(lpos, {name = source})
if source == "default:lava_source" and lpos.y > 0 then
minetest.chat_send_player(user:get_player_name(), S("[Bucket] Lava can only be placed below sea level!"))
return
else
-- see "basis/lib.lua" techage.is_ocean(pos)
minetest.set_node(lpos, {name = source, param2 = 1})
end
-------------------------------- End Modification
return ItemStack("bucket:bucket_empty")
end
})
end
end
-- --
-- Changed default recipes -- Changed default recipes
@ -82,6 +178,14 @@ if techage.modified_recipes_enabled then
} }
}) })
minetest.register_craft({
output = 'bucket:bucket_empty 2',
recipe = {
{'techage:iron_ingot', '', 'techage:iron_ingot'},
{'', 'techage:iron_ingot', ''},
}
})
minetest.override_item("fire:flint_and_steel", { minetest.override_item("fire:flint_and_steel", {
description = S("Flint and Iron"), description = S("Flint and Iron"),
inventory_image = "fire_flint_steel.png^[colorize:#c7643d:60", inventory_image = "fire_flint_steel.png^[colorize:#c7643d:60",
@ -90,22 +194,25 @@ if techage.modified_recipes_enabled then
minetest.override_item("bucket:bucket_empty", { minetest.override_item("bucket:bucket_empty", {
inventory_image = "bucket.png^[colorize:#c7643d:40" inventory_image = "bucket.png^[colorize:#c7643d:40"
}) })
minetest.override_item("bucket:bucket_lava", {
inventory_image = "bucket_lava.png^[colorize:#c7643d:30"
})
minetest.override_item("bucket:bucket_river_water", { minetest.override_item("bucket:bucket_river_water", {
inventory_image = "bucket_river_water.png^[colorize:#c7643d:30" inventory_image = "bucket_river_water.png^[colorize:#c7643d:30"
}) })
minetest.override_item("bucket:bucket_water", {
inventory_image = "bucket_water.png^[colorize:#c7643d:30"
})
minetest.register_craft({ register_liquid(
output = 'bucket:bucket_empty 2', "default:water_source",
recipe = { "default:water_flowing",
{'techage:iron_ingot', '', 'techage:iron_ingot'}, "bucket:bucket_water",
{'', 'techage:iron_ingot', ''}, "bucket_water.png^[colorize:#c7643d:30",
} "Water Bucket",
}) {water_bucket = 1}
)
register_liquid(
"default:lava_source",
"default:lava_flowing",
"bucket:bucket_lava",
"bucket_lava.png^[colorize:#c7643d:30",
"Lava Bucket"
)
end end

View File

@ -20,6 +20,7 @@ local Cable = techage.ElectricCable
local power = techage.power local power = techage.power
local Pipe = techage.LiquidPipe local Pipe = techage.LiquidPipe
local liquid = techage.liquid local liquid = techage.liquid
local networks = techage.networks
local CYCLE_TIME = 4 local CYCLE_TIME = 4
local STANDBY_TICKS = 3 local STANDBY_TICKS = 3
@ -38,7 +39,15 @@ local function formspec(self, pos, nvm)
end end
local function can_start(pos, nvm, state) local function can_start(pos, nvm, state)
return power.power_available(pos, Cable) local outdir = M(pos):get_int("waterdir")
local pos1 = vector.add(pos, tubelib2.Dir6dToVector[outdir or 0])
if not techage.is_ocean(pos1) then
return S("no usable water")
end
if not power.power_available(pos, Cable) then
return S("no power")
end
return true
end end
local function start_node(pos, nvm, state) local function start_node(pos, nvm, state)
@ -56,6 +65,7 @@ local State = techage.NodeStates:new({
cycle_time = CYCLE_TIME, cycle_time = CYCLE_TIME,
standby_ticks = STANDBY_TICKS, standby_ticks = STANDBY_TICKS,
formspec_func = formspec, formspec_func = formspec,
can_start = can_start,
start_node = start_node, start_node = start_node,
stop_node = stop_node, stop_node = stop_node,
}) })
@ -72,14 +82,10 @@ local function on_nopower(pos)
nvm.running = false nvm.running = false
end end
local function water_available(pos, nvm)
return true
end
local function pumping(pos, nvm) local function pumping(pos, nvm)
if not nvm.running then if not nvm.running then
State:nopower(pos, nvm) State:nopower(pos, nvm)
elseif water_available(pos, nvm) then else
local leftover = liquid.put(pos, 6, "default:water_source", 1) local leftover = liquid.put(pos, 6, "default:water_source", 1)
if leftover and leftover > 0 then if leftover and leftover > 0 then
State:blocked(pos, nvm) State:blocked(pos, nvm)
@ -112,6 +118,7 @@ local function after_place_node(pos)
nvm.running = false nvm.running = false
local number = techage.add_node(pos, "techage:t4_waterpump") local number = techage.add_node(pos, "techage:t4_waterpump")
State:node_init(pos, nvm, number) State:node_init(pos, nvm, number)
M(pos):set_int("waterdir", networks.side_to_outdir(pos, "R"))
Pipe:after_place_node(pos) Pipe:after_place_node(pos)
Cable:after_place_node(pos) Cable:after_place_node(pos)
end end

View File

@ -116,4 +116,3 @@ minetest.register_craft({
{"", "", "default:stick"}, {"", "", "default:stick"},
}, },
}) })