diff options
| -rw-r--r-- | README.txt | 2 | ||||
| -rw-r--r-- | init.lua | 1 | ||||
| -rw-r--r-- | node_controllers.lua | 13 | ||||
| -rw-r--r-- | node_diggers.lua | 22 | ||||
| -rw-r--r-- | util.lua | 17 | 
5 files changed, 53 insertions, 2 deletions
@@ -59,6 +59,8 @@ Facing of a digger head is significant; it will excavate material from the node  Digger heads come in both regular and "intermittent" versions, each of which is craftable from the other. The intermittent version can have a period and offset defined if you want them to punch regularly-spaced holes. Note that diggers aimed forward should generally always be the regular kind (or have a period of 1), otherwise the digging machine may be unable to move. +Be cautious around active digger heads when damage is enabled - they bite! +  Soft Material Digger Head  ---------------- @@ -11,6 +11,7 @@ dofile( minetest.get_modpath( "digtron" ) .."/recipes.lua" )  digtron.creative_mode = false -- this causes digtrons to operate without consuming fuel or building materials.  digtron.particle_effects = true -- Enables the spray of particles out the back of a digger head  digtron.lava_impassible = true -- when true, lava counts as protected nodes. +digtron.diggers_damage_creatures = true -- when true, diggers deal damage to creatures when they trigger.  digtron.cycle_time = 1 -- How many seconds a digtron waits between cycles. Auto-controllers can make this wait longer, but cannot make it shorter.  digtron.traction_factor = 3.0 -- How many digtron nodes can be moved for each adjacent solid node that the digtron has traction against diff --git a/node_controllers.lua b/node_controllers.lua index 6ff857e..45abebd 100644 --- a/node_controllers.lua +++ b/node_controllers.lua @@ -208,7 +208,18 @@ local execute_cycle = function(pos, clicker)  	   player_pos.z >= layout.extents.min_z - 1 and player_pos.z <= layout.extents.max_z + 1 then  		move_player = true  	end -		 +	 +	-- damage the weak flesh +	if digtron.diggers_damage_creatures then +		for k, location in pairs(layout.diggers) do +			local target = minetest.get_node(location) +			local targetdef = minetest.registered_nodes[target.name] +			if targetdef.damage_creatures ~= nil then +				targetdef.damage_creatures(clicker, location, digtron.find_new_pos(location, target.param2), controlling_coordinate) +			end +		end +	end +	  	--move the array  	digtron.move_digtron(facing, layout.all, layout.extents, nodes_dug, clicker:get_player_name())  	local oldpos = {x=pos.x, y=pos.y, z=pos.z} diff --git a/node_diggers.lua b/node_diggers.lua index 579cb12..3a7d9f8 100644 --- a/node_diggers.lua +++ b/node_diggers.lua @@ -83,6 +83,10 @@ minetest.register_node("digtron:digger", {  		return digtron.mark_diggable(digpos, nodes_dug)  	end, +	 +	damage_creatures = function(player, pos, targetpos, controlling_coordinate) +		digtron.damage_creatures(player, targetpos, 8) +	end,  })  -- Digs out nodes that are "in front" of the digger head. @@ -138,6 +142,13 @@ minetest.register_node("digtron:intermittent_digger", {  		return digtron.mark_diggable(digpos, nodes_dug)  	end, +	 +	damage_creatures = function(player, pos, targetpos, controlling_coordinate) +		local meta = minetest.get_meta(pos) +		if (targetpos[controlling_coordinate] + meta:get_int("offset")) % meta:get_int("period") == 0 then +			digtron.damage_creatures(player, targetpos, 8) +		end +	end  })  -- 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 @@ -192,6 +203,10 @@ minetest.register_node("digtron:soft_digger", {  		return 0, nil  	end, + +	damage_creatures = function(player, pos, targetpos, controlling_coordinate) +		digtron.damage_creatures(player, targetpos, 4) +	end,  })  minetest.register_node("digtron:intermittent_soft_digger", { @@ -254,4 +269,11 @@ minetest.register_node("digtron:intermittent_soft_digger", {  		return 0, nil  	end, + +	damage_creatures = function(player, pos, targetpos, controlling_coordinate) +		local meta = minetest.get_meta(pos) +		if (targetpos[controlling_coordinate] + meta:get_int("offset")) % meta:get_int("period") == 0 then +			digtron.damage_creatures(player, targetpos, 4) +		end +	end,  })
\ No newline at end of file @@ -429,4 +429,19 @@ digtron.update_builder_item = function(pos)  		digtron.create_builder_item = item_stack:get_name()  		minetest.add_entity(pos,"digtron:builder_item")  	end -end
\ No newline at end of file +end + +digtron.damage_creatures = function(player, pos, amount) +	local objects = minetest.env:get_objects_inside_radius(pos, 1.0) +	if objects ~= nil then +		for _, obj in ipairs(objects) do +			if obj then +				obj:punch(player, 1.0, { +					full_punch_interval = 1.0, +					damage_groups = {fleshy = amount}, +					}, nil ) +			end +		end +	end +end +	
\ No newline at end of file  | 
