├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── build.gradle ├── changelog.txt ├── eclipseFormat.xml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src └── main └── java └── team └── chisel └── ctmlib ├── CTM.java ├── CTMBlock.java ├── CTMLib.java ├── CTMRenderer.java ├── Dir.java ├── Drawing.java ├── ICTMBlock.java ├── ISubmap.java ├── ISubmapManager.java ├── RenderBlocksCTM.java ├── RenderBlocksColumn.java ├── SubmapManagerCTM.java └── TextureSubmap.java /.gitignore: -------------------------------------------------------------------------------- 1 | #eclipse 2 | .project 3 | .classpath 4 | .metadata 5 | org.* 6 | bin 7 | 8 | #idea 9 | .idea 10 | *.iml 11 | *.ipr 12 | *.iws 13 | out 14 | 15 | #gradle 16 | build 17 | .gradle 18 | 19 | #runtime 20 | eclipse 21 | run 22 | 23 | #mac 24 | .DS_Store 25 | *.command 26 | 27 | #windows 28 | Thumbs.db 29 | 30 | #workspace 31 | saves 32 | asm 33 | logs 34 | screenshots 35 | mods 36 | lib 37 | libs 38 | #config I assume you want to keep your minecraft config and world out 39 | #world this is taken care of with the run folder up at runtime you are actually removing the packages 40 | 41 | *.txt 42 | *.json 43 | /server.properties 44 | *.dat 45 | *.psd 46 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing 2 | ============ 3 | ___ 4 | Setting up a Development Environment 5 | ------------------------------------ 6 | Chisel is open-source under the GPL v2 license. As a result, you may contribute to the development of the mod via pull requests. 7 | 8 | To set up the mod as to allow you to make changes, do the following: 9 | 10 | 1. Clone the repository onto your local system. 11 | 2. Open a command prompt from the repository folder. 12 | 3. Run the command `gradlew setupDecompWorkspace` (using `./gradlew` if on Mac/Linux) 13 | 14 | *The next steps vary based on what IDE you wish to use* 15 | 16 | ### IntelliJ IDEA 17 | 1. Run `gradlew idea`. 18 | 2. Open IntelliJ and point to either the project folder or the build.gradle file. 19 | 3. After opening the project in IntelliJ, run `gradlew genIntellijRuns` in the command terminal you opened earlier. 20 | 21 | ### Eclipse 22 | 23 | 1. Run `gradlew eclipse`. 24 | 2. Open Eclipse and import the folder as a project. 25 | 26 | You now have a functional local copy of Chisel, ready to develop on. 27 | 28 | ___ 29 | Formatting 30 | ---------- 31 | 32 | When coding for Chisel 2, please use the provided [formatter settings](eclipseFormat.xml) to format your code. Poorly formatted code, or PRs which reformat existing code will likely not be accepted. 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | 341 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [THIS IS NOT "CTM" WHICH IS REQUIRED BY CHISEL FOR MC 1.10+. CLICK HERE TO GO TO THAT MOD.](https://github.com/Chisel-Team/ConnectedTexturesMod) 2 | 3 | ## CTMLib 4 | Contains the core code Chisel 2 uses for CTM and other texture types. Shipped with Chisel 2. 5 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenCentral() 4 | maven { 5 | name = "forge" 6 | url = "http://files.minecraftforge.net/maven" 7 | } 8 | maven { 9 | name = "sonatype" 10 | url = "https://oss.sonatype.org/content/repositories/snapshots/" 11 | } 12 | } 13 | dependencies { 14 | classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT' 15 | classpath 'org.ajoberstar:gradle-git:0.10.1' 16 | } 17 | 18 | } 19 | plugins { 20 | id 'com.matthewprenger.cursegradle' version '1.0.3' 21 | } 22 | 23 | apply plugin: 'forge' 24 | apply plugin: 'maven-publish' 25 | 26 | compileJava { 27 | options.encoding = 'UTF-8' 28 | } 29 | 30 | import org.ajoberstar.grgit.Grgit 31 | 32 | def repo = Grgit.open(project.file('.')) 33 | project.ext.gitHash = repo.log().find().abbreviatedId 34 | 35 | boolean dev = System.getenv("RELEASE") == null || System.getenv("RELEASE").equalsIgnoreCase("false") 36 | 37 | ext.buildnumber = 0 38 | project.buildnumber = System.getenv('BUILD_NUMBER') == null ? "CUSTOM" : System.getenv('BUILD_NUMBER') 39 | 40 | version = dev ? project.ext.gitHash + "-${buildnumber}" : "MC${minecraft_version}-${mod_version}.${buildnumber}" 41 | group = "team.chisel.ctmlib" // http://maven.apache.org/guides/mini/guide-naming-conventions.html 42 | archivesBaseName = dev ? "CTMLib_DEV" : "CTMLib" 43 | 44 | minecraft { 45 | version = "${minecraft_version}-${forge_version}" 46 | runDir = "run" 47 | 48 | replaceIn "CTMLib.java" 49 | replace "@VERSION@", project.version 50 | } 51 | 52 | repositories { 53 | maven { url = "http://mobiusstrip.eu/maven" } 54 | maven { url = "http://chickenbones.net/maven/" } 55 | maven { url = "http://maven.tterrag.com/" } 56 | } 57 | 58 | dependencies { 59 | compile "team.chisel:Chisel:${chisel_version}:api" 60 | compile "org.projectlombok:lombok:1.16.4" 61 | } 62 | 63 | processResources 64 | { 65 | // this will ensure that this task is redone when the versions change. 66 | inputs.property "version", project.version 67 | inputs.property "mcversion", project.minecraft.version 68 | 69 | // replace stuff in mcmod.info, nothing else 70 | from(sourceSets.main.resources.srcDirs) { 71 | include 'mcmod.info' 72 | 73 | // replace version and mcversion 74 | expand 'version': project.version, 'mcversion': project.minecraft.version 75 | } 76 | 77 | // copy everything else, thats not the mcmod.info 78 | from(sourceSets.main.resources.srcDirs) { 79 | exclude 'mcmod.info' 80 | } 81 | } 82 | 83 | jar { 84 | exclude "com/cricketcraft/chisel/**/*" 85 | } 86 | 87 | // Create deobf dev jars 88 | task deobfJar(type: Jar) { 89 | from sourceSets.main.output 90 | classifier = 'deobf' 91 | } 92 | 93 | // Create source attachment for dev jar 94 | task sourcesJar(type: Jar) { 95 | from sourceSets.main.allJava 96 | classifier = 'sources' 97 | } 98 | 99 | artifacts { 100 | archives deobfJar 101 | archives sourcesJar 102 | } 103 | 104 | publishing { 105 | tasks.publish.dependsOn 'build' 106 | publications { 107 | mavenJava(MavenPublication) { 108 | artifact jar 109 | artifact deobfJar 110 | artifact sourcesJar 111 | } 112 | } 113 | 114 | repositories { 115 | if (project.hasProperty('mavendir')) { 116 | maven { url mavendir } 117 | } 118 | } 119 | } 120 | 121 | println('Changelog:\n' + getChangelogText()) 122 | 123 | 124 | String getChangelogText() { 125 | def changelogFile = file('changelog.txt') 126 | String str = '' 127 | int lineCount = 0 128 | boolean done = false 129 | changelogFile.eachLine { 130 | if (done || it == null) { 131 | return 132 | } 133 | if (it.size() > 1) { 134 | def temp = it 135 | if (lineCount == 0) { 136 | temp = "${archivesBaseName} ${mod_version}.${buildnumber}" 137 | temp = "

$temp

" 138 | } else if (it.trim().startsWith('-')) { 139 | temp = "   $temp" 140 | } else { 141 | temp = "

$temp

