aboutsummaryrefslogtreecommitdiff
path: root/advtrains/textures/advtrains_signal_off.png
blob: 8046e524f1e51daac2018d9232139a4956a04b49 (plain)
ofshex dumpascii
0000 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 04 00 00 00 04 00 08 06 00 00 00 7f 1d 2b .PNG........IHDR...............+
0020 83 00 00 00 06 62 4b 47 44 00 ff 00 ff 00 ff a0 bd a7 93 00 00 00 09 70 48 59 73 00 00 0b 13 00 .....bKGD..............pHYs.....
0040 00 0b 13 01 00 9a 9c 18 00 00 00 07 74 49 4d 45 07 e0 09 0d 0e 33 01 ac 18 73 22 00 00 16 87 49 ............tIME.....3...s"....I
0060 44 41 54 78 da ed dc c1 4d c3 40 10 86 51 40 5b 80 2b 98 42 9c 74 b0 94 4b 5c 82 0b 99 0a dc 01 DATx....M.@..Q@[.+.B.t..K\......
0080 dc 22 24 4e 48 1b 18 67 df ab c0 fa 0f 7b f8 34 f2 6b ef fd f3 05 00 00 00 78 6a 6f 26 00 00 00 ."$NH..g.....{.4.k.......xjo&...
00a0 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 ................................
00c0 00 00 01 00 00 00 00 10 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 ............@..........@........
00e0 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 10 00 00 00 00 00 01 00 ..@..........@..................
0100 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 ................................
0120 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 .........@..........@..........@
0140 00 00 00 00 00 c6 68 26 00 aa c9 4c 23 c0 83 44 84 11 00 60 52 2e 00 00 00 00 40 00 00 00 00 00 ......h&...L#..D...`R.....@.....
0160 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 .....@..........@..........@....
0180 00 04 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 ................................
01a0 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 .......................@........
01c0 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 01 c0 ..@..........@..........@.......
01e0 04 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 ................................
0200 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 ................................
0220 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 02 00 00 00 ................................
0240 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 ................................
0260 00 00 20 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 9c 40 33 01 00 00 c0 58 .........................@3....X
0280 99 69 04 ee 22 a2 c4 77 b8 00 00 00 00 80 09 08 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 .i.."..w........................
02a0 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 ................................
02c0 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 ................................
02e0 00 08 00 00 00 00 80 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 ................................
0300 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 80 00 60 02 00 00 00 78 7e .........................`....x~
0320 cd 04 00 00 30 de c7 ed 66 84 82 de 7b 37 02 d3 72 01 00 00 00 00 02 00 00 00 00 20 00 00 00 00 ....0...f...{7..r...............
0340 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 ................................
0360 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 ................................
0380 00 00 80 00 00 00 00 00 08 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 ................................
03a0 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 08 00 26 00 00 00 00 ...........................&....
03c0 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 ................................
03e0 00 01 00 00 00 00 10 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 ...........@..........@.........
0400 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 10 00 00 00 00 00 01 00 00 .@..........@...................
0420 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 ................................
0440 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 ........@..........@..........@.
0460 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 .........@......................
0480 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 ................................
04a0 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 .....@..........@..........@....
04c0 00 04 00 00 00 00 40 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 ......@.........................
04e0 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 04 00 00 ................................
0500 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 ..@..........@..........@.......
0520 00 00 00 e0 87 66 02 00 60 b4 e3 38 8c 00 4c f9 3e 2d cb 62 64 ca 72 01 00 00 00 00 13 70 01 00 .....f..`..8..L.>-.bd.r......p..
0540 00 00 0f 70 bd 5c 8c 00 94 e2 02 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 ...p.\..............@..........@
0560 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 01 00 00 00 00 ..........@..........@..........
0580 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 ................................
05a0 00 10 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 ......@..........@..........@...
05c0 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 10 00 4c 00 00 00 00 02 00 00 00 00 20 00 .......@............L...........
05e0 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 ................................
0600 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 ................................
0620 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 ................................
0640 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 08 00 00 00 ................................
0660 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 ................................
0680 00 00 80 00 00 00 00 00 08 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 ................................
06a0 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 08 00 00 00 00 80 00 ................................
06c0 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 ................................
06e0 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 ................................
0700 20 00 00 00 00 00 43 34 13 00 d5 44 84 11 00 00 60 30 17 00 00 00 00 20 00 00 00 00 00 02 00 00 ......C4...D....`0..............
0720 00 00 70 0a fe 01 00 9c ce ba ae 46 80 e2 b6 6d 33 02 00 14 e3 02 00 00 00 00 04 00 00 00 00 40 ..p........F...m3..............@
0740 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 ..........@..........@..........
0760 40 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 @...............................
0780 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 .................@..........@...
07a0 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 10 00 4c .......@..........@............L
07c0 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 ................................
07e0 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 ................................
0800 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 20 00 00 00 00 ................................
0820 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 ................................
0840 00 00 02 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 ................................
0860 00 00 c0 9f 68 26 00 00 00 18 2b 22 8c 40 39 2e 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 ....h&....+".@9.....@..........@
0880 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 ..........@..........@..........
08a0 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 ................................
08c0 00 10 00 00 00 00 00 01 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 .................@..........@...
08e0 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 01 c0 04 00 00 00 20 00 .......@..........@.............
0900 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 ................................
0920 00 00 00 00 00 02 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 ................................
0940 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 ................................
0960 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 ................................
0980 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 ................................
09a0 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 ................................
09c0 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 80 00 ................................
09e0 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 ................................
0a00 00 00 00 00 00 08 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 ................................
0a20 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 80 00 00 00 00 ................................
0a40 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 ................................
0a60 00 00 08 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 ................................
0a80 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 ................................
0aa0 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 ................................
0ac0 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 ................................
0ae0 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 ................................
0b00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 02 00 00 00 ................................
0b20 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 ................................
0b40 00 00 20 00 00 00 00 00 02 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 ................................
0b60 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 02 00 00 00 00 20 00 ................................
0b80 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 ................................
0ba0 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 ................................
0bc0 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 ................................
0be0 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 ................................
0c00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 ................................
0c20 00 00 80 00 00 00 00 00 08 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 ................................
0c40 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 80 00 ................................
0c60 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 ................................
0c80 00 00 00 00 00 08 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 ................................
0ca0 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 08 00 00 00 00 80 00 00 00 00 ................................
0cc0 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 ................................
0ce0 00 00 08 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 ................................
0d00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 ................................
0d20 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 02 ................................
0d40 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 ................................
0d60 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 ................................
0d80 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 02 00 00 00 ................................
0da0 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 ................................
0dc0 00 00 20 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 ................................
0de0 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 02 00 00 00 00 20 00 ................................
0e00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 ................................
0e20 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 ................................
0e40 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 ................................
0e60 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 08 00 26 00 ..............................&.
0e80 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 ................................
0ea0 00 00 00 00 01 00 00 00 00 10 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 ..............@..........@......
0ec0 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 10 00 00 00 00 00 ....@..........@................
0ee0 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 ................................
0f00 00 01 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 ...........@..........@.........
0f20 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 10 00 00 00 00 00 01 00 00 .@..........@...................
0f40 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 ................................
0f60 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 ........@..........@..........@.
0f80 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 .........@......................
0fa0 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 ................................
0fc0 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 .....@..........@..........@....
0fe0 00 04 00 00 00 00 40 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 ......@.........................
1000 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 40 00 00 00 00 00 04 00 00 .......................@........
1020 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 ..@..........@..........@.......
1040 00 00 00 40 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 ...@............................
1060 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 ....................@..........@
1080 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 ..........@..........@..........
10a0 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 ................................
10c0 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 .................@..........@...
10e0 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 10 00 00 .......@..........@.............
1100 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 ................................
1120 00 00 00 00 01 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 ..............@..........@......
1140 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 10 00 00 00 00 00 ....@..........@................
1160 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 ................................
1180 00 01 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 fe 45 33 01 ...........@..........@......E3.
11a0 00 00 00 95 65 a6 11 06 70 01 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 ....e...p.......................
11c0 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 80 00 00 00 00 00 08 ................................
11e0 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 08 00 00 00 00 80 00 00 00 00 00 ................................
1200 08 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 20 00 00 00 00 ................................
1220 00 02 00 00 00 00 20 00 00 00 00 00 02 00 00 00 00 08 00 26 00 00 00 00 01 00 00 00 00 10 00 00 ...................&............
1240 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 ................................
1260 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 ...@..........@..........@......
1280 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 ....@...........................
12a0 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 04 00 00 00 00 ................................
12c0 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 @..........@..........@.........
12e0 00 40 00 00 00 00 00 04 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 .@..............................
1300 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 04 00 00 00 00 40 00 00 .............................@..
1320 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 ........@..........@..........@.
1340 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 ................................
1360 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 ..........................@.....
1380 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 .....@..........@..........@....
13a0 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 ................................
13c0 00 00 01 00 00 00 00 10 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 ............@..........@........
13e0 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 01 00 ..@..........@..........@.......
1400 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 ................................
1420 00 00 00 00 10 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 .........@..........@..........@
1440 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 ..........@.....................
1460 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 ................................
1480 00 10 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 ......@..........@..........@...
14a0 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 .......@........................
14c0 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 04 00 ................................
14e0 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 ...@..........@..........@......
1500 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 ....@...........................
1520 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 04 00 00 00 00 ................................
1540 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 @..........@..........@.........
1560 00 40 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 .@..............................
1580 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 04 00 00 00 00 40 00 00 .............................@..
15a0 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 ........@..........@..........@.
15c0 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 ................................
15e0 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 ...............@..........@.....
1600 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 .....@..........@..........@....
1620 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 ................................
1640 00 00 01 00 00 00 00 10 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 ............@..........@........
1660 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 10 00 00 00 00 00 01 00 ..@..........@..................
1680 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 00 00 00 00 10 00 00 00 00 00 01 ................................
16a0 00 00 00 00 10 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 04 00 00 00 00 40 .........@..........@..........@
16c0 00 00 00 00 00 04 00 00 00 00 40 00 00 00 00 00 be 69 26 00 ce 66 df 77 23 00 00 c0 2f b9 00 00 ..........@......i&..f.w#.../...
16e0 00 00 80 09 7c 01 4a ff 21 f2 22 67 5a 66 00 00 00 00 49 45 4e 44 ae 42 60 82 ....|.J.!."gZf....IEND.B`.
>1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413
/*
Minetest
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "lua_api/l_object.h"
#include <cmath>
#include "lua_api/l_internal.h"
#include "lua_api/l_inventory.h"
#include "lua_api/l_item.h"
#include "lua_api/l_playermeta.h"
#include "common/c_converter.h"
#include "common/c_content.h"
#include "log.h"
#include "tool.h"
#include "remoteplayer.h"
#include "server.h"
#include "hud.h"
#include "scripting_server.h"
#include "server/luaentity_sao.h"
#include "server/player_sao.h"
#include "server/serverinventorymgr.h"

/*
	ObjectRef
*/


ObjectRef* ObjectRef::checkobject(lua_State *L, int narg)
{
	luaL_checktype(L, narg, LUA_TUSERDATA);
	void *ud = luaL_checkudata(L, narg, className);
	if (ud == nullptr)
		luaL_typerror(L, narg, className);
	return *(ObjectRef**)ud;  // unbox pointer
}

ServerActiveObject* ObjectRef::getobject(ObjectRef *ref)
{
	ServerActiveObject *sao = ref->m_object;
	if (sao && sao->isGone())
		return nullptr;
	return sao;
}

LuaEntitySAO* ObjectRef::getluaobject(ObjectRef *ref)
{
	ServerActiveObject *sao = getobject(ref);
	if (sao == nullptr)
		return nullptr;
	if (sao->getType() != ACTIVEOBJECT_TYPE_LUAENTITY)
		return nullptr;
	return (LuaEntitySAO*)sao;
}

PlayerSAO* ObjectRef::getplayersao(ObjectRef *ref)
{
	ServerActiveObject *sao = getobject(ref);
	if (sao == nullptr)
		return nullptr;
	if (sao->getType() != ACTIVEOBJECT_TYPE_PLAYER)
		return nullptr;
	return (PlayerSAO*)sao;
}

RemotePlayer *ObjectRef::getplayer(ObjectRef *ref)
{
	PlayerSAO *playersao = getplayersao(ref);
	if (playersao == nullptr)
		return nullptr;
	return playersao->getPlayer();
}

// Exported functions

// garbage collector
int ObjectRef::gc_object(lua_State *L) {
	ObjectRef *obj = *(ObjectRef **)(lua_touserdata(L, 1));
	delete obj;
	return 0;
}

// remove(self)
int ObjectRef::l_remove(lua_State *L)
{
	GET_ENV_PTR;

	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *sao = getobject(ref);
	if (sao == nullptr)
		return 0;
	if (sao->getType() == ACTIVEOBJECT_TYPE_PLAYER)
		return 0;

	sao->clearChildAttachments();
	sao->clearParentAttachment();

	verbosestream << "ObjectRef::l_remove(): id=" << sao->getId() << std::endl;
	sao->markForRemoval();
	return 0;
}

// get_pos(self)
int ObjectRef::l_get_pos(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *sao = getobject(ref);
	if (sao == nullptr)
		return 0;

	push_v3f(L, sao->getBasePosition() / BS);
	return 1;
}

// set_pos(self, pos)
int ObjectRef::l_set_pos(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *sao = getobject(ref);
	if (sao == nullptr)
		return 0;

	v3f pos = checkFloatPos(L, 2);

	sao->setPos(pos);
	return 0;
}

// move_to(self, pos, continuous)
int ObjectRef::l_move_to(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *sao = getobject(ref);
	if (sao == nullptr)
		return 0;

	v3f pos = checkFloatPos(L, 2);
	bool continuous = readParam<bool>(L, 3);

	sao->moveTo(pos, continuous);
	return 0;
}

// punch(self, puncher, time_from_last_punch, tool_capabilities, dir)
int ObjectRef::l_punch(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	ObjectRef *puncher_ref = checkobject(L, 2);
	ServerActiveObject *sao = getobject(ref);
	ServerActiveObject *puncher = getobject(puncher_ref);
	if (sao == nullptr || puncher == nullptr)
		return 0;

	float time_from_last_punch = readParam<float>(L, 3, 1000000.0f);
	ToolCapabilities toolcap = read_tool_capabilities(L, 4);
	v3f dir = readParam<v3f>(L, 5, sao->getBasePosition() - puncher->getBasePosition());
	dir.normalize();

	u16 wear = sao->punch(dir, &toolcap, puncher, time_from_last_punch);
	lua_pushnumber(L, wear);

	return 1;
}

// right_click(self, clicker)
int ObjectRef::l_right_click(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	ObjectRef *ref2 = checkobject(L, 2);
	ServerActiveObject *sao = getobject(ref);
	ServerActiveObject *sao2 = getobject(ref2);
	if (sao == nullptr || sao2 == nullptr)
		return 0;

	sao->rightClick(sao2);
	return 0;
}

// set_hp(self, hp, reason)
int ObjectRef::l_set_hp(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *sao = getobject(ref);
	if (sao == nullptr)
		return 0;

	int hp = readParam<float>(L, 2);
	PlayerHPChangeReason reason(PlayerHPChangeReason::SET_HP);

	reason.from_mod = true;
	if (lua_istable(L, 3)) {
		lua_pushvalue(L, 3);

		lua_getfield(L, -1, "type");
		if (lua_isstring(L, -1) &&
				!reason.setTypeFromString(readParam<std::string>(L, -1))) {
			errorstream << "Bad type given!" << std::endl;
		}
		lua_pop(L, 1);

		reason.lua_reference = luaL_ref(L, LUA_REGISTRYINDEX);
	}

	sao->setHP(hp, reason);
	if (reason.hasLuaReference())
		luaL_unref(L, LUA_REGISTRYINDEX, reason.lua_reference);
	return 0;
}

// get_hp(self)
int ObjectRef::l_get_hp(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *sao = getobject(ref);
	if (sao == nullptr) {
		// Default hp is 1
		lua_pushnumber(L, 1);
		return 1;
	}

	int hp = sao->getHP();

	lua_pushnumber(L, hp);
	return 1;
}

// get_inventory(self)
int ObjectRef::l_get_inventory(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *sao = getobject(ref);
	if (sao == nullptr)
		return 0;

	InventoryLocation loc = sao->getInventoryLocation();
	if (getServerInventoryMgr(L)->getInventory(loc) != nullptr)
		InvRef::create(L, loc);
	else
		lua_pushnil(L); // An object may have no inventory (nil)
	return 1;
}

// get_wield_list(self)
int ObjectRef::l_get_wield_list(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *sao = getobject(ref);
	if (sao == nullptr)
		return 0;

	lua_pushstring(L, sao->getWieldList().c_str());
	return 1;
}

// get_wield_index(self)
int ObjectRef::l_get_wield_index(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *sao = getobject(ref);
	if (sao == nullptr)
		return 0;

	lua_pushinteger(L, sao->getWieldIndex() + 1);
	return 1;
}

// get_wielded_item(self)
int ObjectRef::l_get_wielded_item(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *sao = getobject(ref);
	if (sao == nullptr) {
		// Empty ItemStack
		LuaItemStack::create(L, ItemStack());
		return 1;
	}

	ItemStack selected_item;
	sao->getWieldedItem(&selected_item, nullptr);
	LuaItemStack::create(L, selected_item);
	return 1;
}

// set_wielded_item(self, item)
int ObjectRef::l_set_wielded_item(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *sao = getobject(ref);
	if (sao == nullptr)
		return 0;

	ItemStack item = read_item(L, 2, getServer(L)->idef());

	bool success = sao->setWieldedItem(item);
	if (success && sao->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
		getServer(L)->SendInventory((PlayerSAO *)sao, true);
	}
	lua_pushboolean(L, success);
	return 1;
}

// set_armor_groups(self, groups)
int ObjectRef::l_set_armor_groups(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *sao = getobject(ref);
	if (sao == nullptr)
		return 0;

	ItemGroupList groups;

	read_groups(L, 2, groups);
	if (sao->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
		if (!g_settings->getBool("enable_damage") && !itemgroup_get(groups, "immortal")) {
			warningstream << "Mod tried to enable damage for a player, but it's "
				"disabled globally. Ignoring." << std::endl;
			infostream << script_get_backtrace(L) << std::endl;
			groups["immortal"] = 1;
		}
	}

	sao->setArmorGroups(groups);
	return 0;
}

// get_armor_groups(self)
int ObjectRef::l_get_armor_groups(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *sao = getobject(ref);
	if (sao == nullptr)
		return 0;

	push_groups(L, sao->getArmorGroups());
	return 1;
}

// set_animation(self, frame_range, frame_speed, frame_blend, frame_loop)
int ObjectRef::l_set_animation(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *sao = getobject(ref);
	if (sao == nullptr)
		return 0;

	v2f frame_range   = readParam<v2f>(L,  2, v2f(1, 1));
	float frame_speed = readParam<float>(L, 3, 15.0f);
	float frame_blend = readParam<float>(L, 4, 0.0f);
	bool frame_loop   = readParam<bool>(L, 5, true);

	sao->setAnimation(frame_range, frame_speed, frame_blend, frame_loop);
	return 0;
}

// get_animation(self)
int ObjectRef::l_get_animation(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *sao = getobject(ref);
	if (sao == nullptr)
		return 0;

	v2f frames = v2f(1, 1);
	float frame_speed = 15;
	float frame_blend = 0;
	bool frame_loop = true;

	sao->getAnimation(&frames, &frame_speed, &frame_blend, &frame_loop);
	push_v2f(L, frames);
	lua_pushnumber(L, frame_speed);
	lua_pushnumber(L, frame_blend);
	lua_pushboolean(L, frame_loop);
	return 4;
}

// set_local_animation(self, idle, walk, dig, walk_while_dig, frame_speed)
int ObjectRef::l_set_local_animation(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	RemotePlayer *player = getplayer(ref);
	if (player == nullptr)
		return 0;

	v2s32 frames[4];
	for (int i=0;i<4;i++) {
		if (!lua_isnil(L, 2+1))
			frames[i] = read_v2s32(L, 2+i);
	}
	float frame_speed = readParam<float>(L, 6, 30.0f);

	getServer(L)->setLocalPlayerAnimations(player, frames, frame_speed);
	lua_pushboolean(L, true);
	return 1;
}

// get_local_animation(self)
int ObjectRef::l_get_local_animation(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	RemotePlayer *player = getplayer(ref);
	if (player == nullptr)
		return 0;

	v2s32 frames[4];
	float frame_speed;
	player->getLocalAnimations(frames, &frame_speed);

	for (const v2s32 &frame : frames) {
		push_v2s32(L, frame);
	}

	lua_pushnumber(L, frame_speed);
	return 5;
}

// set_eye_offset(self, firstperson, thirdperson)
int ObjectRef::l_set_eye_offset(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	RemotePlayer *player = getplayer(ref);
	if (player == nullptr)
		return 0;

	v3f offset_first = readParam<v3f>(L, 2, v3f(0, 0, 0));
	v3f offset_third = readParam<v3f>(L, 3, v3f(0, 0, 0));

	// Prevent abuse of offset values (keep player always visible)
	offset_third.X = rangelim(offset_third.X,-10,10);
	offset_third.Z = rangelim(offset_third.Z,-5,5);
	/* TODO: if possible: improve the camera collision detection to allow Y <= -1.5) */
	offset_third.Y = rangelim(offset_third.Y,-10,15); //1.5*BS

	getServer(L)->setPlayerEyeOffset(player, offset_first, offset_third);
	lua_pushboolean(L, true);
	return 1;
}

// get_eye_offset(self)
int ObjectRef::l_get_eye_offset(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	RemotePlayer *player = getplayer(ref);
	if (player == nullptr)
		return 0;

	push_v3f(L, player->eye_offset_first);
	push_v3f(L, player->eye_offset_third);
	return 2;
}

// send_mapblock(self, pos)
int ObjectRef::l_send_mapblock(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	RemotePlayer *player = getplayer(ref);
	if (player == nullptr)
		return 0;

	v3s16 pos = read_v3s16(L, 2);

	session_t peer_id = player->getPeerId();
	bool r = getServer(L)->SendBlock(peer_id, pos);

	lua_pushboolean(L, r);
	return 1;
}

// set_animation_frame_speed(self, frame_speed)
int ObjectRef::l_set_animation_frame_speed(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *sao = getobject(ref);
	if (sao == nullptr)
		return 0;

	if (!lua_isnil(L, 2)) {
		float frame_speed = readParam<float>(L, 2);
		sao->setAnimationSpeed(frame_speed);
		lua_pushboolean(L, true);
	} else {
		lua_pushboolean(L, false);
	}
	return 1;
}

// set_bone_position(self, bone, position, rotation)
int ObjectRef::l_set_bone_position(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *sao = getobject(ref);
	if (sao == nullptr)
		return 0;

	std::string bone = readParam<std::string>(L, 2, "");
	v3f position = readParam<v3f>(L, 3, v3f(0, 0, 0));
	v3f rotation = readParam<v3f>(L, 4, v3f(0, 0, 0));

	sao->setBonePosition(bone, position, rotation);
	return 0;
}

// get_bone_position(self, bone)
int ObjectRef::l_get_bone_position(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *sao = getobject(ref);
	if (sao == nullptr)
		return 0;

	std::string bone = readParam<std::string>(L, 2, "");

	v3f position = v3f(0, 0, 0);
	v3f rotation = v3f(0, 0, 0);
	sao->getBonePosition(bone, &position, &rotation);

	push_v3f(L, position);
	push_v3f(L, rotation);
	return 2;
}

// set_attach(self, parent, bone, position, rotation, force_visible)
int ObjectRef::l_set_attach(lua_State *L)
{
	GET_ENV_PTR;
	ObjectRef *ref = checkobject(L, 1);
	ObjectRef *parent_ref = checkobject(L, 2);
	ServerActiveObject *sao = getobject(ref);
	ServerActiveObject *parent = getobject(parent_ref);
	if (sao == nullptr || parent == nullptr)
		return 0;
	if (sao == parent)
		throw LuaError("ObjectRef::set_attach: attaching object to itself is not allowed.");

	int parent_id;
	std::string bone;
	v3f position;
	v3f rotation;
	bool force_visible;

	sao->getAttachment(&parent_id, &bone, &position, &rotation, &force_visible);
	if (parent_id) {
		ServerActiveObject *old_parent = env->getActiveObject(parent_id);
		old_parent->removeAttachmentChild(sao->getId());
	}

	bone          = readParam<std::string>(L, 3, "");
	position      = readParam<v3f>(L, 4, v3f(0, 0, 0));
	rotation      = readParam<v3f>(L, 5, v3f(0, 0, 0));
	force_visible = readParam<bool>(L, 6, false);

	sao->setAttachment(parent->getId(), bone, position, rotation, force_visible);
	parent->addAttachmentChild(sao->getId());
	return 0;
}

// get_attach(self)
int ObjectRef::l_get_attach(lua_State *L)
{
	GET_ENV_PTR;
	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *sao = getobject(ref);
	if (sao == nullptr)
		return 0;

	int parent_id;
	std::string bone;
	v3f position;
	v3f rotation;
	bool force_visible;

	sao->getAttachment(&parent_id, &bone, &position, &rotation, &force_visible);
	if (parent_id == 0)
		return 0;

	ServerActiveObject *parent = env->getActiveObject(parent_id);
	getScriptApiBase(L)->objectrefGetOrCreate(L, parent);
	lua_pushlstring(L, bone.c_str(), bone.size());
	push_v3f(L, position);
	push_v3f(L, rotation);
	lua_pushboolean(L, force_visible);
	return 5;
}

// get_children(self)
int ObjectRef::l_get_children(lua_State *L)
{
	GET_ENV_PTR;
	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *sao = getobject(ref);
	if (sao == nullptr)
		return 0;

	const std::unordered_set<int> child_ids = sao->getAttachmentChildIds();
	int i = 0;

	lua_createtable(L, child_ids.size(), 0);
	for (const int id : child_ids) {
		ServerActiveObject *child = env->getActiveObject(id);
		getScriptApiBase(L)->objectrefGetOrCreate(L, child);
		lua_rawseti(L, -2, ++i);
	}
	return 1;
}

// set_detach(self)
int ObjectRef::l_set_detach(lua_State *L)
{
	GET_ENV_PTR;
	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *sao = getobject(ref);
	if (sao == nullptr)
		return 0;

	sao->clearParentAttachment();
	return 0;
}

// set_properties(self, properties)
int ObjectRef::l_set_properties(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *sao = getobject(ref);
	if (sao == nullptr)
		return 0;

	ObjectProperties *prop = sao->accessObjectProperties();
	if (prop == nullptr)
		return 0;

	read_object_properties(L, 2, sao, prop, getServer(L)->idef());
	prop->validate();
	sao->notifyObjectPropertiesModified();
	return 0;
}

// get_properties(self)
int ObjectRef::l_get_properties(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *sao = getobject(ref);
	if (sao == nullptr)
		return 0;

	ObjectProperties *prop = sao->accessObjectProperties();
	if (prop == nullptr)
		return 0;

	push_object_properties(L, prop);
	return 1;
}

// is_player(self)
int ObjectRef::l_is_player(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	RemotePlayer *player = getplayer(ref);
	lua_pushboolean(L, (player != nullptr));
	return 1;
}

// set_nametag_attributes(self, attributes)
int ObjectRef::l_set_nametag_attributes(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *sao = getobject(ref);
	if (sao == nullptr)
		return 0;

	ObjectProperties *prop = sao->accessObjectProperties();
	if (prop == nullptr)
		return 0;

	lua_getfield(L, 2, "color");
	if (!lua_isnil(L, -1)) {
		video::SColor color = prop->nametag_color;
		read_color(L, -1, &color);
		prop->nametag_color = color;
	}
	lua_pop(L, 1);

	lua_getfield(L, -1, "bgcolor");
	if (!lua_isnil(L, -1)) {
		if (lua_toboolean(L, -1)) {
			video::SColor color;
			if (read_color(L, -1, &color))
				prop->nametag_bgcolor = color;
		} else {
			prop->nametag_bgcolor = nullopt;
		}
	}
	lua_pop(L, 1);

	std::string nametag = getstringfield_default(L, 2, "text", "");
	prop->nametag = nametag;

	prop->validate();
	sao->notifyObjectPropertiesModified();
	lua_pushboolean(L, true);
	return 1;
}

// get_nametag_attributes(self)
int ObjectRef::l_get_nametag_attributes(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *sao = getobject(ref);
	if (sao == nullptr)
		return 0;

	ObjectProperties *prop = sao->accessObjectProperties();
	if (!prop)
		return 0;

	lua_newtable(L);

	push_ARGB8(L, prop->nametag_color);
	lua_setfield(L, -2, "color");

	if (prop->nametag_bgcolor) {
		push_ARGB8(L, prop->nametag_bgcolor.value());
		lua_setfield(L, -2, "bgcolor");
	} else {
		lua_pushboolean(L, false);
		lua_setfield(L, -2, "bgcolor");
	}

	lua_pushstring(L, prop->nametag.c_str());
	lua_setfield(L, -2, "text");



	return 1;
}

/* LuaEntitySAO-only */

// set_velocity(self, velocity)
int ObjectRef::l_set_velocity(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	LuaEntitySAO *sao = getluaobject(ref);
	if (sao == nullptr)
		return 0;

	v3f vel = checkFloatPos(L, 2);

	sao->setVelocity(vel);
	return 0;
}

// add_velocity(self, velocity)
int ObjectRef::l_add_velocity(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *sao = getobject(ref);
	if (sao == nullptr)
		return 0;

	v3f vel = checkFloatPos(L, 2);

	if (sao->getType() == ACTIVEOBJECT_TYPE_LUAENTITY) {
		LuaEntitySAO *entitysao = dynamic_cast<LuaEntitySAO*>(sao);
		entitysao->addVelocity(vel);
	} else if (sao->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
		PlayerSAO *playersao = dynamic_cast<PlayerSAO*>(sao);
		playersao->setMaxSpeedOverride(vel);
		getServer(L)->SendPlayerSpeed(playersao->getPeerID(), vel);
	}

	return 0;
}

// get_velocity(self)
int ObjectRef::l_get_velocity(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *sao = getobject(ref);
	if (sao == nullptr)
		return 0;

	if (sao->getType() == ACTIVEOBJECT_TYPE_LUAENTITY) {
		LuaEntitySAO *entitysao = dynamic_cast<LuaEntitySAO*>(sao);
		v3f vel = entitysao->getVelocity();
		pushFloatPos(L, vel);
		return 1;
	} else if (sao->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
		RemotePlayer *player = dynamic_cast<PlayerSAO*>(sao)->getPlayer();
		push_v3f(L, player->getSpeed() / BS);
		return 1;
	}

	lua_pushnil(L);
	return 1;
}

// set_acceleration(self, acceleration)
int ObjectRef::l_set_acceleration(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	LuaEntitySAO *entitysao = getluaobject(ref);
	if (entitysao == nullptr)
		return 0;

	v3f acceleration = checkFloatPos(L, 2);

	entitysao->setAcceleration(acceleration);
	return 0;
}

// get_acceleration(self)
int ObjectRef::l_get_acceleration(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	LuaEntitySAO *entitysao = getluaobject(ref);
	if (entitysao == nullptr)
		return 0;

	v3f acceleration = entitysao->getAcceleration();
	pushFloatPos(L, acceleration);
	return 1;
}

// set_rotation(self, rotation)
int ObjectRef::l_set_rotation(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	LuaEntitySAO *entitysao = getluaobject(ref);
	if (entitysao == nullptr)
		return 0;

	v3f rotation = check_v3f(L, 2) * core::RADTODEG;

	entitysao->setRotation(rotation);
	return 0;
}

// get_rotation(self)
int ObjectRef::l_get_rotation(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	LuaEntitySAO *entitysao = getluaobject(ref);
	if (entitysao == nullptr)
		return 0;

	v3f rotation = entitysao->getRotation() * core::DEGTORAD;

	lua_newtable(L);
	push_v3f(L, rotation);
	return 1;
}

// set_yaw(self, yaw)
int ObjectRef::l_set_yaw(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	LuaEntitySAO *entitysao = getluaobject(ref);
	if (entitysao == nullptr)
		return 0;

	float yaw = readParam<float>(L, 2) * core::RADTODEG;

	entitysao->setRotation(v3f(0, yaw, 0));
	return 0;
}

// get_yaw(self)
int ObjectRef::l_get_yaw(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	LuaEntitySAO *entitysao = getluaobject(ref);
	if (entitysao == nullptr)
		return 0;

	float yaw = entitysao->getRotation().Y * core::DEGTORAD;

	lua_pushnumber(L, yaw);
	return 1;
}

// set_texture_mod(self, mod)
int ObjectRef::l_set_texture_mod(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	LuaEntitySAO *entitysao = getluaobject(ref);
	if (entitysao == nullptr)
		return 0;

	std::string mod = readParam<std::string>(L, 2);

	entitysao->setTextureMod(mod);
	return 0;
}

// get_texture_mod(self)
int ObjectRef::l_get_texture_mod(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	LuaEntitySAO *entitysao = getluaobject(ref);
	if (entitysao == nullptr)
		return 0;

	std::string mod = entitysao->getTextureMod();

	lua_pushstring(L, mod.c_str());
	return 1;
}

// set_sprite(self, start_frame, num_frames, framelength, select_x_by_camera)
int ObjectRef::l_set_sprite(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	LuaEntitySAO *entitysao = getluaobject(ref);
	if (entitysao == nullptr)
		return 0;

	v2s16 start_frame = readParam<v2s16>(L, 2, v2s16(0,0));
	int num_frames    = readParam<int>(L, 3, 1);
	float framelength = readParam<float>(L, 4, 0.2f);
	bool select_x_by_camera = readParam<bool>(L, 5, false);

	entitysao->setSprite(start_frame, num_frames, framelength, select_x_by_camera);
	return 0;
}

// DEPRECATED
// get_entity_name(self)
int ObjectRef::l_get_entity_name(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	LuaEntitySAO *entitysao = getluaobject(ref);
	log_deprecated(L,"Deprecated call to \"get_entity_name");
	if (entitysao == nullptr)
		return 0;

	std::string name = entitysao->getName();

	lua_pushstring(L, name.c_str());
	return 1;
}

// get_luaentity(self)
int ObjectRef::l_get_luaentity(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	LuaEntitySAO *entitysao = getluaobject(ref);
	if (entitysao == nullptr)
		return 0;

	luaentity_get(L, entitysao->getId());
	return 1;
}

/* Player-only */

// get_player_name(self)
int ObjectRef::l_get_player_name(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	RemotePlayer *player = getplayer(ref);
	if (player == nullptr) {
		lua_pushlstring(L, "", 0);
		return 1;
	}

	lua_pushstring(L, player->getName());
	return 1;
}

// get_look_dir(self)
int ObjectRef::l_get_look_dir(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	PlayerSAO* playersao = getplayersao(ref);
	if (playersao == nullptr)
		return 0;

	float pitch = playersao->getRadLookPitchDep();
	float yaw = playersao->getRadYawDep();
	v3f v(std::cos(pitch) * std::cos(yaw), std::sin(pitch), std::cos(pitch) *
		std::sin(yaw));

	push_v3f(L, v);
	return 1;
}

// DEPRECATED
// get_look_pitch(self)
int ObjectRef::l_get_look_pitch(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;

	log_deprecated(L,
		"Deprecated call to get_look_pitch, use get_look_vertical instead");

	ObjectRef *ref = checkobject(L, 1);
	PlayerSAO* playersao = getplayersao(ref);
	if (playersao == nullptr)
		return 0;

	lua_pushnumber(L, playersao->getRadLookPitchDep());
	return 1;
}

// DEPRECATED
// get_look_yaw(self)
int ObjectRef::l_get_look_yaw(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;

	log_deprecated(L,
		"Deprecated call to get_look_yaw, use get_look_horizontal instead");

	ObjectRef *ref = checkobject(L, 1);
	PlayerSAO* playersao = getplayersao(ref);
	if (playersao == nullptr)
		return 0;

	lua_pushnumber(L, playersao->getRadYawDep());
	return 1;
}

// get_look_vertical(self)
int ObjectRef::l_get_look_vertical(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	PlayerSAO* playersao = getplayersao(ref);
	if (playersao == nullptr)
		return 0;

	lua_pushnumber(L, playersao->getRadLookPitch());
	return 1;
}

// get_look_horizontal(self)
int ObjectRef::l_get_look_horizontal(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	PlayerSAO* playersao = getplayersao(ref);
	if (playersao == nullptr)
		return 0;

	lua_pushnumber(L, playersao->getRadRotation().Y);
	return 1;
}

// set_look_vertical(self, radians)
int ObjectRef::l_set_look_vertical(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	PlayerSAO* playersao = getplayersao(ref);
	if (playersao == nullptr)
		return 0;

	float pitch = readParam<float>(L, 2) * core::RADTODEG;

	playersao->setLookPitchAndSend(pitch);
	return 1;
}

// set_look_horizontal(self, radians)
int ObjectRef::l_set_look_horizontal(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	PlayerSAO* playersao = getplayersao(ref);
	if (playersao == nullptr)
		return 0;

	float yaw = readParam<float>(L, 2) * core::RADTODEG;

	playersao->setPlayerYawAndSend(yaw);
	return 1;
}

// DEPRECATED
// set_look_pitch(self, radians)
int ObjectRef::l_set_look_pitch(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;

	log_deprecated(L,
		"Deprecated call to set_look_pitch, use set_look_vertical instead.");

	ObjectRef *ref = checkobject(L, 1);
	PlayerSAO* playersao = getplayersao(ref);
	if (playersao == nullptr)
		return 0;

	float pitch = readParam<float>(L, 2) * core::RADTODEG;

	playersao->setLookPitchAndSend(pitch);
	return 1;
}

// DEPRECATED
// set_look_yaw(self, radians)
int ObjectRef::l_set_look_yaw(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;

	log_deprecated(L,
		"Deprecated call to set_look_yaw, use set_look_horizontal instead.");

	ObjectRef *ref = checkobject(L, 1);
	PlayerSAO* playersao = getplayersao(ref);
	if (playersao == nullptr)
		return 0;

	float yaw = readParam<float>(L, 2) * core::RADTODEG;

	playersao->setPlayerYawAndSend(yaw);
	return 1;
}

// set_fov(self, degrees, is_multiplier, transition_time)
int ObjectRef::l_set_fov(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	RemotePlayer *player = getplayer(ref);
	if (player == nullptr)
		return 0;

	float degrees = static_cast<f32>(luaL_checknumber(L, 2));
	bool is_multiplier = readParam<bool>(L, 3, false);
	float transition_time = lua_isnumber(L, 4) ?
		static_cast<f32>(luaL_checknumber(L, 4)) : 0.0f;

	player->setFov({degrees, is_multiplier, transition_time});
	getServer(L)->SendPlayerFov(player->getPeerId());
	return 0;
}

// get_fov(self)
int ObjectRef::l_get_fov(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	RemotePlayer *player = getplayer(ref);
	if (player == nullptr)
		return 0;

	PlayerFovSpec fov_spec = player->getFov();

	lua_pushnumber(L, fov_spec.fov);
	lua_pushboolean(L, fov_spec.is_multiplier);
	lua_pushnumber(L, fov_spec.transition_time);
	return 3;
}

// set_breath(self, breath)
int ObjectRef::l_set_breath(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	PlayerSAO* playersao = getplayersao(ref);
	if (playersao == nullptr)
		return 0;

	u16 breath = luaL_checknumber(L, 2);

	playersao->setBreath(breath);
	return 0;
}

// get_breath(self)
int ObjectRef::l_get_breath(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	PlayerSAO* playersao = getplayersao(ref);
	if (playersao == nullptr)
		return 0;

	u16 breath = playersao->getBreath();

	lua_pushinteger(L, breath);
	return 1;
}

// set_attribute(self, attribute, value)
int ObjectRef::l_set_attribute(lua_State *L)
{
	log_deprecated(L,
		"Deprecated call to set_attribute, use MetaDataRef methods instead.");

	ObjectRef *ref = checkobject(L, 1);
	PlayerSAO* playersao = getplayersao(ref);
	if (playersao == nullptr)
		return 0;

	std::string attr = luaL_checkstring(L, 2);
	if (lua_isnil(L, 3)) {
		playersao->getMeta().removeString(attr);
	} else {
		std::string value = luaL_checkstring(L, 3);
		playersao->getMeta().setString(attr, value);
	}
	return 1;
}

// get_attribute(self, attribute)
int ObjectRef::l_get_attribute(lua_State *L)
{
	log_deprecated(L,
		"Deprecated call to get_attribute, use MetaDataRef methods instead.");

	ObjectRef *ref = checkobject(L, 1);
	PlayerSAO* playersao = getplayersao(ref);
	if (playersao == nullptr)
		return 0;