├── .gitattributes
├── .github
└── FUNDING.yml
├── .gitignore
├── Jenkinsfile
├── LICENSE.txt
├── README.md
├── build.gradle
├── doc
├── benchmarks.png
├── logo.png
└── patreon.png
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── src
└── main
├── java
└── me
│ └── jellysquid
│ └── mods
│ └── phosphor
│ ├── api
│ ├── IChunkLighting.java
│ ├── IChunkLightingData.java
│ ├── ILightingEngine.java
│ └── ILightingEngineProvider.java
│ ├── core
│ └── PhosphorFMLPlugin.java
│ ├── mixins
│ ├── lighting
│ │ ├── client
│ │ │ ├── MixinMinecraft.java
│ │ │ └── MixinRenderGlobal.java
│ │ └── common
│ │ │ ├── MixinAnvilChunkLoader.java
│ │ │ ├── MixinChunk$Sponge.java
│ │ │ ├── MixinChunk$Vanilla.java
│ │ │ ├── MixinChunk.java
│ │ │ ├── MixinChunkProviderServer.java
│ │ │ ├── MixinExtendedBlockStorage.java
│ │ │ ├── MixinSPacketChunkData.java
│ │ │ └── MixinWorld.java
│ └── plugins
│ │ └── LightingEnginePlugin.java
│ └── mod
│ ├── PhosphorConfig.java
│ ├── PhosphorConstants.java
│ ├── PhosphorMod.java
│ ├── collections
│ └── PooledLongQueue.java
│ └── world
│ ├── WorldChunkSlice.java
│ └── lighting
│ ├── LightingEngine.java
│ ├── LightingEngineHelpers.java
│ └── LightingHooks.java
└── resources
├── assets
└── phosphor-lighting
│ └── icon.png
├── mcmod.info
├── mixins.phosphor.json
└── phosphor_at.cfg
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.png binary
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: jellysquid3
4 | patreon: jellysquid
5 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # eclipse
2 | bin
3 | *.launch
4 | .settings
5 | .metadata
6 | .classpath
7 | .project
8 |
9 | # idea
10 | out
11 | *.ipr
12 | *.iws
13 | *.iml
14 | .idea
15 | classes
16 |
17 | # gradle
18 | build
19 | .gradle
20 |
21 | # other
22 | eclipse
23 | run
24 | libs
25 | logs
26 |
--------------------------------------------------------------------------------
/Jenkinsfile:
--------------------------------------------------------------------------------
1 | pipeline {
2 | agent {
3 | docker {
4 | image 'gradle:4.10.3-jdk8-alpine'
5 | args '-v gradle-cache:/home/gradle/.gradle'
6 | }
7 | }
8 |
9 | stages {
10 | stage('Clean') {
11 | steps {
12 | dir('build/libs') {
13 | deleteDir()
14 | }
15 | }
16 | }
17 |
18 | stage('Build') {
19 | steps {
20 | sh 'gradle build'
21 | }
22 | }
23 |
24 | stage('Publish') {
25 | when {
26 | branch 'master'
27 | }
28 |
29 | environment {
30 | MAVEN_SECRETS_FILE = credentials('maven-secrets')
31 |
32 | JARSIGN_KEYSTORE_FILE = credentials('angeline-jarsign-keystore')
33 | JARSIGN_SECRETS_FILE = credentials('angeline-jarsign-secrets')
34 | }
35 |
36 | steps {
37 | sh 'gradle publish'
38 | }
39 | }
40 | }
41 |
42 | post {
43 | success {
44 | archiveArtifacts artifacts: 'build/libs/*.jar', fingerprint: true
45 | }
46 | }
47 | }
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
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 |
635 | Copyright (C)
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 | Copyright (C)
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 | .
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Hesperus: A fork of Phosphor
2 |
3 |
4 | ### How does it work?
5 |
6 | Hesperus makes a variety of modifications to the vanilla lighting engine in order to improve performance. The key highlights can be found below.
7 |
8 | - The code responsible for propagating light changes has been completely rewritten to be far more efficient than the vanilla implementation.
9 | - Light updates are postponed until the regions they modify are queried. This allows lighting updates to be batched together more effectively and reduces the number of duplicated scheduled light updates for a block.
10 | This significantly reduces the CPU time spent propagating skylight updates.
11 | - Skylight propagation on the vertical axis has been fixed to take into account incoming skylight from neighboring chunks, fixing a variety of lighting issues created during world generation and large operations
12 | involving large block volumes (such as /fill.)
13 | - Chunk lighting is only performed once all adjacent chunks are loaded so sky and block light propogation is spread into neighbors correctly, preventing various visual errors.
14 | - Through fixing various errors in vanilla's lighting engine implementation, many checks performed when relighting blocks are now skipped, reducing the overhead of lighting updates.
15 |
16 | This list is still incomplete and a technical writeup of how Hesperus achieves such significant gains is in the works.
17 |
18 | ### License
19 |
20 | Hesperus is licensed under GNU GPLv3, a free and open-source license. For more information, please see the [license file](https://github.com/jellysquid3/Hesperus-forge/blob/master/LICENSE.txt).
21 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | jcenter()
4 |
5 | maven { url = 'https://repo.spongepowered.org/repository/maven-public' }
6 | maven { url = 'https://maven.minecraftforge.net' }
7 | }
8 |
9 | dependencies {
10 | classpath 'net.minecraftforge.gradle:ForgeGradle:6.0.+'
11 | classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT'
12 | }
13 | }
14 |
15 | apply plugin: 'net.minecraftforge.gradle'
16 | apply plugin: 'org.spongepowered.mixin'
17 |
18 | group = "me.jellysquid.mods"
19 |
20 | if (System.getenv("BUILD_NUMBER") != null) {
21 | version = "${minecraft_version}-${mod_version}+build${System.getenv("BUILD_NUMBER")}"
22 | } else {
23 | version = "${minecraft_version}-${mod_version}-SNAPSHOT"
24 | }
25 |
26 | compileJava {
27 | sourceCompatibility = 1.8
28 | targetCompatibility = 1.8
29 | }
30 |
31 | minecraft {
32 | mappings channel: 'stable', version: '39-1.12'
33 |
34 | runs {
35 | client {
36 |
37 | jvmArg "-Dfml.coreMods.load=me.jellysquid.mods.phosphor.core.PhosphorFMLPlugin"
38 | jvmArg "-Dmixin.hotSwap=true"
39 | jvmArg "-Dmixin.checks.interfaces=true"
40 |
41 | workingDirectory project.file('run')
42 |
43 | // Recommended logging data for a userdev environment
44 | property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
45 |
46 | // Recommended logging level for the console
47 | property 'forge.logging.console.level', 'debug'
48 | }
49 |
50 | server {
51 |
52 | jvmArg "-Dfml.coreMods.load=me.jellysquid.mods.phosphor.core.PhosphorFMLPlugin"
53 | jvmArg "-Dmixin.hotSwap=true"
54 | jvmArg "-Dmixin.checks.interfaces=true"
55 |
56 | // Recommended logging data for a userdev environment
57 | property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
58 |
59 | // Recommended logging level for the console
60 | property 'forge.logging.console.level', 'debug'
61 | }
62 | }
63 | }
64 |
65 | repositories {
66 | maven { url = 'https://repo.spongepowered.org/maven' }
67 | maven {
68 | url "https://www.cursemaven.com"
69 | }
70 | maven {
71 | url 'https://maven.cleanroommc.com'
72 | }
73 | flatDir {
74 | dirs "libs"
75 | }
76 | mavenLocal()
77 | }
78 |
79 | configurations {
80 | shade
81 | compile.extendsFrom shade
82 | }
83 |
84 | dependencies {
85 | minecraft "net.minecraftforge:forge:1.12.2-14.23.5.2860"
86 | annotationProcessor("org.spongepowered:mixin:0.8.5:processor")
87 | compileOnly("org.spongepowered:spongeapi:7.4.0")
88 | compileOnly("org.spongepowered:mixin:0.8.5") {
89 | exclude module: "asm-commons"
90 | exclude module: "asm-tree"
91 | exclude module: "launchwrapper"
92 | exclude module: "guava"
93 | exclude module: "log4j-core"
94 | exclude module: "gson"
95 | exclude module: "commons-io"
96 | }
97 | compileOnly fg.deobf("curse.maven:dynamiclights-227874:2563244")
98 | compileOnly fg.deobf("curse.maven:sel-341845:3024600")
99 | compileOnly 'zone.rong:mixinbooter:8.4'
100 | runtimeOnly 'zone.rong:mixinbooter:8.4'
101 | //runtimeOnly "re:witchery:0.5.2.4"
102 | //runtimeOnly "tt:tp:1.0.1.1"
103 | }
104 |
105 | def coreModManifest = {
106 | attributes "FMLAT": "phosphor_at.cfg"
107 | attributes "Maven-Artifact": "${group}:${name}:${version}"
108 | attributes "FMLCorePlugin": "me.jellysquid.mods.phosphor.core.PhosphorFMLPlugin"
109 | attributes "FMLCorePluginContainsFMLMod": true
110 | attributes "ForceLoadAsMod": true
111 | }
112 |
113 | jar {
114 | //classifier = 'universal'
115 |
116 | manifest coreModManifest
117 |
118 | from sourceSets.main.output
119 |
120 | rename '(.+_at.cfg)', 'META-INF/$1'
121 | }
122 |
123 |
124 |
125 | processResources {
126 | duplicatesStrategy(DuplicatesStrategy.INCLUDE)
127 | inputs.property "version", project.version
128 | inputs.property "mcversion", "1.12.2"
129 |
130 | from(sourceSets.main.resources.srcDirs) {
131 | include 'mcmod.info'
132 |
133 | expand 'version': project.version, 'mcversion': "1.12.2"
134 | }
135 |
136 | from(sourceSets.main.resources.srcDirs) {
137 | exclude 'mcmod.info'
138 | }
139 | }
140 |
141 | mixin {
142 | add sourceSets.main, "mixins.phosphor.refmap.json"
143 | disableAnnotationProcessorCheck()
144 | }
145 |
146 |
147 |
--------------------------------------------------------------------------------
/doc/benchmarks.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kappa-maintainer/Hesperus/1f415f936fe0887e589ac4c05715eda9b0618519/doc/benchmarks.png
--------------------------------------------------------------------------------
/doc/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kappa-maintainer/Hesperus/1f415f936fe0887e589ac4c05715eda9b0618519/doc/logo.png
--------------------------------------------------------------------------------
/doc/patreon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kappa-maintainer/Hesperus/1f415f936fe0887e589ac4c05715eda9b0618519/doc/patreon.png
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Sets default memory used for gradle commands. Can be overridden by user or command line properties.
2 | # This is required to provide enough memory for the Minecraft decompilation process.
3 | org.gradle.jvmargs=-Xmx2G -DsocksProxyHost=127.0.0.1 -DsocksProxyPort=1081
4 | mod_version=0.2.9.3
5 | mod_name=phosphor
6 | minecraft_version=1.12.2
7 | forge_version=14.23.5.2847
8 | forge_mappings=stable_39
9 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kappa-maintainer/Hesperus/1f415f936fe0887e589ac4c05715eda9b0618519/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'phosphor'
2 |
--------------------------------------------------------------------------------
/src/main/java/me/jellysquid/mods/phosphor/api/IChunkLighting.java:
--------------------------------------------------------------------------------
1 | package me.jellysquid.mods.phosphor.api;
2 |
3 | import net.minecraft.util.math.BlockPos;
4 | import net.minecraft.world.EnumSkyBlock;
5 |
6 | public interface IChunkLighting {
7 | int getCachedLightFor(EnumSkyBlock enumSkyBlock, BlockPos pos);
8 | }
9 |
--------------------------------------------------------------------------------
/src/main/java/me/jellysquid/mods/phosphor/api/IChunkLightingData.java:
--------------------------------------------------------------------------------
1 | package me.jellysquid.mods.phosphor.api;
2 |
3 | public interface IChunkLightingData {
4 | short[] getNeighborLightChecks();
5 |
6 | void setNeighborLightChecks(short[] data);
7 |
8 | boolean isLightInitialized();
9 |
10 | void setLightInitialized(boolean val);
11 |
12 | void setSkylightUpdatedPublic();
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/me/jellysquid/mods/phosphor/api/ILightingEngine.java:
--------------------------------------------------------------------------------
1 | package me.jellysquid.mods.phosphor.api;
2 |
3 | import net.minecraft.util.math.BlockPos;
4 | import net.minecraft.world.EnumSkyBlock;
5 |
6 | public interface ILightingEngine {
7 | void scheduleLightUpdate(EnumSkyBlock lightType, BlockPos pos);
8 |
9 | void processLightUpdates();
10 |
11 | void processLightUpdatesForType(EnumSkyBlock lightType);
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/me/jellysquid/mods/phosphor/api/ILightingEngineProvider.java:
--------------------------------------------------------------------------------
1 | package me.jellysquid.mods.phosphor.api;
2 |
3 | public interface ILightingEngineProvider {
4 | ILightingEngine getLightingEngine();
5 | }
6 |
--------------------------------------------------------------------------------
/src/main/java/me/jellysquid/mods/phosphor/core/PhosphorFMLPlugin.java:
--------------------------------------------------------------------------------
1 | package me.jellysquid.mods.phosphor.core;
2 |
3 | import com.google.common.collect.ImmutableList;
4 | import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
5 |
6 | import javax.annotation.Nullable;
7 | import java.util.List;
8 | import java.util.Map;
9 | import zone.rong.mixinbooter.IEarlyMixinLoader;
10 |
11 | @IFMLLoadingPlugin.MCVersion("1.12.2")
12 | public class PhosphorFMLPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader {
13 | @Override
14 | public String[] getASMTransformerClass() {
15 | return new String[0];
16 | }
17 |
18 | @Override
19 | public String getModContainerClass() {
20 | return null;
21 | }
22 |
23 | @Nullable
24 | @Override
25 | public String getSetupClass() {
26 | return null;
27 | }
28 |
29 | @Override
30 | public void injectData(Map data) {
31 |
32 | }
33 |
34 | @Override
35 | public String getAccessTransformerClass() {
36 | return null;
37 | }
38 |
39 | @Override
40 | public List getMixinConfigs() {
41 | return ImmutableList.of("mixins.phosphor.json");
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/me/jellysquid/mods/phosphor/mixins/lighting/client/MixinMinecraft.java:
--------------------------------------------------------------------------------
1 | package me.jellysquid.mods.phosphor.mixins.lighting.client;
2 |
3 | import me.jellysquid.mods.phosphor.api.ILightingEngineProvider;
4 | import net.minecraft.client.Minecraft;
5 | import net.minecraft.client.multiplayer.WorldClient;
6 | import net.minecraft.profiler.Profiler;
7 | import org.spongepowered.asm.mixin.Final;
8 | import org.spongepowered.asm.mixin.Mixin;
9 | import org.spongepowered.asm.mixin.Shadow;
10 | import org.spongepowered.asm.mixin.injection.At;
11 | import org.spongepowered.asm.mixin.injection.Inject;
12 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
13 |
14 | @Mixin(Minecraft.class)
15 | public abstract class MixinMinecraft {
16 | @Shadow
17 | @Final
18 | public Profiler profiler;
19 |
20 | @Shadow
21 | public WorldClient world;
22 |
23 | /**
24 | * @author Angeline
25 | * Forces the client to process light updates before rendering the world. We inject before the call to the profiler
26 | * which designates the start of world rendering. This is a rather injection site.
27 | */
28 | @Inject(method = "runTick", at = @At(value = "CONSTANT", args = "stringValue=levelRenderer", shift = At.Shift.BY, by = -3))
29 | private void onRunTick(CallbackInfo ci) {
30 | this.profiler.endStartSection("lighting");
31 |
32 | ((ILightingEngineProvider) this.world).getLightingEngine().processLightUpdates();
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/me/jellysquid/mods/phosphor/mixins/lighting/client/MixinRenderGlobal.java:
--------------------------------------------------------------------------------
1 | package me.jellysquid.mods.phosphor.mixins.lighting.client;
2 |
3 | import me.jellysquid.mods.phosphor.mod.PhosphorMod;
4 | import net.minecraft.client.renderer.RenderGlobal;
5 | import net.minecraft.util.math.BlockPos;
6 | import org.spongepowered.asm.mixin.Mixin;
7 | import org.spongepowered.asm.mixin.injection.At;
8 | import org.spongepowered.asm.mixin.injection.Inject;
9 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
10 |
11 | @Mixin({RenderGlobal.class})
12 | public class MixinRenderGlobal {
13 |
14 | @Inject(at = @At("HEAD"), method = "notifyLightSet")
15 | public void notifyLightSet(BlockPos pos, CallbackInfo ci) {
16 | //PhosphorMod.LOGGER.debug(pos);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/me/jellysquid/mods/phosphor/mixins/lighting/common/MixinAnvilChunkLoader.java:
--------------------------------------------------------------------------------
1 | package me.jellysquid.mods.phosphor.mixins.lighting.common;
2 |
3 | import me.jellysquid.mods.phosphor.api.IChunkLightingData;
4 | import me.jellysquid.mods.phosphor.api.ILightingEngineProvider;
5 | import me.jellysquid.mods.phosphor.mod.world.lighting.LightingHooks;
6 | import net.minecraft.nbt.NBTTagCompound;
7 | import net.minecraft.world.World;
8 | import net.minecraft.world.chunk.Chunk;
9 | import net.minecraft.world.chunk.storage.AnvilChunkLoader;
10 | import org.spongepowered.asm.mixin.Mixin;
11 | import org.spongepowered.asm.mixin.injection.At;
12 | import org.spongepowered.asm.mixin.injection.Inject;
13 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
14 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
15 |
16 | @Mixin(AnvilChunkLoader.class)
17 | public abstract class MixinAnvilChunkLoader {
18 | /**
19 | * Injects into the head of saveChunk() to forcefully process all pending light updates. Fail-safe.
20 | *
21 | * @author Angeline
22 | */
23 | @Inject(method = "saveChunk", at = @At("HEAD"))
24 | private void onConstructed(World world, Chunk chunkIn, CallbackInfo callbackInfo) {
25 | ((ILightingEngineProvider) world).getLightingEngine().processLightUpdates();
26 | }
27 |
28 | /**
29 | * Injects the deserialization logic for chunk data on load so we can extract whether or not we've populated light yet.
30 | *
31 | * @author Angeline
32 | */
33 | @Inject(method = "readChunkFromNBT", at = @At("RETURN"))
34 | private void onReadChunkFromNBT(World world, NBTTagCompound compound, CallbackInfoReturnable cir) {
35 | Chunk chunk = cir.getReturnValue();
36 |
37 | LightingHooks.readNeighborLightChecksFromNBT(chunk, compound);
38 |
39 | ((IChunkLightingData) chunk).setLightInitialized(compound.getBoolean("LightPopulated"));
40 |
41 | }
42 |
43 | /**
44 | * Injects the serialization logic for chunk data on save so we can store whether or not we've populated light yet.
45 | * @author Angeline
46 | */
47 | @Inject(method = "writeChunkToNBT", at = @At("RETURN"))
48 | private void onWriteChunkToNBT(Chunk chunk, World world, NBTTagCompound compound, CallbackInfo ci) {
49 | LightingHooks.writeNeighborLightChecksToNBT(chunk, compound);
50 |
51 | compound.setBoolean("LightPopulated", ((IChunkLightingData) chunk).isLightInitialized());
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/me/jellysquid/mods/phosphor/mixins/lighting/common/MixinChunk$Sponge.java:
--------------------------------------------------------------------------------
1 | package me.jellysquid.mods.phosphor.mixins.lighting.common;
2 |
3 |
4 | import me.jellysquid.mods.phosphor.mod.world.lighting.LightingHooks;
5 | import net.minecraft.world.World;
6 | import net.minecraft.world.chunk.Chunk;
7 | import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
8 | import org.spongepowered.asm.mixin.Dynamic;
9 | import org.spongepowered.asm.mixin.Final;
10 | import org.spongepowered.asm.mixin.Mixin;
11 | import org.spongepowered.asm.mixin.Shadow;
12 | import org.spongepowered.asm.mixin.injection.At;
13 | import org.spongepowered.asm.mixin.injection.ModifyVariable;
14 | import org.spongepowered.asm.mixin.injection.Redirect;
15 | import org.spongepowered.asm.mixin.injection.Slice;
16 |
17 | @Mixin(value = Chunk.class, priority = 10055)
18 | public abstract class MixinChunk$Sponge {
19 | private static final String SET_BLOCK_STATE_SPONGE = "bridge$setBlockState" +
20 | "(Lnet/minecraft/util/math/BlockPos;" +
21 | "Lnet/minecraft/block/state/IBlockState;" +
22 | "Lnet/minecraft/block/state/IBlockState;" +
23 | "Lorg/spongepowered/api/world/BlockChangeFlag;)" +
24 | "Lnet/minecraft/block/state/IBlockState;";
25 |
26 | @Shadow
27 | @Final
28 | private World world;
29 |
30 | /**
31 | * Redirects the construction of the ExtendedBlockStorage in setBlockState(BlockPos, IBlockState). We need to initialize
32 | * the skylight data for the constructed section as soon as possible.
33 | *
34 | * @author Angeline
35 | */
36 | @Dynamic
37 | @Redirect(
38 | method = SET_BLOCK_STATE_SPONGE,
39 | at = @At(
40 | value = "NEW",
41 | args = "class=net/minecraft/world/chunk/storage/ExtendedBlockStorage"
42 | ),
43 | expect = 0
44 | )
45 | private ExtendedBlockStorage setBlockStateCreateSectionSponge(int y, boolean storeSkylight) {
46 | return this.initSection(y, storeSkylight);
47 | }
48 |
49 | private ExtendedBlockStorage initSection(int y, boolean storeSkylight) {
50 | ExtendedBlockStorage storage = new ExtendedBlockStorage(y, storeSkylight);
51 |
52 | LightingHooks.initSkylightForSection(this.world, (Chunk) (Object) this, storage);
53 |
54 | return storage;
55 | }
56 |
57 | /**
58 | * Modifies variable requiresNewLightCalculations before it is used in the conditional that decides whether or not
59 | * generateSkylightMap() should be called. We want it to always take the else branch.
60 | *
61 | * @author Angeline
62 | */
63 | @Dynamic
64 | @ModifyVariable(
65 | method = SET_BLOCK_STATE_SPONGE,
66 | at = @At(
67 | value = "LOAD",
68 | ordinal = 0
69 | ),
70 | index = 14,
71 | name = "requiresNewLightCalculations",
72 | slice = @Slice(
73 | from = @At(
74 | value = "INVOKE",
75 | target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;get(III)Lnet/minecraft/block/state/IBlockState;"
76 | ),
77 | to = @At(
78 | value = "INVOKE",
79 | target = "Lnet/minecraft/world/chunk/Chunk;generateSkylightMap()V"
80 | )
81 | ),
82 | allow = 1
83 | )
84 | private boolean setBlockStateInjectGenerateSkylightMapVanilla(boolean generateSkylight) {
85 | return false;
86 | }
87 |
88 | /**
89 | * Modifies variable newBlockLightOpacity to match postNewBlockLightOpacity before the conditional which decides to
90 | * propagate skylight as to prevent it from ever evaluating as true.
91 | *
92 | * @author Angeline
93 | */
94 | @Dynamic
95 | @ModifyVariable(
96 | method = SET_BLOCK_STATE_SPONGE,
97 | at = @At(
98 | value = "LOAD",
99 | ordinal = 1
100 | ),
101 | index = 13,
102 | name = "newBlockLightOpacity",
103 | slice = @Slice(
104 | from = @At(
105 | value = "INVOKE",
106 | target = "Lnet/minecraft/world/chunk/Chunk;relightBlock(III)V",
107 | ordinal = 1
108 | ),
109 | to = @At(
110 | value = "INVOKE",
111 | target = "Lnet/minecraft/world/chunk/Chunk;propagateSkylightOcclusion(II)V"
112 | )
113 |
114 | ),
115 | allow = 1
116 | )
117 | private int setBlockStatePreventPropagateSkylightOcclusion1(int generateSkylight) {
118 | return WIZARD_MAGIC;
119 | }
120 |
121 | /**
122 | * Modifies variable postNewBlockLightOpacity to match newBlockLightOpacity before the conditional which decides to
123 | * propagate skylight as to prevent it from ever evaluating as true.
124 | *
125 | * @author Angeline
126 | */
127 | @Dynamic
128 | @ModifyVariable(
129 | method = SET_BLOCK_STATE_SPONGE,
130 | at = @At(
131 | value = "LOAD",
132 | ordinal = 0
133 | ),
134 | index = 24,
135 | name = "postNewBlockLightOpacity",
136 | slice = @Slice(
137 | from = @At(
138 | value = "INVOKE",
139 | target = "Lnet/minecraft/world/chunk/Chunk;relightBlock(III)V",
140 | ordinal = 1
141 | ),
142 | to = @At(
143 | value = "INVOKE",
144 | target = "Lnet/minecraft/world/chunk/Chunk;propagateSkylightOcclusion(II)V"
145 | )
146 |
147 | ),
148 | allow = 1
149 | )
150 | private int setBlockStatePreventPropagateSkylightOcclusion2(int generateSkylight) {
151 | return WIZARD_MAGIC;
152 | }
153 |
154 | private static final int WIZARD_MAGIC = 694698818;
155 |
156 | }
157 |
--------------------------------------------------------------------------------
/src/main/java/me/jellysquid/mods/phosphor/mixins/lighting/common/MixinChunk$Vanilla.java:
--------------------------------------------------------------------------------
1 | package me.jellysquid.mods.phosphor.mixins.lighting.common;
2 |
3 | import me.jellysquid.mods.phosphor.mod.world.lighting.LightingHooks;
4 | import net.minecraft.block.state.IBlockState;
5 | import net.minecraft.util.math.BlockPos;
6 | import net.minecraft.world.EnumSkyBlock;
7 | import net.minecraft.world.World;
8 | import net.minecraft.world.chunk.Chunk;
9 | import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
10 | import org.spongepowered.asm.mixin.Final;
11 | import org.spongepowered.asm.mixin.Mixin;
12 | import org.spongepowered.asm.mixin.Shadow;
13 | import org.spongepowered.asm.mixin.injection.*;
14 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
15 |
16 | @Mixin(value = Chunk.class)
17 | public abstract class MixinChunk$Vanilla {
18 | private static final String SET_BLOCK_STATE_VANILLA = "setBlockState" +
19 | "(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/state/IBlockState;)" +
20 | "Lnet/minecraft/block/state/IBlockState;";
21 |
22 | @Shadow
23 | @Final
24 | private World world;
25 |
26 | /**
27 | * Redirects the construction of the ExtendedBlockStorage in setBlockState(BlockPos, IBlockState). We need to initialize
28 | * the skylight data for the constructed section as soon as possible.
29 | *
30 | * @author Angeline
31 | */
32 | @Redirect(
33 | method = SET_BLOCK_STATE_VANILLA,
34 | at = @At(
35 | value = "NEW",
36 | args = "class=net/minecraft/world/chunk/storage/ExtendedBlockStorage"
37 | ),
38 | expect = 0
39 | )
40 | private ExtendedBlockStorage setBlockStateCreateSectionVanilla(int y, boolean storeSkylight) {
41 | return this.initSection(y, storeSkylight);
42 | }
43 |
44 | private ExtendedBlockStorage initSection(int y, boolean storeSkylight) {
45 | ExtendedBlockStorage storage = new ExtendedBlockStorage(y, storeSkylight);
46 |
47 | LightingHooks.initSkylightForSection(this.world, (Chunk) (Object) this, storage);
48 |
49 | return storage;
50 | }
51 |
52 | /**
53 | * Modifies the flag variable of setBlockState(BlockPos, IBlockState) to always be false after it is set.
54 | *
55 | * @author Angeline
56 | */
57 | @ModifyVariable(
58 | method = SET_BLOCK_STATE_VANILLA,
59 | at = @At(
60 | value = "STORE",
61 | ordinal = 1
62 | ),
63 | index = 13,
64 | name = "flag",
65 | allow = 1
66 | )
67 | private boolean setBlockStateInjectGenerateSkylightMapVanilla(boolean generateSkylight) {
68 | return false;
69 | }
70 |
71 | /**
72 | * Prevent propagateSkylightOcclusion from being called.
73 | * @author embeddedt
74 | */
75 | @Redirect(method = SET_BLOCK_STATE_VANILLA, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/Chunk;propagateSkylightOcclusion(II)V"))
76 | private void doPropagateSkylight(Chunk chunk, int i1, int i2) {
77 | /* No-op, we don't want skylight propagated */
78 | }
79 |
80 | /**
81 | * Prevent getLightFor from being called.
82 | * @author embeddedt
83 | */
84 | @Redirect(method = SET_BLOCK_STATE_VANILLA, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/Chunk;getLightFor(Lnet/minecraft/world/EnumSkyBlock;Lnet/minecraft/util/math/BlockPos;)I"))
85 | private int getFakeLightFor(Chunk chunk, EnumSkyBlock skyBlock, BlockPos blockPos) {
86 | return 0;
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/main/java/me/jellysquid/mods/phosphor/mixins/lighting/common/MixinChunk.java:
--------------------------------------------------------------------------------
1 | package me.jellysquid.mods.phosphor.mixins.lighting.common;
2 |
3 | import me.jellysquid.mods.phosphor.api.IChunkLighting;
4 | import me.jellysquid.mods.phosphor.api.IChunkLightingData;
5 | import me.jellysquid.mods.phosphor.api.ILightingEngine;
6 | import me.jellysquid.mods.phosphor.api.ILightingEngineProvider;
7 | import me.jellysquid.mods.phosphor.mod.world.WorldChunkSlice;
8 | import me.jellysquid.mods.phosphor.mod.world.lighting.LightingHooks;
9 | import net.minecraft.block.state.IBlockState;
10 | import net.minecraft.tileentity.TileEntity;
11 | import net.minecraft.util.EnumFacing;
12 | import net.minecraft.util.math.BlockPos;
13 | import net.minecraft.world.EnumSkyBlock;
14 | import net.minecraft.world.World;
15 | import net.minecraft.world.chunk.Chunk;
16 | import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
17 | import org.spongepowered.asm.mixin.Final;
18 | import org.spongepowered.asm.mixin.Mixin;
19 | import org.spongepowered.asm.mixin.Overwrite;
20 | import org.spongepowered.asm.mixin.Shadow;
21 | import org.spongepowered.asm.mixin.injection.At;
22 | import org.spongepowered.asm.mixin.injection.Inject;
23 | import org.spongepowered.asm.mixin.injection.Redirect;
24 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
25 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
26 |
27 | @SuppressWarnings("UnnecessaryQualifiedMemberReference")
28 | @Mixin(value = Chunk.class)
29 | public abstract class MixinChunk implements IChunkLighting, IChunkLightingData, ILightingEngineProvider {
30 | private static final EnumFacing[] HORIZONTAL = EnumFacing.Plane.HORIZONTAL.facings();
31 |
32 | @Shadow
33 | @Final
34 | private ExtendedBlockStorage[] storageArrays;
35 |
36 | @Shadow
37 | private boolean dirty;
38 |
39 | @Shadow
40 | @Final
41 | private int[] heightMap;
42 |
43 | @Shadow
44 | private int heightMapMinimum;
45 |
46 | @Shadow
47 | @Final
48 | private int[] precipitationHeightMap;
49 |
50 | @Shadow
51 | @Final
52 | private World world;
53 |
54 | @Shadow
55 | private boolean isTerrainPopulated;
56 |
57 | @Final
58 | @Shadow
59 | private boolean[] updateSkylightColumns;
60 |
61 | @Final
62 | @Shadow
63 | public int x;
64 |
65 | @Final
66 | @Shadow
67 | public int z;
68 |
69 | @Shadow
70 | private boolean isGapLightingUpdated;
71 |
72 | @Shadow
73 | public abstract TileEntity getTileEntity(BlockPos pos, Chunk.EnumCreateEntityType type);
74 |
75 | @Shadow
76 | public abstract IBlockState getBlockState(BlockPos pos);
77 |
78 | @Shadow
79 | protected abstract int getBlockLightOpacity(int x, int y, int z);
80 |
81 | @Shadow
82 | public abstract boolean canSeeSky(BlockPos pos);
83 |
84 | /**
85 | * Callback injected into the Chunk ctor to cache a reference to the lighting engine from the world.
86 | *
87 | * @author Angeline
88 | */
89 | @Inject(method = "", at = @At("RETURN"))
90 | private void onConstructed(CallbackInfo ci) {
91 | this.lightingEngine = ((ILightingEngineProvider) this.world).getLightingEngine();
92 | }
93 |
94 | /**
95 | * Callback injected to the head of getLightSubtracted(BlockPos, int) to force deferred light updates to be processed.
96 | *
97 | * @author Angeline
98 | */
99 | @Inject(method = "getLightSubtracted", at = @At("HEAD"))
100 | private void onGetLightSubtracted(BlockPos pos, int amount, CallbackInfoReturnable cir) {
101 | this.lightingEngine.processLightUpdates();
102 | }
103 |
104 | /**
105 | * Callback injected at the end of onLoad() to have previously scheduled light updates scheduled again.
106 | *
107 | * @author Angeline
108 | */
109 | @Inject(method = "onLoad", at = @At("RETURN"))
110 | private void onLoad(CallbackInfo ci) {
111 | LightingHooks.scheduleRelightChecksForChunkBoundaries(this.world, (Chunk) (Object) this);
112 | }
113 |
114 | // === REPLACEMENTS ===
115 |
116 | /**
117 | * Replaces the call in setLightFor(Chunk, EnumSkyBlock, BlockPos) with our hook.
118 | *
119 | * @author Angeline
120 | */
121 | @Redirect(
122 | method = "setLightFor",
123 | at = @At(
124 | value = "INVOKE",
125 | target = "Lnet/minecraft/world/chunk/Chunk;generateSkylightMap()V"
126 | ),
127 | expect = 0
128 | )
129 | private void setLightForRedirectGenerateSkylightMap(Chunk chunk, EnumSkyBlock type, BlockPos pos, int value) {
130 | LightingHooks.initSkylightForSection(this.world, (Chunk) (Object) this, this.storageArrays[pos.getY() >> 4]);
131 | }
132 |
133 | /**
134 | * @reason Overwrites relightBlock with a more efficient implementation.
135 | * @author Angeline
136 | */
137 | @Overwrite
138 | private void relightBlock(int x, int y, int z) {
139 | int i = this.heightMap[z << 4 | x] & 255;
140 | int j = i;
141 |
142 | if (y > i) {
143 | j = y;
144 | }
145 |
146 | while (j > 0 && this.getBlockLightOpacity(x, j - 1, z) == 0) {
147 | --j;
148 | }
149 |
150 | if (j != i) {
151 | this.heightMap[z << 4 | x] = j;
152 |
153 | if (this.world.provider.hasSkyLight()) {
154 | LightingHooks.relightSkylightColumn(this.world, (Chunk) (Object) this, x, z, i, j);
155 | }
156 |
157 | int l1 = this.heightMap[z << 4 | x];
158 |
159 | if (l1 < this.heightMapMinimum) {
160 | this.heightMapMinimum = l1;
161 | }
162 | }
163 | }
164 |
165 | /**
166 | * @reason Hook for calculating light updates only as needed. {@link MixinChunk#getCachedLightFor(EnumSkyBlock, BlockPos)} does not
167 | * call this hook.
168 | *
169 | * @author Angeline
170 | */
171 | @Overwrite
172 | public int getLightFor(EnumSkyBlock type, BlockPos pos) {
173 | this.lightingEngine.processLightUpdatesForType(type);
174 |
175 | return this.getCachedLightFor(type, pos);
176 | }
177 |
178 | /**
179 | * @reason Hooks into checkLight() to check chunk lighting and returns immediately after, voiding the rest of the function.
180 | *
181 | * @author Angeline
182 | */
183 | @Overwrite
184 | public void checkLight() {
185 | this.isTerrainPopulated = true;
186 |
187 | LightingHooks.checkChunkLighting((Chunk) (Object) this, this.world);
188 | }
189 |
190 | /**
191 | * @reason Optimized version of recheckGaps. Avoids chunk fetches as much as possible.
192 | *
193 | * @author Angeline
194 | */
195 | @Overwrite
196 | private void recheckGaps(boolean onlyOne) {
197 | this.world.profiler.startSection("recheckGaps");
198 |
199 | WorldChunkSlice slice = new WorldChunkSlice(this.world, this.x, this.z);
200 |
201 | if (this.world.isAreaLoaded(new BlockPos(this.x * 16 + 8, 0, this.z * 16 + 8), 16)) {
202 | for (int x = 0; x < 16; ++x) {
203 | for (int z = 0; z < 16; ++z) {
204 | if (this.recheckGapsForColumn(slice, x, z)) {
205 | if (onlyOne) {
206 | this.world.profiler.endSection();
207 |
208 | return;
209 | }
210 | }
211 | }
212 | }
213 |
214 | this.isGapLightingUpdated = false;
215 | }
216 |
217 | this.world.profiler.endSection();
218 | }
219 |
220 | private boolean recheckGapsForColumn(WorldChunkSlice slice, int x, int z) {
221 | int i = x + z * 16;
222 |
223 | if (this.updateSkylightColumns[i]) {
224 | this.updateSkylightColumns[i] = false;
225 |
226 | int height = this.getHeightValue(x, z);
227 |
228 | int x1 = this.x * 16 + x;
229 | int z1 = this.z * 16 + z;
230 |
231 | int max = this.recheckGapsGetLowestHeight(slice, x1, z1);
232 |
233 | this.recheckGapsSkylightNeighborHeight(slice, x1, z1, height, max);
234 |
235 | return true;
236 | }
237 |
238 | return false;
239 | }
240 |
241 | private int recheckGapsGetLowestHeight(WorldChunkSlice slice, int x, int z) {
242 | int max = Integer.MAX_VALUE;
243 |
244 | for (EnumFacing facing : HORIZONTAL) {
245 | int j = x + facing.getXOffset();
246 | int k = z + facing.getZOffset();
247 | Chunk chunk = slice.getChunkFromWorldCoords(j, k);
248 | if(chunk != null) {
249 | max = Math.min(max, slice.getChunkFromWorldCoords(j, k).getLowestHeight());
250 | }
251 |
252 | }
253 |
254 | return max;
255 | }
256 |
257 | private void recheckGapsSkylightNeighborHeight(WorldChunkSlice slice, int x, int z, int height, int max) {
258 | this.checkSkylightNeighborHeight(slice, x, z, max);
259 |
260 | for (EnumFacing facing : HORIZONTAL) {
261 | int j = x + facing.getXOffset();
262 | int k = z + facing.getZOffset();
263 |
264 | this.checkSkylightNeighborHeight(slice, j, k, height);
265 | }
266 | }
267 |
268 | private void checkSkylightNeighborHeight(WorldChunkSlice slice, int x, int z, int maxValue) {
269 | if(slice.getChunkFromWorldCoords(x, z) == null) {
270 | return;
271 | }
272 | int i = slice.getChunkFromWorldCoords(x, z).getHeightValue(x & 15, z & 15);
273 |
274 | if (i > maxValue) {
275 | this.updateSkylightNeighborHeight(slice, x, z, maxValue, i + 1);
276 | } else if (i < maxValue) {
277 | this.updateSkylightNeighborHeight(slice, x, z, i, maxValue + 1);
278 | }
279 | }
280 |
281 | private void updateSkylightNeighborHeight(WorldChunkSlice slice, int x, int z, int startY, int endY) {
282 | if (endY > startY) {
283 | if (!slice.isLoaded(x, z, 16)) {
284 | return;
285 | }
286 |
287 | for (int i = startY; i < endY; ++i) {
288 | this.world.checkLightFor(EnumSkyBlock.SKY, new BlockPos(x, i, z));
289 | }
290 |
291 | this.dirty = true;
292 | }
293 | }
294 |
295 | @Shadow
296 | public abstract int getHeightValue(int i, int j);
297 |
298 | // === INTERFACE IMPL ===
299 |
300 | private short[] neighborLightChecks;
301 |
302 | private boolean isLightInitialized;
303 |
304 | private ILightingEngine lightingEngine;
305 |
306 | @Override
307 | public short[] getNeighborLightChecks() {
308 | return this.neighborLightChecks;
309 | }
310 |
311 | @Override
312 | public void setNeighborLightChecks(short[] data) {
313 | this.neighborLightChecks = data;
314 | }
315 |
316 | @Override
317 | public ILightingEngine getLightingEngine() {
318 | return this.lightingEngine;
319 | }
320 |
321 | @Override
322 | public boolean isLightInitialized() {
323 | return this.isLightInitialized;
324 | }
325 |
326 | @Override
327 | public void setLightInitialized(boolean lightInitialized) {
328 | this.isLightInitialized = lightInitialized;
329 | }
330 |
331 | @Shadow
332 | protected abstract void setSkylightUpdated();
333 |
334 | @Override
335 | public void setSkylightUpdatedPublic() {
336 | this.setSkylightUpdated();
337 | }
338 |
339 | @Override
340 | public int getCachedLightFor(EnumSkyBlock type, BlockPos pos) {
341 | int i = pos.getX() & 15;
342 | int j = pos.getY();
343 | int k = pos.getZ() & 15;
344 |
345 | ExtendedBlockStorage extendedblockstorage = this.storageArrays[j >> 4];
346 |
347 | if (extendedblockstorage == Chunk.NULL_BLOCK_STORAGE) {
348 | if (this.canSeeSky(pos)) {
349 | return type.defaultLightValue;
350 | } else {
351 | return 0;
352 | }
353 | } else if (type == EnumSkyBlock.SKY) {
354 | if (!this.world.provider.hasSkyLight()) {
355 | return 0;
356 | } else {
357 | return extendedblockstorage.getSkyLight(i, j & 15, k);
358 | }
359 | } else {
360 | if (type == EnumSkyBlock.BLOCK) {
361 | return extendedblockstorage.getBlockLight(i, j & 15, k);
362 | } else {
363 | return type.defaultLightValue;
364 | }
365 | }
366 | }
367 |
368 |
369 | // === END OF INTERFACE IMPL ===
370 | }
371 |
--------------------------------------------------------------------------------
/src/main/java/me/jellysquid/mods/phosphor/mixins/lighting/common/MixinChunkProviderServer.java:
--------------------------------------------------------------------------------
1 | package me.jellysquid.mods.phosphor.mixins.lighting.common;
2 |
3 | import me.jellysquid.mods.phosphor.api.ILightingEngineProvider;
4 | import net.minecraft.world.WorldServer;
5 | import net.minecraft.world.gen.ChunkProviderServer;
6 | import org.spongepowered.asm.mixin.Final;
7 | import org.spongepowered.asm.mixin.Mixin;
8 | import org.spongepowered.asm.mixin.Shadow;
9 | import org.spongepowered.asm.mixin.injection.At;
10 | import org.spongepowered.asm.mixin.injection.Inject;
11 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
12 |
13 | import java.util.Set;
14 |
15 | @Mixin(ChunkProviderServer.class)
16 | public abstract class MixinChunkProviderServer {
17 | @Shadow
18 | @Final
19 | public WorldServer world;
20 |
21 | @Shadow
22 | @Final
23 | private Set droppedChunks;
24 |
25 | /**
26 | * Injects a callback into the start of saveChunks(boolean) to force all light updates to be processed before saving.
27 | *
28 | * @author Angeline
29 | */
30 | @Inject(method = "saveChunks", at = @At("HEAD"))
31 | private void onSaveChunks(boolean all, CallbackInfoReturnable cir) {
32 | ((ILightingEngineProvider) this.world).getLightingEngine().processLightUpdates();
33 | }
34 |
35 | /**
36 | * Injects a callback into the start of the onTick() method to process all pending light updates. This is not necessarily
37 | * required, but we don't want our work queues getting too large.
38 | *
39 | * @author Angeline
40 | */
41 | @Inject(method = "tick", at = @At("HEAD"))
42 | private void onTick(CallbackInfoReturnable cir) {
43 | if (!this.world.disableLevelSaving) {
44 | if (!this.droppedChunks.isEmpty()) {
45 | ((ILightingEngineProvider) this.world).getLightingEngine().processLightUpdates();
46 | }
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/me/jellysquid/mods/phosphor/mixins/lighting/common/MixinExtendedBlockStorage.java:
--------------------------------------------------------------------------------
1 | package me.jellysquid.mods.phosphor.mixins.lighting.common;
2 |
3 | import net.minecraft.world.chunk.NibbleArray;
4 | import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
5 | import org.spongepowered.asm.mixin.Mixin;
6 | import org.spongepowered.asm.mixin.Overwrite;
7 | import org.spongepowered.asm.mixin.Shadow;
8 |
9 | @Mixin(ExtendedBlockStorage.class)
10 | public class MixinExtendedBlockStorage {
11 | @Shadow
12 | private NibbleArray skyLight;
13 |
14 | @Shadow
15 | private int blockRefCount;
16 |
17 | @Shadow
18 | private NibbleArray blockLight;
19 |
20 | private int lightRefCount = -1;
21 |
22 | /**
23 | * @author Angeline
24 | * @author Reset lightRefCount on call
25 | * @reason r
26 | */
27 | @Overwrite
28 | public void setSkyLight(int x, int y, int z, int value) {
29 | this.skyLight.set(x, y, z, value);
30 | this.lightRefCount = -1;
31 | }
32 |
33 | /**
34 | * @author Angeline
35 | * @author Reset lightRefCount on call
36 | * @reason r
37 | */
38 | @Overwrite
39 | public void setBlockLight(int x, int y, int z, int value) {
40 | this.blockLight.set(x, y, z, value);
41 | this.lightRefCount = -1;
42 | }
43 |
44 | /**
45 | * @author Angeline
46 | * @author Reset lightRefCount on call
47 | * @reason r
48 | */
49 | @Overwrite
50 | public void setBlockLight(NibbleArray array) {
51 | this.blockLight = array;
52 | this.lightRefCount = -1;
53 | }
54 |
55 | /**
56 | * @author Angeline
57 | * @reason Reset lightRefCount on call
58 | */
59 | @Overwrite
60 | public void setSkyLight(NibbleArray array) {
61 | this.skyLight = array;
62 | this.lightRefCount = -1;
63 | }
64 |
65 |
66 | /**
67 | * @author Angeline
68 | * @reason Send light data to clients when lighting is non-trivial
69 | */
70 | @Overwrite
71 | public boolean isEmpty() {
72 | if (this.blockRefCount != 0) {
73 | return false;
74 | }
75 |
76 | // -1 indicates the lightRefCount needs to be re-calculated
77 | if (this.lightRefCount == -1) {
78 | if (this.checkLightArrayEqual(this.skyLight, (byte) 0xFF)
79 | && this.checkLightArrayEqual(this.blockLight, (byte) 0x00)) {
80 | this.lightRefCount = 0; // Lighting is trivial, don't send to clients
81 | } else {
82 | this.lightRefCount = 1; // Lighting is not trivial, send to clients
83 | }
84 | }
85 |
86 | return this.lightRefCount == 0;
87 | }
88 |
89 | private boolean checkLightArrayEqual(NibbleArray storage, byte val) {
90 | if (storage == null) {
91 | return true;
92 | }
93 |
94 | byte[] arr = storage.getData();
95 |
96 | for (byte b : arr) {
97 | if (b != val) {
98 | return false;
99 | }
100 | }
101 |
102 | return true;
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/src/main/java/me/jellysquid/mods/phosphor/mixins/lighting/common/MixinSPacketChunkData.java:
--------------------------------------------------------------------------------
1 | package me.jellysquid.mods.phosphor.mixins.lighting.common;
2 |
3 | import me.jellysquid.mods.phosphor.api.ILightingEngineProvider;
4 | import net.minecraft.network.play.server.SPacketChunkData;
5 | import net.minecraft.world.chunk.Chunk;
6 | import org.spongepowered.asm.mixin.Mixin;
7 | import org.spongepowered.asm.mixin.injection.At;
8 | import org.spongepowered.asm.mixin.injection.Inject;
9 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
10 |
11 | @Mixin(SPacketChunkData.class)
12 | public abstract class MixinSPacketChunkData {
13 | /**
14 | * @author Angeline
15 | * Injects a callback into SPacketChunkData#calculateChunkSize(Chunk, booolean, int) to force light updates to be
16 | * processed before creating the client payload. We use this method rather than the constructor as it is not valid
17 | * to inject elsewhere other than the RETURN of a ctor, which is too late for our needs.
18 | */
19 | @Inject(method = "calculateChunkSize", at = @At("HEAD"))
20 | private void onCalculateChunkSize(Chunk chunkIn, boolean hasSkyLight, int changedSectionFilter, CallbackInfoReturnable cir) {
21 | ((ILightingEngineProvider) chunkIn).getLightingEngine().processLightUpdates();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/me/jellysquid/mods/phosphor/mixins/lighting/common/MixinWorld.java:
--------------------------------------------------------------------------------
1 | package me.jellysquid.mods.phosphor.mixins.lighting.common;
2 |
3 | import me.jellysquid.mods.phosphor.api.ILightingEngineProvider;
4 | import me.jellysquid.mods.phosphor.mod.world.lighting.LightingEngine;
5 | import net.minecraft.util.math.BlockPos;
6 | import net.minecraft.world.EnumSkyBlock;
7 | import net.minecraft.world.World;
8 | import org.spongepowered.asm.mixin.Mixin;
9 | import org.spongepowered.asm.mixin.injection.At;
10 | import org.spongepowered.asm.mixin.injection.Inject;
11 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
12 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
13 |
14 | @Mixin(World.class)
15 | public abstract class MixinWorld implements ILightingEngineProvider {
16 | private LightingEngine lightingEngine;
17 |
18 | /**
19 | * @author Angeline
20 | * Initialize the lighting engine on world construction.
21 | */
22 | @Inject(method = "", at = @At("RETURN"))
23 | private void onConstructed(CallbackInfo ci) {
24 | this.lightingEngine = new LightingEngine((World) (Object) this);
25 | }
26 |
27 | /**
28 | * Directs the light update to the lighting engine and always returns a success value.
29 | * @author Angeline
30 | */
31 | @Inject(method = "checkLightFor", at = @At("HEAD"), cancellable = true)
32 | private void checkLightFor(EnumSkyBlock type, BlockPos pos, CallbackInfoReturnable cir) {
33 | this.lightingEngine.scheduleLightUpdate(type, pos);
34 |
35 | cir.setReturnValue(true);
36 | }
37 |
38 | @Override
39 | public LightingEngine getLightingEngine() {
40 | return this.lightingEngine;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/me/jellysquid/mods/phosphor/mixins/plugins/LightingEnginePlugin.java:
--------------------------------------------------------------------------------
1 | package me.jellysquid.mods.phosphor.mixins.plugins;
2 |
3 | import me.jellysquid.mods.phosphor.mod.PhosphorConfig;
4 | import net.minecraft.launchwrapper.Launch;
5 | import org.apache.logging.log4j.LogManager;
6 | import org.apache.logging.log4j.Logger;
7 | import org.spongepowered.asm.mixin.MixinEnvironment;
8 | import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
9 | import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
10 |
11 | import java.util.List;
12 | import java.util.Set;
13 |
14 | public class LightingEnginePlugin implements IMixinConfigPlugin {
15 | private static final Logger logger = LogManager.getLogger("Phosphor Plugin");
16 |
17 | public static boolean ENABLE_ILLEGAL_THREAD_ACCESS_WARNINGS = false;
18 |
19 | private PhosphorConfig config;
20 |
21 | private boolean spongePresent;
22 |
23 | @Override
24 | public void onLoad(String mixinPackage) {
25 | logger.debug("Loading configuration");
26 |
27 | this.config = PhosphorConfig.loadConfig();
28 |
29 | if (!this.config.enablePhosphor) {
30 | logger.warn("Phosphor has been disabled through mod configuration! No patches will be applied...");
31 | }
32 |
33 | ENABLE_ILLEGAL_THREAD_ACCESS_WARNINGS = this.config.enableIllegalThreadAccessWarnings;
34 |
35 | try {
36 | // This class will always be loaded by Forge prior to us (due to the tweak class ordering) and should have
37 | // no effect. On the off chance it isn't, early class loading shouldn't cause any issues as nobody seems to
38 | // transform core-mods themselves, or at least I hope they don't...
39 | Class.forName("org.spongepowered.mod.SpongeCoremod");
40 |
41 | this.spongePresent = true;
42 | } catch (Exception e) {
43 | this.spongePresent = false;
44 | }
45 |
46 | if (this.spongePresent) {
47 | logger.info("Sponge has been detected on the classpath! Enabling Sponge specific patches...");
48 | logger.warn("We cannot currently detect if you are using Sponge's async lighting patch. If you have not " +
49 | "already done so, please disable it in your configuration file for SpongeForge or you will run into issues.");
50 | }
51 | }
52 |
53 | @Override
54 | public String getRefMapperConfig() {
55 | if (Launch.blackboard.get("fml.deobfuscatedEnvironment") == Boolean.TRUE) {
56 | return null;
57 | }
58 |
59 | return "mixins.phosphor.refmap.json";
60 | }
61 |
62 | @Override
63 | public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
64 | if (!this.config.enablePhosphor) {
65 | return false;
66 | }
67 |
68 | if (this.spongePresent) {
69 | // Disable all Vanilla patches if we are in a Sponge environment
70 | if (mixinClassName.endsWith("$Vanilla")) {
71 | logger.debug("Disabled mixin '{}' because we are in a SpongeForge environment", mixinClassName);
72 |
73 | return false;
74 | }
75 | } else {
76 | // Disable all Sponge patches if we are not in a Sponge environment
77 | if (mixinClassName.endsWith("$Sponge")) {
78 | logger.debug("Disabled patch '{}' because we are in a standard Vanilla/Forge environment", mixinClassName);
79 |
80 | return false;
81 | }
82 | }
83 |
84 | // Do not apply client transformations if we are not in a client environment!
85 | if (targetClassName.startsWith("net.minecraft.client") && MixinEnvironment.getCurrentEnvironment().getSide() != MixinEnvironment.Side.CLIENT) {
86 | logger.debug("Disabled patch '{}' because it targets an client-side class unavailable in the current environment", mixinClassName);
87 |
88 | return false;
89 | }
90 |
91 | return true;
92 | }
93 |
94 | @Override
95 | public void acceptTargets(Set myTargets, Set otherTargets) {
96 |
97 | }
98 |
99 | @Override
100 | public List getMixins() {
101 | return null;
102 | }
103 |
104 | @Override
105 | public void preApply(String targetClassName, org.objectweb.asm.tree.ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
106 |
107 | }
108 |
109 | @Override
110 | public void postApply(String targetClassName, org.objectweb.asm.tree.ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
111 |
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/src/main/java/me/jellysquid/mods/phosphor/mod/PhosphorConfig.java:
--------------------------------------------------------------------------------
1 | package me.jellysquid.mods.phosphor.mod;
2 |
3 | import com.google.gson.Gson;
4 | import com.google.gson.GsonBuilder;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | import java.io.*;
8 |
9 | // This class will be initialized very early and should never load any game/mod code.
10 | public class PhosphorConfig {
11 | private static final Gson gson = createGson();
12 |
13 | private static PhosphorConfig INSTANCE;
14 |
15 | @SerializedName("enable_illegal_thread_access_warnings")
16 | public boolean enableIllegalThreadAccessWarnings = true;
17 |
18 | @SerializedName("enable_phosphor")
19 | public boolean enablePhosphor = true;
20 |
21 | public static PhosphorConfig loadConfig() {
22 | if (INSTANCE != null) {
23 | return INSTANCE;
24 | }
25 |
26 | File file = getConfigFile();
27 |
28 | PhosphorConfig config;
29 |
30 | if (!file.exists()) {
31 | config = new PhosphorConfig();
32 | config.saveConfig();
33 | } else {
34 | try (Reader reader = new FileReader(file)) {
35 | config = gson.fromJson(reader, PhosphorConfig.class);
36 | } catch (IOException e) {
37 | throw new RuntimeException("Failed to deserialize config from disk", e);
38 | }
39 | }
40 |
41 | INSTANCE = config;
42 |
43 | return config;
44 | }
45 |
46 | public void saveConfig() {
47 | File dir = getConfigDirectory();
48 |
49 | if (!dir.exists()) {
50 | if (!dir.mkdirs()) {
51 | throw new RuntimeException("Could not create configuration directory at '" + dir.getAbsolutePath() + "'");
52 | }
53 | } else if (!dir.isDirectory()) {
54 | throw new RuntimeException("Configuration directory at '" + dir.getAbsolutePath() + "' is not a directory");
55 | }
56 |
57 | try (Writer writer = new FileWriter(getConfigFile())) {
58 | gson.toJson(this, writer);
59 | } catch (IOException e) {
60 | throw new RuntimeException("Failed to serialize config to disk", e);
61 | }
62 | }
63 |
64 | private static File getConfigDirectory() {
65 | return new File("config");
66 | }
67 |
68 | private static File getConfigFile() {
69 | return new File(getConfigDirectory(), "phosphor.json");
70 | }
71 |
72 | private static Gson createGson() {
73 | return new GsonBuilder().setPrettyPrinting().create();
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/main/java/me/jellysquid/mods/phosphor/mod/PhosphorConstants.java:
--------------------------------------------------------------------------------
1 | package me.jellysquid.mods.phosphor.mod;
2 |
3 | final class PhosphorConstants {
4 | static final String MOD_ID = "phosphor-lighting";
5 |
6 | static final String MOD_NAME = "Hesperus";
7 |
8 | static final String MOD_VERSION = "1.12.2-0.2.9.3";
9 |
10 | static final String MOD_DEPENDENCIES = "after:neid@[1.5.4.4,);after:spongeforge@[1.12.2-2838-7.1.7-RC3844,);required-after:mixinbooter@[8.4,)";
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/me/jellysquid/mods/phosphor/mod/PhosphorMod.java:
--------------------------------------------------------------------------------
1 | package me.jellysquid.mods.phosphor.mod;
2 |
3 | import net.minecraftforge.fml.common.Mod;
4 | import org.apache.logging.log4j.LogManager;
5 | import org.apache.logging.log4j.Logger;
6 |
7 | @Mod(
8 | name = PhosphorConstants.MOD_NAME,
9 | modid = PhosphorConstants.MOD_ID,
10 | version = PhosphorConstants.MOD_VERSION,
11 | acceptedMinecraftVersions = "1.12.2",
12 | acceptableRemoteVersions = "*",
13 | dependencies = PhosphorConstants.MOD_DEPENDENCIES
14 | )
15 | public class PhosphorMod {
16 | public static final Logger LOGGER = LogManager.getLogger("Phosphor");
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/me/jellysquid/mods/phosphor/mod/collections/PooledLongQueue.java:
--------------------------------------------------------------------------------
1 | package me.jellysquid.mods.phosphor.mod.collections;
2 |
3 | import java.util.ArrayDeque;
4 | import java.util.Deque;
5 |
6 | //Implement own queue with pooled segments to reduce allocation costs and reduce idle memory footprint
7 | public class PooledLongQueue {
8 | private static final int CACHED_QUEUE_SEGMENTS_COUNT = 1 << 12; // 4096
9 | private static final int QUEUE_SEGMENT_SIZE = 1 << 10; // 1024
10 |
11 | private final Pool pool;
12 |
13 | private Segment cur, last;
14 |
15 | private int size = 0;
16 |
17 | // Stores whether or not the queue is empty. Updates to this field will be seen by all threads immediately. Writes
18 | // to volatile fields are generally quite a bit more expensive, so we avoid repeatedly setting this flag to true.
19 | private volatile boolean empty;
20 |
21 | public PooledLongQueue(Pool pool) {
22 | this.pool = pool;
23 | }
24 |
25 | /**
26 | * Not thread-safe! If you must know whether or not the queue is empty, please use {@link PooledLongQueue#isEmpty()}.
27 | *
28 | * @return The number of encoded values present in this queue
29 | */
30 | public int size() {
31 | return this.size;
32 | }
33 |
34 | /**
35 | * Thread-safe method to check whether or not this queue has work to do. Significantly cheaper than acquiring a lock.
36 | * @return True if the queue is empty, otherwise false
37 | */
38 | public boolean isEmpty() {
39 | return this.empty;
40 | }
41 |
42 | /**
43 | * Not thread-safe! Adds an encoded long value into this queue.
44 | * @param val The encoded value to add
45 | */
46 | public void add(final long val) {
47 | if (this.cur == null) {
48 | this.empty = false;
49 | this.cur = this.last = this.pool.acquire();
50 | }
51 |
52 | if (this.last.index == QUEUE_SEGMENT_SIZE) {
53 | Segment ret = this.last.next = this.last.pool.acquire();
54 | ret.longArray[ret.index++] = val;
55 |
56 | this.last = ret;
57 | } else {
58 | this.last.longArray[this.last.index++] = val;
59 | }
60 |
61 | ++this.size;
62 | }
63 |
64 | /**
65 | * Not thread safe! Creates an iterator over the values in this queue. Values will be returned in a FIFO fashion.
66 | * @return The iterator
67 | */
68 | public LongQueueIterator iterator() {
69 | return new LongQueueIterator(this.cur);
70 | }
71 |
72 | private void clear() {
73 | Segment segment = this.cur;
74 |
75 | while (segment != null) {
76 | Segment next = segment.next;
77 | segment.release();
78 | segment = next;
79 | }
80 |
81 | this.size = 0;
82 | this.cur = null;
83 | this.last = null;
84 | this.empty = true;
85 | }
86 |
87 | public class LongQueueIterator {
88 | private Segment cur;
89 | private long[] curArray;
90 |
91 | private int index, capacity;
92 |
93 | private LongQueueIterator(Segment cur) {
94 | this.cur = cur;
95 |
96 | if (this.cur != null) {
97 | this.curArray = cur.longArray;
98 | this.capacity = cur.index;
99 | }
100 | }
101 |
102 | public boolean hasNext() {
103 | return this.cur != null;
104 | }
105 |
106 | public long next() {
107 | final long ret = this.curArray[this.index++];
108 |
109 | if (this.index == this.capacity) {
110 | this.index = 0;
111 |
112 | this.cur = this.cur.next;
113 |
114 | if (this.cur != null) {
115 | this.curArray = this.cur.longArray;
116 | this.capacity = this.cur.index;
117 | }
118 | }
119 |
120 | return ret;
121 | }
122 |
123 | public void finish() {
124 | PooledLongQueue.this.clear();
125 | }
126 | }
127 |
128 | public static class Pool {
129 | private final Deque segmentPool = new ArrayDeque<>();
130 |
131 | private Segment acquire() {
132 | if (this.segmentPool.isEmpty()) {
133 | return new Segment(this);
134 | }
135 |
136 | return this.segmentPool.pop();
137 | }
138 |
139 | private void release(Segment segment) {
140 | if (this.segmentPool.size() < CACHED_QUEUE_SEGMENTS_COUNT) {
141 | this.segmentPool.push(segment);
142 | }
143 | }
144 | }
145 |
146 | private static class Segment {
147 | private final long[] longArray = new long[QUEUE_SEGMENT_SIZE];
148 | private int index = 0;
149 | private Segment next;
150 | private final Pool pool;
151 |
152 | private Segment(Pool pool) {
153 | this.pool = pool;
154 | }
155 |
156 | private void release() {
157 | this.index = 0;
158 | this.next = null;
159 |
160 | this.pool.release(this);
161 | }
162 | }
163 |
164 | }
165 |
--------------------------------------------------------------------------------
/src/main/java/me/jellysquid/mods/phosphor/mod/world/WorldChunkSlice.java:
--------------------------------------------------------------------------------
1 | package me.jellysquid.mods.phosphor.mod.world;
2 |
3 | import net.minecraft.world.World;
4 | import net.minecraft.world.chunk.Chunk;
5 |
6 | public class WorldChunkSlice {
7 | private static final int DIAMETER = 5;
8 |
9 | private final Chunk[] chunks;
10 |
11 | private final int x, z;
12 |
13 | public WorldChunkSlice(World world, int x, int z) {
14 | this.chunks = new Chunk[DIAMETER * DIAMETER];
15 |
16 | int radius = DIAMETER / 2;
17 |
18 | for (int xDiff = -radius; xDiff <= radius; xDiff++) {
19 | for (int zDiff = -radius; zDiff <= radius; zDiff++) {
20 | this.chunks[((xDiff + radius) * DIAMETER) + (zDiff + radius)] = world.getChunkProvider().getLoadedChunk(x + xDiff, z + zDiff);
21 | }
22 | }
23 |
24 | this.x = x - radius;
25 | this.z = z - radius;
26 | }
27 |
28 | public Chunk getChunk(int x, int z) {
29 | return this.chunks[(x * DIAMETER) + z];
30 | }
31 |
32 | public Chunk getChunkFromWorldCoords(int x, int z) {
33 | return this.getChunk((x >> 4) - this.x, (z >> 4) - this.z);
34 | }
35 |
36 | public boolean isLoaded(int x, int z, int radius) {
37 | return this.isLoaded(x - radius, z - radius, x + radius, z + radius);
38 | }
39 |
40 | public boolean isLoaded(int xStart, int zStart, int xEnd, int zEnd) {
41 | xStart = (xStart >> 4) - this.x;
42 | zStart = (zStart >> 4) - this.z;
43 | xEnd = (xEnd >> 4) - this.x;
44 | zEnd = (zEnd >> 4) - this.z;
45 |
46 | for (int i = xStart; i <= xEnd; ++i) {
47 | for (int j = zStart; j <= zEnd; ++j) {
48 | if (this.getChunk(i, j) == null) {
49 | return false;
50 | }
51 | }
52 | }
53 |
54 | return true;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/me/jellysquid/mods/phosphor/mod/world/lighting/LightingEngine.java:
--------------------------------------------------------------------------------
1 | package me.jellysquid.mods.phosphor.mod.world.lighting;
2 |
3 | import atomicstryker.dynamiclights.client.DynamicLights;
4 | import me.jellysquid.mods.phosphor.api.IChunkLighting;
5 | import me.jellysquid.mods.phosphor.api.ILightingEngine;
6 | import me.jellysquid.mods.phosphor.mixins.plugins.LightingEnginePlugin;
7 | import me.jellysquid.mods.phosphor.mod.PhosphorMod;
8 | import me.jellysquid.mods.phosphor.mod.collections.PooledLongQueue;
9 | import net.minecraft.block.state.IBlockState;
10 | import net.minecraft.client.Minecraft;
11 | import net.minecraft.profiler.Profiler;
12 | import net.minecraft.util.EnumFacing;
13 | import net.minecraft.util.math.BlockPos;
14 | import net.minecraft.util.math.BlockPos.MutableBlockPos;
15 | import net.minecraft.util.math.MathHelper;
16 | import net.minecraft.util.math.Vec3i;
17 | import net.minecraft.world.EnumSkyBlock;
18 | import net.minecraft.world.World;
19 | import net.minecraft.world.chunk.Chunk;
20 | import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
21 | import net.minecraftforge.fml.common.Loader;
22 | import net.minecraftforge.fml.relauncher.Side;
23 | import net.minecraftforge.fml.relauncher.SideOnly;
24 |
25 | import java.util.concurrent.locks.ReentrantLock;
26 |
27 | public class LightingEngine implements ILightingEngine {
28 | private static final int MAX_SCHEDULED_COUNT = 1 << 22;
29 |
30 | private static final int MAX_LIGHT = 15;
31 |
32 | private final Thread ownedThread = Thread.currentThread();
33 |
34 | private final World world;
35 |
36 | private final Profiler profiler;
37 |
38 | //Layout of longs: [padding(4)] [y(8)] [x(26)] [z(26)]
39 | private final PooledLongQueue[] queuedLightUpdates = new PooledLongQueue[EnumSkyBlock.values().length];
40 |
41 | //Layout of longs: see above
42 | private final PooledLongQueue[] queuedDarkenings = new PooledLongQueue[MAX_LIGHT + 1];
43 | private final PooledLongQueue[] queuedBrightenings = new PooledLongQueue[MAX_LIGHT + 1];
44 |
45 | //Layout of longs: [newLight(4)] [pos(60)]
46 | private final PooledLongQueue initialBrightenings;
47 | //Layout of longs: [padding(4)] [pos(60)]
48 | private final PooledLongQueue initialDarkenings;
49 |
50 | private boolean updating = false;
51 |
52 | //Layout parameters
53 | //Length of bit segments
54 | private static final int
55 | lX = 26,
56 | lY = 8,
57 | lZ = 26,
58 | lL = 4;
59 |
60 | //Bit segment shifts/positions
61 | private static final int
62 | sZ = 0,
63 | sX = sZ + lZ,
64 | sY = sX + lX,
65 | sL = sY + lY;
66 |
67 | //Bit segment masks
68 | private static final long
69 | mX = (1L << lX) - 1,
70 | mY = (1L << lY) - 1,
71 | mZ = (1L << lZ) - 1,
72 | mL = (1L << lL) - 1,
73 | mPos = (mY << sY) | (mX << sX) | (mZ << sZ);
74 |
75 | //Bit to check whether y had overflow
76 | private static final long yCheck = 1L << (sY + lY);
77 |
78 | private static final long[] neighborShifts = new long[6];
79 |
80 | static {
81 | for (int i = 0; i < 6; ++i) {
82 | final Vec3i offset = EnumFacing.VALUES[i].getDirectionVec();
83 | neighborShifts[i] = ((long) offset.getY() << sY) | ((long) offset.getX() << sX) | ((long) offset.getZ() << sZ);
84 | }
85 | }
86 |
87 | //Mask to extract chunk identifier
88 | private static final long mChunk = ((mX >> 4) << (4 + sX)) | ((mZ >> 4) << (4 + sZ));
89 |
90 | //Iteration state data
91 | //Cache position to avoid allocation of new object each time
92 | private final MutableBlockPos curPos = new MutableBlockPos();
93 | private Chunk curChunk;
94 | private long curChunkIdentifier;
95 | private long curData;
96 | static boolean isDynamicLightsLoaded;
97 |
98 | //Cached data about neighboring blocks (of tempPos)
99 | private boolean isNeighborDataValid = false;
100 |
101 | private final NeighborInfo[] neighborInfos = new NeighborInfo[6];
102 | private PooledLongQueue.LongQueueIterator queueIt;
103 |
104 | private final ReentrantLock lock = new ReentrantLock();
105 |
106 | public LightingEngine(final World world) {
107 | this.world = world;
108 | this.profiler = world.profiler;
109 | isDynamicLightsLoaded = Loader.isModLoaded("dynamiclights");
110 |
111 | PooledLongQueue.Pool pool = new PooledLongQueue.Pool();
112 |
113 | this.initialBrightenings = new PooledLongQueue(pool);
114 | this.initialDarkenings = new PooledLongQueue(pool);
115 |
116 | for (int i = 0; i < EnumSkyBlock.values().length; ++i) {
117 | this.queuedLightUpdates[i] = new PooledLongQueue(pool);
118 | }
119 |
120 | for (int i = 0; i < this.queuedDarkenings.length; ++i) {
121 | this.queuedDarkenings[i] = new PooledLongQueue(pool);
122 | }
123 |
124 | for (int i = 0; i < this.queuedBrightenings.length; ++i) {
125 | this.queuedBrightenings[i] = new PooledLongQueue(pool);
126 | }
127 |
128 | for (int i = 0; i < this.neighborInfos.length; ++i) {
129 | this.neighborInfos[i] = new NeighborInfo();
130 | }
131 | }
132 |
133 | /**
134 | * Schedules a light update for the specified light type and position to be processed later by {@link ILightingEngine#processLightUpdatesForType(EnumSkyBlock)}
135 | */
136 | @Override
137 | public void scheduleLightUpdate(final EnumSkyBlock lightType, final BlockPos pos) {
138 | this.acquireLock();
139 |
140 | try {
141 | this.scheduleLightUpdate(lightType, encodeWorldCoord(pos));
142 | } finally {
143 | this.releaseLock();
144 | }
145 | }
146 |
147 | /**
148 | * Schedules a light update for the specified light type and position to be processed later by {@link ILightingEngine#processLightUpdates()}
149 | */
150 | private void scheduleLightUpdate(final EnumSkyBlock lightType, final long pos) {
151 | final PooledLongQueue queue = this.queuedLightUpdates[lightType.ordinal()];
152 |
153 | queue.add(pos);
154 |
155 | //make sure there are not too many queued light updates
156 | if (queue.size() >= MAX_SCHEDULED_COUNT) {
157 | this.processLightUpdatesForType(lightType);
158 | }
159 | }
160 |
161 | /**
162 | * Calls {@link ILightingEngine#processLightUpdatesForType(EnumSkyBlock)} for both light types
163 | *
164 | */
165 | @Override
166 | public void processLightUpdates() {
167 | this.processLightUpdatesForType(EnumSkyBlock.SKY);
168 | this.processLightUpdatesForType(EnumSkyBlock.BLOCK);
169 | }
170 |
171 | /**
172 | * Processes light updates of the given light type
173 | */
174 | @Override
175 | public void processLightUpdatesForType(final EnumSkyBlock lightType) {
176 | // We only want to perform updates if we're being called from a tick event on the client
177 | // There are many locations in the client code which will end up making calls to this method, usually from
178 | // other threads.
179 | if (this.world.isRemote && !this.isCallingFromMainThread()) {
180 | return;
181 | }
182 |
183 | final PooledLongQueue queue = this.queuedLightUpdates[lightType.ordinal()];
184 |
185 | // Quickly check if the queue is empty before we acquire a more expensive lock.
186 | if (queue.isEmpty()) {
187 | return;
188 | }
189 |
190 | this.acquireLock();
191 |
192 | try {
193 | this.processLightUpdatesForTypeInner(lightType, queue);
194 | } finally {
195 | this.releaseLock();
196 | }
197 | }
198 |
199 | @SideOnly(Side.CLIENT)
200 | private boolean isCallingFromMainThread() {
201 | return Minecraft.getMinecraft().isCallingFromMinecraftThread();
202 | }
203 |
204 | private void acquireLock() {
205 | if (!this.lock.tryLock()) {
206 | // If we cannot lock, something has gone wrong... Only one thread should ever acquire the lock.
207 | // Validate that we're on the right thread immediately so we can gather information.
208 | // It is NEVER valid to call World methods from a thread other than the owning thread of the world instance.
209 | // Users can safely disable this warning, however it will not resolve the issue.
210 | if (LightingEnginePlugin.ENABLE_ILLEGAL_THREAD_ACCESS_WARNINGS) {
211 | Thread current = Thread.currentThread();
212 |
213 | if (current != this.ownedThread) {
214 | IllegalAccessException e = new IllegalAccessException(String.format("World is owned by '%s' (ID: %s)," +
215 | " but was accessed from thread '%s' (ID: %s)",
216 | this.ownedThread.getName(), this.ownedThread.getId(), current.getName(), current.getId()));
217 |
218 | PhosphorMod.LOGGER.warn(
219 | "Something (likely another mod) has attempted to modify the world's state from the wrong thread!\n" +
220 | "This is *bad practice* and can cause severe issues in your game. Phosphor has done as best as it can to mitigate this violation," +
221 | " but it may negatively impact performance or introduce stalls.\nIn a future release, this violation may result in a hard crash instead" +
222 | " of the current soft warning. You should report this issue to our issue tracker with the following stacktrace information.\n(If you are" +
223 | " aware you have misbehaving mods and cannot resolve this issue, you can safely disable this warning by setting" +
224 | " `enable_illegal_thread_access_warnings` to `false` in Phosphor's configuration file for the time being.)", e);
225 |
226 | }
227 |
228 | }
229 |
230 | // Wait for the lock to be released. This will likely introduce unwanted stalls, but will mitigate the issue.
231 | this.lock.lock();
232 | }
233 | }
234 |
235 | private void releaseLock() {
236 | this.lock.unlock();
237 | }
238 |
239 | private void processLightUpdatesForTypeInner(final EnumSkyBlock lightType, final PooledLongQueue queue) {
240 | //avoid nested calls
241 | if (this.updating) {
242 | throw new IllegalStateException("Already processing updates!");
243 | }
244 |
245 | this.updating = true;
246 |
247 | this.curChunkIdentifier = -1; //reset chunk cache
248 |
249 | this.profiler.startSection("lighting");
250 |
251 | this.profiler.startSection("checking");
252 |
253 | this.queueIt = queue.iterator();
254 |
255 | //process the queued updates and enqueue them for further processing
256 | while (this.nextItem()) {
257 | if (this.curChunk == null) {
258 | continue;
259 | }
260 |
261 | final int oldLight = this.getCursorCachedLight(lightType);
262 | final int newLight = this.calculateNewLightFromCursor(lightType);
263 |
264 | if (oldLight < newLight) {
265 | //don't enqueue directly for brightening in order to avoid duplicate scheduling
266 | this.initialBrightenings.add(((long) newLight << sL) | this.curData);
267 | } else if (oldLight > newLight) {
268 | //don't enqueue directly for darkening in order to avoid duplicate scheduling
269 | this.initialDarkenings.add(this.curData);
270 | }
271 | }
272 |
273 | this.queueIt = this.initialBrightenings.iterator();
274 |
275 | while (this.nextItem()) {
276 | final int newLight = (int) (this.curData >> sL & mL);
277 |
278 | if (newLight > this.getCursorCachedLight(lightType)) {
279 | //Sets the light to newLight to only schedule once. Clear leading bits of curData for later
280 | this.enqueueBrightening(this.curPos, this.curData & mPos, newLight, this.curChunk, lightType);
281 | }
282 | }
283 |
284 | this.queueIt = this.initialDarkenings.iterator();
285 |
286 | while (this.nextItem()) {
287 | final int oldLight = this.getCursorCachedLight(lightType);
288 |
289 | if (oldLight != 0) {
290 | //Sets the light to 0 to only schedule once
291 | this.enqueueDarkening(this.curPos, this.curData, oldLight, this.curChunk, lightType);
292 | }
293 | }
294 |
295 | this.profiler.endSection();
296 |
297 | //Iterate through enqueued updates (brightening and darkening in parallel) from brightest to darkest so that we only need to iterate once
298 | for (int curLight = MAX_LIGHT; curLight >= 0; --curLight) {
299 | this.profiler.startSection("darkening");
300 |
301 | this.queueIt = this.queuedDarkenings[curLight].iterator();
302 |
303 | while (this.nextItem()) {
304 | if (this.getCursorCachedLight(lightType) >= curLight) //don't darken if we got brighter due to some other change
305 | {
306 | continue;
307 | }
308 |
309 | final IBlockState state = LightingEngineHelpers.posToState(this.curPos, this.curChunk);
310 | final int luminosity = this.getCursorLuminosity(state, lightType);
311 | final int opacity; //if luminosity is high enough, opacity is irrelevant
312 |
313 | if (luminosity >= MAX_LIGHT - 1) {
314 | opacity = 1;
315 | } else {
316 | opacity = this.getPosOpacity(this.curPos, state);
317 | }
318 |
319 | //only darken neighbors if we indeed became darker
320 | if (this.calculateNewLightFromCursor(luminosity, opacity, lightType) < curLight) {
321 | //need to calculate new light value from neighbors IGNORING neighbors which are scheduled for darkening
322 | int newLight = luminosity;
323 |
324 | this.fetchNeighborDataFromCursor(lightType);
325 |
326 | for (NeighborInfo info : this.neighborInfos) {
327 | final Chunk nChunk = info.chunk;
328 |
329 | if (nChunk == null) {
330 | continue;
331 | }
332 |
333 | final int nLight = info.light;
334 |
335 | if (nLight == 0) {
336 | continue;
337 | }
338 |
339 | final MutableBlockPos nPos = info.pos;
340 |
341 | if (curLight - this.getPosOpacity(nPos, LightingEngineHelpers.posToState(nPos, info.section)) >= nLight) //schedule neighbor for darkening if we possibly light it
342 | {
343 | this.enqueueDarkening(nPos, info.key, nLight, nChunk, lightType);
344 | } else //only use for new light calculation if not
345 | {
346 | //if we can't darken the neighbor, no one else can (because of processing order) -> safe to let us be illuminated by it
347 | newLight = Math.max(newLight, nLight - opacity);
348 | }
349 | }
350 |
351 | //schedule brightening since light level was set to 0
352 | this.enqueueBrighteningFromCursor(newLight, lightType);
353 | } else //we didn't become darker, so we need to re-set our initial light value (was set to 0) and notify neighbors
354 | {
355 | this.enqueueBrighteningFromCursor(curLight, lightType); //do not spread to neighbors immediately to avoid scheduling multiple times
356 | }
357 | }
358 |
359 | this.profiler.endStartSection("brightening");
360 |
361 | this.queueIt = this.queuedBrightenings[curLight].iterator();
362 |
363 | while (this.nextItem()) {
364 | final int oldLight = this.getCursorCachedLight(lightType);
365 |
366 | if (oldLight == curLight) //only process this if nothing else has happened at this position since scheduling
367 | {
368 |
369 |
370 | this.world.notifyLightSet(this.curPos);
371 |
372 |
373 | if (curLight > 1) {
374 | this.spreadLightFromCursor(curLight, lightType);
375 | }
376 | }
377 | }
378 |
379 | this.profiler.endSection();
380 | }
381 |
382 | this.profiler.endSection();
383 |
384 | this.updating = false;
385 | }
386 |
387 | /**
388 | * Gets data for neighbors of curPos
and saves the results into neighbor state data members. If a neighbor can't be accessed/doesn't exist, the corresponding entry in neighborChunks
is null
- others are not reset
389 | */
390 | private void fetchNeighborDataFromCursor(final EnumSkyBlock lightType) {
391 | //only update if curPos was changed
392 | if (this.isNeighborDataValid) {
393 | return;
394 | }
395 |
396 | this.isNeighborDataValid = true;
397 |
398 | for (int i = 0; i < this.neighborInfos.length; ++i) {
399 | NeighborInfo info = this.neighborInfos[i];
400 |
401 | final long nLongPos = info.key = this.curData + neighborShifts[i];
402 |
403 | if ((nLongPos & yCheck) != 0) {
404 | info.chunk = null;
405 | info.section = null;
406 | continue;
407 | }
408 |
409 | final MutableBlockPos nPos = decodeWorldCoord(info.pos, nLongPos);
410 |
411 | final Chunk nChunk;
412 |
413 | if ((nLongPos & mChunk) == this.curChunkIdentifier) {
414 | nChunk = info.chunk = this.curChunk;
415 | } else {
416 | nChunk = info.chunk = this.getChunk(nPos);
417 | }
418 |
419 | if (nChunk != null) {
420 | ExtendedBlockStorage nSection = nChunk.getBlockStorageArray()[nPos.getY() >> 4];
421 |
422 | info.light = getCachedLightFor(nChunk, nSection, nPos, lightType);
423 | info.section = nSection;
424 | }
425 | }
426 | }
427 |
428 |
429 | private static int getCachedLightFor(Chunk chunk, ExtendedBlockStorage storage, BlockPos pos, EnumSkyBlock type) {
430 | int i = pos.getX() & 15;
431 | int j = pos.getY();
432 | int k = pos.getZ() & 15;
433 |
434 | if (storage == Chunk.NULL_BLOCK_STORAGE) {
435 | if (type == EnumSkyBlock.SKY && chunk.canSeeSky(pos)) {
436 | return type.defaultLightValue;
437 | } else {
438 | return 0;
439 | }
440 | } else if (type == EnumSkyBlock.SKY) {
441 | if (!chunk.getWorld().provider.hasSkyLight()) {
442 | return 0;
443 | } else {
444 | return storage.getSkyLight(i, j & 15, k);
445 | }
446 | } else {
447 | if (type == EnumSkyBlock.BLOCK) {
448 | return storage.getBlockLight(i, j & 15, k);
449 | } else {
450 | return type.defaultLightValue;
451 | }
452 | }
453 | }
454 |
455 |
456 | private int calculateNewLightFromCursor(final EnumSkyBlock lightType) {
457 | final IBlockState state = LightingEngineHelpers.posToState(this.curPos, this.curChunk);
458 |
459 | final int luminosity = this.getCursorLuminosity(state, lightType);
460 | final int opacity;
461 |
462 | if (luminosity >= MAX_LIGHT - 1) {
463 | opacity = 1;
464 | } else {
465 | opacity = this.getPosOpacity(this.curPos, state);
466 | }
467 |
468 | return this.calculateNewLightFromCursor(luminosity, opacity, lightType);
469 | }
470 |
471 | private int calculateNewLightFromCursor(final int luminosity, final int opacity, final EnumSkyBlock lightType) {
472 | if (luminosity >= MAX_LIGHT - opacity) {
473 | return luminosity;
474 | }
475 |
476 | int newLight = luminosity;
477 |
478 | this.fetchNeighborDataFromCursor(lightType);
479 |
480 | for (NeighborInfo info : this.neighborInfos) {
481 | if (info.chunk == null) {
482 | continue;
483 | }
484 |
485 | final int nLight = info.light;
486 |
487 | newLight = Math.max(nLight - opacity, newLight);
488 | }
489 |
490 | return newLight;
491 | }
492 |
493 | private void spreadLightFromCursor(final int curLight, final EnumSkyBlock lightType) {
494 | this.fetchNeighborDataFromCursor(lightType);
495 |
496 | for (NeighborInfo info : this.neighborInfos) {
497 | final Chunk nChunk = info.chunk;
498 |
499 | if (nChunk == null) {
500 | continue;
501 | }
502 |
503 | final int newLight = curLight - this.getPosOpacity(info.pos, LightingEngineHelpers.posToState(info.pos, info.section));
504 |
505 | if (newLight > info.light) {
506 | this.enqueueBrightening(info.pos, info.key, newLight, nChunk, lightType);
507 | }
508 | }
509 | }
510 |
511 | private void enqueueBrighteningFromCursor(final int newLight, final EnumSkyBlock lightType) {
512 | this.enqueueBrightening(this.curPos, this.curData, newLight, this.curChunk, lightType);
513 | }
514 |
515 | /**
516 | * Enqueues the pos for brightening and sets its light value to newLight
517 | */
518 | private void enqueueBrightening(final BlockPos pos, final long longPos, final int newLight, final Chunk chunk, final EnumSkyBlock lightType) {
519 | this.queuedBrightenings[newLight].add(longPos);
520 |
521 | chunk.setLightFor(lightType, pos, newLight);
522 | }
523 |
524 | /**
525 | * Enqueues the pos for darkening and sets its light value to 0
526 | */
527 | private void enqueueDarkening(final BlockPos pos, final long longPos, final int oldLight, final Chunk chunk, final EnumSkyBlock lightType) {
528 | this.queuedDarkenings[oldLight].add(longPos);
529 |
530 | chunk.setLightFor(lightType, pos, 0);
531 | }
532 |
533 | private static MutableBlockPos decodeWorldCoord(final MutableBlockPos pos, final long longPos) {
534 | final int posX = (int) (longPos >> sX & mX) - (1 << lX - 1);
535 | final int posY = (int) (longPos >> sY & mY);
536 | final int posZ = (int) (longPos >> sZ & mZ) - (1 << lZ - 1);
537 |
538 | return pos.setPos(posX, posY, posZ);
539 | }
540 |
541 | private static long encodeWorldCoord(final BlockPos pos) {
542 | return encodeWorldCoord(pos.getX(), pos.getY(), pos.getZ());
543 | }
544 |
545 | private static long encodeWorldCoord(final long x, final long y, final long z) {
546 | return (y << sY) | (x + (1 << lX - 1) << sX) | (z + (1 << lZ - 1) << sZ);
547 | }
548 |
549 | private static int ITEMS_PROCESSED = 0, CHUNKS_FETCHED = 0;
550 |
551 | /**
552 | * Polls a new item from curQueue
and fills in state data members
553 | *
554 | * @return If there was an item to poll
555 | */
556 | private boolean nextItem() {
557 | if (!this.queueIt.hasNext()) {
558 | this.queueIt.finish();
559 | this.queueIt = null;
560 |
561 | return false;
562 | }
563 |
564 | this.curData = this.queueIt.next();
565 | this.isNeighborDataValid = false;
566 |
567 | decodeWorldCoord(this.curPos, this.curData);
568 |
569 | final long chunkIdentifier = this.curData & mChunk;
570 |
571 | if (this.curChunkIdentifier != chunkIdentifier) {
572 | this.curChunk = this.getChunk(this.curPos);
573 | this.curChunkIdentifier = chunkIdentifier;
574 | CHUNKS_FETCHED++;
575 | }
576 |
577 | ITEMS_PROCESSED++;
578 |
579 | return true;
580 | }
581 |
582 | private int getCursorCachedLight(final EnumSkyBlock lightType) {
583 | return ((IChunkLighting) this.curChunk).getCachedLightFor(lightType, this.curPos);
584 | }
585 |
586 | /**
587 | * Calculates the luminosity for curPos
, taking into account lightType
588 | */
589 | private int getCursorLuminosity(final IBlockState state, final EnumSkyBlock lightType) {
590 | if (lightType == EnumSkyBlock.SKY) {
591 | if (this.curChunk.canSeeSky(this.curPos)) {
592 | return EnumSkyBlock.SKY.defaultLightValue;
593 | } else {
594 | return 0;
595 | }
596 | }
597 |
598 | return MathHelper.clamp(LightingEngineHelpers.getLightValueForState(state, this.world, this.curPos), 0, MAX_LIGHT);
599 | }
600 |
601 | private int getPosOpacity(final BlockPos pos, final IBlockState state) {
602 | return MathHelper.clamp(state.getLightOpacity(this.world, pos), 1, MAX_LIGHT);
603 | }
604 |
605 | private Chunk getChunk(final BlockPos pos) {
606 | return this.world.getChunkProvider().getLoadedChunk(pos.getX() >> 4, pos.getZ() >> 4);
607 | }
608 |
609 | private static class NeighborInfo {
610 | Chunk chunk;
611 | ExtendedBlockStorage section;
612 |
613 | int light;
614 |
615 | long key;
616 |
617 | final MutableBlockPos pos = new MutableBlockPos();
618 | }
619 | }
620 |
621 |
--------------------------------------------------------------------------------
/src/main/java/me/jellysquid/mods/phosphor/mod/world/lighting/LightingEngineHelpers.java:
--------------------------------------------------------------------------------
1 | package me.jellysquid.mods.phosphor.mod.world.lighting;
2 |
3 | import atomicstryker.dynamiclights.client.DynamicLights;
4 | import net.minecraft.block.state.IBlockState;
5 | import net.minecraft.init.Blocks;
6 | import net.minecraft.util.math.BlockPos;
7 | import net.minecraft.world.IBlockAccess;
8 | import net.minecraft.world.chunk.Chunk;
9 | import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
10 |
11 | public class LightingEngineHelpers {
12 | private static final IBlockState DEFAULT_BLOCK_STATE = Blocks.AIR.getDefaultState();
13 |
14 | // Avoids some additional logic in Chunk#getBlockState... 0 is always air
15 | static IBlockState posToState(final BlockPos pos, final Chunk chunk) {
16 | return posToState(pos, chunk.getBlockStorageArray()[pos.getY() >> 4]);
17 | }
18 |
19 | static IBlockState posToState(final BlockPos pos, final ExtendedBlockStorage section) {
20 | final int x = pos.getX();
21 | final int y = pos.getY();
22 | final int z = pos.getZ();
23 |
24 | if (section != Chunk.NULL_BLOCK_STORAGE)
25 | {
26 |
27 | return section.getData().get((x & 15), (y & 15), (z & 15));
28 |
29 | }
30 |
31 | return DEFAULT_BLOCK_STATE;
32 | }
33 |
34 | static int getLightValueForState(final IBlockState state, final IBlockAccess world, final BlockPos pos) {
35 | if(LightingEngine.isDynamicLightsLoaded) {
36 | /* Use the Dynamic Lights implementation */
37 | return DynamicLights.getLightValue(state.getBlock(), state, world, pos);
38 | } else {
39 | /* Use the vanilla implementation */
40 | return state.getLightValue(world, pos);
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/me/jellysquid/mods/phosphor/mod/world/lighting/LightingHooks.java:
--------------------------------------------------------------------------------
1 | package me.jellysquid.mods.phosphor.mod.world.lighting;
2 |
3 | import me.jellysquid.mods.phosphor.api.IChunkLighting;
4 | import me.jellysquid.mods.phosphor.api.IChunkLightingData;
5 | import me.jellysquid.mods.phosphor.api.ILightingEngine;
6 | import me.jellysquid.mods.phosphor.api.ILightingEngineProvider;
7 | import me.jellysquid.mods.phosphor.mod.PhosphorMod;
8 | import net.minecraft.block.state.IBlockState;
9 | import net.minecraft.nbt.NBTTagCompound;
10 | import net.minecraft.nbt.NBTTagList;
11 | import net.minecraft.nbt.NBTTagShort;
12 | import net.minecraft.util.EnumFacing;
13 | import net.minecraft.util.math.BlockPos;
14 | import net.minecraft.world.EnumSkyBlock;
15 | import net.minecraft.world.World;
16 | import net.minecraft.world.chunk.Chunk;
17 | import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
18 |
19 | @SuppressWarnings("unused")
20 | public class LightingHooks {
21 | private static final EnumSkyBlock[] ENUM_SKY_BLOCK_VALUES = EnumSkyBlock.values();
22 |
23 | private static final EnumFacing.AxisDirection[] ENUM_AXIS_DIRECTION_VALUES = EnumFacing.AxisDirection.values();
24 |
25 | private static final int FLAG_COUNT = 32; //2 light types * 4 directions * 2 halves * (inwards + outwards)
26 |
27 | public static void relightSkylightColumn(final World world, final Chunk chunk, final int x, final int z, final int height1, final int height2) {
28 | final int yMin = Math.min(height1, height2);
29 | final int yMax = Math.max(height1, height2) - 1;
30 |
31 | final ExtendedBlockStorage[] sections = chunk.getBlockStorageArray();
32 |
33 | final int xBase = (chunk.x << 4) + x;
34 | final int zBase = (chunk.z << 4) + z;
35 |
36 | scheduleRelightChecksForColumn(world, EnumSkyBlock.SKY, xBase, zBase, yMin, yMax);
37 |
38 | if (sections[yMin >> 4] == Chunk.NULL_BLOCK_STORAGE && yMin > 0) {
39 | world.checkLightFor(EnumSkyBlock.SKY, new BlockPos(xBase, yMin - 1, zBase));
40 | }
41 |
42 | short emptySections = 0;
43 |
44 | for (int sec = yMax >> 4; sec >= yMin >> 4; --sec) {
45 | if (sections[sec] == Chunk.NULL_BLOCK_STORAGE) {
46 | emptySections |= 1 << sec;
47 | }
48 | }
49 |
50 | if (emptySections != 0) {
51 | for (final EnumFacing dir : EnumFacing.HORIZONTALS) {
52 | final int xOffset = dir.getXOffset();
53 | final int zOffset = dir.getZOffset();
54 |
55 | final boolean neighborColumnExists =
56 | (((x + xOffset) | (z + zOffset)) & 16) == 0
57 | //Checks whether the position is at the specified border (the 16 bit is set for both 15+1 and 0-1)
58 | || world.getChunkProvider().getLoadedChunk(chunk.x + xOffset, chunk.z + zOffset) != null;
59 |
60 | if (neighborColumnExists) {
61 | for (int sec = yMax >> 4; sec >= yMin >> 4; --sec) {
62 | if ((emptySections & (1 << sec)) != 0) {
63 | scheduleRelightChecksForColumn(world, EnumSkyBlock.SKY, xBase + xOffset, zBase + zOffset, sec << 4, (sec << 4) + 15);
64 | }
65 | }
66 | } else {
67 | flagChunkBoundaryForUpdate(chunk, emptySections, EnumSkyBlock.SKY, dir, getAxisDirection(dir, x, z), EnumBoundaryFacing.OUT);
68 | }
69 | }
70 | }
71 | }
72 |
73 | public static void scheduleRelightChecksForArea(final World world, final EnumSkyBlock lightType, final int xMin, final int yMin, final int zMin,
74 | final int xMax, final int yMax, final int zMax) {
75 | for (int x = xMin; x <= xMax; ++x) {
76 | for (int z = zMin; z <= zMax; ++z) {
77 | scheduleRelightChecksForColumn(world, lightType, x, z, yMin, yMax);
78 | }
79 | }
80 | }
81 |
82 | private static void scheduleRelightChecksForColumn(final World world, final EnumSkyBlock lightType, final int x, final int z, final int yMin, final int yMax) {
83 | BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos();
84 |
85 | for (int y = yMin; y <= yMax; ++y) {
86 | world.checkLightFor(lightType, pos.setPos(x, y, z));
87 | }
88 | }
89 |
90 | public enum EnumBoundaryFacing {
91 | IN, OUT;
92 |
93 | public EnumBoundaryFacing getOpposite() {
94 | return this == IN ? OUT : IN;
95 | }
96 | }
97 |
98 | public static void flagSecBoundaryForUpdate(final Chunk chunk, final BlockPos pos, final EnumSkyBlock lightType, final EnumFacing dir,
99 | final EnumBoundaryFacing boundaryFacing) {
100 | flagChunkBoundaryForUpdate(chunk, (short) (1 << (pos.getY() >> 4)), lightType, dir, getAxisDirection(dir, pos.getX(), pos.getZ()), boundaryFacing);
101 | }
102 |
103 | public static void flagChunkBoundaryForUpdate(final Chunk chunk, final short sectionMask, final EnumSkyBlock lightType, final EnumFacing dir,
104 | final EnumFacing.AxisDirection axisDirection, final EnumBoundaryFacing boundaryFacing) {
105 | initNeighborLightChecks(chunk);
106 | ((IChunkLightingData) chunk).getNeighborLightChecks()[getFlagIndex(lightType, dir, axisDirection, boundaryFacing)] |= sectionMask;
107 | chunk.markDirty();
108 | }
109 |
110 | public static int getFlagIndex(final EnumSkyBlock lightType, final int xOffset, final int zOffset, final EnumFacing.AxisDirection axisDirection,
111 | final EnumBoundaryFacing boundaryFacing) {
112 | return (lightType == EnumSkyBlock.BLOCK ? 0 : 16) | ((xOffset + 1) << 2) | ((zOffset + 1) << 1) | (axisDirection.getOffset() + 1) | boundaryFacing
113 | .ordinal();
114 | }
115 |
116 | public static int getFlagIndex(final EnumSkyBlock lightType, final EnumFacing dir, final EnumFacing.AxisDirection axisDirection,
117 | final EnumBoundaryFacing boundaryFacing) {
118 | return getFlagIndex(lightType, dir.getXOffset(), dir.getZOffset(), axisDirection, boundaryFacing);
119 | }
120 |
121 | private static EnumFacing.AxisDirection getAxisDirection(final EnumFacing dir, final int x, final int z) {
122 | return ((dir.getAxis() == EnumFacing.Axis.X ? z : x) & 15) < 8 ? EnumFacing.AxisDirection.NEGATIVE : EnumFacing.AxisDirection.POSITIVE;
123 | }
124 |
125 | public static void scheduleRelightChecksForChunkBoundaries(final World world, final Chunk chunk) {
126 | for (final EnumFacing dir : EnumFacing.HORIZONTALS) {
127 | final int xOffset = dir.getXOffset();
128 | final int zOffset = dir.getZOffset();
129 |
130 | final Chunk nChunk = world.getChunkProvider().getLoadedChunk(chunk.x + xOffset, chunk.z + zOffset);
131 |
132 | if (nChunk == null) {
133 | continue;
134 | }
135 |
136 | for (final EnumSkyBlock lightType : ENUM_SKY_BLOCK_VALUES) {
137 | for (final EnumFacing.AxisDirection axisDir : ENUM_AXIS_DIRECTION_VALUES) {
138 | //Merge flags upon loading of a chunk. This ensures that all flags are always already on the IN boundary below
139 | mergeFlags(lightType, chunk, nChunk, dir, axisDir);
140 | mergeFlags(lightType, nChunk, chunk, dir.getOpposite(), axisDir);
141 |
142 | //Check everything that might have been canceled due to this chunk not being loaded.
143 | //Also, pass in chunks if already known
144 | //The boundary to the neighbor chunk (both ways)
145 | scheduleRelightChecksForBoundary(world, chunk, nChunk, null, lightType, xOffset, zOffset, axisDir);
146 | scheduleRelightChecksForBoundary(world, nChunk, chunk, null, lightType, -xOffset, -zOffset, axisDir);
147 | //The boundary to the diagonal neighbor (since the checks in that chunk were aborted if this chunk wasn't loaded, see scheduleRelightChecksForBoundary)
148 | scheduleRelightChecksForBoundary(world, nChunk, null, chunk, lightType, (zOffset != 0 ? axisDir.getOffset() : 0),
149 | (xOffset != 0 ? axisDir.getOffset() : 0), dir.getAxisDirection() == EnumFacing.AxisDirection.POSITIVE ?
150 | EnumFacing.AxisDirection.NEGATIVE :
151 | EnumFacing.AxisDirection.POSITIVE);
152 | }
153 | }
154 | }
155 | }
156 |
157 | private static void mergeFlags(final EnumSkyBlock lightType, final Chunk inChunk, final Chunk outChunk, final EnumFacing dir,
158 | final EnumFacing.AxisDirection axisDir) {
159 | IChunkLightingData outChunkLightingData = (IChunkLightingData) outChunk;
160 |
161 | if (outChunkLightingData.getNeighborLightChecks() == null) {
162 | return;
163 | }
164 |
165 | IChunkLightingData inChunkLightingData = (IChunkLightingData) inChunk;
166 |
167 | initNeighborLightChecks(inChunk);
168 |
169 | final int inIndex = getFlagIndex(lightType, dir, axisDir, EnumBoundaryFacing.IN);
170 | final int outIndex = getFlagIndex(lightType, dir.getOpposite(), axisDir, EnumBoundaryFacing.OUT);
171 |
172 | inChunkLightingData.getNeighborLightChecks()[inIndex] |= outChunkLightingData.getNeighborLightChecks()[outIndex];
173 | //no need to call Chunk.setModified() since checks are not deleted from outChunk
174 | }
175 |
176 | private static void scheduleRelightChecksForBoundary(final World world, final Chunk chunk, Chunk nChunk, Chunk sChunk, final EnumSkyBlock lightType,
177 | final int xOffset, final int zOffset, final EnumFacing.AxisDirection axisDir) {
178 | IChunkLightingData chunkLightingData = (IChunkLightingData) chunk;
179 |
180 | if (chunkLightingData.getNeighborLightChecks() == null) {
181 | return;
182 | }
183 |
184 | final int flagIndex = getFlagIndex(lightType, xOffset, zOffset, axisDir, EnumBoundaryFacing.IN); //OUT checks from neighbor are already merged
185 |
186 | final int flags = chunkLightingData.getNeighborLightChecks()[flagIndex];
187 |
188 | if (flags == 0) {
189 | return;
190 | }
191 |
192 | if (nChunk == null) {
193 | nChunk = world.getChunkProvider().getLoadedChunk(chunk.x + xOffset, chunk.z + zOffset);
194 |
195 | if (nChunk == null) {
196 | return;
197 | }
198 | }
199 |
200 | if (sChunk == null) {
201 | sChunk = world.getChunkProvider()
202 | .getLoadedChunk(chunk.x + (zOffset != 0 ? axisDir.getOffset() : 0), chunk.z + (xOffset != 0 ? axisDir.getOffset() : 0));
203 |
204 | if (sChunk == null) {
205 | return; //Cancel, since the checks in the corner columns require the corner column of sChunk
206 | }
207 | }
208 |
209 | final int reverseIndex = getFlagIndex(lightType, -xOffset, -zOffset, axisDir, EnumBoundaryFacing.OUT);
210 |
211 | chunkLightingData.getNeighborLightChecks()[flagIndex] = 0;
212 |
213 | IChunkLightingData nChunkLightingData = (IChunkLightingData) nChunk;
214 |
215 | if (nChunkLightingData.getNeighborLightChecks() != null) {
216 | nChunkLightingData.getNeighborLightChecks()[reverseIndex] = 0; //Clear only now that it's clear that the checks are processed
217 | }
218 |
219 | chunk.markDirty();
220 | nChunk.markDirty();
221 |
222 | //Get the area to check
223 | //Start in the corner...
224 | int xMin = chunk.x << 4;
225 | int zMin = chunk.z << 4;
226 |
227 | //move to other side of chunk if the direction is positive
228 | if ((xOffset | zOffset) > 0) {
229 | xMin += 15 * xOffset;
230 | zMin += 15 * zOffset;
231 | }
232 |
233 | //shift to other half if necessary (shift perpendicular to dir)
234 | if (axisDir == EnumFacing.AxisDirection.POSITIVE) {
235 | xMin += 8 * (zOffset & 1); //x & 1 is same as abs(x) for x=-1,0,1
236 | zMin += 8 * (xOffset & 1);
237 | }
238 |
239 | //get maximal values (shift perpendicular to dir)
240 | final int xMax = xMin + 7 * (zOffset & 1);
241 | final int zMax = zMin + 7 * (xOffset & 1);
242 |
243 | for (int y = 0; y < 16; ++y) {
244 | if ((flags & (1 << y)) != 0) {
245 | scheduleRelightChecksForArea(world, lightType, xMin, y << 4, zMin, xMax, (y << 4) + 15, zMax);
246 | }
247 | }
248 | }
249 |
250 | public static void initNeighborLightChecks(final Chunk chunk) {
251 | IChunkLightingData lightingData = (IChunkLightingData) chunk;
252 |
253 | if (lightingData.getNeighborLightChecks() == null) {
254 | lightingData.setNeighborLightChecks(new short[FLAG_COUNT]);
255 | }
256 | }
257 |
258 | public static final String neighborLightChecksKey = "NeighborLightChecks";
259 |
260 | public static void writeNeighborLightChecksToNBT(final Chunk chunk, final NBTTagCompound nbt) {
261 | short[] neighborLightChecks = ((IChunkLightingData) chunk).getNeighborLightChecks();
262 |
263 | if (neighborLightChecks == null) {
264 | return;
265 | }
266 |
267 | boolean empty = true;
268 |
269 | final NBTTagList list = new NBTTagList();
270 |
271 | for (final short flags : neighborLightChecks) {
272 | list.appendTag(new NBTTagShort(flags));
273 |
274 | if (flags != 0) {
275 | empty = false;
276 | }
277 | }
278 |
279 | if (!empty) {
280 | nbt.setTag(neighborLightChecksKey, list);
281 | }
282 | }
283 |
284 | public static void readNeighborLightChecksFromNBT(final Chunk chunk, final NBTTagCompound nbt) {
285 | if (nbt.hasKey(neighborLightChecksKey, 9)) {
286 | final NBTTagList list = nbt.getTagList(neighborLightChecksKey, 2);
287 |
288 | if (list.tagCount() == FLAG_COUNT) {
289 | initNeighborLightChecks(chunk);
290 |
291 | short[] neighborLightChecks = ((IChunkLightingData) chunk).getNeighborLightChecks();
292 |
293 | for (int i = 0; i < FLAG_COUNT; ++i) {
294 | neighborLightChecks[i] = ((NBTTagShort) list.get(i)).getShort();
295 | }
296 | } else {
297 | PhosphorMod.LOGGER.warn("Chunk field {} had invalid length, ignoring it (chunk coordinates: {} {})", neighborLightChecksKey, chunk.x, chunk.z);
298 | }
299 | }
300 | }
301 |
302 | public static void initChunkLighting(final Chunk chunk, final World world) {
303 | final int xBase = chunk.x << 4;
304 | final int zBase = chunk.z << 4;
305 |
306 | final BlockPos.PooledMutableBlockPos pos = BlockPos.PooledMutableBlockPos.retain(xBase, 0, zBase);
307 |
308 | if (world.isAreaLoaded(pos.add(-16, 0, -16), pos.add(31, 255, 31), false)) {
309 | final ExtendedBlockStorage[] extendedBlockStorage = chunk.getBlockStorageArray();
310 |
311 | for (int j = 0; j < extendedBlockStorage.length; ++j) {
312 | final ExtendedBlockStorage storage = extendedBlockStorage[j];
313 |
314 | if (storage == Chunk.NULL_BLOCK_STORAGE) {
315 | continue;
316 | }
317 |
318 | int yBase = j * 16;
319 |
320 | for (int y = 0; y < 16; y++) {
321 | for (int z = 0; z < 16; z++) {
322 | for (int x = 0; x < 16; x++) {
323 |
324 | IBlockState state = storage.getData().get(x, y, z);
325 |
326 | int light = LightingEngineHelpers.getLightValueForState(state, world, pos);
327 |
328 | if (light > 0) {
329 | pos.setPos(xBase + x, yBase + y, zBase + z);
330 |
331 | world.checkLightFor(EnumSkyBlock.BLOCK, pos);
332 | }
333 |
334 | }
335 | }
336 | }
337 | }
338 |
339 | if (world.provider.hasSkyLight()) {
340 | ((IChunkLightingData) chunk).setSkylightUpdatedPublic();
341 | }
342 |
343 | ((IChunkLightingData) chunk).setLightInitialized(true);
344 | }
345 |
346 | pos.release();
347 | }
348 |
349 | public static void checkChunkLighting(final Chunk chunk, final World world) {
350 | if (!((IChunkLightingData) chunk).isLightInitialized()) {
351 | initChunkLighting(chunk, world);
352 | }
353 |
354 | for (int x = -1; x <= 1; ++x) {
355 | for (int z = -1; z <= 1; ++z) {
356 | if (x != 0 || z != 0) {
357 | Chunk nChunk = world.getChunkProvider().getLoadedChunk(chunk.x + x, chunk.z + z);
358 |
359 | if (nChunk == null || !((IChunkLightingData) nChunk).isLightInitialized()) {
360 | return;
361 | }
362 | }
363 | }
364 | }
365 |
366 | chunk.setLightPopulated(true);
367 | }
368 |
369 | public static void initSkylightForSection(final World world, final Chunk chunk, final ExtendedBlockStorage section) {
370 | if (world.provider.hasSkyLight()) {
371 | for (int x = 0; x < 16; ++x) {
372 | for (int z = 0; z < 16; ++z) {
373 | if (chunk.getHeightValue(x, z) <= section.getYLocation()) {
374 | for (int y = 0; y < 16; ++y) {
375 | section.setSkyLight(x, y, z, EnumSkyBlock.SKY.defaultLightValue);
376 | }
377 | }
378 | }
379 | }
380 | }
381 | }
382 |
383 | private static short[] getNeighborLightChecks(Chunk chunk) {
384 | return ((IChunkLightingData) chunk).getNeighborLightChecks();
385 | }
386 |
387 | private static void setNeighborLightChecks(Chunk chunk, short[] table) {
388 | ((IChunkLightingData) chunk).setNeighborLightChecks(table);
389 | }
390 |
391 | public static int getCachedLightFor(Chunk chunk, EnumSkyBlock type, BlockPos pos) {
392 | return ((IChunkLighting) chunk).getCachedLightFor(type, pos);
393 | }
394 |
395 | public static ILightingEngine getLightingEngine(World world) {
396 | return ((ILightingEngineProvider) world).getLightingEngine();
397 | }
398 |
399 | }
400 |
--------------------------------------------------------------------------------
/src/main/resources/assets/phosphor-lighting/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kappa-maintainer/Hesperus/1f415f936fe0887e589ac4c05715eda9b0618519/src/main/resources/assets/phosphor-lighting/icon.png
--------------------------------------------------------------------------------
/src/main/resources/mcmod.info:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "modid": "phosphor-lighting",
4 | "name": "Hesperus, fork from Phosphor",
5 | "description": "",
6 | "version": "${version}",
7 | "mcversion": "${mcversion}",
8 | "logoFile": "/assets/phosphor-lighting/icon.png",
9 | "url": "https://minecraft.curseforge.com/projects/hesperus",
10 | "authorList": [
11 | "Angeline (@jellysquid)",
12 | "embeddedt"
13 | ]
14 | }
15 | ]
16 |
--------------------------------------------------------------------------------
/src/main/resources/mixins.phosphor.json:
--------------------------------------------------------------------------------
1 | {
2 | "required": true,
3 | "minVersion": "0.7.10",
4 | "package": "me.jellysquid.mods.phosphor.mixins.lighting",
5 | "plugin": "me.jellysquid.mods.phosphor.mixins.plugins.LightingEnginePlugin",
6 | "compatibilityLevel": "JAVA_8",
7 | "client": [
8 | "client.MixinMinecraft"
9 | ],
10 | "mixins": [
11 | "common.MixinAnvilChunkLoader",
12 | "common.MixinChunk",
13 | "common.MixinChunk$Sponge",
14 | "common.MixinChunk$Vanilla",
15 | "common.MixinChunkProviderServer",
16 | "common.MixinExtendedBlockStorage",
17 | "common.MixinSPacketChunkData",
18 | "common.MixinWorld"
19 | ],
20 | "injectors": {
21 | "defaultRequire": 1
22 | },
23 | "overwrites": {
24 | "conformVisibility": true
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/resources/phosphor_at.cfg:
--------------------------------------------------------------------------------
1 | public net.minecraft.world.chunk.BlockStateContainer field_186021_b # storage
2 | public net.minecraft.world.chunk.BlockStateContainer field_186022_c # palette
3 |
4 | public net.minecraft.world.chunk.storage.ExtendedBlockStorage field_177488_d # data
5 |
--------------------------------------------------------------------------------