Add dual digger heads for eventual use with diagonal movement

This commit is contained in:
FaceDeer 2017-01-13 23:20:59 -07:00
parent 13c74064be
commit f0e09f136a
4 changed files with 237 additions and 37 deletions

@ -9,6 +9,18 @@ local digger_nodebox = {
{-0.25, -0.25, -0.5, 0.25, 0.25, 0}, -- Drive {-0.25, -0.25, -0.5, 0.25, 0.25, 0}, -- Drive
} }
local dual_digger_nodebox = {
{-0.5, -0.4375, 0, 0.5, 0.5, 0.4375}, -- Block
{-0.4375, -0.3125, 0.4375, 0.4375, 0.3125, 0.5}, -- Cutter1
{-0.3125, -0.4375, 0.4375, 0.3125, 0.4375, 0.5}, -- Cutter2
{-0.5, 0, -0.125, 0.5, 0.125, 0}, -- BackFrame1
{-0.25, 0, -0.5, 0.25, 0.25, 0}, -- Drive
{-0.25, 0.25, -0.25, 0.25, 0.5, 0}, -- Upper_Drive
{-0.5, -0.4375, -0.5, 0.5, 0, 0.4375}, -- Lower_Block
{-0.3125, -0.5, -0.4375, 0.3125, -0.4375, 0.4375}, -- Lower_Cutter_1
{-0.4375, -0.5, -0.3125, 0.4375, -0.4375, 0.3125}, -- Lower_Cutter_2
}
local intermittent_on_construct = function(pos) local intermittent_on_construct = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_string("formspec", meta:set_string("formspec",
@ -78,14 +90,15 @@ minetest.register_node("digtron:digger", {
local digpos = digtron.find_new_pos(pos, facing) local digpos = digtron.find_new_pos(pos, facing)
if protected_nodes:get(digpos.x, digpos.y, digpos.z) then if protected_nodes:get(digpos.x, digpos.y, digpos.z) then
return 0, nil return 0, {}
end end
return digtron.mark_diggable(digpos, nodes_dug) return digtron.mark_diggable(digpos, nodes_dug)
end, end,
damage_creatures = function(player, pos, targetpos, controlling_coordinate) damage_creatures = function(player, pos, controlling_coordinate)
digtron.damage_creatures(player, targetpos, 8) local facing = minetest.get_node(pos).param2
digtron.damage_creatures(player, digtron.find_new_pos(pos, facing), 8)
end, end,
}) })
@ -132,18 +145,20 @@ minetest.register_node("digtron:intermittent_digger", {
local digpos = digtron.find_new_pos(pos, facing) local digpos = digtron.find_new_pos(pos, facing)
if protected_nodes:get(digpos.x, digpos.y, digpos.z) then if protected_nodes:get(digpos.x, digpos.y, digpos.z) then
return 0, nil return 0, {}
end end
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
if (digpos[controlling_coordinate] + meta:get_int("offset")) % meta:get_int("period") ~= 0 then if (digpos[controlling_coordinate] + meta:get_int("offset")) % meta:get_int("period") ~= 0 then
return 0, nil return 0, {}
end end
return digtron.mark_diggable(digpos, nodes_dug) return digtron.mark_diggable(digpos, nodes_dug)
end, end,
damage_creatures = function(player, pos, targetpos, controlling_coordinate) damage_creatures = function(player, pos, controlling_coordinate)
local facing = minetest.get_node(pos).param2
local targetpos = digtron.find_new_pos(pos, facing)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
if (targetpos[controlling_coordinate] + meta:get_int("offset")) % meta:get_int("period") == 0 then if (targetpos[controlling_coordinate] + meta:get_int("offset")) % meta:get_int("period") == 0 then
digtron.damage_creatures(player, targetpos, 8) digtron.damage_creatures(player, targetpos, 8)
@ -189,23 +204,19 @@ minetest.register_node("digtron:soft_digger", {
local digpos = digtron.find_new_pos(pos, facing) local digpos = digtron.find_new_pos(pos, facing)
if protected_nodes:get(digpos.x, digpos.y, digpos.z) then if protected_nodes:get(digpos.x, digpos.y, digpos.z) then
return 0, nil return 0, {}
end end
local target_node = minetest.get_node(digpos) if digtron.is_soft_material(digpos) then
if minetest.get_item_group(target_node.name, "crumbly") ~= 0 or
minetest.get_item_group(target_node.name, "choppy") ~= 0 or
minetest.get_item_group(target_node.name, "snappy") ~= 0 or
minetest.get_item_group(target_node.name, "oddly_breakable_by_hand") ~= 0 or
minetest.get_item_group(target_node.name, "fleshy") ~= 0 then
return digtron.mark_diggable(digpos, nodes_dug) return digtron.mark_diggable(digpos, nodes_dug)
end end
return 0, nil return 0, {}
end, end,
damage_creatures = function(player, pos, targetpos, controlling_coordinate) damage_creatures = function(player, pos, controlling_coordinate)
digtron.damage_creatures(player, targetpos, 4) local facing = minetest.get_node(pos).param2
digtron.damage_creatures(player, digtron.find_new_pos(pos, facing), 4)
end, end,
}) })
@ -250,30 +261,177 @@ minetest.register_node("digtron:intermittent_soft_digger", {
local digpos = digtron.find_new_pos(pos, facing) local digpos = digtron.find_new_pos(pos, facing)
if protected_nodes:get(digpos.x, digpos.y, digpos.z) then if protected_nodes:get(digpos.x, digpos.y, digpos.z) then
return 0, nil return 0, {}
end end
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
if (digpos[controlling_coordinate] + meta:get_int("offset")) % meta:get_int("period") ~= 0 then if (digpos[controlling_coordinate] + meta:get_int("offset")) % meta:get_int("period") ~= 0 then
return 0, nil return 0, {}
end end
local target_node = minetest.get_node(digpos) if digtron.is_soft_material(digpos) then
if minetest.get_item_group(target_node.name, "crumbly") ~= 0 or
minetest.get_item_group(target_node.name, "choppy") ~= 0 or
minetest.get_item_group(target_node.name, "snappy") ~= 0 or
minetest.get_item_group(target_node.name, "oddly_breakable_by_hand") ~= 0 or
minetest.get_item_group(target_node.name, "fleshy") ~= 0 then
return digtron.mark_diggable(digpos, nodes_dug) return digtron.mark_diggable(digpos, nodes_dug)
end end
return 0, nil return 0, {}
end, end,
damage_creatures = function(player, pos, targetpos, controlling_coordinate) damage_creatures = function(player, pos, controlling_coordinate)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local facing = minetest.get_node(pos).param2
local targetpos = digtron.find_new_pos(pos, facing)
if (targetpos[controlling_coordinate] + meta:get_int("offset")) % meta:get_int("period") == 0 then if (targetpos[controlling_coordinate] + meta:get_int("offset")) % meta:get_int("period") == 0 then
digtron.damage_creatures(player, targetpos, 4) digtron.damage_creatures(player, targetpos, 4)
end end
end, end,
})
-- Digs out nodes that are "in front" of the digger head and "below" the digger head (can be rotated).
minetest.register_node("digtron:dual_digger", {
description = "Dual Digger Head",
groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 3},
drop = "digtron:dual_digger",
sounds = digtron.metal_sounds,
paramtype = "light",
paramtype2= "facedir",
is_ground_content = false,
drawtype="nodebox",
node_box = {
type = "fixed",
fixed = dual_digger_nodebox,
},
-- Aims in the +Z and -Y direction by default
tiles = {
"digtron_plate.png^digtron_motor.png",
{
name = "digtron_digger_yb.png",
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 1.0,
},
},
"digtron_plate.png",
"digtron_plate.png^[transformR180",
{
name = "digtron_digger_yb.png",
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 1.0,
},
},
"digtron_plate.png^digtron_motor.png",
},
-- returns fuel_cost, items_produced
execute_dig = function(pos, protected_nodes, nodes_dug, controlling_coordinate)
local facing = minetest.get_node(pos).param2
local digpos = digtron.find_new_pos(pos, facing)
local digdown = digtron.find_new_pos_downward(pos, facing)
local items = {}
local cost = 0
if protected_nodes:get(digpos.x, digpos.y, digpos.z) ~= true then
local forward_cost, forward_items = digtron.mark_diggable(digpos, nodes_dug)
for _, item in pairs(forward_items) do
table.insert(items, item)
end
cost = cost + forward_cost
end
if protected_nodes:get(digdown.x, digdown.y, digdown.z) ~= true then
local down_cost, down_items = digtron.mark_diggable(digdown, nodes_dug)
for _, item in pairs(down_items) do
table.insert(items, item)
end
cost = cost + down_cost
end
return cost, items
end,
damage_creatures = function(player, pos, controlling_coordinate)
local facing = minetest.get_node(pos).param2
digtron.damage_creatures(player, digtron.find_new_pos(pos, facing), 8)
digtron.damage_creatures(player, digtron.find_new_pos_downward(pos, facing), 8)
end,
})
-- Digs out soft nodes that are "in front" of the digger head and "below" the digger head (can be rotated).
minetest.register_node("digtron:dual_soft_digger", {
description = "Dual Soft Material Digger Head",
groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 3},
drop = "digtron:dual_soft_digger",
sounds = digtron.metal_sounds,
paramtype = "light",
paramtype2= "facedir",
is_ground_content = false,
drawtype="nodebox",
node_box = {
type = "fixed",
fixed = dual_digger_nodebox,
},
-- Aims in the +Z and -Y direction by default
tiles = {
"digtron_plate.png^digtron_motor.png^[colorize:#88880030",
{
name = "digtron_digger_yb.png^[colorize:#88880030",
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 1.0,
},
},
"digtron_plate.png^[colorize:#88880030",
"digtron_plate.png^[transformR180^[colorize:#88880030",
{
name = "digtron_digger_yb.png^[colorize:#88880030",
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 1.0,
},
},
"digtron_plate.png^digtron_motor.png^[colorize:#88880030",
},
-- returns fuel_cost, items_produced
execute_dig = function(pos, protected_nodes, nodes_dug, controlling_coordinate)
local facing = minetest.get_node(pos).param2
local digpos = digtron.find_new_pos(pos, facing)
local digdown = digtron.find_new_pos_downward(pos, facing)
local items = {}
local cost = 0
if protected_nodes:get(digpos.x, digpos.y, digpos.z) ~= true and digtron.is_soft_material(digpos) then
local forward_cost, forward_items = digtron.mark_diggable(digpos, nodes_dug)
for _, item in pairs(forward_items) do
table.insert(items, item)
end
cost = cost + forward_cost
end
if protected_nodes:get(digdown.x, digdown.y, digdown.z) ~= true and digtron.is_soft_material(digdown) then
local down_cost, down_items = digtron.mark_diggable(digdown, nodes_dug)
for _, item in pairs(down_items) do
table.insert(items, item)
end
cost = cost + down_cost
end
return cost, items
end,
damage_creatures = function(player, pos, controlling_coordinate)
local facing = minetest.get_node(pos).param2
digtron.damage_creatures(player, digtron.find_new_pos(pos, facing), 4)
digtron.damage_creatures(player, digtron.find_new_pos_downward(pos, facing), 4)
end,
}) })

