mirror of
				https://github.com/minetest-mods/mesecons.git
				synced 2025-11-04 12:55:29 +01:00 
			
		
		
		
	Modified movestone pistons mvps for all liquid
This commit is contained in:
		@@ -1,211 +1,211 @@
 | 
			
		||||
-- MOVESTONE
 | 
			
		||||
 | 
			
		||||
function mesecon:get_movestone_direction(pos)
 | 
			
		||||
	getactivated=0
 | 
			
		||||
	local lpos
 | 
			
		||||
	local getactivated=0
 | 
			
		||||
	local rules=mesecon:get_rules("movestone")
 | 
			
		||||
 | 
			
		||||
	lpos={x=pos.x+1, y=pos.y, z=pos.z}
 | 
			
		||||
	for n=1, 3 do
 | 
			
		||||
		if mesecon:is_power_on(lpos, rules[n].x, rules[n].y, rules[n].z) then
 | 
			
		||||
			return {x=0, y=0, z=-1}
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	lpos={x=pos.x-1, y=pos.y, z=pos.z}
 | 
			
		||||
	for n=4, 6 do
 | 
			
		||||
		if mesecon:is_power_on(lpos, rules[n].x, rules[n].y, rules[n].z) then
 | 
			
		||||
			return {x=0, y=0, z=1}
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	lpos={x=pos.x, y=pos.y, z=pos.z+1}
 | 
			
		||||
	for n=7, 9 do
 | 
			
		||||
		if mesecon:is_power_on(lpos, rules[n].x, rules[n].y, rules[n].z) then
 | 
			
		||||
			return {x=-1, y=0, z=0}
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	lpos={x=pos.x, y=pos.y, z=pos.z-1}
 | 
			
		||||
	for n=10, 12 do
 | 
			
		||||
		if mesecon:is_power_on(lpos, rules[n].x, rules[n].y, rules[n].z) then
 | 
			
		||||
			return {x=1, y=0, z=0}
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
minetest.register_node("mesecons_movestones:movestone", {
 | 
			
		||||
	tiles = {"jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_arrows.png", "jeija_movestone_arrows.png"},
 | 
			
		||||
	paramtype2 = "facedir",
 | 
			
		||||
	legacy_facedir_simple = true,
 | 
			
		||||
	groups = {cracky=3},
 | 
			
		||||
    	description="Movestone",
 | 
			
		||||
})
 | 
			
		||||
mesecon:register_effector("mesecons_movestones:movestone", "mesecons_movestones:movestone")
 | 
			
		||||
 | 
			
		||||
