├── .nojekyll ├── LICENSE ├── README.md ├── images ├── github.png ├── help.png ├── icon.png ├── mc-heads.png ├── slots.png └── twitter.png ├── index.htm ├── js ├── colpick.css ├── colpick.js └── main.js └── style.css /.nojekyll: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Minecraft Armor Stand 2 | ================= 3 | 4 | ### [Try it out](http://haselkern.github.io/Minecraft-ArmorStand) 5 | 6 | In Minecraft 1.8 Armor stands were introduced. Unfortunately, the syntax to summon one is quite confusing and not very intuitive, especially when you're trying to create an awesome pose. This tool provides a graphical interface so that you can focus on the looks and not worry about the code. 7 | 8 | If you would like to see a feature implemented, feel free to open an issue or submit a pull request. 9 | -------------------------------------------------------------------------------- /images/github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haselkern/Minecraft-ArmorStand/6413875cd0a4c9c78ff66f5fe2e72dd17aa43620/images/github.png -------------------------------------------------------------------------------- /images/help.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haselkern/Minecraft-ArmorStand/6413875cd0a4c9c78ff66f5fe2e72dd17aa43620/images/help.png -------------------------------------------------------------------------------- /images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haselkern/Minecraft-ArmorStand/6413875cd0a4c9c78ff66f5fe2e72dd17aa43620/images/icon.png -------------------------------------------------------------------------------- /images/mc-heads.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haselkern/Minecraft-ArmorStand/6413875cd0a4c9c78ff66f5fe2e72dd17aa43620/images/mc-heads.png -------------------------------------------------------------------------------- /images/slots.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haselkern/Minecraft-ArmorStand/6413875cd0a4c9c78ff66f5fe2e72dd17aa43620/images/slots.png -------------------------------------------------------------------------------- /images/twitter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haselkern/Minecraft-ArmorStand/6413875cd0a4c9c78ff66f5fe2e72dd17aa43620/images/twitter.png -------------------------------------------------------------------------------- /index.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Minecraft Armor stand 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 |
23 | 24 |
25 |

MINECRAFT ARMOR STAND

26 |
27 | GitHub 28 | Twitter 29 | haselkern.com/armorstand 30 |
31 |
32 | 33 |
34 | 44 |
45 | 46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 | 60 |
61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 |
Rotation:
Head:
Body:
Left Leg:
Right Leg:
91 |
92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 |
Left Arm:
Right Arm:
106 |
107 |
108 | 109 |
110 |
111 |
112 |

113 | Enter the text id of an item (for example stone or iron_sword) into the appropriate slots. You can enter an arbitrary item for the head or hand, but the other slots must contain an appropriate item. 114 |

115 | 116 | 117 | 118 | 119 | 120 | 121 | 128 |
129 | 130 | 131 | 132 | 139 |
140 | 141 | 142 | 143 | 151 |
152 | 153 | 154 | 155 | 163 |
164 | 165 |
Helmet specifies 166 | 172 | 173 |
174 |
175 | You can find lots of different heads here. Pick one and copy the Give-Code into the helmet field: 176 |
177 | minecraft-heads.com 178 |
179 |
180 |
181 | 182 |
183 | 184 |
185 |
186 |

187 | In 1.13, you can now add formats to the name tags. 188 | Enter the color id (for example red, dark_blue) in the name color field to give it a color. 189 |

190 | 191 | 192 | 209 |
210 | 211 | 212 | 213 | 214 |
215 |
216 |
217 | 218 |
219 |

220 | Add scoreboard tags to your armor stand.
221 | When adding multiple tags, make sure they are separated by a comma ' , ' 222 |

223 | 224 |
225 | 226 |
227 | 228 | 229 | 230 |
231 |
232 |   233 | 234 | 235 | 236 | 237 | 238 | 239 |
240 | 241 |
242 | Remove 243 | 244 | 245 | 246 | 247 | 248 | 249 |
250 |
251 | Replace 252 | 253 | 254 | 255 | 256 | 257 | 258 |
259 |
260 | Place 261 | 262 | 263 | 264 | 265 | 266 | 267 |
268 |
269 |
270 | 271 |
272 |
click to copy
273 |
274 |
275 |
276 | Please note: 277 | This command is too long to be executed from chat. You need to place it inside a command block. (see below) 278 |
279 | 280 |
281 | 282 |
283 | 284 | + Save and Load 285 | 286 |
287 |
288 |
289 |

290 | Save your current armor stand creation 291 |

292 | 293 |
294 |
295 |
296 |

297 | Load your saved creations 298 |

299 |
300 | 301 | 302 |
303 |
304 |
305 |
306 |
307 |
308 | 309 |
310 | 311 | + Obtain a command block 312 | 313 |
314 |
315 |
316 | If your command is longer than 256 characters (100 before Minecraft 1.11), it needs to be executed with a command block. Obtain one by typing: 317 |
318 |
319 | /give @p minecraft:command_block 320 |
321 |
322 |
323 | 324 |
325 | 326 | + Troubleshooting 327 | 328 |
329 |

330 | This thing uses WebGL! 331 | If you don't see anything on the left enable WebGL in your browser or visit the official WebGL website to troubleshoot problems. 332 |

