Compare commits

...

5 Commits

Author SHA1 Message Date
khonkhortisan 7ca0ac3cbc Stealing notice 2013-04-05 23:14:14 -07:00
khonkhortisan c4c03bc406 Face awareness 2013-04-05 23:08:09 -07:00
khonkhortisan 9f6c28d8a9 Forgot some textures 2013-04-05 23:07:54 -07:00
khonkhortisan a34e1e894a Fix a should've-been-obvious mistake 2013-03-31 15:14:49 -07:00
khonkhortisan 317c6b5d7d Unscratch formspec (use inventory cubes) 2013-03-30 23:12:27 -07:00
5 changed files with 155 additions and 27 deletions

182
init.lua
View File

@ -48,19 +48,60 @@ local function set_cubelet_formspec(pos, size)
meta:set_string("formspec",
"size["..size..","..size.."]"..
"image_button_exit[0,0;1,1;rubiks_larger.png;larger;]"..
"image_button_exit[0,1;1,1;rubiks_reset.png;reset;]"..
"image_button_exit[0,0;1,1;"..minetest.inventorycube(
tiles[1]..'^rubiks_four.png',
tiles[6]..'^rubiks_four.png',
tiles[3]..'^rubiks_four.png')..
";larger;]"..
"image_button_exit[0,1;1,1;"..minetest.inventorycube(
spawntex[1],
spawntex[6],
spawntex[3])..
";reset;]"..
--"image_button_exit[0,2;1,1;rubiks_scramble.png;scramble;]"..
--"image_button_exit[0,2;1,1;rubiks_smaller.png;smaller;]"..
"image_button_exit[0,2;1,1;"..cubetex[6]..";smaller;]"..
"image_button_exit[0,2;1,1;"..minetest.inventorycube(
tiles[1]..'^rubiks_two.png',
tiles[6]..'^rubiks_two.png',
tiles[3]..'^rubiks_two.png')..
";smaller;]"..
"image_button_exit[1,0;1,1;"..minetest.inventorycube(
spawntex[1],
spawntex[4],
spawntex[6])..
";L3;]"..
"image_button_exit[1,1;1,1;"..minetest.inventorycube(
spawntex[1],
tiles[6]..'^rubiks_with_orange.png^rubiks_three.png',
tiles[3]..'^rubiks_with_yellow.png^rubiks_three.png')..
";L1;]"..
"image_button_exit[1,2;1,1;"..minetest.inventorycube(
spawntex[1],
tiles[6]..'^rubiks_with_orange.png^rubiks_three.png^[transformR180',
tiles[3]..'^rubiks_with_yellow.png^rubiks_three.png^[transformR180')..
";L2;]"..
"image_button_exit[1,0;1,1;rubiks_L3.png;L3;]"..
"image_button_exit[1,1;1,1;rubiks_L1.png;L1;]"..
"image_button_exit[1,2;1,1;rubiks_L2.png;L2;]"..
"image_button_exit[2,0;1,1;rubiks_R3.png;R3;]"..
"image_button_exit[2,1;1,1;rubiks_R1.png;R1;]"..
"image_button_exit[2,2;1,1;rubiks_R2.png;R2;]"..
"image_button_exit[2,0;1,1;"..minetest.inventorycube(
spawntex[1],
spawntex[3],
spawntex[5])..
";R3;]"..
"image_button_exit[2,1;1,1;"..minetest.inventorycube(
spawntex[1],
tiles[6]..'^rubiks_with_red.png^rubiks_three.png',
tiles[3]..'^rubiks_with_white.png^rubiks_three.png')..
";R1;]"..
"image_button_exit[2,2;1,1;"..minetest.inventorycube(
spawntex[1],
tiles[6]..'^rubiks_with_red.png^rubiks_three.png^[transformR180',
tiles[3]..'^rubiks_with_white.png^rubiks_three.png^[transformR180')..
";R2;]"..
'')
end
end
@ -185,9 +226,11 @@ local function rotate_cube(pos, dir, clockwise, layer)
axes[2] = 1--x
end
sign = true
if dir.x == -1 or dir.y == -1 or dir.z == -1 then
clockwise = not clockwise
--still clockwise, just from the opposite perspective
sign = false
end
--start rotating
@ -212,10 +255,14 @@ local function rotate_cube(pos, dir, clockwise, layer)
if dir.x ~= 0 then turnaxis = 1
elseif dir.y ~= 0 then turnaxis = 2
else turnaxis = 3 end
--print(minetest.registered_nodes['rubiks:cubelet'].tiles[getface(loadcubelet.node.param2, turnaxis, negative)])
--place it
minetest.env:add_node(pos2, {name = name, param2 =
axisRotate(loadcubelet.node.param2, turnaxis, clockwise and 90 or -90)
})
--
--print(colors[getface(loadcubelet.node.param2, turnaxis, sign)])
--
local meta = minetest.env:get_meta(pos2)
meta:from_table(loadcubelet.meta)
end
@ -294,6 +341,12 @@ for rotations = 1, 6 do
minetest.register_alias('rubiks:cubelet'..rotations, 'rubiks:cubelet')
end
--Stealable Code
--You may edit this for coding style
--Do not use this in your mod. This is for sharing only.
--Put this somewhere where all modders can get to it
-------------------------------------------------------------------------------
function axisRotate(facedir, turnaxis, turnrot)
turnrot = math.floor(turnrot / 90) % 4
axis = math.floor(facedir / 4)
@ -304,12 +357,14 @@ function axisRotate(facedir, turnaxis, turnrot)
rot = (rot + turnrot) % 4
else
for r = 0, turnrot-1 do
if axis == 0 then axis = 1
elseif axis == 1 then axis = 5
rot=rot+2
elseif axis == 5 then axis = 2
rot=rot-2
else--[[axis == 2 then]]axis = 0
if axis == 0 then axis = 1
elseif axis == 1 then axis = 5
rot=(rot+2)%4
elseif axis == 5 then axis = 2
rot=(rot-2)%4
elseif axis == 2 then axis = 0
else
error("axisRotate: my bad")
end
end
end
@ -319,26 +374,99 @@ function axisRotate(facedir, turnaxis, turnrot)
rot = (rot + turnrot) % 4
else
for r = 0, turnrot-1 do
if axis == 1 then axis = 3
elseif axis == 3 then axis = 2
elseif axis == 2 then axis = 4
else--[[axis == 4 then]]axis = 1
if axis == 1 then axis = 3
elseif axis == 3 then axis = 2
elseif axis == 2 then axis = 4
elseif axis == 4 then axis = 1
else
error("axisRotate: my bad")
end rot = (rot + 1) % 4
end
end
elseif turnaxis == 3 then --z
if 1 == axis or axis == 2 then
if axis == 4 then turnrot = -turnrot end
if axis == 2 then turnrot = -turnrot end
rot = (rot + turnrot) % 4
else
for r = 0, turnrot-1 do
if axis == 0 then axis = 4
elseif axis == 4 then axis = 5
elseif axis == 5 then axis = 3
else--[[axis == 3 then]]axis = 0
if axis == 0 then axis = 4
elseif axis == 4 then axis = 5
elseif axis == 5 then axis = 3
elseif axis == 3 then axis = 0
else
error("axisRotate: my bad")
end
end
end
else
error("axisRotate: turnaxis not 1-3")
end
return --[[facedir = ]] axis * 4 + rot
facedir = axis * 4 + rot
return facedir
end
local function rotfaces(faces, turnaxis, turnrot)
turnrot = turnrot % 4
for r = 0, turnrot-1 do
if turnaxis == 1 then --x
torot = {1, 5, 2, 6}
elseif turnaxis == 2 then --y
torot = {6, 4, 5, 3}
elseif turnaxis == 3 then --z
torot = {1, 4, 2, 3}
else
error("rotfaces: turnaxis: my bad")
end
wraparound = faces[torot[3]]
faces[torot[3]] = faces[torot[2]]
faces[torot[2]] = faces[torot[1]]
faces[torot[1]] = wraparound
end
return faces
end
function getfaces(facedir)
--FIXME?
--tiles ±Y±X±Z
--facedir axes +Y±Z±X-Y
axis = math.floor(facedir / 4)
rot = facedir % 4
-- +Y -Y +X -X +Z -Z
faces = {1, 2, 3, 4, 5, 6}
if axis == 0 then -- +Y
turnaxis = 2
elseif axis == 1 then -- +Z
faces = rotfaces(faces, 1, 1) -- +X
turnaxis = 3
elseif axis == 2 then -- -Z
faces = rotfaces(faces, 1, -1) -- -X
turnaxis = 3
rot = -rot
elseif axis == 3 then -- +X
faces = rotfaces(faces, 3, -1) -- -Z
turnaxis = 1
elseif axis == 4 then -- -X
faces = rotfaces(faces, 3, 1) -- +Z
turnaxis = 1
rot = -rot
elseif axis == 5 then -- -Y
faces = rotfaces(faces, 3, 2)-- ±Z
turnaxis = 2
rot = -rot
else
error("getfaces: bad facedir: "..facedir..' '..axis..' '..rot)
end
return rotfaces(faces, turnaxis, rot)
end
function getface(facedir, axis, sign)
faces = getfaces(facedir)
return faces[
axis == 1 and (sign and 3 or 4) or (
axis == 2 and (sign and 1 or 2) or (
axis == 3 and (sign and 5 or 6)
)
)
]
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB