mirror of
https://github.com/minetest-mods/digtron.git
synced 2024-12-22 20:32:22 +01:00
making digtron nodes diggable by hand. Also extracting controller code in prep for an autonomous controller
This commit is contained in:
parent
711c43b964
commit
c1a090137c
@ -3,7 +3,7 @@
|
||||
-- Builds objects in the targeted node. This is a complicated beastie.
|
||||
minetest.register_node("digtron:builder", {
|
||||
description = "Builder Unit",
|
||||
groups = {cracky = 3, stone = 1, digtron = 4},
|
||||
groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 4},
|
||||
drop = "digtron:builder",
|
||||
sounds = default.node_sound_metal_defaults(),
|
||||
paramtype2= 'facedir',
|
||||
|
@ -1,66 +1,21 @@
|
||||
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, 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)
|
||||
digtron.execute_cycle = function(pos, node, clicker)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if meta:get_string("waiting") == "true" then
|
||||
-- Been too soon since last time the digtron did a cycle.
|
||||
return
|
||||
return pos, nil
|
||||
end
|
||||
|
||||
local layout = digtron.get_all_digtron_neighbours(pos, clicker)
|
||||
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.
|
||||
minetest.sound_play("buzzer", {gain=0.5, pos=pos})
|
||||
meta:set_string("infotext", "Digtron is adjacent to unloaded nodes.")
|
||||
return
|
||||
return pos, "Digtron is adjacent to unloaded nodes."
|
||||
end
|
||||
|
||||
if layout.traction * digtron.traction_factor < table.getn(layout.all) then
|
||||
-- digtrons can't fly
|
||||
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
|
||||
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)
|
||||
end
|
||||
|
||||
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("buzzer", {gain=0.5, pos=pos})
|
||||
meta:set_string("infotext", "Digtron is obstructed.")
|
||||
return --Abort, don't dig and don't build.
|
||||
return pos, "Digtron is obstructed." --Abort, don't dig and don't build.
|
||||
end
|
||||
|
||||
----------------------------------------------------------------------------------------------------------------------
|
||||
@ -163,8 +117,7 @@ minetest.register_node("digtron:controller", {
|
||||
|
||||
if test_fuel_needed > fuel_burning + test_fuel_burned then
|
||||
minetest.sound_play("buzzer", {gain=0.5, pos=pos})
|
||||
meta:set_string("infotext", "Digtron needs more fuel")
|
||||
return -- abort, don't dig and don't build.
|
||||
return pos, "Digtron needs more fuel" -- abort, don't dig and don't build.
|
||||
end
|
||||
|
||||
if not can_build then
|
||||
@ -174,15 +127,16 @@ minetest.register_node("digtron:controller", {
|
||||
minetest.get_meta(pos):set_string("waiting", nil)
|
||||
end, pos
|
||||
)
|
||||
local return_string = nil
|
||||
if test_build_return_code == 3 then
|
||||
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
|
||||
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",
|
||||
test_build_return_item:get_name()))
|
||||
return_string = string.format("Digtron has insufficient materials in inventory to execute all build operations.\nNeeded: %s",
|
||||
test_build_return_item:get_name())
|
||||
end
|
||||
return --Abort, don't dig and don't build.
|
||||
return pos, return_string --Abort, don't dig and don't build.
|
||||
end
|
||||
|
||||
----------------------------------------------------------------------------------------------------------------------
|
||||
@ -257,9 +211,7 @@ minetest.register_node("digtron:controller", {
|
||||
fuel_burning = fuel_burning + digtron.burn(layout.fuelstores, -fuel_burning, false)
|
||||
end
|
||||
meta:set_float("fuel_burning", fuel_burning)
|
||||
if not strange_failure then
|
||||
meta:set_string("infotext", status_text .. string.format("Heat remaining in controller furnace: %d", fuel_burning))
|
||||
end
|
||||
status_text = status_text .. string.format("Heat remaining in controller furnace: %d", fuel_burning)
|
||||
|
||||
-- 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.
|
||||
@ -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})
|
||||
node_to_dig, whether_to_dig = nodes_dug:pop()
|
||||
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,
|
||||
})
|
||||
|
||||
@ -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.
|
||||
minetest.register_node("digtron:pusher", {
|
||||
description = "Digtron Pusher Unit",
|
||||
groups = {cracky = 3, stone = 1, digtron = 1},
|
||||
groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 1},
|
||||
drop = 'digtron:pusher',
|
||||
sounds = default.node_sound_metal_defaults(),
|
||||
paramtype2= 'facedir',
|
||||
|
@ -12,7 +12,7 @@ local digger_nodebox = {
|
||||
-- Digs out nodes that are "in front" of the digger head.
|
||||
minetest.register_node("digtron:digger", {
|
||||
description = "Digger Head",
|
||||
groups = {cracky = 3, stone = 1, digtron = 3},
|
||||
groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 3},
|
||||
drop = 'digtron:digger',
|
||||
sounds = default.node_sound_metal_defaults(),
|
||||
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
|
||||
minetest.register_node("digtron:soft_digger", {
|
||||
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',
|
||||
sounds = default.node_sound_metal_defaults(),
|
||||
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.
|
||||
minetest.register_node("digtron:structure", {
|
||||
description = "Digger Structure",
|
||||
groups = {cracky = 3, stone = 1, digtron = 1},
|
||||
groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 1},
|
||||
drop = 'digtron:structure',
|
||||
tiles = {"digtron_plate.png"},
|
||||
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.
|
||||
minetest.register_node("digtron:light", {
|
||||
description = "Digger Light",
|
||||
groups = {cracky = 3, stone = 1, digtron = 1},
|
||||
groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 1},
|
||||
drop = 'digtron:light',
|
||||
tiles = {"digtron_light.png"},
|
||||
drawtype = "nodebox",
|
||||
@ -52,7 +52,7 @@ minetest.register_node("digtron:light", {
|
||||
minetest.register_node("digtron:inventory",
|
||||
{
|
||||
description = "Digtron Inventory Hopper",
|
||||
groups = {cracky = 3, stone = 1, digtron = 2},
|
||||
groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 2},
|
||||
drop = 'digtron:inventory',
|
||||
sounds = default.node_sound_metal_defaults(),
|
||||
paramtype2= 'facedir',
|
||||
@ -89,7 +89,7 @@ minetest.register_node("digtron:inventory",
|
||||
minetest.register_node("digtron:fuelstore",
|
||||
{
|
||||
description = "Digtron Fuel Hopper",
|
||||
groups = {cracky = 3, stone = 1, digtron = 5},
|
||||
groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 5},
|
||||
drop = 'digtron:fuelstore',
|
||||
sounds = default.node_sound_metal_defaults(),
|
||||
paramtype2= 'facedir',
|
||||
|
Loading…
Reference in New Issue
Block a user