forked from mtcontrib/pipeworks
Deployer fixes
This commit is contained in:
parent
d662a37920
commit
274d7fb048
71
deployer.lua
71
deployer.lua
@ -3,60 +3,6 @@
|
||||
minetest.register_alias("technic:deployer_off", "pipeworks:deployer_off")
|
||||
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({
|
||||
output = 'pipeworks:deployer_off 1',
|
||||
recipe = {
|
||||
@ -87,15 +33,16 @@ local function deployer_on(pos, node)
|
||||
--locate the above and under positions
|
||||
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}
|
||||
|
||||
|
||||
swap_node(pos, "pipeworks:deployer_on")
|
||||
nodeupdate(pos)
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
print(dump(meta:to_table()))
|
||||
local inv = meta:get_inventory()
|
||||
local invlist = inv:get_list("main")
|
||||
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 yaw
|
||||
if dir.z < 0 then
|
||||
@ -117,6 +64,7 @@ local function deployer_on(pos, node)
|
||||
yaw = 0
|
||||
pitch = math.pi/2
|
||||
end
|
||||
print(meta:get_string("owner"))
|
||||
local placer = {
|
||||
get_inventory_formspec = delay(meta:get_string("formspec")),
|
||||
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_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_name = delay("deployer"),
|
||||
get_player_name = delay(meta:get_string("owner")),
|
||||
is_player = delay(true),
|
||||
set_inventory_formspec = delay(),
|
||||
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
|
||||
}
|
||||
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.log("action", "real (6d) facedir: " .. node.param2)
|
||||
end
|
||||
|
||||
minetest.get_meta(pos):set_string("owner", placer:get_player_name())
|
||||
end,
|
||||
after_dig_node = pipeworks.scan_for_tube_objects,
|
||||
})
|
||||
@ -244,6 +194,7 @@ minetest.register_node("pipeworks:deployer_on", {
|
||||
is_ground_content = true,
|
||||
paramtype2 = "facedir",
|
||||
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},
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
on_construct = function(pos)
|
||||
@ -277,10 +228,12 @@ minetest.register_node("pipeworks:deployer_on", {
|
||||
z = pos.z - placer_pos.z
|
||||
}
|
||||
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.log("action", "real (6d) facedir: " .. node.param2)
|
||||
end
|
||||
|
||||
minetest.get_meta(pos):set_string("owner", placer:get_player_name())
|
||||
end,
|
||||
after_dig_node = pipeworks.scan_for_tube_objects,
|
||||
})
|
||||
|
@ -257,7 +257,7 @@ local function go_next(pos, velocity, stack)
|
||||
else
|
||||
speed = 1
|
||||
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
|
||||
can_go = minetest.registered_nodes[cnode.name].tube.can_go(pos, cnode, vel, stack)
|
||||
else
|
||||
@ -361,15 +361,14 @@ minetest.register_entity("pipeworks:tubed_item", {
|
||||
end,
|
||||
|
||||
get_staticdata = function(self)
|
||||
if self.start_pos==nil then return end
|
||||
local velocity=self.object:getvelocity()
|
||||
--self.object:setvelocity({x=0,y=0,z=0})
|
||||
self.object:setpos(self.start_pos)
|
||||
return minetest.serialize({
|
||||
itemstring=self.itemstring,
|
||||
velocity=velocity,
|
||||
start_pos=self.start_pos
|
||||
})
|
||||
if self.start_pos==nil then return end
|
||||
local velocity=self.object:getvelocity()
|
||||
self.object:setpos(self.start_pos)
|
||||
return minetest.serialize({
|
||||
itemstring=self.itemstring,
|
||||
velocity=velocity,
|
||||
start_pos=self.start_pos
|
||||
})
|
||||
end,
|
||||
|
||||
on_activate = function(self, staticdata)
|
||||
@ -392,89 +391,85 @@ minetest.register_entity("pipeworks:tubed_item", {
|
||||
end,
|
||||
|
||||
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()
|
||||
self.start_pos=roundpos(pos)
|
||||
end
|
||||
local pos = self.object:getpos()
|
||||
local node = minetest.get_node(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
tubelike=meta:get_int("tubelike")
|
||||
local stack = ItemStack(self.itemstring)
|
||||
local drop_pos=nil
|
||||
local node = minetest.get_node(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local 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 moved=false
|
||||
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}
|
||||
|
||||
if math.abs(vel.x)==1 then
|
||||
local next_node=math.abs(pos.x-self.start_pos.x)
|
||||
local velocitycopy = {x = velocity.x, y = velocity.y, z = velocity.z}
|
||||
|
||||
local moved = false
|
||||
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}
|
||||
|
||||
if math.abs(vel.x) == 1 then
|
||||
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
|
||||
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
|
||||
self.start_pos.y=self.start_pos.y+vel.y
|
||||
moved=true
|
||||
self.start_pos.y = self.start_pos.y+vel.y
|
||||
moved = true
|
||||
end
|
||||
elseif math.abs(vel.z)==1 then
|
||||
local next_node=math.abs(pos.z-self.start_pos.z)
|
||||
if next_node >= 1 then
|
||||
self.start_pos.z=self.start_pos.z+vel.z
|
||||
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()
|
||||
elseif math.abs(vel.z) == 1 then
|
||||
local next_node = math.abs(pos.z-self.start_pos.z)
|
||||
if next_node >= 1 then
|
||||
self.start_pos.z = self.start_pos.z+vel.z
|
||||
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
|
||||
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
|
||||
|
||||
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
|
||||
|
73
tubes.lua
73
tubes.lua
@ -595,40 +595,43 @@ end
|
||||
|
||||
if pipeworks.enable_one_way_tube then
|
||||
minetest.register_node("pipeworks: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",
|
||||
"pipeworks_one_way_tube_input.png", "pipeworks_one_way_tube_side.png", "pipeworks_one_way_tube_top.png"},
|
||||
paramtype2 = "facedir",
|
||||
drawtype = "nodebox",
|
||||
paramtype = "light",
|
||||
node_box = {type = "fixed",
|
||||
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},
|
||||
legacy_facedir_simple = true,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
after_place_node = function(pos)
|
||||
pipeworks.scan_for_tube_objects(pos)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
pipeworks.scan_for_tube_objects(pos)
|
||||
end,
|
||||
tube = {connect_sides = {left = 1, right = 1},
|
||||
can_go = function(pos, node, velocity, stack)
|
||||
return velocity
|
||||
end,
|
||||
insert_object = function(pos, node, stack, direction)
|
||||
item1 = pipeworks.tube_item(pos, stack)
|
||||
item1:get_luaentity().start_pos = pos
|
||||
item1:setvelocity({x = direction.x*direction.speed, y = direction.y*direction.speed, z = direction.z*direction.speed})
|
||||
item1:setacceleration({x = 0, y = 0, z = 0})
|
||||
return ItemStack("")
|
||||
end,
|
||||
can_insert = function(pos, node, stack, direction)
|
||||
local dir = facedir_to_right_dir(node.param2)
|
||||
if dir.x == direction.x and dir.y == direction.y and dir.z == direction.z then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end},
|
||||
description = "One way tube",
|
||||
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"},
|
||||
paramtype2 = "facedir",
|
||||
drawtype = "nodebox",
|
||||
paramtype = "light",
|
||||
node_box = {type = "fixed",
|
||||
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},
|
||||
legacy_facedir_simple = true,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_construct = function(pos)
|
||||
minetest.get_meta(pos):set_int("tubelike", 1)
|
||||
end,
|
||||
after_place_node = function(pos)
|
||||
pipeworks.scan_for_tube_objects(pos)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
pipeworks.scan_for_tube_objects(pos)
|
||||
end,
|
||||
tube = {connect_sides = {left = 1, right = 1},
|
||||
can_go = function(pos, node, velocity, stack)
|
||||
return velocity
|
||||
end,
|
||||
insert_object = function(pos, node, stack, direction)
|
||||
item1 = pipeworks.tube_item(pos, stack)
|
||||
item1:get_luaentity().start_pos = pos
|
||||
item1:setvelocity({x = direction.x*direction.speed, y = direction.y*direction.speed, z = direction.z*direction.speed})
|
||||
item1:setacceleration({x = 0, y = 0, z = 0})
|
||||
return ItemStack("")
|
||||
end,
|
||||
can_insert = function(pos, node, stack, direction)
|
||||
local dir = facedir_to_right_dir(node.param2)
|
||||
if dir.x == direction.x and dir.y == direction.y and dir.z == direction.z then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end},
|
||||
})
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user