" 142 | } 143 | str += "$temp
" 144 | lineCount++ 145 | return 146 | } else { 147 | done = true 148 | } 149 | } 150 | return str 151 | } 152 | 153 | tasks.curseforge.dependsOn 'reobf' 154 | tasks.curseforge.enabled = !dev && project.hasProperty('curseforge_key') 155 | 156 | curseforge { 157 | if (project.hasProperty('curseforge_key')) { 158 | apiKey = project.curseforge_key 159 | } 160 | 161 | project { 162 | id = project.projectId 163 | changelog = System.getenv('CHANGELOG') == null || System.getenv('CHANGELOG').equals('none') ? getChangelogText() : System.getenv('CHANGELOG') 164 | changelogType = 'html' 165 | releaseType = 'release' 166 | mainArtifact(jar) { 167 | displayName = "CTMLib - ${mod_version}.${buildnumber}" 168 | } 169 | addArtifact deobfJar 170 | addArtifact sourcesJar 171 | } 172 | } 173 | 174 | idea { module { inheritOutputDirs = true } } -------------------------------------------------------------------------------- /changelog.txt: -------------------------------------------------------------------------------- 1 | 1.4.1: 2 | Changes 3 | - Call preRenderSide and postRenderSide even when rendering standard block 4 | 5 | 1.4.0: 6 | Changes 7 | - Add ISubmap, which provides getters for height and width (no longer required to be square) 8 | - TextureSubmap implements this 9 | - Add custom crash reporting to CTMRenderer 10 | - Add getters to SubmapManagerCTM for submap and submapSmall 11 | 12 | 1.3.0: 13 | Changes 14 | - Repackage to team.chisel.ctmlib 15 | - Update to latest Chisel API 16 | 17 | 1.0.1: 18 | Changes 19 | - inWorld is now protected in RenderBlocksCTM 20 | Fixes 21 | - Fix blocks not connecting to IFacade 22 | 23 | 1.0.0: 24 | Initial Release -------------------------------------------------------------------------------- /eclipseFormat.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | mod_version=1.4.1 2 | minecraft_version=1.7.10 3 | forge_version=10.13.3.1403-1.7.10 4 | 5 | chisel_version=dev-3.0-c3d27e1-5 6 | waila_version=1.5.10 7 | 8 | projectId=232154 9 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Chisel-Team/CTMLib/4d056f8f26d210fd6d781b9a7e34ebf8ad34dfd9/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Jan 08 23:20:41 CST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-bin.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 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 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /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 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 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 Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'CTMLib' -------------------------------------------------------------------------------- /src/main/java/team/chisel/ctmlib/CTM.java: -------------------------------------------------------------------------------- 1 | package team.chisel.ctmlib; 2 | 3 | import gnu.trove.map.TIntObjectMap; 4 | import gnu.trove.map.hash.TIntObjectHashMap; 5 | 6 | import java.util.EnumMap; 7 | 8 | import net.minecraft.block.Block; 9 | import net.minecraft.world.IBlockAccess; 10 | import net.minecraftforge.common.util.ForgeDirection; 11 | import team.chisel.api.IConnectable; 12 | import team.chisel.api.IFacade; 13 | 14 | import com.google.common.base.Optional; 15 | import com.google.common.collect.Maps; 16 | 17 | import static team.chisel.ctmlib.Dir.*; 18 | 19 | //@formatter:off 20 | /** 21 | * The CTM renderer will draw the block's FACE using by assembling 4 quadrants from the 5 available block 22 | * textures. The normal Texture.png is the blocks "unconnected" texture, and is used when CTM is disabled or the block 23 | * has nothing to connect to. This texture has all of the outside corner quadrants The texture-ctm.png contains the 24 | * rest of the quadrants. 25 | *
26 | * ┌─────────────────┐ ┌────────────────────────────────┐ 27 | * │ texture.png │ │ texture-ctm.png │ 28 | * │ ╔══════╤══════╗ │ │ ──────┼────── ║ ─────┼───── ║ │ 29 | * │ ║ │ ║ │ │ │ │ │║ │ ║ │ 30 | * │ ║ 16 │ 17 ║ │ │ │ 0 │ 1 │║ 2 │ 3 ║ │ 31 | * │ ╟──────┼──────╢ │ │ ┼──────┼──────┼╟──────┼──────╢ │ 32 | * │ ║ │ ║ │ │ │ │ │║ │ ║ │ 33 | * │ ║ 18 │ 19 ║ │ │ │ 4 │ 5 │║ 6 │ 7 ║ │ 34 | * │ ╚══════╧══════╝ │ │ ──────┼────── ║ ─────┼───── ║ │ 35 | * └─────────────────┘ │ ═══════╤═══════╝ ─────┼───── ╚ │ 36 | * │ │ │ ││ │ │ │ 37 | * │ │ 8 │ 9 ││ 10 │ 11 │ │ 38 | * │ ┼──────┼──────┼┼──────┼──────┼ │ 39 | * │ │ │ ││ │ │ │ 40 | * │ │ 12 │ 13 ││ 14 │ 15 │ │ 41 | * │ ═══════╧═══════╗ ─────┼───── ╔ │ 42 | * └────────────────────────────────┘ 43 | *
44 | * combining { 18, 13, 9, 16 }, we can generate a texture connected to the right! 45 | *
46 | * ╔══════╤═══════ 47 | * ║ │ │ 48 | * ║ 16 │ 9 │ 49 | * ╟──────┼──────┼ 50 | * ║ │ │ 51 | * ║ 18 │ 13 │ 52 | * ╚══════╧═══════ 53 | *
54 | * 55 | * combining { 18, 13, 11, 2 }, we can generate a texture, in the shape of an L (connected to the right, and up 56 | *
57 | * ║ ─────┼───── ╚ 58 | * ║ │ │ 59 | * ║ 2 │ 11 │ 60 | * ╟──────┼──────┼ 61 | * ║ │ │ 62 | * ║ 18 │ 13 │ 63 | * ╚══════╧═══════ 64 | *
65 | * 66 | * HAVE FUN! 67 | * -CptRageToaster- 68 | */ 69 | //@formatter:on 70 | public class CTM { 71 | 72 | /** Some hardcoded offset values for the different corner indeces */ 73 | protected static int[] submapOffsets = { 4, 5, 1, 0 }; 74 | /** For use via the Chisel 2 config only, altering this could cause unintended behavior */ 75 | public static boolean disableObscuredFaceCheckConfig = false; 76 | 77 | public Optional disableObscuredFaceCheck = Optional.absent(); 78 | 79 | protected TIntObjectMap submapMap = new TIntObjectHashMap(); 80 | protected EnumMap connectionMap = Maps.newEnumMap(Dir.class); 81 | 82 | protected CTM() { 83 | for (Dir dir : Dir.VALUES) { 84 | connectionMap.put(dir, false); 85 | } 86 | 87 | // Mapping the different corner indeces to their respective dirs 88 | submapMap.put(0, new Dir[] { BOTTOM, LEFT, BOTTOM_LEFT }); 89 | submapMap.put(1, new Dir[] { BOTTOM, RIGHT, BOTTOM_RIGHT }); 90 | submapMap.put(2, new Dir[] { TOP, RIGHT, TOP_RIGHT }); 91 | submapMap.put(3, new Dir[] { TOP, LEFT, TOP_LEFT }); 92 | } 93 | 94 | public static CTM getInstance() { 95 | return new CTM(); 96 | } 97 | 98 | /** 99 | * @return The indeces of the typical 4x4 submap to use for the given face at the given location. 100 | * 101 | * Indeces are in counter-clockwise order starting at bottom left. 102 | */ 103 | public int[] getSubmapIndices(IBlockAccess world, int x, int y, int z, int side) { 104 | int[] ret = new int[] { 18, 19, 17, 16 }; 105 | 106 | if (world == null) { 107 | return ret; 108 | } 109 | 110 | Block block = world.getBlock(x, y, z); 111 | int meta = world.getBlockMetadata(x, y, z); 112 | 113 | buildConnectionMap(world, x, y, z, side, block, meta); 114 | 115 | // Map connections to submap indeces 116 | for (int i = 0; i < 4; i++) { 117 | fillSubmaps(ret, i); 118 | } 119 | 120 | return ret; 121 | } 122 | 123 | /** 124 | * Builds the connection map and stores it in this CTM instance. The {@link #connected(Dir)}, {@link #connectedAnd(Dir...)}, and {@link #connectedOr(Dir...)} methods can be used to access it. 125 | */ 126 | public void buildConnectionMap(IBlockAccess world, int x, int y, int z, int side, Block block, int meta) { 127 | for (Dir dir : Dir.VALUES) { 128 | connectionMap.put(dir, dir.isConnected(this, world, x, y, z, side, block, meta)); 129 | } 130 | } 131 | 132 | private void fillSubmaps(int[] ret, int idx) { 133 | Dir[] dirs = submapMap.get(idx); 134 | if (connectedOr(dirs[0], dirs[1])) { 135 | if (connectedAnd(dirs)) { 136 | // If all dirs are connected, we use the fully connected face, 137 | // the base offset value. 138 | ret[idx] = submapOffsets[idx]; 139 | } else { 140 | // This is a bit magic-y, but basically the array is ordered so 141 | // the first dir requires an offset of 2, and the second dir 142 | // requires an offset of 8, plus the initial offset for the 143 | // corner. 144 | ret[idx] = submapOffsets[idx] + (connected(dirs[0]) ? 2 : 0) + (connected(dirs[1]) ? 8 : 0); 145 | } 146 | } 147 | } 148 | 149 | /** 150 | * @param dir 151 | * The direction to check connection in. 152 | * @return True if the cached connectionMap holds a connection in this {@link Dir direction}. 153 | */ 154 | public boolean connected(Dir dir) { 155 | return connectionMap.get(dir); 156 | } 157 | 158 | /** 159 | * @param dirs 160 | * The directions to check connection in. 161 | * @return True if the cached connectionMap holds a connection in all the given {@link Dir directions}. 162 | */ 163 | public boolean connectedAnd(Dir... dirs) { 164 | for (Dir dir : dirs) { 165 | if (!connected(dir)) { 166 | return false; 167 | } 168 | } 169 | return true; 170 | } 171 | 172 | /** 173 | * @param dirs 174 | * The directions to check connection in. 175 | * @return True if the cached connectionMap holds a connection in one of the given {@link Dir directions}. 176 | */ 177 | private boolean connectedOr(Dir... dirs) { 178 | for (Dir dir : dirs) { 179 | if (connected(dir)) { 180 | return true; 181 | } 182 | } 183 | return false; 184 | } 185 | 186 | /** 187 | * A simple check for if the given block can connect to the given direction on the given side. 188 | * 189 | * @param world 190 | * @param x 191 | * The x coordinate of the block to check against. This is not the position of your block. 192 | * @param y 193 | * The y coordinate of the block to check against. This is not the position of your block. 194 | * @param z 195 | * The z coordinate of the block to check against. This is not the position of your block. 196 | * @param side 197 | * The side of the block to check for connection status. This is not the direction to check in. 198 | * @param block 199 | * The block to check against for connection. 200 | * @param meta 201 | * The metadata to check against for connection. 202 | * @return True if the given block can connect to the given location on the given side. 203 | */ 204 | public boolean isConnected(IBlockAccess world, int x, int y, int z, int side, Block block, int meta) { 205 | ForgeDirection dir = ForgeDirection.VALID_DIRECTIONS[side]; 206 | return isConnected(world, x, y, z, dir, block, meta); 207 | } 208 | 209 | /** 210 | * A simple check for if the given block can connect to the given direction on the given side. 211 | * 212 | * @param world 213 | * @param x 214 | * The x coordinate of the block to check against. This is not the position of your block. 215 | * @param y 216 | * The y coordinate of the block to check against. This is not the position of your block. 217 | * @param z 218 | * The z coordinate of the block to check against. This is not the position of your block. 219 | * @param dir 220 | * The {@link ForgeDirection side} of the block to check for connection status. This is not the direction to check in. 221 | * @param block 222 | * The block to check against for connection. 223 | * @param meta 224 | * The metadata to check against for connection. 225 | * @return True if the given block can connect to the given location on the given side. 226 | */ 227 | public boolean isConnected(IBlockAccess world, int x, int y, int z, ForgeDirection dir, Block block, int meta) { 228 | 229 | if (CTMLib.chiselLoaded() && connectionBlocked(world, x, y, z, dir.ordinal())) { 230 | return false; 231 | } 232 | 233 | int x2 = x + dir.offsetX; 234 | int y2 = y + dir.offsetY; 235 | int z2 = z + dir.offsetZ; 236 | 237 | boolean disableObscured = disableObscuredFaceCheck.or(disableObscuredFaceCheckConfig); 238 | 239 | Block con = getBlockOrFacade(world, x, y, z, dir.ordinal()); 240 | Block obscuring = disableObscured ? null : getBlockOrFacade(world, x2, y2, z2, dir.ordinal()); 241 | 242 | // no block or a bad API user 243 | if (con == null) { 244 | return false; 245 | } 246 | 247 | boolean ret = con.equals(block) && getBlockOrFacadeMetadata(world, x, y, z, dir.ordinal()) == meta; 248 | 249 | // no block obscuring this face 250 | if (obscuring == null) { 251 | return ret; 252 | } 253 | 254 | // check that we aren't already connected outwards from this side 255 | ret &= !(obscuring.equals(block) && getBlockOrFacadeMetadata(world, x2, y2, z2, dir.ordinal()) == meta); 256 | 257 | return ret; 258 | } 259 | 260 | private boolean connectionBlocked(IBlockAccess world, int x, int y, int z, int side) { 261 | Block block = world.getBlock(x, y, z); 262 | if (block instanceof IConnectable) { 263 | return !((IConnectable) block).canConnectCTM(world, x, y, z, side); 264 | } 265 | return false; 266 | } 267 | 268 | /** 269 | * A utility method to access metadata from both the world and {@link IFacade} blocks in the world. 270 | * 271 | * @param world 272 | * @param x 273 | * @param y 274 | * @param z 275 | * @param side 276 | * The side to check for. -1 for unknown. 277 | * @return The metadata at this position in the world, or inside an {@link IFacade} block. 278 | */ 279 | public int getBlockOrFacadeMetadata(IBlockAccess world, int x, int y, int z, int side) { 280 | Block blk = world.getBlock(x, y, z); 281 | if (CTMLib.chiselLoaded()) { 282 | return getFacadeMeta(blk, world, x, y, z, side); 283 | } 284 | return world.getBlockMetadata(x, y, z); 285 | } 286 | 287 | private int getFacadeMeta(Block blk, IBlockAccess world, int x, int y, int z, int side) { 288 | if (blk instanceof IFacade) { 289 | return ((IFacade) blk).getFacadeMetadata(world, x, y, z, side); 290 | } 291 | return world.getBlockMetadata(x, y, z); 292 | } 293 | 294 | /** 295 | * A utility method to access a block from both the world and {@link IFacade} blocks in the world. 296 | * 297 | * @param world 298 | * @param x 299 | * @param y 300 | * @param z 301 | * @param side 302 | * The side to check for. -1 for unknown. 303 | * @return The block at this position in the world, or inside an {@link IFacade} block. 304 | */ 305 | public Block getBlockOrFacade(IBlockAccess world, int x, int y, int z, int side) { 306 | Block blk = world.getBlock(x, y, z); 307 | if (CTMLib.chiselLoaded()) { 308 | return getFacade(blk, world, x, y, z, side); 309 | } 310 | return blk; 311 | } 312 | 313 | private Block getFacade(Block blk, IBlockAccess world, int x, int y, int z, int side) { 314 | if (blk instanceof IFacade) { 315 | blk = ((IFacade) blk).getFacade(world, x, y, z, side); 316 | } 317 | return blk; 318 | } 319 | } -------------------------------------------------------------------------------- /src/main/java/team/chisel/ctmlib/CTMBlock.java: -------------------------------------------------------------------------------- 1 | package team.chisel.ctmlib; 2 | 3 | import lombok.Getter; 4 | import net.minecraft.block.Block; 5 | import net.minecraft.block.material.Material; 6 | import net.minecraft.client.renderer.texture.IIconRegister; 7 | import net.minecraft.util.IIcon; 8 | import net.minecraft.world.IBlockAccess; 9 | import cpw.mods.fml.relauncher.Side; 10 | import cpw.mods.fml.relauncher.SideOnly; 11 | 12 | /** 13 | * Convenience implementation of ICMBlock. This does everything you should need for basic CTM. 14 | *

15 | * This class does not handle metadata-dependent textures. 16 | */ 17 | public class CTMBlock extends Block implements ICTMBlock { 18 | 19 | @SideOnly(Side.CLIENT) 20 | private SubmapManagerCTM manager; 21 | 22 | @Getter 23 | private final String modid; 24 | @Getter 25 | private final String texturePath; 26 | 27 | private final int renderId; 28 | 29 | public CTMBlock(String modid, String texturePath, int renderId) { 30 | super(Material.rock); 31 | this.modid = modid; 32 | this.texturePath = texturePath; 33 | this.renderId = renderId; 34 | } 35 | 36 | @Override 37 | @SideOnly(Side.CLIENT) 38 | public void registerBlockIcons(IIconRegister icon) { 39 | manager = new SubmapManagerCTM(texturePath); 40 | manager.registerIcons(modid, this, icon); 41 | } 42 | 43 | @Override 44 | @SideOnly(Side.CLIENT) 45 | public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) { 46 | return manager.getIcon(world, x, y, z, side); 47 | } 48 | 49 | @Override 50 | @SideOnly(Side.CLIENT) 51 | public IIcon getIcon(int side, int meta) { 52 | return manager.getIcon(side, meta); 53 | } 54 | 55 | @Override 56 | @SideOnly(Side.CLIENT) 57 | public int getRenderType() { 58 | return renderId; 59 | } 60 | 61 | @Override 62 | public ISubmapManager getManager(IBlockAccess world, int x, int y, int z, int meta) { 63 | return manager; 64 | } 65 | 66 | @Override 67 | public ISubmapManager getManager(int meta) { 68 | return manager; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/team/chisel/ctmlib/CTMLib.java: -------------------------------------------------------------------------------- 1 | package team.chisel.ctmlib; 2 | 3 | import cpw.mods.fml.common.ModAPIManager; 4 | 5 | public class CTMLib { 6 | 7 | public static final String VERSION = "@VERSION@"; 8 | 9 | private static boolean chiselPresent, chiselInitialized; 10 | 11 | public static boolean chiselLoaded() { 12 | if (!chiselInitialized) { 13 | chiselInitialized = true; 14 | chiselPresent = ModAPIManager.INSTANCE.hasAPI("ChiselAPI"); 15 | } 16 | return chiselPresent; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/team/chisel/ctmlib/CTMRenderer.java: -------------------------------------------------------------------------------- 1 | package team.chisel.ctmlib; 2 | 3 | import net.minecraft.block.Block; 4 | import net.minecraft.client.Minecraft; 5 | import net.minecraft.client.renderer.RenderBlocks; 6 | import net.minecraft.crash.CrashReport; 7 | import net.minecraft.crash.CrashReportCategory; 8 | import net.minecraft.util.ReportedException; 9 | import net.minecraft.world.IBlockAccess; 10 | 11 | import org.lwjgl.opengl.GL11; 12 | 13 | import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; 14 | import cpw.mods.fml.common.registry.GameRegistry; 15 | 16 | /** 17 | * A convenience base class for CTM blocks. Any block using this must implement {@link ICTMBlock}. 18 | */ 19 | public class CTMRenderer implements ISimpleBlockRenderingHandler { 20 | 21 | private int renderId; 22 | 23 | public CTMRenderer(int renderId) { 24 | this.renderId = renderId; 25 | } 26 | 27 | @Override 28 | public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) { 29 | GL11.glTranslatef(-0.5F, -0.5F, -0.5F); 30 | RenderBlocks rb = getContext(renderer, block, Minecraft.getMinecraft().theWorld, ((ICTMBlock)block).getManager(metadata), metadata); 31 | Drawing.drawBlock(block, metadata, rb); 32 | GL11.glTranslatef(0.5F, 0.5F, 0.5F); 33 | rb.unlockBlockBounds(); 34 | } 35 | 36 | @Override 37 | public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks rendererOld) { 38 | try { 39 | int meta = world.getBlockMetadata(x, y, z); 40 | RenderBlocks rb = getContext(rendererOld, block, world, ((ICTMBlock) block).getManager(world, x, y, z, meta), meta); 41 | boolean ret = rb.renderStandardBlock(block, x, y, z); 42 | rb.unlockBlockBounds(); 43 | return ret; 44 | } catch (Throwable t) { 45 | CrashReport crashreport = CrashReport.makeCrashReport(t, "Rendering CTM Block"); 46 | CrashReportCategory crashreportcategory = crashreport.makeCategory("Block being rendered"); 47 | crashreportcategory.addCrashSection("Block name", GameRegistry.findUniqueIdentifierFor(block)); 48 | crashreportcategory.addCrashSection("Block metadata", world.getBlockMetadata(x, y, z)); 49 | throw new ReportedException(crashreport); 50 | } 51 | } 52 | 53 | protected RenderBlocks getContext(RenderBlocks rendererOld, Block block, IBlockAccess world, ISubmapManager manager, int meta) { 54 | if (!rendererOld.hasOverrideBlockTexture() && manager != null) { 55 | RenderBlocks rb = manager.createRenderContext(rendererOld, block, world); 56 | if (rb != null && rb != rendererOld) { 57 | rb.blockAccess = world; 58 | if (rendererOld.lockBlockBounds) { 59 | rb.overrideBlockBounds(rendererOld.renderMinX, rendererOld.renderMinY, rendererOld.renderMinZ, rendererOld.renderMaxX, rendererOld.renderMaxY, rendererOld.renderMaxZ); 60 | } 61 | if (rb instanceof RenderBlocksCTM) { 62 | RenderBlocksCTM rbctm = (RenderBlocksCTM) rb; 63 | rbctm.manager = rbctm.manager == null ? manager : rbctm.manager; 64 | rbctm.rendererOld = rbctm.rendererOld == null ? rendererOld : rbctm.rendererOld; 65 | } 66 | return rb; 67 | } 68 | } 69 | return rendererOld; 70 | } 71 | 72 | @Override 73 | public boolean shouldRender3DInInventory(int renderId) { 74 | return true; 75 | } 76 | 77 | @Override 78 | public int getRenderId() { 79 | return renderId; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/team/chisel/ctmlib/Dir.java: -------------------------------------------------------------------------------- 1 | package team.chisel.ctmlib; 2 | 3 | import net.minecraft.block.Block; 4 | import net.minecraft.world.IBlockAccess; 5 | import net.minecraftforge.common.util.ForgeDirection; 6 | 7 | import static net.minecraftforge.common.util.ForgeDirection.*; 8 | 9 | /** 10 | * Think of this class as a "Two dimensional ForgeDirection, with diagonals". 11 | *

12 | * It represents the eight different directions a face of a block can connect with CTM, and contains the logic for determining if a block is indeed connected in that direction. 13 | *

14 | * Note that, for example, {@link #TOP_RIGHT} does not mean connected to the {@link #TOP} and {@link #RIGHT}, but connected in the diagonal direction represented by {@link #TOP_RIGHT}. This is used 15 | * for inner corner rendering. 16 | */ 17 | public enum Dir { 18 | // @formatter:off 19 | TOP(UP), 20 | TOP_RIGHT(UP, EAST), 21 | RIGHT(EAST), 22 | BOTTOM_RIGHT(DOWN, EAST), 23 | BOTTOM(DOWN), 24 | BOTTOM_LEFT(DOWN, WEST), 25 | LEFT(WEST), 26 | TOP_LEFT(UP, WEST); 27 | // @formatter:on 28 | 29 | /** 30 | * All values of this enum, used to prevent unnecessary allocation via {@link #values()}. 31 | */ 32 | public static final Dir[] VALUES = values(); 33 | private static final ForgeDirection NORMAL = SOUTH; 34 | 35 | private ForgeDirection[] dirs; 36 | 37 | private Dir(ForgeDirection... dirs) { 38 | this.dirs = dirs; 39 | } 40 | 41 | /** 42 | * Finds if this block is connected for the given side in this Dir. 43 | * 44 | * @param inst 45 | * The CTM instance to use for logic. 46 | * @param world 47 | * The world the block is in. 48 | * @param x 49 | * The x coordinate of your block. 50 | * @param y 51 | * The y coordinate of your block. 52 | * @param z 53 | * The z coordinate of your block. 54 | * @param sideIdx 55 | * The side index of the current face. This equivalent to {@link ForgeDirection#ordinal()} 56 | * @param block 57 | * The block being rendered. 58 | * @param meta 59 | * The metadata of the block. 60 | * @return True if the block is connected in the given Dir, false otherwise. 61 | */ 62 | public boolean isConnected(CTM inst, IBlockAccess world, int x, int y, int z, int sideIdx, Block block, int meta) { 63 | ForgeDirection side = getOrientation(sideIdx); 64 | ForgeDirection[] dirs = getNormalizedDirs(side); 65 | for (ForgeDirection dir : dirs) { 66 | x += dir.offsetX; 67 | y += dir.offsetY; 68 | z += dir.offsetZ; 69 | } 70 | return inst.isConnected(world, x, y, z, side, block, meta); 71 | } 72 | 73 | private ForgeDirection[] getNormalizedDirs(ForgeDirection normal) { 74 | if (normal == NORMAL) { 75 | return dirs; 76 | } else if (normal == NORMAL.getOpposite()) { 77 | // If this is the opposite direction of the default normal, we 78 | // need to mirror the dirs 79 | // A mirror version does not affect y+ and y- so we ignore those 80 | ForgeDirection[] ret = new ForgeDirection[dirs.length]; 81 | for (int i = 0; i < ret.length; i++) { 82 | ret[i] = dirs[i].offsetY != 0 ? dirs[i] : dirs[i].getOpposite(); 83 | } 84 | return ret; 85 | } else { 86 | ForgeDirection axis = null; 87 | // Next, we need different a different rotation axis depending 88 | // on if this is up/down or not 89 | if (normal.offsetY == 0) { 90 | // If it is not up/down, pick either the left or right-hand 91 | // rotation 92 | axis = normal == NORMAL.getRotation(UP) ? UP : DOWN; 93 | } else { 94 | // If it is up/down, pick either the up or down rotation. 95 | axis = normal == UP ? NORMAL.getRotation(DOWN) : NORMAL.getRotation(UP); 96 | } 97 | ForgeDirection[] ret = new ForgeDirection[dirs.length]; 98 | // Finally apply all the rotations 99 | for (int i = 0; i < ret.length; i++) { 100 | ret[i] = dirs[i].getRotation(axis); 101 | } 102 | return ret; 103 | } 104 | } 105 | } -------------------------------------------------------------------------------- /src/main/java/team/chisel/ctmlib/Drawing.java: -------------------------------------------------------------------------------- 1 | package team.chisel.ctmlib; 2 | 3 | import net.minecraft.block.Block; 4 | import net.minecraft.client.renderer.RenderBlocks; 5 | import net.minecraft.client.renderer.Tessellator; 6 | import net.minecraft.util.IIcon; 7 | 8 | public class Drawing { 9 | 10 | public static void drawBlock(Block block, IIcon icon, RenderBlocks renderer) { 11 | Tessellator tessellator = Tessellator.instance; 12 | 13 | tessellator.startDrawingQuads(); 14 | tessellator.setNormal(0.0F, -1.0F, 0.0F); 15 | renderer.renderFaceYNeg(block, 0.0D, 0.0D, 0.0D, icon); 16 | tessellator.draw(); 17 | tessellator.startDrawingQuads(); 18 | tessellator.setNormal(0.0F, 1.0F, 0.0F); 19 | renderer.renderFaceYPos(block, 0.0D, 0.0D, 0.0D, icon); 20 | tessellator.draw(); 21 | tessellator.startDrawingQuads(); 22 | tessellator.setNormal(0.0F, 0.0F, -1.0F); 23 | renderer.renderFaceZNeg(block, 0.0D, 0.0D, 0.0D, icon); 24 | tessellator.draw(); 25 | tessellator.startDrawingQuads(); 26 | tessellator.setNormal(0.0F, 0.0F, 1.0F); 27 | renderer.renderFaceZPos(block, 0.0D, 0.0D, 0.0D, icon); 28 | tessellator.draw(); 29 | tessellator.startDrawingQuads(); 30 | tessellator.setNormal(-1.0F, 0.0F, 0.0F); 31 | renderer.renderFaceXNeg(block, 0.0D, 0.0D, 0.0D, icon); 32 | tessellator.draw(); 33 | tessellator.startDrawingQuads(); 34 | tessellator.setNormal(1.0F, 0.0F, 0.0F); 35 | renderer.renderFaceXPos(block, 0.0D, 0.0D, 0.0D, icon); 36 | tessellator.draw(); 37 | } 38 | 39 | public static void drawBlock(Block block, int meta, RenderBlocks renderer) { 40 | Tessellator tessellator = Tessellator.instance; 41 | 42 | tessellator.startDrawingQuads(); 43 | tessellator.setNormal(0.0F, -1.0F, 0.0F); 44 | renderer.renderFaceYNeg(block, 0.0D, 0.0D, 0.0D, block.getIcon(0, meta)); 45 | tessellator.draw(); 46 | tessellator.startDrawingQuads(); 47 | tessellator.setNormal(0.0F, 1.0F, 0.0F); 48 | renderer.renderFaceYPos(block, 0.0D, 0.0D, 0.0D, block.getIcon(1, meta)); 49 | tessellator.draw(); 50 | tessellator.startDrawingQuads(); 51 | tessellator.setNormal(0.0F, 0.0F, -1.0F); 52 | renderer.renderFaceZNeg(block, 0.0D, 0.0D, 0.0D, block.getIcon(2, meta)); 53 | tessellator.draw(); 54 | tessellator.startDrawingQuads(); 55 | tessellator.setNormal(0.0F, 0.0F, 1.0F); 56 | renderer.renderFaceZPos(block, 0.0D, 0.0D, 0.0D, block.getIcon(3, meta)); 57 | tessellator.draw(); 58 | tessellator.startDrawingQuads(); 59 | tessellator.setNormal(-1.0F, 0.0F, 0.0F); 60 | renderer.renderFaceXNeg(block, 0.0D, 0.0D, 0.0D, block.getIcon(4, meta)); 61 | tessellator.draw(); 62 | tessellator.startDrawingQuads(); 63 | tessellator.setNormal(1.0F, 0.0F, 0.0F); 64 | renderer.renderFaceXPos(block, 0.0D, 0.0D, 0.0D, block.getIcon(5, meta)); 65 | tessellator.draw(); 66 | } 67 | 68 | public static void renderAllFaces(RenderBlocks renderer, Block block, int x, int y, int z, IIcon icon) { 69 | renderer.renderFaceYNeg(block, x, y, z, icon); 70 | renderer.renderFaceYPos(block, x, y, z, icon); 71 | renderer.renderFaceZNeg(block, x, y, z, icon); 72 | renderer.renderFaceZPos(block, x, y, z, icon); 73 | renderer.renderFaceXNeg(block, x, y, z, icon); 74 | renderer.renderFaceXPos(block, x, y, z, icon); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/team/chisel/ctmlib/ICTMBlock.java: -------------------------------------------------------------------------------- 1 | package team.chisel.ctmlib; 2 | 3 | import net.minecraft.world.IBlockAccess; 4 | 5 | public interface ICTMBlock { 6 | 7 | /** 8 | * Gets the {@link ISubmapManager} for this block in the world. 9 | */ 10 | T getManager(IBlockAccess world, int x, int y, int z, int meta); 11 | 12 | /** 13 | * Gets the {@link ISubmapManager} for this block in item form. 14 | * 15 | * @param meta 16 | * The meta (damage) of the stack. 17 | */ 18 | T getManager(int meta); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/team/chisel/ctmlib/ISubmap.java: -------------------------------------------------------------------------------- 1 | package team.chisel.ctmlib; 2 | 3 | import net.minecraft.util.IIcon; 4 | 5 | public interface ISubmap { 6 | 7 | /** 8 | * The width, in icons, of the submap. 9 | */ 10 | int getWidth(); 11 | 12 | /** 13 | * The height, in icons, of the submap. 14 | */ 15 | int getHeight(); 16 | 17 | IIcon getSubIcon(int x, int y); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/team/chisel/ctmlib/ISubmapManager.java: -------------------------------------------------------------------------------- 1 | package team.chisel.ctmlib; 2 | 3 | import cpw.mods.fml.relauncher.Side; 4 | import cpw.mods.fml.relauncher.SideOnly; 5 | import net.minecraft.block.Block; 6 | import net.minecraft.client.renderer.RenderBlocks; 7 | import net.minecraft.client.renderer.texture.IIconRegister; 8 | import net.minecraft.util.IIcon; 9 | import net.minecraft.world.IBlockAccess; 10 | import net.minecraftforge.common.util.ForgeDirection; 11 | 12 | public interface ISubmapManager { 13 | 14 | /** 15 | * Gets the icon for item rendering, based on side and item metadata. 16 | * 17 | * @param side 18 | * Side of the ItemBlock. 19 | * @param meta 20 | * Metadata of the ItemBlock. 21 | * @return The IIcon for rendering. 22 | */ 23 | IIcon getIcon(int side, int meta); 24 | 25 | /** 26 | * Gets the icon for world rendering, based on world position and side. 27 | */ 28 | IIcon getIcon(IBlockAccess world, int x, int y, int z, int side); 29 | 30 | /** 31 | * Hook for registering any custom icons you might need in this class. Will be called during the normal block method. 32 | * 33 | * @param modName 34 | * The mod ID this submap was registered to. 35 | * @param block 36 | * The block being registered for. 37 | * @param register 38 | * The IIconRegister instance. 39 | */ 40 | @SideOnly(Side.CLIENT) 41 | void registerIcons(String modName, Block block, IIconRegister register); 42 | 43 | @SideOnly(Side.CLIENT) 44 | RenderBlocks createRenderContext(RenderBlocks rendererOld, Block block, IBlockAccess world); 45 | 46 | @SideOnly(Side.CLIENT) 47 | void preRenderSide(RenderBlocks renderer, IBlockAccess world, int x, int y, int z, ForgeDirection side); 48 | 49 | @SideOnly(Side.CLIENT) 50 | void postRenderSide(RenderBlocks renderer, IBlockAccess world, int x, int y, int z, ForgeDirection side); 51 | } -------------------------------------------------------------------------------- /src/main/java/team/chisel/ctmlib/RenderBlocksCTM.java: -------------------------------------------------------------------------------- 1 | package team.chisel.ctmlib; 2 | 3 | import static team.chisel.ctmlib.RenderBlocksCTM.SubSide.*; 4 | import static team.chisel.ctmlib.RenderBlocksCTM.Vert.*; 5 | 6 | import lombok.Getter; 7 | import net.minecraft.block.Block; 8 | import net.minecraft.client.Minecraft; 9 | import net.minecraft.client.renderer.RenderBlocks; 10 | import net.minecraft.client.renderer.Tessellator; 11 | import net.minecraft.util.IIcon; 12 | import net.minecraftforge.common.util.ForgeDirection; 13 | 14 | public class RenderBlocksCTM extends RenderBlocks { 15 | 16 | /** 17 | * An enum for all possible 26 sub-side vertices. 18 | * 19 | * The naming scheme is as follows: 20 | * 21 | * ZERO is a special case, it is the absolute min point of the block. X, Y, Z, or any combination means that the axes listed in the name are at 1. X, Y, Z, or any combination followed by HALF 22 | * means that those axes are at 0.5. X, Y, Z, or any combination after a HALF means those axes are at 1. 23 | */ 24 | protected enum Vert { 25 | // @formatter:off 26 | ZERO(0, 0, 0), 27 | XYZ(1, 1, 1), 28 | X(1, 0, 0), 29 | Y(0, 1, 0), 30 | Z(0, 0, 1), 31 | XY(1, 1, 0), 32 | YZ(0, 1, 1), 33 | XZ(1, 0, 1), 34 | X_HALF(0.5, 0, 0), 35 | Y_HALF(0, 0.5, 0), 36 | Z_HALF(0, 0, 0.5), 37 | XY_HALF(0.5, 0.5, 0), 38 | YZ_HALF(0, 0.5, 0.5), 39 | XZ_HALF(0.5, 0, 0.5), 40 | X_HALF_Y(0.5, 1, 0), 41 | X_HALF_Z(0.5, 0, 1), 42 | Y_HALF_X(1, 0.5, 0), 43 | Y_HALF_Z(0, 0.5, 1), 44 | Z_HALF_X(1, 0, 0.5), 45 | Z_HALF_Y(0, 1, 0.5), 46 | X_HALF_YZ(0.5, 1, 1), 47 | Y_HALF_XZ(1, 0.5, 1), 48 | Z_HALF_XY(1, 1, 0.5), 49 | XY_HALF_Z(0.5, 0.5, 1), 50 | YZ_HALF_X(1, 0.5, 0.5), 51 | XZ_HALF_Y(0.5, 1, 0.5); 52 | // @formatter:on 53 | 54 | private double x, y, z; 55 | 56 | private Vert(double x, double y, double z) { 57 | this.x = x; 58 | this.y = y; 59 | this.z = z; 60 | } 61 | 62 | private static double u, v, xDiff, yDiff, zDiff, uDiff, vDiff; 63 | 64 | void render(RenderBlocksCTM inst, ForgeDirection normal, int cacheID) { 65 | if (inst.enableAO) { 66 | inst.tessellator.setColorOpaque_F(inst.redCache[cacheID], inst.grnCache[cacheID], inst.bluCache[cacheID]); 67 | inst.tessellator.setBrightness(inst.lightingCache[cacheID]); 68 | } 69 | 70 | u = cacheID == 1 || cacheID == 2 ? inst.maxU : inst.minU; 71 | v = cacheID < 2 ? inst.maxV : inst.minV; 72 | 73 | uDiff = inst.maxU - inst.minU; 74 | vDiff = inst.maxV - inst.minV; 75 | 76 | if (inst.renderMinX + inst.renderMinY + inst.renderMinZ != 0 || inst.renderMaxX + inst.renderMaxY + inst.renderMaxZ != 3) { 77 | boolean uMin = u == inst.minU; 78 | boolean vMin = v == inst.minV; 79 | 80 | xDiff = inst.renderMaxX - inst.renderMinX; 81 | yDiff = inst.renderMaxY - inst.renderMinY; 82 | zDiff = inst.renderMaxZ - inst.renderMinZ; 83 | 84 | if (normal.offsetY != 0) { 85 | uDiff *= uMin ? inst.renderMinX : 1 - inst.renderMaxX; 86 | vDiff *= vMin ? inst.renderMinZ : 1 - inst.renderMaxZ; 87 | } else if (normal.offsetX != 0) { 88 | uDiff *= uMin ? inst.renderMinZ : 1 - inst.renderMaxZ; 89 | vDiff *= vMin ? inst.renderMinY : 1 - inst.renderMaxY; 90 | } else if (normal.offsetZ != 0) { 91 | uDiff *= uMin ? inst.renderMinX : 1 - inst.renderMaxX; 92 | vDiff *= vMin ? inst.renderMinY : 1 - inst.renderMaxY; 93 | } 94 | u = u == inst.minU ? inst.minU + uDiff : inst.maxU - uDiff; 95 | 96 | v = v == inst.minV ? inst.minV + vDiff : inst.maxV - vDiff; 97 | } else { 98 | xDiff = yDiff = zDiff = 1; 99 | } 100 | 101 | inst.tessellator.addVertexWithUV(inst.renderMinX + (x * xDiff), inst.renderMinY + (y * yDiff), inst.renderMinZ + (z * zDiff), u, v); 102 | } 103 | } 104 | 105 | /** 106 | * Each side is divided into 4 sub-sides. LB(left bottom), RB(right bottom), LT(right top), and RT(right top). 107 | * 108 | * Each sub-side contains 4 {@link Vert} objects representing its position on the block. 109 | */ 110 | protected enum SubSide { 111 | // @formatter:off 112 | XNEG_LB(ZERO, Z_HALF, YZ_HALF, Y_HALF), XNEG_RB(Z_HALF, Z, Y_HALF_Z, YZ_HALF), XNEG_RT(YZ_HALF, Y_HALF_Z, YZ, Z_HALF_Y), XNEG_LT(Y_HALF, YZ_HALF, Z_HALF_Y, Y), 113 | XPOS_LB(XZ, Z_HALF_X, YZ_HALF_X, Y_HALF_XZ), XPOS_RB(Z_HALF_X, X, Y_HALF_X, YZ_HALF_X), XPOS_RT(YZ_HALF_X, Y_HALF_X, XY, Z_HALF_XY), XPOS_LT(Y_HALF_XZ, YZ_HALF_X, Z_HALF_XY, XYZ), 114 | 115 | ZNEG_LB(X, X_HALF, XY_HALF, Y_HALF_X), ZNEG_RB(X_HALF, ZERO, Y_HALF, XY_HALF), ZNEG_RT(XY_HALF, Y_HALF, Y, X_HALF_Y), ZNEG_LT(Y_HALF_X, XY_HALF, X_HALF_Y, XY), 116 | ZPOS_LB(Z, X_HALF_Z, XY_HALF_Z, Y_HALF_Z), ZPOS_RB(X_HALF_Z, XZ, Y_HALF_XZ, XY_HALF_Z), ZPOS_RT(XY_HALF_Z, Y_HALF_XZ, XYZ, X_HALF_YZ), ZPOS_LT(Y_HALF_Z, XY_HALF_Z, X_HALF_YZ, YZ), 117 | 118 | YNEG_LB(ZERO, X_HALF, XZ_HALF, Z_HALF), YNEG_RB(X_HALF, X, Z_HALF_X, XZ_HALF), YNEG_RT(XZ_HALF, Z_HALF_X, XZ, X_HALF_Z), YNEG_LT(Z_HALF, XZ_HALF, X_HALF_Z, Z), 119 | YPOS_LB(YZ, X_HALF_YZ, XZ_HALF_Y, Z_HALF_Y), YPOS_RB(X_HALF_YZ, XYZ, Z_HALF_XY, XZ_HALF_Y), YPOS_RT(XZ_HALF_Y, Z_HALF_XY, XY, X_HALF_Y), YPOS_LT(Z_HALF_Y, XZ_HALF_Y, X_HALF_Y, Y); 120 | // @formatter:on 121 | private Vert xmin, xmax, ymin, ymax; 122 | private ForgeDirection normal; 123 | 124 | SubSide(Vert xmin, Vert ymin, Vert ymax, Vert xmax) { 125 | this.xmin = xmin; 126 | this.ymin = ymin; 127 | this.ymax = ymax; 128 | this.xmax = xmax; 129 | this.normal = calcNormal(); 130 | } 131 | 132 | private ForgeDirection calcNormal() { 133 | double xTot = xmin.x + xmax.x + ymin.x + ymax.x; 134 | double yTot = xmin.y + xmax.y + ymin.y + ymax.y; 135 | double zTot = xmin.z + xmax.z + ymin.z + ymax.z; 136 | if (xTot % 4 == 0) { 137 | return xTot > 0 ? ForgeDirection.EAST : ForgeDirection.WEST; 138 | } else if (yTot % 4 == 0) { 139 | return yTot > 0 ? ForgeDirection.UP : ForgeDirection.DOWN; 140 | } else if (zTot % 4 == 0) { 141 | return zTot > 0 ? ForgeDirection.SOUTH : ForgeDirection.NORTH; 142 | } 143 | return ForgeDirection.UNKNOWN; 144 | } 145 | 146 | void render(RenderBlocksCTM inst) { 147 | xmin.render(inst, normal, 0); 148 | ymin.render(inst, normal, 1); 149 | ymax.render(inst, normal, 2); 150 | xmax.render(inst, normal, 3); 151 | } 152 | } 153 | 154 | public CTM ctm = CTM.getInstance(); 155 | 156 | // globals added to save the JVM some trouble. No need to constantly create 157 | // and destroy ints if we don't have to 158 | protected int blockLightBitChannel = 0; 159 | protected int redBitChannel = 0; 160 | protected int greenBitChannel = 0; 161 | protected int blueBitChannel = 0; 162 | protected int sunlightBitChannel = 0; 163 | 164 | public RenderBlocksCTM() { 165 | super(); 166 | renderMaxX = renderMaxY = renderMaxZ = 1; 167 | } 168 | 169 | protected Tessellator tessellator = Tessellator.instance; 170 | protected double minU, maxU; 171 | protected double minV, maxV; 172 | protected int[] lightingCache = new int[4]; 173 | protected float[] redCache = new float[4]; 174 | protected float[] grnCache = new float[4]; 175 | protected float[] bluCache = new float[4]; 176 | public TextureSubmap submap; 177 | public TextureSubmap submapSmall; 178 | public RenderBlocks rendererOld; 179 | public ISubmapManager manager; 180 | 181 | protected int[][] lightmap = new int[3][3]; 182 | protected float[][] redmap = new float[3][3]; 183 | protected float[][] grnmap = new float[3][3]; 184 | protected float[][] blumap = new float[3][3]; 185 | 186 | protected int bx, by, bz, meta; 187 | 188 | @Getter 189 | protected boolean inWorld = false; 190 | 191 | @Override 192 | public boolean renderStandardBlock(Block block, int x, int y, int z) { 193 | bx = x; 194 | by = y; 195 | bz = z; 196 | meta = Minecraft.getMinecraft().theWorld.getBlockMetadata(x, y, z); 197 | 198 | tessellator.setColorOpaque_F(1.0F, 1.0F, 1.0F); 199 | tessellator.addTranslation(x, y, z); 200 | if (rendererOld != null && rendererOld.hasOverrideBlockTexture()) { 201 | setOverrideBlockTexture(rendererOld.overrideBlockTexture); 202 | } 203 | inWorld = true; 204 | boolean res = super.renderStandardBlock(block, x, y, z); 205 | inWorld = false; 206 | tessellator.addTranslation(-x, -y, -z); 207 | 208 | return res; 209 | } 210 | 211 | /* @formatter:off 212 | * This method fills a 3x3 grid of light values based on the four corners, by averaging them together. 213 | * 214 | * 2 TL x TR 215 | * 216 | * 1 x x x 217 | * 218 | * 0 BL x BR 219 | * 0 1 2 220 | * 221 | * Note: Variable names mean nothing... don't touch 222 | * 223 | * ._. 224 | * 225 | * shakes fist in anger 226 | */ 227 | // @formatter:on 228 | protected void fillLightmap(int bottomLeft, int bottomRight, int topRight, int topLeft) { 229 | lightmap[0][0] = bottomLeft; 230 | lightmap[2][0] = bottomRight; 231 | lightmap[2][2] = topRight; 232 | lightmap[0][2] = topLeft; 233 | 234 | lightmap[1][0] = avg(bottomLeft, bottomRight); 235 | lightmap[2][1] = avg(bottomRight, topRight); 236 | lightmap[1][2] = avg(topRight, topLeft); 237 | lightmap[0][1] = avg(topLeft, bottomLeft); 238 | 239 | lightmap[1][1] = avg(bottomLeft, bottomRight, topRight, topLeft); 240 | } 241 | 242 | protected void fillColormap(float bottomLeft, float bottomRight, float topRight, float topLeft, float[][] map) { 243 | map[0][0] = bottomLeft; 244 | map[2][0] = bottomRight; 245 | map[2][2] = topRight; 246 | map[0][2] = topLeft; 247 | 248 | map[1][0] = (bottomLeft + bottomRight) / 2.0F; 249 | map[2][1] = (bottomRight + topRight) / 2.0F; 250 | map[1][2] = (topRight + topLeft) / 2.0F; 251 | map[0][1] = (topLeft + bottomLeft) / 2.0F; 252 | 253 | map[1][1] = (bottomLeft + bottomRight + topRight + topLeft) / 4.0F; 254 | } 255 | 256 | protected void getLight(int x, int y) { 257 | lightingCache[0] = lightmap[0 + x][0 + y]; 258 | lightingCache[1] = lightmap[1 + x][0 + y]; 259 | lightingCache[2] = lightmap[1 + x][1 + y]; 260 | lightingCache[3] = lightmap[0 + x][1 + y]; 261 | 262 | redCache[0] = redmap[0 + x][0 + y]; 263 | redCache[1] = redmap[1 + x][0 + y]; 264 | redCache[2] = redmap[1 + x][1 + y]; 265 | redCache[3] = redmap[0 + x][1 + y]; 266 | 267 | grnCache[0] = grnmap[0 + x][0 + y]; 268 | grnCache[1] = grnmap[1 + x][0 + y]; 269 | grnCache[2] = grnmap[1 + x][1 + y]; 270 | grnCache[3] = grnmap[0 + x][1 + y]; 271 | 272 | bluCache[0] = blumap[0 + x][0 + y]; 273 | bluCache[1] = blumap[1 + x][0 + y]; 274 | bluCache[2] = blumap[1 + x][1 + y]; 275 | bluCache[3] = blumap[0 + x][1 + y]; 276 | } 277 | 278 | /** 279 | * This works around a bug in CLC atm 280 | */ 281 | private int avg(int... lightVals) { 282 | blockLightBitChannel = 0; 283 | redBitChannel = 0; 284 | greenBitChannel = 0; 285 | blueBitChannel = 0; 286 | sunlightBitChannel = 0; 287 | 288 | for (int light : lightVals) { 289 | blockLightBitChannel += (light & 0xFF); 290 | redBitChannel += (light & 0xF00); 291 | greenBitChannel += (light & 0xF000); 292 | blueBitChannel += (light & 0xF0000); 293 | sunlightBitChannel += (light & 0xF00000); 294 | } 295 | 296 | return ((blockLightBitChannel / lightVals.length) & 0xFF) | ((redBitChannel / lightVals.length) & 0xF00) | ((greenBitChannel / lightVals.length) & 0xF000) 297 | | ((blueBitChannel / lightVals.length) & 0xF0000) | ((sunlightBitChannel / lightVals.length) & 0xF00000); 298 | } 299 | 300 | protected void side(Block block, SubSide side, int iconIndex) { 301 | 302 | IIcon icon; 303 | TextureSubmap map; 304 | if (iconIndex >= 16) { 305 | iconIndex -= 16; 306 | map = submapSmall; 307 | } else { 308 | map = submap; 309 | } 310 | 311 | if (map == null) { 312 | icon = getBlockIconFromSideAndMetadata(block, side.normal.ordinal(), meta); 313 | } else { 314 | int x = iconIndex % map.getWidth(); 315 | int y = iconIndex / map.getHeight(); 316 | icon = map.getSubIcon(x, y); 317 | } 318 | 319 | double umax = icon.getMaxU(); 320 | double umin = icon.getMinU(); 321 | double vmax = icon.getMaxV(); 322 | double vmin = icon.getMinV(); 323 | 324 | minU = umin; 325 | maxU = umax; 326 | minV = vmin; 327 | maxV = vmax; 328 | 329 | // uCache[0] = umin; 330 | // uCache[1] = umax; 331 | // uCache[2] = umax; 332 | // uCache[3] = umin; 333 | // 334 | // vCache[0] = vmax; 335 | // vCache[1] = vmax; 336 | // vCache[2] = vmin; 337 | // vCache[3] = vmin; 338 | 339 | side.render(this); 340 | } 341 | 342 | @Override 343 | public void renderFaceXNeg(Block block, double x, double y, double z, IIcon icon) { 344 | pre(ForgeDirection.WEST); 345 | if (!inWorld || hasOverrideBlockTexture() || submap == null) { 346 | super.renderFaceXNeg(block, 0, 0, 0, icon); 347 | } else { 348 | int tex[] = ctm.getSubmapIndices(blockAccess, bx, by, bz, 4); 349 | 350 | fillLightmap(brightnessBottomRight, brightnessTopRight, brightnessTopLeft, brightnessBottomLeft); 351 | fillColormap(colorRedBottomRight, colorRedTopRight, colorRedTopLeft, colorRedBottomLeft, redmap); 352 | fillColormap(colorGreenBottomRight, colorGreenTopRight, colorGreenTopLeft, colorGreenBottomLeft, grnmap); 353 | fillColormap(colorBlueBottomRight, colorBlueTopRight, colorBlueTopLeft, colorBlueBottomLeft, blumap); 354 | 355 | getLight(0, 0); 356 | side(block, XNEG_LB, tex[0]); 357 | getLight(1, 0); 358 | side(block, XNEG_RB, tex[1]); 359 | getLight(1, 1); 360 | side(block, XNEG_RT, tex[2]); 361 | getLight(0, 1); 362 | side(block, XNEG_LT, tex[3]); 363 | } 364 | post(ForgeDirection.WEST); 365 | } 366 | 367 | @Override 368 | public void renderFaceXPos(Block block, double x, double y, double z, IIcon icon) { 369 | pre(ForgeDirection.EAST); 370 | if (!inWorld || hasOverrideBlockTexture() || submap == null) { 371 | super.renderFaceXPos(block, 0, 0, 0, icon); 372 | } else { 373 | int tex[] = ctm.getSubmapIndices(blockAccess, bx, by, bz, 5); 374 | 375 | fillLightmap(brightnessTopLeft, brightnessBottomLeft, brightnessBottomRight, brightnessTopRight); 376 | fillColormap(colorRedTopLeft, colorRedBottomLeft, colorRedBottomRight, colorRedTopRight, redmap); 377 | fillColormap(colorGreenTopLeft, colorGreenBottomLeft, colorGreenBottomRight, colorGreenTopRight, grnmap); 378 | fillColormap(colorBlueTopLeft, colorBlueBottomLeft, colorBlueBottomRight, colorBlueTopRight, blumap); 379 | 380 | getLight(0, 0); 381 | side(block, XPOS_LB, tex[0]); 382 | getLight(1, 0); 383 | side(block, XPOS_RB, tex[1]); 384 | getLight(1, 1); 385 | side(block, XPOS_RT, tex[2]); 386 | getLight(0, 1); 387 | side(block, XPOS_LT, tex[3]); 388 | } 389 | post(ForgeDirection.EAST); 390 | } 391 | 392 | @Override 393 | public void renderFaceZNeg(Block block, double x, double y, double z, IIcon icon) { 394 | pre(ForgeDirection.NORTH); 395 | if (!inWorld || hasOverrideBlockTexture() || submap == null) { 396 | super.renderFaceZNeg(block, 0, 0, 0, icon); 397 | } else { 398 | int tex[] = ctm.getSubmapIndices(blockAccess, bx, by, bz, 2); 399 | 400 | fillLightmap(brightnessBottomRight, brightnessTopRight, brightnessTopLeft, brightnessBottomLeft); 401 | fillColormap(colorRedBottomRight, colorRedTopRight, colorRedTopLeft, colorRedBottomLeft, redmap); 402 | fillColormap(colorGreenBottomRight, colorGreenTopRight, colorGreenTopLeft, colorGreenBottomLeft, grnmap); 403 | fillColormap(colorBlueBottomRight, colorBlueTopRight, colorBlueTopLeft, colorBlueBottomLeft, blumap); 404 | 405 | getLight(0, 0); 406 | side(block, ZNEG_LB, tex[0]); 407 | getLight(1, 0); 408 | side(block, ZNEG_RB, tex[1]); 409 | getLight(1, 1); 410 | side(block, ZNEG_RT, tex[2]); 411 | getLight(0, 1); 412 | side(block, ZNEG_LT, tex[3]); 413 | } 414 | post(ForgeDirection.NORTH); 415 | } 416 | 417 | @Override 418 | public void renderFaceZPos(Block block, double x, double y, double z, IIcon icon) { 419 | pre(ForgeDirection.SOUTH); 420 | if (!inWorld || hasOverrideBlockTexture() || submap == null) { 421 | super.renderFaceZPos(block, 0, 0, 0, icon); 422 | } else { 423 | int tex[] = ctm.getSubmapIndices(blockAccess, bx, by, bz, 3); 424 | 425 | 426 | fillLightmap(brightnessBottomLeft, brightnessBottomRight, brightnessTopRight, brightnessTopLeft); 427 | fillColormap(colorRedBottomLeft, colorRedBottomRight, colorRedTopRight, colorRedTopLeft, redmap); 428 | fillColormap(colorGreenBottomLeft, colorGreenBottomRight, colorGreenTopRight, colorGreenTopLeft, grnmap); 429 | fillColormap(colorBlueBottomLeft, colorBlueBottomRight, colorBlueTopRight, colorBlueTopLeft, blumap); 430 | 431 | getLight(0, 0); 432 | side(block, ZPOS_LB, tex[0]); 433 | getLight(1, 0); 434 | side(block, ZPOS_RB, tex[1]); 435 | getLight(1, 1); 436 | side(block, ZPOS_RT, tex[2]); 437 | getLight(0, 1); 438 | side(block, ZPOS_LT, tex[3]); 439 | } 440 | post(ForgeDirection.SOUTH); 441 | } 442 | 443 | @Override 444 | public void renderFaceYNeg(Block block, double x, double y, double z, IIcon icon) { 445 | pre(ForgeDirection.DOWN); 446 | if (!inWorld || hasOverrideBlockTexture() || submap == null) { 447 | super.renderFaceYNeg(block, 0, 0, 0, icon); 448 | } else { 449 | int tex[] = ctm.getSubmapIndices(blockAccess, bx, by, bz, 0); 450 | 451 | fillLightmap(brightnessBottomLeft, brightnessBottomRight, brightnessTopRight, brightnessTopLeft); 452 | fillColormap(colorRedBottomLeft, colorRedBottomRight, colorRedTopRight, colorRedTopLeft, redmap); 453 | fillColormap(colorGreenBottomLeft, colorGreenBottomRight, colorGreenTopRight, colorGreenTopLeft, grnmap); 454 | fillColormap(colorBlueBottomLeft, colorBlueBottomRight, colorBlueTopRight, colorBlueTopLeft, blumap); 455 | 456 | getLight(0, 0); 457 | side(block, YNEG_LB, tex[0]); 458 | getLight(1, 0); 459 | side(block, YNEG_RB, tex[1]); 460 | getLight(1, 1); 461 | side(block, YNEG_RT, tex[2]); 462 | getLight(0, 1); 463 | side(block, YNEG_LT, tex[3]); 464 | } 465 | post(ForgeDirection.DOWN); 466 | } 467 | 468 | @Override 469 | public void renderFaceYPos(Block block, double x, double y, double z, IIcon icon) { 470 | pre(ForgeDirection.UP); 471 | if (!inWorld || hasOverrideBlockTexture() || submap == null) { 472 | super.renderFaceYPos(block, 0, 0, 0, icon); 473 | } else { 474 | int tex[] = ctm.getSubmapIndices(blockAccess, bx, by, bz, 1); 475 | 476 | fillLightmap(brightnessTopRight, brightnessTopLeft, brightnessBottomLeft, brightnessBottomRight); 477 | fillColormap(colorRedTopRight, colorRedTopLeft, colorRedBottomLeft, colorRedBottomRight, redmap); 478 | fillColormap(colorGreenTopRight, colorGreenTopLeft, colorGreenBottomLeft, colorGreenBottomRight, grnmap); 479 | fillColormap(colorBlueTopRight, colorBlueTopLeft, colorBlueBottomLeft, colorBlueBottomRight, blumap); 480 | 481 | getLight(0, 0); 482 | side(block, YPOS_LB, tex[0]); 483 | getLight(1, 0); 484 | side(block, YPOS_RB, tex[1]); 485 | getLight(1, 1); 486 | side(block, YPOS_RT, tex[2]); 487 | getLight(0, 1); 488 | side(block, YPOS_LT, tex[3]); 489 | } 490 | post(ForgeDirection.UP); 491 | } 492 | 493 | protected void pre(ForgeDirection face) { 494 | manager.preRenderSide(this, blockAccess, bx, by, bz, face); 495 | } 496 | 497 | protected void post(ForgeDirection face) { 498 | manager.postRenderSide(this, blockAccess, bx, by, bz, face); 499 | } 500 | } -------------------------------------------------------------------------------- /src/main/java/team/chisel/ctmlib/RenderBlocksColumn.java: -------------------------------------------------------------------------------- 1 | package team.chisel.ctmlib; 2 | 3 | import net.minecraft.block.Block; 4 | import net.minecraft.client.renderer.RenderBlocks; 5 | import net.minecraft.util.IIcon; 6 | import net.minecraft.world.IBlockAccess; 7 | 8 | /** 9 | * Used by {@link TextureType#CTMV} 10 | */ 11 | public class RenderBlocksColumn extends RenderBlocks { 12 | 13 | public TextureSubmap submap; 14 | public IIcon iconTop; 15 | private boolean inWorld; 16 | 17 | private IIcon sides[] = new IIcon[6]; 18 | private CTM ctm = CTM.getInstance(); 19 | 20 | public RenderBlocksColumn() { 21 | super(); 22 | } 23 | 24 | boolean connected(IBlockAccess world, int x, int y, int z, Block block, int meta) { 25 | Block inWorld = ctm.getBlockOrFacade(world, x, y, z, -1); 26 | return inWorld != null && inWorld.equals(block) && ctm.getBlockOrFacadeMetadata(world, x, y, z, -1) == meta; 27 | } 28 | 29 | @Override 30 | public boolean renderStandardBlock(Block block, int x, int y, int z) { 31 | int metadata = blockAccess.getBlockMetadata(x, y, z); 32 | inWorld = true; 33 | 34 | boolean yp = connected(blockAccess, x, y + 1, z, block, metadata); 35 | boolean yn = connected(blockAccess, x, y - 1, z, block, metadata); 36 | 37 | if (yp || yn) { 38 | sides[0] = iconTop; 39 | sides[1] = iconTop; 40 | 41 | if (yp && yn) 42 | sides[2] = submap.getSubIcon(0, 1); 43 | else if (yp) 44 | sides[2] = submap.getSubIcon(1, 1); 45 | else 46 | sides[2] = submap.getSubIcon(1, 0); 47 | 48 | sides[3] = sides[4] = sides[5] = sides[2]; 49 | } else { 50 | boolean xp = connected(blockAccess, x + 1, y, z, block, metadata); 51 | boolean xn = connected(blockAccess, x - 1, y, z, block, metadata); 52 | 53 | if (xp && (connected(blockAccess, x + 1, y + 1, z, block, metadata) || connected(blockAccess, x + 1, y - 1, z, block, metadata))) 54 | xp = false; 55 | if (xn && (connected(blockAccess, x - 1, y + 1, z, block, metadata) || connected(blockAccess, x - 1, y - 1, z, block, metadata))) 56 | xn = false; 57 | 58 | if (xp || xn) { 59 | uvRotateEast = 2; 60 | uvRotateWest = 1; 61 | uvRotateTop = 1; 62 | uvRotateBottom = 1; 63 | 64 | sides[4] = iconTop; 65 | sides[5] = iconTop; 66 | 67 | // for some reason along the x axis the bottom texture on the ends is backwards. This flips it around. 68 | if (xp && xn) { 69 | sides[1] = submap.getSubIcon(0, 1); 70 | sides[0] = sides[1]; 71 | } else if (xp) { 72 | sides[1] = submap.getSubIcon(1, 1); 73 | sides[0] = submap.getSubIcon(1, 0); 74 | } else { 75 | sides[1] = submap.getSubIcon(1, 0); 76 | sides[0] = submap.getSubIcon(1, 1); 77 | } 78 | sides[2] = sides[3] = sides[1]; 79 | } else { 80 | boolean zp = connected(blockAccess, x, y, z + 1, block, metadata); 81 | boolean zn = connected(blockAccess, x, y, z - 1, block, metadata); 82 | 83 | if (zp && (connected(blockAccess, x, y + 1, z + 1, block, metadata) || connected(blockAccess, x, y - 1, z + 1, block, metadata))) 84 | zp = false; 85 | if (zp && (connected(blockAccess, x + 1, y, z + 1, block, metadata) || connected(blockAccess, x - 1, y, z + 1, block, metadata))) 86 | zp = false; 87 | if (zn && (connected(blockAccess, x, y + 1, z - 1, block, metadata) || connected(blockAccess, x, y - 1, z - 1, block, metadata))) 88 | zn = false; 89 | if (zn && (connected(blockAccess, x + 1, y, z - 1, block, metadata) || connected(blockAccess, x - 1, y, z - 1, block, metadata))) 90 | zn = false; 91 | 92 | if (zp || zn) { 93 | uvRotateSouth = 1; 94 | uvRotateNorth = 2; 95 | 96 | sides[2] = iconTop; 97 | sides[3] = iconTop; 98 | 99 | if (zp && zn) 100 | sides[0] = submap.getSubIcon(0, 1); 101 | else if (zp) 102 | sides[0] = submap.getSubIcon(1, 0); 103 | else 104 | sides[0] = submap.getSubIcon(1, 1); 105 | 106 | sides[1] = sides[4] = sides[5] = sides[0]; 107 | } else { 108 | sides[0] = sides[1] = iconTop; 109 | sides[2] = sides[3] = sides[4] = sides[5] = submap.getSubIcon(0, 0); 110 | } 111 | } 112 | } 113 | 114 | boolean flag = super.renderStandardBlock(block, x, y, z); 115 | 116 | uvRotateSouth = 0; 117 | uvRotateEast = 0; 118 | uvRotateWest = 0; 119 | uvRotateNorth = 0; 120 | uvRotateTop = 0; 121 | uvRotateBottom = 0; 122 | 123 | inWorld = false; 124 | return flag; 125 | } 126 | 127 | @Override 128 | public void renderFaceXNeg(Block block, double x, double y, double z, IIcon icon) { 129 | super.renderFaceXNeg(block, x, y, z, getIcon(icon, 4)); 130 | } 131 | 132 | @Override 133 | public void renderFaceXPos(Block block, double x, double y, double z, IIcon icon) { 134 | super.renderFaceXPos(block, x, y, z, getIcon(icon, 5)); 135 | } 136 | 137 | @Override 138 | public void renderFaceZNeg(Block block, double x, double y, double z, IIcon icon) { 139 | super.renderFaceZNeg(block, x, y, z, getIcon(icon, 2)); 140 | } 141 | 142 | @Override 143 | public void renderFaceZPos(Block block, double x, double y, double z, IIcon icon) { 144 | super.renderFaceZPos(block, x, y, z, getIcon(icon, 3)); 145 | } 146 | 147 | @Override 148 | public void renderFaceYNeg(Block block, double x, double y, double z, IIcon icon) { 149 | super.renderFaceYNeg(block, x, y, z, getIcon(icon, 0)); 150 | } 151 | 152 | @Override 153 | public void renderFaceYPos(Block block, double x, double y, double z, IIcon icon) { 154 | super.renderFaceYPos(block, x, y, z, getIcon(icon, 1)); 155 | } 156 | 157 | private IIcon getIcon(IIcon defaultIcon, int side) { 158 | return sides[side] == null || !inWorld ? defaultIcon : sides[side]; 159 | } 160 | } -------------------------------------------------------------------------------- /src/main/java/team/chisel/ctmlib/SubmapManagerCTM.java: -------------------------------------------------------------------------------- 1 | package team.chisel.ctmlib; 2 | 3 | import lombok.Getter; 4 | import net.minecraft.block.Block; 5 | import net.minecraft.client.renderer.RenderBlocks; 6 | import net.minecraft.client.renderer.texture.IIconRegister; 7 | import net.minecraft.util.IIcon; 8 | import net.minecraft.world.IBlockAccess; 9 | import net.minecraftforge.common.util.ForgeDirection; 10 | import cpw.mods.fml.relauncher.Side; 11 | import cpw.mods.fml.relauncher.SideOnly; 12 | 13 | /** 14 | * A convenience implementation of {@link ISubmapManager} which does the standard CTM behavior. 15 | */ 16 | public class SubmapManagerCTM implements ISubmapManager { 17 | 18 | @SideOnly(Side.CLIENT) 19 | private static RenderBlocksCTM rb; 20 | 21 | @Getter 22 | private TextureSubmap submap, submapSmall; 23 | @Getter 24 | private final String textureName; 25 | 26 | /** 27 | * @param textureName 28 | * The path to the texture, excluding the mod ID (this is passed into {@link #registerIcons(String, Block, IIconRegister)}). 29 | *

30 | * The CTM texture will be this path, plus {@code "-ctm"}. 31 | */ 32 | public SubmapManagerCTM(String textureName) { 33 | this.textureName = textureName; 34 | } 35 | 36 | @Override 37 | public IIcon getIcon(int side, int meta) { 38 | return submapSmall.getBaseIcon(); 39 | } 40 | 41 | @Override 42 | public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) { 43 | return getIcon(side, world.getBlockMetadata(x, y, z)); 44 | } 45 | 46 | @Override 47 | @SideOnly(Side.CLIENT) 48 | public void registerIcons(String modName, Block block, IIconRegister register) { 49 | submap = new TextureSubmap(register.registerIcon(modName + ":" + textureName + "-ctm"), 4, 4); 50 | submapSmall = new TextureSubmap(register.registerIcon(modName + ":" + textureName), 2, 2); 51 | } 52 | 53 | @Override 54 | @SideOnly(Side.CLIENT) 55 | public RenderBlocks createRenderContext(RenderBlocks rendererOld, Block block, IBlockAccess world) { 56 | if (rb == null) { 57 | rb = new RenderBlocksCTM(); 58 | } 59 | rb.setRenderBoundsFromBlock(block); 60 | rb.submap = submap; 61 | rb.submapSmall = submapSmall; 62 | return rb; 63 | } 64 | 65 | @Override 66 | public void preRenderSide(RenderBlocks renderer, IBlockAccess world, int x, int y, int z, ForgeDirection side) { 67 | } 68 | 69 | @Override 70 | public void postRenderSide(RenderBlocks renderer, IBlockAccess world, int x, int y, int z, ForgeDirection side) { 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/team/chisel/ctmlib/TextureSubmap.java: -------------------------------------------------------------------------------- 1 | package team.chisel.ctmlib; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.commons.lang3.ArrayUtils; 6 | 7 | import lombok.experimental.Delegate; 8 | import net.minecraft.util.IIcon; 9 | import net.minecraftforge.client.event.TextureStitchEvent; 10 | import net.minecraftforge.common.MinecraftForge; 11 | 12 | import com.google.common.collect.Lists; 13 | 14 | import cpw.mods.fml.common.eventhandler.SubscribeEvent; 15 | import cpw.mods.fml.relauncher.Side; 16 | import cpw.mods.fml.relauncher.SideOnly; 17 | 18 | /** 19 | * This class is used to split up a large IIcon into smaller "submapped" icons used for CTM and other texture manipulation. 20 | */ 21 | public class TextureSubmap implements IIcon, ISubmap { 22 | 23 | private static List submaps = Lists.newArrayList(); 24 | private static TextureSubmap dummy = new TextureSubmap(null, 0, 0); 25 | static { 26 | MinecraftForge.EVENT_BUS.register(dummy); 27 | } 28 | 29 | private int width, height; 30 | @Delegate 31 | private IIcon baseIcon; 32 | 33 | protected IIcon[][] icons; 34 | 35 | /** 36 | * Construct a new submap. A submap is not required to be square, but it is required to be rectangular. 37 | * 38 | * @param baseIcon 39 | * The IIcon to submap. 40 | * @param width 41 | * The width of the map, in icons. 42 | * @param height 43 | * The height of the map, in icons. 44 | */ 45 | public TextureSubmap(IIcon baseIcon, int width, int height) { 46 | this.baseIcon = baseIcon; 47 | this.width = width; 48 | this.height = height; 49 | this.icons = new IIcon[width][height]; 50 | submaps.add(this); 51 | } 52 | 53 | /** 54 | * The large "base" icon used for the submap. 55 | */ 56 | public IIcon getBaseIcon() { 57 | return baseIcon; 58 | } 59 | 60 | /** 61 | * Gets all the icons in this submap. This is an expensive operation as it first clones the entire 2D array. 62 | * 63 | * @return All icons in this submap. 64 | */ 65 | public IIcon[][] getAllIcons() { 66 | IIcon[][] ret = ArrayUtils.clone(icons); 67 | for (int i = 0; i < ret.length; i++) { 68 | ret[i] = ArrayUtils.clone(ret[i]); 69 | } 70 | return ret; 71 | } 72 | 73 | /* ==== ISubmap ==== */ 74 | 75 | /** 76 | * Finds and returns the sub-icon at the given coordinates. For example, if you have a 3 by 3 submap, calling {@code getSubIcon(1, 1)} will return the center subicon. 77 | */ 78 | @Override 79 | public IIcon getSubIcon(int x, int y) { 80 | x = x % icons.length; 81 | return icons[x][y % icons[x].length]; 82 | } 83 | 84 | @Override 85 | public int getWidth() { 86 | return width; 87 | } 88 | 89 | @Override 90 | public int getHeight() { 91 | return height; 92 | } 93 | 94 | /* ==== Internal Stitching Logic ==== */ 95 | 96 | /** 97 | * For internal use only, this is used to create the virtual "subicons" used in the map. 98 | */ 99 | @SubscribeEvent 100 | public final void TexturesStitched(TextureStitchEvent.Post event) { 101 | for (TextureSubmap ts : submaps) { 102 | ts.texturesStitched(); 103 | } 104 | } 105 | 106 | public void texturesStitched() { 107 | for (int x = 0; x < width; x++) { 108 | for (int y = 0; y < height; y++) { 109 | icons[x][y] = new TextureVirtual(getBaseIcon(), width, height, x, y); 110 | } 111 | } 112 | } 113 | 114 | private class TextureVirtual implements IIcon { 115 | 116 | private int width, height; 117 | private float umin, umax, vmin, vmax; 118 | private String name; 119 | private IIcon parentIcon; 120 | 121 | private TextureVirtual(IIcon parent, int w, int h, int x, int y) { 122 | parentIcon = parent; 123 | 124 | umin = parentIcon.getInterpolatedU(16.0 * (x) / w); 125 | umax = parentIcon.getInterpolatedU(16.0 * (x + 1) / w); 126 | vmin = parentIcon.getInterpolatedV(16.0 * (y) / h); 127 | vmax = parentIcon.getInterpolatedV(16.0 * (y + 1) / h); 128 | 129 | name = parentIcon.getIconName() + "|" + x + "." + y; 130 | 131 | width = parentIcon.getIconWidth(); 132 | height = parentIcon.getIconHeight(); 133 | } 134 | 135 | @Override 136 | @SideOnly(Side.CLIENT) 137 | public float getMinU() { 138 | return umin; 139 | } 140 | 141 | @Override 142 | @SideOnly(Side.CLIENT) 143 | public float getMaxU() { 144 | return umax; 145 | } 146 | 147 | @Override 148 | @SideOnly(Side.CLIENT) 149 | public float getInterpolatedU(double d0) { 150 | return (float) (umin + (umax - umin) * d0 / 16.0); 151 | } 152 | 153 | @Override 154 | @SideOnly(Side.CLIENT) 155 | public float getMinV() { 156 | return vmin; 157 | } 158 | 159 | @Override 160 | @SideOnly(Side.CLIENT) 161 | public float getMaxV() { 162 | return vmax; 163 | } 164 | 165 | @Override 166 | @SideOnly(Side.CLIENT) 167 | public float getInterpolatedV(double d0) { 168 | return (float) (vmin + (vmax - vmin) * d0 / 16.0); 169 | } 170 | 171 | @Override 172 | @SideOnly(Side.CLIENT) 173 | public String getIconName() { 174 | return name; 175 | } 176 | 177 | @Override 178 | @SideOnly(Side.CLIENT) 179 | public int getIconWidth() { 180 | return width; 181 | } 182 | 183 | @Override 184 | @SideOnly(Side.CLIENT) 185 | public int getIconHeight() { 186 | return height; 187 | } 188 | } 189 | } 190 | --------------------------------------------------------------------------------