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

@ -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,7 +398,7 @@ 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
@ -443,9 +442,6 @@ minetest.register_entity("pipeworks:tubed_item", {
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
@ -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,7 +469,6 @@ minetest.register_entity("pipeworks:tubed_item", {
self.object:setpos(self.start_pos)
self.object:setvelocity(velocity)
end
end
})

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,