Add pack controller
This commit is contained in:
parent
bec48ca37f
commit
b917f63dc0
@ -692,13 +692,7 @@ function flylib.rotate_nodes(pos, posses1, rot)
|
||||
|
||||
for i, pos1 in ipairs(posses1) do
|
||||
local node = techage.get_node_lvm(pos1)
|
||||
if rot == "l" then
|
||||
param2 = techage.param2_turn_right(node.param2)
|
||||
elseif rot == "r" then
|
||||
param2 = techage.param2_turn_left(node.param2)
|
||||
else
|
||||
param2 = techage.param2_turn_right(techage.param2_turn_right(node.param2))
|
||||
end
|
||||
param2 = techage.rotate_param2(node, rot)
|
||||
if not minetest.is_protected(pos1, owner) and is_simple_node(pos1) then
|
||||
minetest.remove_node(pos1)
|
||||
nodes2[#nodes2 + 1] = {pos = posses2[i], name = node.name, param2 = param2}
|
||||
|
@ -64,6 +64,10 @@ local FACEDIR_TO_ROT = {[0] =
|
||||
{x=0.000000, y=4.712389, z=3.141593},
|
||||
}
|
||||
|
||||
-- 0 1 2 3 4 5
|
||||
local WALLMOUNTED_TO_RIGHT = {[0]=0, 1, 5, 4, 2, 3}
|
||||
local WALLMOUNTED_TO_LEFT = {[0]=0, 1, 4, 5, 3, 2}
|
||||
|
||||
local RotationViaYAxis = {}
|
||||
|
||||
for _,row in ipairs(ROTATION) do
|
||||
@ -80,11 +84,11 @@ function techage.facedir_to_rotation(facedir)
|
||||
end
|
||||
|
||||
function techage.param2_turn_left(param2)
|
||||
return (RotationViaYAxis[param2] or RotationViaYAxis[0])[2]
|
||||
return (RotationViaYAxis[param2] or RotationViaYAxis[0])[1]
|
||||
end
|
||||
|
||||
function techage.param2_turn_right(param2)
|
||||
return (RotationViaYAxis[param2] or RotationViaYAxis[0])[1]
|
||||
return (RotationViaYAxis[param2] or RotationViaYAxis[0])[2]
|
||||
end
|
||||
|
||||
-- Roll a block in north direction (south is vice versa)
|
||||
@ -133,6 +137,91 @@ end
|
||||
-------------------------------------------------------------------------------
|
||||
-- Rotate nodes around the center
|
||||
-------------------------------------------------------------------------------
|
||||
-- turn is one of "l", "r", "2l", "2r", or ""
|
||||
function techage.rotate_param2(node, turn)
|
||||
print("calc_node_param2", turn)
|
||||
local ndef = minetest.registered_nodes[node.name]
|
||||
if ndef then
|
||||
print("calc_node_param2", ndef.paramtype2)
|
||||
if ndef.paramtype2 == "facedir" then
|
||||
if turn == "l" then
|
||||
return techage.param2_turn_left(node.param2)
|
||||
elseif turn == "r" then
|
||||
return techage.param2_turn_right(node.param2)
|
||||
elseif turn == "" then
|
||||
return node.param2
|
||||
else
|
||||
return techage.param2_turn_right(techage.param2_turn_right(node.param2))
|
||||
end
|
||||
elseif ndef.paramtype2 == "colorfacedir" then
|
||||
local param2 = math.floor(node.param2 % 32)
|
||||
if turn == "l" then
|
||||
param2 = techage.param2_turn_left(param2)
|
||||
elseif turn == "r" then
|
||||
param2 = techage.param2_turn_right(param2)
|
||||
elseif turn == "" then
|
||||
param2 = param2
|
||||
else
|
||||
param2 = techage.param2_turn_right(param2)
|
||||
param2 = techage.param2_turn_right(param2)
|
||||
end
|
||||
-- Add color again
|
||||
return math.floor(node.param2 / 32) * 32 + param2
|
||||
elseif ndef.paramtype2 == "wallmounted" then
|
||||
if turn == "l" then
|
||||
return WALLMOUNTED_TO_LEFT[node.param2]
|
||||
elseif turn == "r" then
|
||||
return WALLMOUNTED_TO_RIGHT[node.param2]
|
||||
elseif turn == "" then
|
||||
return node.param2
|
||||
else
|
||||
return WALLMOUNTED_TO_RIGHT[WALLMOUNTED_TO_RIGHT[node.param2]]
|
||||
end
|
||||
elseif ndef.paramtype2 == "colorwallmounted" then
|
||||
local param2 = math.floor(node.param2 % 8)
|
||||
if turn == "l" then
|
||||
param2 = WALLMOUNTED_TO_LEFT[param2]
|
||||
elseif turn == "r" then
|
||||
param2 = WALLMOUNTED_TO_RIGHT[param2]
|
||||
elseif turn == "" then
|
||||
param2 = param2
|
||||
else
|
||||
param2 = WALLMOUNTED_TO_RIGHT[param2]
|
||||
param2 = WALLMOUNTED_TO_RIGHT[param2]
|
||||
end
|
||||
-- Add color again
|
||||
return math.floor(node.param2 / 8) * 8 + param2
|
||||
elseif ndef.paramtype2 == "degrotate" then
|
||||
local rot = (node.param2 * 1.5) + 360
|
||||
if turn == "l" then
|
||||
rot = rot + 90
|
||||
elseif turn == "r" then
|
||||
rot = rot - 90
|
||||
elseif turn == "" then
|
||||
rot = rot + 0
|
||||
else
|
||||
rot = rot + 180
|
||||
end
|
||||
return math.floor((rot % 360) / 1.5)
|
||||
elseif ndef.paramtype2 == "colordegrotate" then
|
||||
local param2 = node.param2 % 32
|
||||
local rot = (param2 * 15) + 360
|
||||
if turn == "l" then
|
||||
rot = rot + 90
|
||||
elseif turn == "r" then
|
||||
rot = rot - 90
|
||||
elseif turn == "" then
|
||||
rot = rot + 0
|
||||
else
|
||||
rot = rot + 180
|
||||
end
|
||||
-- Add color again
|
||||
return math.floor(node.param2 / 32) * 32 + math.floor((rot % 360) / 15)
|
||||
end
|
||||
end
|
||||
return node.param2
|
||||
end
|
||||
|
||||
function techage.positions_center(lpos)
|
||||
local c = {x=0, y=0, z=0}
|
||||
for _,v in ipairs(lpos) do
|
||||
|
@ -85,6 +85,14 @@ local function on_unpack_fallback(pos, name, param2, data)
|
||||
end
|
||||
end
|
||||
|
||||
-- cpos is the center pos
|
||||
-- npos the the node pos
|
||||
-- turn is one of "l", "r", "2l", "2r"
|
||||
local function get_new_node_pos(cpos, npos, turn, item)
|
||||
item.param2 = techage.rotate_param2(item, turn)
|
||||
return techage.rotate_around_axis(npos, cpos, turn)
|
||||
end
|
||||
|
||||
-- pack/unpack API functions
|
||||
function techage.pack_nodes(pos, pos_list)
|
||||
print("pack_nodes", P2S(pos), #pos_list)
|
||||
@ -103,14 +111,32 @@ function techage.pack_nodes(pos, pos_list)
|
||||
return tbl
|
||||
end
|
||||
|
||||
function techage.unpack_nodes(pos, tbl)
|
||||
function techage.unpack_nodes(pos, tbl, turn)
|
||||
print("unpack_nodes", P2S(pos), turn)
|
||||
-- Check positions
|
||||
for rpos, item in pairs(tbl or {}) do
|
||||
local pos2 = vector.add(pos, rpos)
|
||||
pos2 = techage.rotate_around_axis(pos2, pos, turn)
|
||||
local node = minetest.get_node(pos2)
|
||||
if not techage.is_air_like(node.name) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
-- Place nodes
|
||||
local out = {}
|
||||
for rpos, item in pairs(tbl or {}) do
|
||||
local pos2 = vector.add(pos, rpos)
|
||||
item.param2 = techage.rotate_param2(item, turn)
|
||||
pos2 = techage.rotate_around_axis(pos2, pos, turn)
|
||||
local ndef = minetest.registered_nodes[item.name]
|
||||
if ndef and ndef.on_unpack then
|
||||
ndef.on_unpack(pos2, item.name, item.param2, item.data)
|
||||
else
|
||||
on_unpack_fallback(pos2, item.name, item.param2, item.data)
|
||||
end
|
||||
-- Because of the rotated arrangement, generate a new rel-pos table
|
||||
table.insert(out, vector.subtract(pos2, pos))
|
||||
end
|
||||
return out
|
||||
end
|
||||
|
||||
|
@ -1403,7 +1403,7 @@ TA5 Turbine=TA5 Turbine
|
||||
|
||||
### turncontroller.lua ###
|
||||
|
||||
Click on all blocks that shall be turned=Klicke auf all Blöcke, die gedreht werden sollen
|
||||
Click on all blocks that shall be turned=Klicke auf alle Blöcke, die gedreht werden sollen
|
||||
TA4 Turn Controller=TA4 Dreh Controller
|
||||
Turn left=Drehe links
|
||||
Turn right=Drehe rechts
|
||||
|
@ -40,7 +40,7 @@ local function formspec(nvm, meta)
|
||||
"button[4.1,2.1;3.8,1;done;" .. S("Done") .. "]" ..
|
||||
"button[0.1,2.9;3.8,1;pack;" .. S("Pack") .. "]" ..
|
||||
"button[4.1,2.9;3.8,1;unpack;" .. S("Unpack") .. "]" ..
|
||||
"label[0.3,9;" .. status .. "]"
|
||||
"label[0.3,3.9;" .. status .. "]"
|
||||
end
|
||||
|
||||
local function get_rposlist(pos, pos_list)
|
||||
@ -53,21 +53,24 @@ local function get_rposlist(pos, pos_list)
|
||||
end
|
||||
|
||||
local function set_storage_pos(pos, oldnode, oldmetadata, drops)
|
||||
local meta = drops[1]:get_meta()
|
||||
meta:set_string("storage_pos", P2S(pos))
|
||||
meta:set_string("node_name", (oldmetadata.node_name or ""))
|
||||
meta:set_string("description", DESCRIPTION .. ' "' .. (oldmetadata.node_name or "") .. '"')
|
||||
if oldmetadata.data_stored == "1" then
|
||||
local meta = drops[1]:get_meta()
|
||||
meta:set_string("storage_pos", P2S(pos))
|
||||
meta:set_string("node_name", oldmetadata.node_name or "")
|
||||
meta:set_string("status", oldmetadata.status or "")
|
||||
meta:set_int("data_stored", 1)
|
||||
meta:set_string("description", DESCRIPTION .. ' "' .. (oldmetadata.node_name or "") .. '"')
|
||||
end
|
||||
end
|
||||
|
||||
local function get_storage_pos(pos, nvm, itemstack)
|
||||
print("get_storage_pos")
|
||||
local imeta = itemstack:get_meta()
|
||||
if imeta then
|
||||
print("get_storage_pos2")
|
||||
local meta = M(pos)
|
||||
meta:set_string("node_name", imeta:get_string("node_name"))
|
||||
meta:set_string("status", imeta:get_string("status"))
|
||||
meta:set_int("data_stored", imeta:get_int("data_stored"))
|
||||
nvm.storage_pos = S2P(imeta:get_string("storage_pos"))
|
||||
print("get_storage_pos3", dump(nvm))
|
||||
return nvm.storage_pos ~= nil
|
||||
end
|
||||
end
|
||||
@ -81,12 +84,24 @@ local function copy_data_and_remove_node(mypos, rmtpos)
|
||||
techage.del_mem(rmtpos)
|
||||
end
|
||||
|
||||
local function determine_rotation(old_param2, new_param2)
|
||||
local offs = new_param2 - old_param2
|
||||
print("determine_rotation", offs)
|
||||
if offs == 0 then return ""
|
||||
elseif offs == -1 then return "l"
|
||||
elseif offs == 1 then return "r"
|
||||
else return "2r" end
|
||||
end
|
||||
|
||||
local function after_place_node(pos, placer, itemstack)
|
||||
local meta = M(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
meta:set_string("infotext", DESCRIPTION)
|
||||
meta:set_string("owner", placer:get_player_name())
|
||||
if get_storage_pos(pos, nvm, itemstack) then
|
||||
if techage.get_node_lvm(nvm.storage_pos).name == "techage:ta5_packcontainer_storage" then
|
||||
local node = techage.get_node_lvm(nvm.storage_pos)
|
||||
if node.name == "techage:ta5_packcontainer_storage" then
|
||||
nvm.turn = determine_rotation(node.param2, minetest.get_node(pos).param2)
|
||||
copy_data_and_remove_node(pos, nvm.storage_pos)
|
||||
nvm.storage_pos = nil
|
||||
end
|
||||
@ -101,18 +116,19 @@ local function on_receive_fields(pos, formname, fields, player)
|
||||
|
||||
local meta = M(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local data_stored = meta:get_int("data_stored") == 1
|
||||
|
||||
if fields.record then
|
||||
nvm.lrpos = {}
|
||||
if fields.record and not data_stored then
|
||||
nvm.lrpos = nil
|
||||
meta:set_string("status", S("Recording..."))
|
||||
local name = player:get_player_name()
|
||||
minetest.chat_send_player(name, S("Click on all blocks that shall be turned"))
|
||||
mark.start(name, MAX_BLOCKS)
|
||||
meta:set_string("formspec", formspec(nvm, meta))
|
||||
elseif fields.store then
|
||||
elseif fields.store and not data_stored then
|
||||
meta:set_string("node_name", fields.node_name)
|
||||
meta:set_string("formspec", formspec(nvm, meta))
|
||||
elseif fields.done then
|
||||
elseif fields.done and not data_stored then
|
||||
local name = player:get_player_name()
|
||||
local pos_list = mark.get_poslist(name)
|
||||
local text = #pos_list.." "..S("block positions are stored.")
|
||||
@ -122,20 +138,23 @@ local function on_receive_fields(pos, formname, fields, player)
|
||||
mark.unmark_all(name)
|
||||
mark.stop(name)
|
||||
meta:set_string("formspec", formspec(nvm, meta))
|
||||
elseif fields.pack then
|
||||
elseif fields.pack and nvm.lrpos and #nvm.lrpos > 0 and not data_stored then
|
||||
nvm.pack_tbl = techage.pack_nodes(pos, nvm.lrpos or {})
|
||||
meta:set_string("status", S("Packed"))
|
||||
meta:set_string("status", S("Blocks stored"))
|
||||
meta:set_string("formspec", formspec(nvm, meta))
|
||||
meta:set_int("data_stored", 1)
|
||||
local name = player:get_player_name()
|
||||
mark.stop(name)
|
||||
elseif fields.unpack then
|
||||
techage.unpack_nodes(pos, nvm.pack_tbl)
|
||||
meta:set_string("status", S("Unpacked"))
|
||||
meta:set_string("formspec", formspec(nvm, meta))
|
||||
meta:set_int("data_stored", 0)
|
||||
local name = player:get_player_name()
|
||||
mark.stop(name)
|
||||
elseif fields.unpack and data_stored then
|
||||
local tbl = techage.unpack_nodes(pos, nvm.pack_tbl, nvm.turn or "")
|
||||
if tbl then
|
||||
nvm.lrpos = tbl
|
||||
meta:set_string("status", S("Blocks placed"))
|
||||
meta:set_string("formspec", formspec(nvm, meta))
|
||||
meta:set_int("data_stored", 0)
|
||||
nvm.turn = ""
|
||||
else
|
||||
meta:set_string("status", S("Position(s) occupied"))
|
||||
meta:set_string("formspec", formspec(nvm, meta))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -145,7 +164,9 @@ local function after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
mark.stop(name)
|
||||
|
||||
if oldmetadata.fields.data_stored == "1" then
|
||||
minetest.set_node(pos, {name = "techage:ta5_packcontainer_storage"})
|
||||
minetest.set_node(pos, {name = "techage:ta5_packcontainer_storage", param2 = oldnode.param2})
|
||||
local owner = oldmetadata.fields.owner or ""
|
||||
M(pos):set_string("infotext", S("@1's @2 storage", owner, DESCRIPTION))
|
||||
else
|
||||
techage.del_mem(pos)
|
||||
end
|
||||
@ -155,9 +176,9 @@ minetest.register_node("techage:ta5_packcontainer", {
|
||||
description = DESCRIPTION,
|
||||
tiles = {
|
||||
-- up, down, right, left, back, front
|
||||
"techage_filling_ta4.png^techage_frame_ta5_top.png^techage_appl_arrow.png",
|
||||
"techage_filling_ta4.png^techage_frame_ta5_top.png",
|
||||
"techage_filling_ta4.png^techage_frame_ta5_top.png",
|
||||
"techage_filling_ta4.png^techage_frame_ta5.png^techage_appl_turn.png",
|
||||
"techage_filling_ta4.png^techage_frame_ta5.png^techage_appl_pack.png",
|
||||
},
|
||||
after_place_node = after_place_node,
|
||||
on_receive_fields = on_receive_fields,
|
||||
@ -195,20 +216,18 @@ minetest.register_node("techage:ta5_packcontainer_storage", {
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{ -11/32, -1/2, -11/32, 11/32, -5/16, 11/32},
|
||||
{ -5/16, -8/16, -5/16, 5/16, -5/16, 5/16},
|
||||
},
|
||||
},
|
||||
tiles = {
|
||||
-- up, down, right, left, back, front
|
||||
"signs_bot_sensor2.png^signs_bot_sensor_bot.png",
|
||||
"signs_bot_sensor2.png",
|
||||
"signs_bot_sensor2.png",
|
||||
"signs_bot_sensor2.png",
|
||||
"signs_bot_sensor2.png",
|
||||
"signs_bot_sensor2.png",
|
||||
"techage_pack_storage.png",
|
||||
},
|
||||
paramtype2 = "facedir",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
light_source = 5,
|
||||
glow = 12,
|
||||
use_texture_alpha = techage.CLIP,
|
||||
is_ground_content = false,
|
||||
on_blast = function() end,
|
||||
|
BIN
textures/techage_appl_pack.png
Normal file
BIN
textures/techage_appl_pack.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 245 B |
BIN
textures/techage_pack_storage.png
Normal file
BIN
textures/techage_pack_storage.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 635 B |
@ -69,7 +69,8 @@ local function turn_node_param2(pos, node, ndef, user)
|
||||
end
|
||||
|
||||
local function turn_left(pos, node, ndef)
|
||||
local param2 = techage.param2_turn_left(node.param2)
|
||||
-- Turn face left means turn block right
|
||||
local param2 = techage.param2_turn_right(node.param2)
|
||||
if ndef.ta_rotate_node then
|
||||
ndef.ta_rotate_node(pos, node, param2)
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user