├── .gitattributes
├── .gitignore
├── LICENSE
├── README.md
├── examples
├── libtrails-example-basic
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── devcexx
│ │ │ └── libtrails
│ │ │ └── examples
│ │ │ └── basic
│ │ │ └── BasicExample.java
│ │ └── resources
│ │ └── plugin.yml
├── libtrails-example-colorful
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── devcexx
│ │ │ └── libtrails
│ │ │ └── examples
│ │ │ └── colorful
│ │ │ └── ColorfulExample.java
│ │ └── resources
│ │ └── plugin.yml
├── libtrails-example-skin-gadget
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── devcexx
│ │ │ └── libtrails
│ │ │ └── examples
│ │ │ └── skin
│ │ │ ├── CachedSkin.java
│ │ │ ├── DefaultSkinModel.java
│ │ │ ├── PlayerState.java
│ │ │ ├── Reflector.java
│ │ │ ├── SkinDownloader.java
│ │ │ ├── SkinExample.java
│ │ │ └── SkinPixelProvider.java
│ │ └── resources
│ │ ├── alex.png
│ │ ├── plugin.yml
│ │ └── steve.png
└── pom.xml
├── library
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── devcexx
│ └── libtrails
│ ├── EntityTrail.java
│ ├── LinearTransf.java
│ ├── Particle.java
│ ├── ParticleSupplier.java
│ ├── SuppliedParticle.java
│ ├── TrailUtil.java
│ ├── Vector3.java
│ └── suppliers
│ ├── BitmapSupplier.java
│ ├── CircumferenceSupplier.java
│ ├── EpitrochoidSupplier.java
│ ├── HelixSupplier.java
│ ├── HypotrochoidSupplier.java
│ ├── LinearSupplier.java
│ ├── PolySupplier.java
│ ├── ScatteringSupplier.java
│ ├── SinusoidalSupplier.java
│ ├── SpirographSupplier.java
│ └── StarSupplier.java
└── pom.xml
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.java text eol=lf encoding=utf-8
2 | *.xml text eol=lf encoding=utf-8
3 | *.yml text eol=lf encoding=utf-8
4 | LICENSE text eol=lf encoding=utf-8
5 | README.md text eol=lf encoding=utf-8
6 | *.png binary
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .idea/
3 | **/target/
4 | server/
5 | *.iml
6 | pom.xml.versionsBackup
7 | dependency-reduced-pom.xml
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 | {one line to give the program's name and a brief idea of what it does.}
635 | Copyright (C) {year} {name of author}
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | {project} Copyright (C) {year} {fullname}
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Libtrails
2 | Little trails & particles library for Spigot.
3 |
4 | This library contains utilities oriented to simplify the creation of trails and effects with particles in Spigot. This includes mathematical functions to work with vectors in the three-dimensional space and some kawaii predefined trails such as helix generators, sinusoidal waves, some shapes generators and even a image renderer with particles.
5 |
6 | It's important to note that this library is optimized for using it with the Java 8 Functional API (lambda expressions, streams, you know), so Java 8 is required to use this library.
7 |
8 | ## Usage
9 |
10 | First things first, you have to be clear about that **THIS IS NOT A SPIGOT PLUGIN**. This is just a utility library and, therefore, if you want to use it, you should shade it into your plugin final jar.
11 |
12 | As I don't provide any Maven repository for this library, if you are using GIT as VCS, maybe could be a good idea to use this project as a submodule, to make easier the compilation process, and to be sure that you're code is always up-to-date with the project.
13 |
14 | This Maven project is divided in two main reactors: the library itself and an example reactor, that contains example plugins of the usage of this library. This examples are fully functional plugins that can be directly loaded by spigot to be tested, and can help you to understood (unless until I write a better README file). If you want to compile just the library, you have to activate the profile `build-library` of the Maven project as follows:
15 |
16 | ```mvn clean install -Pbuild-library```
17 |
18 | In the other hand, if you want to compile only the examples, you have to active the profile `build-examples` of the project:
19 |
20 | ```mvn clean install -Pbuild-examples```
21 |
22 | ## Compatibility
23 |
24 | This library is supposed to work in Spigot 1.8 - 1.11 inclusive, but it has been only tested in Spigot 1.8. Also, it uses some deprecated API in the Spigot 1.11 API Specification to allow the library to be compatible with previous versions of it.
25 |
26 | ## License
27 |
28 | This software is under the GNU GPL v3 license. This mean, in a nutshell, that you can freely use and distribute open source software that uses this library, but you cannot use it for privative projects. For more details about this license, please refer to the file LICENSE present in this repository.
29 |
--------------------------------------------------------------------------------
/examples/libtrails-example-basic/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | 4.0.0
7 |
8 |
9 | com.devcexx
10 | libtrails-examples
11 | 1.0
12 | ../pom.xml
13 |
14 |
15 | libtrails-example-basic
16 | 1.0
17 |
18 |
19 |
20 | com.devcexx
21 | libtrails
22 | 1.0.3
23 |
24 |
25 |
26 |
27 |
28 |
29 | src/main/resources
30 | true
31 |
32 |
33 |
34 |
35 |
36 | org.apache.maven.plugins
37 | maven-shade-plugin
38 | 2.4.3
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/examples/libtrails-example-basic/src/main/java/com/devcexx/libtrails/examples/basic/BasicExample.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of libtrails.
3 | * libtrails is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * libtrails is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with libtrails. If not, see .
15 | */
16 |
17 | package com.devcexx.libtrails.examples.basic;
18 |
19 | import com.devcexx.libtrails.EntityTrail;
20 | import com.devcexx.libtrails.Particle;
21 | import com.devcexx.libtrails.Vector3;
22 | import com.devcexx.libtrails.suppliers.ScatteringSupplier;
23 | import org.bukkit.Bukkit;
24 | import org.bukkit.Effect;
25 | import org.bukkit.entity.Arrow;
26 | import org.bukkit.entity.Entity;
27 | import org.bukkit.entity.Player;
28 | import org.bukkit.event.EventHandler;
29 | import org.bukkit.event.Listener;
30 | import org.bukkit.event.entity.EntityShootBowEvent;
31 | import org.bukkit.event.entity.ProjectileHitEvent;
32 | import org.bukkit.plugin.java.JavaPlugin;
33 |
34 | import java.util.HashMap;
35 | import java.util.Map;
36 | import java.util.Random;
37 |
38 | public class BasicExample extends JavaPlugin implements Listener {
39 | private final Map trails = new HashMap<>();
40 | private final Particle[] particles = new Particle[] {
41 | Particle.builder()
42 | .effect(Effect.FIREWORKS_SPARK)
43 | .offsetX(0.0f)
44 | .offsetZ(0.0f)
45 | .count(3)
46 | .radius(120)
47 | .build(),
48 |
49 | Particle.builder()
50 | .effect(Effect.FLAME)
51 | .offsetX(0.0f)
52 | .offsetZ(0.0f)
53 | .count(3)
54 | .radius(120)
55 | .build(),
56 |
57 | Particle.builder()
58 | .effect(Effect.SMOKE)
59 | .offsetX(0.0f)
60 | .offsetZ(0.0f)
61 | .count(3)
62 | .radius(120)
63 | .build(),
64 | };
65 | @Override
66 | public void onEnable() {
67 | getServer().getPluginManager().registerEvents(this, this);
68 | }
69 |
70 | @EventHandler
71 | public void onBowShot(EntityShootBowEvent e) {
72 | if (e.getEntity() instanceof Player &&
73 | e.getProjectile() instanceof Arrow) {
74 | Bukkit.getScheduler().runTaskLater(this, () -> {
75 | if (!e.getProjectile().isDead()) {
76 | EntityTrail t = new EntityTrail(this, e.getProjectile(),
77 | new ScatteringSupplier(particles,
78 | new Vector3(2.0f, 1.0f, 2.0f),
79 | Vector3.ORIGIN, 5, 20, 1)
80 | , 1);
81 |
82 | trails.put(e.getProjectile(), t);
83 | t.begin();
84 | }
85 | }, 5L);
86 | }
87 | }
88 |
89 | @EventHandler
90 | public void onProjectileHit(ProjectileHitEvent e) {
91 | if (e.getEntity() instanceof Arrow) {
92 | EntityTrail t = trails.remove(e.getEntity());
93 | if (t != null)
94 | t.stop();
95 | }
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/examples/libtrails-example-basic/src/main/resources/plugin.yml:
--------------------------------------------------------------------------------
1 | name: ${project.artifactId}
2 | version: ${project.version}
3 | author: devcexx
4 | main: com.devcexx.libtrails.examples.basic.BasicExample
--------------------------------------------------------------------------------
/examples/libtrails-example-colorful/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | libtrails-examples
7 | com.devcexx
8 | 1.0
9 |
10 | 4.0.0
11 |
12 | libtrails-example-colorful
13 | 1.0
14 |
15 |
16 |
17 | com.devcexx
18 | libtrails
19 | 1.0.3
20 |
21 |
22 |
23 |
24 |
25 |
26 | src/main/resources
27 | true
28 |
29 |
30 |
31 |
32 |
33 | org.apache.maven.plugins
34 | maven-shade-plugin
35 | 2.4.3
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/examples/libtrails-example-colorful/src/main/java/com/devcexx/libtrails/examples/colorful/ColorfulExample.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of libtrails.
3 | * libtrails is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * libtrails is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with libtrails. If not, see .
15 | */
16 |
17 | package com.devcexx.libtrails.examples.colorful;
18 |
19 | import com.devcexx.libtrails.EntityTrail;
20 | import com.devcexx.libtrails.Particle;
21 | import com.devcexx.libtrails.suppliers.CircumferenceSupplier;
22 | import org.bukkit.Bukkit;
23 | import org.bukkit.Effect;
24 | import org.bukkit.entity.Arrow;
25 | import org.bukkit.entity.Entity;
26 | import org.bukkit.entity.Player;
27 | import org.bukkit.event.EventHandler;
28 | import org.bukkit.event.Listener;
29 | import org.bukkit.event.entity.EntityShootBowEvent;
30 | import org.bukkit.event.entity.ProjectileHitEvent;
31 | import org.bukkit.plugin.java.JavaPlugin;
32 |
33 | import java.util.HashMap;
34 | import java.util.Map;
35 |
36 | public class ColorfulExample extends JavaPlugin implements Listener {
37 |
38 | private final Map trails = new HashMap<>();
39 | private final Particle particle = Particle.builder()
40 | .effect(Effect.COLOURED_DUST)
41 | .count(0)
42 | .speed(1.0f)
43 | .offsetX(this::tickToColor)
44 |
45 | /* Both Green and Blue components follows the same Piecewise as the
46 | * Red channel, with shifted to the right.
47 | */
48 | .offsetY(t -> tickToColor(t + 256))
49 | .offsetZ(t -> tickToColor(t + 512))
50 | .radius(120)
51 | .build();
52 |
53 |
54 | private float tickToColor(int tick) {
55 | tick = (tick * 20) % 1536;
56 | if (tick < 256) return 1.0f;
57 | if (tick < 512) return Math.max(0.001f, (255 - (tick % 256)) / 256.0f);
58 | if (tick < 1024) return 0.0f;
59 | if (tick < 1280) return Math.max(0.001f, (tick % 256) / 256.0f);
60 | return 1.0f;
61 | }
62 |
63 | @Override
64 | public void onEnable() {
65 | getServer().getPluginManager().registerEvents(this, this);
66 | }
67 |
68 |
69 | @EventHandler
70 | public void onBowShot(EntityShootBowEvent e) {
71 | if (e.getEntity() instanceof Player &&
72 | e.getProjectile() instanceof Arrow) {
73 | Bukkit.getScheduler().runTaskLater(this, () -> {
74 | if (!e.getProjectile().isDead()) {
75 | EntityTrail t = new EntityTrail(this, e.getProjectile(),
76 | new CircumferenceSupplier(particle, 1.2f, 0.9f, 0.0f, 1)
77 | .rotateY(tick -> tick * (2.0f * (float) Math.PI / 20))
78 | , 1);
79 | trails.put(e.getProjectile(), t);
80 | t.begin();
81 | }
82 | }, 5L);
83 | }
84 | }
85 |
86 | @EventHandler
87 | public void onProjectileHit(ProjectileHitEvent e) {
88 | if (e.getEntity() instanceof Arrow) {
89 | EntityTrail t = trails.remove(e.getEntity());
90 | if (t != null)
91 | t.stop();
92 | }
93 | }
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/examples/libtrails-example-colorful/src/main/resources/plugin.yml:
--------------------------------------------------------------------------------
1 | name: ${project.artifactId}
2 | version: ${project.version}
3 | author: devcexx
4 | main: com.devcexx.libtrails.examples.colorful.ColorfulExample
--------------------------------------------------------------------------------
/examples/libtrails-example-skin-gadget/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | libtrails-examples
7 | com.devcexx
8 | 1.0
9 |
10 | 4.0.0
11 |
12 | libtrails-example-skin-gadget
13 | 1.0
14 |
15 |
16 |
17 | mojang-repo
18 | https://libraries.minecraft.net
19 |
20 |
21 |
22 |
23 |
24 | com.devcexx
25 | libtrails
26 | 1.0.3
27 |
28 |
29 |
30 | com.mojang
31 | authlib
32 | 1.5.21
33 |
34 |
35 |
36 |
37 |
38 |
39 | src/main/resources
40 | true
41 |
42 |
43 |
44 |
45 |
46 | org.apache.maven.plugins
47 | maven-shade-plugin
48 | 2.4.3
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/examples/libtrails-example-skin-gadget/src/main/java/com/devcexx/libtrails/examples/skin/CachedSkin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of libtrails.
3 | * libtrails is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * libtrails is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with libtrails. If not, see .
15 | */
16 |
17 | package com.devcexx.libtrails.examples.skin;
18 |
19 | import com.devcexx.libtrails.suppliers.BitmapSupplier;
20 |
21 | import java.util.UUID;
22 |
23 | public class CachedSkin {
24 | public long timestamp;
25 | public final BitmapSupplier supplier;
26 | public final UUID owner;
27 | public final String skinUrl;
28 |
29 |
30 | public CachedSkin(String skinUrl, UUID owner, BitmapSupplier s) {
31 | this.owner = owner;
32 | this.supplier = s;
33 | this.skinUrl = skinUrl;
34 | this.timestamp = System.currentTimeMillis();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/examples/libtrails-example-skin-gadget/src/main/java/com/devcexx/libtrails/examples/skin/DefaultSkinModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of libtrails.
3 | * libtrails is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * libtrails is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with libtrails. If not, see .
15 | */
16 |
17 | package com.devcexx.libtrails.examples.skin;
18 |
19 | public enum DefaultSkinModel {
20 | STEVE,
21 | ALEX
22 | }
23 |
--------------------------------------------------------------------------------
/examples/libtrails-example-skin-gadget/src/main/java/com/devcexx/libtrails/examples/skin/PlayerState.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of libtrails.
3 | * libtrails is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * libtrails is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with libtrails. If not, see .
15 | */
16 |
17 | package com.devcexx.libtrails.examples.skin;
18 |
19 | import org.bukkit.entity.Player;
20 |
21 | import java.util.UUID;
22 |
23 | class PlayerState {
24 | public final Player player;
25 | public final UUID id;
26 | public final DefaultSkinModel defSkinModel;
27 | public CachedSkin currentSkin;
28 | public long lastMovementTime;
29 |
30 |
31 | PlayerState(Player p) {
32 | this.player = p;
33 | this.id = p.getUniqueId();
34 | this.defSkinModel = (id.hashCode() & 1) == 1 ?
35 | DefaultSkinModel.ALEX :
36 | DefaultSkinModel.STEVE;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/examples/libtrails-example-skin-gadget/src/main/java/com/devcexx/libtrails/examples/skin/Reflector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of libtrails.
3 | * libtrails is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * libtrails is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with libtrails. If not, see .
15 | */
16 |
17 | package com.devcexx.libtrails.examples.skin;
18 |
19 | import java.lang.reflect.Method;
20 |
21 | public class Reflector {
22 | public static Object invoke(Class> from, String method, Object instance,
23 | Class>[] types, Object[] params){
24 | try {
25 | Method mtd = from.getDeclaredMethod(method, types);
26 | mtd.setAccessible(true);
27 | return mtd.invoke(instance, params == null ?
28 | new Object[0] : params);
29 | } catch (Exception ex){
30 | throw new RuntimeException("Reflection error!", ex);
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/examples/libtrails-example-skin-gadget/src/main/java/com/devcexx/libtrails/examples/skin/SkinDownloader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of libtrails.
3 | * libtrails is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * libtrails is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with libtrails. If not, see .
15 | */
16 |
17 | package com.devcexx.libtrails.examples.skin;
18 |
19 | import com.google.common.collect.Iterators;
20 | import com.mojang.authlib.GameProfile;
21 | import com.mojang.authlib.properties.Property;
22 | import org.bukkit.entity.Player;
23 | import org.bukkit.plugin.Plugin;
24 | import org.json.simple.JSONObject;
25 | import org.json.simple.parser.JSONParser;
26 | import org.json.simple.parser.ParseException;
27 |
28 | import javax.imageio.ImageIO;
29 | import java.awt.image.BufferedImage;
30 | import java.io.IOException;
31 | import java.net.URL;
32 | import java.util.Base64;
33 | import java.util.Collection;
34 | import java.util.concurrent.Executor;
35 | import java.util.concurrent.Executors;
36 | import java.util.logging.Logger;
37 |
38 | public class SkinDownloader {
39 |
40 | private final Logger logger;
41 | private final Executor pool = Executors
42 | .newCachedThreadPool(r -> new Thread(r, "Skin Downloader"));
43 |
44 | public SkinDownloader(Plugin pl) {
45 | this.logger = pl.getLogger();
46 | }
47 |
48 | public void beginDownloadSkin(String url, Callback
49 | callback) {
50 | pool.execute(() -> {
51 | try {
52 | BufferedImage img = downloadSkin(url);
53 | if (callback != null) {
54 | callback.done(img);
55 | }
56 | } catch (Exception ex) {
57 | logger.severe("Failed to download skin from url " + url);
58 | ex.printStackTrace();
59 | }
60 | });
61 | }
62 |
63 | public BufferedImage downloadSkin(String url)
64 | throws IOException{
65 | return ImageIO.read(new URL(url));
66 | }
67 |
68 | public String getSkinUrl(Player p) throws ParseException {
69 | return getSkinUrl((GameProfile) Reflector
70 | .invoke(p.getClass(), "getProfile", p, null, null));
71 | }
72 |
73 | public String getSkinUrl(GameProfile prof) throws ParseException {
74 | Collection ps = prof.getProperties().get("textures");
75 |
76 | if (ps == null || ps.isEmpty()) {
77 | return null;
78 | } else {
79 | Property p = Iterators.getLast(ps.iterator());
80 |
81 | JSONObject obj = (JSONObject) new JSONParser().parse(
82 | new String(Base64.getDecoder().decode(p.getValue())));
83 |
84 | obj = ((JSONObject) obj.get("textures"));
85 | obj = ((JSONObject) obj.get("SKIN"));
86 | return (String) obj.get("url");
87 | }
88 | }
89 |
90 | public interface Callback {
91 | void done(T o);
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/examples/libtrails-example-skin-gadget/src/main/java/com/devcexx/libtrails/examples/skin/SkinExample.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of libtrails.
3 | * libtrails is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * libtrails is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with libtrails. If not, see .
15 | */
16 |
17 | package com.devcexx.libtrails.examples.skin;
18 |
19 | import com.devcexx.libtrails.LinearTransf;
20 | import com.devcexx.libtrails.Vector3;
21 | import com.devcexx.libtrails.suppliers.BitmapSupplier;
22 | import com.google.common.collect.Collections2;
23 | import com.google.common.collect.Maps;
24 | import org.bukkit.Bukkit;
25 | import org.bukkit.Effect;
26 | import org.bukkit.Location;
27 | import org.bukkit.entity.Player;
28 | import org.bukkit.event.EventHandler;
29 | import org.bukkit.event.Listener;
30 | import org.bukkit.event.player.PlayerJoinEvent;
31 | import org.bukkit.event.player.PlayerMoveEvent;
32 | import org.bukkit.event.player.PlayerQuitEvent;
33 | import org.bukkit.plugin.java.JavaPlugin;
34 | import org.json.simple.parser.ParseException;
35 |
36 | import javax.imageio.ImageIO;
37 | import java.awt.image.BufferedImage;
38 | import java.io.InputStream;
39 | import java.util.Collection;
40 | import java.util.Iterator;
41 | import java.util.Map;
42 | import java.util.UUID;
43 |
44 | public class SkinExample extends JavaPlugin implements Listener {
45 |
46 | private CachedSkin steveSkin;
47 | private CachedSkin alexSkin;
48 |
49 | private final SkinDownloader downloader = new SkinDownloader(this);
50 | private final Collection onlineIds = Collections2.transform(
51 | Bukkit.getOnlinePlayers(), f -> f == null ? null : f.getUniqueId());
52 |
53 | private final Map cachedSkins = Maps.newHashMap();
54 | private final Map playerState = Maps.newHashMap();
55 |
56 |
57 | @Override
58 | public void onEnable() {
59 | getServer().getPluginManager().registerEvents(this, this);
60 |
61 | try {
62 | try (InputStream in = getResource("alex.png")) {
63 | alexSkin = new CachedSkin(null, null,
64 | buildSupplier(ImageIO.read(in)));
65 | }
66 |
67 | try (InputStream in = getResource("steve.png")) {
68 | steveSkin = new CachedSkin(null, null,
69 | buildSupplier(ImageIO.read(in)));
70 | }
71 |
72 | getServer().getScheduler().runTaskTimer(this, new SkinCacheCleanupper(),
73 | 100L, 100L);
74 | getServer().getScheduler().runTaskTimer(this, new PlayerTicker(),
75 | 5L, 5L);
76 |
77 | for (Player p : Bukkit.getOnlinePlayers()){
78 | performJoin(p);
79 | }
80 | } catch (Exception ex) {
81 | getLogger().severe("Failed to load plugin!");
82 | ex.printStackTrace();
83 | getServer().getPluginManager().disablePlugin(this);
84 | }
85 | }
86 |
87 | public void performJoin(Player player) {
88 | PlayerState st = new PlayerState(player);
89 |
90 | CachedSkin skin = cachedSkins.get(player.getUniqueId());
91 |
92 | String url;
93 | try {
94 | url = downloader.getSkinUrl(player);
95 | } catch (ParseException e1) {
96 | url = null;
97 | getLogger().severe("Error parsing GameProfile data!");
98 | e1.printStackTrace();
99 | }
100 |
101 | if (skin == null || (url != null && !skin.skinUrl.equals(url))) {
102 | st.currentSkin = getDefaultSkin(st);
103 | String finalUrl = url;
104 |
105 | if (url != null) {
106 | downloader.beginDownloadSkin(url, img -> {
107 | if (img != null) {
108 | BitmapSupplier supplier = buildSupplier(img);
109 | Bukkit.getScheduler().runTask(this, () -> {
110 | CachedSkin sk = new CachedSkin(finalUrl,
111 | player.getUniqueId(), supplier);
112 | cachedSkins.put(sk.owner, sk);
113 | st.currentSkin = sk;
114 | });
115 | }
116 | });
117 | }
118 | }
119 |
120 | playerState.put(player.getUniqueId(), st);
121 | }
122 |
123 | @EventHandler
124 | public void onJoin(PlayerJoinEvent e) {
125 | performJoin(e.getPlayer());
126 | }
127 |
128 | @EventHandler
129 | public void onMove(PlayerMoveEvent e) {
130 | if (e.getFrom().distanceSquared(e.getTo()) > 0.0) {
131 | playerState.get(e.getPlayer().getUniqueId()).lastMovementTime =
132 | System.currentTimeMillis();
133 | }
134 | }
135 |
136 | @EventHandler
137 | public void onQuit(PlayerQuitEvent e) {
138 | playerState.remove(e.getPlayer().getUniqueId());
139 | }
140 |
141 | public BitmapSupplier buildSupplier(BufferedImage img) {
142 | return new BitmapSupplier(Effect.COLOURED_DUST, 1, 60,
143 | new SkinPixelProvider(img), 8, 8, 2.0f, 2.0f, 8.0f, 8.0f);
144 | }
145 |
146 | public CachedSkin getDefaultSkin(PlayerState p) {
147 | return p.defSkinModel == DefaultSkinModel.STEVE ? steveSkin : alexSkin;
148 | }
149 |
150 | private class PlayerTicker implements Runnable {
151 |
152 | @Override
153 | public void run() {
154 | for (PlayerState st : playerState.values()) {
155 | if (System.currentTimeMillis() - st.lastMovementTime > 100) {
156 |
157 | Location ploc = st.player.getLocation().add(0, 3.0, 0);
158 | Vector3 direction = Vector3.from(ploc.getDirection())
159 | .stripY();
160 | Vector3 position = Vector3.from(ploc);
161 | st.currentSkin.supplier.transformVectors(
162 | LinearTransf.translate(0.1f, 0.0f, 0.0f).andThen(
163 | LinearTransf.rotateRenderPlane(direction)
164 | .andThen(LinearTransf
165 | .translate(position))))
166 | .supply(1).forEach((p) ->
167 | p.particle.spawn(st.player.getWorld(), p.position));
168 | }
169 | }
170 | }
171 | }
172 |
173 | private class SkinCacheCleanupper implements Runnable {
174 |
175 | @Override
176 | public void run() {
177 | Iterator iterator = cachedSkins.values().iterator();
178 | while (iterator.hasNext()) {
179 | CachedSkin k = iterator.next();
180 | boolean timedout = System.currentTimeMillis() -
181 | k.timestamp > 1800;
182 | if (onlineIds.contains(k.owner)) {
183 | k.timestamp = System.currentTimeMillis();
184 | } else if (timedout ||
185 | (cachedSkins.size() > 200 &&
186 | onlineIds.size() < cachedSkins.size())) {
187 | iterator.remove();
188 | }
189 | }
190 | }
191 | }
192 | }
193 |
--------------------------------------------------------------------------------
/examples/libtrails-example-skin-gadget/src/main/java/com/devcexx/libtrails/examples/skin/SkinPixelProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of libtrails.
3 | * libtrails is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * libtrails is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with libtrails. If not, see .
15 | */
16 |
17 | package com.devcexx.libtrails.examples.skin;
18 |
19 | import java.awt.image.BufferedImage;
20 | import java.util.function.IntBinaryOperator;
21 |
22 | public class SkinPixelProvider implements IntBinaryOperator {
23 | private final BufferedImage skin;
24 |
25 | public SkinPixelProvider(BufferedImage skin) {
26 | this.skin = skin;
27 | }
28 |
29 | @Override
30 | public int applyAsInt(int x, int y) {
31 |
32 | //Test for helmet
33 | int color = skin.getRGB(40 + x, 8 + y);
34 | if (((color >> 24) & 0xFF) > 0) { //Check for total transparency
35 | return color;
36 | } else {
37 | //If there's not helmet at that position, return the
38 | //color of the normal head.
39 | return skin.getRGB(8 + x, 8 + y);
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/examples/libtrails-example-skin-gadget/src/main/resources/alex.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devcexx/libtrails/053f8caebd819607becd0f903a22fdf60cb82217/examples/libtrails-example-skin-gadget/src/main/resources/alex.png
--------------------------------------------------------------------------------
/examples/libtrails-example-skin-gadget/src/main/resources/plugin.yml:
--------------------------------------------------------------------------------
1 | name: ${project.artifactId}
2 | version: ${project.version}
3 | author: devcexx
4 | main: com.devcexx.libtrails.examples.skin.SkinExample
--------------------------------------------------------------------------------
/examples/libtrails-example-skin-gadget/src/main/resources/steve.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devcexx/libtrails/053f8caebd819607becd0f903a22fdf60cb82217/examples/libtrails-example-skin-gadget/src/main/resources/steve.png
--------------------------------------------------------------------------------
/examples/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | 4.0.0
7 |
8 |
9 | com.devcexx
10 | libtrails-parent
11 | 1.0-SNAPSHOT
12 | ../pom.xml
13 |
14 |
15 | libtrails-examples
16 | 1.0
17 | pom
18 |
19 |
20 | libtrails-example-basic
21 | libtrails-example-skin-gadget
22 | libtrails-example-colorful
23 |
24 |
25 |
26 |
27 |
28 |
29 | org.apache.maven.plugins
30 | maven-shade-plugin
31 | 2.4.3
32 |
33 |
34 |
35 | package
36 |
37 | shade
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 | com.devcexx:libtrails
46 |
47 |
48 |
49 |
50 |
51 | org.apache.maven.plugins
52 | maven-compiler-plugin
53 | 3.5.1
54 |
55 |
56 | 1.8
57 | 1.8
58 |
59 |
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/library/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 |
8 | com.devcexx
9 | libtrails-parent
10 | 1.0-SNAPSHOT
11 |
12 |
13 | libtrails
14 | 1.0.3
15 |
16 |
17 |
18 | spigot-repo
19 | https://hub.spigotmc.org/nexus/content/repositories/snapshots/
20 |
21 |
22 |
23 |
24 |
25 | org.spigotmc
26 | spigot-api
27 | 1.11.2-R0.1-SNAPSHOT
28 | provided
29 |
30 |
31 |
32 |
33 |
34 |
35 | org.apache.maven.plugins
36 | maven-javadoc-plugin
37 | 2.7
38 |
39 |
40 |
41 | prepare-javadoc
42 | prepare-package
43 |
44 | javadoc
45 |
46 |
47 |
48 | attach-javadoc
49 | package
50 |
51 | jar
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/library/src/main/java/com/devcexx/libtrails/EntityTrail.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of libtrails.
3 | * libtrails is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * libtrails is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with libtrails. If not, see .
15 | */
16 |
17 | package com.devcexx.libtrails;
18 |
19 | import org.bukkit.Bukkit;
20 | import org.bukkit.Location;
21 | import org.bukkit.entity.Arrow;
22 | import org.bukkit.entity.Entity;
23 | import org.bukkit.plugin.Plugin;
24 | import org.bukkit.scheduler.BukkitTask;
25 |
26 | import java.util.function.Function;
27 |
28 | /**
29 | * Represents a trail of particles that can be synchronized with the movement
30 | * and the direction of an entity.
31 | */
32 | public class EntityTrail {
33 |
34 | /**
35 | * The entity that owns this trail.
36 | */
37 | public final Entity entity;
38 |
39 | /**
40 | * The plugin that will register all the tasks.
41 | */
42 | public final Plugin plugin;
43 |
44 | /**
45 | * The interval of the scheduled task.
46 | */
47 | public final int taskInterval;
48 |
49 | /**
50 | * The transformation applied to the direction of the entity that allows
51 | * to correctly apply a trail over it.
52 | */
53 | public Function entityDirectionTransformer;
54 |
55 | /**
56 | * The transformation applied to the position of the entity that allows
57 | * to correctly apply a trail over it.
58 | */
59 | public Function entityPositionTransformer;
60 |
61 | /**
62 | * The supplier of the trail that will be applied over the entity.
63 | */
64 | public ParticleSupplier trail;
65 |
66 | /**
67 | * The number of ticks that of life that the trail has.
68 | */
69 | public int ticksAlive;
70 |
71 | private boolean began;
72 | private BukkitTask task;
73 |
74 | /**
75 | * Determines whether the particle is being rendered or not.
76 | * @return true if does. false otherwhise.
77 | */
78 | public boolean hasBegun() {
79 | return began;
80 | }
81 |
82 | private static Function getDefaultDirFunction(Entity e){
83 | if (e instanceof Arrow)
84 | return v -> v.mul(-1.0f, -1.0f, 1.0f);
85 | return v -> v;
86 |
87 | }
88 |
89 | /**
90 | * Creates a new {@link EntityTrail} with the default transformations for
91 | * both position and entity location, optimized for each entity.
92 | * @param plugin The plugin that owns this trail.
93 | * @param entity The entity that owns this trail.
94 | * @param trail The trail that will be applied.
95 | * @param interval The interval, in Minecraft ticks, of the task that will
96 | * render the trail.
97 | */
98 | public EntityTrail(Plugin plugin, Entity entity, ParticleSupplier trail,
99 | int interval) {
100 | this(plugin, entity, getDefaultDirFunction(entity), v -> v, trail,
101 | interval);
102 | }
103 |
104 | /**
105 | * Creates a new {@link EntityTrail}.
106 | * @param plugin The plugin that owns this trail.
107 | * @param entity The entity that owns this trail.
108 | * @param directionTransf The transformation applied to the direction of the
109 | * entity that allows to correctly apply a trail
110 | * over it.
111 | * @param positionTransf The transformation applied to the position of the
112 | * entity that allows to correctly apply a trail
113 | * over it.
114 | * @param trail The trail that will be applied.
115 | * @param interval The interval, in Minecraft ticks, of the task that will
116 | * render the trail.
117 | */
118 | public EntityTrail(Plugin plugin, Entity entity,
119 | Function directionTransf,
120 | Function positionTransf,
121 | ParticleSupplier trail, int interval) {
122 | this.entityDirectionTransformer = directionTransf == null
123 | ? v -> v : directionTransf;
124 | this.entityPositionTransformer = positionTransf == null
125 | ? v -> v : positionTransf;
126 | this.entity = entity;
127 | this.trail = trail;
128 | this.taskInterval = interval;
129 | this.plugin = plugin;
130 | }
131 |
132 | /**
133 | * Begins the task to render the trail. If the task is already started, it
134 | * does nothing.
135 | */
136 | public void begin() {
137 | if (!began) {
138 | began = true;
139 | task = Bukkit.getScheduler().runTaskTimer(plugin, new TrailTicker(),
140 | 0, taskInterval);
141 | }
142 | }
143 |
144 | /**
145 | * Stops the trail rendering. If the {@link #begin()} method is called again
146 | * after invoking this method, the trail will be start rendering with the
147 | * value of ticksAlive that has when it stopped, unless the method
148 | * {@link #reset()} is called before.
149 | */
150 | public void stop() {
151 | if (began) {
152 | task.cancel();
153 | task = null;
154 | began = false;
155 | }
156 | }
157 |
158 | /**
159 | * Resets the life of the trail to zero.
160 | */
161 | public void reset() {
162 | ticksAlive = 0;
163 | }
164 |
165 | private class TrailTicker implements Runnable {
166 |
167 | @Override
168 | public void run() {
169 | if (entity.isDead() || !entity.isValid()) {
170 | stop();
171 | } else {
172 | Location eLoc = entity.getLocation();
173 | Vector3 position = entityPositionTransformer.apply(Vector3
174 | .from(eLoc));
175 | Vector3 direction = entityDirectionTransformer.apply(Vector3
176 | .from(eLoc.getDirection()));
177 |
178 | ParticleSupplier finalSupplier = trail.transformVectors(
179 | LinearTransf.rotateRenderPlane(direction)
180 | .andThen(LinearTransf.translate(position)));
181 |
182 | finalSupplier.supply(ticksAlive).forEach((p) -> p.particle
183 | .spawn(eLoc.getWorld(), p.position, ticksAlive));
184 | ticksAlive += taskInterval;
185 | }
186 | }
187 | }
188 | }
189 |
--------------------------------------------------------------------------------
/library/src/main/java/com/devcexx/libtrails/LinearTransf.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of libtrails.
3 | * libtrails is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * libtrails is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with libtrails. If not, see .
15 | */
16 |
17 | package com.devcexx.libtrails;
18 |
19 | import java.util.function.Function;
20 |
21 | public abstract class LinearTransf {
22 | public static Function translate(float xoffset,
23 | float yoffset,
24 | float zoffset) {
25 | return v -> v.add(xoffset, yoffset, zoffset);
26 | }
27 |
28 | public static Function translate(Vector3 vec) {
29 | return v -> v.add(vec);
30 | }
31 |
32 | public static Function scale(float scaleFactor) {
33 | return v -> v.scale(scaleFactor);
34 | }
35 |
36 | public static Function rotate(Vector3 axis, float angle) {
37 | return v -> v.rotate(axis, angle);
38 | }
39 |
40 | public static Function rotateRenderPlane(Vector3 normal) {
41 | //Gets the rotation axis of the transformation.
42 | Vector3 axis = Vector3.AXIS_Y.cross(normal).normalize();
43 | if (axis.equals(Vector3.ORIGIN)) {
44 | if (Vector3.AXIS_Y.dot(normal) > 0) {
45 | //Axis Y has the same direction as normal. Nothing to do
46 | return v -> v;
47 | } else {
48 | //Axis Y is opposite to normal.
49 | axis = Vector3.AXIS_Z;
50 | }
51 | }
52 |
53 | //Get normal vector on the XZ plane.
54 | Vector3 xzvector = normal.stripY();
55 |
56 | //Gets the rotation angle of the normal vector
57 | //around the y axis.
58 | float yAngle = (float) Vector3.AXIS_Z.fullAngle(xzvector,
59 | Vector3.AXIS_Y);
60 |
61 | //Gets the rotation axis of the transformation.
62 | float angle = (float) normal.angle(Vector3.AXIS_Y);
63 |
64 | //First rotation: rotates the point around the y axis
65 | //to place the drawing in front of the rotation axis, to avoid
66 | //unexpected rotations.
67 |
68 | //Second rotation: rotates the point around the axis of the
69 | //rotation between the Y axis and the new normal axis, to place
70 | //the drawing inside the plane.
71 | Vector3 faxis = axis;
72 | return v -> v.rotateY(yAngle + (float) Math.PI).rotate(faxis, angle);
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/library/src/main/java/com/devcexx/libtrails/Particle.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of libtrails.
3 | * libtrails is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * libtrails is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with libtrails. If not, see .
15 | */
16 |
17 | package com.devcexx.libtrails;
18 |
19 | import lombok.AllArgsConstructor;
20 | import lombok.Builder;
21 | import lombok.With;
22 | import lombok.experimental.Tolerate;
23 | import org.bukkit.Effect;
24 | import org.bukkit.Location;
25 | import org.bukkit.World;
26 | import org.bukkit.entity.Player;
27 |
28 | import java.util.function.Function;
29 |
30 | @With
31 | @Builder
32 | @AllArgsConstructor
33 | public class Particle {
34 | private final Effect effect;
35 | private final int id;
36 | private final int data;
37 |
38 | private final Function offsetX;
39 | private final Function offsetY;
40 | private final Function offsetZ;
41 |
42 | private final Function speed;
43 | private final Function count;
44 | private final int radius;
45 |
46 | public Particle withOffset(float offX, float offY, float offZ) {
47 | return new Particle(effect, id, data, (tick) -> offX, (tick) -> offY, (tick) -> offZ,
48 | speed, count, radius);
49 | }
50 |
51 | public Particle withOffset(Function fx,
52 | Function fy,
53 | Function fz) {
54 | return new Particle(effect, id, data, fx, fy, fz,
55 | speed, count, radius);
56 | }
57 |
58 | @Tolerate
59 | public Particle withOffsetX(float offX) {
60 | return withOffsetX((tick) -> offX);
61 | }
62 |
63 | @Tolerate
64 | public Particle withOffsetY(float offY) {
65 | return withOffsetY((tick) -> offY);
66 | }
67 |
68 | @Tolerate
69 | public Particle withOffsetZ(float offZ) {
70 | return withOffsetZ((tick) -> offZ);
71 | }
72 |
73 | @Tolerate
74 | public Particle withSpeed(float speed) {
75 | return withSpeed((tick) -> speed);
76 | }
77 |
78 | @Tolerate
79 | public Particle withCount(int count) {
80 | return withCount((tick) -> count);
81 | }
82 |
83 | public void spawn(Player p, Vector3 loc) {
84 | spawn(p, loc, 0);
85 | }
86 |
87 | public void spawn(Player p, float x, float y, float z) {
88 | spawn(p, x, y, z, 0);
89 | }
90 |
91 | public void spawn(World w, Vector3 loc) {
92 | spawn(w, loc, 0);
93 | }
94 |
95 | public void spawn(World w, float x, float y, float z) {
96 | spawn(w, x, y, z, 0);
97 | }
98 |
99 | public void spawn(Player p, Vector3 loc, int tick) {
100 | spawn0(p, loc.toLocation(p.getWorld()), tick);
101 | }
102 |
103 | public void spawn(Player p, float x, float y, float z, int tick) {
104 | spawn0(p, new Location(p.getWorld(), x, y, z), tick);
105 | }
106 |
107 | public void spawn(World w, Vector3 loc, int tick) {
108 | spawn0(w, loc.toLocation(w), tick);
109 | }
110 |
111 | public void spawn(World w, float x, float y, float z, int tick) {
112 | spawn0(w, new Location(w, x, y, z), tick);
113 | }
114 |
115 | private void spawn0(Object o, Location loc, int tick) {
116 | float offx = this.offsetX.apply(tick);
117 | float offy = this.offsetY.apply(tick);
118 | float offz = this.offsetZ.apply(tick);
119 | float speed = this.speed.apply(tick);
120 | int n = this.count.apply(tick);
121 |
122 | if (o instanceof Player) {
123 | ((Player)o).spigot().playEffect(loc, effect, id, data,
124 | offx, offy, offz, speed, n, radius);
125 | } else {
126 | ((World)o).spigot().playEffect(loc, effect, id, data,
127 | offx, offy, offz, speed, n, radius);
128 | }
129 | }
130 |
131 | public static class ParticleBuilder {
132 | public ParticleBuilder() {
133 | this.offsetX = (tick) -> 0.0f;
134 | this.offsetY = (tick) -> 0.0f;
135 | this.offsetZ = (tick) -> 0.0f;
136 | this.speed = (tick) -> 0.0f;
137 | this.count = (tick) -> 1;
138 | }
139 |
140 | @Tolerate
141 | public ParticleBuilder offsetX(float offsetX) {
142 | return offsetX((tick) -> offsetX);
143 | }
144 |
145 | @Tolerate
146 | public ParticleBuilder offsetY(float offsetY) {
147 | return offsetY((tick) -> offsetY);
148 | }
149 |
150 | @Tolerate
151 | public ParticleBuilder offsetZ(float offsetZ) {
152 | return offsetZ((tick) -> offsetZ);
153 | }
154 |
155 | @Tolerate
156 | public ParticleBuilder speed(float speed) {
157 | return speed((tick) -> speed);
158 | }
159 |
160 | @Tolerate
161 | public ParticleBuilder count(int count) {
162 | return count((tick) -> count);
163 | }
164 | }
165 | }
166 |
--------------------------------------------------------------------------------
/library/src/main/java/com/devcexx/libtrails/ParticleSupplier.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of libtrails.
3 | * libtrails is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * libtrails is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with libtrails. If not, see .
15 | */
16 |
17 | package com.devcexx.libtrails;
18 |
19 | import java.util.function.BiFunction;
20 | import java.util.function.Function;
21 | import java.util.stream.Stream;
22 |
23 | /**
24 | * An interface that identifies a class as a particle supplier for a determined
25 | * particle trails.
26 | */
27 | public interface ParticleSupplier {
28 |
29 | /**
30 | * Returns a stream of particles that should be render at the specified
31 | * moment.
32 | * @param tick a number that the particle rendering should be dependent of.
33 | * The caller of this method should invoke it with consecutive
34 | * values of this number, with a fixed delay rate, to ensure
35 | * the particle system is rendered correctly.
36 | * @return an Stream that contains the particles that should be render
37 | * at this moment.
38 | */
39 | Stream supply(int tick);
40 |
41 | /**
42 | * Creates a {@link ParticleSupplier} whose {@link #supply(int)} method
43 | * returns the current output stream transformed by the specified function.
44 | * @param f A {@link BiFunction} that requires a Stream, as the Stream
45 | * that should be transformed; and an Integer, as the tick
46 | * parameter of the {@link #supply(int)} call, and returns the
47 | * transformed Stream.
48 | * @return a new ParticleSupplier with its {@link #supply(int)} output value
49 | * transformed as requested.
50 | */
51 | default ParticleSupplier transformStream(
52 | BiFunction, Integer,
53 | Stream> f) {
54 | return tick -> f.apply(ParticleSupplier.this.supply(tick), tick);
55 | }
56 |
57 | /**
58 | * Creates a {@link ParticleSupplier} whose {@link #supply(int)} returns
59 | * the current output stream where all of its entries are transformed by
60 | * the specified function.
61 | * @param f A {@link BiFunction} that requires a {@link SuppliedParticle},
62 | * as the particle to transform, and an Integer, as the tick
63 | * parameter of the {@link #supply(int)} call, and returns the
64 | * transformed particle.
65 | * @return a new ParticleSupplier with its {@link #supply(int)} output value
66 | * transformed as requested.
67 | */
68 | default ParticleSupplier transformParticles(
69 | BiFunction f) {
70 | return transformStream((s, t) -> s.map(p -> f.apply(p, t)));
71 | }
72 |
73 | /**
74 | * Creates a {@link ParticleSupplier} whose {@link #supply(int)} returns
75 | * the current output stream where all of its entries are transformed by
76 | * the specified function.
77 | * @param f A {@link BiFunction} that requires a {@link SuppliedParticle},
78 | * as the particle to transform, and an Integer, as the tick
79 | * parameter of the {@link #supply(int)} call, and returns the
80 | * transformed particle.
81 | * @return a new ParticleSupplier with its {@link #supply(int)} output value
82 | * transformed as requested.
83 | */
84 | default ParticleSupplier transformVectors(Function f) {
85 | return transformStream((s, t) -> s.map(p -> p.with(f.apply(p.position))));
86 | }
87 |
88 | default ParticleSupplier combine(ParticleSupplier... others) {
89 | return transformStream((s, t) -> {
90 | Stream stream = s;
91 | for (ParticleSupplier p : others) {
92 | stream = Stream.concat(s, p.supply(t));
93 | }
94 | return stream;
95 | });
96 | }
97 |
98 | /**
99 | * Creates a {@link ParticleSupplier} whose {@link #supply(int)} returns
100 | * the current output stream where all of its entries are translated as
101 | * specified.
102 | * @param f a {@link Function} that takes an Integer, as the tick of the
103 | * current call, and returns the translation vector for that tick.
104 | * @return a new ParticleSupplier with its {@link #supply(int)} output value
105 | * transformed as requested.
106 | */
107 | default ParticleSupplier translate(Function f) {
108 | return transformParticles((p, t) -> p.with(p.position.add(f.apply(t))));
109 | }
110 |
111 | /**
112 | * Creates a {@link ParticleSupplier} whose {@link #supply(int)} returns
113 | * the current output stream where all of its entries are scaled as
114 | * specified.
115 | * @param f a {@link Function} that takes an Integer, as the tick of the
116 | * current call, and returns the scale factor for that tick.
117 | * @return a new ParticleSupplier with its {@link #supply(int)} output value
118 | * transformed as requested.
119 | */
120 | default ParticleSupplier scale(Function f) {
121 | return transformParticles((p, t) -> p.with(p.position
122 | .scale(f.apply(t))));
123 | }
124 |
125 | /**
126 | * Creates a {@link ParticleSupplier} whose {@link #supply(int)} returns
127 | * the current output stream where all of its entries are rotated as
128 | * specified.
129 | * @param f a {@link Function} that takes an Integer, as the tick of the
130 | * current call, and returns the rotation angle around the x axis
131 | * for that tick.
132 | * @return a new ParticleSupplier with its {@link #supply(int)} output value
133 | * transformed as requested.
134 | */
135 | default ParticleSupplier rotateX(Function f) {
136 | return transformParticles((p, t) -> p.with(p.position
137 | .rotateX(f.apply(t))));
138 | }
139 |
140 | /**
141 | * Creates a {@link ParticleSupplier} whose {@link #supply(int)} returns
142 | * the current output stream where all of its entries are rotated as
143 | * specified.
144 | * @param f a {@link Function} that takes an Integer, as the tick of the
145 | * current call, and returns the rotation angle around the y axis
146 | * for that tick.
147 | * @return a new ParticleSupplier with its {@link #supply(int)} output value
148 | * transformed as requested.
149 | */
150 | default ParticleSupplier rotateY(Function f) {
151 | return transformParticles((p, t) -> p.with(p.position
152 | .rotateY(f.apply(t))));
153 | }
154 |
155 | /**
156 | * Creates a {@link ParticleSupplier} whose {@link #supply(int)} returns
157 | * the current output stream where all of its entries are rotated as
158 | * specified.
159 | * @param f a {@link Function} that takes an Integer, as the tick of the
160 | * current call, and returns the rotation angle around the z axis
161 | * for that tick.
162 | * @return a new ParticleSupplier with its {@link #supply(int)} output value
163 | * transformed as requested.
164 | */
165 | default ParticleSupplier rotateZ(Function f) {
166 | return transformParticles((p, t) -> p.with(p.position
167 | .rotateZ(f.apply(t))));
168 | }
169 |
170 | }
171 |
--------------------------------------------------------------------------------
/library/src/main/java/com/devcexx/libtrails/SuppliedParticle.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of libtrails.
3 | * libtrails is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * libtrails is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with libtrails. If not, see .
15 | */
16 |
17 | package com.devcexx.libtrails;
18 |
19 | /**
20 | * Represents a particle provided by a {@link ParticleSupplier}, ready to be
21 | * spawned.
22 | */
23 | public class SuppliedParticle {
24 | /**
25 | * The particle that should be rendered.
26 | */
27 | public final Particle particle;
28 |
29 | /**
30 | * The position of the particle respect the origin.
31 | */
32 | public final Vector3 position;
33 |
34 | /**
35 | * Creates a new supplied particle, from the specified particle and offset.
36 | * @param particle The particle that should be rendered.
37 | * @param position The position of the particle respect the origin.
38 | */
39 | public SuppliedParticle(Particle particle, Vector3 position) {
40 | this.particle = particle;
41 | this.position = position;
42 | }
43 |
44 | /**
45 | * Returns a new {@link SuppliedParticle} with the specified particle.
46 | * @param p the new particle.
47 | * @return A new instance of the {@link SuppliedParticle} with the specified
48 | * particle, and the same offset.
49 | */
50 | public SuppliedParticle with(Particle p) {
51 | return new SuppliedParticle(p, position);
52 | }
53 |
54 | /**
55 | * Returns a new {@link SuppliedParticle} wt
56 | * @param o the new offset.
57 | * @return A new instance of the {@link SuppliedParticle} with the same
58 | * particle and the specified new offset.
59 | */
60 | public SuppliedParticle with(Vector3 o) {
61 | return new SuppliedParticle(particle, o);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/library/src/main/java/com/devcexx/libtrails/TrailUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of libtrails.
3 | * libtrails is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * libtrails is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with libtrails. If not, see .
15 | */
16 |
17 | package com.devcexx.libtrails;
18 |
19 | /**
20 | * Provides some methods to perform some common operations.
21 | */
22 | public abstract class TrailUtil {
23 |
24 | /**
25 | * Returns an approximation of the inverse square root of the specified
26 | * number.
27 | * @param n A number greater or equal to zero, whose inverse square root
28 | * will be calculated.
29 | * @return the inverse square root of the specified number.
30 | */
31 | public static double isqrt(double n) {
32 | double xhalf = 0.5 * n;
33 | long i = Double.doubleToRawLongBits(n);
34 | i = 0x5FE6EB50C7B537AAL - (i>>1);
35 | n = Double.longBitsToDouble(i);
36 | n = n * (1.5 - xhalf*n*n);
37 | return n;
38 | }
39 |
40 | /**
41 | * Returns an approximation of the square root of the specified number.
42 | * This method is equivalent to {@code 1.0 / isqrt(n)}
43 | * @param n A number greater or equal to zero, whose square root
44 | * will be calculated.
45 | * @return the square root of the specified number.
46 | */
47 | public static double sqrt(double n)
48 | {
49 | return 1.0 / isqrt(n);
50 | }
51 |
52 | /**
53 | * Returns the Greatest Common Division using a recursive algorithm based
54 | * on the Euclides theorem.
55 | * @param a the first number, positive.
56 | * @param b the second number, positive.
57 | * @return The Greatest Common Division of the input numbers.
58 | */
59 | public static int gcd(int a, int b) {
60 | int min = Math.min(a,b);
61 | int max = Math.max(a,b);
62 |
63 | int r = max % min;
64 | if (r == 0) {
65 | return min;
66 | } else {
67 | return gcd(min, r);
68 | }
69 | }
70 |
71 | /**
72 | * Draws a line into the specified array.
73 | * @param buffer The array where the line will be w
74 | * @param p The particles that will be used to draw the line.
75 | * @param index The first index where the line particles will be placed.
76 | * @param from The location of the first point of the line.
77 | * @param director The unit vector that defines the direction of the line.
78 | * @param step The distance between each point of the line.
79 | * @param n The number of the points of the line.
80 | */
81 | public static void fillWithLine(SuppliedParticle[] buffer, Particle p,
82 | int index, Vector3 from,
83 | Vector3 director, float step, int n) {
84 | for (int i = 0; i < n; i++) {
85 | buffer[index + i] = new SuppliedParticle(p,
86 | from.add(director.mul(step * i)));
87 | }
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/library/src/main/java/com/devcexx/libtrails/Vector3.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of libtrails.
3 | * libtrails is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * libtrails is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with libtrails. If not, see .
15 | */
16 |
17 | package com.devcexx.libtrails;
18 |
19 | import lombok.Data;
20 | import org.bukkit.Location;
21 | import org.bukkit.World;
22 | import org.bukkit.block.Block;
23 | import org.bukkit.util.Vector;
24 |
25 | /**
26 | * Represents a vector member of the R^3 Euclidean vector space and provides
27 | * methods to transform it. This class is immutable. This means that the
28 | * components xyz of the vector cannot be modified after the constructor, and
29 | * all the methods that returns instances of Vector3 will return fresh instances
30 | * of this class.
31 | *
32 | * @author devcexx
33 | */
34 | @Data
35 | public class Vector3 {
36 | /**
37 | * A final field that contains the null vector of the Euclidean space
38 | * (0,0,0)
39 | */
40 | public static final Vector3 ORIGIN = new Vector3(0,0,0);
41 |
42 | /**
43 | * A final field that contains the director vector of the X-axis of the
44 | * canonical base.
45 | */
46 | public static final Vector3 AXIS_X = new Vector3(1,0,0);
47 |
48 | /**
49 | * A final field that contains the director vector of the Y-axis of the
50 | * canonical base.
51 | */
52 | public static final Vector3 AXIS_Y = new Vector3(0,1,0);
53 |
54 | /**
55 | * A final field that contains the director vector of the Z-axis of the
56 | * canonical base.
57 | */
58 | public static final Vector3 AXIS_Z = new Vector3(0,0,1);
59 |
60 | /**
61 | * The X component of the vector.
62 | */
63 | public final float x;
64 |
65 | /**
66 | * The Y component of the vector.
67 | */
68 | public final float y;
69 |
70 | /**
71 | * The Z component of the vector.
72 | */
73 | public final float z;
74 |
75 | /**
76 | * Creates a new instance of a Vector3 with the specified components.
77 | * @param x The x component of the new vector.
78 | * @param y The y component of the new vector.
79 | * @param z The z component of the new vector.
80 | */
81 | public Vector3(float x, float y, float z) {
82 | this.x = x;
83 | this.y = y;
84 | this.z = z;
85 | }
86 |
87 | /**
88 | * Creates a new instance of a Vector3 with the specified components.
89 | * @param x The x component of the new vector.
90 | * @param y The y component of the new vector.
91 | * @param z The z component of the new vector.
92 | */
93 | public Vector3(double x, double y, double z) {
94 | this.x = (float) x;
95 | this.y = (float) y;
96 | this.z = (float) z;
97 | }
98 |
99 | /**
100 | * Creates a new instance of a Vector3 with the specified array of
101 | * components.
102 | * @param comps an array of three elements that contains the components
103 | * of the new vector. The components must in the order of
104 | * x, y, z.
105 | */
106 | public Vector3(float[] comps) {
107 | this.x = comps[0];
108 | this.y = comps[1];
109 | this.z = comps[2];
110 | }
111 |
112 | /**
113 | * Builds a new instance of this class from the components of a vector
114 | * from the Bukkit API.
115 | * @param v the source vector.
116 | * @return A new instance of this class with the same values as the source
117 | * vector.
118 | *
119 | * @see Vector
120 | */
121 | public static Vector3 from(Vector v){
122 | return new Vector3(v.getX(), v.getY(), v.getZ());
123 | }
124 |
125 | /**
126 | * Builds a new instance of this class from the components of a Location
127 | * object from the Bukkit API.
128 | * @param l the source Location object.
129 | * @return A new instance of this class with the same values as the source
130 | * Object.
131 | *
132 | * @see Vector
133 | */
134 | public static Vector3 from(Location l){
135 | return new Vector3(l.getX(), l.getY(), l.getZ());
136 | }
137 |
138 | /**
139 | * Builds a new instance of this class from the components of a Block
140 | * object from the Bukkit API.
141 | * @param l the source Block object.
142 | * @return A new instance of this class with the same values as the source
143 | * Object.
144 | *
145 | * @see Vector
146 | */
147 | public static Vector3 from(Block l){
148 | return new Vector3(l.getX(), l.getY(), l.getZ());
149 | }
150 |
151 | /**
152 | * Determines if the current object is inside the cuboid defined by the
153 | * input vectors.
154 | * @param min The lower point of the cuboid, inclusive.
155 | * @param max The upper point of the cuboid, inclusive.
156 | * @return {@code true} if the current vector is contained in the cuboid.
157 | * {@code false} otherwise.
158 | */
159 | public boolean isBetween(Vector3 min, Vector3 max){
160 | return min.x >= x && min.y >= y && min.z >= z &&
161 | x <= max.x && y <= max.y && z <= max.z;
162 | }
163 |
164 | /**
165 | * Create a new vector from the current one, but setting a new value for the
166 | * x component.
167 | * @param x The x component of the returned vector.
168 | * @return A new vector created from the current one, but with the specified
169 | * x component.
170 | */
171 | public Vector3 withX(float x){
172 | return new Vector3(x, y, z);
173 | }
174 |
175 | /**
176 | * Create a new vector from the current one, but setting a new value for the
177 | * y component.
178 | * @param y The y component of the returned vector.
179 | * @return A new vector created from the current one, but with the specified
180 | * y component.
181 | */
182 | public Vector3 withY(float y){
183 | return new Vector3(x, y, z);
184 | }
185 |
186 | /**
187 | * Create a new vector from the current one, but setting a new value for the
188 | * z component.
189 | * @param z The z component of the returned vector.
190 | * @return A new vector created from the current one, but with the specified
191 | * z component.
192 | */
193 | public Vector3 withZ(float z){
194 | return new Vector3(x, y, z);
195 | }
196 |
197 | /**
198 | * Sum up the components of the current vector with the specified ones.
199 | * @param x the x component.
200 | * @param y the y component.
201 | * @param z the z component.
202 | * @return A new vector that is the sum of the components of the current one
203 | * with the specified components.
204 | */
205 | public Vector3 add(float x, float y, float z){
206 | return new Vector3(this.x + x, this.y + y, this.z + z);
207 | }
208 |
209 | /**
210 | * Sum up the current vector with another.
211 | * @param other The vector to sum with.
212 | * @return A new vector that is the sum of the current vector with the
213 | * input vector.
214 | */
215 | public Vector3 add(Vector3 other){
216 | return add(other.x, other.y, other.z);
217 | }
218 |
219 | /**
220 | * Subtract up the components of the current vector with the specified ones.
221 | * @param x the x component.
222 | * @param y the y component.
223 | * @param z the z component.
224 | * @return A new vector that is the subtraction of the components of the
225 | * current on with the specified components.
226 | */
227 | public Vector3 sub(float x, float y, float z){
228 | return new Vector3(this.x - x, this.y - y, this.z - z);
229 | }
230 |
231 | /**
232 | * Subtract up the current vector with another.
233 | * @param other The vector to sum with.
234 | * @return A new vector that is the result of the subtraction of the current
235 | * vector with the input vector.
236 | */
237 | public Vector3 sub(Vector3 other){
238 | return sub(other.x, other.y, other.z);
239 | }
240 |
241 | /**
242 | * Multiplies all the components of the current vector by a factor f.
243 | * @param f the multiplication factor.
244 | * @return A new vector that is the result of the multiplication of all
245 | * the components of the current vector by a factor f.
246 | */
247 | public Vector3 mul(float f){
248 | return new Vector3(this.x * f, this.y * f, this.z * f);
249 | }
250 |
251 | /**
252 | * Multiplies each component of the current vector by its corresponding
253 | * component of the input vector.
254 | * @param f the multiplication vector.
255 | * @return A new vector that is the result of the multiplication of each
256 | * component of the current vector by its corresponding component of the
257 | * input vector.
258 | */
259 | public Vector3 mul(Vector3 f){
260 | return new Vector3(this.x * f.x, this.y * f.y, this.z * f.z);
261 | }
262 |
263 | /**
264 | * Multiplies each component of the current vector by its corresponding
265 | * specified component.
266 | * @param fx The x component.
267 | * @param fy The y component.
268 | * @param fz The z component.
269 | * @return A new vector that is the result of the multiplication of each
270 | * component of the current vector by its corresponding specified component.
271 | */
272 | public Vector3 mul(float fx, float fy, float fz){
273 | return new Vector3(this.x * fx, this.y * fy, this.z * fz);
274 | }
275 |
276 | /**
277 | * Divides all the components of the current vector by a divisor f.
278 | * @param f the divisor.
279 | * @return A new vector that is the result of the divison of all
280 | * the components of the current vector by a divisor f.
281 | */
282 | public Vector3 div(float f){
283 | return new Vector3(this.x / f, this.y / f, this.z / f);
284 | }
285 |
286 | /**
287 | * Divides each component of the current vector by its corresponding
288 | * component of the input vector.
289 | * @param f the divisor vector.
290 | * @return A new vector that is the result of the divsion of each
291 | * component of the current vector by its corresponding component of the
292 | * input vector.
293 | */
294 | public Vector3 div(Vector3 f){
295 | return new Vector3(this.x / f.x, this.y / f.y, this.z / f.z);
296 | }
297 |
298 | /**
299 | * Divides each component of the current vector by its corresponding
300 | * specified component.
301 | * @param fx The x component.
302 | * @param fy The y component.
303 | * @param fz The z component.
304 | * @return A new vector that is the result of the division of each
305 | * component of the current vector by its corresponding specified component.
306 | */
307 | public Vector3 div(float fx, float fy, float fz){
308 | return new Vector3(this.x / fx, this.y / fy, this.z / fz);
309 | }
310 |
311 | /**
312 | * Returns the dot product between the current vector and other.
313 | * @param other the other vector.
314 | * @return The dot product between the current vector and other in a float
315 | * number.
316 | */
317 | public float dot(Vector3 other){
318 | return this.x * other.x + this.y * other.y + this.z * other.z;
319 | }
320 |
321 | /**
322 | * Returns the vector that represents the cross product between this vector
323 | * and another, where this vector is the first operand, and the specified
324 | * vector, the second one.
325 | * @param o the other vector.
326 | * @return the cross product between this vector
327 | * and another.
328 | */
329 | public Vector3 cross(Vector3 o){
330 | return new Vector3(
331 | this.y * o.z - o.y * this.z,
332 | this.z * o.x - o.z * this.x,
333 | this.x * o.y - o.x * this.y
334 | );
335 | }
336 |
337 | /**
338 | * Returns the mixed product, or the triple scalar product between this
339 | * vector and two more vectors, where the current vector is the first
340 | * operand of the dot product of the operation.
341 | * @param cross1 the first operand of the cross product.
342 | * @param cross2 the second operand of the cross product.
343 | * @return the mixed product of the current vector and another two ones.
344 | */
345 | public float mixed(Vector3 cross1, Vector3 cross2){
346 | return cross1.cross(cross2).dot(this);
347 | }
348 |
349 | /**
350 | * Returns the squared norm, or squared length of the current vector.
351 | * @return The squared norm of the current product.
352 | */
353 | public double normSquared(){
354 | return x * x + y * y + z * z;
355 | }
356 |
357 | /**
358 | * Returns the norm, or length, of the current vector.
359 | * @return the norm of the current vector.
360 | */
361 | public double norm(){
362 | return (float) TrailUtil.sqrt(normSquared());
363 | }
364 |
365 | /**
366 | * Returns the squared distance between the current vector and the
367 | * specified one.
368 | * @param o The other vector.
369 | * @return The squared distance between the current vector and the
370 | * specified one.
371 | */
372 | public float distanceSquared(Vector3 o){
373 | float x = this.x - o.x;
374 | float y = this.y - o.y;
375 | float z = this.z - o.z;
376 | return x * x + y * y + z * z;
377 | }
378 |
379 | /**
380 | * Returns the Euclidean distance between the current vector and the
381 | * specified one.
382 | * @param o the other vector.
383 | * @return the euclidean distance between the current vector and the
384 | * specified one.
385 | */
386 | public double distance(Vector3 o){
387 | return TrailUtil.sqrt(distanceSquared(o));
388 | }
389 |
390 | /**
391 | * Returns the cosine of the angle between the current vector and another.
392 | * @param o the other vector.
393 | * @return the cosine of the angle between the current vector and another.
394 | */
395 | public float cosine(Vector3 o){
396 | return this.dot(o) / ((float) this.norm() * (float) o.norm());
397 | }
398 |
399 | /**
400 | * Returns the angle between the current vector and another.
401 | * @param o the other vector.
402 | * @return the angle in radians between the current vector and another. The
403 | * angle will be between 0 and π, inclusive.
404 | */
405 | public double angle(Vector3 o){
406 | return Math.acos(cosine(o));
407 | }
408 |
409 |
410 | /**
411 | * Returns the full angle between the current vector and another.
412 | * @param o the other vector.
413 | * @param normal the vector perpendicular to the plane respect the angle
414 | * will be metered.
415 | * @return The angle between 0 and 2π between this vector and the specified
416 | * vector, respect to the plane whose perpendicular vector is the specified
417 | * normal vector.
418 | */
419 | public double fullAngle(Vector3 o, Vector3 normal){
420 | float dot = this.dot(o);
421 | float det = normal.mixed(this, o);
422 | double angle = Math.atan2(det, dot);
423 | return angle > 0 ? angle : angle + 2 * Math.PI;
424 | }
425 |
426 | /**
427 | * Returns this vector normalized, this means, with norm 1
428 | * @return the current vector normalized.
429 | */
430 | public Vector3 normalize(){
431 | float mod = (float) this.norm();
432 | if (mod == 0) return Vector3.ORIGIN;
433 | return new Vector3(x / mod, y / mod, z / mod);
434 | }
435 |
436 | /**
437 | * Scales the current vector to get one with the same direction as the
438 | * current one, but with the specified norm.
439 | * @param norm the new norm of the vector.
440 | * @return a vector with the same direction as the current one, but
441 | * with the specified norm.
442 | */
443 | public Vector3 withNorm(float norm) {
444 | return normalize().mul(norm);
445 | }
446 |
447 | /**
448 | * Scales the current vector to get one with the same direction as the
449 | * current one, but with the specified size factor.
450 | * @param factor the size factor of the norm.
451 | * @return a vector with the same direction as the current one, but
452 | * with its norm multiplied by the specified factor.
453 | */
454 | public Vector3 scale(float factor) {
455 | return withNorm((float) this.norm() * factor);
456 | }
457 |
458 | /**
459 | * Rotates the current vector around de X axis of the canonical base.
460 | * @param angle the rotation angle, in radians.
461 | * @return the current vector rotated around the X axis, {@code angle}
462 | * radians.
463 | */
464 | public Vector3 rotateX(float angle){
465 | return rotate(AXIS_X, angle);
466 | }
467 |
468 | /**
469 | * Rotates the current vector around de Y axis of the canonical base.
470 | * @param angle the rotation angle, in radians.
471 | * @return the current vector rotated around the Y axis, {@code angle}
472 | * radians.
473 | */
474 | public Vector3 rotateY(float angle){
475 | return rotate(AXIS_Y, angle);
476 | }
477 |
478 | /**
479 | * Rotates the current vector around de Z axis of the canonical base.
480 | * @param angle the rotation angle, in radians.
481 | * @return the current vector rotated around the Z axis, {@code angle}
482 | * radians.
483 | */
484 | public Vector3 rotateZ(float angle){
485 | return rotate(AXIS_Z, angle);
486 | }
487 |
488 | /**
489 | * Rotates the current vector around an arbitrary axis, defined by the
490 | * parameter k.
491 | * @param k the rotation axis.
492 | * @param angle the rotation angle, in radians.
493 | * @return the current vector rotated around the {@code k} axis,
494 | * {@code angle} radians.
495 | */
496 | public Vector3 rotate(Vector3 k, float angle){
497 | if (k.normSquared() != 1){
498 | k = k.normalize();
499 | }
500 |
501 | float cos = (float) Math.cos(angle);
502 | float sin = (float) Math.sin(angle);
503 |
504 | Vector3 cross = k.cross(this);
505 | float kfactor = k.dot(this) * (1 - cos);
506 |
507 | return new Vector3(
508 | this.x * cos + cross.x * sin + k.x * kfactor,
509 | this.y * cos + cross.y * sin + k.y * kfactor,
510 | this.z * cos + cross.z * sin + k.z * kfactor
511 | );
512 | }
513 |
514 | /**
515 | * Projects the current vector onto the specified one.
516 | * @param onto The vector.
517 | * @return The current vector, projected onto the specified vector.
518 | */
519 | public Vector3 project(Vector3 onto) {
520 | return onto.mul(this.dot(onto) / (float) onto.normSquared());
521 | }
522 |
523 | /**
524 | * Projects the current vector onto the surface whose ortogonal base is
525 | * defined by the specified vectors.
526 | * @param d1 The first vector of the surface base, ortogonal to {@code d2}
527 | * @param d2 The second vector of the surface base, ortogonal to {@code d1}
528 | * @return The current vector projected onto the surface defined by the
529 | * specified base.
530 | */
531 | public Vector3 projectOntoSurface(Vector3 d1, Vector3 d2) {
532 | return this.project(d1).add(this.project(d2));
533 | }
534 |
535 | /**
536 | * Returns the current vector, with the x component set to 0
537 | * @return the current vector with the x component set to 0
538 | */
539 | public Vector3 stripX(){
540 | return withX(0);
541 | }
542 |
543 | /**
544 | * Returns the current vector, with the y component set to 0
545 | * @return the current vector with the y component set to 0
546 | */
547 | public Vector3 stripY(){
548 | return withY(0);
549 | }
550 |
551 | /**
552 | * Returns the current vector, with the z component set to 0
553 | * @return the current vector with the z component set to 0
554 | */
555 | public Vector3 stripZ(){
556 | return withZ(0);
557 | }
558 |
559 | /**
560 | * Returns the current vector as a vector of the Bukkit API.
561 | * @return the current vector as a vector of Bukkit API.
562 | */
563 | public Vector toVector(){
564 | return new Vector(x, y, z);
565 | }
566 |
567 | /**
568 | * Returns the current vector as an array of components.
569 | * @return a float array of 3 items that contains the value of each
570 | * component x, y, z, respectively.
571 | */
572 | public float[] toFloats(){
573 | return new float[]{x, y, z};
574 | }
575 |
576 | /**
577 | * Returns the current vector as a Location object, with the world set to
578 | * {@code null}, and pitch and yaw set to 0.
579 | * @return a Location object with the data of the current vector.
580 | */
581 | public Location toLocation(){
582 | return toLocation(null);
583 | }
584 |
585 | /**
586 | * Returns the current vector as a Location object, with the world set to
587 | * the specified one, and pitch and yaw set to 0.
588 | *
589 | * @param w The target world.
590 | * @return a Location object with the data of the current vector.
591 | */
592 | public Location toLocation(World w){
593 | return toLocation(w, 0.0f, 0.0f);
594 | }
595 |
596 | /**
597 | * Returns the current vector as a Location object, with the world, pitch
598 | * and yaw specified.
599 | *
600 | * @param w The target world.
601 | * @param pitch The pitch.
602 | * @param yaw The yaw.
603 | * @return a Location object with the data of the current vector.
604 | */
605 | public Location toLocation(World w, float pitch, float yaw){
606 | return new Location(w, x, y, z, yaw, pitch);
607 | }
608 | }
609 |
--------------------------------------------------------------------------------
/library/src/main/java/com/devcexx/libtrails/suppliers/BitmapSupplier.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of libtrails.
3 | * libtrails is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * libtrails is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with libtrails. If not, see .
15 | */
16 |
17 | package com.devcexx.libtrails.suppliers;
18 |
19 | import com.devcexx.libtrails.Particle;
20 | import com.devcexx.libtrails.ParticleSupplier;
21 | import com.devcexx.libtrails.SuppliedParticle;
22 | import com.devcexx.libtrails.Vector3;
23 | import org.bukkit.Effect;
24 |
25 | import java.awt.image.BufferedImage;
26 | import java.util.Arrays;
27 | import java.util.function.IntBinaryOperator;
28 | import java.util.stream.Stream;
29 |
30 | /**
31 | * Class that allows to represent compose an image made of coloreables
32 | * particles in Minecraft, from a bitmap.
33 | */
34 | public class BitmapSupplier implements ParticleSupplier {
35 | public final SuppliedParticle[] particles;
36 | public final int allocatedPixels;
37 | public final int appearingInterval;
38 |
39 | /**
40 | * Creates a new bitmap supplier.
41 | * @param particleType the type of the particle that will be spawned. MUST
42 | * BE a coloreable particle, (COLORED_DUST or SPELL).
43 | * @param appearingInterval the time, in Minecraft ticks, that must elapse
44 | * between each image.
45 | * @param visibilityRadius the visible radius of the particles. Anyone
46 | * in the same world as the particles, and nearer
47 | * than this value will be able to see them.
48 | * @param image an instance of {@link BufferedImage} that contains the
49 | * imagen that will be rendered.
50 | * @param w the width, in Minecraft Blocks of the rendered image.
51 | * @param h the height, in Minecraft Blocks of the rendered image.
52 | * @param horizontalResolution the number of horizontal particles per
53 | * block that will compose the rendered image.
54 | * @param verticalResolution the number of vertical particles per
55 | * block that will compose the rendered image.
56 | */
57 | public BitmapSupplier(Effect particleType, int appearingInterval,
58 | int visibilityRadius, BufferedImage image, float w,
59 | float h, float horizontalResolution,
60 | float verticalResolution) {
61 |
62 | this(particleType, appearingInterval, visibilityRadius, image::getRGB,
63 | image.getWidth(), image.getHeight(), w, h, horizontalResolution,
64 | verticalResolution);
65 | }
66 |
67 | /**
68 | * Creates a new bitmap supplier.
69 | * @param particleType the type of the particle that will be spawned. MUST
70 | * BE a coloreable particle, (COLORED_DUST or SPELL).
71 | * @param appearingInterval the time, in Minecraft ticks, that must elapse
72 | * between each image.
73 | * @param visibilityRadius the visible radius of the particles. Anyone
74 | * in the same world as the particles, and nearer
75 | * than this value will be able to see them.
76 | * @param provider a {@link IntBinaryOperator} that is the origin of the
77 | * data of the bitmap. It must take two parameters: x and y,
78 | * respectively. The result of this function must the color
79 | * of the pixel located at (x, y), in ARGB format, with
80 | * 8 bits per channel.
81 | * [AAAAAAAA|RRRRRRRR|GGGGGGGG|BBBBBBBB]
82 | * @param originw the width of the source image.
83 | * @param originh the height of the source image.
84 | * @param w the width, in Minecraft Blocks of the rendered image.
85 | * @param h the height, in Minecraft Blocks of the rendered image.
86 | * @param horizontalResolution the number of horizontal particles per
87 | * block that will compose the rendered image.
88 | * @param verticalResolution the number of vertical particles per
89 | * block that will compose the rendered image.
90 | */
91 | public BitmapSupplier(Effect particleType, int appearingInterval,
92 | int visibilityRadius, IntBinaryOperator provider,
93 | int originw, int originh, float w, float h,
94 | float horizontalResolution,
95 | float verticalResolution) {
96 |
97 | if (particleType != Effect.COLOURED_DUST
98 | && particleType != Effect.SPELL)
99 | throw new IllegalArgumentException("The specified effect " +
100 | "cannot have RGB colors");
101 |
102 | this.appearingInterval = appearingInterval;
103 |
104 | int finalw = (int) (w * horizontalResolution);
105 | int finalh = (int) (h * verticalResolution);
106 |
107 | particles = new SuppliedParticle[finalh * finalw];
108 |
109 | double xdist = 1.0 / horizontalResolution;
110 | double zdist = 1.0 / verticalResolution;
111 |
112 | float midw = w / 2;
113 | float midh = h / 2;
114 |
115 | double xScale = originw/(double)finalw;
116 | double yScale = originh/(double)finalh;
117 | int px, py;
118 |
119 | int index = 0;
120 |
121 | //Nearest neighbor image scaling
122 | for (int i = 0; i < finalh; i++) {
123 | for (int j = 0; j < finalw; j++) {
124 |
125 | px = (int) Math.floor(j*xScale);
126 | py = (int) Math.floor(i*yScale);
127 | int argb = provider.applyAsInt(px, py);
128 |
129 | if (((argb >> 24) & 0xFF) >= 127) {
130 |
131 | //Math.max(0.001f...): if speed is 0.0f, Minecraft draws it
132 | //with a red color. This code avoids it.
133 | float r = Math.max(0.001f, ((argb >> 16) & 0xFF) / 256.0f);
134 | float g = Math.max(0.001f, ((argb >> 8) & 0xFF) / 256.0f);
135 | float b = Math.max(0.001f, (argb & 0xFF) / 256.0f);
136 |
137 | particles[index++] = new SuppliedParticle(
138 | Particle.builder()
139 | .effect(particleType)
140 | .radius(visibilityRadius)
141 | .count(0)
142 | .offsetX(r)
143 | .offsetY(g)
144 | .offsetZ(b)
145 | .speed(1.0f).build(),
146 | new Vector3(j * xdist - midw, 0, midh - (i * zdist))
147 | );
148 | }
149 | }
150 | }
151 | this.allocatedPixels = index;
152 | }
153 |
154 | @Override
155 | public Stream supply(int tick) {
156 | if (tick % appearingInterval == 0) {
157 | return Arrays.stream(particles, 0, allocatedPixels);
158 | } else {
159 | return Stream.of();
160 | }
161 | }
162 |
163 | }
164 |
--------------------------------------------------------------------------------
/library/src/main/java/com/devcexx/libtrails/suppliers/CircumferenceSupplier.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of libtrails.
3 | * libtrails is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * libtrails is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with libtrails. If not, see .
15 | */
16 |
17 | package com.devcexx.libtrails.suppliers;
18 |
19 | import com.devcexx.libtrails.Particle;
20 | import com.devcexx.libtrails.ParticleSupplier;
21 | import com.devcexx.libtrails.SuppliedParticle;
22 | import com.devcexx.libtrails.Vector3;
23 |
24 | import java.util.Arrays;
25 | import java.util.stream.Stream;
26 |
27 | /**
28 | * Class that provides a circumference trail.
29 | */
30 | public class CircumferenceSupplier implements ParticleSupplier {
31 | public final SuppliedParticle[] particles;
32 | public final int appearingInterval;
33 |
34 | /**
35 | * Creates a new trail with the specified parameters.
36 | * @param particle the particle of the circumference.
37 | * @param radius the radius of the circumference.
38 | * @param delta the variation of the angle between each point, in radians.
39 | * @param offset the start angle.
40 | * @param appearingInterval the time, in Minecraft ticks, that must elapse
41 | * between each drawing.
42 | */
43 | public CircumferenceSupplier(Particle particle,
44 | float radius, float delta, float offset,
45 | int appearingInterval) {
46 | this.appearingInterval = appearingInterval;
47 |
48 | int n = (int) Math.round(2 * Math.PI / delta);
49 | particles = new SuppliedParticle[n];
50 | for (int i = 0; i < n; i++) {
51 | float angle = offset + delta * i;
52 | particles[i] = new SuppliedParticle(particle, new Vector3(
53 | Math.cos(angle),
54 | 0,
55 | Math.sin(angle)
56 | ).mul(radius));
57 | }
58 | }
59 |
60 | @Override
61 | public Stream supply(int tick) {
62 | if (tick % appearingInterval == 0) {
63 | return Arrays.stream(particles);
64 | } else {
65 | return Stream.of();
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/library/src/main/java/com/devcexx/libtrails/suppliers/EpitrochoidSupplier.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of libtrails.
3 | * libtrails is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * libtrails is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with libtrails. If not, see .
15 | */
16 |
17 | package com.devcexx.libtrails.suppliers;
18 |
19 | import com.devcexx.libtrails.*;
20 |
21 | /**
22 | * Class that provides an Epitrochoid trail.
23 | */
24 | public class EpitrochoidSupplier extends SpirographSupplier {
25 |
26 | /**
27 | * Builds a new epitrochoid trail.
28 | * @param particle The particle that will be spawned.
29 | * @param delta The variation of the angle per drawn point.
30 | * @param directorRadius The radius of the fixed circumference.
31 | * @param rollingRadius The radius of the rolling circumference.
32 | * @param hdist The distance between the center of the rolling center to
33 | * the point that will be used to draw the curve.
34 | * @param appearingInterval the time, in Minecraft ticks, that must elapse
35 | * between each drawing.
36 | */
37 | public EpitrochoidSupplier(Particle particle, float delta,
38 | float directorRadius, float rollingRadius,
39 | float hdist, int appearingInterval) {
40 | super(particle, delta, directorRadius, rollingRadius, hdist,
41 | appearingInterval);
42 | }
43 |
44 | @Override
45 | protected Vector3 fetchVector(float R, float r, float h, float theta) {
46 | return new Vector3(
47 | (R + r) * Math.cos(theta) - h * Math.cos(theta * (R + r) / r),
48 | 0,
49 | (R + r) * Math.sin(theta) - h * Math.sin(theta * (R + r) / r)
50 | );
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/library/src/main/java/com/devcexx/libtrails/suppliers/HelixSupplier.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of libtrails.
3 | * libtrails is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * libtrails is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with libtrails. If not, see .
15 | */
16 |
17 | package com.devcexx.libtrails.suppliers;
18 |
19 | import com.devcexx.libtrails.Particle;
20 | import com.devcexx.libtrails.SuppliedParticle;
21 |
22 | import java.util.stream.Stream;
23 |
24 | /**
25 | * Class that provides an helix trail.
26 | */
27 | public class HelixSupplier extends CircumferenceSupplier {
28 |
29 | /**
30 | * Creates a new trail with the specified parameters.
31 | * @param particle the particle of the helix.
32 | * @param radius the radius of the circumference that defines the helix.
33 | * @param delta the variation of the angle between each point, in radians.
34 | * @param offset the start angle.
35 | */
36 | public HelixSupplier(Particle particle, float radius, float delta, float offset) {
37 | super(particle, radius, delta, offset, 0);
38 | }
39 |
40 | @Override
41 | public Stream supply(int tick) {
42 | return Stream.of(particles[tick % particles.length]);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/library/src/main/java/com/devcexx/libtrails/suppliers/HypotrochoidSupplier.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of libtrails.
3 | * libtrails is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * libtrails is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with libtrails. If not, see .
15 | */
16 |
17 | package com.devcexx.libtrails.suppliers;
18 |
19 | import com.devcexx.libtrails.Particle;
20 | import com.devcexx.libtrails.Vector3;
21 |
22 | /**
23 | * Class that provides an Hypotrochoid trail.
24 | */
25 | public class HypotrochoidSupplier extends SpirographSupplier {
26 |
27 | /**
28 | * Builds a new epitrochoid trail.
29 | * @param particle The particle that will be spawned.
30 | * @param delta The variation of the angle per drawn point.
31 | * @param directorRadius The radius of the fixed circumference.
32 | * @param rollingRadius The radius of the rolling circumference.
33 | * @param hdist The distance between the center of the rolling center to
34 | * the point that will be used to draw the curve.
35 | * @param appearingInterval the time, in Minecraft ticks, that must elapse
36 | * between each drawing.
37 | */
38 | public HypotrochoidSupplier(Particle particle, float delta,
39 | float directorRadius, float rollingRadius,
40 | float hdist, int appearingInterval) {
41 | super(particle, delta, directorRadius, rollingRadius, hdist,
42 | appearingInterval);
43 | }
44 |
45 | @Override
46 | protected Vector3 fetchVector(float R, float r, float h, float theta) {
47 | return new Vector3(
48 | (R - r) * Math.cos(theta) + h * Math.cos(theta * (R - r) / r),
49 | 0,
50 | (R - r) * Math.sin(theta) - h * Math.sin(theta * (R - r) / r)
51 | );
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/library/src/main/java/com/devcexx/libtrails/suppliers/LinearSupplier.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of libtrails.
3 | * libtrails is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * libtrails is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with libtrails. If not, see .
15 | */
16 |
17 | package com.devcexx.libtrails.suppliers;
18 |
19 | import com.devcexx.libtrails.Particle;
20 | import com.devcexx.libtrails.ParticleSupplier;
21 | import com.devcexx.libtrails.SuppliedParticle;
22 | import com.devcexx.libtrails.Vector3;
23 |
24 | import java.util.stream.Stream;
25 |
26 | /**
27 | * Represents a basic linear trail.
28 | */
29 | public class LinearSupplier implements ParticleSupplier {
30 |
31 | private SuppliedParticle particle;
32 |
33 | /**
34 | * Builds a new linear trail.
35 | * @param particle The particle of the trail.
36 | */
37 | public LinearSupplier(Particle particle) {
38 | this(particle, Vector3.ORIGIN);
39 | }
40 |
41 | /**
42 | * Builds a new linear trail.
43 | * @param particle The particle of the trail.
44 | * @param offset The offset of the particle from the origin.
45 | */
46 | public LinearSupplier(Particle particle, Vector3 offset) {
47 | this.particle = new SuppliedParticle(particle, offset);
48 | }
49 |
50 | @Override
51 | public Stream supply(int tick) {
52 | return Stream.of(this.particle);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/library/src/main/java/com/devcexx/libtrails/suppliers/PolySupplier.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of libtrails.
3 | * libtrails is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * libtrails is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with libtrails. If not, see .
15 | */
16 |
17 | package com.devcexx.libtrails.suppliers;
18 |
19 | import com.devcexx.libtrails.Particle;
20 | import com.devcexx.libtrails.ParticleSupplier;
21 | import com.devcexx.libtrails.SuppliedParticle;
22 | import com.devcexx.libtrails.TrailUtil;
23 | import com.devcexx.libtrails.Vector3;
24 |
25 | import java.util.Arrays;
26 | import java.util.stream.Stream;
27 |
28 | /**
29 | * Class that allows to render a trail composed by shapes with equidistants
30 | * vertex placed in a circumference. This points are connected with lines,
31 | * and a specified jump between vertex. This allow to create regular common
32 | * 2D polygons (when jump = 0) or complex handy-like star drawings.
33 | */
34 | public class PolySupplier implements ParticleSupplier {
35 | public final SuppliedParticle[] particles;
36 | public final int appearingInterval;
37 |
38 | /**
39 | * Creates a new instance of the supplier.
40 | * @param particle Creates a new trail with the specified parameters.
41 | * @param appearingInterval The time, in Minecraft ticks, that must elapse
42 | * between each drawing.
43 | * @param vertex The number of vertex of the shape.
44 | * @param jumps The number of vertex that will be skipped each time when
45 | * connecting them with lines.
46 | * @param radius The radius of the circumference that circumscribes the
47 | * shape.
48 | * @param step The distance, in Minecraft blocks, between each point
49 | * of the lines of the shape.
50 | * @param angleOffset The angle of the first vertex.
51 | */
52 | public PolySupplier(Particle particle, int appearingInterval, int vertex,
53 | int jumps, float radius, float step,
54 | float angleOffset) {
55 | this.appearingInterval = appearingInterval;
56 |
57 | float fullAngle = (2 * (float) Math.PI / vertex) * (jumps + 1);
58 | double linesLength = new Vector3(radius, 0, 0)
59 | .sub(
60 | radius * (float) Math.cos(fullAngle),
61 | radius * (float) Math.sin(fullAngle), 0
62 | ).norm();
63 |
64 | int n = (int) Math.round(linesLength / step);
65 |
66 | // k * (j + 1) ≡ 0 (mod n) <=> k ≡ 0 (mod n / mcd(n, j + 1)), where
67 | // k ≡ line count; n ≡ vertex count; j ≡ jumps between vertex.
68 | int lineCount = vertex / TrailUtil.gcd(vertex, jumps + 1);
69 |
70 | particles = new SuppliedParticle[lineCount * n];
71 |
72 | for (int i = 0; i < lineCount; i++) {
73 | float originAngle = angleOffset + i * fullAngle;
74 | float targetAngle = originAngle + fullAngle;
75 |
76 | Vector3 ptFrom = new Vector3(radius * Math.cos(originAngle), 0,
77 | radius * Math.sin(originAngle));
78 | Vector3 ptTo = new Vector3(radius * Math.cos(targetAngle), 0,
79 | radius * Math.sin(targetAngle));
80 |
81 | TrailUtil.fillWithLine(particles, particle, i * n,
82 | ptFrom, ptTo.sub(ptFrom).normalize(), step, n);
83 | }
84 | }
85 |
86 | @Override
87 | public Stream supply(int tick) {
88 | if (tick % appearingInterval == 0) {
89 | return Arrays.stream(particles);
90 | } else {
91 | return Stream.of();
92 | }
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/library/src/main/java/com/devcexx/libtrails/suppliers/ScatteringSupplier.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of libtrails.
3 | * libtrails is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * libtrails is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with libtrails. If not, see .
15 | */
16 |
17 | package com.devcexx.libtrails.suppliers;
18 |
19 | import com.devcexx.libtrails.Particle;
20 | import com.devcexx.libtrails.ParticleSupplier;
21 | import com.devcexx.libtrails.SuppliedParticle;
22 | import com.devcexx.libtrails.Vector3;
23 |
24 | import java.util.Arrays;
25 | import java.util.Random;
26 | import java.util.stream.Stream;
27 |
28 | /**
29 | * Class that provides a trail that spreads particles randomly into
30 | * a defined space.
31 | */
32 | public class ScatteringSupplier implements ParticleSupplier{
33 |
34 | private final Random random = new Random();
35 | public final Particle[] particles;
36 | public final Vector3 spreadSpace;
37 | public final Vector3 spreadSpaceOffset;
38 | public final int minParticles;
39 | public final int maxParticles;
40 | public final int appearingInteval;
41 |
42 | /**
43 | * Creates a new trail with the specified parameters.
44 | * @param particles the possible kind of particles that could be spawned
45 | * in the trail.
46 | * @param spreadSpace the space where the particles can be spawned.
47 | * @param spreadSpaceOffset the offset of the spread space from the center.
48 | * @param minParticles the minimum count of particles that must be spawned
49 | * in each step.
50 | * @param maxParticles the maximum number of particles that could be spawned
51 | * in each step.
52 | * @param appearingInterval the time between each spawning, in Minecraft
53 | * ticks.
54 | */
55 | public ScatteringSupplier(Particle[] particles, Vector3 spreadSpace,
56 | Vector3 spreadSpaceOffset, int minParticles,
57 | int maxParticles, int appearingInterval) {
58 | this.particles = particles;
59 |
60 | //Half the size of the space, to consider the positive and negative
61 | //coordinates.
62 | this.spreadSpace = spreadSpace.mul(0.5f);
63 | this.spreadSpaceOffset = spreadSpaceOffset;
64 | this.minParticles = minParticles;
65 | this.maxParticles = maxParticles;
66 | this.appearingInteval = appearingInterval;
67 | }
68 |
69 |
70 | @Override
71 | public Stream supply(int tick) {
72 | if (tick % appearingInteval == 0) {
73 | int n = random.nextInt(maxParticles - minParticles) + minParticles + 1;
74 | SuppliedParticle[] res = new SuppliedParticle[n];
75 |
76 | for (int i = 0; i < n; i++) {
77 | res[i] = new SuppliedParticle(
78 | particles[random.nextInt(particles.length)],
79 | spreadSpaceOffset.add(
80 | spreadSpace.mul(
81 | (float) random.nextGaussian(),
82 | (float) random.nextGaussian(),
83 | (float) random.nextGaussian()
84 | )));
85 | }
86 | return Arrays.stream(res);
87 | } else {
88 | return Stream.of();
89 | }
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/library/src/main/java/com/devcexx/libtrails/suppliers/SinusoidalSupplier.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of libtrails.
3 | * libtrails is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * libtrails is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with libtrails. If not, see .
15 | */
16 |
17 | package com.devcexx.libtrails.suppliers;
18 |
19 | import com.devcexx.libtrails.Particle;
20 | import com.devcexx.libtrails.ParticleSupplier;
21 | import com.devcexx.libtrails.SuppliedParticle;
22 | import com.devcexx.libtrails.Vector3;
23 |
24 | import java.util.stream.Stream;
25 |
26 | /**
27 | * Class that provides a circumference trail.
28 | */
29 | public class SinusoidalSupplier implements ParticleSupplier {
30 | private final SuppliedParticle[] particles;
31 |
32 | /**
33 | * Creates a new trail with the specified parameters.
34 | * @param particle the particle of the sinusoidal wave.
35 | * @param radius the radius of the sinusoidal wave (amplitude).
36 | * @param delta the angle between each point of the wave, in radians.
37 | * @param offset the start angle, in radians.
38 | * @param rotation the rotation angle of the wave around the Y axis,
39 | * in radians.
40 | */
41 | public SinusoidalSupplier(Particle particle, float radius, float delta,
42 | float offset, float rotation) {
43 | int n = (int) (2 * Math.PI / delta);
44 | particles = new SuppliedParticle[n];
45 | for (int i = 0; i < n; i++) {
46 | float angle = offset + delta * i;
47 | particles[i] = new SuppliedParticle(particle, new Vector3(
48 | 0,
49 | 0,
50 | Math.sin(angle)
51 | ).mul(radius).rotateY(rotation));
52 | }
53 | }
54 |
55 | @Override
56 | public Stream supply(int tick) {
57 | return Stream.of(particles[tick % particles.length]);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/library/src/main/java/com/devcexx/libtrails/suppliers/SpirographSupplier.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of libtrails.
3 | * libtrails is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * libtrails is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with libtrails. If not, see .
15 | */
16 |
17 | package com.devcexx.libtrails.suppliers;
18 |
19 | import com.devcexx.libtrails.*;
20 |
21 | import java.util.Arrays;
22 | import java.util.stream.Stream;
23 |
24 | /**
25 | * Represents a trail defined by a curve that can be generated by a
26 | * Spirograph.
27 | */
28 | public abstract class SpirographSupplier implements ParticleSupplier {
29 | public final SuppliedParticle[] particles;
30 | public final int appearingInterval;
31 |
32 | /**
33 | * Builds a new epitrochoid trail.
34 | * @param particle The particle that will be spawned.
35 | * @param delta The variation of the angle per drawn point.
36 | * @param directorRadius The radius of the fixed circumference.
37 | * @param rollingRadius The radius of the rolling circumference.
38 | * @param hdist The distance between the center of the rolling center to
39 | * the point that will be used to draw the curve.
40 | * @param appearingInterval the time, in Minecraft ticks, that must elapse
41 | * between each drawing.
42 | */
43 | public SpirographSupplier(Particle particle, float delta,
44 | float directorRadius, float rollingRadius,
45 | float hdist, int appearingInterval) {
46 | this.appearingInterval = appearingInterval;
47 |
48 | //two decimal precision
49 | directorRadius = (float) (Math.floor(directorRadius * 100.0f) / 100.0f);
50 | rollingRadius = (float) (Math.floor(rollingRadius * 100.0f) / 100.0f);
51 |
52 | int period = (int) Math.ceil(directorRadius /
53 | (TrailUtil.gcd((int) (directorRadius * 100),
54 | (int) (rollingRadius * 100)) / 100.0f));
55 |
56 | double finalAngle = period * (rollingRadius / directorRadius) * 2 * Math.PI;
57 | int steps = (int) Math.round(finalAngle / delta);
58 | particles = new SuppliedParticle[steps];
59 |
60 | for (int i = 0; i < steps; i++) {
61 | particles[i] = new SuppliedParticle(particle,
62 | fetchVector(directorRadius, rollingRadius, hdist, i * delta));
63 | }
64 | }
65 |
66 | @Override
67 | public Stream supply(int tick) {
68 | if (tick % appearingInterval == 0)
69 | return Arrays.stream(particles);
70 | else
71 | return Stream.of();
72 | }
73 |
74 | protected abstract Vector3 fetchVector(float R, float r, float h, float theta);
75 | }
76 |
--------------------------------------------------------------------------------
/library/src/main/java/com/devcexx/libtrails/suppliers/StarSupplier.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of libtrails.
3 | * libtrails is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * libtrails is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with libtrails. If not, see .
15 | */
16 |
17 | package com.devcexx.libtrails.suppliers;
18 |
19 | import com.devcexx.libtrails.Particle;
20 | import com.devcexx.libtrails.ParticleSupplier;
21 | import com.devcexx.libtrails.SuppliedParticle;
22 | import com.devcexx.libtrails.TrailUtil;
23 | import com.devcexx.libtrails.Vector3;
24 |
25 | import java.util.Arrays;
26 | import java.util.stream.Stream;
27 |
28 | /**
29 | * Class that provides a star trail.
30 | */
31 | public class StarSupplier implements ParticleSupplier {
32 | public final SuppliedParticle[] particles;
33 | public final int appearingInterval;
34 |
35 | /**
36 | * Creates a new instance of this class.
37 | * @param particle The particle used to render the star.
38 | * @param appearingInterval the time, in Minecraft ticks, that must elapse
39 | * between each star.
40 | * @param vertex The number of vertex of the star.
41 | * @param step The distance, in Minecraft blocks, between each point
42 | * of the lines of the star.
43 | * @param highRadius The radius of the outer circumference that delimites
44 | * the star.
45 | * @param lowRadius The radius of the inner circumference that delimites
46 | * the minimum size of the star.
47 | * @param angleStartOffset The offset of the initial angle.
48 | */
49 | public StarSupplier(Particle particle, int appearingInterval,
50 | int vertex, float step, float highRadius,
51 | float lowRadius, float angleStartOffset) {
52 | this.appearingInterval = appearingInterval;
53 |
54 | float fullAngle = (float) (2 * Math.PI / vertex);
55 | float midAngle = fullAngle / 2.0f;
56 | double linesLength = new Vector3(highRadius, 0, 0)
57 | .sub(
58 | lowRadius * (float) Math.cos(midAngle),
59 | lowRadius * (float) Math.sin(midAngle), 0
60 | ).norm();
61 |
62 | int pointsPerLine = (int) Math.round(linesLength / step);
63 | particles = new SuppliedParticle[2 * pointsPerLine * vertex];
64 | int index = 0;
65 |
66 | for (int i = 0; i < vertex; i++) {
67 | double highAngle = angleStartOffset + fullAngle * i;
68 | double lowAngle = highAngle + midAngle;
69 | double nextHighAngle = highAngle + fullAngle;
70 |
71 | Vector3 ptFrom = new Vector3(highRadius * Math.cos(highAngle), 0,
72 | highRadius * Math.sin(highAngle));
73 | Vector3 ptTo = new Vector3(lowRadius * Math.cos(lowAngle), 0,
74 | lowRadius * Math.sin(lowAngle));
75 |
76 | TrailUtil.fillWithLine(particles, particle, index,
77 | ptFrom, ptTo.sub(ptFrom).normalize(), step, pointsPerLine);
78 | index += pointsPerLine;
79 |
80 | ptFrom = ptTo;
81 | ptTo = new Vector3(highRadius * Math.cos(nextHighAngle), 0,
82 | highRadius * Math.sin(nextHighAngle));
83 |
84 | TrailUtil.fillWithLine(particles, particle, index,
85 | ptFrom, ptTo.sub(ptFrom).normalize(), step, pointsPerLine);
86 | index += pointsPerLine;
87 | }
88 | }
89 |
90 | @Override
91 | public Stream supply(int tick) {
92 | if (tick % appearingInterval == 0) {
93 | return Arrays.stream(particles);
94 | } else {
95 | return Stream.of();
96 | }
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.devcexx
8 | libtrails-parent
9 | 1.0-SNAPSHOT
10 | pom
11 |
12 |
13 |
14 | build-library
15 |
16 | library
17 |
18 |
19 |
20 |
21 | build-examples
22 |
23 | examples
24 |
25 |
26 |
27 |
28 |
29 |
30 | spigot-repo
31 | https://hub.spigotmc.org/nexus/content/repositories/snapshots/
32 |
33 |
34 |
35 |
36 |
37 | org.spigotmc
38 | spigot-api
39 | 1.11.2-R0.1-SNAPSHOT
40 | provided
41 |
42 |
43 | org.projectlombok
44 | lombok
45 | 1.18.20
46 | provided
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 | org.apache.maven.plugins
55 | maven-compiler-plugin
56 | 3.5.1
57 |
58 |
59 | 1.8
60 | 1.8
61 |
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------