333 |
334 |
335 | 336 | 337 | 338 | 339 | -------------------------------------------------------------------------------- /js/colpick.css: -------------------------------------------------------------------------------- 1 | /* 2 | colpick Color Picker / colpick.com 3 | */ 4 | 5 | /*Main container*/ 6 | .colpick { 7 | position: absolute; 8 | width: 346px; 9 | height: 170px; 10 | overflow: hidden; 11 | display: none; 12 | font-family: Arial, Helvetica, sans-serif; 13 | background:#ebebeb; 14 | border: 1px solid #bbb; 15 | -webkit-border-radius: 5px; 16 | -moz-border-radius: 5px; 17 | border-radius: 5px; 18 | 19 | /*Prevents selecting text when dragging the selectors*/ 20 | -webkit-user-select: none; 21 | -moz-user-select: none; 22 | -ms-user-select: none; 23 | -o-user-select: none; 24 | user-select: none; 25 | } 26 | /*Color selection box with gradients*/ 27 | .colpick_color { 28 | position: absolute; 29 | left: 7px; 30 | top: 7px; 31 | width: 156px; 32 | height: 156px; 33 | overflow: hidden; 34 | outline: 1px solid #aaa; 35 | cursor: crosshair; 36 | } 37 | .colpick_color_overlay1 { 38 | position: absolute; 39 | left:0; 40 | top:0; 41 | width: 156px; 42 | height: 156px; 43 | -ms-filter: "progid:DXImageTransform.Microsoft.gradient(GradientType=1,startColorstr='#ffffff', endColorstr='#00ffffff')"; /* IE8 */ 44 | background: -moz-linear-gradient(left, rgba(255,255,255,1) 0%, rgba(255,255,255,0) 100%); /* FF3.6+ */ 45 | background: -webkit-gradient(linear, left top, right top, color-stop(0%,rgba(255,255,255,1)), color-stop(100%,rgba(255,255,255,0))); /* Chrome,Safari4+ */ 46 | background: -webkit-linear-gradient(left, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%); /* Chrome10+,Safari5.1+ */ 47 | background: -o-linear-gradient(left, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%); /* Opera 11.10+ */ 48 | background: -ms-linear-gradient(left, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%); /* IE10+ */ 49 | background: linear-gradient(to right, rgba(255,255,255,1) 0%, rgba(255,255,255,0) 100%); 50 | filter: progid:DXImageTransform.Microsoft.gradient(GradientType=1,startColorstr='#ffffff', endColorstr='#00ffffff'); /* IE6 & IE7 */ 51 | } 52 | .colpick_color_overlay2 { 53 | position: absolute; 54 | left:0; 55 | top:0; 56 | width: 156px; 57 | height: 156px; 58 | -ms-filter: "progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#00000000', endColorstr='#000000')"; /* IE8 */ 59 | background: -moz-linear-gradient(top, rgba(0,0,0,0) 0%, rgba(0,0,0,1) 100%); /* FF3.6+ */ 60 | background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,0)), color-stop(100%,rgba(0,0,0,1))); /* Chrome,Safari4+ */ 61 | background: -webkit-linear-gradient(top, rgba(0,0,0,0) 0%,rgba(0,0,0,1) 100%); /* Chrome10+,Safari5.1+ */ 62 | background: -o-linear-gradient(top, rgba(0,0,0,0) 0%,rgba(0,0,0,1) 100%); /* Opera 11.10+ */ 63 | background: -ms-linear-gradient(top, rgba(0,0,0,0) 0%,rgba(0,0,0,1) 100%); /* IE10+ */ 64 | background: linear-gradient(to bottom, rgba(0,0,0,0) 0%,rgba(0,0,0,1) 100%); /* W3C */ 65 | filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00000000', endColorstr='#000000',GradientType=0 ); /* IE6-9 */ 66 | } 67 | /*Circular color selector*/ 68 | .colpick_selector_outer { 69 | background:none; 70 | position: absolute; 71 | width: 11px; 72 | height: 11px; 73 | margin: -6px 0 0 -6px; 74 | border: 1px solid black; 75 | border-radius: 50%; 76 | } 77 | .colpick_selector_inner{ 78 | position: absolute; 79 | width: 9px; 80 | height: 9px; 81 | border: 1px solid white; 82 | border-radius: 50%; 83 | } 84 | /*Vertical hue bar*/ 85 | .colpick_hue { 86 | position: absolute; 87 | top: 6px; 88 | left: 175px; 89 | width: 19px; 90 | height: 156px; 91 | border: 1px solid #aaa; 92 | cursor: n-resize; 93 | } 94 | /*Hue bar sliding indicator*/ 95 | .colpick_hue_arrs { 96 | position: absolute; 97 | left: -8px; 98 | width: 35px; 99 | height: 7px; 100 | margin: -7px 0 0 0; 101 | } 102 | .colpick_hue_larr { 103 | position:absolute; 104 | width: 0; 105 | height: 0; 106 | border-top: 6px solid transparent; 107 | border-bottom: 6px solid transparent; 108 | border-left: 7px solid #858585; 109 | } 110 | .colpick_hue_rarr { 111 | position:absolute; 112 | right:0; 113 | width: 0; 114 | height: 0; 115 | border-top: 6px solid transparent; 116 | border-bottom: 6px solid transparent; 117 | border-right: 7px solid #858585; 118 | } 119 | /*New color box*/ 120 | .colpick_new_color { 121 | position: absolute; 122 | left: 207px; 123 | top: 6px; 124 | width: 60px; 125 | height: 27px; 126 | background: #f00; 127 | border: 1px solid #8f8f8f; 128 | } 129 | /*Current color box*/ 130 | .colpick_current_color { 131 | position: absolute; 132 | left: 277px; 133 | top: 6px; 134 | width: 60px; 135 | height: 27px; 136 | background: #f00; 137 | border: 1px solid #8f8f8f; 138 | } 139 | /*Input field containers*/ 140 | .colpick_field, .colpick_hex_field { 141 | position: absolute; 142 | height: 20px; 143 | width: 60px; 144 | overflow:hidden; 145 | background:#f3f3f3; 146 | color:#b8b8b8; 147 | font-size:12px; 148 | border:1px solid #bdbdbd; 149 | -webkit-border-radius: 3px; 150 | -moz-border-radius: 3px; 151 | border-radius: 3px; 152 | } 153 | .colpick_rgb_r { 154 | top: 40px; 155 | left: 207px; 156 | } 157 | .colpick_rgb_g { 158 | top: 67px; 159 | left: 207px; 160 | } 161 | .colpick_rgb_b { 162 | top: 94px; 163 | left: 207px; 164 | } 165 | .colpick_hsb_h { 166 | top: 40px; 167 | left: 277px; 168 | } 169 | .colpick_hsb_s { 170 | top: 67px; 171 | left: 277px; 172 | } 173 | .colpick_hsb_b { 174 | top: 94px; 175 | left: 277px; 176 | } 177 | .colpick_hex_field { 178 | width: 68px; 179 | left: 207px; 180 | top: 121px; 181 | } 182 | /*Text field container on focus*/ 183 | .colpick_focus { 184 | border-color: #999; 185 | } 186 | /*Field label container*/ 187 | .colpick_field_letter { 188 | position: absolute; 189 | width: 12px; 190 | height: 20px; 191 | line-height: 20px; 192 | padding-left: 4px; 193 | background: #efefef; 194 | border-right: 1px solid #bdbdbd; 195 | font-weight: bold; 196 | color:#777; 197 | } 198 | /*Text inputs*/ 199 | .colpick_field input, .colpick_hex_field input { 200 | position: absolute; 201 | right: 11px; 202 | margin: 0; 203 | padding: 0; 204 | height: 20px; 205 | line-height: 20px; 206 | background: transparent; 207 | border: none; 208 | font-size: 12px; 209 | font-family: Arial, Helvetica, sans-serif; 210 | color: #555; 211 | text-align: right; 212 | outline: none; 213 | } 214 | .colpick_hex_field input { 215 | right: 4px; 216 | } 217 | /*Field up/down arrows*/ 218 | .colpick_field_arrs { 219 | position: absolute; 220 | top: 0; 221 | right: 0; 222 | width: 9px; 223 | height: 21px; 224 | cursor: n-resize; 225 | } 226 | .colpick_field_uarr { 227 | position: absolute; 228 | top: 5px; 229 | width: 0; 230 | height: 0; 231 | border-left: 4px solid transparent; 232 | border-right: 4px solid transparent; 233 | border-bottom: 4px solid #959595; 234 | } 235 | .colpick_field_darr { 236 | position: absolute; 237 | bottom:5px; 238 | width: 0; 239 | height: 0; 240 | border-left: 4px solid transparent; 241 | border-right: 4px solid transparent; 242 | border-top: 4px solid #959595; 243 | } 244 | /*Submit/Select button*/ 245 | .colpick_submit { 246 | position: absolute; 247 | left: 207px; 248 | top: 149px; 249 | width: 130px; 250 | height: 22px; 251 | line-height:22px; 252 | background: #efefef; 253 | text-align: center; 254 | color: #555; 255 | font-size: 12px; 256 | font-weight:bold; 257 | border: 1px solid #bdbdbd; 258 | -webkit-border-radius: 3px; 259 | -moz-border-radius: 3px; 260 | border-radius: 3px; 261 | } 262 | .colpick_submit:hover { 263 | background:#f3f3f3; 264 | border-color:#999; 265 | cursor: pointer; 266 | } 267 | 268 | /*full layout with no submit button*/ 269 | .colpick_full_ns .colpick_submit, .colpick_full_ns .colpick_current_color{ 270 | display:none; 271 | } 272 | .colpick_full_ns .colpick_new_color { 273 | width: 130px; 274 | height: 25px; 275 | } 276 | .colpick_full_ns .colpick_rgb_r, .colpick_full_ns .colpick_hsb_h { 277 | top: 42px; 278 | } 279 | .colpick_full_ns .colpick_rgb_g, .colpick_full_ns .colpick_hsb_s { 280 | top: 73px; 281 | } 282 | .colpick_full_ns .colpick_rgb_b, .colpick_full_ns .colpick_hsb_b { 283 | top: 104px; 284 | } 285 | .colpick_full_ns .colpick_hex_field { 286 | top: 135px; 287 | } 288 | 289 | /*rgbhex layout*/ 290 | .colpick_rgbhex .colpick_hsb_h, .colpick_rgbhex .colpick_hsb_s, .colpick_rgbhex .colpick_hsb_b { 291 | display:none; 292 | } 293 | .colpick_rgbhex { 294 | width:282px; 295 | } 296 | .colpick_rgbhex .colpick_field, .colpick_rgbhex .colpick_submit { 297 | width:68px; 298 | } 299 | .colpick_rgbhex .colpick_new_color { 300 | width:34px; 301 | border-right:none; 302 | } 303 | .colpick_rgbhex .colpick_current_color { 304 | width:34px; 305 | left:240px; 306 | border-left:none; 307 | } 308 | 309 | /*rgbhex layout, no submit button*/ 310 | .colpick_rgbhex_ns .colpick_submit, .colpick_rgbhex_ns .colpick_current_color{ 311 | display:none; 312 | } 313 | .colpick_rgbhex_ns .colpick_new_color{ 314 | width:68px; 315 | border: 1px solid #8f8f8f; 316 | } 317 | .colpick_rgbhex_ns .colpick_rgb_r { 318 | top: 42px; 319 | } 320 | .colpick_rgbhex_ns .colpick_rgb_g { 321 | top: 73px; 322 | } 323 | .colpick_rgbhex_ns .colpick_rgb_b { 324 | top: 104px; 325 | } 326 | .colpick_rgbhex_ns .colpick_hex_field { 327 | top: 135px; 328 | } 329 | 330 | /*hex layout*/ 331 | .colpick_hex .colpick_hsb_h, .colpick_hex .colpick_hsb_s, .colpick_hex .colpick_hsb_b, .colpick_hex .colpick_rgb_r, .colpick_hex .colpick_rgb_g, .colpick_hex .colpick_rgb_b { 332 | display:none; 333 | } 334 | .colpick_hex { 335 | width:206px; 336 | height:201px; 337 | } 338 | .colpick_hex .colpick_hex_field { 339 | width:72px; 340 | height:25px; 341 | top:168px; 342 | left:80px; 343 | } 344 | .colpick_hex .colpick_hex_field div, .colpick_hex .colpick_hex_field input { 345 | height: 25px; 346 | line-height: 25px; 347 | } 348 | .colpick_hex .colpick_new_color { 349 | left:9px; 350 | top:168px; 351 | width:30px; 352 | border-right:none; 353 | } 354 | .colpick_hex .colpick_current_color { 355 | left:39px; 356 | top:168px; 357 | width:30px; 358 | border-left:none; 359 | } 360 | .colpick_hex .colpick_submit { 361 | left:164px; 362 | top: 168px; 363 | width:30px; 364 | height:25px; 365 | line-height: 25px; 366 | } 367 | 368 | /*hex layout, no submit button*/ 369 | .colpick_hex_ns .colpick_submit, .colpick_hex_ns .colpick_current_color { 370 | display:none; 371 | } 372 | .colpick_hex_ns .colpick_hex_field { 373 | width:80px; 374 | } 375 | .colpick_hex_ns .colpick_new_color{ 376 | width:60px; 377 | border: 1px solid #8f8f8f; 378 | } 379 | 380 | /*Dark color scheme*/ 381 | .colpick_dark { 382 | background: #161616; 383 | border-color: #2a2a2a; 384 | } 385 | .colpick_dark .colpick_color { 386 | outline-color: #333; 387 | } 388 | .colpick_dark .colpick_hue { 389 | border-color: #555; 390 | } 391 | .colpick_dark .colpick_field, .colpick_dark .colpick_hex_field { 392 | background: #101010; 393 | border-color: #2d2d2d; 394 | } 395 | .colpick_dark .colpick_field_letter { 396 | background: #131313; 397 | border-color: #2d2d2d; 398 | color: #696969; 399 | } 400 | .colpick_dark .colpick_field input, .colpick_dark .colpick_hex_field input { 401 | color: #7a7a7a; 402 | } 403 | .colpick_dark .colpick_field_uarr { 404 | border-bottom-color:#696969; 405 | } 406 | .colpick_dark .colpick_field_darr { 407 | border-top-color:#696969; 408 | } 409 | .colpick_dark .colpick_focus { 410 | border-color:#444; 411 | } 412 | .colpick_dark .colpick_submit { 413 | background: #131313; 414 | border-color:#2d2d2d; 415 | color:#7a7a7a; 416 | } 417 | .colpick_dark .colpick_submit:hover { 418 | background-color:#101010; 419 | border-color:#444; 420 | } -------------------------------------------------------------------------------- /js/colpick.js: -------------------------------------------------------------------------------- 1 | /* 2 | colpick Color Picker 3 | Copyright 2013 Jose Vargas. Licensed under GPL license. Based on Stefan Petre's Color Picker www.eyecon.ro, dual licensed under the MIT and GPL licenses 4 | 5 | For usage and examples: colpick.com/plugin 6 | */ 7 | 8 | (function ($) { 9 | var colpick = function () { 10 | var 11 | tpl = '
#
R
G
B
H
S
B
', 12 | defaults = { 13 | showEvent: 'click', 14 | onShow: function () {}, 15 | onBeforeShow: function(){}, 16 | onHide: function () {}, 17 | onChange: function () {}, 18 | onSubmit: function () {}, 19 | colorScheme: 'light', 20 | color: '3289c7', 21 | livePreview: true, 22 | flat: false, 23 | layout: 'full', 24 | submit: 1, 25 | submitText: 'OK', 26 | height: 156 27 | }, 28 | //Fill the inputs of the plugin 29 | fillRGBFields = function (hsb, cal) { 30 | var rgb = hsbToRgb(hsb); 31 | $(cal).data('colpick').fields 32 | .eq(1).val(rgb.r).end() 33 | .eq(2).val(rgb.g).end() 34 | .eq(3).val(rgb.b).end(); 35 | }, 36 | fillHSBFields = function (hsb, cal) { 37 | $(cal).data('colpick').fields 38 | .eq(4).val(Math.round(hsb.h)).end() 39 | .eq(5).val(Math.round(hsb.s)).end() 40 | .eq(6).val(Math.round(hsb.b)).end(); 41 | }, 42 | fillHexFields = function (hsb, cal) { 43 | $(cal).data('colpick').fields.eq(0).val(hsbToHex(hsb)); 44 | }, 45 | //Set the round selector position 46 | setSelector = function (hsb, cal) { 47 | $(cal).data('colpick').selector.css('backgroundColor', '#' + hsbToHex({h: hsb.h, s: 100, b: 100})); 48 | $(cal).data('colpick').selectorIndic.css({ 49 | left: parseInt($(cal).data('colpick').height * hsb.s/100, 10), 50 | top: parseInt($(cal).data('colpick').height * (100-hsb.b)/100, 10) 51 | }); 52 | }, 53 | //Set the hue selector position 54 | setHue = function (hsb, cal) { 55 | $(cal).data('colpick').hue.css('top', parseInt($(cal).data('colpick').height - $(cal).data('colpick').height * hsb.h/360, 10)); 56 | }, 57 | //Set current and new colors 58 | setCurrentColor = function (hsb, cal) { 59 | $(cal).data('colpick').currentColor.css('backgroundColor', '#' + hsbToHex(hsb)); 60 | }, 61 | setNewColor = function (hsb, cal) { 62 | $(cal).data('colpick').newColor.css('backgroundColor', '#' + hsbToHex(hsb)); 63 | }, 64 | //Called when the new color is changed 65 | change = function (ev) { 66 | var cal = $(this).parent().parent(), col; 67 | if (this.parentNode.className.indexOf('_hex') > 0) { 68 | cal.data('colpick').color = col = hexToHsb(fixHex(this.value)); 69 | fillRGBFields(col, cal.get(0)); 70 | fillHSBFields(col, cal.get(0)); 71 | } else if (this.parentNode.className.indexOf('_hsb') > 0) { 72 | cal.data('colpick').color = col = fixHSB({ 73 | h: parseInt(cal.data('colpick').fields.eq(4).val(), 10), 74 | s: parseInt(cal.data('colpick').fields.eq(5).val(), 10), 75 | b: parseInt(cal.data('colpick').fields.eq(6).val(), 10) 76 | }); 77 | fillRGBFields(col, cal.get(0)); 78 | fillHexFields(col, cal.get(0)); 79 | } else { 80 | cal.data('colpick').color = col = rgbToHsb(fixRGB({ 81 | r: parseInt(cal.data('colpick').fields.eq(1).val(), 10), 82 | g: parseInt(cal.data('colpick').fields.eq(2).val(), 10), 83 | b: parseInt(cal.data('colpick').fields.eq(3).val(), 10) 84 | })); 85 | fillHexFields(col, cal.get(0)); 86 | fillHSBFields(col, cal.get(0)); 87 | } 88 | setSelector(col, cal.get(0)); 89 | setHue(col, cal.get(0)); 90 | setNewColor(col, cal.get(0)); 91 | cal.data('colpick').onChange.apply(cal.parent(), [col, hsbToHex(col), hsbToRgb(col), cal.data('colpick').el, 0]); 92 | }, 93 | //Change style on blur and on focus of inputs 94 | blur = function (ev) { 95 | $(this).parent().removeClass('colpick_focus'); 96 | }, 97 | focus = function () { 98 | $(this).parent().parent().data('colpick').fields.parent().removeClass('colpick_focus'); 99 | $(this).parent().addClass('colpick_focus'); 100 | }, 101 | //Increment/decrement arrows functions 102 | downIncrement = function (ev) { 103 | ev.preventDefault ? ev.preventDefault() : ev.returnValue = false; 104 | var field = $(this).parent().find('input').focus(); 105 | var current = { 106 | el: $(this).parent().addClass('colpick_slider'), 107 | max: this.parentNode.className.indexOf('_hsb_h') > 0 ? 360 : (this.parentNode.className.indexOf('_hsb') > 0 ? 100 : 255), 108 | y: ev.pageY, 109 | field: field, 110 | val: parseInt(field.val(), 10), 111 | preview: $(this).parent().parent().data('colpick').livePreview 112 | }; 113 | $(document).mouseup(current, upIncrement); 114 | $(document).mousemove(current, moveIncrement); 115 | }, 116 | moveIncrement = function (ev) { 117 | ev.data.field.val(Math.max(0, Math.min(ev.data.max, parseInt(ev.data.val - ev.pageY + ev.data.y, 10)))); 118 | if (ev.data.preview) { 119 | change.apply(ev.data.field.get(0), [true]); 120 | } 121 | return false; 122 | }, 123 | upIncrement = function (ev) { 124 | change.apply(ev.data.field.get(0), [true]); 125 | ev.data.el.removeClass('colpick_slider').find('input').focus(); 126 | $(document).off('mouseup', upIncrement); 127 | $(document).off('mousemove', moveIncrement); 128 | return false; 129 | }, 130 | //Hue slider functions 131 | downHue = function (ev) { 132 | ev.preventDefault ? ev.preventDefault() : ev.returnValue = false; 133 | var current = { 134 | cal: $(this).parent(), 135 | y: $(this).offset().top 136 | }; 137 | $(document).on('mouseup touchend',current,upHue); 138 | $(document).on('mousemove touchmove',current,moveHue); 139 | 140 | var pageY = ((ev.type == 'touchstart') ? ev.originalEvent.changedTouches[0].pageY : ev.pageY ); 141 | change.apply( 142 | current.cal.data('colpick') 143 | .fields.eq(4).val(parseInt(360*(current.cal.data('colpick').height - (pageY - current.y))/current.cal.data('colpick').height, 10)) 144 | .get(0), 145 | [current.cal.data('colpick').livePreview] 146 | ); 147 | return false; 148 | }, 149 | moveHue = function (ev) { 150 | var pageY = ((ev.type == 'touchmove') ? ev.originalEvent.changedTouches[0].pageY : ev.pageY ); 151 | change.apply( 152 | ev.data.cal.data('colpick') 153 | .fields.eq(4).val(parseInt(360*(ev.data.cal.data('colpick').height - Math.max(0,Math.min(ev.data.cal.data('colpick').height,(pageY - ev.data.y))))/ev.data.cal.data('colpick').height, 10)) 154 | .get(0), 155 | [ev.data.preview] 156 | ); 157 | return false; 158 | }, 159 | upHue = function (ev) { 160 | fillRGBFields(ev.data.cal.data('colpick').color, ev.data.cal.get(0)); 161 | fillHexFields(ev.data.cal.data('colpick').color, ev.data.cal.get(0)); 162 | $(document).off('mouseup touchend',upHue); 163 | $(document).off('mousemove touchmove',moveHue); 164 | return false; 165 | }, 166 | //Color selector functions 167 | downSelector = function (ev) { 168 | ev.preventDefault ? ev.preventDefault() : ev.returnValue = false; 169 | var current = { 170 | cal: $(this).parent(), 171 | pos: $(this).offset() 172 | }; 173 | current.preview = current.cal.data('colpick').livePreview; 174 | 175 | $(document).on('mouseup touchend',current,upSelector); 176 | $(document).on('mousemove touchmove',current,moveSelector); 177 | 178 | var payeX,pageY; 179 | if(ev.type == 'touchstart') { 180 | pageX = ev.originalEvent.changedTouches[0].pageX, 181 | pageY = ev.originalEvent.changedTouches[0].pageY; 182 | } else { 183 | pageX = ev.pageX; 184 | pageY = ev.pageY; 185 | } 186 | 187 | change.apply( 188 | current.cal.data('colpick').fields 189 | .eq(6).val(parseInt(100*(current.cal.data('colpick').height - (pageY - current.pos.top))/current.cal.data('colpick').height, 10)).end() 190 | .eq(5).val(parseInt(100*(pageX - current.pos.left)/current.cal.data('colpick').height, 10)) 191 | .get(0), 192 | [current.preview] 193 | ); 194 | return false; 195 | }, 196 | moveSelector = function (ev) { 197 | var payeX,pageY; 198 | if(ev.type == 'touchmove') { 199 | pageX = ev.originalEvent.changedTouches[0].pageX, 200 | pageY = ev.originalEvent.changedTouches[0].pageY; 201 | } else { 202 | pageX = ev.pageX; 203 | pageY = ev.pageY; 204 | } 205 | 206 | change.apply( 207 | ev.data.cal.data('colpick').fields 208 | .eq(6).val(parseInt(100*(ev.data.cal.data('colpick').height - Math.max(0,Math.min(ev.data.cal.data('colpick').height,(pageY - ev.data.pos.top))))/ev.data.cal.data('colpick').height, 10)).end() 209 | .eq(5).val(parseInt(100*(Math.max(0,Math.min(ev.data.cal.data('colpick').height,(pageX - ev.data.pos.left))))/ev.data.cal.data('colpick').height, 10)) 210 | .get(0), 211 | [ev.data.preview] 212 | ); 213 | return false; 214 | }, 215 | upSelector = function (ev) { 216 | fillRGBFields(ev.data.cal.data('colpick').color, ev.data.cal.get(0)); 217 | fillHexFields(ev.data.cal.data('colpick').color, ev.data.cal.get(0)); 218 | $(document).off('mouseup touchend',upSelector); 219 | $(document).off('mousemove touchmove',moveSelector); 220 | return false; 221 | }, 222 | //Submit button 223 | clickSubmit = function (ev) { 224 | var cal = $(this).parent(); 225 | var col = cal.data('colpick').color; 226 | cal.data('colpick').origColor = col; 227 | setCurrentColor(col, cal.get(0)); 228 | cal.data('colpick').onSubmit(col, hsbToHex(col), hsbToRgb(col), cal.data('colpick').el); 229 | }, 230 | //Show/hide the color picker 231 | show = function (ev) { 232 | // Prevent the trigger of any direct parent 233 | ev.stopPropagation(); 234 | var cal = $('#' + $(this).data('colpickId')); 235 | cal.data('colpick').onBeforeShow.apply(this, [cal.get(0)]); 236 | var pos = $(this).offset(); 237 | var top = pos.top + this.offsetHeight; 238 | var left = pos.left; 239 | var viewPort = getViewport(); 240 | var calW = cal.width(); 241 | if (left + calW > viewPort.l + viewPort.w) { 242 | left -= calW; 243 | } 244 | cal.css({left: left + 'px', top: top + 'px'}); 245 | if (cal.data('colpick').onShow.apply(this, [cal.get(0)]) != false) { 246 | cal.show(); 247 | } 248 | //Hide when user clicks outside 249 | $('html').mousedown({cal:cal}, hide); 250 | cal.mousedown(function(ev){ev.stopPropagation();}) 251 | }, 252 | hide = function (ev) { 253 | if (ev.data.cal.data('colpick').onHide.apply(this, [ev.data.cal.get(0)]) != false) { 254 | ev.data.cal.hide(); 255 | } 256 | $('html').off('mousedown', hide); 257 | }, 258 | getViewport = function () { 259 | var m = document.compatMode == 'CSS1Compat'; 260 | return { 261 | l : window.pageXOffset || (m ? document.documentElement.scrollLeft : document.body.scrollLeft), 262 | w : window.innerWidth || (m ? document.documentElement.clientWidth : document.body.clientWidth) 263 | }; 264 | }, 265 | //Fix the values if the user enters a negative or high value 266 | fixHSB = function (hsb) { 267 | return { 268 | h: Math.min(360, Math.max(0, hsb.h)), 269 | s: Math.min(100, Math.max(0, hsb.s)), 270 | b: Math.min(100, Math.max(0, hsb.b)) 271 | }; 272 | }, 273 | fixRGB = function (rgb) { 274 | return { 275 | r: Math.min(255, Math.max(0, rgb.r)), 276 | g: Math.min(255, Math.max(0, rgb.g)), 277 | b: Math.min(255, Math.max(0, rgb.b)) 278 | }; 279 | }, 280 | fixHex = function (hex) { 281 | var len = 6 - hex.length; 282 | if (len > 0) { 283 | var o = []; 284 | for (var i=0; i').attr('style','height:8.333333%; filter:progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='+stops[i]+', endColorstr='+stops[i+1]+'); -ms-filter: "progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='+stops[i]+', endColorstr='+stops[i+1]+')";'); 356 | huebar.append(div); 357 | } 358 | } else { 359 | stopList = stops.join(','); 360 | huebar.attr('style','background:-webkit-linear-gradient(top,'+stopList+'); background: -o-linear-gradient(top,'+stopList+'); background: -ms-linear-gradient(top,'+stopList+'); background:-moz-linear-gradient(top,'+stopList+'); -webkit-linear-gradient(top,'+stopList+'); background:linear-gradient(to bottom,'+stopList+'); '); 361 | } 362 | cal.find('div.colpick_hue').on('mousedown touchstart',downHue); 363 | options.newColor = cal.find('div.colpick_new_color'); 364 | options.currentColor = cal.find('div.colpick_current_color'); 365 | //Store options and fill with default color 366 | cal.data('colpick', options); 367 | fillRGBFields(options.color, cal.get(0)); 368 | fillHSBFields(options.color, cal.get(0)); 369 | fillHexFields(options.color, cal.get(0)); 370 | setHue(options.color, cal.get(0)); 371 | setSelector(options.color, cal.get(0)); 372 | setCurrentColor(options.color, cal.get(0)); 373 | setNewColor(options.color, cal.get(0)); 374 | //Append to body if flat=false, else show in place 375 | if (options.flat) { 376 | cal.appendTo(this).show(); 377 | cal.css({ 378 | position: 'relative', 379 | display: 'block' 380 | }); 381 | } else { 382 | cal.appendTo(document.body); 383 | $(this).on(options.showEvent, show); 384 | cal.css({ 385 | position:'absolute' 386 | }); 387 | } 388 | } 389 | }); 390 | }, 391 | //Shows the picker 392 | showPicker: function() { 393 | return this.each( function () { 394 | if ($(this).data('colpickId')) { 395 | show.apply(this); 396 | } 397 | }); 398 | }, 399 | //Hides the picker 400 | hidePicker: function() { 401 | return this.each( function () { 402 | if ($(this).data('colpickId')) { 403 | $('#' + $(this).data('colpickId')).hide(); 404 | } 405 | }); 406 | }, 407 | //Sets a color as new and current (default) 408 | setColor: function(col, setCurrent) { 409 | setCurrent = (typeof setCurrent === "undefined") ? 1 : setCurrent; 410 | if (typeof col == 'string') { 411 | col = hexToHsb(col); 412 | } else if (col.r != undefined && col.g != undefined && col.b != undefined) { 413 | col = rgbToHsb(col); 414 | } else if (col.h != undefined && col.s != undefined && col.b != undefined) { 415 | col = fixHSB(col); 416 | } else { 417 | return this; 418 | } 419 | return this.each(function(){ 420 | if ($(this).data('colpickId')) { 421 | var cal = $('#' + $(this).data('colpickId')); 422 | cal.data('colpick').color = col; 423 | cal.data('colpick').origColor = col; 424 | fillRGBFields(col, cal.get(0)); 425 | fillHSBFields(col, cal.get(0)); 426 | fillHexFields(col, cal.get(0)); 427 | setHue(col, cal.get(0)); 428 | setSelector(col, cal.get(0)); 429 | 430 | setNewColor(col, cal.get(0)); 431 | cal.data('colpick').onChange.apply(cal.parent(), [col, hsbToHex(col), hsbToRgb(col), cal.data('colpick').el, 1]); 432 | if(setCurrent) { 433 | setCurrentColor(col, cal.get(0)); 434 | } 435 | } 436 | }); 437 | } 438 | }; 439 | }(); 440 | //Color space convertions 441 | var hexToRgb = function (hex) { 442 | var hex = parseInt(((hex.indexOf('#') > -1) ? hex.substring(1) : hex), 16); 443 | return {r: hex >> 16, g: (hex & 0x00FF00) >> 8, b: (hex & 0x0000FF)}; 444 | }; 445 | var hexToHsb = function (hex) { 446 | return rgbToHsb(hexToRgb(hex)); 447 | }; 448 | var rgbToHsb = function (rgb) { 449 | var hsb = {h: 0, s: 0, b: 0}; 450 | var min = Math.min(rgb.r, rgb.g, rgb.b); 451 | var max = Math.max(rgb.r, rgb.g, rgb.b); 452 | var delta = max - min; 453 | hsb.b = max; 454 | hsb.s = max != 0 ? 255 * delta / max : 0; 455 | if (hsb.s != 0) { 456 | if (rgb.r == max) hsb.h = (rgb.g - rgb.b) / delta; 457 | else if (rgb.g == max) hsb.h = 2 + (rgb.b - rgb.r) / delta; 458 | else hsb.h = 4 + (rgb.r - rgb.g) / delta; 459 | } else hsb.h = -1; 460 | hsb.h *= 60; 461 | if (hsb.h < 0) hsb.h += 360; 462 | hsb.s *= 100/255; 463 | hsb.b *= 100/255; 464 | return hsb; 465 | }; 466 | var hsbToRgb = function (hsb) { 467 | var rgb = {}; 468 | var h = hsb.h; 469 | var s = hsb.s*255/100; 470 | var v = hsb.b*255/100; 471 | if(s == 0) { 472 | rgb.r = rgb.g = rgb.b = v; 473 | } else { 474 | var t1 = v; 475 | var t2 = (255-s)*v/255; 476 | var t3 = (t1-t2)*(h%60)/60; 477 | if(h==360) h = 0; 478 | if(h<60) {rgb.r=t1; rgb.b=t2; rgb.g=t2+t3} 479 | else if(h<120) {rgb.g=t1; rgb.b=t2; rgb.r=t1-t3} 480 | else if(h<180) {rgb.g=t1; rgb.r=t2; rgb.b=t2+t3} 481 | else if(h<240) {rgb.b=t1; rgb.r=t2; rgb.g=t1-t3} 482 | else if(h<300) {rgb.b=t1; rgb.g=t2; rgb.r=t2+t3} 483 | else if(h<360) {rgb.r=t1; rgb.g=t2; rgb.b=t1-t3} 484 | else {rgb.r=0; rgb.g=0; rgb.b=0} 485 | } 486 | return {r:Math.round(rgb.r), g:Math.round(rgb.g), b:Math.round(rgb.b)}; 487 | }; 488 | var rgbToHex = function (rgb) { 489 | var hex = [ 490 | rgb.r.toString(16), 491 | rgb.g.toString(16), 492 | rgb.b.toString(16) 493 | ]; 494 | $.each(hex, function (nr, val) { 495 | if (val.length == 1) { 496 | hex[nr] = '0' + val; 497 | } 498 | }); 499 | return hex.join(''); 500 | }; 501 | var hsbToHex = function (hsb) { 502 | return rgbToHex(hsbToRgb(hsb)); 503 | }; 504 | $.fn.extend({ 505 | colpick: colpick.init, 506 | colpickHide: colpick.hidePicker, 507 | colpickShow: colpick.showPicker, 508 | colpickSetColor: colpick.setColor 509 | }); 510 | $.extend({ 511 | colpick:{ 512 | rgbToHex: rgbToHex, 513 | rgbToHsb: rgbToHsb, 514 | hsbToHex: hsbToHex, 515 | hsbToRgb: hsbToRgb, 516 | hexToHsb: hexToHsb, 517 | hexToRgb: hexToRgb 518 | } 519 | }); 520 | })(jQuery); 521 | -------------------------------------------------------------------------------- /js/main.js: -------------------------------------------------------------------------------- 1 | // BIG Thanks to tutsplus.com 2 | // http://code.tutsplus.com/tutorials/webgl-with-threejs-basics--net-35688 3 | // for helping me getting started 4 | 5 | //Stuff for rendering 6 | var DEG2RAD = Math.PI / 180; 7 | var width, height, renderer, scene, camera; 8 | var clock = new THREE.Clock; 9 | var rotY = 0, rotX = 0; 10 | var matWood = new THREE.MeshLambertMaterial({ color: 0x826841 }); 11 | //var matWood = new THREE.MeshLambertMaterial({ color: 0x826841, transparent: true, opacity: 0.5 }); //For testing the mesh alignment 12 | var matStone = new THREE.MeshLambertMaterial({ color: 0xadadad }); 13 | var matTransparentStone = new THREE.MeshLambertMaterial({ color: 0xadadad }); 14 | matTransparentStone.opacity = 0.8; 15 | matTransparentStone.transparent = true; 16 | var viewCenter = new THREE.Vector3(0,0,0); 17 | // Meshes 18 | // The ones marked with //* are not real meshes, but contain a child (or more) which gets rendered. 19 | // This is done, so these can easily be rotated around an accurate pivot point. 20 | var mBasePlate; 21 | var mBody; //* 22 | var mHead; //* 23 | var mSkull; 24 | var mLegLeft; //* 25 | var mLegRight; //* 26 | var mArmLeft; //* 27 | var mArmRight; //* 28 | var armorstand, armorstandWrapper; //Group all the other elements 29 | 30 | 31 | //DATA -> Stuff that we'll use to generate the command. Fetched from the controls. 32 | 33 | var mcVersion; 34 | 35 | var invisible = false; 36 | var invulnerable = false; 37 | var persistencerequired = false; 38 | var noBasePlate = false; 39 | var noGravity = false; 40 | var showArms = false; 41 | var small = false; 42 | var marker = false; 43 | var centercorrected = false; 44 | var give = false; 45 | 46 | var useEquipment; 47 | var equipHandRight; 48 | var equipHandLeft; 49 | var equipShoes; 50 | var equipLeggings; 51 | var equipChestplate; 52 | var equipHelmet = ""; 53 | var equipCustomHeadMode; 54 | var equipColorShoes; 55 | var equipColorLeggings; 56 | var equipColorChestplate; 57 | var equipColorHelmet; 58 | var helmetList; 59 | var chestplateList; 60 | var leggingsList; 61 | var bootsList; 62 | 63 | var customName; 64 | var showCustomName; 65 | var nameColor; 66 | var nameBold; 67 | var nameItalic; 68 | var nameobfuscated; 69 | var nameStrikethrough; 70 | 71 | var useDisabledSlots; 72 | 73 | var scoreboardTags; 74 | 75 | 76 | //The rotation values are all in degrees. 77 | var head = new THREE.Vector3(0,0,0); 78 | var body = new THREE.Vector3(0,0,0); 79 | var leftLeg = new THREE.Vector3(0,0,0); 80 | var rightLeg = new THREE.Vector3(0,0,0); 81 | var leftArm = new THREE.Vector3(0,0,0); 82 | var rightArm = new THREE.Vector3(0,0,0); 83 | var rotation = 0; 84 | 85 | //Stuff for mouse movements 86 | var mouseDownX; 87 | var mouseDownY; 88 | var mouseMoveX; 89 | var mouseMoveY; 90 | var mouseRotationMultiplier = 0.008; 91 | //A point class will help us manage the mouse movements. 92 | Point = { 93 | x:null, 94 | y:null 95 | }; 96 | 97 | jQuery.fn.selectAndCopyText = function(){ 98 | // https://stackoverflow.com/a/9976413/1456971 99 | this.find('input').each(function() { 100 | if($(this).prev().length == 0 || !$(this).prev().hasClass('p_copy')) { 101 | $('

').insertBefore($(this)); 102 | } 103 | $(this).prev().html($(this).val()); 104 | }); 105 | 106 | var doc = document; 107 | var element = this[0]; 108 | if (doc.body.createTextRange) { 109 | var range = document.body.createTextRange(); 110 | range.moveToElementText(element); 111 | range.select(); 112 | } else if (window.getSelection) { 113 | var selection = window.getSelection(); 114 | var range = document.createRange(); 115 | range.selectNodeContents(element); 116 | selection.removeAllRanges(); 117 | selection.addRange(range); 118 | } 119 | 120 | document.execCommand("copy"); 121 | }; 122 | 123 | $(document).ready(function(){ 124 | //Init 125 | setup(); 126 | updateUI(); 127 | render(); 128 | loadScreen(); 129 | 130 | // Confirm exit 131 | window.onbeforeunload = function(){ 132 | return "Unsaved changes will NOT be saved. Exit anyways?"; 133 | }; 134 | 135 | // Copy code on click 136 | $(".code").click(function(){ 137 | $("#code").selectAndCopyText(); 138 | }); 139 | 140 | //Stuff to handle and update input 141 | $("input").on("input", function(){ 142 | handleInput(); 143 | }); 144 | $(':checkbox, #equipCustomHeadMode, #equipmode, #mcversion').change(function() { 145 | handleInput(); 146 | }); 147 | 148 | 149 | //Handle rotating with mouse 150 | $("#gl") 151 | .mousedown(function(event){ 152 | mouseDownX = event.pageX; 153 | mouseDownY = event.pageY; 154 | }) 155 | .mousemove(function(event){ 156 | mouseMoveX = event.pageX; 157 | mouseMoveY = event.pageY; 158 | }) 159 | .mouseup(function(event){ 160 | rotY += getMouseDeltaX(); 161 | rotX += getMouseDeltaY(); 162 | mouseDownX = null; 163 | mouseDownY = null; 164 | }); 165 | 166 | //Hide elements 167 | $("#getcommandblock").hide(); 168 | $("#saveandload").hide(); 169 | $("#troubleshooting").hide(); 170 | $("#inputarms").hide(); 171 | $("#customequipment").hide(); 172 | $("#disabledslots").hide(); 173 | $("#namecustomization").hide(); 174 | 175 | //Show elements 176 | $("#namecustomization").show(); 177 | $("#centercorrected").show(); 178 | 179 | //Initialize colorpickers 180 | $('.colorfield').colpick({ 181 | colorScheme:'light', 182 | layout:'hex', 183 | color:'ff8800', 184 | onSubmit:function(hsb,hex,rgb,el) { 185 | $(el).css('background-color', '#'+hex); 186 | $(el).colpickHide(); 187 | handleInput(); 188 | } 189 | }); 190 | 191 | helmetList = $("#list-helmet").find("option"); 192 | chestplateList = $("#list-chestplate").find("option"); 193 | leggingsList = $("#list-leggings").find("option"); 194 | bootsList = $("#list-shoes").find("option"); 195 | 196 | }); 197 | 198 | function loadScreen() { 199 | $(`#creationname`).attr(`placeholder`, `My Armor Stand #${localStorage.length + 1}`); 200 | if (!localStorage.length) { 201 | $(`#loadlistopts`).hide(); 202 | $(`#loadmessage`).text(`You do not have any creations to load!`); 203 | } else { 204 | $(`#loadlistopts`).show(); 205 | $(`#loadmessage`).text(`Load your saved creations`); 206 | $(`#loadlist`).empty(); 207 | for (let i = 0; i < localStorage.length; i++) { 208 | $(`#loadlist`).append(``); 209 | }; 210 | }; 211 | }; 212 | 213 | function setup(){ 214 | width = $("#gl").width(); 215 | height = $("#gl").height(); 216 | 217 | renderer = new THREE.WebGLRenderer({ antialias: true, alpha:true }); 218 | renderer.setSize(width, height); 219 | $("#gl").append(renderer.domElement); 220 | 221 | 222 | scene = new THREE.Scene(); 223 | armorstand = new THREE.Object3D(); 224 | //Add an armorstandWrapper to the scene, so the armorstand can be rotated naturally. 225 | armorstandWrapper = new THREE.Object3D(); 226 | armorstand.position.set(0,-0.5,0); 227 | armorstandWrapper.add(armorstand); 228 | 229 | 230 | //BasePlate 231 | mBasePlate = new THREE.Mesh( 232 | new THREE.BoxGeometry(12/16, 1/16, 12/16), 233 | matStone); 234 | mBasePlate.position.y = - (1/32 - armorstand.position.y); 235 | armorstandWrapper.add(mBasePlate); 236 | //Add a little dot, so the user knows which way is forward 237 | var mmBaseDot = new THREE.Mesh( 238 | new THREE.BoxGeometry(2/16, 1/16, 4/16), 239 | matStone); 240 | mmBaseDot.position.set(0,mBasePlate.position.y,10/16); 241 | armorstandWrapper.add(mmBaseDot); 242 | 243 | // To Generate the other body parts, we will use a mesh to display, 244 | // and add it as a child to the object that serves as a pivot. 245 | 246 | //Left Leg 247 | var mmLegLeft = new THREE.Mesh( 248 | new THREE.BoxGeometry(2/16, 11/16, 2/16), 249 | matWood); 250 | mmLegLeft.position.set(0,-5.5/16,0); 251 | mLegLeft = new THREE.Object3D(); 252 | mLegLeft.position.set(2/16,11/16,0); //Pivot Point 253 | mLegLeft.add(mmLegLeft); 254 | armorstand.add(mLegLeft); 255 | 256 | //Right Leg 257 | var mmLegRight = new THREE.Mesh( 258 | new THREE.BoxGeometry(2/16, 11/16, 2/16), 259 | matWood); 260 | mmLegRight.position.set(0,-5.5/16,0); 261 | mLegRight = new THREE.Object3D(); 262 | mLegRight.position.set(-2/16,11/16,0); //Pivot Point 263 | mLegRight.add(mmLegRight); 264 | armorstand.add(mLegRight); 265 | 266 | //Left Arm 267 | var mmArmLeft = new THREE.Mesh( 268 | new THREE.BoxGeometry(2/16, 12/16, 2/16), 269 | matWood); 270 | mmArmLeft.position.set(0,-4/16,0); 271 | mArmLeft = new THREE.Object3D(); 272 | mArmLeft.position.set(6/16,21/16,0); //Pivot Point 273 | mArmLeft.add(mmArmLeft); 274 | armorstand.add(mArmLeft); 275 | 276 | //Right Arm 277 | var mmArmRight = new THREE.Mesh( 278 | new THREE.BoxGeometry(2/16, 12/16, 2/16), 279 | matWood); 280 | mmArmRight.position.set(0,-4/16,0); 281 | mArmRight = new THREE.Object3D(); 282 | mArmRight.position.set(-6/16,21/16,0); //Pivot Point 283 | mArmRight.add(mmArmRight); 284 | armorstand.add(mArmRight); 285 | 286 | //Body (consists of four parts) 287 | var mmHip = new THREE.Mesh( 288 | new THREE.BoxGeometry(8/16, 2/16, 2/16), 289 | matWood); 290 | mmHip.position.set(0,-11/16,0); 291 | var mmBodyLeft = new THREE.Mesh( 292 | new THREE.BoxGeometry(2/16, 7/16, 2/16), 293 | matWood); 294 | mmBodyLeft.position.set(2/16,-6.5/16,0); 295 | var mmBodyRight = new THREE.Mesh( 296 | new THREE.BoxGeometry(2/16, 7/16, 2/16), 297 | matWood); 298 | mmBodyRight.position.set(-2/16,-6.5/16,0); 299 | var mmShoulders = new THREE.Mesh( 300 | new THREE.BoxGeometry(12/16, 3/16, 3/16), 301 | matWood); 302 | mmShoulders.position.set(0,-1.5/16,0); 303 | mBody = new THREE.Object3D(); 304 | mBody.position.set(0,23/16,0); //Pivot Point 305 | mBody.add(mmHip); 306 | mBody.add(mmBodyLeft); 307 | mBody.add(mmBodyRight); 308 | mBody.add(mmShoulders); 309 | armorstand.add(mBody); 310 | 311 | //Head (neck and skull) 312 | var mmNeck = new THREE.Mesh( 313 | new THREE.BoxGeometry(2/16, 7/16, 2/16), 314 | matWood); 315 | mmNeck.position.set(0,3.5/16,0); 316 | mSkull = new THREE.Mesh( 317 | new THREE.BoxGeometry(10/16, 10/16, 10/16), 318 | matTransparentStone); 319 | mSkull.position.set(0,5/16,0); 320 | mHead = new THREE.Object3D(); 321 | mHead.position.set(0,22/16,0); //Pivot Point 322 | mHead.add(mmNeck); 323 | mHead.add(mSkull); 324 | armorstand.add(mHead); 325 | 326 | 327 | scene.add(armorstandWrapper); 328 | 329 | camera = new THREE.PerspectiveCamera(45, width/height, 0.1, 1000); 330 | camera.position.y = 2; 331 | camera.position.z = 4; 332 | camera.lookAt(viewCenter); 333 | scene.add(camera); 334 | 335 | var pointLight = new THREE.PointLight(0xffffff); 336 | pointLight.position.set(0, 300, 200); 337 | 338 | scene.add(pointLight); 339 | 340 | // Resize view 341 | window.addEventListener("resize", () => { 342 | width = $("#gl").width(); 343 | height = $("#gl").height(); 344 | 345 | camera.aspect = width / height; 346 | camera.updateProjectionMatrix(); 347 | 348 | renderer.setSize(width, height); 349 | }); 350 | } 351 | 352 | const MC_VERSION = Object.freeze({ 353 | v1_8: 0, 354 | v1_9: 1, 355 | v1_11: 2, 356 | v1_13: 3, 357 | v1_14: 4, 358 | v1_16: 5, 359 | v1_20_5: 6, 360 | v1_21: 7 361 | }); 362 | 363 | function getMcVersion() { 364 | let tag = document.getElementById("mcversion"); 365 | return tag.options.length - tag.selectedIndex - 1; 366 | } 367 | 368 | // Write stuff from input into variables 369 | function handleInput(){ 370 | 371 | mcVersion = getMcVersion(); 372 | 373 | invisible = getCheckBoxInput("invisible"); 374 | invulnerable = getCheckBoxInput("invulnerable"); 375 | persistencerequired = getCheckBoxInput("persistencerequired"); 376 | noBasePlate = getCheckBoxInput("nobaseplate"); 377 | noGravity = getCheckBoxInput("nogravity"); 378 | showArms = getCheckBoxInput("showarms"); 379 | small = getCheckBoxInput("small"); 380 | marker = getCheckBoxInput("marker"); 381 | centercorrected = getCheckBoxInput("center-corrected"); 382 | 383 | useEquipment = getCheckBoxInput("useequipment"); 384 | equipHandRight = getInput("equipHandRight"); 385 | equipHandLeft = getInput("equipHandLeft"); 386 | equipShoes = getInput("equipShoes"); 387 | equipLeggings = getInput("equipLeggings"); 388 | equipChestplate = getInput("equipChestplate"); 389 | equipHelmet = getInput("equipHelmet"); 390 | equipCustomHeadMode = $("#equipCustomHeadMode").val(); 391 | 392 | equipColorShoes = $("#boots_color").css("background-color"); 393 | equipColorLeggings = $("#leggings_color").css("background-color"); 394 | equipColorChestplate = $("#chestplate_color").css("background-color"); 395 | equipColorHelmet = $("#helmet_color").css("background-color"); 396 | 397 | customName = getInput("customname"); 398 | showCustomName = getCheckBoxInput("showcustomname"); 399 | nameColor = getInput("namecolor"); 400 | nameBold = getCheckBoxInput("namebold"); 401 | nameItalic = getCheckBoxInput("nameitalic"); 402 | nameObfuscated = getCheckBoxInput("nameobfuscated"); 403 | nameStrikethrough = getCheckBoxInput("namestrikethrough"); 404 | 405 | scoreboardTags = getInput("scoreboardtags"); 406 | 407 | useDisabledSlots = getCheckBoxInput("usedisabledslots"); 408 | give = getCheckBoxInput("slashgive"); 409 | 410 | body.set(getRangeInput("bodyX"), getRangeInput("bodyY"), getRangeInput("bodyZ")); 411 | head.set(getRangeInput("headX"), getRangeInput("headY"), getRangeInput("headZ")); 412 | leftLeg.set(getRangeInput("leftLegX"), getRangeInput("leftLegY"), getRangeInput("leftLegZ")); 413 | rightLeg.set(getRangeInput("rightLegX"), getRangeInput("rightLegY"), getRangeInput("rightLegZ")); 414 | leftArm.set(getRangeInput("leftArmX"), getRangeInput("leftArmY"), getRangeInput("leftArmZ")); 415 | rightArm.set(getRangeInput("rightArmX"), getRangeInput("rightArmY"), getRangeInput("rightArmZ")); 416 | 417 | rotation = getRangeInput("rotation"); 418 | 419 | updateUI(); 420 | }; 421 | 422 | function getCheckBoxInput(name) { 423 | return $("input[name="+name+"]").prop("checked"); 424 | }; 425 | 426 | function getRangeInput(name) { 427 | return $("input[name="+name+"]").val(); 428 | }; 429 | 430 | function getInput(name) { 431 | return $("input[name="+name+"]").val(); 432 | }; 433 | 434 | /** Changes stuff according to our input values */ 435 | function updateUI(){ 436 | 437 | //Hide/Show different inputs 438 | 439 | if(showArms) 440 | $("#inputarms").slideDown(); 441 | else 442 | $("#inputarms").slideUp(); 443 | 444 | if(useEquipment){ 445 | $("#customequipment").slideDown(); 446 | 447 | // Hide left hand item input for minecraft 1.8 448 | if(mcVersion < MC_VERSION.v1_9) { 449 | $("#equipHandLeft").hide(); 450 | } else { 451 | $("#equipHandLeft").show(); 452 | } 453 | 454 | let chestplate = chestplateList; 455 | let helmet = helmetList; 456 | let boots = bootsList; 457 | let leggings = leggingsList; 458 | 459 | // Hide elytra for versions <1.9 460 | if (mcVersion < MC_VERSION.v1_9) { 461 | chestplate = chestplate.filter("[value!=elytra]"); 462 | } 463 | 464 | // Hide turtle_helmet for versions <1.13 465 | if (mcVersion < MC_VERSION.v1_13) { 466 | helmet = helmet.filter("[value!=turtle_helmet]"); 467 | } 468 | 469 | // Hide netherite armor for versions < 1.16 470 | if (mcVersion < MC_VERSION.v1_16) { 471 | helmet = helmet.filter("[value!=netherite_helmet]"); 472 | chestplate = chestplate.filter("[value!=netherite_chestplate]"); 473 | leggings = leggings.filter("[value!=netherite_leggings]"); 474 | boots = boots.filter("[value!=netherite_boots]"); 475 | } 476 | 477 | $("#list-helmet").empty().append(helmet); 478 | $("#list-chestplate").empty().append(chestplate); 479 | $("#list-leggings").empty().append(leggings); 480 | $("#list-shoes").empty().append(boots); 481 | 482 | } 483 | else 484 | $("#customequipment").slideUp(); 485 | 486 | //Different colorinputs for armorparts 487 | if(isLeatherArmor(equipShoes)) 488 | $("#boots_color").slideDown(); 489 | else 490 | $("#boots_color").slideUp(); 491 | if(isLeatherArmor(equipLeggings)) 492 | $("#leggings_color").slideDown(); 493 | else 494 | $("#leggings_color").slideUp(); 495 | if(isLeatherArmor(equipChestplate)) 496 | $("#chestplate_color").slideDown(); 497 | else 498 | $("#chestplate_color").slideUp(); 499 | if(isLeatherArmor(equipHelmet)) 500 | $("#helmet_color").slideDown(); 501 | else 502 | $("#helmet_color").slideUp(); 503 | 504 | // Link to minecraft-heads.com 505 | if(equipCustomHeadMode == "givecode"){ 506 | $("#minecraft-heads").slideDown(); 507 | } 508 | else{ 509 | $("#minecraft-heads").slideUp(); 510 | } 511 | 512 | // Show disabled slots 513 | if(useDisabledSlots) { 514 | // Hide offhand disabled slot buttons for versions below 1.13 515 | if (mcVersion > MC_VERSION.v1_13) { 516 | $(".sprite.offhand").show(); 517 | $("#dO").show(); 518 | $("#rO").show(); 519 | $("#pO").show(); 520 | } else { 521 | $(".sprite.offhand").hide(); 522 | $("#dO").hide(); 523 | $("#rO").hide(); 524 | $("#pO").hide(); 525 | } 526 | 527 | $("#disabledslots").slideDown(); 528 | } else { 529 | $("#disabledslots").slideUp(); 530 | } 531 | 532 | //Hide 1.13 features for 1.12 and lower. 533 | if (mcVersion < MC_VERSION.v1_13) { 534 | $("#namecustomization").hide(); 535 | $("#centercorrected").hide(); 536 | } else { 537 | $("#namecustomization").show(); 538 | $("#centercorrected").show(); 539 | } 540 | 541 | // Generate code 542 | const generatedCode = generateCode(); 543 | $("#code").text(generatedCode); 544 | 545 | // Show hint, when command is too long 546 | const characterLimit = (mcVersion <= MC_VERSION.v1_9) ? 100 : 256; 547 | if (generatedCode.length > characterLimit) 548 | $("#codeinfo").slideDown(); 549 | else 550 | $("#codeinfo").slideUp(); 551 | 552 | 553 | // Rotate 3D Stuff 554 | // y and z rotation needs to be inverted 555 | setRotation(mBody, body); 556 | setRotation(mHead, head); 557 | setRotation(mLegLeft, leftLeg); 558 | setRotation(mLegRight, rightLeg); 559 | setRotation(mArmLeft, leftArm); 560 | setRotation(mArmRight, rightArm); 561 | armorstand.rotation.y = -rotation * DEG2RAD; 562 | 563 | // Scale model, depending on small variable 564 | if(small) 565 | armorstand.scale.set(0.6, 0.6, 0.6); 566 | else 567 | armorstand.scale.set(1, 1, 1); 568 | 569 | //Set Visibility 570 | mArmRight.visible = mArmLeft.visible = showArms; 571 | mBasePlate.visible = !noBasePlate; 572 | mSkull.visible = equipHelmet != ""; 573 | } 574 | 575 | function generateCode() { 576 | const tags = { 577 | Invisible: invisible || null, 578 | Invulnerable: invulnerable || null, 579 | PersistenceRequired: persistencerequired || null, 580 | NoBasePlate: noBasePlate || null, 581 | NoGravity: noGravity || null, 582 | ShowArms: showArms || null, 583 | Small: small || null, 584 | Marker: marker || null, 585 | 586 | Rotation: (rotation != 0) ? [ new NBTFloat(rotation) ] : null, 587 | 588 | CustomNameVisible: showCustomName || null, 589 | CustomName: (customName) ? generateCustomName() : null, 590 | 591 | DisabledSlots: (useDisabledSlots) ? calculateDisabledSlotsFlag() : null, 592 | Pose: generatePose(), 593 | }; 594 | 595 | // Equipment 596 | if (useEquipment) { 597 | if (mcVersion == MC_VERSION.v1_8) { 598 | // Old 1.8 Equipment format 599 | // Equipment: [ RightHand, Boots, Leggings, Chestplate, Helmet ] 600 | const rightHandItem = generateHandItems()[0]; 601 | tags.Equipment = [rightHandItem, ...generateArmorItems()]; 602 | } else { 603 | // New 1.9+ Equipment format 604 | if (equipShoes != "" || equipLeggings != "" || equipChestplate != "" || equipHelmet != "") { 605 | tags.ArmorItems = generateArmorItems(); 606 | } 607 | 608 | if (equipHandRight != "" || equipHandLeft != "") { 609 | tags.HandItems = generateHandItems(); 610 | } 611 | } 612 | } 613 | 614 | // Scoreboard tags 615 | if (scoreboardTags) { 616 | const tagsList = scoreboardTags.split(','); 617 | if (!tagsList[tagsList.length - 1].trim()) { 618 | tagsList.pop(); 619 | } 620 | 621 | tags.Tags = tagsList.map(value => value.trim()); 622 | } 623 | 624 | // Generate the final command 625 | if (give && mcVersion > MC_VERSION.v1_16) { 626 | tags.id = "minecraft:armor_stand"; 627 | } 628 | 629 | const parsedTags = NBT.stringify(tags); 630 | 631 | if (give) { 632 | let command = "/give @p "; 633 | if (mcVersion <= MC_VERSION.v1_11) { 634 | return command + "minecraft:armor_stand 1 0 {EntityTag:" + parsedTags + "}"; 635 | 636 | } else if (mcVersion <= MC_VERSION.v1_16) { 637 | return command + "minecraft:armor_stand{EntityTag:" + parsedTags + "} 1" 638 | 639 | } else { 640 | let code = "minecraft:armor_stand[minecraft:entity_data=" + parsedTags; 641 | if (customName && mcVersion >= MC_VERSION.v1_21) { 642 | code += `,minecraft:custom_name=${generateCustomName()}` 643 | } 644 | return command + code + "] 1"; 645 | } 646 | } else { 647 | if (mcVersion <= MC_VERSION.v1_9) { 648 | // Old entity name 649 | return "/summon ArmorStand ~ ~ ~ " + parsedTags; 650 | 651 | } else if (mcVersion < MC_VERSION.v1_13) { 652 | return "/summon minecraft:armor_stand ~ ~ ~ " + parsedTags; 653 | 654 | } else { 655 | // In 1.13, positions are no longer center-corrected. 656 | // Adding .5 makes it centered. However for players it is already center-corrected 657 | let position = centercorrected ? "~ ~-0.5 ~" : "~ ~ ~"; 658 | return "/summon minecraft:armor_stand " + position + " " + parsedTags; 659 | } 660 | } 661 | } 662 | 663 | function generateCustomName() { 664 | if (mcVersion <= MC_VERSION.v1_11) { 665 | // Versions less than 1.12 did not support styles 666 | return customName; 667 | } 668 | 669 | let props = {}; 670 | 671 | if (customName) { 672 | props.text = customName; 673 | } 674 | 675 | if (nameColor) { 676 | props.color = nameColor; 677 | } 678 | 679 | if (nameBold) { 680 | props.bold = nameBold; 681 | } 682 | 683 | if (nameItalic) { 684 | props.italic = nameItalic; 685 | } 686 | 687 | if (nameStrikethrough) { 688 | props.strikethrough = nameStrikethrough; 689 | } 690 | 691 | if (nameObfuscated) { 692 | props.obfuscated = nameObfuscated; 693 | } 694 | 695 | let stringified = JSON.stringify(props); 696 | if (mcVersion < MC_VERSION.v1_14) { 697 | // Stringify again to escape double quotes, as versions below 1.14 698 | // did not have the ability to use single quotes as strings 699 | return new NBTRaw(JSON.stringify(stringified)); 700 | } 701 | 702 | return new NBTRaw("'" + stringified + "'"); 703 | } 704 | 705 | function generateArmorItems() { 706 | function generateArmorItem(armorID) { 707 | if (armorID === "") { 708 | return {}; 709 | } 710 | 711 | let data = { 712 | id: armorID, 713 | Count: 1, 714 | } 715 | 716 | // If the armor is leather, then apply its color 717 | if (isLeatherArmor(armorID)) { 718 | const element = $(`#${armorID.substring(8) + "_color"}`); 719 | const color = getDecimalRGB(element.css("background-color")); 720 | 721 | if (mcVersion >= MC_VERSION.v1_20_5) { 722 | data.components = { 723 | dyed_color: { rgb: color } 724 | }; 725 | } else { 726 | data.tag = { 727 | display: { 728 | color: color 729 | } 730 | }; 731 | } 732 | } 733 | 734 | return data; 735 | } 736 | 737 | // Equipments (aka ArmorItems) are order-sensitive 738 | // and must follow the order: feet, legs, chest, head 739 | let items = [ 740 | generateArmorItem(equipShoes), 741 | generateArmorItem(equipLeggings), 742 | generateArmorItem(equipChestplate), 743 | ]; 744 | 745 | // Handle different items in the head slot 746 | if (equipHelmet == "") { 747 | items.push({}); 748 | return items; 749 | } 750 | 751 | switch (equipCustomHeadMode) { 752 | case "item": 753 | items.push(generateArmorItem(equipHelmet)); 754 | break; 755 | 756 | // Head is a player head with the given name 757 | case "player": { 758 | let data = { 759 | id: (mcVersion <= MC_VERSION.v1_11) ? "skull" : "player_head", 760 | Count: 1, 761 | }; 762 | 763 | if (mcVersion <= MC_VERSION.v1_11) { 764 | data.Damage = 3; 765 | } 766 | 767 | if (mcVersion <= MC_VERSION.v1_16) { 768 | data.tag = { SkullOwner: equipHelmet }; 769 | } else { 770 | data.components = { 771 | profile: { name: equipHelmet } 772 | }; 773 | } 774 | 775 | items.push(data); 776 | break; 777 | } 778 | 779 | case "url": { 780 | // Best reference: http://redd.it/24quwx 781 | const base64Value = btoa(JSON.stringify({ 782 | textures: { 783 | SKIN: { url: equipHelmet } 784 | } 785 | })); 786 | 787 | const innerNBT = { 788 | Id: (mcVersion >= MC_VERSION.v1_16) ? generateIntArray() : generateUUID(), 789 | Properties: { 790 | textures: [{ Value: base64Value }] 791 | } 792 | }; 793 | 794 | const data = { 795 | id: "minecraft:player_head", 796 | Count: 1 797 | }; 798 | 799 | if (mcVersion >= MC_VERSION.v1_20_5) { 800 | data.components = { 801 | profile: innerNBT 802 | }; 803 | 804 | } else { 805 | data.tag = { 806 | SkullOwner: innerNBT 807 | }; 808 | 809 | if (mcVersion < MC_VERSION.v1_13) { 810 | data.id = "skull"; 811 | data.Damage = 3; 812 | } 813 | } 814 | 815 | items.push(data); 816 | break; 817 | } 818 | 819 | case "givecode": { 820 | // For now, assume the give code is from minecraft-heads 821 | // TODO Parser to read any valid give codes 822 | const data = { 823 | id: "minecraft:player_head", 824 | Count: 1 825 | }; 826 | 827 | if (mcVersion < MC_VERSION.v1_13) { 828 | data.id = "skull"; 829 | data.Damage = 3; 830 | data.tag = new NBTRaw(equipHelmet.trim().slice(29)); 831 | 832 | } else if (mcVersion < MC_VERSION.v1_20_5) { 833 | data.tag = new NBTRaw(equipHelmet.trim().slice(30, -2)); 834 | 835 | } else { 836 | // Extracting the entity data for versions greater than 1.20.5 requires more work. 837 | // Format of the give code that is generated from minecraft-heads: 838 | // /give @p minecraft:player_head[minecraft:custom_name='...', minecraft:lore=[...], profile={...}] 1 839 | 840 | const nameIndex = equipHelmet.indexOf("minecraft:custom_name="); 841 | const loreIndex = equipHelmet.indexOf("minecraft:lore="); 842 | const profileIndex = equipHelmet.indexOf("profile="); 843 | 844 | const customName = equipHelmet.slice(nameIndex + 22, loreIndex - 1); 845 | const lore = equipHelmet.slice(loreIndex + 15, profileIndex - 1); 846 | const profile = equipHelmet.slice(profileIndex + 8, -3); 847 | 848 | data.components = { 849 | custom_name: new NBTRaw(customName), 850 | lore: new NBTRaw(lore), 851 | profile: new NBTRaw(profile), 852 | }; 853 | } 854 | 855 | items.push(data); 856 | break; 857 | } 858 | } 859 | 860 | return items; 861 | } 862 | 863 | function generateHandItems() { 864 | function generateHandItem(item) { 865 | if (item == "") { 866 | return {}; 867 | } 868 | 869 | return { 870 | id: item, 871 | Count: 1 872 | }; 873 | } 874 | 875 | // HandItems must follow the order: Main hand (right hand), Off hand (left hand) 876 | return [ 877 | generateHandItem(equipHandRight), 878 | generateHandItem(equipHandLeft), 879 | ]; 880 | } 881 | 882 | function generatePose() { 883 | const pose = {}; 884 | 885 | if (!isZero(body)) { 886 | pose.Body = toNBTFloatArray(body); 887 | } 888 | 889 | if (!isZero(head)) { 890 | pose.Head = toNBTFloatArray(head); 891 | } 892 | 893 | if (!isZero(leftLeg)) { 894 | pose.LeftLeg = toNBTFloatArray(leftLeg); 895 | } 896 | 897 | if (!isZero(rightLeg)) { 898 | pose.RightLeg = toNBTFloatArray(rightLeg); 899 | } 900 | 901 | if (showArms) { 902 | if (!isZero(leftArm)) { 903 | pose.LeftArm = toNBTFloatArray(leftArm); 904 | } 905 | 906 | if (!isZero(rightArm)) { 907 | pose.RightArm = toNBTFloatArray(rightArm); 908 | } 909 | } 910 | 911 | return (Object.keys(pose).length > 0) ? pose : null; 912 | } 913 | 914 | function calculateDisabledSlotsFlag() { 915 | var dO = $("#dO").is(":checked") ? 1 << (5) : 0; 916 | var dH = $("#dH").is(":checked") ? 1 << (4) : 0; 917 | var dC = $("#dC").is(":checked") ? 1 << (3) : 0; 918 | var dL = $("#dL").is(":checked") ? 1 << (2) : 0; 919 | var dB = $("#dB").is(":checked") ? 1 << (1) : 0; 920 | var dW = $("#dW").is(":checked") ? 1 << (0) : 0; 921 | var dR = dO + dH + dC + dL + dB + dW; 922 | 923 | var rO = $("#rO").is(":checked") ? 1 << (5 + 8) : 0; 924 | var rH = $("#rH").is(":checked") ? 1 << (4 + 8) : 0; 925 | var rC = $("#rC").is(":checked") ? 1 << (3 + 8) : 0; 926 | var rL = $("#rL").is(":checked") ? 1 << (2 + 8) : 0; 927 | var rB = $("#rB").is(":checked") ? 1 << (1 + 8) : 0; 928 | var rW = $("#rW").is(":checked") ? 1 << (0 + 8) : 0; 929 | var rR = rO + rH + rC + rL + rB + rW; 930 | 931 | var pO = $("#pO").is(":checked") ? 1 << (5 + 16) : 0; 932 | var pH = $("#pH").is(":checked") ? 1 << (4 + 16) : 0; 933 | var pC = $("#pC").is(":checked") ? 1 << (3 + 16) : 0; 934 | var pL = $("#pL").is(":checked") ? 1 << (2 + 16) : 0; 935 | var pB = $("#pB").is(":checked") ? 1 << (1 + 16) : 0; 936 | var pW = $("#pW").is(":checked") ? 1 << (0 + 16) : 0; 937 | var pR = pO + pH + pC + pL + pB + pW; 938 | 939 | var result = dR + rR + pR; 940 | return result; 941 | } 942 | 943 | function isZero(vector) { 944 | return vector.x == 0 && vector.y == 0 && vector.z == 0; 945 | } 946 | 947 | function toNBTFloatArray(vector) { 948 | return [ new NBTFloat(vector.x), new NBTFloat(vector.y), new NBTFloat(vector.z) ]; 949 | } 950 | 951 | function getMouseDeltaX(){ 952 | var mouseDeltaX = 0; 953 | if(mouseDownX != null && mouseMoveX != null){ 954 | mouseDeltaX = mouseMoveX - mouseDownX; 955 | } 956 | return mouseDeltaX * mouseRotationMultiplier; 957 | } 958 | function getMouseDeltaY(){ 959 | var mouseDeltaY = 0; 960 | if(mouseDownY != null && mouseMoveY != null){ 961 | mouseDeltaY = mouseMoveY - mouseDownY; 962 | } 963 | return mouseDeltaY * mouseRotationMultiplier; 964 | } 965 | 966 | function render(){ 967 | renderer.render(scene, camera); 968 | 969 | armorstandWrapper.rotation.y = rotY + getMouseDeltaX(); 970 | armorstandWrapper.rotation.x = rotX + getMouseDeltaY(); 971 | 972 | requestAnimationFrame(render); 973 | } 974 | 975 | // ---- Additional functions 976 | 977 | function generateUUID() { 978 | // From here: http://stackoverflow.com/a/8809472/1456971 979 | var d = new Date().getTime(); 980 | var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { 981 | var r = (d + Math.random()*16)%16 | 0; 982 | d = Math.floor(d/16); 983 | return (c=='x' ? r : (r&0x3|0x8)).toString(16); 984 | }); 985 | 986 | return uuid; 987 | } 988 | 989 | function generateIntArray() { 990 | const buffer = new Uint32Array(4); 991 | const UUID = new DataView(buffer.buffer); 992 | const paddings = [8, 4, 4, 4, 12]; 993 | 994 | let hexUUID = generateUUID().split("-").map((val, i) => val.padStart(paddings[i], "0")).join(""); 995 | let ints = []; 996 | 997 | for (let i = 0; i < 4; i++) { 998 | num = Number("0x" + hexUUID.substring(i*8, (i+1)*8)); 999 | UUID.setInt32(i*4, num); 1000 | ints.push(UUID.getInt32(i*4)); 1001 | } 1002 | 1003 | return new NBTArrayInt(ints); 1004 | } 1005 | 1006 | function getDecimalRGB(rgb){ 1007 | //The string has the format 'rgb(r, g, b)' 1008 | 1009 | //Remove whitespaces. Now formatted: 'rgb(r,g,b)' 1010 | rgb = rgb.replace(/ /g,""); 1011 | 1012 | var r = rgb.substring(4,rgb.indexOf(",")); 1013 | var g = rgb.substring(rgb.indexOf(",")+1,rgb.lastIndexOf(",")); 1014 | var b = rgb.substring(rgb.lastIndexOf(",")+1, rgb.length-1); 1015 | 1016 | 1017 | return (r << 16) | (g << 8) | b; 1018 | } 1019 | 1020 | function isLeatherArmor(item) { 1021 | return item ? item.startsWith("leather_") : false; 1022 | } 1023 | 1024 | // Rotate three.js mesh to fit the minecraft rotation 1025 | function setRotation(mesh, rotation){ 1026 | rotateAroundWorldAxis(mesh, new THREE.Vector3(1,0,0), rotation.x * DEG2RAD, true); 1027 | rotateAroundWorldAxis(mesh, new THREE.Vector3(0,1,0), -rotation.y * DEG2RAD, false); 1028 | rotateAroundWorldAxis(mesh, new THREE.Vector3(0,0,1), -rotation.z * DEG2RAD, false); 1029 | } 1030 | 1031 | // From here: http://stackoverflow.com/a/11124197/1456971 1032 | var rotWorldMatrix; 1033 | // Rotate an object around an arbitrary axis in world space 1034 | function rotateAroundWorldAxis(object, axis, radians, reset) { 1035 | rotWorldMatrix = new THREE.Matrix4(); 1036 | rotWorldMatrix.makeRotationAxis(axis.normalize(), radians); 1037 | if(!reset) 1038 | rotWorldMatrix.multiply(object.matrix); // pre-multiply 1039 | object.matrix = rotWorldMatrix; 1040 | object.rotation.setFromRotationMatrix(object.matrix); 1041 | } 1042 | 1043 | function saveData() { 1044 | // Handles saving of armor stand data 1045 | const SAVE_DATA = { 1046 | name: $(`#creationname`).val() === `` ? `My Armor Stand #${localStorage.length + 1}` : $(`#creationname`).val(), 1047 | version: $(`#mcversion`).val(), 1048 | 1049 | options: { 1050 | invisible: getCheckBoxInput("invisible"), 1051 | invulnerable: getCheckBoxInput("invulnerable"), 1052 | presistence_required: getCheckBoxInput("persistencerequired"), 1053 | no_base_plate: getCheckBoxInput("nobaseplate"), 1054 | no_gravity: getCheckBoxInput("nogravity"), 1055 | show_arms: getCheckBoxInput("showarms"), 1056 | small: getCheckBoxInput("small"), 1057 | marker: getCheckBoxInput("marker"), 1058 | center_corrected: getCheckBoxInput("center-corrected") 1059 | }, 1060 | 1061 | rotation: { 1062 | main: getRangeInput("rotation"), 1063 | head: [getRangeInput("headX"), getRangeInput("headY"), getRangeInput("headZ")], 1064 | body: [getRangeInput("bodyX"), getRangeInput("bodyY"), getRangeInput("bodyZ")], 1065 | legs: { 1066 | left: [getRangeInput("leftLegX"), getRangeInput("leftLegY"), getRangeInput("leftLegZ")], 1067 | right: [getRangeInput("rightLegX"), getRangeInput("rightLegY"), getRangeInput("rightLegZ")], 1068 | }, 1069 | arms: { 1070 | left: [getRangeInput("leftArmX"), getRangeInput("leftArmY"), getRangeInput("leftArmZ")], 1071 | right: [getRangeInput("rightArmX"), getRangeInput("rightArmY"), getRangeInput("rightArmZ")] 1072 | } 1073 | }, 1074 | 1075 | equipment: { 1076 | enabled: getCheckBoxInput("useequipment"), 1077 | hands: { 1078 | right: getInput("equipHandRight"), 1079 | left: getInput("equipHandLeft") 1080 | }, 1081 | boots: getInput("equipShoes"), 1082 | leggings: getInput("equipLeggings"), 1083 | chestplate: getInput("equipChestplate"), 1084 | helmet: getInput("equipHelmet"), 1085 | helmet_specifies: $("#equipCustomHeadMode").val(), 1086 | 1087 | leather_colours: { 1088 | helmet: $(`#helmet_color`).css(`background-color`), 1089 | chestplate: $(`#chestplate_color`).css(`background-color`), 1090 | leggings: $(`#leggings_color`).css(`background-color`), 1091 | boots: $(`#boots_color`).css(`background-color`) 1092 | } 1093 | }, 1094 | 1095 | custom_name: { 1096 | name: $(`#customname`).val(), 1097 | show_custom_name: getCheckBoxInput("showcustomname"), 1098 | name_color: getInput("namecolor"), 1099 | options: { 1100 | bold: getCheckBoxInput("namebold"), 1101 | italic: getCheckBoxInput("nameitalic"), 1102 | obfuscated: getCheckBoxInput("nameobfuscated"), 1103 | strikethrough: getCheckBoxInput("namestrikethrough") 1104 | } 1105 | }, 1106 | 1107 | scoreboard_tags: getInput("scoreboardtags"), 1108 | 1109 | lock_slot_interaction: { 1110 | enabled: $("input[name=usedisabledslots]").is(":checked"), 1111 | remove: { 1112 | helmet: $("#dH").is(":checked"), 1113 | chestplate: $("#dC").is(":checked"), 1114 | leggings: $("#dL").is(":checked"), 1115 | boots: $("#dB").is(":checked"), 1116 | weapons: $("#dW").is(":checked"), 1117 | offhand: $("#dO").is(":checked") 1118 | }, 1119 | replace: { 1120 | helmet: $("#rH").is(":checked"), 1121 | chestplate: $("#rC").is(":checked"), 1122 | leggings: $("#rL").is(":checked"), 1123 | boots: $("#rB").is(":checked"), 1124 | weapons: $("#rW").is(":checked"), 1125 | offhand: $("#rO").is(":checked") 1126 | }, 1127 | place: { 1128 | helmet: $("#pH").is(":checked"), 1129 | chestplate: $("#pC").is(":checked"), 1130 | leggings: $("#pL").is(":checked"), 1131 | boots: $("#pB").is(":checked"), 1132 | weapons: $("#pW").is(":checked"), 1133 | offhand: $("#pO").is(":checked") 1134 | } 1135 | } 1136 | }; 1137 | 1138 | localStorage.setItem(SAVE_DATA.name, JSON.stringify(SAVE_DATA)); 1139 | loadScreen(); 1140 | $(`#creationname`).val(``); 1141 | alert(`Awesome! Your creation has been saved as ${SAVE_DATA.name}.`); 1142 | }; 1143 | 1144 | function loadData(data) { 1145 | //console.log(`loading data!`); 1146 | data = localStorage.getItem(data); 1147 | if (!data) return alert(`An error occurred while loading the creation.`); 1148 | 1149 | try { 1150 | data = JSON.parse(data); 1151 | 1152 | // version 1153 | $(`#mcversion`).val(data.version); 1154 | 1155 | // options 1156 | $("input[name=invisible]").prop(`checked`, data.options.invisible); 1157 | $("input[name=invulnerable]").prop(`checked`, data.options.invulnerable); 1158 | $("input[name=persistencerequired]").prop(`checked`, data.options.presistence_required); 1159 | $("input[name=nobaseplate]").prop(`checked`, data.options.no_base_plate); 1160 | $("input[name=nogravity]").prop(`checked`, data.options.no_gravity); 1161 | $("input[name=showarms]").prop(`checked`, data.options.show_arms); 1162 | $("input[name=small]").prop(`checked`, data.options.small); 1163 | $("input[name=marker]").prop(`checked`, data.options.marker); 1164 | $("input[name=center-corrected]").prop(`checked`, data.options.center_corrected); 1165 | 1166 | // rotation 1167 | $("input[name=rotation]").val(data.rotation.main); 1168 | $("input[name=headX]").val(data.rotation.head[0]); 1169 | $("input[name=headY]").val(data.rotation.head[1]); 1170 | $("input[name=headZ]").val(data.rotation.head[2]); 1171 | 1172 | $("input[name=bodyX]").val(data.rotation.body[0]); 1173 | $("input[name=bodyY]").val(data.rotation.body[1]); 1174 | $("input[name=bodyZ]").val(data.rotation.body[2]); 1175 | 1176 | $("input[name=leftLegX]").val(data.rotation.legs.left[0]); 1177 | $("input[name=leftLegY]").val(data.rotation.legs.left[1]); 1178 | $("input[name=leftLegZ]").val(data.rotation.legs.left[2]); 1179 | 1180 | $("input[name=rightLegX]").val(data.rotation.legs.right[0]); 1181 | $("input[name=rightLegY]").val(data.rotation.legs.right[1]); 1182 | $("input[name=rightLegZ]").val(data.rotation.legs.right[2]); 1183 | 1184 | $("input[name=leftArmX]").val(data.rotation.arms.left[0]); 1185 | $("input[name=leftArmY]").val(data.rotation.arms.left[1]); 1186 | $("input[name=leftArmZ]").val(data.rotation.arms.left[2]); 1187 | 1188 | $("input[name=rightArmX]").val(data.rotation.arms.right[0]); 1189 | $("input[name=rightArmY]").val(data.rotation.arms.right[1]); 1190 | $("input[name=rightArmZ]").val(data.rotation.arms.right[2]); 1191 | 1192 | //equipment 1193 | $("input[name=useequipment]").prop(`checked`, data.equipment.enabled); 1194 | $(`input[name=equipShoes]`).val(data.equipment.boots); 1195 | $(`input[name=equipLeggings]`).val(data.equipment.leggings); 1196 | $(`input[name=equipChestplate]`).val(data.equipment.chestplate); 1197 | $(`input[name=equipHelmet]`).val(data.equipment.helmet); 1198 | $(`input[name=equipHandRight]`).val(data.equipment.hands.right); 1199 | $(`input[name=equipHandLeft]`).val(data.equipment.hands.left); 1200 | $(`#equipCustomHeadMode`).val(data.equipment.helmet_specifies); 1201 | 1202 | $(`#helmet_color`).css(`background-color`, data.equipment.leather_colours.helmet); 1203 | $(`#chestplate_color`).css(`background-color`, data.equipment.leather_colours.chestplate); 1204 | $(`#leggings_color`).css(`background-color`, data.equipment.leather_colours.leggings); 1205 | $(`#boots_color`).css(`background-color`, data.equipment.leather_colours.boots); 1206 | 1207 | //custom name 1208 | $(`#customname`).val(data.custom_name.name); 1209 | $(`input[name=showcustomname]`).prop(`checked`, data.custom_name.show_custom_name); 1210 | $(`input[name=namecolor]`).val(data.custom_name.name_color); 1211 | $("input[name=namebold]").prop(`checked`, data.custom_name.options.bold); 1212 | $("input[name=nameitalic]").prop(`checked`, data.custom_name.options.italic); 1213 | $("input[name=nameobfuscated]").prop(`checked`, data.custom_name.options.obfuscated); 1214 | $("input[name=namestrikethrough]").prop(`checked`, data.custom_name.options.strikethrough); 1215 | 1216 | $("input[name=scoreboardtags]").val(data.scoreboard_tags); 1217 | 1218 | //lock slot interaction 1219 | $("input[name=usedisabledslots]").prop(`checked`, data.lock_slot_interaction.enabled); 1220 | 1221 | $(`#dO`).prop(`checked`, data.lock_slot_interaction.remove.offhand); 1222 | $(`#dH`).prop(`checked`, data.lock_slot_interaction.remove.helmet); 1223 | $(`#dC`).prop(`checked`, data.lock_slot_interaction.remove.chestplate); 1224 | $(`#dL`).prop(`checked`, data.lock_slot_interaction.remove.leggings); 1225 | $(`#dB`).prop(`checked`, data.lock_slot_interaction.remove.boots); 1226 | $(`#dW`).prop(`checked`, data.lock_slot_interaction.remove.weapons); 1227 | 1228 | $(`#rO`).prop(`checked`, data.lock_slot_interaction.replace.offhand); 1229 | $(`#rH`).prop(`checked`, data.lock_slot_interaction.replace.helmet); 1230 | $(`#rC`).prop(`checked`, data.lock_slot_interaction.replace.chestplate); 1231 | $(`#rL`).prop(`checked`, data.lock_slot_interaction.replace.leggings); 1232 | $(`#rB`).prop(`checked`, data.lock_slot_interaction.replace.boots); 1233 | $(`#rW`).prop(`checked`, data.lock_slot_interaction.replace.weapons); 1234 | 1235 | $(`#pO`).prop(`checked`, data.lock_slot_interaction.place.offhand); 1236 | $(`#pH`).prop(`checked`, data.lock_slot_interaction.place.helmet); 1237 | $(`#pC`).prop(`checked`, data.lock_slot_interaction.place.chestplate); 1238 | $(`#pL`).prop(`checked`, data.lock_slot_interaction.place.leggings); 1239 | $(`#pB`).prop(`checked`, data.lock_slot_interaction.place.boots); 1240 | $(`#pW`).prop(`checked`, data.lock_slot_interaction.place.weapons); 1241 | 1242 | handleInput(); 1243 | } catch (err) { 1244 | console.error(err); 1245 | alert(`An error occurred while loading the creation.`); 1246 | }; 1247 | 1248 | //loadScreen(); 1249 | }; 1250 | 1251 | function deleteSave(data) { 1252 | localStorage.removeItem(data); 1253 | loadScreen(); 1254 | alert(`${data} has been deleted!`); 1255 | }; 1256 | 1257 | // Define NBT classes for properly stringifying JS objects to NBT 1258 | class NBTObject {}; 1259 | 1260 | class NBTRaw extends NBTObject { 1261 | constructor(raw) { 1262 | super(); 1263 | this.raw = raw; 1264 | } 1265 | 1266 | toString() { 1267 | return this.raw; 1268 | } 1269 | } 1270 | 1271 | class NBTFloat extends NBTObject { 1272 | constructor(n) { 1273 | super(); 1274 | this.n = n; 1275 | } 1276 | 1277 | toString() { 1278 | return this.n + "f"; 1279 | } 1280 | } 1281 | 1282 | class NBTArrayInt extends NBTObject { 1283 | constructor(arr) { 1284 | super(); 1285 | this.arr = arr; 1286 | } 1287 | 1288 | toString() { 1289 | return "[I;" + this.arr.join(",") + "]"; 1290 | } 1291 | }; 1292 | 1293 | class NBT { 1294 | static stringify(object) { 1295 | const type = typeof object; 1296 | switch (type) { 1297 | case "string": 1298 | return '"' + object + '"'; 1299 | 1300 | case "number": 1301 | case "boolean": 1302 | return new String(object); 1303 | 1304 | case "object": { 1305 | if (Array.isArray(object)) { 1306 | return "[" + 1307 | object 1308 | .filter(value => value != null) 1309 | .map(value => NBT.stringify(value)) 1310 | .join(",") 1311 | + "]"; 1312 | } 1313 | 1314 | if (object instanceof NBTObject) { 1315 | return object.toString(); 1316 | } 1317 | 1318 | // Fallback (javascript object) 1319 | return "{" + 1320 | Object.entries(object) 1321 | .filter(([key, value]) => value != null) 1322 | .map(([key, value]) => key + ":" + NBT.stringify(value)) 1323 | .join(",") 1324 | + "}"; 1325 | } 1326 | } 1327 | } 1328 | } -------------------------------------------------------------------------------- /style.css: -------------------------------------------------------------------------------- 1 | html, body{ 2 | height: 100%; 3 | font-family: Arial, sans-serif; 4 | margin: 0; 5 | padding: 0; 6 | } 7 | 8 | canvas{ 9 | position: relative; 10 | top: 0; 11 | left: 0; 12 | } 13 | 14 | body{ 15 | background-color: #dddddd; 16 | } 17 | 18 | div{ 19 | padding: 0; 20 | margin: 0; 21 | } 22 | 23 | h1{ 24 | text-align: center; 25 | font-family: "Oswald", sans-serif; 26 | margin: 0; 27 | } 28 | 29 | a{ 30 | color: #000000; 31 | } 32 | 33 | button { 34 | border: 1px solid #aaa; 35 | background-color: rgb(230, 230, 230); 36 | border-radius: 3px; 37 | padding: 0.5em; 38 | } 39 | 40 | button:hover { 41 | cursor: pointer; 42 | background-color: rgb(220, 220, 220); 43 | } 44 | 45 | button:active { 46 | background-color: rgb(200, 200, 200); 47 | } 48 | 49 | button:focus { 50 | 51 | outline:0; 52 | } 53 | 54 | input[type="text"], select{ 55 | border: 1px solid #aaa; 56 | border-radius: 3px; 57 | padding: 0.5em; 58 | } 59 | input[type="text"]:not(:last-child){ 60 | margin-bottom: 0.5em; 61 | } 62 | #customname{ 63 | margin-bottom: 0; 64 | } 65 | 66 | #gl{ 67 | width: 60%; 68 | height: 100%; 69 | float: left; 70 | cursor: move; 71 | position: fixed; 72 | } 73 | 74 | .card{ 75 | background-color: #ffffff; 76 | box-shadow: 0 2px 4px #555555; 77 | margin: 0.5em; 78 | border-radius: 3px; 79 | padding: 1em; 80 | } 81 | 82 | .right{ 83 | margin-left: 60%; 84 | } 85 | 86 | .padding{ 87 | padding: 1em; 88 | } 89 | 90 | .underline{ 91 | border-bottom: 1px dashed #ddd; 92 | } 93 | 94 | .code{ 95 | word-wrap: break-word; 96 | padding: 1em; 97 | font-family: monospace; 98 | background-color: #37474f; 99 | border-radius: 3px; 100 | color: #ffffff; 101 | } 102 | #code-copy-hint{ 103 | font-family: sans-serif; 104 | font-style: italic; 105 | font-size: 0.8em; 106 | text-align: right; 107 | opacity: 0.6; 108 | } 109 | 110 | #disabledslots{ 111 | display: block; 112 | } 113 | 114 | #disabledslots .first{ 115 | width: 60px; 116 | display: inline-block; 117 | clear: left; 118 | text-align: right; 119 | vertical-align: top; 120 | } 121 | 122 | #disabledslots span{ 123 | width: 16px; 124 | height: 16px; 125 | display: inline-block; 126 | } 127 | 128 | #disabledslots div{ 129 | height: 16px; 130 | line-height: 16px; 131 | } 132 | 133 | #disabledslots div + div{ 134 | margin-top: 4px; 135 | } 136 | 137 | #disabledslots input[type=checkbox]{ 138 | width: 16px; 139 | height: 16px; 140 | margin: 0; 141 | } 142 | 143 | #disabledslots .sprite{ 144 | background-repeat: no-repeat; 145 | background-image: url("images/slots.png"); 146 | width: 16px; 147 | height: 16px; 148 | display: inline-block; 149 | } 150 | 151 | /* Things needed for colorpicker */ 152 | .colorfield{ 153 | display: inline-block; 154 | width: 15%; 155 | vertical-align: middle; 156 | height: 1em; 157 | background-color: #ff8800; 158 | border: 1px solid #777; 159 | } 160 | 161 | .equipment{ 162 | width: 80%; 163 | } 164 | 165 | .rotations{ 166 | width: 100%; 167 | text-align: right; 168 | } 169 | 170 | .rotations tr td:nth-child(1){ 171 | width: 80px; 172 | } 173 | 174 | .rotations input{ 175 | width: 100%; 176 | } 177 | --------------------------------------------------------------------------------