minetest.register_entity("mesecons_movestones:movestone_entity", {
 | 
			
		||||
	physical = false,
 | 
			
		||||
	visual = "sprite",
 | 
			
		||||
	textures = {"jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_arrows.png", "jeija_movestone_arrows.png"},
 | 
			
		||||
	collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
 | 
			
		||||
	visual = "cube",
 | 
			
		||||
	--on_activate = function(self, staticdata)
 | 
			
		||||
		--self.object:setsprite({x=0,y=0}, 1, 0, true)
 | 
			
		||||
		--self.object:setvelocity({x=-3, y=0, z=0})
 | 
			
		||||
	--end,
 | 
			
		||||
 | 
			
		||||
	on_punch = function(self, hitter)
 | 
			
		||||
		self.object:remove()
 | 
			
		||||
		hitter:get_inventory():add_item("main", "mesecons_movestones:movestone")
 | 
			
		||||
	end,
 | 
			
		||||
 | 
			
		||||
	on_step = function(self, dtime)
 | 
			
		||||
		local pos = self.object:getpos()
 | 
			
		||||
		local direction=mesecon:get_movestone_direction(pos)
 | 
			
		||||
 | 
			
		||||
		if not direction then
 | 
			
		||||
			minetest.env:add_node(pos, {name="mesecons_movestones:movestone"})
 | 
			
		||||
			self.object:remove()
 | 
			
		||||
			return
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		self.object:setvelocity({x=direction.x*3, y=direction.y*3, z=direction.z*3})
 | 
			
		||||
 | 
			
		||||
		mesecon:mvps_push(pos, direction)
 | 
			
		||||
	end
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
minetest.register_craft({
 | 
			
		||||
	output = '"mesecons_movestones:movestone" 2',
 | 
			
		||||
	recipe = {
 | 
			
		||||
		{'"default:stone"', '"default:stone"', '"default:stone"'},
 | 
			
		||||
		{'"group:mesecon_conductor_craftable"', '"group:mesecon_conductor_craftable"', '"group:mesecon_conductor_craftable"'},
 | 
			
		||||
		{'"default:stone"', '"default:stone"', '"default:stone"'},
 | 
			
		||||
	}
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
mesecon:register_on_signal_on(function (pos, node)
 | 
			
		||||
	if node.name=="mesecons_movestones:movestone" then
 | 
			
		||||
		local direction=mesecon:get_movestone_direction(pos)
 | 
			
		||||
		if not direction then return end
 | 
			
		||||
		local checknode={}
 | 
			
		||||
		local collpos={x=pos.x, y=pos.y, z=pos.z}
 | 
			
		||||
		repeat -- Check if it collides with a stopper
 | 
			
		||||
			collpos={x=collpos.x+direction.x, y=collpos.y+direction.y, z=collpos.z+direction.z}
 | 
			
		||||
			checknode=minetest.env:get_node(collpos)
 | 
			
		||||
			if mesecon:is_mvps_stopper(checknode.name) then 
 | 
			
		||||
				return
 | 
			
		||||
			end
 | 
			
		||||
		until checknode.name=="air"
 | 
			
		||||
		or checknode.name=="ignore" 
 | 
			
		||||
		or checknode.name=="default:water"
 | 
			
		||||
		or checknode.name=="default:water_flowing"
 | 
			
		||||
		minetest.env:remove_node(pos)
 | 
			
		||||
		nodeupdate(pos)
 | 
			
		||||
		minetest.env:add_entity(pos, "mesecons_movestones:movestone_entity")
 | 
			
		||||
	end
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
-- STICKY_MOVESTONE
 | 
			
		||||
 | 
			
		||||
minetest.register_node("mesecons_movestones:sticky_movestone", {
 | 
			
		||||
	tiles = {"jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_sticky_movestone.png", "jeija_sticky_movestone.png"},
 | 
			
		||||
	inventory_image = minetest.inventorycube("jeija_sticky_movestone.png", "jeija_movestone_side.png", "jeija_movestone_side.png"),
 | 
			
		||||
	paramtype2 = "facedir",
 | 
			
		||||
	legacy_facedir_simple = true,
 | 
			
		||||
	groups = {cracky=3},
 | 
			
		||||
    	description="Sticky Movestone",
 | 
			
		||||
})
 | 
			
		||||
mesecon:register_effector("mesecons_movestones:sticky_movestone", "mesecons_movestones:sticky_movestone")
 | 
			
		||||
 | 
			
		||||
minetest.register_craft({
 | 
			
		||||
	output = '"mesecons_movestones:sticky_movestone" 2',
 | 
			
		||||
	recipe = {
 | 
			
		||||
		{'"mesecons_materials:glue"', '"mesecons_movestones:movestone"', '"mesecons_materials:glue"'},
 | 
			
		||||
	}
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
minetest.register_entity("mesecons_movestones:sticky_movestone_entity", {
 | 
			
		||||
	physical = false,
 | 
			
		||||
	visual = "sprite",
 | 
			
		||||
	textures = {"jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_sticky_movestone.png", "jeija_sticky_movestone.png"},
 | 
			
		||||
	collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
 | 
			
		||||
	visual = "cube",
 | 
			
		||||
 | 
			
		||||
	on_punch = function(self, hitter)
 | 
			
		||||
		self.object:remove()
 | 
			
		||||
		hitter:get_inventory():add_item("main", 'mesecons_movestones:sticky_movestone')
 | 
			
		||||
	end,
 | 
			
		||||
 | 
			
		||||
	on_step = function(self, dtime)
 | 
			
		||||
		local pos = self.object:getpos()
 | 
			
		||||
		local colp = pos
 | 
			
		||||
		local direction=mesecon:get_movestone_direction(colp)
 | 
			
		||||
 | 
			
		||||
		if not direction then
 | 
			
		||||
		--or (minetest.env:get_node_or_nil(pos).name ~="air" 
 | 
			
		||||
		--and minetest.env:get_node_or_nil(pos).name ~= nil) then
 | 
			
		||||
			minetest.env:add_node(pos, {name="mesecons_movestones:sticky_movestone"})
 | 
			
		||||
			self.object:remove()
 | 
			
		||||
			return
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		self.object:setvelocity({x=direction.x*3, y=direction.y*3, z=direction.z*3})
 | 
			
		||||
 | 
			
		||||
		mesecon:mvps_push(pos, direction)
 | 
			
		||||
 | 
			
		||||
		--STICKY
 | 
			
		||||
		mesecon:mvps_pull_all(pos, direction)
 | 
			
		||||
	end
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
mesecon:register_on_signal_on(function (pos, node)
 | 
			
		||||
	if node.name=="mesecons_movestones:sticky_movestone" then
 | 
			
		||||
		local direction=mesecon:get_movestone_direction(pos)
 | 
			
		||||
		if not direction then return end
 | 
			
		||||
		local checknode={}
 | 
			
		||||
		local collpos={x=pos.x, y=pos.y, z=pos.z}
 | 
			
		||||
		repeat -- Check if it collides with a stopper
 | 
			
		||||
			collpos={x=collpos.x+direction.x, y=collpos.y+direction.y, z=collpos.z+direction.z}
 | 
			
		||||
			checknode=minetest.env:get_node(collpos)
 | 
			
		||||
			if mesecon:is_mvps_stopper(checknode.name) then 
 | 
			
		||||
				return 
 | 
			
		||||
			end
 | 
			
		||||
		until checknode.name=="air"
 | 
			
		||||
		or checknode.name=="ignore" 
 | 
			
		||||
		or checknode.name=="default:water" 
 | 
			
		||||
		or checknode.name=="default:water_flowing" 
 | 
			
		||||
		repeat -- Check if it collides with a stopper (pull direction)
 | 
			
		||||
			collpos={x=collpos.x-direction.x, y=collpos.y-direction.y, z=collpos.z-direction.z}
 | 
			
		||||
			checknode=minetest.env:get_node(collpos)
 | 
			
		||||
			if mesecon:is_mvps_stopper(checknode.name) then
 | 
			
		||||
				return 
 | 
			
		||||
			end
 | 
			
		||||
		until checknode.name=="air"
 | 
			
		||||
		or checknode.name=="ignore" 
 | 
			
		||||
		or checknode.name=="default:water" 
 | 
			
		||||
		or checknode.name=="default:water_flowing" 
 | 
			
		||||
 | 
			
		||||
		minetest.env:remove_node(pos)
 | 
			
		||||
		nodeupdate(pos)
 | 
			
		||||
		minetest.env:add_entity(pos, "mesecons_movestones:sticky_movestone_entity")
 | 
			
		||||
	end
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
mesecon:add_rules("movestone", {
 | 
			
		||||
{x=0,  y=1,  z=-1},
 | 
			
		||||
{x=0,  y=0,  z=-1},
 | 
			
		||||
{x=0,  y=-1, z=-1},
 | 
			
		||||
{x=0,  y=1,  z=1},
 | 
			
		||||
{x=0,  y=-1, z=1},
 | 
			
		||||
{x=0,  y=0,  z=1},
 | 
			
		||||
{x=1,  y=0,  z=0},
 | 
			
		||||
{x=1,  y=1,  z=0},
 | 
			
		||||
{x=1,  y=-1, z=0},
 | 
			
		||||
{x=-1, y=1,  z=0},
 | 
			
		||||
{x=-1, y=-1, z=0},
 | 
			
		||||
{x=-1, y=0,  z=0}})
 | 
			
		||||
-- MOVESTONE
 | 
			
		||||
 | 
			
		||||
function mesecon:get_movestone_direction(pos)
 | 
			
		||||
	getactivated=0
 | 
			
		||||
	local lpos
 | 
			
		||||
	local getactivated=0
 | 
			
		||||
	local rules=mesecon:get_rules("movestone")
 | 
			
		||||
 | 
			
		||||
	lpos={x=pos.x+1, y=pos.y, z=pos.z}
 | 
			
		||||
	for n=1, 3 do
 | 
			
		||||
		if mesecon:is_power_on(lpos, rules[n].x, rules[n].y, rules[n].z) then
 | 
			
		||||
			return {x=0, y=0, z=-1}
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	lpos={x=pos.x-1, y=pos.y, z=pos.z}
 | 
			
		||||
	for n=4, 6 do
 | 
			
		||||
		if mesecon:is_power_on(lpos, rules[n].x, rules[n].y, rules[n].z) then
 | 
			
		||||
			return {x=0, y=0, z=1}
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	lpos={x=pos.x, y=pos.y, z=pos.z+1}
 | 
			
		||||
	for n=7, 9 do
 | 
			
		||||
		if mesecon:is_power_on(lpos, rules[n].x, rules[n].y, rules[n].z) then
 | 
			
		||||
			return {x=-1, y=0, z=0}
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	lpos={x=pos.x, y=pos.y, z=pos.z-1}
 | 
			
		||||
	for n=10, 12 do
 | 
			
		||||
		if mesecon:is_power_on(lpos, rules[n].x, rules[n].y, rules[n].z) then
 | 
			
		||||
			return {x=1, y=0, z=0}
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
minetest.register_node("mesecons_movestones:movestone", {
 | 
			
		||||
	tiles = {"jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_arrows.png", "jeija_movestone_arrows.png"},
 | 
			
		||||
	paramtype2 = "facedir",
 | 
			
		||||
	legacy_facedir_simple = true,
 | 
			
		||||
	groups = {cracky=3},
 | 
			
		||||
    	description="Movestone",
 | 
			
		||||
})
 | 
			
		||||
mesecon:register_effector("mesecons_movestones:movestone", "mesecons_movestones:movestone")
 | 
			
		||||
 | 
			
		||||
minetest.register_entity("mesecons_movestones:movestone_entity", {
 | 
			
		||||
	physical = false,
 | 
			
		||||
	visual = "sprite",
 | 
			
		||||
	textures = {"jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_arrows.png", "jeija_movestone_arrows.png"},
 | 
			
		||||
	collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
 | 
			
		||||
	visual = "cube",
 | 
			
		||||
	--on_activate = function(self, staticdata)
 | 
			
		||||
		--self.object:setsprite({x=0,y=0}, 1, 0, true)
 | 
			
		||||
		--self.object:setvelocity({x=-3, y=0, z=0})
 | 
			
		||||
	--end,
 | 
			
		||||
 | 
			
		||||
	on_punch = function(self, hitter)
 | 
			
		||||
		self.object:remove()
 | 
			
		||||
		hitter:get_inventory():add_item("main", "mesecons_movestones:movestone")
 | 
			
		||||
	end,
 | 
			
		||||
 | 
			
		||||
	on_step = function(self, dtime)
 | 
			
		||||
		local pos = self.object:getpos()
 | 
			
		||||
		local direction=mesecon:get_movestone_direction(pos)
 | 
			
		||||
 | 
			
		||||
		if not direction then
 | 
			
		||||
			minetest.env:add_node(pos, {name="mesecons_movestones:movestone"})
 | 
			
		||||
			self.object:remove()
 | 
			
		||||
			return
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		self.object:setvelocity({x=direction.x*3, y=direction.y*3, z=direction.z*3})
 | 
			
		||||
 | 
			
		||||
		mesecon:mvps_push(pos, direction)
 | 
			
		||||
	end
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
minetest.register_craft({
 | 
			
		||||
	output = '"mesecons_movestones:movestone" 2',
 | 
			
		||||
	recipe = {
 | 
			
		||||
		{'"default:stone"', '"default:stone"', '"default:stone"'},
 | 
			
		||||
		{'"group:mesecon_conductor_craftable"', '"group:mesecon_conductor_craftable"', '"group:mesecon_conductor_craftable"'},
 | 
			
		||||
		{'"default:stone"', '"default:stone"', '"default:stone"'},
 | 
			
		||||
	}
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
mesecon:register_on_signal_on(function (pos, node)
 | 
			
		||||
	if node.name=="mesecons_movestones:movestone" then
 | 
			
		||||
		local direction=mesecon:get_movestone_direction(pos)
 | 
			
		||||
		if not direction then return end
 | 
			
		||||
		local checknode={}
 | 
			
		||||
		local collpos={x=pos.x, y=pos.y, z=pos.z}
 | 
			
		||||
		repeat -- Check if it collides with a stopper
 | 
			
		||||
			collpos={x=collpos.x+direction.x, y=collpos.y+direction.y, z=collpos.z+direction.z}
 | 
			
		||||
			checknode=minetest.env:get_node(collpos)
 | 
			
		||||
			if mesecon:is_mvps_stopper(checknode.name) then 
 | 
			
		||||
				return
 | 
			
		||||
			end
 | 
			
		||||
		until checknode.name=="air"
 | 
			
		||||
		or checknode.name=="ignore" 
 | 
			
		||||
		or string.find(checknode.name, "_source")
 | 
			
		||||
		or string.find(checknode.name, "_flowing")
 | 
			
		||||
		minetest.env:remove_node(pos)
 | 
			
		||||
		nodeupdate(pos)
 | 
			
		||||
		minetest.env:add_entity(pos, "mesecons_movestones:movestone_entity")
 | 
			
		||||
	end
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
-- STICKY_MOVESTONE
 | 
			
		||||
 | 
			
		||||
minetest.register_node("mesecons_movestones:sticky_movestone", {
 | 
			
		||||
	tiles = {"jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_sticky_movestone.png", "jeija_sticky_movestone.png"},
 | 
			
		||||
	inventory_image = minetest.inventorycube("jeija_sticky_movestone.png", "jeija_movestone_side.png", "jeija_movestone_side.png"),
 | 
			
		||||
	paramtype2 = "facedir",
 | 
			
		||||
	legacy_facedir_simple = true,
 | 
			
		||||
	groups = {cracky=3},
 | 
			
		||||
    	description="Sticky Movestone",
 | 
			
		||||
})
 | 
			
		||||
mesecon:register_effector("mesecons_movestones:sticky_movestone", "mesecons_movestones:sticky_movestone")
 | 
			
		||||
 | 
			
		||||
minetest.register_craft({
 | 
			
		||||
	output = '"mesecons_movestones:sticky_movestone" 2',
 | 
			
		||||
	recipe = {
 | 
			
		||||
		{'"mesecons_materials:glue"', '"mesecons_movestones:movestone"', '"mesecons_materials:glue"'},
 | 
			
		||||
	}
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
minetest.register_entity("mesecons_movestones:sticky_movestone_entity", {
 | 
			
		||||
	physical = false,
 | 
			
		||||
	visual = "sprite",
 | 
			
		||||
	textures = {"jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_sticky_movestone.png", "jeija_sticky_movestone.png"},
 | 
			
		||||
	collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
 | 
			
		||||
	visual = "cube",
 | 
			
		||||
 | 
			
		||||
	on_punch = function(self, hitter)
 | 
			
		||||
		self.object:remove()
 | 
			
		||||
		hitter:get_inventory():add_item("main", 'mesecons_movestones:sticky_movestone')
 | 
			
		||||
	end,
 | 
			
		||||
 | 
			
		||||
	on_step = function(self, dtime)
 | 
			
		||||
		local pos = self.object:getpos()
 | 
			
		||||
		local colp = pos
 | 
			
		||||
		local direction=mesecon:get_movestone_direction(colp)
 | 
			
		||||
 | 
			
		||||
		if not direction then
 | 
			
		||||
		--or (minetest.env:get_node_or_nil(pos).name ~="air" 
 | 
			
		||||
		--and minetest.env:get_node_or_nil(pos).name ~= nil) then
 | 
			
		||||
			minetest.env:add_node(pos, {name="mesecons_movestones:sticky_movestone"})
 | 
			
		||||
			self.object:remove()
 | 
			
		||||
			return
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		self.object:setvelocity({x=direction.x*3, y=direction.y*3, z=direction.z*3})
 | 
			
		||||
 | 
			
		||||
		mesecon:mvps_push(pos, direction)
 | 
			
		||||
 | 
			
		||||
		--STICKY
 | 
			
		||||
		mesecon:mvps_pull_all(pos, direction)
 | 
			
		||||
	end
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
mesecon:register_on_signal_on(function (pos, node)
 | 
			
		||||
	if node.name=="mesecons_movestones:sticky_movestone" then
 | 
			
		||||
		local direction=mesecon:get_movestone_direction(pos)
 | 
			
		||||
		if not direction then return end
 | 
			
		||||
		local checknode={}
 | 
			
		||||
		local collpos={x=pos.x, y=pos.y, z=pos.z}
 | 
			
		||||
		repeat -- Check if it collides with a stopper
 | 
			
		||||
			collpos={x=collpos.x+direction.x, y=collpos.y+direction.y, z=collpos.z+direction.z}
 | 
			
		||||
			checknode=minetest.env:get_node(collpos)
 | 
			
		||||
			if mesecon:is_mvps_stopper(checknode.name) then 
 | 
			
		||||
				return 
 | 
			
		||||
			end
 | 
			
		||||
		until checknode.name=="air"
 | 
			
		||||
		or checknode.name=="ignore" 
 | 
			
		||||
		or string.find(checknode.name, "_source")
 | 
			
		||||
		or string.find(checknode.name, "_flowing")
 | 
			
		||||
		repeat -- Check if it collides with a stopper (pull direction)
 | 
			
		||||
			collpos={x=collpos.x-direction.x, y=collpos.y-direction.y, z=collpos.z-direction.z}
 | 
			
		||||
			checknode=minetest.env:get_node(collpos)
 | 
			
		||||
			if mesecon:is_mvps_stopper(checknode.name) then
 | 
			
		||||
				return 
 | 
			
		||||
			end
 | 
			
		||||
		until checknode.name=="air"
 | 
			
		||||
		or checknode.name=="ignore" 
 | 
			
		||||
		or string.find(checknode.name, "_source") 
 | 
			
		||||
		or string.find(checknode.name, "_flowing")
 | 
			
		||||
 | 
			
		||||
		minetest.env:remove_node(pos)
 | 
			
		||||
		nodeupdate(pos)
 | 
			
		||||
		minetest.env:add_entity(pos, "mesecons_movestones:sticky_movestone_entity")
 | 
			
		||||
	end
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
mesecon:add_rules("movestone", {
 | 
			
		||||
{x=0,  y=1,  z=-1},
 | 
			
		||||
{x=0,  y=0,  z=-1},
 | 
			
		||||
{x=0,  y=-1, z=-1},
 | 
			
		||||
{x=0,  y=1,  z=1},
 | 
			
		||||
{x=0,  y=-1, z=1},
 | 
			
		||||
{x=0,  y=0,  z=1},
 | 
			
		||||
{x=1,  y=0,  z=0},
 | 
			
		||||
{x=1,  y=1,  z=0},
 | 
			
		||||
{x=1,  y=-1, z=0},
 | 
			
		||||
{x=-1, y=1,  z=0},
 | 
			
		||||
{x=-1, y=-1, z=0},
 | 
			
		||||
{x=-1, y=0,  z=0}})
 | 
			
		||||
 
 | 
			
		||||
@@ -1,67 +1,67 @@
 | 
			
		||||
--register stoppers for movestones/pistons
 | 
			
		||||
 | 
			
		||||
mesecon.mvps_stoppers={}
 | 
			
		||||
 | 
			
		||||
function mesecon:is_mvps_stopper(nodename)
 | 
			
		||||
	local i=1
 | 
			
		||||
	repeat
 | 
			
		||||
		i=i+1
 | 
			
		||||
		if mesecon.mvps_stoppers[i]==nodename then return true end
 | 
			
		||||
	until mesecon.mvps_stoppers[i]==nil
 | 
			
		||||
	return false
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function mesecon:register_mvps_stopper(nodename)
 | 
			
		||||
	local i=1
 | 
			
		||||
	repeat
 | 
			
		||||
		i=i+1
 | 
			
		||||
		if mesecon.mvps_stoppers[i]==nil then break end
 | 
			
		||||
	until false
 | 
			
		||||
	mesecon.mvps_stoppers[i]=nodename
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function mesecon:mvps_push(pos, direction) -- pos: pos of mvps; direction: direction of push
 | 
			
		||||
		pos.x=pos.x+direction.x
 | 
			
		||||
		pos.y=pos.y+direction.y
 | 
			
		||||
		pos.z=pos.z+direction.z
 | 
			
		||||
 | 
			
		||||
		local lpos = {x=pos.x, y=pos.y, z=pos.z}
 | 
			
		||||
		local lnode = minetest.env:get_node(lpos)
 | 
			
		||||
		local newnode
 | 
			
		||||
		minetest.env:remove_node(lpos)
 | 
			
		||||
		while not(lnode.name == "ignore" or lnode.name == "air" or lnode.name == "default:water" or lnode.name == "default:water_flowing") do
 | 
			
		||||
			lpos.x=lpos.x+direction.x
 | 
			
		||||
			lpos.y=lpos.y+direction.y
 | 
			
		||||
			lpos.z=lpos.z+direction.z
 | 
			
		||||
			newnode = lnode
 | 
			
		||||
			lnode = minetest.env:get_node(lpos)
 | 
			
		||||
			minetest.env:add_node(lpos, newnode)
 | 
			
		||||
			nodeupdate(lpos)
 | 
			
		||||
		end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function mesecon:mvps_pull_all(pos, direction) -- pos: pos of mvps; direction: direction of pull
 | 
			
		||||
		local lpos = {x=pos.x-direction.x, y=pos.y-direction.y, z=pos.z-direction.z} -- 1 away
 | 
			
		||||
		local lnode = minetest.env:get_node(lpos)
 | 
			
		||||
		local lpos2 = {x=pos.x-direction.x*2, y=pos.y-direction.y*2, z=pos.z-direction.z*2} -- 2 away
 | 
			
		||||
		local lnode2 = minetest.env:get_node(lpos2)
 | 
			
		||||
 | 
			
		||||
		if lnode.name ~= "ignore" and lnode.name ~= "air" and lnode.name ~= "default:water" and lnode.name ~= "default:water_flowing" then return end
 | 
			
		||||
		if lnode2.name == "ignore" or lnode2.name == "air" or lnode2.name == "default:water" or lnode2.name == "default:water_flowing" then return end
 | 
			
		||||
 | 
			
		||||
		local oldpos = {x=lpos2.x+direction.x, y=lpos2.y+direction.y, z=lpos2.z+direction.z}
 | 
			
		||||
		repeat
 | 
			
		||||
			minetest.env:add_node(oldpos, {name=minetest.env:get_node(lpos2).name})
 | 
			
		||||
			nodeupdate(oldpos)
 | 
			
		||||
			oldpos = {x=lpos2.x, y=lpos2.y, z=lpos2.z}
 | 
			
		||||
			lpos2.x = lpos2.x-direction.x
 | 
			
		||||
			lpos2.y = lpos2.y-direction.y
 | 
			
		||||
			lpos2.z = lpos2.z-direction.z
 | 
			
		||||
			lnode = minetest.env:get_node(lpos2)
 | 
			
		||||
		until lnode.name=="air" or lnode.name=="ignore" or lnode.name=="default:water" or lnode.name=="default:water_flowing"
 | 
			
		||||
		minetest.env:remove_node(oldpos)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
mesecon:register_mvps_stopper("default:chest")
 | 
			
		||||
mesecon:register_mvps_stopper("default:chest_locked")
 | 
			
		||||
mesecon:register_mvps_stopper("default:furnace")
 | 
			
		||||
--register stoppers for movestones/pistons
 | 
			
		||||
 | 
			
		||||
mesecon.mvps_stoppers={}
 | 
			
		||||
 | 
			
		||||
function mesecon:is_mvps_stopper(nodename)
 | 
			
		||||
	local i=1
 | 
			
		||||
	repeat
 | 
			
		||||
		i=i+1
 | 
			
		||||
		if mesecon.mvps_stoppers[i]==nodename then return true end
 | 
			
		||||
	until mesecon.mvps_stoppers[i]==nil
 | 
			
		||||
	return false
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function mesecon:register_mvps_stopper(nodename)
 | 
			
		||||
	local i=1
 | 
			
		||||
	repeat
 | 
			
		||||
		i=i+1
 | 
			
		||||
		if mesecon.mvps_stoppers[i]==nil then break end
 | 
			
		||||
	until false
 | 
			
		||||
	mesecon.mvps_stoppers[i]=nodename
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function mesecon:mvps_push(pos, direction) -- pos: pos of mvps; direction: direction of push
 | 
			
		||||
		pos.x=pos.x+direction.x
 | 
			
		||||
		pos.y=pos.y+direction.y
 | 
			
		||||
		pos.z=pos.z+direction.z
 | 
			
		||||
 | 
			
		||||
		local lpos = {x=pos.x, y=pos.y, z=pos.z}
 | 
			
		||||
		local lnode = minetest.env:get_node(lpos)
 | 
			
		||||
		local newnode
 | 
			
		||||
		minetest.env:remove_node(lpos)
 | 
			
		||||
		while not(lnode.name == "ignore" or lnode.name == "air" or string.find(lnode.name, "_source") or string.find(lnode.name, "_flowing") do
 | 
			
		||||
			lpos.x=lpos.x+direction.x
 | 
			
		||||
			lpos.y=lpos.y+direction.y
 | 
			
		||||
			lpos.z=lpos.z+direction.z
 | 
			
		||||
			newnode = lnode
 | 
			
		||||
			lnode = minetest.env:get_node(lpos)
 | 
			
		||||
			minetest.env:add_node(lpos, newnode)
 | 
			
		||||
			nodeupdate(lpos)
 | 
			
		||||
		end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function mesecon:mvps_pull_all(pos, direction) -- pos: pos of mvps; direction: direction of pull
 | 
			
		||||
		local lpos = {x=pos.x-direction.x, y=pos.y-direction.y, z=pos.z-direction.z} -- 1 away
 | 
			
		||||
		local lnode = minetest.env:get_node(lpos)
 | 
			
		||||
		local lpos2 = {x=pos.x-direction.x*2, y=pos.y-direction.y*2, z=pos.z-direction.z*2} -- 2 away
 | 
			
		||||
		local lnode2 = minetest.env:get_node(lpos2)
 | 
			
		||||
 | 
			
		||||
		if lnode.name ~= "ignore" and lnode.name ~= "air" and not(string.find(lnode.name, "_flowing")) and not(string.find(lnode.name, "_source")) then return end
 | 
			
		||||
		if lnode2.name == "ignore" or lnode2.name == "air" or string.find(lnode2.name, "_source") or string.find(lnode.name, "_flowing") then return end
 | 
			
		||||
 | 
			
		||||
		local oldpos = {x=lpos2.x+direction.x, y=lpos2.y+direction.y, z=lpos2.z+direction.z}
 | 
			
		||||
		repeat
 | 
			
		||||
			minetest.env:add_node(oldpos, {name=minetest.env:get_node(lpos2).name})
 | 
			
		||||
			nodeupdate(oldpos)
 | 
			
		||||
			oldpos = {x=lpos2.x, y=lpos2.y, z=lpos2.z}
 | 
			
		||||
			lpos2.x = lpos2.x-direction.x
 | 
			
		||||
			lpos2.y = lpos2.y-direction.y
 | 
			
		||||
			lpos2.z = lpos2.z-direction.z
 | 
			
		||||
			lnode = minetest.env:get_node(lpos2)
 | 
			
		||||
		until lnode.name=="air" or lnode.name=="ignore" or string.find(lnode.name, "_source") or string.find(lnode.name, "_flowing")
 | 
			
		||||
		minetest.env:remove_node(oldpos)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
mesecon:register_mvps_stopper("default:chest")
 | 
			
		||||
mesecon:register_mvps_stopper("default:chest_locked")
 | 
			
		||||
mesecon:register_mvps_stopper("default:furnace")
 | 
			
		||||
 
 | 
			
		||||
@@ -1,235 +1,231 @@
 | 
			
		||||
--PISTONS
 | 
			
		||||
--registration normal one:
 | 
			
		||||
minetest.register_node("mesecons_pistons:piston_normal", {
 | 
			
		||||
	description = "Piston",
 | 
			
		||||
	tiles = {"jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_side.png"},
 | 
			
		||||
	groups = {cracky=3, mesecon = 2},
 | 
			
		||||
	paramtype2 = "facedir",
 | 
			
		||||
	after_dig_node = function(pos, oldnode)
 | 
			
		||||
		local dir = mesecon:piston_get_direction(oldnode)
 | 
			
		||||
		pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node to check
 | 
			
		||||
 | 
			
		||||
		--ensure piston is extended
 | 
			
		||||
		local checknode = minetest.env:get_node(pos)
 | 
			
		||||
		if checknode.name == "mesecons_pistons:piston_pusher_normal" then
 | 
			
		||||
			if checknode.param2 == oldnode.param2 then --pusher is facing the same direction as the piston
 | 
			
		||||
				minetest.env:remove_node(pos) --remove the pusher
 | 
			
		||||
			end
 | 
			
		||||
		end
 | 
			
		||||
	end,
 | 
			
		||||
})
 | 
			
		||||
mesecon:register_effector("mesecons_pistons:piston_normal", "mesecons_pistons:piston_normal")
 | 
			
		||||
 | 
			
		||||
--registration sticky one:
 | 
			
		||||
minetest.register_node("mesecons_pistons:piston_sticky", {
 | 
			
		||||
	description = "Sticky Piston",
 | 
			
		||||
	tiles = {"jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_sticky_side.png"},
 | 
			
		||||
	groups = {cracky=3, mesecon = 2},
 | 
			
		||||
	paramtype2 = "facedir",
 | 
			
		||||
	after_dig_node = function(pos, oldnode)
 | 
			
		||||
		local dir = mesecon:piston_get_direction(oldnode)
 | 
			
		||||
		pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node to check
 | 
			
		||||
 | 
			
		||||
		--ensure piston is extended
 | 
			
		||||
		local checknode = minetest.env:get_node(pos)
 | 
			
		||||
		if checknode.name == "mesecons_pistons:piston_pusher_sticky" then
 | 
			
		||||
			if checknode.param2 == oldnode.param2 then --pusher is facing the same direction as the piston
 | 
			
		||||
				minetest.env:remove_node(pos) --remove the pusher
 | 
			
		||||
			end
 | 
			
		||||
		end
 | 
			
		||||
	end,
 | 
			
		||||
})
 | 
			
		||||
mesecon:register_effector("mesecons_pistons:piston_sticky", "mesecons_pistons:piston_sticky")
 | 
			
		||||
 | 
			
		||||
minetest.register_craft({
 | 
			
		||||
	output = '"mesecons_pistons:piston_normal" 2',
 | 
			
		||||
	recipe = {
 | 
			
		||||
		{"default:wood", "default:wood", "default:wood"},
 | 
			
		||||
		{"default:cobble", "default:steel_ingot", "default:cobble"},
 | 
			
		||||
		{"default:cobble", "group:mesecon_conductor_craftable", "default:cobble"},
 | 
			
		||||
	}
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
minetest.register_craft({
 | 
			
		||||
	output = "mesecons_pistons:piston_sticky",
 | 
			
		||||
	recipe = {
 | 
			
		||||
		{"mesecons_materials:glue"},
 | 
			
		||||
		{"mesecons_pistons:piston_normal"},
 | 
			
		||||
	}
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
minetest.register_node("mesecons_pistons:piston_pusher_normal", {
 | 
			
		||||
	drawtype = "nodebox",
 | 
			
		||||
	tiles = {"jeija_piston_pusher_normal.png"},
 | 
			
		||||
	paramtype = "light",
 | 
			
		||||
	paramtype2 = "facedir",
 | 
			
		||||
	diggable = false,
 | 
			
		||||
	selection_box = {
 | 
			
		||||
		type = "fixed",
 | 
			
		||||
		fixed = {
 | 
			
		||||
			{-0.2, -0.2, -0.3, 0.2, 0.2, 0.5},
 | 
			
		||||
			{-0.5, -0.5, -0.5, 0.5, 0.5, -0.3},
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
	node_box = {
 | 
			
		||||
		type = "fixed",
 | 
			
		||||
		fixed = {
 | 
			
		||||
			{-0.2, -0.2, -0.3, 0.2, 0.2, 0.5},
 | 
			
		||||
			{-0.5, -0.5, -0.5, 0.5, 0.5, -0.3},
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
mesecon:register_mvps_stopper("mesecons_pistons:piston_pusher_normal")
 | 
			
		||||
mesecon:register_mvps_stopper("mesecons_pistons:piston_pusher_sticky")
 | 
			
		||||
 | 
			
		||||
minetest.register_node("mesecons_pistons:piston_pusher_sticky", {
 | 
			
		||||
	drawtype = "nodebox",
 | 
			
		||||
	tiles = {
 | 
			
		||||
		"jeija_piston_pusher_normal.png",
 | 
			
		||||
		"jeija_piston_pusher_normal.png",
 | 
			
		||||
		"jeija_piston_pusher_normal.png",
 | 
			
		||||
		"jeija_piston_pusher_normal.png",
 | 
			
		||||
		"jeija_piston_pusher_normal.png",
 | 
			
		||||
		"jeija_piston_pusher_sticky.png"
 | 
			
		||||
		},
 | 
			
		||||
	paramtype = "light",
 | 
			
		||||
	paramtype2 = "facedir",
 | 
			
		||||
	diggable = false,
 | 
			
		||||
	selection_box = {
 | 
			
		||||
		type = "fixed",
 | 
			
		||||
		fixed = {
 | 
			
		||||
			{-0.2, -0.2, -0.3, 0.2, 0.2, 0.5},
 | 
			
		||||
			{-0.5, -0.5, -0.5, 0.5, 0.5, -0.3},
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
	node_box = {
 | 
			
		||||
		type = "fixed",
 | 
			
		||||
		fixed = {
 | 
			
		||||
			{-0.2, -0.2, -0.3, 0.2, 0.2, 0.5},
 | 
			
		||||
			{-0.5, -0.5, -0.5, 0.5, 0.5, -0.3},
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
-- Push action
 | 
			
		||||
mesecon:register_on_signal_on(function(pos, node)
 | 
			
		||||
	if node.name ~= "mesecons_pistons:piston_normal" and node.name ~= "mesecons_pistons:piston_sticky" then
 | 
			
		||||
		return
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	local dir = mesecon:piston_get_direction(node)
 | 
			
		||||
	pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node being pushed
 | 
			
		||||
 | 
			
		||||
	--determine the number of nodes that need to be pushed
 | 
			
		||||
	local count = 0
 | 
			
		||||
	local checkpos = {x=pos.x, y=pos.y, z=pos.z} --first node being pushed
 | 
			
		||||
	while true do
 | 
			
		||||
		local checknode = minetest.env:get_node(checkpos)
 | 
			
		||||
 | 
			
		||||
		--check for collision with stopper
 | 
			
		||||
		if mesecon:is_mvps_stopper(checknode.name) then 
 | 
			
		||||
			return
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		--check for column end
 | 
			
		||||
		if checknode.name == "air"
 | 
			
		||||
		or checknode.name == "ignore"
 | 
			
		||||
		or checknode.name == "default:water_source"
 | 
			
		||||
		or checknode.name == "default:water_flowing"
 | 
			
		||||
		or checknode.name == "default:lava_source"
 | 
			
		||||
		or checknode.name == "default:lava_flowing" then
 | 
			
		||||
			break
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		--limit piston pushing capacity
 | 
			
		||||
		count = count + 1
 | 
			
		||||
		if count > 15 then
 | 
			
		||||
			return
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		checkpos.x, checkpos.y, checkpos.z = checkpos.x + dir.x, checkpos.y + dir.y, checkpos.z + dir.z
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	local checknode = minetest.env:get_node(pos)
 | 
			
		||||
	minetest.env:remove_node(pos) --remove the first node
 | 
			
		||||
	mesecon:updatenode(pos)
 | 
			
		||||
 | 
			
		||||
	--add pusher
 | 
			
		||||
	if node.name == "mesecons_pistons:piston_normal" then
 | 
			
		||||
		minetest.env:add_node(pos, {name="mesecons_pistons:piston_pusher_normal", param2=node.param2})
 | 
			
		||||
	else
 | 
			
		||||
		minetest.env:add_node(pos, {name="mesecons_pistons:piston_pusher_sticky", param2=node.param2})
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	--move nodes forward
 | 
			
		||||
	for i = 1, count do
 | 
			
		||||
		pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to the next node
 | 
			
		||||
 | 
			
		||||
		--move the node forward
 | 
			
		||||
		local nextnode = minetest.env:get_node(pos)
 | 
			
		||||
		--minetest.env:dig_node(pos)
 | 
			
		||||
		minetest.env:set_node(pos, checknode)
 | 
			
		||||
		mesecon:updatenode(pos)
 | 
			
		||||
		checknode = nextnode
 | 
			
		||||
	end
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
--Pull action
 | 
			
		||||
mesecon:register_on_signal_off(function(pos, node)
 | 
			
		||||
	if node.name ~= "mesecons_pistons:piston_normal" and node.name ~= "mesecons_pistons:piston_sticky" then
 | 
			
		||||
		return
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	local dir = mesecon:piston_get_direction(node)
 | 
			
		||||
	pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to the node to be replaced
 | 
			
		||||
 | 
			
		||||
	--ensure piston is extended
 | 
			
		||||
	local checknode = minetest.env:get_node(pos)
 | 
			
		||||
	if checknode.name ~= "mesecons_pistons:piston_pusher_normal" and checknode.name ~= "mesecons_pistons:piston_pusher_sticky" then
 | 
			
		||||
		return
 | 
			
		||||
	end
 | 
			
		||||
	if checknode.param2 ~= node.param2 then --pusher is not facing the same direction as the piston
 | 
			
		||||
		return --piston is not extended
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	--retract piston
 | 
			
		||||
	minetest.env:remove_node(pos) --remove pusher
 | 
			
		||||
	if node.name ~= "mesecons_pistons:piston_sticky" then
 | 
			
		||||
	    nodeupdate(pos)
 | 
			
		||||
	end
 | 
			
		||||
	if node.name == "mesecons_pistons:piston_sticky" then --retract block
 | 
			
		||||
		local checkpos = {x=pos.x + dir.x, y=pos.y + dir.y, z=pos.z + dir.z} --move to the node to be retracted
 | 
			
		||||
		checknode = minetest.env:get_node(checkpos)
 | 
			
		||||
		if checknode.name ~= "air"
 | 
			
		||||
		and checknode.name ~= "ignore"
 | 
			
		||||
		and checknode.name ~= "default:water_source"
 | 
			
		||||
		and checknode.name ~= "default:water_flowing"
 | 
			
		||||
		and checknode.name ~= "default:lava_source"
 | 
			
		||||
		and checknode.name ~= "default:lava_flowing"
 | 
			
		||||
		and not mesecon:is_mvps_stopper(checknode.name) then
 | 
			
		||||
		    minetest.env:set_node(pos, checknode)
 | 
			
		||||
		    minetest.env:remove_node(checkpos)
 | 
			
		||||
		    mesecon:updatenode(checkpos)
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
	if node.name == "mesecons_pistons:piston_sticky" then
 | 
			
		||||
	    nodeupdate(pos)
 | 
			
		||||
	end
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
-- get push direction
 | 
			
		||||
function mesecon:piston_get_direction(node)
 | 
			
		||||
	if node.param2 == 3 then
 | 
			
		||||
		return {x=1, y=0, z=0}
 | 
			
		||||
	elseif node.param2 == 2 then
 | 
			
		||||
		return {x=0, y=0, z=1}
 | 
			
		||||
	elseif node.param2 == 1 then
 | 
			
		||||
		return {x=-1, y=0, z=0}
 | 
			
		||||
	else --node.param2 == 0
 | 
			
		||||
		return {x=0, y=0, z=-1}
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
dofile(minetest.get_modpath("mesecons_pistons").."/pistons_down.lua")
 | 
			
		||||
dofile(minetest.get_modpath("mesecons_pistons").."/pistons_up.lua")
 | 
			
		||||
--PISTONS
 | 
			
		||||
--registration normal one:
 | 
			
		||||
minetest.register_node("mesecons_pistons:piston_normal", {
 | 
			
		||||
	description = "Piston",
 | 
			
		||||
	tiles = {"jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_side.png"},
 | 
			
		||||
	groups = {cracky=3, mesecon = 2},
 | 
			
		||||
	paramtype2 = "facedir",
 | 
			
		||||
	after_dig_node = function(pos, oldnode)
 | 
			
		||||
		local dir = mesecon:piston_get_direction(oldnode)
 | 
			
		||||
		pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node to check
 | 
			
		||||
 | 
			
		||||
		--ensure piston is extended
 | 
			
		||||
		local checknode = minetest.env:get_node(pos)
 | 
			
		||||
		if checknode.name == "mesecons_pistons:piston_pusher_normal" then
 | 
			
		||||
			if checknode.param2 == oldnode.param2 then --pusher is facing the same direction as the piston
 | 
			
		||||
				minetest.env:remove_node(pos) --remove the pusher
 | 
			
		||||
			end
 | 
			
		||||
		end
 | 
			
		||||
	end,
 | 
			
		||||
})
 | 
			
		||||
mesecon:register_effector("mesecons_pistons:piston_normal", "mesecons_pistons:piston_normal")
 | 
			
		||||
 | 
			
		||||
--registration sticky one:
 | 
			
		||||
minetest.register_node("mesecons_pistons:piston_sticky", {
 | 
			
		||||
	description = "Sticky Piston",
 | 
			
		||||
	tiles = {"jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_sticky_side.png"},
 | 
			
		||||
	groups = {cracky=3, mesecon = 2},
 | 
			
		||||
	paramtype2 = "facedir",
 | 
			
		||||
	after_dig_node = function(pos, oldnode)
 | 
			
		||||
		local dir = mesecon:piston_get_direction(oldnode)
 | 
			
		||||
		pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node to check
 | 
			
		||||
 | 
			
		||||
		--ensure piston is extended
 | 
			
		||||
		local checknode = minetest.env:get_node(pos)
 | 
			
		||||
		if checknode.name == "mesecons_pistons:piston_pusher_sticky" then
 | 
			
		||||
			if checknode.param2 == oldnode.param2 then --pusher is facing the same direction as the piston
 | 
			
		||||
				minetest.env:remove_node(pos) --remove the pusher
 | 
			
		||||
			end
 | 
			
		||||
		end
 | 
			
		||||
	end,
 | 
			
		||||
})
 | 
			
		||||
mesecon:register_effector("mesecons_pistons:piston_sticky", "mesecons_pistons:piston_sticky")
 | 
			
		||||
 | 
			
		||||
minetest.register_craft({
 | 
			
		||||
	output = '"mesecons_pistons:piston_normal" 2',
 | 
			
		||||
	recipe = {
 | 
			
		||||
		{"default:wood", "default:wood", "default:wood"},
 | 
			
		||||
		{"default:cobble", "default:steel_ingot", "default:cobble"},
 | 
			
		||||
		{"default:cobble", "group:mesecon_conductor_craftable", "default:cobble"},
 | 
			
		||||
	}
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
minetest.register_craft({
 | 
			
		||||
	output = "mesecons_pistons:piston_sticky",
 | 
			
		||||
	recipe = {
 | 
			
		||||
		{"mesecons_materials:glue"},
 | 
			
		||||
		{"mesecons_pistons:piston_normal"},
 | 
			
		||||
	}
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
minetest.register_node("mesecons_pistons:piston_pusher_normal", {
 | 
			
		||||
	drawtype = "nodebox",
 | 
			
		||||
	tiles = {"jeija_piston_pusher_normal.png"},
 | 
			
		||||
	paramtype = "light",
 | 
			
		||||
	paramtype2 = "facedir",
 | 
			
		||||
	diggable = false,
 | 
			
		||||
	selection_box = {
 | 
			
		||||
		type = "fixed",
 | 
			
		||||
		fixed = {
 | 
			
		||||
			{-0.2, -0.2, -0.3, 0.2, 0.2, 0.5},
 | 
			
		||||
			{-0.5, -0.5, -0.5, 0.5, 0.5, -0.3},
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
	node_box = {
 | 
			
		||||
		type = "fixed",
 | 
			
		||||
		fixed = {
 | 
			
		||||
			{-0.2, -0.2, -0.3, 0.2, 0.2, 0.5},
 | 
			
		||||
			{-0.5, -0.5, -0.5, 0.5, 0.5, -0.3},
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
mesecon:register_mvps_stopper("mesecons_pistons:piston_pusher_normal")
 | 
			
		||||
mesecon:register_mvps_stopper("mesecons_pistons:piston_pusher_sticky")
 | 
			
		||||
 | 
			
		||||
minetest.register_node("mesecons_pistons:piston_pusher_sticky", {
 | 
			
		||||
	drawtype = "nodebox",
 | 
			
		||||
	tiles = {
 | 
			
		||||
		"jeija_piston_pusher_normal.png",
 | 
			
		||||
		"jeija_piston_pusher_normal.png",
 | 
			
		||||
		"jeija_piston_pusher_normal.png",
 | 
			
		||||
		"jeija_piston_pusher_normal.png",
 | 
			
		||||
		"jeija_piston_pusher_normal.png",
 | 
			
		||||
		"jeija_piston_pusher_sticky.png"
 | 
			
		||||
		},
 | 
			
		||||
	paramtype = "light",
 | 
			
		||||
	paramtype2 = "facedir",
 | 
			
		||||
	diggable = false,
 | 
			
		||||
	selection_box = {
 | 
			
		||||
		type = "fixed",
 | 
			
		||||
		fixed = {
 | 
			
		||||
			{-0.2, -0.2, -0.3, 0.2, 0.2, 0.5},
 | 
			
		||||
			{-0.5, -0.5, -0.5, 0.5, 0.5, -0.3},
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
	node_box = {
 | 
			
		||||
		type = "fixed",
 | 
			
		||||
		fixed = {
 | 
			
		||||
			{-0.2, -0.2, -0.3, 0.2, 0.2, 0.5},
 | 
			
		||||
			{-0.5, -0.5, -0.5, 0.5, 0.5, -0.3},
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
-- Push action
 | 
			
		||||
mesecon:register_on_signal_on(function(pos, node)
 | 
			
		||||
	if node.name ~= "mesecons_pistons:piston_normal" and node.name ~= "mesecons_pistons:piston_sticky" then
 | 
			
		||||
		return
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	local dir = mesecon:piston_get_direction(node)
 | 
			
		||||
	pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node being pushed
 | 
			
		||||
 | 
			
		||||
	--determine the number of nodes that need to be pushed
 | 
			
		||||
	local count = 0
 | 
			
		||||
	local checkpos = {x=pos.x, y=pos.y, z=pos.z} --first node being pushed
 | 
			
		||||
	while true do
 | 
			
		||||
		local checknode = minetest.env:get_node(checkpos)
 | 
			
		||||
 | 
			
		||||
		--check for collision with stopper
 | 
			
		||||
		if mesecon:is_mvps_stopper(checknode.name) then 
 | 
			
		||||
			return
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		--check for column end
 | 
			
		||||
		if checknode.name == "air"
 | 
			
		||||
		or checknode.name == "ignore"
 | 
			
		||||
		or string.find(checknode.name, "_source")
 | 
			
		||||
		or string.find(checknode.name, "_flowing") then
 | 
			
		||||
			break
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		--limit piston pushing capacity
 | 
			
		||||
		count = count + 1
 | 
			
		||||
		if count > 15 then
 | 
			
		||||
			return
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		checkpos.x, checkpos.y, checkpos.z = checkpos.x + dir.x, checkpos.y + dir.y, checkpos.z + dir.z
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	local checknode = minetest.env:get_node(pos)
 | 
			
		||||
	minetest.env:remove_node(pos) --remove the first node
 | 
			
		||||
	mesecon:updatenode(pos)
 | 
			
		||||
 | 
			
		||||
	--add pusher
 | 
			
		||||
	if node.name == "mesecons_pistons:piston_normal" then
 | 
			
		||||
		minetest.env:add_node(pos, {name="mesecons_pistons:piston_pusher_normal", param2=node.param2})
 | 
			
		||||
	else
 | 
			
		||||
		minetest.env:add_node(pos, {name="mesecons_pistons:piston_pusher_sticky", param2=node.param2})
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	--move nodes forward
 | 
			
		||||
	for i = 1, count do
 | 
			
		||||
		pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to the next node
 | 
			
		||||
 | 
			
		||||
		--move the node forward
 | 
			
		||||
		local nextnode = minetest.env:get_node(pos)
 | 
			
		||||
		--minetest.env:dig_node(pos)
 | 
			
		||||
		minetest.env:set_node(pos, checknode)
 | 
			
		||||
		mesecon:updatenode(pos)
 | 
			
		||||
		checknode = nextnode
 | 
			
		||||
	end
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
--Pull action
 | 
			
		||||
mesecon:register_on_signal_off(function(pos, node)
 | 
			
		||||
	if node.name ~= "mesecons_pistons:piston_normal" and node.name ~= "mesecons_pistons:piston_sticky" then
 | 
			
		||||
		return
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	local dir = mesecon:piston_get_direction(node)
 | 
			
		||||
	pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to the node to be replaced
 | 
			
		||||
 | 
			
		||||
	--ensure piston is extended
 | 
			
		||||
	local checknode = minetest.env:get_node(pos)
 | 
			
		||||
	if checknode.name ~= "mesecons_pistons:piston_pusher_normal" and checknode.name ~= "mesecons_pistons:piston_pusher_sticky" then
 | 
			
		||||
		return
 | 
			
		||||
	end
 | 
			
		||||
	if checknode.param2 ~= node.param2 then --pusher is not facing the same direction as the piston
 | 
			
		||||
		return --piston is not extended
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	--retract piston
 | 
			
		||||
	minetest.env:remove_node(pos) --remove pusher
 | 
			
		||||
	if node.name ~= "mesecons_pistons:piston_sticky" then
 | 
			
		||||
	    nodeupdate(pos)
 | 
			
		||||
	end
 | 
			
		||||
	if node.name == "mesecons_pistons:piston_sticky" then --retract block
 | 
			
		||||
		local checkpos = {x=pos.x + dir.x, y=pos.y + dir.y, z=pos.z + dir.z} --move to the node to be retracted
 | 
			
		||||
		checknode = minetest.env:get_node(checkpos)
 | 
			
		||||
		if checknode.name ~= "air"
 | 
			
		||||
		and checknode.name ~= "ignore"
 | 
			
		||||
		and string.find(checknode.name, "_source")
 | 
			
		||||
		and string.find(checknode.name, "_flowing")
 | 
			
		||||
		and not mesecon:is_mvps_stopper(checknode.name) then
 | 
			
		||||
		    minetest.env:set_node(pos, checknode)
 | 
			
		||||
		    minetest.env:remove_node(checkpos)
 | 
			
		||||
		    mesecon:updatenode(checkpos)
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
	if node.name == "mesecons_pistons:piston_sticky" then
 | 
			
		||||
	    nodeupdate(pos)
 | 
			
		||||
	end
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
-- get push direction
 | 
			
		||||
function mesecon:piston_get_direction(node)
 | 
			
		||||
	if node.param2 == 3 then
 | 
			
		||||
		return {x=1, y=0, z=0}
 | 
			
		||||
	elseif node.param2 == 2 then
 | 
			
		||||
		return {x=0, y=0, z=1}
 | 
			
		||||
	elseif node.param2 == 1 then
 | 
			
		||||
		return {x=-1, y=0, z=0}
 | 
			
		||||
	else --node.param2 == 0
 | 
			
		||||
		return {x=0, y=0, z=-1}
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
dofile(minetest.get_modpath("mesecons_pistons").."/pistons_down.lua")
 | 
			
		||||
dofile(minetest.get_modpath("mesecons_pistons").."/pistons_up.lua")
 | 
			
		||||
 
 | 
			
		||||
@@ -1,226 +1,222 @@
 | 
			
		||||
--PISTONS
 | 
			
		||||
--registration normal one:
 | 
			
		||||
minetest.register_node("mesecons_pistons:piston_down_normal", {
 | 
			
		||||
	description = "Piston DOWN",
 | 
			
		||||
	tiles = {"jeija_piston_tb.png", "jeija_piston_side.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png"},
 | 
			
		||||
	groups = {cracky=3, mesecon = 2},
 | 
			
		||||
	after_dig_node = function(pos, oldnode)
 | 
			
		||||
		local dir = {x=0, y=-1, z=0}
 | 
			
		||||
		pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node to check
 | 
			
		||||
 | 
			
		||||
		--ensure piston is extended
 | 
			
		||||
		local checknode = minetest.env:get_node(pos)
 | 
			
		||||
		if checknode.name == "mesecons_pistons:piston_down_pusher_normal" then
 | 
			
		||||
			if checknode.param2 == oldnode.param2 then --pusher is facing the same direction as the piston
 | 
			
		||||
				minetest.env:remove_node(pos) --remove the pusher
 | 
			
		||||
			end
 | 
			
		||||
		end
 | 
			
		||||
	end,
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
mesecon:register_effector("mesecons_pistons:piston_down_normal", "mesecons_pistons:piston_down_normal")
 | 
			
		||||
 | 
			
		||||
--registration sticky one:
 | 
			
		||||
minetest.register_node("mesecons_pistons:piston_down_sticky", {
 | 
			
		||||
	description = "Sticky Piston DOWN",
 | 
			
		||||
	tiles = {"jeija_piston_tb.png", "jeija_piston_sticky_side.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png"},
 | 
			
		||||
	groups = {cracky=3, mesecon = 2},
 | 
			
		||||
	after_dig_node = function(pos, oldnode)
 | 
			
		||||
		local dir = {x=0, y=-1, z=0}
 | 
			
		||||
		pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node to check
 | 
			
		||||
 | 
			
		||||
		--ensure piston is extended
 | 
			
		||||
		local checknode = minetest.env:get_node(pos)
 | 
			
		||||
		if checknode.name == "mesecons_pistons:piston_down_pusher_sticky" then
 | 
			
		||||
			if checknode.param2 == oldnode.param2 then --pusher is facing the same direction as the piston
 | 
			
		||||
				minetest.env:remove_node(pos) --remove the pusher
 | 
			
		||||
			end
 | 
			
		||||
		end
 | 
			
		||||
	end,
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
mesecon:register_effector("mesecons_pistons:piston_down_sticky", "mesecons_pistons:piston_down_sticky")
 | 
			
		||||
 | 
			
		||||
minetest.register_craft({
 | 
			
		||||
	output = "mesecons_pistons:piston_down_normal",
 | 
			
		||||
	recipe = {
 | 
			
		||||
		{"mesecons_pistons:piston_up_normal"},
 | 
			
		||||
	}
 | 
			
		||||
})
 | 
			
		||||
minetest.register_craft({
 | 
			
		||||
	output = "mesecons_pistons:piston_normal",
 | 
			
		||||
	recipe = {
 | 
			
		||||
		{"mesecons_pistons:piston_down_normal"},
 | 
			
		||||
	}
 | 
			
		||||
})
 | 
			
		||||
minetest.register_craft({
 | 
			
		||||
	output = "mesecons_pistons:piston_down_sticky",
 | 
			
		||||
	recipe = {
 | 
			
		||||
		{"mesecons_pistons:piston_up_sticky"},
 | 
			
		||||
	}
 | 
			
		||||
})
 | 
			
		||||
minetest.register_craft({
 | 
			
		||||
	output = "mesecons_pistons:piston_sticky",
 | 
			
		||||
	recipe = {
 | 
			
		||||
		{"mesecons_pistons:piston_down_sticky"},
 | 
			
		||||
	}
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
minetest.register_node("mesecons_pistons:piston_down_pusher_normal", {
 | 
			
		||||
	drawtype = "nodebox",
 | 
			
		||||
	tiles = {"jeija_piston_pusher_normal.png"},
 | 
			
		||||
	paramtype = "light",
 | 
			
		||||
	diggable = false,
 | 
			
		||||
	selection_box = {
 | 
			
		||||
		type = "fixed",
 | 
			
		||||
		fixed = {
 | 
			
		||||
			{-0.2, -0.3, -0.2, 0.2, 0.5, 0.2},
 | 
			
		||||
			{-0.5, -0.5, -0.5, 0.5, -0.3, 0.5},
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
	node_box = {
 | 
			
		||||
		type = "fixed",
 | 
			
		||||
		fixed = {
 | 
			
		||||
			{-0.2, -0.3, -0.2, 0.2, 0.5, 0.2},
 | 
			
		||||
			{-0.5, -0.5, -0.5, 0.5, -0.3, 0.5},
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
mesecon:register_mvps_stopper("mesecons_pistons:piston_down_pusher_normal")
 | 
			
		||||
mesecon:register_mvps_stopper("mesecons_pistons:piston_down_pusher_sticky")
 | 
			
		||||
 | 
			
		||||
minetest.register_node("mesecons_pistons:piston_down_pusher_sticky", {
 | 
			
		||||
	drawtype = "nodebox",
 | 
			
		||||
	tiles = {
 | 
			
		||||
		"jeija_piston_pusher_sticky.png",
 | 
			
		||||
		"jeija_piston_pusher_normal.png",
 | 
			
		||||
		"jeija_piston_pusher_normal.png",
 | 
			
		||||
		"jeija_piston_pusher_normal.png",
 | 
			
		||||
		"jeija_piston_pusher_normal.png",
 | 
			
		||||
		"jeija_piston_pusher_normal.png"
 | 
			
		||||
		},
 | 
			
		||||
	paramtype = "light",
 | 
			
		||||
	diggable = false,
 | 
			
		||||
	selection_box = {
 | 
			
		||||
		type = "fixed",
 | 
			
		||||
		fixed = {
 | 
			
		||||
			{-0.2, -0.3, -0.2, 0.2, 0.5, 0.2},
 | 
			
		||||
			{-0.5, -0.5, -0.5, 0.5, -0.3, 0.5},
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
	node_box = {
 | 
			
		||||
		type = "fixed",
 | 
			
		||||
		fixed = {
 | 
			
		||||
			{-0.2, -0.3, -0.2, 0.2, 0.5, 0.2},
 | 
			
		||||
			{-0.5, -0.5, -0.5, 0.5, -0.3, 0.5},
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
-- Push action
 | 
			
		||||
mesecon:register_on_signal_on(function(pos, node)
 | 
			
		||||
	if node.name ~= "mesecons_pistons:piston_down_normal" and node.name ~= "mesecons_pistons:piston_down_sticky" then
 | 
			
		||||
		return
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	local dir = {x=0, y=-1, z=0}
 | 
			
		||||
	pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node being pushed
 | 
			
		||||
 | 
			
		||||
	--determine the number of nodes that need to be pushed
 | 
			
		||||
	local count = 0
 | 
			
		||||
	local checkpos = {x=pos.x, y=pos.y, z=pos.z} --first node being pushed
 | 
			
		||||
	while true do
 | 
			
		||||
		local checknode = minetest.env:get_node(checkpos)
 | 
			
		||||
 | 
			
		||||
		--check for collision with stopper
 | 
			
		||||
		if mesecon:is_mvps_stopper(checknode.name) then 
 | 
			
		||||
			return
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		--check for column end
 | 
			
		||||
		if checknode.name == "air"
 | 
			
		||||
		or checknode.name == "ignore"
 | 
			
		||||
		or checknode.name == "default:water_source"
 | 
			
		||||
		or checknode.name == "default:water_flowing"
 | 
			
		||||
		or checknode.name == "default:lava_source"
 | 
			
		||||
		or checknode.name == "default:lava_flowing" then
 | 
			
		||||
			break
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		--limit piston pushing capacity
 | 
			
		||||
		count = count + 1
 | 
			
		||||
		if count > 15 then
 | 
			
		||||
			return
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		checkpos.x, checkpos.y, checkpos.z = checkpos.x + dir.x, checkpos.y + dir.y, checkpos.z + dir.z
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	local checknode = minetest.env:get_node(pos)
 | 
			
		||||
	minetest.env:remove_node(pos) --remove the first node
 | 
			
		||||
	mesecon:updatenode(pos)
 | 
			
		||||
 | 
			
		||||
	--add pusher
 | 
			
		||||
	if node.name == "mesecons_pistons:piston_down_normal" then
 | 
			
		||||
		minetest.env:add_node(pos, {name="mesecons_pistons:piston_down_pusher_normal", param2=node.param2})
 | 
			
		||||
	else
 | 
			
		||||
		minetest.env:add_node(pos, {name="mesecons_pistons:piston_down_pusher_sticky", param2=node.param2})
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	--move nodes forward
 | 
			
		||||
	for i = 1, count do
 | 
			
		||||
		pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to the next node
 | 
			
		||||
 | 
			
		||||
		--move the node forward
 | 
			
		||||
		local nextnode = minetest.env:get_node(pos)
 | 
			
		||||
		--minetest.env:dig_node(pos)
 | 
			
		||||
		minetest.env:set_node(pos, checknode)
 | 
			
		||||
		mesecon:updatenode(pos)
 | 
			
		||||
		checknode = nextnode
 | 
			
		||||
	end
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
--Pull action
 | 
			
		||||
mesecon:register_on_signal_off(function(pos, node)
 | 
			
		||||
	if node.name ~= "mesecons_pistons:piston_down_normal" and node.name ~= "mesecons_pistons:piston_down_sticky" then
 | 
			
		||||
		return
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	local dir = {x=0, y=-1, z=0}
 | 
			
		||||
	pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to the node to be replaced
 | 
			
		||||
 | 
			
		||||
	--ensure piston is extended
 | 
			
		||||
	local checknode = minetest.env:get_node(pos)
 | 
			
		||||
	if checknode.name ~= "mesecons_pistons:piston_down_pusher_normal" and checknode.name ~= "mesecons_pistons:piston_down_pusher_sticky" then
 | 
			
		||||
		return
 | 
			
		||||
	end
 | 
			
		||||
	if checknode.param2 ~= node.param2 then --pusher is not facing the same direction as the piston
 | 
			
		||||
		return --piston is not extended
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	--retract piston
 | 
			
		||||
	minetest.env:remove_node(pos) --remove pusher
 | 
			
		||||
	if node.name ~= "mesecons_pistons:piston_down_sticky" then
 | 
			
		||||
	    nodeupdate(pos)
 | 
			
		||||
	end
 | 
			
		||||
	if node.name == "mesecons_pistons:piston_down_sticky" then --retract block
 | 
			
		||||
		local checkpos = {x=pos.x + dir.x, y=pos.y + dir.y, z=pos.z + dir.z} --move to the node to be retracted
 | 
			
		||||
		checknode = minetest.env:get_node(checkpos)
 | 
			
		||||
		if checknode.name ~= "air"
 | 
			
		||||
		and checknode.name ~= "ignore"
 | 
			
		||||
		and checknode.name ~= "default:water_source"
 | 
			
		||||
		and checknode.name ~= "default:water_flowing"
 | 
			
		||||
		and checknode.name ~= "default:lava_source"
 | 
			
		||||
		and checknode.name ~= "default:lava_flowing"
 | 
			
		||||
		and not mesecon:is_mvps_stopper(checknode.name) then
 | 
			
		||||
			minetest.env:remove_node(checkpos)
 | 
			
		||||
		    mesecon:updatenode(checkpos)
 | 
			
		||||
		    minetest.env:set_node(pos, checknode)
 | 
			
		||||
		    mesecon:updatenode(pos)
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
	if node.name == "mesecons_pistons:piston_down_sticky" then
 | 
			
		||||
	    nodeupdate(pos)
 | 
			
		||||
	end
 | 
			
		||||
end)
 | 
			
		||||
--PISTONS
 | 
			
		||||
--registration normal one:
 | 
			
		||||
minetest.register_node("mesecons_pistons:piston_down_normal", {
 | 
			
		||||
	description = "Piston DOWN",
 | 
			
		||||
	tiles = {"jeija_piston_tb.png", "jeija_piston_side.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png"},
 | 
			
		||||
	groups = {cracky=3, mesecon = 2},
 | 
			
		||||
	after_dig_node = function(pos, oldnode)
 | 
			
		||||
		local dir = {x=0, y=-1, z=0}
 | 
			
		||||
		pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node to check
 | 
			
		||||
 | 
			
		||||
		--ensure piston is extended
 | 
			
		||||
		local checknode = minetest.env:get_node(pos)
 | 
			
		||||
		if checknode.name == "mesecons_pistons:piston_down_pusher_normal" then
 | 
			
		||||
			if checknode.param2 == oldnode.param2 then --pusher is facing the same direction as the piston
 | 
			
		||||
				minetest.env:remove_node(pos) --remove the pusher
 | 
			
		||||
			end
 | 
			
		||||
		end
 | 
			
		||||
	end,
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
mesecon:register_effector("mesecons_pistons:piston_down_normal", "mesecons_pistons:piston_down_normal")
 | 
			
		||||
 | 
			
		||||
--registration sticky one:
 | 
			
		||||
minetest.register_node("mesecons_pistons:piston_down_sticky", {
 | 
			
		||||
	description = "Sticky Piston DOWN",
 | 
			
		||||
	tiles = {"jeija_piston_tb.png", "jeija_piston_sticky_side.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png"},
 | 
			
		||||
	groups = {cracky=3, mesecon = 2},
 | 
			
		||||
	after_dig_node = function(pos, oldnode)
 | 
			
		||||
		local dir = {x=0, y=-1, z=0}
 | 
			
		||||
		pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node to check
 | 
			
		||||
 | 
			
		||||
		--ensure piston is extended
 | 
			
		||||
		local checknode = minetest.env:get_node(pos)
 | 
			
		||||
		if checknode.name == "mesecons_pistons:piston_down_pusher_sticky" then
 | 
			
		||||
			if checknode.param2 == oldnode.param2 then --pusher is facing the same direction as the piston
 | 
			
		||||
				minetest.env:remove_node(pos) --remove the pusher
 | 
			
		||||
			end
 | 
			
		||||
		end
 | 
			
		||||
	end,
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
mesecon:register_effector("mesecons_pistons:piston_down_sticky", "mesecons_pistons:piston_down_sticky")
 | 
			
		||||
 | 
			
		||||
minetest.register_craft({
 | 
			
		||||
	output = "mesecons_pistons:piston_down_normal",
 | 
			
		||||
	recipe = {
 | 
			
		||||
		{"mesecons_pistons:piston_up_normal"},
 | 
			
		||||
	}
 | 
			
		||||
})
 | 
			
		||||
minetest.register_craft({
 | 
			
		||||
	output = "mesecons_pistons:piston_normal",
 | 
			
		||||
	recipe = {
 | 
			
		||||
		{"mesecons_pistons:piston_down_normal"},
 | 
			
		||||
	}
 | 
			
		||||
})
 | 
			
		||||
minetest.register_craft({
 | 
			
		||||
	output = "mesecons_pistons:piston_down_sticky",
 | 
			
		||||
	recipe = {
 | 
			
		||||
		{"mesecons_pistons:piston_up_sticky"},
 | 
			
		||||
	}
 | 
			
		||||
})
 | 
			
		||||
minetest.register_craft({
 | 
			
		||||
	output = "mesecons_pistons:piston_sticky",
 | 
			
		||||
	recipe = {
 | 
			
		||||
		{"mesecons_pistons:piston_down_sticky"},
 | 
			
		||||
	}
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
minetest.register_node("mesecons_pistons:piston_down_pusher_normal", {
 | 
			
		||||
	drawtype = "nodebox",
 | 
			
		||||
	tiles = {"jeija_piston_pusher_normal.png"},
 | 
			
		||||
	paramtype = "light",
 | 
			
		||||
	diggable = false,
 | 
			
		||||
	selection_box = {
 | 
			
		||||
		type = "fixed",
 | 
			
		||||
		fixed = {
 | 
			
		||||
			{-0.2, -0.3, -0.2, 0.2, 0.5, 0.2},
 | 
			
		||||
			{-0.5, -0.5, -0.5, 0.5, -0.3, 0.5},
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
	node_box = {
 | 
			
		||||
		type = "fixed",
 | 
			
		||||
		fixed = {
 | 
			
		||||
			{-0.2, -0.3, -0.2, 0.2, 0.5, 0.2},
 | 
			
		||||
			{-0.5, -0.5, -0.5, 0.5, -0.3, 0.5},
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
mesecon:register_mvps_stopper("mesecons_pistons:piston_down_pusher_normal")
 | 
			
		||||
mesecon:register_mvps_stopper("mesecons_pistons:piston_down_pusher_sticky")
 | 
			
		||||
 | 
			
		||||
minetest.register_node("mesecons_pistons:piston_down_pusher_sticky", {
 | 
			
		||||
	drawtype = "nodebox",
 | 
			
		||||
	tiles = {
 | 
			
		||||
		"jeija_piston_pusher_sticky.png",
 | 
			
		||||
		"jeija_piston_pusher_normal.png",
 | 
			
		||||
		"jeija_piston_pusher_normal.png",
 | 
			
		||||
		"jeija_piston_pusher_normal.png",
 | 
			
		||||
		"jeija_piston_pusher_normal.png",
 | 
			
		||||
		"jeija_piston_pusher_normal.png"
 | 
			
		||||
		},
 | 
			
		||||
	paramtype = "light",
 | 
			
		||||
	diggable = false,
 | 
			
		||||
	selection_box = {
 | 
			
		||||
		type = "fixed",
 | 
			
		||||
		fixed = {
 | 
			
		||||
			{-0.2, -0.3, -0.2, 0.2, 0.5, 0.2},
 | 
			
		||||
			{-0.5, -0.5, -0.5, 0.5, -0.3, 0.5},
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
	node_box = {
 | 
			
		||||
		type = "fixed",
 | 
			
		||||
		fixed = {
 | 
			
		||||
			{-0.2, -0.3, -0.2, 0.2, 0.5, 0.2},
 | 
			
		||||
			{-0.5, -0.5, -0.5, 0.5, -0.3, 0.5},
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
-- Push action
 | 
			
		||||
mesecon:register_on_signal_on(function(pos, node)
 | 
			
		||||
	if node.name ~= "mesecons_pistons:piston_down_normal" and node.name ~= "mesecons_pistons:piston_down_sticky" then
 | 
			
		||||
		return
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	local dir = {x=0, y=-1, z=0}
 | 
			
		||||
	pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node being pushed
 | 
			
		||||
 | 
			
		||||
	--determine the number of nodes that need to be pushed
 | 
			
		||||
	local count = 0
 | 
			
		||||
	local checkpos = {x=pos.x, y=pos.y, z=pos.z} --first node being pushed
 | 
			
		||||
	while true do
 | 
			
		||||
		local checknode = minetest.env:get_node(checkpos)
 | 
			
		||||
 | 
			
		||||
		--check for collision with stopper
 | 
			
		||||
		if mesecon:is_mvps_stopper(checknode.name) then 
 | 
			
		||||
			return
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		--check for column end
 | 
			
		||||
		if checknode.name == "air"
 | 
			
		||||
		or checknode.name == "ignore"
 | 
			
		||||
		or string.find(checknode.name, "_flowing")
 | 
			
		||||
		or string.find(checknode.name, "_source") then
 | 
			
		||||
			break
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		--limit piston pushing capacity
 | 
			
		||||
		count = count + 1
 | 
			
		||||
		if count > 15 then
 | 
			
		||||
			return
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		checkpos.x, checkpos.y, checkpos.z = checkpos.x + dir.x, checkpos.y + dir.y, checkpos.z + dir.z
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	local checknode = minetest.env:get_node(pos)
 | 
			
		||||
	minetest.env:remove_node(pos) --remove the first node
 | 
			
		||||
	mesecon:updatenode(pos)
 | 
			
		||||
 | 
			
		||||
	--add pusher
 | 
			
		||||
	if node.name == "mesecons_pistons:piston_down_normal" then
 | 
			
		||||
		minetest.env:add_node(pos, {name="mesecons_pistons:piston_down_pusher_normal", param2=node.param2})
 | 
			
		||||
	else
 | 
			
		||||
		minetest.env:add_node(pos, {name="mesecons_pistons:piston_down_pusher_sticky", param2=node.param2})
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	--move nodes forward
 | 
			
		||||
	for i = 1, count do
 | 
			
		||||
		pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to the next node
 | 
			
		||||
 | 
			
		||||
		--move the node forward
 | 
			
		||||
		local nextnode = minetest.env:get_node(pos)
 | 
			
		||||
		--minetest.env:dig_node(pos)
 | 
			
		||||
		minetest.env:set_node(pos, checknode)
 | 
			
		||||
		mesecon:updatenode(pos)
 | 
			
		||||
		checknode = nextnode
 | 
			
		||||
	end
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
--Pull action
 | 
			
		||||
mesecon:register_on_signal_off(function(pos, node)
 | 
			
		||||
	if node.name ~= "mesecons_pistons:piston_down_normal" and node.name ~= "mesecons_pistons:piston_down_sticky" then
 | 
			
		||||
		return
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	local dir = {x=0, y=-1, z=0}
 | 
			
		||||
	pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to the node to be replaced
 | 
			
		||||
 | 
			
		||||
	--ensure piston is extended
 | 
			
		||||
	local checknode = minetest.env:get_node(pos)
 | 
			
		||||
	if checknode.name ~= "mesecons_pistons:piston_down_pusher_normal" and checknode.name ~= "mesecons_pistons:piston_down_pusher_sticky" then
 | 
			
		||||
		return
 | 
			
		||||
	end
 | 
			
		||||
	if checknode.param2 ~= node.param2 then --pusher is not facing the same direction as the piston
 | 
			
		||||
		return --piston is not extended
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	--retract piston
 | 
			
		||||
	minetest.env:remove_node(pos) --remove pusher
 | 
			
		||||
	if node.name ~= "mesecons_pistons:piston_down_sticky" then
 | 
			
		||||
	    nodeupdate(pos)
 | 
			
		||||
	end
 | 
			
		||||
	if node.name == "mesecons_pistons:piston_down_sticky" then --retract block
 | 
			
		||||
		local checkpos = {x=pos.x + dir.x, y=pos.y + dir.y, z=pos.z + dir.z} --move to the node to be retracted
 | 
			
		||||
		checknode = minetest.env:get_node(checkpos)
 | 
			
		||||
		if checknode.name ~= "air"
 | 
			
		||||
		and checknode.name ~= "ignore"
 | 
			
		||||
		and string.find(checknode.name, "_source")
 | 
			
		||||
		and string.find(checknode.name, "_flowing")
 | 
			
		||||
		and not mesecon:is_mvps_stopper(checknode.name) then
 | 
			
		||||
			minetest.env:remove_node(checkpos)
 | 
			
		||||
		    mesecon:updatenode(checkpos)
 | 
			
		||||
		    minetest.env:set_node(pos, checknode)
 | 
			
		||||
		    mesecon:updatenode(pos)
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
	if node.name == "mesecons_pistons:piston_down_sticky" then
 | 
			
		||||
	    nodeupdate(pos)
 | 
			
		||||
	end
 | 
			
		||||
end)
 | 
			
		||||
 
 | 
			
		||||
@@ -1,214 +1,210 @@
 | 
			
		||||
--PISTONS
 | 
			
		||||
--registration normal one:
 | 
			
		||||
minetest.register_node("mesecons_pistons:piston_up_normal", {
 | 
			
		||||
	description = "Piston UP",
 | 
			
		||||
	tiles = {"jeija_piston_side.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png"},
 | 
			
		||||
	groups = {cracky=3, mesecon = 2},
 | 
			
		||||
	after_dig_node = function(pos, oldnode)
 | 
			
		||||
		local dir = {x=0, y=1, z=0}
 | 
			
		||||
		pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node to check
 | 
			
		||||
 | 
			
		||||
		--ensure piston is extended
 | 
			
		||||
		local checknode = minetest.env:get_node(pos)
 | 
			
		||||
		if checknode.name == "mesecons_pistons:piston_up_pusher_normal" then
 | 
			
		||||
			if checknode.param2 == oldnode.param2 then --pusher is facing the same direction as the piston
 | 
			
		||||
				minetest.env:remove_node(pos) --remove the pusher
 | 
			
		||||
			end
 | 
			
		||||
		end
 | 
			
		||||
	end,
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
mesecon:register_effector("mesecons_pistons:piston_up_normal", "mesecons_pistons:piston_up_normal")
 | 
			
		||||
 | 
			
		||||
--registration sticky one:
 | 
			
		||||
minetest.register_node("mesecons_pistons:piston_up_sticky", {
 | 
			
		||||
	description = "Sticky Piston UP",
 | 
			
		||||
	tiles = {"jeija_piston_sticky_side.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png"},
 | 
			
		||||
	groups = {cracky=3, mesecon = 2},
 | 
			
		||||
	after_dig_node = function(pos, oldnode)
 | 
			
		||||
		local dir = {x=0, y=1, z=0}
 | 
			
		||||
		pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node to check
 | 
			
		||||
 | 
			
		||||
		--ensure piston is extended
 | 
			
		||||
		local checknode = minetest.env:get_node(pos)
 | 
			
		||||
		if checknode.name == "mesecons_pistons:piston_up_pusher_sticky" then
 | 
			
		||||
			if checknode.param2 == oldnode.param2 then --pusher is facing the same direction as the piston
 | 
			
		||||
				minetest.env:remove_node(pos) --remove the pusher
 | 
			
		||||
			end
 | 
			
		||||
		end
 | 
			
		||||
	end,
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
mesecon:register_effector("mesecons_pistons:piston_up_sticky", "mesecons_pistons:piston_up_sticky")
 | 
			
		||||
 | 
			
		||||
minetest.register_craft({
 | 
			
		||||
	output = "mesecons_pistons:piston_up_normal",
 | 
			
		||||
	recipe = {
 | 
			
		||||
		{"mesecons_pistons:piston_normal"},
 | 
			
		||||
	}
 | 
			
		||||
})
 | 
			
		||||
minetest.register_craft({
 | 
			
		||||
	output = "mesecons_pistons:piston_up_sticky",
 | 
			
		||||
	recipe = {
 | 
			
		||||
		{"mesecons_pistons:piston_sticky"},
 | 
			
		||||
	}
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
minetest.register_node("mesecons_pistons:piston_up_pusher_normal", {
 | 
			
		||||
	drawtype = "nodebox",
 | 
			
		||||
	tiles = {"jeija_piston_pusher_normal.png"},
 | 
			
		||||
	paramtype = "light",
 | 
			
		||||
	diggable = false,
 | 
			
		||||
	selection_box = {
 | 
			
		||||
		type = "fixed",
 | 
			
		||||
		fixed = {
 | 
			
		||||
			{-0.2, -0.5, -0.2, 0.2, 0.3, 0.2},
 | 
			
		||||
			{-0.5, 0.3, -0.5, 0.5, 0.5, 0.5},
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
	node_box = {
 | 
			
		||||
		type = "fixed",
 | 
			
		||||
		fixed = {
 | 
			
		||||
			{-0.2, -0.5, -0.2, 0.2, 0.3, 0.2},
 | 
			
		||||
			{-0.5, 0.3, -0.5, 0.5, 0.5, 0.5},
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
mesecon:register_mvps_stopper("mesecons_pistons:piston_up_pusher_normal")
 | 
			
		||||
mesecon:register_mvps_stopper("mesecons_pistons:piston_up_pusher_sticky")
 | 
			
		||||
 | 
			
		||||
minetest.register_node("mesecons_pistons:piston_up_pusher_sticky", {
 | 
			
		||||
	drawtype = "nodebox",
 | 
			
		||||
	tiles = {
 | 
			
		||||
		"jeija_piston_pusher_normal.png",
 | 
			
		||||
		"jeija_piston_pusher_sticky.png",
 | 
			
		||||
		"jeija_piston_pusher_normal.png",
 | 
			
		||||
		"jeija_piston_pusher_normal.png",
 | 
			
		||||
		"jeija_piston_pusher_normal.png",
 | 
			
		||||
		"jeija_piston_pusher_normal.png"
 | 
			
		||||
		},
 | 
			
		||||
	paramtype = "light",
 | 
			
		||||
	diggable = false,
 | 
			
		||||
	selection_box = {
 | 
			
		||||
		type = "fixed",
 | 
			
		||||
		fixed = {
 | 
			
		||||
			{-0.2, -0.5, -0.2, 0.2, 0.3, 0.2},
 | 
			
		||||
			{-0.5, 0.3, -0.5, 0.5, 0.5, 0.5},
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
	node_box = {
 | 
			
		||||
		type = "fixed",
 | 
			
		||||
		fixed = {
 | 
			
		||||
			{-0.2, -0.5, -0.2, 0.2, 0.3, 0.2},
 | 
			
		||||
			{-0.5, 0.3, -0.5, 0.5, 0.5, 0.5},
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
-- Push action
 | 
			
		||||
mesecon:register_on_signal_on(function(pos, node)
 | 
			
		||||
	if node.name ~= "mesecons_pistons:piston_up_normal" and node.name ~= "mesecons_pistons:piston_up_sticky" then
 | 
			
		||||
		return
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	local dir = {x=0, y=1, z=0}
 | 
			
		||||
	pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node being pushed
 | 
			
		||||
 | 
			
		||||
	--determine the number of nodes that need to be pushed
 | 
			
		||||
	local count = 0
 | 
			
		||||
	local checkpos = {x=pos.x, y=pos.y, z=pos.z} --first node being pushed
 | 
			
		||||
	while true do
 | 
			
		||||
		local checknode = minetest.env:get_node(checkpos)
 | 
			
		||||
 | 
			
		||||
		--check for collision with stopper
 | 
			
		||||
		if mesecon:is_mvps_stopper(checknode.name) then 
 | 
			
		||||
			return
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		--check for column end
 | 
			
		||||
		if checknode.name == "air"
 | 
			
		||||
		or checknode.name == "ignore"
 | 
			
		||||
		or checknode.name == "default:water_source"
 | 
			
		||||
		or checknode.name == "default:water_flowing"
 | 
			
		||||
		or checknode.name == "default:lava_source"
 | 
			
		||||
		or checknode.name == "default:lava_flowing" then
 | 
			
		||||
			break
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		--limit piston pushing capacity
 | 
			
		||||
		count = count + 1
 | 
			
		||||
		if count > 15 then
 | 
			
		||||
			return
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		checkpos.x, checkpos.y, checkpos.z = checkpos.x + dir.x, checkpos.y + dir.y, checkpos.z + dir.z
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	local checknode = minetest.env:get_node(pos)
 | 
			
		||||
	minetest.env:remove_node(pos) --remove the first node
 | 
			
		||||
	mesecon:updatenode(pos)
 | 
			
		||||
 | 
			
		||||
	--add pusher
 | 
			
		||||
	if node.name == "mesecons_pistons:piston_up_normal" then
 | 
			
		||||
		minetest.env:add_node(pos, {name="mesecons_pistons:piston_up_pusher_normal", param2=node.param2})
 | 
			
		||||
	else
 | 
			
		||||
		minetest.env:add_node(pos, {name="mesecons_pistons:piston_up_pusher_sticky", param2=node.param2})
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	--move nodes forward
 | 
			
		||||
	for i = 1, count do
 | 
			
		||||
		pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to the next node
 | 
			
		||||
 | 
			
		||||
		--move the node forward
 | 
			
		||||
		local nextnode = minetest.env:get_node(pos)
 | 
			
		||||
		--minetest.env:dig_node(pos)
 | 
			
		||||
		minetest.env:set_node(pos, checknode)
 | 
			
		||||
		mesecon:updatenode(pos)
 | 
			
		||||
		checknode = nextnode
 | 
			
		||||
	end
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
--Pull action
 | 
			
		||||
mesecon:register_on_signal_off(function(pos, node)
 | 
			
		||||
	if node.name ~= "mesecons_pistons:piston_up_normal" and node.name ~= "mesecons_pistons:piston_up_sticky" then
 | 
			
		||||
		return
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	local dir = {x=0, y=1, z=0}
 | 
			
		||||
	pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to the node to be replaced
 | 
			
		||||
 | 
			
		||||
	--ensure piston is extended
 | 
			
		||||
	local checknode = minetest.env:get_node(pos)
 | 
			
		||||
	if checknode.name ~= "mesecons_pistons:piston_up_pusher_normal" and checknode.name ~= "mesecons_pistons:piston_up_pusher_sticky" then
 | 
			
		||||
		return
 | 
			
		||||
	end
 | 
			
		||||
	if checknode.param2 ~= node.param2 then --pusher is not facing the same direction as the piston
 | 
			
		||||
		return --piston is not extended
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	--retract piston
 | 
			
		||||
	minetest.env:remove_node(pos) --remove pusher
 | 
			
		||||
	if node.name ~= "mesecons_pistons:piston_up_sticky" then
 | 
			
		||||
	    nodeupdate(pos)
 | 
			
		||||
	end
 | 
			
		||||
	if node.name == "mesecons_pistons:piston_up_sticky" then --retract block
 | 
			
		||||
		local checkpos = {x=pos.x + dir.x, y=pos.y + dir.y, z=pos.z + dir.z} --move to the node to be retracted
 | 
			
		||||
		checknode = minetest.env:get_node(checkpos)
 | 
			
		||||
		if checknode.name ~= "air"
 | 
			
		||||
		and checknode.name ~= "ignore"
 | 
			
		||||
		and checknode.name ~= "default:water_source"
 | 
			
		||||
		and checknode.name ~= "default:water_flowing"
 | 
			
		||||
		and checknode.name ~= "default:lava_source"
 | 
			
		||||
		and checknode.name ~= "default:lava_flowing"
 | 
			
		||||
		and not mesecon:is_mvps_stopper(checknode.name) then
 | 
			
		||||
			minetest.env:remove_node(checkpos)
 | 
			
		||||
		    mesecon:updatenode(checkpos)
 | 
			
		||||
		    minetest.env:set_node(pos, checknode)
 | 
			
		||||
		    mesecon:updatenode(pos)
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
	if node.name == "mesecons_pistons:piston_up_sticky" then
 | 
			
		||||
	    nodeupdate(pos)
 | 
			
		||||
	end
 | 
			
		||||
end)
 | 
			
		||||
--PISTONS
 | 
			
		||||
--registration normal one:
 | 
			
		||||
minetest.register_node("mesecons_pistons:piston_up_normal", {
 | 
			
		||||
	description = "Piston UP",
 | 
			
		||||
	tiles = {"jeija_piston_side.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png"},
 | 
			
		||||
	groups = {cracky=3, mesecon = 2},
 | 
			
		||||
	after_dig_node = function(pos, oldnode)
 | 
			
		||||
		local dir = {x=0, y=1, z=0}
 | 
			
		||||
		pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node to check
 | 
			
		||||
 | 
			
		||||
		--ensure piston is extended
 | 
			
		||||
		local checknode = minetest.env:get_node(pos)
 | 
			
		||||
		if checknode.name == "mesecons_pistons:piston_up_pusher_normal" then
 | 
			
		||||
			if checknode.param2 == oldnode.param2 then --pusher is facing the same direction as the piston
 | 
			
		||||
				minetest.env:remove_node(pos) --remove the pusher
 | 
			
		||||
			end
 | 
			
		||||
		end
 | 
			
		||||
	end,
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
mesecon:register_effector("mesecons_pistons:piston_up_normal", "mesecons_pistons:piston_up_normal")
 | 
			
		||||
 | 
			
		||||
--registration sticky one:
 | 
			
		||||
minetest.register_node("mesecons_pistons:piston_up_sticky", {
 | 
			
		||||
	description = "Sticky Piston UP",
 | 
			
		||||
	tiles = {"jeija_piston_sticky_side.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png"},
 | 
			
		||||
	groups = {cracky=3, mesecon = 2},
 | 
			
		||||
	after_dig_node = function(pos, oldnode)
 | 
			
		||||
		local dir = {x=0, y=1, z=0}
 | 
			
		||||
		pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node to check
 | 
			
		||||
 | 
			
		||||
		--ensure piston is extended
 | 
			
		||||
		local checknode = minetest.env:get_node(pos)
 | 
			
		||||
		if checknode.name == "mesecons_pistons:piston_up_pusher_sticky" then
 | 
			
		||||
			if checknode.param2 == oldnode.param2 then --pusher is facing the same direction as the piston
 | 
			
		||||
				minetest.env:remove_node(pos) --remove the pusher
 | 
			
		||||
			end
 | 
			
		||||
		end
 | 
			
		||||
	end,
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
mesecon:register_effector("mesecons_pistons:piston_up_sticky", "mesecons_pistons:piston_up_sticky")
 | 
			
		||||
 | 
			
		||||
minetest.register_craft({
 | 
			
		||||
	output = "mesecons_pistons:piston_up_normal",
 | 
			
		||||
	recipe = {
 | 
			
		||||
		{"mesecons_pistons:piston_normal"},
 | 
			
		||||
	}
 | 
			
		||||
})
 | 
			
		||||
minetest.register_craft({
 | 
			
		||||
	output = "mesecons_pistons:piston_up_sticky",
 | 
			
		||||
	recipe = {
 | 
			
		||||
		{"mesecons_pistons:piston_sticky"},
 | 
			
		||||
	}
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
minetest.register_node("mesecons_pistons:piston_up_pusher_normal", {
 | 
			
		||||
	drawtype = "nodebox",
 | 
			
		||||
	tiles = {"jeija_piston_pusher_normal.png"},
 | 
			
		||||
	paramtype = "light",
 | 
			
		||||
	diggable = false,
 | 
			
		||||
	selection_box = {
 | 
			
		||||
		type = "fixed",
 | 
			
		||||
		fixed = {
 | 
			
		||||
			{-0.2, -0.5, -0.2, 0.2, 0.3, 0.2},
 | 
			
		||||
			{-0.5, 0.3, -0.5, 0.5, 0.5, 0.5},
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
	node_box = {
 | 
			
		||||
		type = "fixed",
 | 
			
		||||
		fixed = {
 | 
			
		||||
			{-0.2, -0.5, -0.2, 0.2, 0.3, 0.2},
 | 
			
		||||
			{-0.5, 0.3, -0.5, 0.5, 0.5, 0.5},
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
mesecon:register_mvps_stopper("mesecons_pistons:piston_up_pusher_normal")
 | 
			
		||||
mesecon:register_mvps_stopper("mesecons_pistons:piston_up_pusher_sticky")
 | 
			
		||||
 | 
			
		||||
minetest.register_node("mesecons_pistons:piston_up_pusher_sticky", {
 | 
			
		||||
	drawtype = "nodebox",
 | 
			
		||||
	tiles = {
 | 
			
		||||
		"jeija_piston_pusher_normal.png",
 | 
			
		||||
		"jeija_piston_pusher_sticky.png",
 | 
			
		||||
		"jeija_piston_pusher_normal.png",
 | 
			
		||||
		"jeija_piston_pusher_normal.png",
 | 
			
		||||
		"jeija_piston_pusher_normal.png",
 | 
			
		||||
		"jeija_piston_pusher_normal.png"
 | 
			
		||||
		},
 | 
			
		||||
	paramtype = "light",
 | 
			
		||||
	diggable = false,
 | 
			
		||||
	selection_box = {
 | 
			
		||||
		type = "fixed",
 | 
			
		||||
		fixed = {
 | 
			
		||||
			{-0.2, -0.5, -0.2, 0.2, 0.3, 0.2},
 | 
			
		||||
			{-0.5, 0.3, -0.5, 0.5, 0.5, 0.5},
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
	node_box = {
 | 
			
		||||
		type = "fixed",
 | 
			
		||||
		fixed = {
 | 
			
		||||
			{-0.2, -0.5, -0.2, 0.2, 0.3, 0.2},
 | 
			
		||||
			{-0.5, 0.3, -0.5, 0.5, 0.5, 0.5},
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
-- Push action
 | 
			
		||||
mesecon:register_on_signal_on(function(pos, node)
 | 
			
		||||
	if node.name ~= "mesecons_pistons:piston_up_normal" and node.name ~= "mesecons_pistons:piston_up_sticky" then
 | 
			
		||||
		return
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	local dir = {x=0, y=1, z=0}
 | 
			
		||||
	pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node being pushed
 | 
			
		||||
 | 
			
		||||
	--determine the number of nodes that need to be pushed
 | 
			
		||||
	local count = 0
 | 
			
		||||
	local checkpos = {x=pos.x, y=pos.y, z=pos.z} --first node being pushed
 | 
			
		||||
	while true do
 | 
			
		||||
		local checknode = minetest.env:get_node(checkpos)
 | 
			
		||||
 | 
			
		||||
		--check for collision with stopper
 | 
			
		||||
		if mesecon:is_mvps_stopper(checknode.name) then 
 | 
			
		||||
			return
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		--check for column end
 | 
			
		||||
		if checknode.name == "air"
 | 
			
		||||
		or checknode.name == "ignore"
 | 
			
		||||
		or string.find(checknode.name, "_source")
 | 
			
		||||
		or string.find(checknode.name, "_flowing") then
 | 
			
		||||
			break
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		--limit piston pushing capacity
 | 
			
		||||
		count = count + 1
 | 
			
		||||
		if count > 15 then
 | 
			
		||||
			return
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		checkpos.x, checkpos.y, checkpos.z = checkpos.x + dir.x, checkpos.y + dir.y, checkpos.z + dir.z
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	local checknode = minetest.env:get_node(pos)
 | 
			
		||||
	minetest.env:remove_node(pos) --remove the first node
 | 
			
		||||
	mesecon:updatenode(pos)
 | 
			
		||||
 | 
			
		||||
	--add pusher
 | 
			
		||||
	if node.name == "mesecons_pistons:piston_up_normal" then
 | 
			
		||||
		minetest.env:add_node(pos, {name="mesecons_pistons:piston_up_pusher_normal", param2=node.param2})
 | 
			
		||||
	else
 | 
			
		||||
		minetest.env:add_node(pos, {name="mesecons_pistons:piston_up_pusher_sticky", param2=node.param2})
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	--move nodes forward
 | 
			
		||||
	for i = 1, count do
 | 
			
		||||
		pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to the next node
 | 
			
		||||
 | 
			
		||||
		--move the node forward
 | 
			
		||||
		local nextnode = minetest.env:get_node(pos)
 | 
			
		||||
		--minetest.env:dig_node(pos)
 | 
			
		||||
		minetest.env:set_node(pos, checknode)
 | 
			
		||||
		mesecon:updatenode(pos)
 | 
			
		||||
		checknode = nextnode
 | 
			
		||||
	end
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
--Pull action
 | 
			
		||||
mesecon:register_on_signal_off(function(pos, node)
 | 
			
		||||
	if node.name ~= "mesecons_pistons:piston_up_normal" and node.name ~= "mesecons_pistons:piston_up_sticky" then
 | 
			
		||||
		return
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	local dir = {x=0, y=1, z=0}
 | 
			
		||||
	pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to the node to be replaced
 | 
			
		||||
 | 
			
		||||
	--ensure piston is extended
 | 
			
		||||
	local checknode = minetest.env:get_node(pos)
 | 
			
		||||
	if checknode.name ~= "mesecons_pistons:piston_up_pusher_normal" and checknode.name ~= "mesecons_pistons:piston_up_pusher_sticky" then
 | 
			
		||||
		return
 | 
			
		||||
	end
 | 
			
		||||
	if checknode.param2 ~= node.param2 then --pusher is not facing the same direction as the piston
 | 
			
		||||
		return --piston is not extended
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	--retract piston
 | 
			
		||||
	minetest.env:remove_node(pos) --remove pusher
 | 
			
		||||
	if node.name ~= "mesecons_pistons:piston_up_sticky" then
 | 
			
		||||
	    nodeupdate(pos)
 | 
			
		||||
	end
 | 
			
		||||
	if node.name == "mesecons_pistons:piston_up_sticky" then --retract block
 | 
			
		||||
		local checkpos = {x=pos.x + dir.x, y=pos.y + dir.y, z=pos.z + dir.z} --move to the node to be retracted
 | 
			
		||||
		checknode = minetest.env:get_node(checkpos)
 | 
			
		||||
		if checknode.name ~= "air"
 | 
			
		||||
		and checknode.name ~= "ignore"
 | 
			
		||||
		and string.find(checknode.name, "_source")
 | 
			
		||||
		and string.find(checknode.name, "_flowing")
 | 
			
		||||
		and not mesecon:is_mvps_stopper(checknode.name) then
 | 
			
		||||
			minetest.env:remove_node(checkpos)
 | 
			
		||||
		    mesecon:updatenode(checkpos)
 | 
			
		||||
		    minetest.env:set_node(pos, checknode)
 | 
			
		||||
		    mesecon:updatenode(pos)
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
	if node.name == "mesecons_pistons:piston_up_sticky" then
 | 
			
		||||
	    nodeupdate(pos)
 | 
			
		||||
	end
 | 
			
		||||
end)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user