@ -175,6 +175,29 @@ minetest.register_craft({
} }
}) })
minetest.register_craft({
output = "digtron:dual_soft_digger",
type = "shapeless",
recipe = {"digtron:soft_digger", "digtron:soft_digger"},
})
minetest.register_craft({
output = "digtron:dual_digger",
type = "shapeless",
recipe = {"digtron:digger", "digtron:digger"},
})
minetest.register_craft({
output = "digtron:soft_digger 2",
recipe = {
{"digtron:dual_soft_digger"},
}
})
minetest.register_craft({
output = "digtron:digger 2",
recipe = {
{"digtron:dual_digger"},
}
})
-- And some recycling reactions to get digtron cores out of the "cheap" parts: -- And some recycling reactions to get digtron cores out of the "cheap" parts:
minetest.register_craft({ minetest.register_craft({

@ -16,11 +16,19 @@ end
digtron.find_new_pos = function(pos, facing) digtron.find_new_pos = function(pos, facing)
-- finds the point one node "forward", based on facing -- finds the point one node "forward", based on facing
local dir = minetest.facedir_to_dir(facing) local dir = minetest.facedir_to_dir(facing)
local newpos = {} return vector.add(pos, dir)
newpos.x = pos.x + dir.x end
newpos.y = pos.y + dir.y
newpos.z = pos.z + dir.z digtron.find_new_pos_downward = function(pos, facing)
return newpos local downdir = (
{[0]={x=0, y=-1, z=0},
{x=0, y=0, z=-1},
{x=0, y=0, z=1},
{x=-1, y=0, z=0},
{x=1, y=0, z=0},
{x=0, y=1, z=0}})[math.floor(facing/4)]
return vector.add(pos, downdir)
end end
digtron.mark_diggable = function(pos, nodes_dug) digtron.mark_diggable = function(pos, nodes_dug)
@ -34,7 +42,7 @@ digtron.mark_diggable = function(pos, nodes_dug)
-- prevent digtrons from being marked for digging. -- prevent digtrons from being marked for digging.
if minetest.get_item_group(target.name, "digtron") ~= 0 then if minetest.get_item_group(target.name, "digtron") ~= 0 then
return 0, nil return 0, {}
end end
local targetdef = minetest.registered_nodes[target.name] local targetdef = minetest.registered_nodes[target.name]
@ -65,7 +73,7 @@ digtron.mark_diggable = function(pos, nodes_dug)
return material_cost, minetest.get_node_drops(target.name, "") return material_cost, minetest.get_node_drops(target.name, "")
end end
end end
return 0, nil return 0, {}
end end
digtron.can_build_to = function(pos, protected_nodes, dug_nodes) digtron.can_build_to = function(pos, protected_nodes, dug_nodes)
@ -221,4 +229,15 @@ digtron.damage_creatures = function(player, pos, amount)
end end
end end
end end
digtron.is_soft_material = function(target)
local target_node = minetest.get_node(target)
if minetest.get_item_group(target_node.name, "crumbly") ~= 0 or
minetest.get_item_group(target_node.name, "choppy") ~= 0 or
minetest.get_item_group(target_node.name, "snappy") ~= 0 or
minetest.get_item_group(target_node.name, "oddly_breakable_by_hand") ~= 0 or
minetest.get_item_group(target_node.name, "fleshy") ~= 0 then
return true
end
return false
end

@ -116,7 +116,7 @@ digtron.execute_dig_cycle = function(pos, clicker)
local targetdef = minetest.registered_nodes[target.name] local targetdef = minetest.registered_nodes[target.name]
if targetdef.execute_dig ~= nil then if targetdef.execute_dig ~= nil then
local fuel_cost, dropped = targetdef.execute_dig(location.pos, layout.protected, layout.nodes_dug, controlling_coordinate) local fuel_cost, dropped = targetdef.execute_dig(location.pos, layout.protected, layout.nodes_dug, controlling_coordinate)
if dropped ~= nil then if table.getn(dropped) > 0 then
for _, itemname in pairs(dropped) do for _, itemname in pairs(dropped) do
table.insert(items_dropped, itemname) table.insert(items_dropped, itemname)
end end
@ -230,7 +230,7 @@ digtron.execute_dig_cycle = function(pos, clicker)
local target = minetest.get_node(location.pos) local target = minetest.get_node(location.pos)
local targetdef = minetest.registered_nodes[target.name] local targetdef = minetest.registered_nodes[target.name]
if targetdef.damage_creatures ~= nil then if targetdef.damage_creatures ~= nil then
targetdef.damage_creatures(clicker, location.pos, digtron.find_new_pos(location.pos, target.param2), controlling_coordinate) targetdef.damage_creatures(clicker, location.pos, controlling_coordinate)
end end
end end
end end