mirror of
https://github.com/minetest-mods/digtron.git
synced 2025-03-23 13:32:28 +01:00
making digtron nodes diggable by hand. Also extracting controller code in prep for an autonomous controller
This commit is contained in:
@ -3,7 +3,7 @@
|
|||||||
-- Builds objects in the targeted node. This is a complicated beastie.
|
-- Builds objects in the targeted node. This is a complicated beastie.
|
||||||
minetest.register_node("digtron:builder", {
|
minetest.register_node("digtron:builder", {
|
||||||
description = "Builder Unit",
|
description = "Builder Unit",
|
||||||
groups = {cracky = 3, stone = 1, digtron = 4},
|
groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 4},
|
||||||
drop = "digtron:builder",
|
drop = "digtron:builder",
|
||||||
sounds = default.node_sound_metal_defaults(),
|
sounds = default.node_sound_metal_defaults(),
|
||||||
paramtype2= 'facedir',
|
paramtype2= 'facedir',
|
||||||
|
@ -1,66 +1,21 @@
|
|||||||
local controller_nodebox ={
|
digtron.execute_cycle = function(pos, node, clicker)
|
||||||
{-0.3125, -0.3125, -0.3125, 0.3125, 0.3125, 0.3125}, -- Core
|
|
||||||
{-0.1875, 0.3125, -0.1875, 0.1875, 0.5, 0.1875}, -- +y_connector
|
|
||||||
{-0.1875, -0.5, -0.1875, 0.1875, -0.3125, 0.1875}, -- -y_Connector
|
|
||||||
{0.3125, -0.1875, -0.1875, 0.5, 0.1875, 0.1875}, -- +x_connector
|
|
||||||
{-0.5, -0.1875, -0.1875, -0.3125, 0.1875, 0.1875}, -- -x_connector
|
|
||||||
{-0.1875, -0.1875, 0.3125, 0.1875, 0.1875, 0.5}, -- +z_connector
|
|
||||||
{-0.5, 0.125, -0.5, -0.125, 0.5, -0.3125}, -- back_connector_3
|
|
||||||
{0.125, 0.125, -0.5, 0.5, 0.5, -0.3125}, -- back_connector_1
|
|
||||||
{0.125, -0.5, -0.5, 0.5, -0.125, -0.3125}, -- back_connector_2
|
|
||||||
{-0.5, -0.5, -0.5, -0.125, -0.125, -0.3125}, -- back_connector_4
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Master controller. Most complicated part of the whole system. Determines which direction a digtron moves and triggers all of its component parts.
|
|
||||||
minetest.register_node("digtron:controller", {
|
|
||||||
description = "Digtron Control Unit",
|
|
||||||
groups = {cracky = 3, stone = 1, digtron = 1},
|
|
||||||
drop = 'digtron:controller',
|
|
||||||
sounds = default.node_sound_metal_defaults(),
|
|
||||||
paramtype2= 'facedir',
|
|
||||||
-- Aims in the +Z direction by default
|
|
||||||
tiles = {
|
|
||||||
"digtron_plate.png^[transformR90",
|
|
||||||
"digtron_plate.png^[transformR270",
|
|
||||||
"digtron_plate.png",
|
|
||||||
"digtron_plate.png^[transformR180",
|
|
||||||
"digtron_plate.png",
|
|
||||||
"digtron_control.png",
|
|
||||||
},
|
|
||||||
|
|
||||||
drawtype = "nodebox",
|
|
||||||
paramtype = "light",
|
|
||||||
node_box = {
|
|
||||||
type = "fixed",
|
|
||||||
fixed = controller_nodebox,
|
|
||||||
},
|
|
||||||
|
|
||||||
on_construct = function(pos)
|
|
||||||
local meta = minetest.env:get_meta(pos)
|
|
||||||
meta:set_float("fuel_burning", 0.0)
|
|
||||||
meta:set_string("infotext", "Heat remaining in controller furnace: 0")
|
|
||||||
end,
|
|
||||||
|
|
||||||
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
if meta:get_string("waiting") == "true" then
|
if meta:get_string("waiting") == "true" then
|
||||||
-- Been too soon since last time the digtron did a cycle.
|
-- Been too soon since last time the digtron did a cycle.
|
||||||
return
|
return pos, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local layout = digtron.get_all_digtron_neighbours(pos, clicker)
|
local layout = digtron.get_all_digtron_neighbours(pos, clicker)
|
||||||
if layout.all == nil then
|
if layout.all == nil then
|
||||||
-- get_all_digtron_neighbours returns nil if the digtron array touches unloaded nodes, too dangerous to do anything in that situation. Abort.
|
-- get_all_digtron_neighbours returns nil if the digtron array touches unloaded nodes, too dangerous to do anything in that situation. Abort.
|
||||||
minetest.sound_play("buzzer", {gain=0.5, pos=pos})
|
minetest.sound_play("buzzer", {gain=0.5, pos=pos})
|
||||||
meta:set_string("infotext", "Digtron is adjacent to unloaded nodes.")
|
return pos, "Digtron is adjacent to unloaded nodes."
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if layout.traction * digtron.traction_factor < table.getn(layout.all) then
|
if layout.traction * digtron.traction_factor < table.getn(layout.all) then
|
||||||
-- digtrons can't fly
|
-- digtrons can't fly
|
||||||
minetest.sound_play("squeal", {gain=1.0, pos=pos})
|
minetest.sound_play("squeal", {gain=1.0, pos=pos})
|
||||||
meta:set_string("infotext", string.format("Digtron has %d nodes but only enough traction to move %d nodes.", table.getn(layout.all), layout.traction * digtron.traction_factor))
|
return pos, string.format("Digtron has %d nodes but only enough traction to move %d nodes.", table.getn(layout.all), layout.traction * digtron.traction_factor)
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local facing = minetest.get_node(pos).param2
|
local facing = minetest.get_node(pos).param2
|
||||||
@ -114,8 +69,7 @@ minetest.register_node("digtron:controller", {
|
|||||||
)
|
)
|
||||||
minetest.sound_play("squeal", {gain=1.0, pos=pos})
|
minetest.sound_play("squeal", {gain=1.0, pos=pos})
|
||||||
minetest.sound_play("buzzer", {gain=0.5, pos=pos})
|
minetest.sound_play("buzzer", {gain=0.5, pos=pos})
|
||||||
meta:set_string("infotext", "Digtron is obstructed.")
|
return pos, "Digtron is obstructed." --Abort, don't dig and don't build.
|
||||||
return --Abort, don't dig and don't build.
|
|
||||||
end
|
end
|
||||||
|
|
||||||
----------------------------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------------------------
|
||||||
@ -163,8 +117,7 @@ minetest.register_node("digtron:controller", {
|
|||||||
|
|
||||||
if test_fuel_needed > fuel_burning + test_fuel_burned then
|
if test_fuel_needed > fuel_burning + test_fuel_burned then
|
||||||
minetest.sound_play("buzzer", {gain=0.5, pos=pos})
|
minetest.sound_play("buzzer", {gain=0.5, pos=pos})
|
||||||
meta:set_string("infotext", "Digtron needs more fuel")
|
return pos, "Digtron needs more fuel" -- abort, don't dig and don't build.
|
||||||
return -- abort, don't dig and don't build.
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if not can_build then
|
if not can_build then
|
||||||
@ -174,15 +127,16 @@ minetest.register_node("digtron:controller", {
|
|||||||
minetest.get_meta(pos):set_string("waiting", nil)
|
minetest.get_meta(pos):set_string("waiting", nil)
|
||||||
end, pos
|
end, pos
|
||||||
)
|
)
|
||||||
|
local return_string = nil
|
||||||
if test_build_return_code == 3 then
|
if test_build_return_code == 3 then
|
||||||
minetest.sound_play("honk", {gain=0.5, pos=pos}) -- A builder is not configured
|
minetest.sound_play("honk", {gain=0.5, pos=pos}) -- A builder is not configured
|
||||||
meta:set_string("infotext", "Digtron connected to at least one builder node that hasn't had an output material assigned.")
|
return_string = "Digtron connected to at least one builder node that hasn't had an output material assigned."
|
||||||
elseif test_build_return_code == 2 then
|
elseif test_build_return_code == 2 then
|
||||||
minetest.sound_play("dingding", {gain=1.0, pos=pos}) -- Insufficient inventory
|
minetest.sound_play("dingding", {gain=1.0, pos=pos}) -- Insufficient inventory
|
||||||
meta:set_string("infotext", string.format("Digtron has insufficient materials in inventory to execute all build operations.\nNeeded: %s",
|
return_string = string.format("Digtron has insufficient materials in inventory to execute all build operations.\nNeeded: %s",
|
||||||
test_build_return_item:get_name()))
|
test_build_return_item:get_name())
|
||||||
end
|
end
|
||||||
return --Abort, don't dig and don't build.
|
return pos, return_string --Abort, don't dig and don't build.
|
||||||
end
|
end
|
||||||
|
|
||||||
----------------------------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------------------------
|
||||||
@ -257,9 +211,7 @@ minetest.register_node("digtron:controller", {
|
|||||||
fuel_burning = fuel_burning + digtron.burn(layout.fuelstores, -fuel_burning, false)
|
fuel_burning = fuel_burning + digtron.burn(layout.fuelstores, -fuel_burning, false)
|
||||||
end
|
end
|
||||||
meta:set_float("fuel_burning", fuel_burning)
|
meta:set_float("fuel_burning", fuel_burning)
|
||||||
if not strange_failure then
|
status_text = status_text .. string.format("Heat remaining in controller furnace: %d", fuel_burning)
|
||||||
meta:set_string("infotext", status_text .. string.format("Heat remaining in controller furnace: %d", fuel_burning))
|
|
||||||
end
|
|
||||||
|
|
||||||
-- finally, dig out any nodes remaining to be dug. Some of these will have had their flag revoked because
|
-- finally, dig out any nodes remaining to be dug. Some of these will have had their flag revoked because
|
||||||
-- a builder put something there or because they're another digtron node.
|
-- a builder put something there or because they're another digtron node.
|
||||||
@ -273,6 +225,59 @@ minetest.register_node("digtron:controller", {
|
|||||||
minetest.check_for_falling({x=node_to_dig.x, y=node_to_dig.y+1, z=node_to_dig.z})
|
minetest.check_for_falling({x=node_to_dig.x, y=node_to_dig.y+1, z=node_to_dig.z})
|
||||||
node_to_dig, whether_to_dig = nodes_dug:pop()
|
node_to_dig, whether_to_dig = nodes_dug:pop()
|
||||||
end
|
end
|
||||||
|
return pos, status_text
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local controller_nodebox ={
|
||||||
|
{-0.3125, -0.3125, -0.3125, 0.3125, 0.3125, 0.3125}, -- Core
|
||||||
|
{-0.1875, 0.3125, -0.1875, 0.1875, 0.5, 0.1875}, -- +y_connector
|
||||||
|
{-0.1875, -0.5, -0.1875, 0.1875, -0.3125, 0.1875}, -- -y_Connector
|
||||||
|
{0.3125, -0.1875, -0.1875, 0.5, 0.1875, 0.1875}, -- +x_connector
|
||||||
|
{-0.5, -0.1875, -0.1875, -0.3125, 0.1875, 0.1875}, -- -x_connector
|
||||||
|
{-0.1875, -0.1875, 0.3125, 0.1875, 0.1875, 0.5}, -- +z_connector
|
||||||
|
{-0.5, 0.125, -0.5, -0.125, 0.5, -0.3125}, -- back_connector_3
|
||||||
|
{0.125, 0.125, -0.5, 0.5, 0.5, -0.3125}, -- back_connector_1
|
||||||
|
{0.125, -0.5, -0.5, 0.5, -0.125, -0.3125}, -- back_connector_2
|
||||||
|
{-0.5, -0.5, -0.5, -0.125, -0.125, -0.3125}, -- back_connector_4
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Master controller. Most complicated part of the whole system. Determines which direction a digtron moves and triggers all of its component parts.
|
||||||
|
minetest.register_node("digtron:controller", {
|
||||||
|
description = "Digtron Control Unit",
|
||||||
|
groups = {cracky = 3, oddly_breakable_by_hand = 3, digtron = 1},
|
||||||
|
drop = 'digtron:controller',
|
||||||
|
sounds = default.node_sound_metal_defaults(),
|
||||||
|
paramtype2= 'facedir',
|
||||||
|
-- Aims in the +Z direction by default
|
||||||
|
tiles = {
|
||||||
|
"digtron_plate.png^[transformR90",
|
||||||
|
"digtron_plate.png^[transformR270",
|
||||||
|
"digtron_plate.png",
|
||||||
|
"digtron_plate.png^[transformR180",
|
||||||
|
"digtron_plate.png",
|
||||||
|
"digtron_control.png",
|
||||||
|
},
|
||||||
|
|
||||||
|
drawtype = "nodebox",
|
||||||
|
paramtype = "light",
|
||||||
|
node_box = {
|
||||||
|
type = "fixed",
|
||||||
|
fixed = controller_nodebox,
|
||||||
|
},
|
||||||
|
|
||||||
|
on_construct = function(pos)
|
||||||
|
local meta = minetest.env:get_meta(pos)
|
||||||
|
meta:set_float("fuel_burning", 0.0)
|
||||||
|
meta:set_string("infotext", "Heat remaining in controller furnace: 0")
|
||||||
|
end,
|
||||||
|
|
||||||
|
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
||||||
|
newpos, status = digtron.execute_cycle(pos, node, clicker)
|
||||||
|
if status ~= nil then
|
||||||
|
local meta = minetest.get_meta(newpos)
|
||||||
|
meta:set_string("infotext", status)
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -280,7 +285,7 @@ minetest.register_node("digtron:controller", {
|
|||||||
-- Handy for shoving a digtron to the side if it's been built a bit off.
|
-- Handy for shoving a digtron to the side if it's been built a bit off.
|
||||||
minetest.register_node("digtron:pusher", {
|
minetest.register_node("digtron:pusher", {
|
||||||
description = "Digtron Pusher Unit",
|
description = "Digtron Pusher Unit",
|
||||||
groups = {cracky = 3, stone = 1, digtron = 1},
|
groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 1},
|
||||||
drop = 'digtron:pusher',
|
drop = 'digtron:pusher',
|
||||||
sounds = default.node_sound_metal_defaults(),
|
sounds = default.node_sound_metal_defaults(),
|
||||||
paramtype2= 'facedir',
|
paramtype2= 'facedir',
|
||||||
|
@ -12,7 +12,7 @@ local digger_nodebox = {
|
|||||||
-- Digs out nodes that are "in front" of the digger head.
|
-- Digs out nodes that are "in front" of the digger head.
|
||||||
minetest.register_node("digtron:digger", {
|
minetest.register_node("digtron:digger", {
|
||||||
description = "Digger Head",
|
description = "Digger Head",
|
||||||
groups = {cracky = 3, stone = 1, digtron = 3},
|
groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 3},
|
||||||
drop = 'digtron:digger',
|
drop = 'digtron:digger',
|
||||||
sounds = default.node_sound_metal_defaults(),
|
sounds = default.node_sound_metal_defaults(),
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
@ -96,7 +96,7 @@ minetest.register_node("digtron:digger", {
|
|||||||
-- A special-purpose digger to deal with stuff like sand and gravel in the ceiling. It always digs (no periodicity or offset), but it only digs falling_block nodes
|
-- A special-purpose digger to deal with stuff like sand and gravel in the ceiling. It always digs (no periodicity or offset), but it only digs falling_block nodes
|
||||||
minetest.register_node("digtron:soft_digger", {
|
minetest.register_node("digtron:soft_digger", {
|
||||||
description = "Soft Material Digger Head",
|
description = "Soft Material Digger Head",
|
||||||
groups = {cracky = 3, stone = 1, digtron = 3},
|
groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 3},
|
||||||
drop = 'digtron:soft_digger',
|
drop = 'digtron:soft_digger',
|
||||||
sounds = default.node_sound_metal_defaults(),
|
sounds = default.node_sound_metal_defaults(),
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
-- A do-nothing "structural" node, to ensure all digtron nodes that are supposed to be connected to each other can be connected to each other.
|
-- A do-nothing "structural" node, to ensure all digtron nodes that are supposed to be connected to each other can be connected to each other.
|
||||||
minetest.register_node("digtron:structure", {
|
minetest.register_node("digtron:structure", {
|
||||||
description = "Digger Structure",
|
description = "Digger Structure",
|
||||||
groups = {cracky = 3, stone = 1, digtron = 1},
|
groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 1},
|
||||||
drop = 'digtron:structure',
|
drop = 'digtron:structure',
|
||||||
tiles = {"digtron_plate.png"},
|
tiles = {"digtron_plate.png"},
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
@ -31,7 +31,7 @@ minetest.register_node("digtron:structure", {
|
|||||||
-- A modest light source that will move with the digtron, handy for working in a tunnel you aren't bothering to install permanent lights in.
|
-- A modest light source that will move with the digtron, handy for working in a tunnel you aren't bothering to install permanent lights in.
|
||||||
minetest.register_node("digtron:light", {
|
minetest.register_node("digtron:light", {
|
||||||
description = "Digger Light",
|
description = "Digger Light",
|
||||||
groups = {cracky = 3, stone = 1, digtron = 1},
|
groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 1},
|
||||||
drop = 'digtron:light',
|
drop = 'digtron:light',
|
||||||
tiles = {"digtron_light.png"},
|
tiles = {"digtron_light.png"},
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
@ -52,7 +52,7 @@ minetest.register_node("digtron:light", {
|
|||||||
minetest.register_node("digtron:inventory",
|
minetest.register_node("digtron:inventory",
|
||||||
{
|
{
|
||||||
description = "Digtron Inventory Hopper",
|
description = "Digtron Inventory Hopper",
|
||||||
groups = {cracky = 3, stone = 1, digtron = 2},
|
groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 2},
|
||||||
drop = 'digtron:inventory',
|
drop = 'digtron:inventory',
|
||||||
sounds = default.node_sound_metal_defaults(),
|
sounds = default.node_sound_metal_defaults(),
|
||||||
paramtype2= 'facedir',
|
paramtype2= 'facedir',
|
||||||
@ -89,7 +89,7 @@ minetest.register_node("digtron:inventory",
|
|||||||
minetest.register_node("digtron:fuelstore",
|
minetest.register_node("digtron:fuelstore",
|
||||||
{
|
{
|
||||||
description = "Digtron Fuel Hopper",
|
description = "Digtron Fuel Hopper",
|
||||||
groups = {cracky = 3, stone = 1, digtron = 5},
|
groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 5},
|
||||||
drop = 'digtron:fuelstore',
|
drop = 'digtron:fuelstore',
|
||||||
sounds = default.node_sound_metal_defaults(),
|
sounds = default.node_sound_metal_defaults(),
|
||||||
paramtype2= 'facedir',
|
paramtype2= 'facedir',
|
||||||
|
Reference in New Issue
Block a user