Deployer fixes

This commit is contained in:
Novatux 2014-04-13 09:25:17 +02:00
parent d662a37920
commit 274d7fb048
3 changed files with 129 additions and 178 deletions

View File

@ -3,60 +3,6 @@
minetest.register_alias("technic:deployer_off", "pipeworks:deployer_off") minetest.register_alias("technic:deployer_off", "pipeworks:deployer_off")
minetest.register_alias("technic:deployer_on", "pipeworks:deployer_on") minetest.register_alias("technic:deployer_on", "pipeworks:deployer_on")
--define the functions from https://github.com/minetest/minetest/pull/834 while waiting for the devs to notice it
local function dir_to_facedir(dir, is6d)
--account for y if requested
if is6d and math.abs(dir.y) > math.abs(dir.x) and math.abs(dir.y) > math.abs(dir.z) then
--from above
if dir.y < 0 then
if math.abs(dir.x) > math.abs(dir.z) then
if dir.x < 0 then
return 19
else
return 13
end
else
if dir.z < 0 then
return 10
else
return 4
end
end
--from below
else
if math.abs(dir.x) > math.abs(dir.z) then
if dir.x < 0 then
return 15
else
return 17
end
else
if dir.z < 0 then
return 6
else
return 8
end
end
end
--otherwise, place horizontally
elseif math.abs(dir.x) > math.abs(dir.z) then
if dir.x < 0 then
return 3
else
return 1
end
else
if dir.z < 0 then
return 2
else
return 0
end
end
end
minetest.register_craft({ minetest.register_craft({
output = 'pipeworks:deployer_off 1', output = 'pipeworks:deployer_off 1',
recipe = { recipe = {
@ -87,15 +33,16 @@ local function deployer_on(pos, node)
--locate the above and under positions --locate the above and under positions
local dir = minetest.facedir_to_dir(node.param2) local dir = minetest.facedir_to_dir(node.param2)
local pos_under, pos_above = {x = pos.x - dir.x, y = pos.y - dir.y, z = pos.z - dir.z}, {x = pos.x - 2*dir.x, y = pos.y - 2*dir.y, z = pos.z - 2*dir.z} local pos_under, pos_above = {x = pos.x - dir.x, y = pos.y - dir.y, z = pos.z - dir.z}, {x = pos.x - 2*dir.x, y = pos.y - 2*dir.y, z = pos.z - 2*dir.z}
swap_node(pos, "pipeworks:deployer_on") swap_node(pos, "pipeworks:deployer_on")
nodeupdate(pos) nodeupdate(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
print(dump(meta:to_table()))
local inv = meta:get_inventory() local inv = meta:get_inventory()
local invlist = inv:get_list("main") local invlist = inv:get_list("main")
for i, stack in ipairs(invlist) do for i, stack in ipairs(invlist) do
if stack:get_name() ~= nil and stack:get_name() ~= "" and minetest.get_node(pos_under).name == "air" then --obtain the first non-empty item slot if stack:get_name() ~= nil and stack:get_name() ~= "" then--and minetest.get_node(pos_under).name == "air" then --obtain the first non-empty item slot
local pitch local pitch
local yaw local yaw
if dir.z < 0 then if dir.z < 0 then
@ -117,6 +64,7 @@ local function deployer_on(pos, node)
yaw = 0 yaw = 0
pitch = math.pi/2 pitch = math.pi/2
end end
print(meta:get_string("owner"))
local placer = { local placer = {
get_inventory_formspec = delay(meta:get_string("formspec")), get_inventory_formspec = delay(meta:get_string("formspec")),
get_look_dir = delay({x = -dir.x, y = -dir.y, z = -dir.z}), get_look_dir = delay({x = -dir.x, y = -dir.y, z = -dir.z}),
@ -124,7 +72,7 @@ local function deployer_on(pos, node)
get_look_yaw = delay(yaw), get_look_yaw = delay(yaw),
get_player_control = delay({jump=false, right=false, left=false, LMB=false, RMB=false, sneak=false, aux1=false, down=false, up=false}), get_player_control = delay({jump=false, right=false, left=false, LMB=false, RMB=false, sneak=false, aux1=false, down=false, up=false}),
get_player_control_bits = delay(0), get_player_control_bits = delay(0),
get_player_name = delay("deployer"), get_player_name = delay(meta:get_string("owner")),
is_player = delay(true), is_player = delay(true),
set_inventory_formspec = delay(), set_inventory_formspec = delay(),
getpos = delay({x = pos.x, y = pos.y - 1.5, z = pos.z}), -- Player height getpos = delay({x = pos.x, y = pos.y - 1.5, z = pos.z}), -- Player height
@ -216,10 +164,12 @@ minetest.register_node("pipeworks:deployer_off", {
z = pos.z - placer_pos.z z = pos.z - placer_pos.z
} }
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
node.param2 = dir_to_facedir(dir, true) node.param2 = minetest.dir_to_facedir(dir, true)
minetest.set_node(pos, node) minetest.set_node(pos, node)
minetest.log("action", "real (6d) facedir: " .. node.param2) minetest.log("action", "real (6d) facedir: " .. node.param2)
end end
minetest.get_meta(pos):set_string("owner", placer:get_player_name())
end, end,
after_dig_node = pipeworks.scan_for_tube_objects, after_dig_node = pipeworks.scan_for_tube_objects,
}) })
@ -244,6 +194,7 @@ minetest.register_node("pipeworks:deployer_on", {
is_ground_content = true, is_ground_content = true,
paramtype2 = "facedir", paramtype2 = "facedir",
tubelike=1, tubelike=1,
drop = "pipeworks:deployer_off",
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2,tubedevice=1, tubedevice_receiver=1,not_in_creative_inventory=1}, groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2,tubedevice=1, tubedevice_receiver=1,not_in_creative_inventory=1},
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
on_construct = function(pos) on_construct = function(pos)
@ -277,10 +228,12 @@ minetest.register_node("pipeworks:deployer_on", {
z = pos.z - placer_pos.z z = pos.z - placer_pos.z
} }
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
node.param2 = dir_to_facedir(dir, true) node.param2 = minetest.dir_to_facedir(dir, true)
minetest.set_node(pos, node) minetest.set_node(pos, node)
minetest.log("action", "real (6d) facedir: " .. node.param2) minetest.log("action", "real (6d) facedir: " .. node.param2)
end end
minetest.get_meta(pos):set_string("owner", placer:get_player_name())
end, end,
after_dig_node = pipeworks.scan_for_tube_objects, after_dig_node = pipeworks.scan_for_tube_objects,
}) })

View File

@ -257,7 +257,7 @@ local function go_next(pos, velocity, stack)
else else
speed = 1 speed = 1
end end
vel.speed=speed vel.speed = speed
if minetest.registered_nodes[cnode.name] and minetest.registered_nodes[cnode.name].tube and minetest.registered_nodes[cnode.name].tube.can_go then if minetest.registered_nodes[cnode.name] and minetest.registered_nodes[cnode.name].tube and minetest.registered_nodes[cnode.name].tube.can_go then
can_go = minetest.registered_nodes[cnode.name].tube.can_go(pos, cnode, vel, stack) can_go = minetest.registered_nodes[cnode.name].tube.can_go(pos, cnode, vel, stack)
else else
@ -361,15 +361,14 @@ minetest.register_entity("pipeworks:tubed_item", {
end, end,
get_staticdata = function(self) get_staticdata = function(self)
if self.start_pos==nil then return end if self.start_pos==nil then return end
local velocity=self.object:getvelocity() local velocity=self.object:getvelocity()
--self.object:setvelocity({x=0,y=0,z=0}) self.object:setpos(self.start_pos)
self.object:setpos(self.start_pos) return minetest.serialize({
return minetest.serialize({ itemstring=self.itemstring,
itemstring=self.itemstring, velocity=velocity,
velocity=velocity, start_pos=self.start_pos
start_pos=self.start_pos })
})
end, end,
on_activate = function(self, staticdata) on_activate = function(self, staticdata)
@ -392,89 +391,85 @@ minetest.register_entity("pipeworks:tubed_item", {
end, end,
on_step = function(self, dtime) on_step = function(self, dtime)
if self.start_pos==nil then if self.start_pos==nil then
local pos = self.object:getpos()
self.start_pos=roundpos(pos)
end
local pos = self.object:getpos() local pos = self.object:getpos()
self.start_pos=roundpos(pos) local node = minetest.get_node(pos)
end local meta = minetest.get_meta(pos)
local pos = self.object:getpos() local tubelike = meta:get_int("tubelike")
local node = minetest.get_node(pos) local stack = ItemStack(self.itemstring)
local meta = minetest.get_meta(pos) local drop_pos = nil
tubelike=meta:get_int("tubelike")
local stack = ItemStack(self.itemstring)
local drop_pos=nil
local velocity=self.object:getvelocity() local velocity=self.object:getvelocity()
if velocity==nil then return end if velocity == nil then return end
local velocitycopy={x=velocity.x,y=velocity.y,z=velocity.z} local velocitycopy = {x = velocity.x, y = velocity.y, z = velocity.z}
local moved=false local moved = false
local speed=math.abs(velocity.x+velocity.y+velocity.z) local speed = math.abs(velocity.x+velocity.y+velocity.z)
local vel={x=velocity.x/speed,y=velocity.y/speed,z=velocity.z/speed, speed=speed} local vel = {x = velocity.x/speed, y = velocity.y/speed, z = velocity.z/speed, speed = speed}
if math.abs(vel.x)==1 then if math.abs(vel.x) == 1 then
local next_node=math.abs(pos.x-self.start_pos.x) local next_node = math.abs(pos.x-self.start_pos.x)
if next_node >= 1 then
self.start_pos.x = self.start_pos.x+vel.x
moved = true
end
elseif math.abs(vel.y) == 1 then
local next_node = math.abs(pos.y-self.start_pos.y)
if next_node >= 1 then if next_node >= 1 then
self.start_pos.x=self.start_pos.x+vel.x self.start_pos.y = self.start_pos.y+vel.y
moved=true moved = true
end
elseif math.abs(vel.y)==1 then
local next_node=math.abs(pos.y-self.start_pos.y)
if next_node >= 1 then
self.start_pos.y=self.start_pos.y+vel.y
moved=true
end end
elseif math.abs(vel.z)==1 then elseif math.abs(vel.z) == 1 then
local next_node=math.abs(pos.z-self.start_pos.z) local next_node = math.abs(pos.z-self.start_pos.z)
if next_node >= 1 then if next_node >= 1 then
self.start_pos.z=self.start_pos.z+vel.z self.start_pos.z = self.start_pos.z+vel.z
moved=true moved = true
end
end
local sposcopy={x=self.start_pos.x,y=self.start_pos.y,z=self.start_pos.z}
node = minetest.get_node(self.start_pos)
if moved and minetest.get_item_group(node.name,"tubedevice_receiver")==1 then
local leftover = nil
if minetest.registered_nodes[node.name].tube and minetest.registered_nodes[node.name].tube.insert_object then
leftover = minetest.registered_nodes[node.name].tube.insert_object(self.start_pos,node,stack,vel)
else
leftover = stack
end
--drop_pos=minetest.find_node_near(self.start_pos,1,"air")
--if drop_pos and not leftover:is_empty() then minetest.item_drop(leftover,"",drop_pos) end
--self.object:remove()
if leftover:is_empty() then
self.object:remove()
return
end
velocity.x=-velocity.x
velocity.y=-velocity.y
velocity.z=-velocity.z
self.object:setvelocity(velocity)
self:set_item(leftover:to_string())
return
end
if moved then
if go_next (self.start_pos, velocity, stack) == 0 then
drop_pos=minetest.find_node_near({x=self.start_pos.x+velocity.x,y=self.start_pos.y+velocity.y,z=self.start_pos.z+velocity.z}, 1, "air")
if drop_pos then
minetest.item_drop(stack, "", drop_pos)
self.object:remove()
end end
end end
local sposcopy = {x = self.start_pos.x, y = self.start_pos.y, z = self.start_pos.z}
node = minetest.get_node(self.start_pos)
if moved and minetest.get_item_group(node.name, "tubedevice_receiver") == 1 then
local leftover = nil
if minetest.registered_nodes[node.name].tube and minetest.registered_nodes[node.name].tube.insert_object then
leftover = minetest.registered_nodes[node.name].tube.insert_object(self.start_pos, node, stack, vel)
else
leftover = stack
end
if leftover:is_empty() then
self.object:remove()
return
end
velocity.x = -velocity.x
velocity.y = -velocity.y
velocity.z = -velocity.z
self.object:setvelocity(velocity)
self:set_item(leftover:to_string())
return
end
if moved then
if go_next (self.start_pos, velocity, stack) == 0 then
drop_pos = minetest.find_node_near(vector.add(self.start_pos, velocity), 1, "air")
if drop_pos then
minetest.item_drop(stack, "", drop_pos)
self.object:remove()
end
end
end
if velocity.x~=velocitycopy.x or velocity.y~=velocitycopy.y or velocity.z~=velocitycopy.z or
self.start_pos.x~=sposcopy.x or self.start_pos.y~=sposcopy.y or self.start_pos.z~=sposcopy.z then
self.object:setpos(self.start_pos)
self.object:setvelocity(velocity)
end
end end
if velocity.x~=velocitycopy.x or velocity.y~=velocitycopy.y or velocity.z~=velocitycopy.z or
self.start_pos.x~=sposcopy.x or self.start_pos.y~=sposcopy.y or self.start_pos.z~=sposcopy.z then
self.object:setpos(self.start_pos)
self.object:setvelocity(velocity)
end
end
}) })
if minetest.get_modpath("mesecons_mvps") ~= nil then if minetest.get_modpath("mesecons_mvps") ~= nil then

View File

@ -595,40 +595,43 @@ end
if pipeworks.enable_one_way_tube then if pipeworks.enable_one_way_tube then
minetest.register_node("pipeworks:one_way_tube", { minetest.register_node("pipeworks:one_way_tube", {
description = "One way tube", description = "One way tube",
tiles = {"pipeworks_one_way_tube_top.png", "pipeworks_one_way_tube_top.png", "pipeworks_one_way_tube_output.png", tiles = {"pipeworks_one_way_tube_top.png", "pipeworks_one_way_tube_top.png", "pipeworks_one_way_tube_output.png",
"pipeworks_one_way_tube_input.png", "pipeworks_one_way_tube_side.png", "pipeworks_one_way_tube_top.png"}, "pipeworks_one_way_tube_input.png", "pipeworks_one_way_tube_side.png", "pipeworks_one_way_tube_top.png"},
paramtype2 = "facedir", paramtype2 = "facedir",
drawtype = "nodebox", drawtype = "nodebox",
paramtype = "light", paramtype = "light",
node_box = {type = "fixed", node_box = {type = "fixed",
fixed = {{-1/2, -9/64, -9/64, 1/2, 9/64, 9/64}}}, fixed = {{-1/2, -9/64, -9/64, 1/2, 9/64, 9/64}}},
groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 2, tubedevice = 1, tubedevice_receiver = 1}, groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 2, tubedevice = 1, tubedevice_receiver = 1},
legacy_facedir_simple = true, legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
after_place_node = function(pos) on_construct = function(pos)
pipeworks.scan_for_tube_objects(pos) minetest.get_meta(pos):set_int("tubelike", 1)
end, end,
after_dig_node = function(pos) after_place_node = function(pos)
pipeworks.scan_for_tube_objects(pos) pipeworks.scan_for_tube_objects(pos)
end, end,
tube = {connect_sides = {left = 1, right = 1}, after_dig_node = function(pos)
can_go = function(pos, node, velocity, stack) pipeworks.scan_for_tube_objects(pos)
return velocity end,
end, tube = {connect_sides = {left = 1, right = 1},
insert_object = function(pos, node, stack, direction) can_go = function(pos, node, velocity, stack)
item1 = pipeworks.tube_item(pos, stack) return velocity
item1:get_luaentity().start_pos = pos end,
item1:setvelocity({x = direction.x*direction.speed, y = direction.y*direction.speed, z = direction.z*direction.speed}) insert_object = function(pos, node, stack, direction)
item1:setacceleration({x = 0, y = 0, z = 0}) item1 = pipeworks.tube_item(pos, stack)
return ItemStack("") item1:get_luaentity().start_pos = pos
end, item1:setvelocity({x = direction.x*direction.speed, y = direction.y*direction.speed, z = direction.z*direction.speed})
can_insert = function(pos, node, stack, direction) item1:setacceleration({x = 0, y = 0, z = 0})
local dir = facedir_to_right_dir(node.param2) return ItemStack("")
if dir.x == direction.x and dir.y == direction.y and dir.z == direction.z then end,
return true can_insert = function(pos, node, stack, direction)
end local dir = facedir_to_right_dir(node.param2)
return false if dir.x == direction.x and dir.y == direction.y and dir.z == direction.z then
end}, return true
end
return false
end},
}) })
end end