diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..91926c7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,26 @@ +# eclipse +bin +*.launch +.settings +.metadata +.classpath +.project + +# idea +out +*.ipr +*.iws +*.iml +.idea + +# gradle +build +.gradle + +# other +eclipse +run + +# Files from Forge MDK +forge*changelog.txt +/repo/ diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..78690ba --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,51 @@ +@Library('forge-shared-library')_ + +pipeline { + agent { + docker { + image 'gradlewrapper:latest' + args '-v gradlecache:/gradlecache' + } + } + environment { + GRADLE_ARGS = '-Dorg.gradle.daemon.idletimeout=5000' + } + + stages { + stage('buildandtest') { + steps { + sh './gradlew ${GRADLE_ARGS} --refresh-dependencies --continue build test' + script { + env.MYVERSION = sh(returnStdout: true, script: './gradlew properties -q | grep "version:" | awk \'{print $2}\'').trim() + } + } + post { + success { + writeChangelog(currentBuild, 'build/changelog.txt') + archiveArtifacts artifacts: 'build/changelog.txt', fingerprint: false + } + } + } + stage('publish') { + when { + not { + changeRequest() + } + } + environment { + FORGE_MAVEN = credentials('forge-maven-forge-user') + } + steps { + sh './gradlew ${GRADLE_ARGS} publish -PforgeMavenUser=${FORGE_MAVEN_USR} -PforgeMavenPassword=${FORGE_MAVEN_PSW}' + sh 'curl --user ${FORGE_MAVEN} http://files.minecraftforge.net/maven/manage/promote/latest/net.minecraftforge.lex.ChunkNoGoByeBye/${MYVERSION}' + } + } + } + post { + always { + archiveArtifacts artifacts: 'build/libs/**/*.jar', fingerprint: true + //junit 'build/test-results/*/*.xml' + //jacoco sourcePattern: '**/src/*/java' + } + } +} \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8000a6f --- /dev/null +++ b/LICENSE @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/LICENSE-header.txt b/LICENSE-header.txt new file mode 100644 index 0000000..c23a639 --- /dev/null +++ b/LICENSE-header.txt @@ -0,0 +1,16 @@ +ChunkNoGoByeBye +Copyright (c) 2019. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation version 2.1 +of the License. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..d66bd2a --- /dev/null +++ b/build.gradle @@ -0,0 +1,181 @@ +buildscript { + repositories { + maven { url = 'https://files.minecraftforge.net/maven' } + jcenter() + mavenCentral() + } + dependencies { + classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true + } +} + +plugins { + id 'net.minecrell.licenser' version '0.3' + id 'org.ajoberstar.grgit' version '2.3.0' +} + +apply plugin: 'net.minecraftforge.gradle' +apply plugin: 'eclipse' +apply plugin: 'maven-publish' + +ext { + MC_VERSION = '1.14.4' + FORGE_VERSION = '28.0.17' + MY_VERSION = gitVersion() + MODID = 'chunknogobyebye' +} + +version = "${MC_VERSION}-${MY_VERSION}" +group = 'net.minecraftforge.lex' +archivesBaseName = 'ChunkNoGoByeBye' + +sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly. + +sourceSets { + main { + resources { + srcDir 'src/generated/resources' + } + } +} + +minecraft { + mappings channel: 'snapshot', version: '20190719-1.14.3' + accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') + + runs { + client { + workingDirectory project.file('run') + property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' + property 'forge.logging.console.level', 'info' + + mods { + chunknogobyebye { + source sourceSets.main + } + } + } + + server { + workingDirectory project.file('run') + property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' + property 'forge.logging.console.level', 'info' + + mods { + chunknogobyebye { + source sourceSets.main + } + } + } + + data { + workingDirectory project.file('run') + property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' + property 'forge.logging.console.level', 'debug' + + args '--mod', MODID, '--all', '--output', file('src/generated/resources/') + + mods { + chunknogobyebye { + source sourceSets.main + } + } + } + } +} + +dependencies { + minecraft "net.minecraftforge:forge:${MC_VERSION}-${FORGE_VERSION}" +} + +// Example for how to get properties into the manifest for reading by the runtime.. +jar { + manifest { + attributes([ + 'Specification-Title' : 'ChunkNoGoByeBye', + 'Specification-Vendor' : 'LexManos', + 'Specification-Version' : MY_VERSION, + 'Implementation-Title' : project.name, + 'Implementation-Version' : version, + 'Implementation-Vendor' : 'LexManos', + 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") + ]) + } +} + +license { + header project.file('LICENSE-header.txt') + include 'net/minecraftforge/lex/**/*.java' + newLine false +} + +task sourcesJar(type: Jar, dependsOn: classes) { + classifier = 'sources' + from sourceSets.main.allSource + manifest.from(jar.manifest) +} + +jar.finalizedBy('reobfJar') + +artifacts { + archives jar + archives sourcesJar +} + +publishing { + publications { + mavenJava(MavenPublication) { + artifact jar + artifact sourcesJar + pom { + name = project.archivesBaseName + packaging = 'jar' + description = 'Simple chunk loader using vanilla forceload mechanics.' + url = 'https://github.com/LexManos/ChunkNoGoByeBye' + + scm { + url = 'https://github.com/LexManos/ChunkNoGoByeBye' + connection = 'scm:git:git://github.com/LexManos/ChunkNoGoByeBye.git' + developerConnection = 'scm:git:git@github.com:LexManos/ChunkNoGoByeBye.git' + } + + issueManagement { + system = 'github' + url = 'https://github.com/LexManos/ChunkNoGoByeBye/issues' + } + + developers { + developer { + id = 'LexManos' + name = 'Lex Manos' + } + } + } + } + } + repositories { + maven { + if (project.hasProperty('forgeMavenPassword')) { + credentials { + username project.properties.forgeMavenUser + password project.properties.forgeMavenPassword + } + url 'https://files.minecraftforge.net/maven/manage/upload' + } else { + url 'file://' + rootProject.file('repo').getAbsolutePath() + } + } + } +} + + +def gitVersion() { + def raw = grgit.describe(longDescr: true) + def desc = (raw == null ? 'unknown-offset-hash' : grgit.describe(longDescr: true)).split('-') as List + def hash = desc.remove(desc.size() - 1) + def offset = desc.remove(desc.size() - 1) + def tag = desc.join('-') + def branch = grgit.branch.current().name + project.ext.SPEC_VERSION = tag + return "${tag}.${offset}" //${t -> if (branch != 'master') t << '-' + branch}" +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..878bf1f --- /dev/null +++ b/gradle.properties @@ -0,0 +1,4 @@ +# Sets default memory used for gradle commands. Can be overridden by user or command line properties. +# This is required to provide enough memory for the Minecraft decompilation process. +org.gradle.jvmargs=-Xmx3G +org.gradle.daemon=false \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..7a3265e Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..949819d --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..cccdd3d --- /dev/null +++ b/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..f955316 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,84 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..c77756c --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'ChunkNoGoByeBye' diff --git a/src/generated/resources/.cache/cache b/src/generated/resources/.cache/cache new file mode 100644 index 0000000..c684748 --- /dev/null +++ b/src/generated/resources/.cache/cache @@ -0,0 +1,4 @@ +b4085cac20e4b9e5c14e4bc7b093d4edf19db0b0 assets\chunknogobyebye\lang\en_us.json +b31ae4e41293688ef821b62a1bc2a7638c3c9ed8 data\chunknogobyebye\advancements\recipes\misc\loader.json +bdcd590c5683a07af6e9b0fbd2a2ae0449932023 data\chunknogobyebye\loot_tables\blocks\loader.json +2ffe32c8e8521714838e873f187bad898780c1a4 data\chunknogobyebye\recipes\loader.json diff --git a/src/generated/resources/assets/chunknogobyebye/lang/en_us.json b/src/generated/resources/assets/chunknogobyebye/lang/en_us.json new file mode 100644 index 0000000..98589b8 --- /dev/null +++ b/src/generated/resources/assets/chunknogobyebye/lang/en_us.json @@ -0,0 +1,3 @@ +{ + "block.chunknogobyebye.loader": "Single Chunk Loader" +} \ No newline at end of file diff --git a/src/generated/resources/data/chunknogobyebye/advancements/recipes/misc/loader.json b/src/generated/resources/data/chunknogobyebye/advancements/recipes/misc/loader.json new file mode 100644 index 0000000..d001a05 --- /dev/null +++ b/src/generated/resources/data/chunknogobyebye/advancements/recipes/misc/loader.json @@ -0,0 +1,32 @@ +{ + "parent": "minecraft:recipes/root", + "rewards": { + "recipes": [ + "chunknogobyebye:loader" + ] + }, + "criteria": { + "has_ender_pearl": { + "trigger": "minecraft:inventory_changed", + "conditions": { + "items": [ + { + "item": "minecraft:ender_pearl" + } + ] + } + }, + "has_the_recipe": { + "trigger": "minecraft:recipe_unlocked", + "conditions": { + "recipe": "chunknogobyebye:loader" + } + } + }, + "requirements": [ + [ + "has_ender_pearl", + "has_the_recipe" + ] + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/chunknogobyebye/loot_tables/blocks/loader.json b/src/generated/resources/data/chunknogobyebye/loot_tables/blocks/loader.json new file mode 100644 index 0000000..5a7fde9 --- /dev/null +++ b/src/generated/resources/data/chunknogobyebye/loot_tables/blocks/loader.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "chunknogobyebye:loader" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/chunknogobyebye/recipes/loader.json b/src/generated/resources/data/chunknogobyebye/recipes/loader.json new file mode 100644 index 0000000..899f1b7 --- /dev/null +++ b/src/generated/resources/data/chunknogobyebye/recipes/loader.json @@ -0,0 +1,20 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "OOO", + "OEO", + "OOO" + ], + "key": { + "O": { + "item": "minecraft:ender_pearl" + }, + "E": { + "item": "minecraft:enchanting_table" + } + }, + "result": { + "item": "chunknogobyebye:loader", + "count": 10 + } +} \ No newline at end of file diff --git a/src/main/java/net/minecraftforge/lex/cngbb/ChunkLoaderList.java b/src/main/java/net/minecraftforge/lex/cngbb/ChunkLoaderList.java new file mode 100644 index 0000000..8509a20 --- /dev/null +++ b/src/main/java/net/minecraftforge/lex/cngbb/ChunkLoaderList.java @@ -0,0 +1,143 @@ +/* + * ChunkNoGoByeBye + * Copyright (c) 2019. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +package net.minecraftforge.lex.cngbb; + +import javax.annotation.Nullable; + +import it.unimi.dsi.fastutil.longs.Long2IntMap; +import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap; +import it.unimi.dsi.fastutil.longs.LongOpenHashSet; +import it.unimi.dsi.fastutil.longs.LongSet; +import net.minecraft.command.CommandSource; +import net.minecraft.nbt.INBT; +import net.minecraft.nbt.LongArrayNBT; +import net.minecraft.util.Direction; +import net.minecraft.util.concurrent.TickDelayedTask; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.world.server.ServerWorld; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.Capability.IStorage; + +public class ChunkLoaderList implements IChunkLoaderList { + private Long2IntMap refCount = new Long2IntOpenHashMap(); + private LongSet loaders = new LongOpenHashSet(); + private boolean loading = false; + @Nullable private final ServerWorld world; + + public ChunkLoaderList(@Nullable ServerWorld world) { + refCount.defaultReturnValue(Integer.MIN_VALUE); + this.world = world; + } + + @Override + public void add(BlockPos pos) { + long block = pos.toLong(); + if (!loaders.contains(block)) { + long chunk = toChunk(pos); + int ref = refCount.get(chunk); + if (ref == Integer.MIN_VALUE) { + if (!loading) + force(pos); + ref = 1; + } else { + ref += 1; + } + refCount.put(chunk, ref); + loaders.add(block); + } + } + + @Override + public void remove(BlockPos pos) { + if (loaders.remove(pos.toLong())) { + long chunk = toChunk(pos); + int ref = refCount.get(chunk); + + if (ref == Integer.MIN_VALUE || --ref <= 0) { + if (!loading) + unforce(pos); + refCount.remove(chunk); + } else { + refCount.put(chunk, ref); + } + } + } + + @Override + public boolean contains(BlockPos pos) { + return loaders.contains(pos.toLong()); + } + + private final long toChunk(BlockPos pos) { + return ChunkPos.asLong(pos.getX() >> 4, pos.getZ() >> 4); + } + + private void force(BlockPos pos) { forceload(pos, "add"); } + private void unforce(BlockPos pos) { forceload(pos, "remove"); } + + private void forceload(BlockPos pos, String action) { + if (this.world == null || this.world.getServer() == null) return; + CommandSource source = this.world.getServer().getCommandSource().withWorld(this.world); //TODO: Use custom source that doesn't spam chat? + @SuppressWarnings("unused") + int ret = this.world.getServer().getCommandManager().handleCommand(source, "forceload " + action + " " + pos.getX() + " " + pos.getZ()); + + //Lame feedback. + //BasicParticleType particle = ret == 0 ? ParticleTypes.ANGRY_VILLAGER : ParticleTypes.HAPPY_VILLAGER; + //world.spawnParticle(particle, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5F, 5, 0.5D, 0.5D, 0.5D, 0.0D); + } + + public static class Storage implements IStorage { + @Override + public INBT writeNBT(Capability capability, IChunkLoaderList instance, Direction side) { + if (!(instance instanceof ChunkLoaderList)) return null; + ChunkLoaderList list = (ChunkLoaderList)instance; + long[] data = new long[list.loaders.size()]; + int idx = 0; + for (long l : list.loaders) + data[idx++] = l; + return new LongArrayNBT(data); + } + + @Override + public void readNBT(Capability capability, IChunkLoaderList instance, Direction side, INBT nbt) { + if (!(instance instanceof ChunkLoaderList) || !(nbt instanceof LongArrayNBT)) return; + ChunkLoaderList list = (ChunkLoaderList)instance; + list.loading = true; + list.refCount.clear(); + list.loaders.clear(); + try { + for (long l : ((LongArrayNBT)nbt).getAsLongArray()) { + list.add(BlockPos.fromLong(l)); + } + if (list.world != null) { + // Run the force commands next tick to make sure they wern't removed. + list.world.getServer().enqueue(new TickDelayedTask(1, () -> { + for (long l : list.refCount.keySet()) { + ChunkPos chunk = new ChunkPos(l); + list.force(new BlockPos(chunk.x << 4, 0, chunk.z << 4)); + } + })); + } + } finally { + list.loading = false; + } + } + } +} diff --git a/src/main/java/net/minecraftforge/lex/cngbb/ChunkNoGoByeBye.java b/src/main/java/net/minecraftforge/lex/cngbb/ChunkNoGoByeBye.java new file mode 100644 index 0000000..f8619f4 --- /dev/null +++ b/src/main/java/net/minecraftforge/lex/cngbb/ChunkNoGoByeBye.java @@ -0,0 +1,128 @@ +/* + * ChunkNoGoByeBye + * Copyright (c) 2019. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +package net.minecraftforge.lex.cngbb; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; +import net.minecraft.item.ItemGroup; +import net.minecraft.nbt.INBT; +import net.minecraft.util.Direction; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; +import net.minecraft.world.server.ServerWorld; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.CapabilityInject; +import net.minecraftforge.common.capabilities.CapabilityManager; +import net.minecraftforge.common.capabilities.ICapabilitySerializable; +import net.minecraftforge.common.util.LazyOptional; +import net.minecraftforge.event.AttachCapabilitiesEvent; +import net.minecraftforge.event.RegistryEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; +import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import net.minecraftforge.registries.ObjectHolder; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Supplier; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +@Mod(ChunkNoGoByeBye.MODID) +public class ChunkNoGoByeBye { + public static final String MODID = "chunknogobyebye"; + public static final String LOADERID = "loader"; + + @SuppressWarnings("unused") + private static final Logger LOGGER = LogManager.getLogger(); + private static List> ITEMS = new ArrayList<>(); + private static List> BLOCKS = new ArrayList<>(); + + @CapabilityInject(IChunkLoaderList.class) + public static Capability CAPABILITY = null; + + @ObjectHolder(MODID + ":" + LOADERID) + public static final Block LOADER_BLOCK = registerBlock(LOADERID, () -> new LoaderBlock(Block.Properties.create(Material.ROCK).hardnessAndResistance(3.5F))); + @ObjectHolder(MODID + ":" + LOADERID) + public static final Item LOADER_ITEM = registerItem(LOADERID, () -> new BlockItem(LOADER_BLOCK, new Item.Properties().group(ItemGroup.MISC))); + + public ChunkNoGoByeBye() { + FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); + FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setupClient); + FMLJavaModLoadingContext.get().getModEventBus().register(this); + MinecraftForge.EVENT_BUS.register(this); + } + private void setupClient(final FMLClientSetupEvent event) {} + + private void setup(final FMLCommonSetupEvent event){ + CapabilityManager.INSTANCE.register(IChunkLoaderList.class, new ChunkLoaderList.Storage(), () -> new ChunkLoaderList(null)); + } + + @SubscribeEvent + public void attachWorldCaps(AttachCapabilitiesEvent event) { + if (event.getObject().isRemote) return; + final LazyOptional inst = LazyOptional.of(() -> new ChunkLoaderList((ServerWorld)event.getObject())); + final ICapabilitySerializable provider = new ICapabilitySerializable() { + @Override + public LazyOptional getCapability(Capability cap, Direction side) { + return CAPABILITY.orEmpty(cap, inst); + } + + @Override + public INBT serializeNBT() { + return CAPABILITY.writeNBT(inst.orElse(null), null); + } + + @Override + public void deserializeNBT(INBT nbt) { + CAPABILITY.readNBT(inst.orElse(null), null, nbt); + } + }; + event.addCapability(new ResourceLocation(MODID, LOADERID), provider); + event.addListener(() -> inst.invalidate()); + } + + /* + * Helper functions, because I feel like trying out this coding style. + * We gather things to register in the static initalizer. But since we are using Suppliers, + * the objects arn't actually run and this can be repeated/executed in the register events as they should be + */ + private static T registerItem(final String name, final Supplier sup) { + ITEMS.add(() -> sup.get().setRegistryName(MODID, name)); + return null; + } + private static T registerBlock(final String name, final Supplier sup) { + BLOCKS.add(() -> sup.get().setRegistryName(MODID, name)); + return null; + } + @SubscribeEvent + public void registerItems(final RegistryEvent.Register event) { + ITEMS.stream().map(Supplier::get).forEach(event.getRegistry()::register); + } + @SubscribeEvent + public void registerBlocks(final RegistryEvent.Register event) { + BLOCKS.stream().map(Supplier::get).forEach(event.getRegistry()::register); + } +} diff --git a/src/main/java/net/minecraftforge/lex/cngbb/DataCreator.java b/src/main/java/net/minecraftforge/lex/cngbb/DataCreator.java new file mode 100644 index 0000000..3a43a94 --- /dev/null +++ b/src/main/java/net/minecraftforge/lex/cngbb/DataCreator.java @@ -0,0 +1,232 @@ +/* + * ChunkNoGoByeBye + * Copyright (c) 2019. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +package net.minecraftforge.lex.cngbb; + +import static net.minecraftforge.lex.cngbb.ChunkNoGoByeBye.LOADER_BLOCK; +import static net.minecraftforge.lex.cngbb.ChunkNoGoByeBye.MODID; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.HashSet; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.TreeMap; +import java.util.function.BiConsumer; +import java.util.function.Consumer; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.util.TriConsumer; + +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; + +import net.minecraft.block.Block; +import net.minecraft.block.Blocks; +import net.minecraft.data.DataGenerator; +import net.minecraft.data.DirectoryCache; +import net.minecraft.data.IDataProvider; +import net.minecraft.data.IFinishedRecipe; +import net.minecraft.data.RecipeProvider; +import net.minecraft.data.ShapedRecipeBuilder; +import net.minecraft.data.loot.BlockLootTables; +import net.minecraft.item.Items; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.storage.loot.LootParameterSet; +import net.minecraft.world.storage.loot.LootParameterSets; +import net.minecraft.world.storage.loot.LootTable; +import net.minecraft.world.storage.loot.LootTableManager; +import net.minecraft.world.storage.loot.LootTables; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod.EventBusSubscriber; +import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; +import net.minecraftforge.fml.event.lifecycle.GatherDataEvent; + +@EventBusSubscriber(modid = MODID, bus = Bus.MOD) +public class DataCreator { + private static final Logger LOGGER = LogManager.getLogger(); + private static final Gson GSON = (new GsonBuilder()).setPrettyPrinting().disableHtmlEscaping().create(); + + @SubscribeEvent + public static void gatherData(GatherDataEvent event) { + DataGenerator gen = event.getGenerator(); + + if (event.includeServer()) { + gen.addProvider(new Recipes(gen)); + gen.addProvider(new Loots(gen)); + } + if (event.includeClient()) { + //TODO: Generate models when Forge/Someone makes model data generators + gen.addProvider(new Language(gen, MODID)); + } + } + + private static void save(DirectoryCache cache, Object object, Path target) throws IOException { + String data = GSON.toJson(object); + String hash = IDataProvider.HASH_FUNCTION.hashUnencodedChars(data).toString(); + if (!Objects.equals(cache.getPreviousHash(target), hash) || !Files.exists(target)) { + Files.createDirectories(target.getParent()); + + try (BufferedWriter bufferedwriter = Files.newBufferedWriter(target)) { + bufferedwriter.write(data); + } + } + + cache.func_208316_a(target, hash); + } + + private static class Recipes extends RecipeProvider { + private final DataGenerator gen; + private final Path ADV_ROOT; + + public Recipes(DataGenerator gen) { + super(gen); + this.gen = gen; + ADV_ROOT = this.gen.getOutputFolder().resolve("data/minecraft/advancements/recipes/root.json"); + } + + @Override + protected void saveRecipeAdvancement(DirectoryCache cache, JsonObject json, Path path) { + if (path.equals(ADV_ROOT)) return; //We NEVER care about this. + super.saveRecipeAdvancement(cache, json, path); + } + + @Override + protected void registerRecipes(Consumer consumer) { + ShapedRecipeBuilder.shapedRecipe(LOADER_BLOCK, 10) + .key('O', Items.ENDER_PEARL).key('E', Blocks.ENCHANTING_TABLE) + .patternLine("OOO").patternLine("OEO").patternLine("OOO") + .addCriterion("has_ender_pearl", hasItem(Items.ENDER_PEARL)) + .build(consumer); + } + } + + private static class Loots implements IDataProvider { + private final DataGenerator gen; + + public Loots(DataGenerator gen) { + this.gen = gen; + } + + + @Override + public String getName() { + return "LootTables"; + } + + @Override + public void act(DirectoryCache cache) { + Map map = Maps.newHashMap(); + TriConsumer consumer = (set, key, builder) -> { + if (map.put(key, builder.setParameterSet(set).build()) != null) + throw new IllegalStateException("Duplicate loot table " + key); + }; + + new Blocks().accept((key, builder) -> consumer.accept(LootParameterSets.BLOCK, key, builder)); + + map.forEach((key, table) -> { + Path target = this.gen.getOutputFolder().resolve("data/" + key.getNamespace() + "/loot_tables/" + key.getPath() + ".json"); + + try { + IDataProvider.save(GSON, cache, LootTableManager.toJson(table), target); + } catch (IOException ioexception) { + LOGGER.error("Couldn't save loot table {}", target, ioexception); + } + }); + } + + private class Blocks extends BlockLootTables { + private Set knownBlocks = new HashSet<>(); + + private void addTables() { + this.func_218492_c(LOADER_BLOCK); + } + + @Override + public void accept(BiConsumer consumer) { + this.addTables(); + + Set visited = Sets.newHashSet(); + + for(Block block : knownBlocks) { + ResourceLocation tabke_name = block.getLootTable(); + if (tabke_name != LootTables.EMPTY && visited.add(tabke_name)) { + LootTable.Builder builder = this.field_218581_i.remove(tabke_name); + if (builder == null) + throw new IllegalStateException(String.format("Missing loottable '%s' for '%s'", tabke_name, block.getRegistryName())); + + consumer.accept(tabke_name, builder); + } + } + + if (!this.field_218581_i.isEmpty()) + throw new IllegalStateException("Created block loot tables for non-blocks: " + this.field_218581_i.keySet()); + } + + @Override + public void func_218492_c(Block block) { + knownBlocks.add(block); + super.func_218492_c(block); + } + } + } + + private static class Language implements IDataProvider { + private final DataGenerator gen; + private final String modid; + private final Map data = new TreeMap<>(); + + public Language(DataGenerator gen, String modid) { + this.gen = gen; + this.modid = modid; + } + + private void addTranslations() { + add(LOADER_BLOCK, "Chunk Loader"); + } + + @Override + public String getName() { + return "Languages"; + } + + @Override + public void act(DirectoryCache cache) throws IOException { + addTranslations(); + + if (!data.isEmpty()) + save(cache, data, this.gen.getOutputFolder().resolve("assets/" + modid + "/lang/en_us.json")); + } + + private void add(Block block, String name) { + add(block.getTranslationKey(), name); + } + + private void add(String key, String value) { + if (data.put(key, value) != null) + throw new IllegalStateException("Duplicate translation key " + key); + } + } +} diff --git a/src/main/java/net/minecraftforge/lex/cngbb/IChunkLoaderList.java b/src/main/java/net/minecraftforge/lex/cngbb/IChunkLoaderList.java new file mode 100644 index 0000000..55c9054 --- /dev/null +++ b/src/main/java/net/minecraftforge/lex/cngbb/IChunkLoaderList.java @@ -0,0 +1,27 @@ +/* + * ChunkNoGoByeBye + * Copyright (c) 2019. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +package net.minecraftforge.lex.cngbb; + +import net.minecraft.util.math.BlockPos; + +public interface IChunkLoaderList { + void add(BlockPos pos); + void remove(BlockPos pos); + boolean contains(BlockPos pos); +} diff --git a/src/main/java/net/minecraftforge/lex/cngbb/LoaderBlock.java b/src/main/java/net/minecraftforge/lex/cngbb/LoaderBlock.java new file mode 100644 index 0000000..bd46ecf --- /dev/null +++ b/src/main/java/net/minecraftforge/lex/cngbb/LoaderBlock.java @@ -0,0 +1,42 @@ +/* + * ChunkNoGoByeBye + * Copyright (c) 2019. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +package net.minecraftforge.lex.cngbb; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class LoaderBlock extends Block { + public LoaderBlock(Properties properties) { + super(properties); + } + + @Override + public void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean isMoving) { + if (world.isRemote) return; + world.getCapability(ChunkNoGoByeBye.CAPABILITY, null).ifPresent(cap -> cap.add(pos)); + } + + @Override + public void onReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean isMoving) { + if (world.isRemote) return; + world.getCapability(ChunkNoGoByeBye.CAPABILITY, null).ifPresent(cap -> cap.remove(pos)); + } +} diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg new file mode 100644 index 0000000..14d49fa --- /dev/null +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -0,0 +1,2 @@ +public net.minecraft.data.RecipeProvider func_200403_a(Lnet/minecraft/util/IItemProvider;)Lnet/minecraft/advancements/criterion/InventoryChangeTrigger$Instance; # hasItem +public net.minecraft.data.loot.BlockLootTables field_218581_i # Table Map \ No newline at end of file diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml new file mode 100644 index 0000000..174f427 --- /dev/null +++ b/src/main/resources/META-INF/mods.toml @@ -0,0 +1,29 @@ +modLoader="javafml" +loaderVersion="[28,)" +# A URL to refer people to when problems occur with this mod +#issueTrackerURL="http://my.issue.tracker/" #optional + +[[mods]] + modId="chunknogobyebye" + version="${file.jarVersion}" + displayName="ChunkNoGoByeBye" + #updateJSONURL="http://myurl.me/" + #displayURL="http://example.com/" + #logoFile="examplemod.png" + #credits="" + authors="LexManos" + description="Adds a Block to keep the current chunk loaded using vanilla loading mechanics." + +[[dependencies.chunknogobyebye]] + modId="forge" + mandatory=true + versionRange="[28,)" + ordering="NONE" + side="BOTH" + +[[dependencies.chunknogobyebye]] + modId="minecraft" + mandatory=true + versionRange="[1.14.4]" + ordering="NONE" + side="BOTH" diff --git a/src/main/resources/assets/chunknogobyebye/blockstates/loader.json b/src/main/resources/assets/chunknogobyebye/blockstates/loader.json new file mode 100644 index 0000000..3c0b21d --- /dev/null +++ b/src/main/resources/assets/chunknogobyebye/blockstates/loader.json @@ -0,0 +1,7 @@ +{ + "variants": { + "": [ + { "model": "chunknogobyebye:block/loader" } + ] + } +} diff --git a/src/main/resources/assets/chunknogobyebye/models/block/loader.json b/src/main/resources/assets/chunknogobyebye/models/block/loader.json new file mode 100644 index 0000000..63c2164 --- /dev/null +++ b/src/main/resources/assets/chunknogobyebye/models/block/loader.json @@ -0,0 +1,6 @@ +{ + "parent": "block/cube_all", + "textures": { + "all": "block/debug" + } +} diff --git a/src/main/resources/assets/chunknogobyebye/models/item/loader.json b/src/main/resources/assets/chunknogobyebye/models/item/loader.json new file mode 100644 index 0000000..10d2e23 --- /dev/null +++ b/src/main/resources/assets/chunknogobyebye/models/item/loader.json @@ -0,0 +1,3 @@ +{ + "parent": "chunknogobyebye:block/loader" +} diff --git a/src/main/resources/pack.mcmeta b/src/main/resources/pack.mcmeta new file mode 100644 index 0000000..42ab490 --- /dev/null +++ b/src/main/resources/pack.mcmeta @@ -0,0 +1,7 @@ +{ + "pack": { + "description": "examplemod resources", + "pack_format": 4, + "_comment": "A pack_format of 4 requires json lang files. Note: we require v4 pack meta for all mods." + } +}