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_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 = {
@ -92,10 +38,11 @@ local function deployer_on(pos, node)
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,
})

View File

@ -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
@ -363,7 +363,6 @@ minetest.register_entity("pipeworks:tubed_item", {
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,
@ -399,60 +398,57 @@ minetest.register_entity("pipeworks:tubed_item", {
local pos = self.object:getpos()
local node = minetest.get_node(pos)
local meta = minetest.get_meta(pos)
tubelike=meta:get_int("tubelike")
local tubelike = meta:get_int("tubelike")
local stack = ItemStack(self.itemstring)
local drop_pos=nil
local drop_pos = nil
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 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 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 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
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)
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)
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
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}
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
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)
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
velocity.x = -velocity.x
velocity.y = -velocity.y
velocity.z = -velocity.z
self.object:setvelocity(velocity)
self:set_item(leftover:to_string())
return
@ -460,7 +456,7 @@ minetest.register_entity("pipeworks:tubed_item", {
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")
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()
@ -473,8 +469,7 @@ minetest.register_entity("pipeworks:tubed_item", {
self.object:setpos(self.start_pos)
self.object:setvelocity(velocity)
end
end
end
})
if minetest.get_modpath("mesecons_mvps") ~= nil then

View File

@ -606,6 +606,9 @@ if pipeworks.enable_one_way_tube then
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,