diff options
author | Raven Szewczyk <git@eigenraven.me> | 2024-05-24 19:14:21 +0100 |
---|---|---|
committer | Raven Szewczyk <git@eigenraven.me> | 2024-05-24 19:14:21 +0100 |
commit | 9f42a6f1f90a8d36df7a7febd19a1afc563c0dca (patch) | |
tree | 9d722203c3548ba579623500d0207b237b97c64b | |
parent | 7b534efabcc2f45031f29b197a3fa896e7166258 (diff) | |
parent | 38c18b5d591c557cab8fede6bf3a2a662dfdd4aa (diff) | |
download | GT5-Unofficial-9f42a6f1f90a8d36df7a7febd19a1afc563c0dca.tar.gz GT5-Unofficial-9f42a6f1f90a8d36df7a7febd19a1afc563c0dca.tar.bz2 GT5-Unofficial-9f42a6f1f90a8d36df7a7febd19a1afc563c0dca.zip |
Merge in GalacticGreg with history
git-subtree-dir: galacticgreg
git-subtree-mainline: 7b534efabcc2f45031f29b197a3fa896e7166258
git-subtree-split: 38c18b5d591c557cab8fede6bf3a2a662dfdd4aa
56 files changed, 6358 insertions, 0 deletions
diff --git a/galacticgreg/.git-blame-ignore-revs b/galacticgreg/.git-blame-ignore-revs new file mode 100644 index 0000000000..e6422951ec --- /dev/null +++ b/galacticgreg/.git-blame-ignore-revs @@ -0,0 +1,3 @@ +# Ignore spotlessApply reformat +960bbb3537d7c8c552050b5826de58bc8d798f04 +7976c2a8c761e9a4cd53ae42ac6939f89aafdf86 diff --git a/galacticgreg/.gitattributes b/galacticgreg/.gitattributes new file mode 100644 index 0000000000..fd2792b6cb --- /dev/null +++ b/galacticgreg/.gitattributes @@ -0,0 +1,44 @@ +* text eol=lf + +*.[jJ][aA][rR] binary + +*.[pP][nN][gG] binary +*.[jJ][pP][gG] binary +*.[jJ][pP][eE][gG] binary +*.[gG][iI][fF] binary +*.[tT][iI][fF] binary +*.[tT][iI][fF][fF] binary +*.[iI][cC][oO] binary +*.[sS][vV][gG] text +*.[eE][pP][sS] binary +*.[xX][cC][fF] binary + +*.[kK][aA][rR] binary +*.[mM]4[aA] binary +*.[mM][iI][dD] binary +*.[mM][iI][dD][iI] binary +*.[mM][pP]3 binary +*.[oO][gG][gG] binary +*.[rR][aA] binary + +*.7[zZ] binary +*.[gG][zZ] binary +*.[tT][aA][rR] binary +*.[tT][gG][zZ] binary +*.[zZ][iI][pP] binary + +*.[tT][cC][nN] binary +*.[sS][oO] binary +*.[dD][lL][lL] binary +*.[dD][yY][lL][iI][bB] binary +*.[pP][sS][dD] binary +*.[tT][tT][fF] binary +*.[oO][tT][fF] binary + +*.[pP][aA][tT][cC][hH] -text + +*.[bB][aA][tT] text eol=crlf +*.[cC][mM][dD] text eol=crlf +*.[pP][sS]1 text eol=crlf + +*[aA][uU][tT][oO][gG][eE][nN][eE][rR][aA][tT][eE][dD]* binary diff --git a/galacticgreg/.github/workflows/build-and-test.yml b/galacticgreg/.github/workflows/build-and-test.yml new file mode 100644 index 0000000000..3ee2f686fd --- /dev/null +++ b/galacticgreg/.github/workflows/build-and-test.yml @@ -0,0 +1,13 @@ + +name: Build and test + +on: + pull_request: + branches: [ master, main ] + push: + branches: [ master, main ] + +jobs: + build-and-test: + uses: GTNewHorizons/GTNH-Actions-Workflows/.github/workflows/build-and-test.yml@master + secrets: inherit diff --git a/galacticgreg/.github/workflows/release-tags.yml b/galacticgreg/.github/workflows/release-tags.yml new file mode 100644 index 0000000000..e4c0be6b0d --- /dev/null +++ b/galacticgreg/.github/workflows/release-tags.yml @@ -0,0 +1,14 @@ + +name: Release tagged build + +on: + push: + tags: [ '*' ] + +permissions: + contents: write + +jobs: + release-tags: + uses: GTNewHorizons/GTNH-Actions-Workflows/.github/workflows/release-tags.yml@master + secrets: inherit diff --git a/galacticgreg/.gitignore b/galacticgreg/.gitignore new file mode 100644 index 0000000000..40fb5e4a7d --- /dev/null +++ b/galacticgreg/.gitignore @@ -0,0 +1,29 @@ +.gradle +.settings +/.idea/ +/run/ +/build/ +/eclipse/ +.classpath +.project +/bin/ +/config/ +/crash-reports/ +/logs/ +options.txt +/saves/ +usernamecache.json +banned-ips.json +banned-players.json +eula.txt +ops.json +server.properties +servers.dat +usercache.json +whitelist.json +/out/ +*.iml +*.ipr +*.iws +src/main/resources/mixins.*.json +*.bat diff --git a/galacticgreg/CODEOWNERS b/galacticgreg/CODEOWNERS new file mode 100644 index 0000000000..a6b5f68cd0 --- /dev/null +++ b/galacticgreg/CODEOWNERS @@ -0,0 +1,3 @@ +# Any Github changes require admin approval +/.github/** @GTNewHorizons/admin + diff --git a/galacticgreg/GGregLogo.xcf b/galacticgreg/GGregLogo.xcf Binary files differnew file mode 100644 index 0000000000..4888998c8a --- /dev/null +++ b/galacticgreg/GGregLogo.xcf diff --git a/galacticgreg/LICENSE b/galacticgreg/LICENSE new file mode 100644 index 0000000000..8cdb8451d9 --- /dev/null +++ b/galacticgreg/LICENSE @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/> + 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. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, 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 or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +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 give any other recipients of the Program a copy of this License +along with the Program. + +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 Program or any portion +of it, thus forming a work based on the Program, 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) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +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 Program, 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 Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) 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; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, 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 executable. However, as a +special exception, the source code 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. + +If distribution of executable or 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 counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program 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. + + 5. 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 Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program 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 to +this License. + + 7. 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 Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program 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 Program. + +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. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program 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. + + 9. The Free Software Foundation may publish revised and/or new versions +of the 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 Program +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 Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, 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 + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "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 PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. 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 PROGRAM 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 PROGRAM (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 PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), 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 Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. 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. + + {description} + Copyright (C) {year} {fullname} + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; 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. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + {signature of Ty Coon}, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. + diff --git a/galacticgreg/README.md b/galacticgreg/README.md new file mode 100644 index 0000000000..d462ff74da --- /dev/null +++ b/galacticgreg/README.md @@ -0,0 +1,18 @@ +# GalacticGregGT5 +The rewritten GalacticGreg mod for GregTech5 + +This mod: + +- is not compatible with GregTech 6 +- is not compatible with GalacticGreg-Config settings created prior to this mod +- is still WiP (Not anymore!) +- is not maintained by BloodAsp, so don't contact him about bugs, use the issue tracker here + +You can build it for yourself, but if you just feel lazy (As I do most times), feel free to grab a compiled version here: + +[](http://jenkins.usrv.eu:8080/job/GalacticGreg/) + + + +# Copyright / License / Modpack usage +You may use this mod in any modpack you want to. You may also fork this repository and continue to develop this mod to cover your own ideas. Pullrequests are welcome. diff --git a/galacticgreg/build.gradle b/galacticgreg/build.gradle new file mode 100644 index 0000000000..e57a16f9f1 --- /dev/null +++ b/galacticgreg/build.gradle @@ -0,0 +1,5 @@ +//version: 1707058017 + +plugins { + id 'com.gtnewhorizons.gtnhconvention' +} diff --git a/galacticgreg/dependencies.gradle b/galacticgreg/dependencies.gradle new file mode 100644 index 0000000000..1a4675dd3d --- /dev/null +++ b/galacticgreg/dependencies.gradle @@ -0,0 +1,8 @@ +// Add your dependencies here + +dependencies { + api("com.github.GTNewHorizons:Galacticraft:3.1.1-GTNH:dev") + api("com.github.GTNewHorizons:bartworks:0.9.2:dev") { + exclude group:"com.github.GTNewHorizons", module:"GalacticGregGT5" + } +} diff --git a/galacticgreg/gradle.properties b/galacticgreg/gradle.properties new file mode 100644 index 0000000000..6635006f9f --- /dev/null +++ b/galacticgreg/gradle.properties @@ -0,0 +1,192 @@ +# ExampleMod tag to use as Blowdryer (Spotless, etc.) settings version, leave empty to disable. +# LOCAL to test local config updates. +gtnh.settings.blowdryerTag = 0.2.2 + +# Human-readable mod name, available for mcmod.info population. +modName = Galactic Greg + +# Case-sensitive identifier string, available for mcmod.info population and used for automatic mixin JSON generation. +# Conventionally lowercase. +modId = galacticgreg + +# Root package of the mod, used to find various classes in other properties, +# mcmod.info substitution, enabling assertions in run tasks, etc. +modGroup = bloodasp.galacticgreg + +# Whether to use modGroup as the maven publishing group. +# Due to a history of using JitPack, the default is com.github.GTNewHorizons for all mods. +useModGroupForPublishing = false + +# Updates your build.gradle and settings.gradle automatically whenever an update is available. +autoUpdateBuildScript = false + +# Version of Minecraft to target +minecraftVersion = 1.7.10 + +# Version of Minecraft Forge to target +forgeVersion = 10.13.4.1614 + +# Specify an MCP channel for dependency deobfuscation and the deobfParams task. +channel = stable + +# Specify an MCP mappings version for dependency deobfuscation and the deobfParams task. +mappingsVersion = 12 + +# Defines other MCP mappings for dependency deobfuscation. +remoteMappings = https\://raw.githubusercontent.com/MinecraftForge/FML/1.7.10/conf/ + +# Select a default username for testing your mod. You can always override this per-run by running +# `./gradlew runClient --username=AnotherPlayer`, or configuring this command in your IDE. +developmentEnvironmentUserName = "Developer" + +# Enables using modern Java syntax (up to version 17) via Jabel, while still targeting JVM 8. +# See https://github.com/bsideup/jabel for details on how this works. +enableModernJavaSyntax = false + +# Enables injecting missing generics into the decompiled source code for a better coding experience. +# Turns most publicly visible List, Map, etc. into proper List<E>, Map<K, V> types. +enableGenericInjection = false + +# Generate a class with a String field for the mod version named as defined below. +# If generateGradleTokenClass is empty or not missing, no such class will be generated. +# If gradleTokenVersion is empty or missing, the field will not be present in the class. +generateGradleTokenClass = + +# Name of the token containing the project's current version to generate/replace. +gradleTokenVersion = GRADLETOKEN_VERSION + +# [DEPRECATED] Mod ID replacement token. +gradleTokenModId = + +# [DEPRECATED] Mod name replacement token. +gradleTokenModName = + +# [DEPRECATED] Mod Group replacement token. +gradleTokenGroupName = + +# [DEPRECATED] +# Multiple source files can be defined here by providing a comma-separated list: Class1.java,Class2.java,Class3.java +# public static final String VERSION = "GRADLETOKEN_VERSION"; +# The string's content will be replaced with your mod's version when compiled. You should use this to specify your mod's +# version in @Mod([...], version = VERSION, [...]). +# Leave these properties empty to skip individual token replacements. +replaceGradleTokenInFile = GalacticGreg.java + +# In case your mod provides an API for other mods to implement you may declare its package here. Otherwise, you can +# leave this property empty. +# Example value: (apiPackage = api) + (modGroup = com.myname.mymodid) -> com.myname.mymodid.api +apiPackage = + +# Specify the configuration file for Forge's access transformers here. It must be placed into /src/main/resources/META-INF/ +# There can be multiple files in a space-separated list. +# Example value: mymodid_at.cfg nei_at.cfg +accessTransformersFile = + +# Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled! +usesMixins = false + +# Adds some debug arguments like verbose output and class export. +usesMixinDebug = false + +# Specify the location of your implementation of IMixinConfigPlugin. Leave it empty otherwise. +mixinPlugin = + +# Specify the package that contains all of your Mixins. You may only place Mixins in this package or the build will fail! +mixinsPackage = + +# Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin! +# This parameter is for legacy compatibility only +# Example value: (coreModClass = asm.FMLPlugin) + (modGroup = com.myname.mymodid) -> com.myname.mymodid.asm.FMLPlugin +coreModClass = + +# If your project is only a consolidation of mixins or a core mod and does NOT contain a 'normal' mod ( = some class +# that is annotated with @Mod) you want this to be true. When in doubt: leave it on false! +containsMixinsAndOrCoreModOnly = false + +# Enables Mixins even if this mod doesn't use them, useful if one of the dependencies uses mixins. +forceEnableMixins = false + +# If enabled, you may use 'shadowCompile' for dependencies. They will be integrated into your jar. It is your +# responsibility to check the license and request permission for distribution if required. +usesShadowedDependencies = false + +# If disabled, won't remove unused classes from shadowed dependencies. Some libraries use reflection to access +# their own classes, making the minimization unreliable. +minimizeShadowedDependencies = true + +# If disabled, won't rename the shadowed classes. +relocateShadowedDependencies = true + +# Adds the GTNH maven, CurseMaven, Modrinth, and some more well-known 1.7.10 repositories. +includeWellKnownRepositories = true + +# Change these to your Maven coordinates if you want to publish to a custom Maven repository instead of the default GTNH Maven. +# Authenticate with the MAVEN_USER and MAVEN_PASSWORD environment variables. +# If you need a more complex setup disable maven publishing here and add a publishing repository to addon.gradle. +usesMavenPublishing = true + +# Maven repository to publish the mod to. +# mavenPublishUrl = https\://nexus.gtnewhorizons.com/repository/releases/ + +# Publishing to Modrinth requires you to set the MODRINTH_TOKEN environment variable to your current Modrinth API token. +# +# The project's ID on Modrinth. Can be either the slug or the ID. +# Leave this empty if you don't want to publish to Modrinth. +modrinthProjectId = + +# The project's relations on Modrinth. You can use this to refer to other projects on Modrinth. +# Syntax: scope1-type1:name1;scope2-type2:name2;... +# Where scope can be one of [required, optional, incompatible, embedded], +# type can be one of [project, version], +# and the name is the Modrinth project or version slug/id of the other mod. +# Example: required-project:fplib;optional-project:gasstation;incompatible-project:gregtech +# Note: GTNH Mixins is automatically set as a required dependency if usesMixins = true +modrinthRelations = + +# Publishing to CurseForge requires you to set the CURSEFORGE_TOKEN environment variable to one of your CurseForge API tokens. +# +# The project's numeric ID on CurseForge. You can find this in the About Project box. +# Leave this empty if you don't want to publish on CurseForge. +curseForgeProjectId = + +# The project's relations on CurseForge. You can use this to refer to other projects on CurseForge. +# Syntax: type1:name1;type2:name2;... +# Where type can be one of [requiredDependency, embeddedLibrary, optionalDependency, tool, incompatible], +# and the name is the CurseForge project slug of the other mod. +# Example: requiredDependency:railcraft;embeddedLibrary:cofhlib;incompatible:buildcraft +# Note: UniMixins is automatically set as a required dependency if usesMixins = true. +curseForgeRelations = + +# Optional parameter to customize the produced artifacts. Use this to preserve artifact naming when migrating older +# projects. New projects should not use this parameter. +# customArchiveBaseName = + +# Optional parameter to have the build automatically fail if an illegal version is used. +# This can be useful if you e.g. only want to allow versions in the form of '1.1.xxx'. +# The check is ONLY performed if the version is a git tag. +# Note: the specified string must be escaped, so e.g. 1\\.1\\.\\d+ instead of 1\.1\.\d+ +# versionPattern = + +# Uncomment to prevent the source code from being published. +# noPublishedSources = true + +# Uncomment this to disable Spotless checks. +# This should only be uncommented to keep it easier to sync with upstream/other forks. +# That is, if there is no other active fork/upstream, NEVER change this. +# disableSpotless = true + +# Uncomment this to disable Checkstyle checks (currently wildcard import check). +# disableCheckstyle = true + +# Override the IDEA build type. Valid values are: "" (leave blank, do not override), "idea" (force use native IDEA build), "gradle" +# (force use delegated build). +# This is meant to be set in $HOME/.gradle/gradle.properties. +# e.g. add "systemProp.org.gradle.project.ideaOverrideBuildType=idea" will override the build type to be native build. +# WARNING: If you do use this option, it will overwrite whatever you have in your existing projects. This might not be what you want! +# Usually there is no need to uncomment this here as other developers do not necessarily use the same build type as you. +# ideaOverrideBuildType = idea + +# Whether IDEA should run spotless checks when pressing the Build button. +# This is meant to be set in $HOME/.gradle/gradle.properties. +# ideaCheckSpotlessOnBuild = true + diff --git a/galacticgreg/gradle/wrapper/gradle-wrapper.jar b/galacticgreg/gradle/wrapper/gradle-wrapper.jar Binary files differnew file mode 100644 index 0000000000..e6441136f3 --- /dev/null +++ b/galacticgreg/gradle/wrapper/gradle-wrapper.jar diff --git a/galacticgreg/gradle/wrapper/gradle-wrapper.properties b/galacticgreg/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..b82aa23a4f --- /dev/null +++ b/galacticgreg/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/galacticgreg/gradlew b/galacticgreg/gradlew new file mode 100755 index 0000000000..1aa94a4269 --- /dev/null +++ b/galacticgreg/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# 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 ;; #( + MSYS* | 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 + if ! command -v java >/dev/null 2>&1 + then + 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 +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/galacticgreg/gradlew.bat b/galacticgreg/gradlew.bat new file mode 100644 index 0000000000..25da30dbde --- /dev/null +++ b/galacticgreg/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@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=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@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="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +: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 %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 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! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/galacticgreg/jitpack.yml b/galacticgreg/jitpack.yml new file mode 100644 index 0000000000..09bbb514fc --- /dev/null +++ b/galacticgreg/jitpack.yml @@ -0,0 +1,2 @@ +before_install: + - ./gradlew setupCIWorkspace
\ No newline at end of file diff --git a/galacticgreg/repositories.gradle b/galacticgreg/repositories.gradle new file mode 100644 index 0000000000..c227b16ec2 --- /dev/null +++ b/galacticgreg/repositories.gradle @@ -0,0 +1,4 @@ +// Add any additional repositories for your dependencies here + +repositories { +} diff --git a/galacticgreg/settings.gradle b/galacticgreg/settings.gradle new file mode 100644 index 0000000000..94c2daf35c --- /dev/null +++ b/galacticgreg/settings.gradle @@ -0,0 +1,23 @@ + +pluginManagement { + repositories { + maven { + // RetroFuturaGradle + name "GTNH Maven" + url "https://nexus.gtnewhorizons.com/repository/public/" + mavenContent { + includeGroup("com.gtnewhorizons") + includeGroupByRegex("com\\.gtnewhorizons\\..+") + } + } + gradlePluginPortal() + mavenCentral() + mavenLocal() + } +} + +plugins { + id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.22' +} + + diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/GT_TileEntity_Ores_Space.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/GT_TileEntity_Ores_Space.java new file mode 100644 index 0000000000..dfa1307bce --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/GT_TileEntity_Ores_Space.java @@ -0,0 +1,144 @@ +package bloodasp.galacticgreg; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +import bloodasp.galacticgreg.api.Enums.ReplaceState; +import bloodasp.galacticgreg.api.ModDimensionDef; +import gregtech.api.GregTech_API; +import gregtech.api.util.GT_Log; +import gregtech.common.blocks.GT_Block_Ores_Abstract; +import gregtech.common.blocks.GT_TileEntity_Ores; + +public class GT_TileEntity_Ores_Space { + + // Renamed function to prevent function shadowing with base GT-code + public static boolean setOuterSpaceOreBlock(ModDimensionDef pDimensionDef, World pWorld, int pX, int pY, int pZ, + int pMetaData) { + return setOuterSpaceOreBlock(pDimensionDef, pWorld, pX, pY, pZ, pMetaData, false, -1); + } + + public static boolean setOuterSpaceOreBlock(ModDimensionDef pDimensionDef, World pWorld, int pX, int pY, int pZ, + int pMetaData, boolean pAir) { + return setOuterSpaceOreBlock(pDimensionDef, pWorld, pX, pY, pZ, pMetaData, pAir, -1); + } + + /** + * Check if the block at given position may be replaced by an ore + * + * @param pWorld the world in question + * @param pX X-Cord + * @param pY Y-Cord + * @param pZ Z-Cord + * @return + */ + private static ReplaceState CheckForReplaceableBlock(World pWorld, int pX, int pY, int pZ, + ModDimensionDef pDimDef) { + try { + ReplaceState tFlag = ReplaceState.Unknown; + + Block targetBlock = pWorld.getBlock(pX, pY, pZ); + int targetBlockMeta = pWorld.getBlockMetadata(pX, pY, pZ); + + if (targetBlock == Blocks.air) tFlag = ReplaceState.Airblock; + else tFlag = pDimDef.getReplaceStateForBlock(targetBlock, targetBlockMeta); + + return tFlag; + } catch (Exception e) { + e.printStackTrace(GT_Log.err); + GalacticGreg.Logger.error("Error while processing CheckForReplaceableBlock(), defaulting to UNKNOWN"); + return ReplaceState.Unknown; + } + } + + /** + * Actually set the OreBlock + * + * @param pWorld the world in question + * @param pX + * @param pY + * @param pZ + * @param pMetaData GT-Ore metadata + * @param pAir + * @return + */ + public static boolean setOuterSpaceOreBlock(ModDimensionDef pDimensionDef, World pWorld, int pX, int pY, int pZ, + int pMetaData, boolean pAir, int pCustomGTOreOffset) { + if (!pAir) pY = Math.min(pWorld.getActualHeight(), Math.max(pY, 1)); + + if (pDimensionDef == null) { + GalacticGreg.Logger + .warn("Unknown DimensionID: %d. Will not set anything here", pWorld.provider.dimensionId); + return false; + } + try { + Block tBlock = pWorld.getBlock(pX, pY, pZ); + // If the meta is non-zero, and the target block is either non-air or the air-override is active + if ((pMetaData > 0) && ((tBlock != Blocks.air) || pAir)) { + // make sure we're either going with normal ore-metas, or small ores. + // Probably should do another check for <= 1700 + if (pMetaData < 1000 || pMetaData >= 16000) { + ReplaceState tRS = CheckForReplaceableBlock(pWorld, pX, pY, pZ, pDimensionDef); + + // Unable to lookup replacement state. Means: The block is unknown, and shall not be replaced + if (tRS == ReplaceState.Unknown) { + GalacticGreg.Logger.trace("Not placing ore Meta %d, as target block is unknown", pMetaData); + return false; + } else if (tRS == ReplaceState.Airblock && !pAir) { + GalacticGreg.Logger.trace("Not placing ore Meta %d in midair, as AIR is FALSE", pMetaData); + return false; + } + if (tRS == ReplaceState.CannotReplace) { + // wrong metaData ID for target block + GalacticGreg.Logger.trace("Not placing ore Meta %d, as the state is CANNOTREPLACE", pMetaData); + return false; + } + + if (pCustomGTOreOffset == -1) pMetaData += pDimensionDef.getStoneType() + .getOffset(); + else pMetaData += pCustomGTOreOffset; + // This fix seems like cargo cult coding...The Abstract class just returns 0 for the harvest level. + // But it aligns with the GT5U method, so yay? + pWorld.setBlock( + pX, + pY, + pZ, + GregTech_API.sBlockOres1, + GT_TileEntity_Ores.getHarvestData( + (short) pMetaData, + ((GT_Block_Ores_Abstract) GregTech_API.sBlockOres1) + .getBaseBlockHarvestLevel(pMetaData % 16000 / 1000)), + 0); + TileEntity tTileEntity = pWorld.getTileEntity(pX, pY, pZ); + if ((tTileEntity instanceof GT_TileEntity_Ores)) { + ((GT_TileEntity_Ores) tTileEntity).mMetaData = ((short) pMetaData); + ((GT_TileEntity_Ores) tTileEntity).mNatural = true; + } else { + // This is somehow triggered randomly, and most times the target block is air, which should + // never happen as we check for air... + // That's why I put this behind a debug config option. If you ever find the reason for it, + // please tell me what caused this + if (GalacticGreg.GalacticConfig.ReportOreGenFailures) GalacticGreg.Logger.warn( + "Something went wrong while placing GT OreTileEntity. Meta: %d X [%d] Y [%d] Z [%d]", + pMetaData, + pX, + pY, + pZ); + } + + return true; + } else GalacticGreg.Logger.warn( + "Not replacing block at pos %d %d %d due unexpected metaData for OreBlock: %d", + pX, + pY, + pZ, + pMetaData); + } + } catch (Exception e) { + if (GalacticGreg.GalacticConfig.ReportOreGenFailures) e.printStackTrace(); + } + return false; + } +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/GT_Worldgen_GT_Ore_Layer_Space.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/GT_Worldgen_GT_Ore_Layer_Space.java new file mode 100644 index 0000000000..44fa0bf5a4 --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/GT_Worldgen_GT_Ore_Layer_Space.java @@ -0,0 +1,390 @@ +package bloodasp.galacticgreg; + +import static gregtech.api.enums.GT_Values.oreveinPlacerOres; +import static gregtech.api.enums.GT_Values.oreveinPlacerOresMultiplier; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; + +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import net.minecraft.world.chunk.IChunkProvider; + +import bloodasp.galacticgreg.api.ModDimensionDef; +import bloodasp.galacticgreg.auxiliary.GTOreGroup; +import bloodasp.galacticgreg.bartworks.BW_Worldgen_Ore_Layer_Space; +import bloodasp.galacticgreg.dynconfig.DynamicOreMixWorldConfig; +import bloodasp.galacticgreg.registry.GalacticGregRegistry; +import gregtech.api.GregTech_API; +import gregtech.api.enums.Materials; +import gregtech.api.util.GT_Log; +import gregtech.api.world.GT_Worldgen; + +public class GT_Worldgen_GT_Ore_Layer_Space extends GT_Worldgen { + + public static int sWeight = 0; + public final short mMinY; + public final short mMaxY; + public final short mWeight; + public final short mDensity; + public final short mSize; + public final short mPrimaryMeta; + public final short mSecondaryMeta; + public final short mBetweenMeta; + public final short mSporadicMeta; + + private long mProfilingStart; + private long mProfilingEnd; + + private DynamicOreMixWorldConfig _mDynWorldConfig; + + public GT_Worldgen_GT_Ore_Layer_Space(String pName, boolean pDefault, int pMinY, int pMaxY, int pWeight, + int pDensity, int pSize, Materials pPrimary, Materials pSecondary, Materials pBetween, Materials pSporadic) { + super(pName, GalacticGreg.oreVeinWorldgenList, pDefault); + mMinY = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "MinHeight", pMinY)); + mMaxY = ((short) Math + .max(this.mMinY + 5, GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "MaxHeight", pMaxY))); + mWeight = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "RandomWeight", pWeight)); + mDensity = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "Density", pDensity)); + mSize = ((short) Math.max(1, GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "Size", pSize))); + mPrimaryMeta = ((short) GregTech_API.sWorldgenFile + .get("worldgen." + this.mWorldGenName, "OrePrimaryLayer", pPrimary.mMetaItemSubID)); + mSecondaryMeta = ((short) GregTech_API.sWorldgenFile + .get("worldgen." + this.mWorldGenName, "OreSecondaryLayer", pSecondary.mMetaItemSubID)); + mBetweenMeta = ((short) GregTech_API.sWorldgenFile + .get("worldgen." + this.mWorldGenName, "OreSporadiclyInbetween", pBetween.mMetaItemSubID)); + mSporadicMeta = ((short) GregTech_API.sWorldgenFile + .get("worldgen." + this.mWorldGenName, "OreSporaticlyAround", pSporadic.mMetaItemSubID)); + + _mDynWorldConfig = new DynamicOreMixWorldConfig(mWorldGenName); + _mDynWorldConfig.InitDynamicConfig(); + + GalacticGreg.Logger.trace("Initialized new OreLayer: %s", pName); + + if (mEnabled) GT_Worldgen_GT_Ore_Layer_Space.sWeight += this.mWeight; + + } + + public GT_Worldgen_GT_Ore_Layer_Space(String pName, boolean pDefault, int pMinY, int pMaxY, int pWeight, + int pDensity, int pSize, short pPrimary, short pSecondary, short pBetween, short pSporadic) { + super(pName, GalacticGreg.oreVeinWorldgenList, pDefault); + mMinY = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "MinHeight", pMinY)); + mMaxY = ((short) Math + .max(this.mMinY + 5, GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "MaxHeight", pMaxY))); + mWeight = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "RandomWeight", pWeight)); + mDensity = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "Density", pDensity)); + mSize = ((short) Math.max(1, GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "Size", pSize))); + mPrimaryMeta = ((short) GregTech_API.sWorldgenFile + .get("worldgen." + this.mWorldGenName, "OrePrimaryLayer", pPrimary)); + mSecondaryMeta = ((short) GregTech_API.sWorldgenFile + .get("worldgen." + this.mWorldGenName, "OreSecondaryLayer", pSecondary)); + mBetweenMeta = ((short) GregTech_API.sWorldgenFile + .get("worldgen." + this.mWorldGenName, "OreSporadiclyInbetween", pBetween)); + mSporadicMeta = ((short) GregTech_API.sWorldgenFile + .get("worldgen." + this.mWorldGenName, "OreSporaticlyAround", pSporadic)); + + _mDynWorldConfig = new DynamicOreMixWorldConfig(mWorldGenName); + _mDynWorldConfig.InitDynamicConfig(); + + GalacticGreg.Logger.trace("Initialized new OreLayer: %s", pName); + + if (mEnabled) sWeight += this.mWeight; + + } + + /** + * Check if *this* orelayer is enabled for pDimensionDef + * + * @param pDimensionDef the ChunkProvider in question + * @return + */ + public boolean isEnabledForDim(ModDimensionDef pDimensionDef) { + return _mDynWorldConfig.isEnabledInDim(pDimensionDef); + } + + private static Map<String, Integer> _mBufferedVeinCountList = new HashMap<>(); + + /** + * Get the number of enabled OreMixes for given Dimension. This query is buffered and will only consume calculation + * time on the first run for each dimension + * + * @param pDimensionDef + * @return + */ + private static int getNumOremixedForDim(ModDimensionDef pDimensionDef) { + int tVal = 0; + if (_mBufferedVeinCountList.containsKey(pDimensionDef.getDimIdentifier())) + tVal = _mBufferedVeinCountList.get(pDimensionDef.getDimIdentifier()); + else { + for (GT_Worldgen tWorldGen : GalacticGreg.oreVeinWorldgenList) + if (tWorldGen instanceof GT_Worldgen_GT_Ore_Layer_Space + && ((GT_Worldgen_GT_Ore_Layer_Space) tWorldGen).isEnabledForDim(pDimensionDef)) tVal++; + + _mBufferedVeinCountList.put(pDimensionDef.getDimIdentifier(), tVal); + } + + return tVal; + } + + private static Map<String, List<String>> _mBufferedVeinList = new HashMap<>(); + + /** + * Get a List of all Veins which are enabled for given Dim. Query is buffered + * + * @param pDimensionDef + * @return null if nothing is found or error + */ + private static List<String> getOreMixIDsForDim(ModDimensionDef pDimensionDef) { + List<String> tReturn; + + if (_mBufferedVeinList.containsKey(pDimensionDef.getDimIdentifier())) + tReturn = _mBufferedVeinList.get(pDimensionDef.getDimIdentifier()); + else { + tReturn = new ArrayList<>(); + for (GT_Worldgen tWorldGen : GalacticGreg.oreVeinWorldgenList) + if (tWorldGen instanceof GT_Worldgen_GT_Ore_Layer_Space + && ((GT_Worldgen_GT_Ore_Layer_Space) tWorldGen).isEnabledForDim(pDimensionDef)) + tReturn.add(tWorldGen.mWorldGenName); + else if (tWorldGen instanceof BW_Worldgen_Ore_Layer_Space + && ((BW_Worldgen_Ore_Layer_Space) tWorldGen).isEnabledForDim(pDimensionDef)) + tReturn.add(tWorldGen.mWorldGenName); + + _mBufferedVeinList.put(pDimensionDef.getDimIdentifier(), tReturn); + } + + return tReturn; + } + + private static short getMaxWeightForDim(ModDimensionDef pDimensionDef) { + short tVal = 0; + for (GT_Worldgen tWorldGen : GalacticGreg.oreVeinWorldgenList) + if (tWorldGen instanceof GT_Worldgen_GT_Ore_Layer_Space + && ((GT_Worldgen_GT_Ore_Layer_Space) tWorldGen).isEnabledForDim(pDimensionDef) + && tVal < ((GT_Worldgen_GT_Ore_Layer_Space) tWorldGen).mWeight) + tVal = ((GT_Worldgen_GT_Ore_Layer_Space) tWorldGen).mWeight; + + return tVal; + } + + /** + * Select a random ore-vein from the list + * + * @param pDimensionDef + * @param pRandom + * @return + */ + public static GTOreGroup getRandomOreGroup(ModDimensionDef pDimensionDef, Random pRandom, boolean pIgnoreWeight) { + short primaryMeta = 0; + short secondaryMeta = 0; + short betweenMeta = 0; + short sporadicMeta = 0; + + // int tRangeSplit = getMaxWeightForDim(pDimensionDef) / 2; + + if (pIgnoreWeight) { + List<String> tEnabledVeins = getOreMixIDsForDim(pDimensionDef); + int tRnd = pRandom.nextInt(tEnabledVeins.size()); + String tVeinName = tEnabledVeins.get(tRnd); + + // No lambda in Java 1.6 and 1.7 :( + // GT_Worldgen_GT_Ore_Layer_Space tGen = GalacticGreg.oreVeinWorldgenList.stream().filter(p -> + // p.mWorldGenName == tVeinName).findFirst(); + + GT_Worldgen tGen = null; + for (GT_Worldgen tWorldGen : GalacticGreg.oreVeinWorldgenList) + if (tWorldGen instanceof GT_Worldgen_GT_Ore_Layer_Space + && ((GT_Worldgen_GT_Ore_Layer_Space) tWorldGen).mWorldGenName.equals(tVeinName)) tGen = tWorldGen; + + if (tGen != null) { + // GT_Worldgen_GT_Ore_Layer_Space tGen = GalacticGreg.oreVeinWorldgenList.get(tRndMix); + GalacticGreg.Logger.trace("Using Oremix %s for asteroid", tGen.mWorldGenName); + primaryMeta = ((GT_Worldgen_GT_Ore_Layer_Space) tGen).mPrimaryMeta; + secondaryMeta = ((GT_Worldgen_GT_Ore_Layer_Space) tGen).mSecondaryMeta; + betweenMeta = ((GT_Worldgen_GT_Ore_Layer_Space) tGen).mBetweenMeta; + sporadicMeta = ((GT_Worldgen_GT_Ore_Layer_Space) tGen).mSporadicMeta; + } + } else { + if ((GT_Worldgen_GT_Ore_Layer_Space.sWeight > 0) && (GalacticGreg.oreVeinWorldgenList.size() > 0)) { + GalacticGreg.Logger.trace("About to select oremix"); + boolean temp = true; + int tRandomWeight; + for (int i = 0; (i < 256) && (temp); i++) { + tRandomWeight = pRandom.nextInt(GT_Worldgen_GT_Ore_Layer_Space.sWeight); + for (GT_Worldgen tWorldGen : GalacticGreg.oreVeinWorldgenList) { + if (!(tWorldGen instanceof GT_Worldgen_GT_Ore_Layer_Space)) continue; + + tRandomWeight -= ((GT_Worldgen_GT_Ore_Layer_Space) tWorldGen).mWeight; + if (tRandomWeight <= 0) { + try { + if (((GT_Worldgen_GT_Ore_Layer_Space) tWorldGen).isEnabledForDim(pDimensionDef)) { + GalacticGreg.Logger.trace("Using Oremix %s for asteroid", tWorldGen.mWorldGenName); + primaryMeta = ((GT_Worldgen_GT_Ore_Layer_Space) tWorldGen).mPrimaryMeta; + secondaryMeta = ((GT_Worldgen_GT_Ore_Layer_Space) tWorldGen).mSecondaryMeta; + betweenMeta = ((GT_Worldgen_GT_Ore_Layer_Space) tWorldGen).mBetweenMeta; + sporadicMeta = ((GT_Worldgen_GT_Ore_Layer_Space) tWorldGen).mSporadicMeta; + + temp = false; + break; + } + } catch (Throwable e) { + e.printStackTrace(GT_Log.err); + } + } + } + } + } + } + if (primaryMeta != 0 || secondaryMeta != 0 || betweenMeta != 0 || sporadicMeta != 0) + return new GTOreGroup(primaryMeta, secondaryMeta, betweenMeta, sporadicMeta); + else return null; + } + + @Override + public boolean executeWorldgen(World pWorld, Random pRandom, String pBiome, int pDimensionType, int pChunkX, + int pChunkZ, IChunkProvider pChunkGenerator, IChunkProvider pChunkProvider) { + GalacticGreg.Logger.trace("Entering executeWorldgen for [%s]", mWorldGenName); + ModDimensionDef tMDD = GalacticGregRegistry.getDimensionTypeByChunkGenerator(pChunkGenerator); + if (tMDD == null) { + GalacticGreg.Logger + .trace("Can't find dimension definition for ChunkProvider %s, skipping", pChunkGenerator.toString()); + return false; + } + + if (!_mDynWorldConfig.isEnabledInDim(tMDD)) { + GalacticGreg.Logger + .trace("OreGen for %s is disallowed in dimension %s, skipping", mWorldGenName, tMDD.getDimensionName()); + return false; + } + + if (GalacticGreg.GalacticConfig.ProfileOreGen) mProfilingStart = System.currentTimeMillis(); + // --------------------------- + int tMinY = this.mMinY + pRandom.nextInt(this.mMaxY - this.mMinY - 7); + + int cX = pChunkX - pRandom.nextInt(this.mSize); + int eX = pChunkX + 16 + pRandom.nextInt(this.mSize); + int cZ = pChunkZ - pRandom.nextInt(this.mSize); + int eZ = pChunkZ + 16 + pRandom.nextInt(this.mSize); + for (int tX = cX; tX <= eX; tX++) { + for (int tZ = cZ; tZ <= eZ; tZ++) { + if (this.mSecondaryMeta > 0) { + for (int i = tMinY - 1; i < tMinY + 3; i++) { + int placeX = Math.max( + 1, + Math.max(MathHelper.abs_int(cX - tX), MathHelper.abs_int(eX - tX)) + / getDensityFromPos(tX, tZ, pChunkX, pChunkZ)); + int placeZ = Math.max( + 1, + Math.max(MathHelper.abs_int(cZ - tZ), MathHelper.abs_int(eZ - tZ)) + / getDensityFromPos(tX, tZ, pChunkX, pChunkZ)); + if ((pRandom.nextInt(placeZ) == 0) || (pRandom.nextInt(placeX) == 0)) { + GT_TileEntity_Ores_Space + .setOuterSpaceOreBlock(tMDD, pWorld, tX, i, tZ, this.mSecondaryMeta); + } + } + } + if (this.mBetweenMeta > 0) { + for (int i = tMinY + 2; i < tMinY + 6; i++) { + int placeX = Math.max( + 1, + Math.max(MathHelper.abs_int(cX - tX), MathHelper.abs_int(eX - tX)) + / getDensityFromPos(tX, tZ, pChunkX, pChunkZ)); + int placeZ = Math.max( + 1, + Math.max(MathHelper.abs_int(cZ - tZ), MathHelper.abs_int(eZ - tZ)) + / getDensityFromPos(tX, tZ, pChunkX, pChunkZ)); + if (((pRandom.nextInt(placeZ) == 0) || (pRandom.nextInt(placeX) == 0)) + && (pRandom.nextInt(2) == 0)) { + GT_TileEntity_Ores_Space.setOuterSpaceOreBlock(tMDD, pWorld, tX, i, tZ, this.mBetweenMeta); + } + } + + } + if (this.mPrimaryMeta > 0) { + for (int i = tMinY + 4; i < tMinY + 8; i++) { + int placeX = Math.max( + 1, + Math.max(MathHelper.abs_int(cX - tX), MathHelper.abs_int(eX - tX)) + / getDensityFromPos(tX, tZ, pChunkX, pChunkZ)); + int placeZ = Math.max( + 1, + Math.max(MathHelper.abs_int(cZ - tZ), MathHelper.abs_int(eZ - tZ)) + / getDensityFromPos(tX, tZ, pChunkX, pChunkZ)); + if ((pRandom.nextInt(placeZ) == 0) || (pRandom.nextInt(placeX) == 0)) { + GT_TileEntity_Ores_Space.setOuterSpaceOreBlock(tMDD, pWorld, tX, i, tZ, this.mPrimaryMeta); + } + } + } + if (this.mSporadicMeta > 0) { + for (int i = tMinY - 1; i < tMinY + 8; i++) { + int placeX = Math.max( + 1, + Math.max(MathHelper.abs_int(cX - tX), MathHelper.abs_int(eX - tX)) + / getDensityFromPos(tX, tZ, pChunkX, pChunkZ)); + int placeZ = Math.max( + 1, + Math.max(MathHelper.abs_int(cZ - tZ), MathHelper.abs_int(eZ - tZ)) + / getDensityFromPos(tX, tZ, pChunkX, pChunkZ)); + if (((pRandom.nextInt(placeX) == 0) || (pRandom.nextInt(placeZ) == 0)) + && (pRandom.nextInt(7) == 0)) { + GT_TileEntity_Ores_Space.setOuterSpaceOreBlock(tMDD, pWorld, tX, i, tZ, this.mSporadicMeta); + } + } + } + } + } + + if (oreveinPlacerOres) { + int nSmallOres = (cX - eX) * (cZ - eZ) * this.mDensity / 10 * oreveinPlacerOresMultiplier; + for (int nSmallOresCount = 0; nSmallOresCount < nSmallOres; nSmallOresCount++) { + int tX = pRandom.nextInt(16) + pChunkX + 2; + int tZ = pRandom.nextInt(16) + pChunkZ + 2; + int tY = pRandom.nextInt(160) + 10; // Y height can vary from 10 to 170 for small ores. + if (this.mPrimaryMeta > 0) + GT_TileEntity_Ores_Space.setOuterSpaceOreBlock(tMDD, pWorld, tX, tY, tZ, this.mPrimaryMeta + 16000); + tX = pRandom.nextInt(16) + pChunkX + 2; + tZ = pRandom.nextInt(16) + pChunkZ + 2; + tY = pRandom.nextInt(160) + 10; // Y height can vary from 10 to 170 for small ores. + if (this.mSecondaryMeta > 0) GT_TileEntity_Ores_Space + .setOuterSpaceOreBlock(tMDD, pWorld, tX, tY, tZ, this.mSecondaryMeta + 16000); + tX = pRandom.nextInt(16) + pChunkX + 2; + tZ = pRandom.nextInt(16) + pChunkZ + 2; + tY = pRandom.nextInt(160) + 10; // Y height can vary from 10 to 170 for small ores. + if (this.mBetweenMeta > 0) + GT_TileEntity_Ores_Space.setOuterSpaceOreBlock(tMDD, pWorld, tX, tY, tZ, this.mBetweenMeta + 16000); + tX = pRandom.nextInt(16) + pChunkX + 2; + tZ = pRandom.nextInt(16) + pChunkZ + 2; + tY = pRandom.nextInt(190) + 10; // Y height can vary from 10 to 200 for small ores. + if (this.mSporadicMeta > 0) GT_TileEntity_Ores_Space + .setOuterSpaceOreBlock(tMDD, pWorld, tX, tY, tZ, this.mSporadicMeta + 16000); + } + } + + // --------------------------- + if (GalacticGreg.GalacticConfig.ProfileOreGen) { + try { + mProfilingEnd = System.currentTimeMillis(); + long tTotalTime = mProfilingEnd - mProfilingStart; + GalacticGreg.Profiler.AddTimeToList(tMDD, tTotalTime); + GalacticGreg.Logger.debug( + "Done with OreLayer-Worldgen in DimensionType %s. Generation took %d ms", + tMDD.getDimensionName(), + tTotalTime); + } catch (Exception ignored) {} // Silently ignore errors + } + + GalacticGreg.Logger.trace("Leaving executeWorldgen"); + return true; + } + + public int getDensityFromPos(int aX, int aZ, int aSeedX, int aSeedZ) { + if (aX < 0) aX -= 16; + if (aZ < 0) aZ -= 16; + return Math.max( + 1, + this.mDensity + / ((int) Math.sqrt(2 + Math.pow(aX / 16 - aSeedX / 16, 2) + Math.pow(aZ / 16 - aSeedZ / 16, 2)))); + } +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/GT_Worldgen_GT_Ore_SmallPieces_Space.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/GT_Worldgen_GT_Ore_SmallPieces_Space.java new file mode 100644 index 0000000000..11e264b4fb --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/GT_Worldgen_GT_Ore_SmallPieces_Space.java @@ -0,0 +1,123 @@ +package bloodasp.galacticgreg; + +import java.util.Random; + +import net.minecraft.world.World; +import net.minecraft.world.chunk.IChunkProvider; + +import bloodasp.galacticgreg.api.ModDimensionDef; +import bloodasp.galacticgreg.dynconfig.DynamicOreMixWorldConfig; +import bloodasp.galacticgreg.registry.GalacticGregRegistry; +import gregtech.api.GregTech_API; +import gregtech.api.enums.Materials; +import gregtech.api.world.GT_Worldgen; + +public class GT_Worldgen_GT_Ore_SmallPieces_Space extends GT_Worldgen { + + public final short mMinY; + public final short mMaxY; + public final short mAmount; + public final short mMeta; + + private long mProfilingStart; + private long mProfilingEnd; + private DynamicOreMixWorldConfig _mDynWorldConfig; + + public GT_Worldgen_GT_Ore_SmallPieces_Space(String pName, boolean pDefault, int pMinY, int pMaxY, int pAmount, + Materials pPrimary) { + super(pName, GalacticGreg.smallOreWorldgenList, pDefault); + + mMinY = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "MinHeight", pMinY)); + mMaxY = ((short) Math + .max(this.mMinY + 1, GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "MaxHeight", pMaxY))); + mAmount = ((short) Math + .max(1, GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "Amount", pAmount))); + mMeta = ((short) GregTech_API.sWorldgenFile + .get("worldgen." + this.mWorldGenName, "Ore", pPrimary.mMetaItemSubID)); + + _mDynWorldConfig = new DynamicOreMixWorldConfig(mWorldGenName); + _mDynWorldConfig.InitDynamicConfig(); + + GalacticGreg.Logger.trace("Initialized new OreLayer: %s", pName); + } + + public GT_Worldgen_GT_Ore_SmallPieces_Space(String pName, boolean pDefault, int pMinY, int pMaxY, int pAmount, + short pPrimary) { + super(pName, GalacticGreg.smallOreWorldgenList, pDefault); + + mMinY = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "MinHeight", pMinY)); + mMaxY = ((short) Math + .max(this.mMinY + 1, GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "MaxHeight", pMaxY))); + mAmount = ((short) Math + .max(1, GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "Amount", pAmount))); + mMeta = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "Ore", pPrimary)); + + _mDynWorldConfig = new DynamicOreMixWorldConfig(mWorldGenName); + _mDynWorldConfig.InitDynamicConfig(); + + GalacticGreg.Logger.trace("Initialized new OreLayer: %s", pName); + } + + /** + * Check if *this* orelayer is enabled for pDimensionDef + * + * @param pDimensionDef the ChunkProvider in question + * @return + */ + public boolean isEnabledForDim(ModDimensionDef pDimensionDef) { + return _mDynWorldConfig.isEnabledInDim(pDimensionDef); + } + + @Override + public boolean executeWorldgen(World pWorld, Random pRandom, String pBiome, int pDimensionType, int pChunkX, + int pChunkZ, IChunkProvider pChunkGenerator, IChunkProvider pChunkProvider) { + GalacticGreg.Logger.trace("Entering executeWorldgen for [%s]", mWorldGenName); + ModDimensionDef tMDD = GalacticGregRegistry.getDimensionTypeByChunkGenerator(pChunkGenerator); + if (tMDD == null) { + GalacticGreg.Logger + .trace("Can't find dimension definition for ChunkProvider %s, skipping", pChunkGenerator.toString()); + return false; + } + + if (!_mDynWorldConfig.isEnabledInDim(tMDD)) { + GalacticGreg.Logger + .trace("OreGen for %s is disallowed in dimension %s, skipping", mWorldGenName, tMDD.getDimensionName()); + return false; + } + + if (GalacticGreg.GalacticConfig.ProfileOreGen) mProfilingStart = System.currentTimeMillis(); + // --------------------------- + + if (this.mMeta > 0) { + int i = 0; + for (int j = Math.max(1, this.mAmount / 2 + pRandom.nextInt(this.mAmount) / 2); i < j; i++) { + GT_TileEntity_Ores_Space.setOuterSpaceOreBlock( + tMDD, + pWorld, + pChunkX + pRandom.nextInt(16), + this.mMinY + pRandom.nextInt(Math.max(1, this.mMaxY - this.mMinY)), + pChunkZ + pRandom.nextInt(16), + this.mMeta + 16000); + } + } + // --------------------------- + if (GalacticGreg.GalacticConfig.ProfileOreGen) { + try { + mProfilingEnd = System.currentTimeMillis(); + long tTotalTime = mProfilingEnd - mProfilingStart; + GalacticGreg.Profiler.AddTimeToList(tMDD, tTotalTime); + GalacticGreg.Logger.debug( + "Done with SmallOre-Worldgen in DimensionType %s. Generation took %d ms", + tMDD.getDimensionName(), + tTotalTime); + } catch (Exception ignored) {} // Silently ignore errors + } + + GalacticGreg.Logger.trace("Leaving executeWorldgen"); + return true; + } + + public boolean isAllowedForHeight(int pTargetHeight) { + return (pTargetHeight >= mMinY && pTargetHeight <= mMaxY); + } +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/GT_Worldgenerator_Space.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/GT_Worldgenerator_Space.java new file mode 100644 index 0000000000..d2060ca71e --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/GT_Worldgenerator_Space.java @@ -0,0 +1,578 @@ +package bloodasp.galacticgreg; + +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.inventory.IInventory; +import net.minecraft.util.Vec3; +import net.minecraft.util.WeightedRandomChestContent; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; +import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.chunk.IChunkProvider; +import net.minecraftforge.common.ChestGenHooks; + +import bloodasp.galacticgreg.api.AsteroidBlockComb; +import bloodasp.galacticgreg.api.BlockMetaComb; +import bloodasp.galacticgreg.api.Enums.DimensionType; +import bloodasp.galacticgreg.api.Enums.SpaceObjectType; +import bloodasp.galacticgreg.api.Enums.TargetBlockPosition; +import bloodasp.galacticgreg.api.GTOreTypes; +import bloodasp.galacticgreg.api.ISpaceObjectGenerator; +import bloodasp.galacticgreg.api.ModDimensionDef; +import bloodasp.galacticgreg.api.SpecialBlockComb; +import bloodasp.galacticgreg.api.StructureInformation; +import bloodasp.galacticgreg.auxiliary.GTOreGroup; +import bloodasp.galacticgreg.bartworks.BW_Worldgen_Ore_Layer_Space; +import bloodasp.galacticgreg.bartworks.BW_Worldgen_Ore_SmallOre_Space; +import bloodasp.galacticgreg.dynconfig.DynamicDimensionConfig; +import bloodasp.galacticgreg.dynconfig.DynamicDimensionConfig.AsteroidConfig; +import bloodasp.galacticgreg.registry.GalacticGregRegistry; +import cpw.mods.fml.common.IWorldGenerator; +import cpw.mods.fml.common.eventhandler.EventBus; +import cpw.mods.fml.common.registry.GameRegistry; +import gregtech.api.util.GT_Log; +import gregtech.api.world.GT_Worldgen; +import gregtech.common.GT_Worldgenerator; + +public class GT_Worldgenerator_Space implements IWorldGenerator { + + public static boolean sAsteroids = true; + private final EventBus eventBus = new EventBus(); + private World worldObj; + + private int chunkX; + private int chunkZ; + private int mSize = 100; + + private long mProfilingStart; + private long mProfilingEnd; + + public GT_Worldgenerator_Space() { + GameRegistry.registerWorldGenerator(this, Integer.MAX_VALUE); + } + + public void generate(Random pRandom, int pX, int pZ, World pWorld, IChunkProvider pChunkGenerator, + IChunkProvider pChunkProvider) { + pX *= 16; + pZ *= 16; + + String tBiome = pWorld.getBiomeGenForCoords(pX + 8, pZ + 8).biomeName; + pRandom = new Random(pRandom.nextInt()); + if (tBiome == null) { + tBiome = BiomeGenBase.plains.biomeName; + } + GalacticGreg.Logger + .trace("Triggered generate: [ChunkGenerator %s] [Biome %s]", pChunkGenerator.toString(), tBiome); + + ModDimensionDef tDimDef = GalacticGregRegistry.getDimensionTypeByChunkGenerator(pChunkGenerator); + + if (tDimDef == null) { + GalacticGreg.Logger.trace( + "Ignoring ChunkGenerator type %s as there is no definition for it in the registry", + pChunkGenerator.toString()); + return; + } else { + GalacticGreg.Logger.trace("Selected DimDef: [%s]", tDimDef.getDimIdentifier()); + } + + /* + * In some later addons maybe, not for now. Ignoring Biome-based worldgen String tBiome = + * pWorld.getBiomeGenForCoords(pX + 8, pZ + 8).biomeName; pRandom = new Random(pRandom.nextInt()); if (tBiome == + * null) { tBiome = BiomeGenBase.plains.biomeName; } + */ + + if (tDimDef.getDimensionType() != DimensionType.Planet) { + if (tDimDef.getRandomAsteroidMaterial() == null) GalacticGreg.Logger.error( + "Dimension [%s] is set to Asteroids, but no asteroid material is specified! Nothing will generate", + tDimDef.getDimensionName()); + else Generate_Asteroids(tDimDef, pRandom, pWorld, pX, pZ); + } else if (tDimDef.getDimensionType() != DimensionType.Asteroid) { + Generate_OreVeins(tDimDef, pRandom, pWorld, pX, pZ, "", pChunkGenerator, pChunkProvider); + } + + Chunk tChunk = pWorld.getChunkFromBlockCoords(pX, pZ); + if (tChunk != null) { + tChunk.isModified = true; + } + } + + private void Generate_Asteroids(ModDimensionDef pDimensionDef, Random pRandom, World pWorld, int pX, int pZ) { + GalacticGreg.Logger.trace("Running asteroid-gen in Dim %s", pDimensionDef.getDimIdentifier()); + + AsteroidConfig tAConf = DynamicDimensionConfig.getAsteroidConfig(pDimensionDef); + if (tAConf == null) { + GalacticGreg.Logger.error( + "Dimension %s is set to asteroid, but no config object can be found. Skipping!", + pDimensionDef.getDimIdentifier()); + return; + } else { + GalacticGreg.Logger.trace("Asteroid probability: %d", tAConf.Probability); + } + + if ((tAConf.Probability <= 1) || (pRandom.nextInt(tAConf.Probability) == 0)) { + GalacticGreg.Logger.trace("Generating asteroid NOW"); + // --------------------------- + if (GalacticGreg.GalacticConfig.ProfileOreGen) mProfilingStart = System.currentTimeMillis(); + // ----------------------------- + + // Get Random position + int tX = pX + pRandom.nextInt(16); + int tY = 50 + pRandom.nextInt(200 - 50); + int tZ = pZ + pRandom.nextInt(16); + + // Check if position is free + if ((pWorld.getBlock(tX, tY, tZ) + .isAir(pWorld, tX, tY, tZ))) { + + int tCustomAsteroidOffset = -1; + int tGraniteMeta = 0; + + // Select Random OreGroup and Asteroid Material + GTOreGroup tOreGroup = GT_Worldgen_GT_Ore_Layer_Space.getRandomOreGroup(pDimensionDef, pRandom, true); + AsteroidBlockComb tABComb = pDimensionDef.getRandomAsteroidMaterial(); + if (tABComb == null) return; + + // Fill Vars for random Asteroid + Block tFinalAsteroidBlock = tABComb.getBlock(); + int tFinalAsteroidBlockMeta = tABComb.getMeta(); + int tFinalOreOffset = tABComb.getOreMaterial() + .getOffset(); + int tFinalUpdateMode = tABComb.getOreMaterial() + .getUpdateMode(); + GalacticGreg.Logger.debug( + "Asteroid will be build with: Block: [%s] OreType: [%s]", + Block.blockRegistry.getNameForObject(tABComb.getBlock()), + tABComb.getOreMaterial() + .toString()); + + // get random Ore-asteroid generator from the list of registered generators + ISpaceObjectGenerator aGen = pDimensionDef.getRandomSOGenerator(SpaceObjectType.OreAsteroid); + if (aGen == null) { + GalacticGreg.Logger.ot_error( + "GalacticGreg.Generate_Asteroids.NoSOGenFound", + "No SpaceObjectGenerator has been registered for type ORE_ASTEROID in Dimension %s. Nothing will generate", + pDimensionDef.getDimensionName()); + return; + } + + aGen.reset(); + aGen.setCenterPoint(tX, tY, tZ); + aGen.randomize(tAConf.MinSize, tAConf.MaxSize); // Initialize random values and set size + aGen.calculate(); // Calculate structure + + // Random loot-chest somewhere in the asteroid + Vec3 tChestPosition = Vec3.createVectorHelper(0, 0, 0); + boolean tDoLootChest = false; + int tNumLootItems = 0; + if (tAConf.LootChestChance > 0) { + GalacticGreg.Logger.trace("Random loot chest enabled, flipping the coin"); + int tChance = pRandom.nextInt(100); // Loot chest is 1 in 100 (Was: 1:1000 which actually never + // happend) + if (tAConf.LootChestChance >= tChance) { + GalacticGreg.Logger.debug("We got a match. Preparing to generate the loot chest"); + // Get amount of items for the loot chests, randomize it (1-num) if enabled + if (tAConf.RandomizeNumLootItems) tNumLootItems = pRandom.nextInt(tAConf.NumLootItems - 1) + 1; + else tNumLootItems = tAConf.NumLootItems; + + GalacticGreg.Logger + .debug(String.format("Loot chest random item count will be: %d", tNumLootItems)); + + // try to find any block that is not on the asteroids outer-shell + GalacticGreg.Logger.trace("Starting lookup for valid asteroid-block for the chest"); + for (int x = 0; x < 64; x++) // 64 enough? Should be + { + int tRndBlock = pRandom.nextInt( + aGen.getStructure() + .size()); + StructureInformation tChestSI = aGen.getStructure() + .get(tRndBlock); + if (tChestSI.getBlockPosition() != TargetBlockPosition.AsteroidShell) { + GalacticGreg.Logger.debug( + String.format( + "Chest position found [x:%d y:%d z:%d]", + tChestSI.getX(), + tChestSI.getY(), + tChestSI.getZ())); + // Found valid position "Somewhere" in the asteroid, set position... + tChestPosition = Vec3 + .createVectorHelper(tChestSI.getX(), tChestSI.getY(), tChestSI.getZ()); + // .. and set CreateFlag to true + tDoLootChest = true; + break; + } + } + } + } + + // Now build the structure + GalacticGreg.Logger.trace("Now generating Space-Structure"); + for (StructureInformation si : aGen.getStructure()) { + // Only replace airblocks + if (pWorld.isAirBlock(si.getX(), si.getY(), si.getZ())) { + // === Loot-chest generator >> + if (tDoLootChest) // If gen-lootchest enabled... + { + // Check if current x/y/z is the location where the chest shall be created + if ((int) tChestPosition.xCoord == si.getX() && (int) tChestPosition.yCoord == si.getY() + && (int) tChestPosition.zCoord == si.getZ()) { + GalacticGreg.Logger.trace("Now generating LootChest and contents"); + // Get items for the configured loot-table + WeightedRandomChestContent[] tRandomLoot = ChestGenHooks + .getItems(DynamicDimensionConfig.getLootChestTable(tAConf), pRandom); + + // Get chest-block to spawn + BlockMetaComb tTargetChestType = GalacticGreg.GalacticConfig.CustomLootChest; + + // Place down the chest + if (tTargetChestType.getMeta() > 0) pWorld.setBlock( + si.getX(), + si.getY(), + si.getZ(), + tTargetChestType.getBlock(), + tTargetChestType.getMeta(), + 2); + else pWorld.setBlock(si.getX(), si.getY(), si.getZ(), tTargetChestType.getBlock()); + + // Retrieve the TEs IInventory that should've been created + IInventory entityChestInventory = (IInventory) pWorld + .getTileEntity(si.getX(), si.getY(), si.getZ()); + // If it's not null... + if (entityChestInventory != null) { + // and if we're on the server... + if (!pWorld.isRemote) { + // Fill the chest with stuffz! + WeightedRandomChestContent.generateChestContents( + pRandom, + tRandomLoot, + entityChestInventory, + tNumLootItems); + GalacticGreg.Logger.trace("Loot chest successfully generated"); + } + } else { + // Something made a boo.. + GalacticGreg.Logger.warn( + "Could not create lootchest at X[%d] Y[%d] Z[%d]. getTileEntity() returned null", + si.getX(), + si.getY(), + si.getZ()); + } + // Make sure we never compare coordinates again (for this asteroid/Structure) + tDoLootChest = false; + // Do some debug logging + GalacticGreg.Logger + .debug("Generated LootChest at X[%d] Y[%d] Z[%d]", si.getX(), si.getY(), si.getZ()); + // And skip the rest of this function + continue; + } + } + // << Loot-chest generator === + + // === Ore generator >> + boolean tPlacedOreBlock = false; + // If a valid oregroup has been selected (more than 0 ore-veins are enabled for this dim) + if (tOreGroup != null) { + // GalacticGreg.Logger.trace("tOreGoup is populated, continuing"); + // Choose a number between 0 and 100 + int ranOre = pRandom.nextInt(100); + int tFinalOreMeta = 0; + + // If choosen number is below the configured orechance, do random between and sporadic + if (ranOre < tAConf.OreChance) { + if (pRandom.nextBoolean()) { + // Only take as final value if meta is not zero + if (tOreGroup.SporadicBetweenMeta > 0) + tFinalOreMeta = tOreGroup.SporadicBetweenMeta; + } else { + // Only take as final value if meta is not zero + if (tOreGroup.SporadicAroundMeta > 0) tFinalOreMeta = tOreGroup.SporadicAroundMeta; + } + } + // If choosen number is below the configured orechance, do random primary and secondary + // We use an offset here, so this part is always higher than the first check. + else if (ranOre < tAConf.OreChance + tAConf.OrePrimaryOffset) { + if (pRandom.nextBoolean()) { + // Only take as final value if meta is not zero + if (tOreGroup.PrimaryMeta > 0) tFinalOreMeta = tOreGroup.PrimaryMeta; + } else { + // Only take as final value if meta is not zero + if (tOreGroup.SecondaryMeta > 0) tFinalOreMeta = tOreGroup.SecondaryMeta; + } + } + + // if the final oreMeta has been found... + // GalacticGreg.Logger.info("tFinalOreMeta is %d", tFinalOreMeta); + if (tFinalOreMeta > 0) { + // make sure we obey the configured "HiddenOres" setting (No ores on the shell) + if (tAConf.HiddenOres && (si.getBlockPosition() == TargetBlockPosition.AsteroidShell)) { + // Ore would be placed around the shell, which is disabled (hiddenores) + GalacticGreg.Logger.trace( + "Skipping ore-placement event (HiddenOres=true; TargetBlockPosition=AsteroidShell)"); + } else { + // try to place the ore block. The result is stored in tPlacedOreBlock + tPlacedOreBlock = GT_TileEntity_Ores_Space.setOuterSpaceOreBlock( + pDimensionDef, + pWorld, + si.getX(), + si.getY(), + si.getZ(), + tOreGroup.SecondaryMeta, + true, + tFinalOreOffset); + } + } + } + // << Ore generator === + + // === Additional special blocks >> + // If no ore-block has been placed yet... + if (!tPlacedOreBlock) { + // try to spawn special blocks + boolean tFlag = doGenerateSpecialBlocks( + pDimensionDef, + pRandom, + pWorld, + tAConf, + si.getX(), + si.getY(), + si.getZ(), + si.getBlockPosition()); + + // No special block placed? Try smallores + if (tFlag) tFlag = doGenerateSmallOreBlock( + pDimensionDef, + pRandom, + pWorld, + tAConf, + si.getX(), + si.getY(), + si.getZ(), + tFinalOreOffset); + + // no smallores either? do normal block + if (tFlag) pWorld.setBlock( + si.getX(), + si.getY(), + si.getZ(), + tFinalAsteroidBlock, + tFinalAsteroidBlockMeta, + tFinalUpdateMode); + + } + // << Additional special blocks === + } + } + } + // --------------------------- + // OreGen profiler stuff + if (GalacticGreg.GalacticConfig.ProfileOreGen) { + try { + mProfilingEnd = System.currentTimeMillis(); + long tTotalTime = mProfilingEnd - mProfilingStart; + GalacticGreg.Profiler.AddTimeToList(pDimensionDef, tTotalTime); + GalacticGreg.Logger.debug( + "Done with Asteroid-Worldgen in DimensionType %s. Generation took %d ms", + pDimensionDef.getDimensionName(), + tTotalTime); + } catch (Exception ignored) {} // Silently ignore errors + } + // --------------------------- + } + GalacticGreg.Logger.trace("Leaving asteroid-gen for Dim %s", pDimensionDef.getDimIdentifier()); + } + + /** + * Generate Special Blocks in asteroids if enabled + * + * @param pDimensionDef + * @param pRandom + * @param pWorld + * @param tAConf + * @param eX + * @param eY + * @param eZ + * @return + */ + private boolean doGenerateSpecialBlocks(ModDimensionDef pDimensionDef, Random pRandom, World pWorld, + AsteroidConfig tAConf, int eX, int eY, int eZ, TargetBlockPosition pBlockPosition) { + + boolean tFlag = true; + // Handler to generate special BlockTypes randomly if activated + if (tAConf.SpecialBlockChance > 0) { + if (pRandom.nextInt(100) < tAConf.SpecialBlockChance) { + SpecialBlockComb bmc = pDimensionDef.getRandomSpecialAsteroidBlock(); + if (bmc != null) { + boolean tIsAllowed = false; + + switch (bmc.getBlockPosition()) { + case AsteroidCore: + if (pBlockPosition == TargetBlockPosition.AsteroidCore) tIsAllowed = true; + break; + case AsteroidCoreAndShell: + if (pBlockPosition == TargetBlockPosition.AsteroidCore + || pBlockPosition == TargetBlockPosition.AsteroidShell) tIsAllowed = true; + break; + case AsteroidShell: + if (pBlockPosition == TargetBlockPosition.AsteroidShell) tIsAllowed = true; + break; + case AsteroidInnerCore: + if (pBlockPosition == TargetBlockPosition.AsteroidInnerCore) tIsAllowed = true; + break; + default: + break; + } + + if (tIsAllowed) { + pWorld.setBlock(eX, eY, eZ, bmc.getBlock(), bmc.getMeta(), 2); + tFlag = false; + } + } + } + } + return tFlag; + } + + /** + * Pick a random small-ore block from the list of enabled small ores for this dim + * + * @param pDimDef + * @param pRandom + * @return + */ + private boolean doGenerateSmallOreBlock(ModDimensionDef pDimDef, Random pRandom, World pWorld, + AsteroidConfig pAConf, int pX, int pY, int pZ, int pTargetBlockOffset) { + boolean tFlag = true; + // If smallores are enabled... + if (pAConf.SmallOreChance > 0) { + // ... and we hit the random-chance ... + if (pRandom.nextInt(100) < pAConf.SmallOreChance) { + // Do small ores. + int tRandomWeight; + boolean continueSearch = true; + int tFoundOreMeta = -1; + BW_Worldgen_Ore_SmallOre_Space bwOreGen = null; + // First find a small ore... + for (int i = 0; (i < 256) && (continueSearch); i++) { + tRandomWeight = pRandom.nextInt(GT_Worldgen_GT_Ore_Layer_Space.sWeight); + for (GT_Worldgen tWorldGen : GalacticGreg.smallOreWorldgenList) { + if (tWorldGen instanceof BW_Worldgen_Ore_SmallOre_Space) { + tRandomWeight = ((BW_Worldgen_Ore_SmallOre_Space) tWorldGen).mDensity; + if (tRandomWeight <= 0) { + tFoundOreMeta = ((BW_Worldgen_Ore_SmallOre_Space) tWorldGen).mPrimaryMeta; + continueSearch = false; + bwOreGen = ((BW_Worldgen_Ore_SmallOre_Space) tWorldGen); + } + } else if (tWorldGen instanceof GT_Worldgen_GT_Ore_SmallPieces_Space) { + // That is enabled for *this* dim... + if (!((GT_Worldgen_GT_Ore_SmallPieces_Space) tWorldGen).isEnabledForDim(pDimDef)) continue; + + // And in the correct y-level, of ObeyLimits is true... + if (pAConf.ObeyHeightLimits + && !((GT_Worldgen_GT_Ore_SmallPieces_Space) tWorldGen).isAllowedForHeight(pY)) continue; + + // Care about weight + tRandomWeight -= ((GT_Worldgen_GT_Ore_SmallPieces_Space) tWorldGen).mAmount; + if (tRandomWeight <= 0) { + // And return found ore meta + tFoundOreMeta = ((GT_Worldgen_GT_Ore_SmallPieces_Space) tWorldGen).mMeta; + continueSearch = false; + } + } + } + } + if (tFoundOreMeta > -1) { + if (bwOreGen == null) { + // Make the oreID a small ore with correct type + int tCustomOffset = (GTOreTypes.SmallOres.getOffset() + pTargetBlockOffset); + + // Set the smallOre block + GT_TileEntity_Ores_Space + .setOuterSpaceOreBlock(pDimDef, pWorld, pX, pY, pZ, tFoundOreMeta, true, tCustomOffset); + tFlag = false; + } else { + bwOreGen.setOreBlock(pWorld, pX, pY, pZ, tFoundOreMeta, true); + } + } + } + } + return tFlag; + } + + /** + * Untested! But should work... Comments are todo + * + * @param pDimensionDef + * @param pRandom + * @param pWorld + * @param pX + * @param pZ + * @param pBiome + * @param pChunkGenerator + * @param pChunkProvider + */ + private void Generate_OreVeins(ModDimensionDef pDimensionDef, Random pRandom, World pWorld, int pX, int pZ, + String pBiome, IChunkProvider pChunkGenerator, IChunkProvider pChunkProvider) { + GalacticGreg.Logger.trace("Running orevein-gen in Dim %s", pDimensionDef.getDimIdentifier()); + + if (GT_Worldgenerator.isOreChunk(pX / 16, pZ / 16)) { + if ((GT_Worldgen_GT_Ore_Layer_Space.sWeight > 0) && (GalacticGreg.oreVeinWorldgenList.size() > 0)) { + + boolean temp = true; + int tRandomWeight; + for (int i = 0; (i < 256) && (temp); i++) { + tRandomWeight = pRandom.nextInt(GT_Worldgen_GT_Ore_Layer_Space.sWeight); + for (GT_Worldgen tWorldGen : GalacticGreg.oreVeinWorldgenList) { + if (tWorldGen instanceof GT_Worldgen_GT_Ore_Layer_Space) + tRandomWeight -= ((GT_Worldgen_GT_Ore_Layer_Space) tWorldGen).mWeight; + else if (tWorldGen instanceof BW_Worldgen_Ore_Layer_Space) + tRandomWeight -= ((BW_Worldgen_Ore_Layer_Space) tWorldGen).mWeight; + if (tRandomWeight <= 0) { + try { + if (tWorldGen.executeWorldgen( + pWorld, + pRandom, + pBiome, + Integer.MIN_VALUE, + pX, + pZ, + pChunkGenerator, + pChunkProvider)) { + temp = false; + } + } catch (Throwable e) { + e.printStackTrace(GT_Log.err); + } + break; + } + } + } + } + // Generate Small Ores + + int i = 0; + for (int tX = pX - 16; i < 3; tX += 16) { + int j = 0; + for (int tZ = pZ - 16; j < 3; tZ += 16) { + for (GT_Worldgen tWorldGen : GalacticGreg.smallOreWorldgenList) { + try { + tWorldGen.executeWorldgen( + pWorld, + pRandom, + "", + Integer.MIN_VALUE, + tX, + tZ, + pChunkGenerator, + pChunkProvider); + } catch (Throwable e) { + e.printStackTrace(GT_Log.err); + } + } + j++; + } + i++; + } + } + GalacticGreg.Logger.trace("Leaving orevein-gen for Dim %s", pDimensionDef.getDimIdentifier()); + } +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/GalacticGreg.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/GalacticGreg.java new file mode 100644 index 0000000000..3becbcb92b --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/GalacticGreg.java @@ -0,0 +1,143 @@ +package bloodasp.galacticgreg; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import bloodasp.galacticgreg.auxiliary.GalacticGregConfig; +import bloodasp.galacticgreg.auxiliary.LogHelper; +import bloodasp.galacticgreg.auxiliary.ProfilingStorage; +import bloodasp.galacticgreg.bartworks.BW_Worldgen_Ore_Layer_Space; +import bloodasp.galacticgreg.bartworks.BW_Worldgen_Ore_SmallOre_Space; +import bloodasp.galacticgreg.command.AEStorageCommand; +import bloodasp.galacticgreg.command.ProfilingCommand; +import bloodasp.galacticgreg.registry.GalacticGregRegistry; +import bloodasp.galacticgreg.schematics.SpaceSchematicHandler; +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.Mod; +import cpw.mods.fml.common.Mod.EventHandler; +import cpw.mods.fml.common.event.FMLPostInitializationEvent; +import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import cpw.mods.fml.common.event.FMLServerStartingEvent; +import gregtech.api.GregTech_API; +import gregtech.api.world.GT_Worldgen; + +@Mod( + modid = GalacticGreg.MODID, + name = GalacticGreg.MODNAME, + version = GalacticGreg.VERSION, + dependencies = "required-after:GalacticraftCore; required-after:gregtech@5.09.32.30;", + acceptableRemoteVersions = "*") +public class GalacticGreg { + + public static final List<GT_Worldgen> smallOreWorldgenList = new ArrayList<>(); + public static final List<GT_Worldgen> oreVeinWorldgenList = new ArrayList<>(); + + public static final String NICE_MODID = "GalacticGreg"; + public static final String MODID = "galacticgreg"; + public static final String MODNAME = "Galactic Greg"; + + public static final String VERSION = "GRADLETOKEN_VERSION"; + + public static final LogHelper Logger = new LogHelper(NICE_MODID); + public static ProfilingStorage Profiler = new ProfilingStorage(); + public static SpaceSchematicHandler SchematicHandler; + + public static Random GalacticRandom = null; + + public static GalacticGregConfig GalacticConfig = null; + + /** + * Preload phase. Read config values and set various features.. n stuff... + * + * @param aEvent + */ + @EventHandler + public void onPreLoad(FMLPreInitializationEvent aEvent) { + GalacticConfig = new GalacticGregConfig(aEvent.getModConfigurationDirectory(), NICE_MODID, NICE_MODID); + if (!GalacticConfig.LoadConfig()) GalacticGreg.Logger + .warn("Something went wrong while reading GalacticGregs config file. Things will be wonky.."); + + GalacticRandom = new Random(System.currentTimeMillis()); + + if (GalacticConfig.SchematicsEnabled) + SchematicHandler = new SpaceSchematicHandler(aEvent.getModConfigurationDirectory()); + + Logger.trace("Leaving PRELOAD"); + } + + // @EventHandler + // public void onLoad(FMLInitializationEvent event){ + // GalacticGregRegistry.registerModContainer(ModRegisterer.Setup_GalactiCraftCore()); + // } + + public static final ArrayList<Runnable> ADDITIONALVEINREGISTER = new ArrayList<>(); + + /** + * Postload phase. Mods can add their custom definition to our api in their own PreLoad or Init-phase Once + * GalacticGregRegistry.InitRegistry() is called, no changes are accepted. (Well you can with reflection, but on a + * "normal" way it's not possible) + * + * @param aEvent + */ + @EventHandler + public void onPostLoad(FMLPostInitializationEvent aEvent) { + Logger.trace("Entering POSTLOAD"); + + if (!GalacticGregRegistry.InitRegistry()) throw new RuntimeException( + "GalacticGreg registry has been finalized from a 3rd-party mod, this is forbidden!"); + + // new WorldGenGaGT().run(); DO NOT UNCOMMENT, was moved to gregtech.loaders.postload.GT_Worldgenloader + + if (Loader.isModLoaded("bartworks")) { + for (int f = 0, + j = GregTech_API.sWorldgenFile.get("worldgen.GaGregBartworks", "AmountOfCustomLargeVeinSlots", 0); f + < j; f++) { + new BW_Worldgen_Ore_Layer_Space( + "mix.custom." + (f < 10 ? "0" : "") + f, + GregTech_API.sWorldgenFile + .get("worldgen.GaGregBartworks." + "mix.custom." + (f < 10 ? "0" : "") + f, "Enabled", false)); + } + + for (int f = 0, + j = GregTech_API.sWorldgenFile.get("worldgen.GaGregBartworks", "AmountOfCustomSmallSlots", 0); f + < j; f++) { + new BW_Worldgen_Ore_SmallOre_Space( + "small.custom." + (f < 10 ? "0" : "") + f, + GregTech_API.sWorldgenFile.get( + "worldgen.GaGregBartworks." + "small.custom." + (f < 10 ? "0" : "") + f, + "Enabled", + false)); + } + } + + for (Runnable r : ADDITIONALVEINREGISTER) { + try { + r.run(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + GalacticConfig.serverPostInit(); + + Logger.trace("Leaving POSTLOAD"); + } + + /** + * If oregen profiling is enabled, then register the command + * + * @param pEvent + */ + @EventHandler + public void serverLoad(FMLServerStartingEvent pEvent) { + Logger.trace("Entering SERVERLOAD"); + + if (GalacticConfig.ProfileOreGen) pEvent.registerServerCommand(new ProfilingCommand()); + + if (Loader.isModLoaded("appliedenergistics2") && GalacticConfig.EnableAEExportCommand + && GalacticConfig.SchematicsEnabled) pEvent.registerServerCommand(new AEStorageCommand()); + + Logger.trace("Leaving SERVERLOAD"); + } +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/ModRegisterer.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/ModRegisterer.java new file mode 100644 index 0000000000..889cee0ca6 --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/ModRegisterer.java @@ -0,0 +1,283 @@ +package bloodasp.galacticgreg; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.init.Blocks; +import net.minecraft.world.gen.ChunkProviderEnd; + +import bloodasp.galacticgreg.api.AsteroidBlockComb; +import bloodasp.galacticgreg.api.Enums; +import bloodasp.galacticgreg.api.Enums.AllowedBlockPosition; +import bloodasp.galacticgreg.api.Enums.DimensionType; +import bloodasp.galacticgreg.api.GTOreTypes; +import bloodasp.galacticgreg.api.ModContainer; +import bloodasp.galacticgreg.api.ModDBMDef; +import bloodasp.galacticgreg.api.ModDimensionDef; +import bloodasp.galacticgreg.api.SpecialBlockComb; + +/** + * In this class, you'll find everything you need in order to tell GGreg what to do and where. Everything is done in + * here. If you're trying to use anything else, you're probably doing something wrong (Or I forgot to add it. In that + * case, find me on github and create an issue please) + */ +public class ModRegisterer { + + /** + * Just a helper to convert a single element to a list + * + * @param pDef + * @return + */ + private static List<ModDBMDef> singleToList(ModDBMDef pDef) { + List<ModDBMDef> tLst = new ArrayList<>(); + tLst.add(pDef); + return tLst; + } + + private static Method registerModContainer; + + /** + * Use loose binding of the register-method. Should be enough to provide support for GGreg without the requirement + * to have it in a modpack at all + * + * @param pModContainer + */ + public static void registerModContainer(ModContainer pModContainer) { + /* + * try { registerModContainer.invoke(null, pModContainer); } catch (Exception e) { e.printStackTrace(); } + */ + } + + /** + * Try to get the instance of GalacticGregs registry in order to register stuff + * + * @return + */ + public boolean Init() { + return false; + /* + * try { Class gGregRegistry = Class.forName("bloodasp.galacticgreg.registry.GalacticGregRegistry"); + * registerModContainer = gGregRegistry.getMethod("registerModContainer", ModContainer.class); return true; } + * catch (Exception e) { // GalacticGreg is not installed or something is wrong return false; } + */ + } + + public void Register() { + /* + * if (GalacticGreg.GalacticConfig.RegisterVanillaDim) registerModContainer(Setup_Vanilla()); if + * (GalacticGreg.GalacticConfig.RegisterGalacticCraftCore) registerModContainer(Setup_GalactiCraftCore()); if + * (GalacticGreg.GalacticConfig.RegisterGalacticCraftPlanets) registerModContainer(Setup_GalactiCraftPlanets()); + * if (GalacticGreg.GalacticConfig.RegisterGalaxySpace) registerModContainer(Setup_GalaxySpace()); + */ + } + + /** + * Vanilla MC (End Asteroids) + */ + private ModContainer Setup_Vanilla() { + // --- Mod Vanilla (Heh, "mod") + ModContainer modMCVanilla = new ModContainer("Vanilla"); + + // If you happen to have an asteroid dim, just skip the blocklist, and setDimensionType() to + // DimensionType.Asteroid + // also don't forget to add at least one asteroid type, or nothing will generate! + ModDimensionDef dimEndAsteroids = new ModDimensionDef( + "EndAsteroids", + ChunkProviderEnd.class, + DimensionType.Asteroid); + + dimEndAsteroids.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.Netherrack)); + dimEndAsteroids.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.RedGranite)); + dimEndAsteroids.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.BlackGranite)); + dimEndAsteroids.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.EndStone)); + + // These Blocks will randomly be generated + dimEndAsteroids.addSpecialAsteroidBlock(new SpecialBlockComb(Blocks.glowstone)); + dimEndAsteroids.addSpecialAsteroidBlock(new SpecialBlockComb(Blocks.lava, AllowedBlockPosition.AsteroidCore)); + + modMCVanilla.addDimensionDef(dimEndAsteroids); + + return modMCVanilla; + } + + /** + * Mod GalactiCraft Just another setup based on existing classes, due the fact that we're working with GalactiCraft + */ + public static ModContainer Setup_GalactiCraftCore() { + ModContainer modGCraftCore = new ModContainer("GalacticraftCore"); + ModDBMDef DBMMoon = new ModDBMDef("tile.moonBlock", 4); + + ModDimensionDef tMoonDim = new ModDimensionDef( + "Moon", + "micdoodle8.mods.galacticraft.core.world.gen.ChunkProviderMoon", + Enums.DimensionType.Planet, + singleToList(DBMMoon)); + modGCraftCore.addDimensionDef(tMoonDim); + + return modGCraftCore; + } + + /** + * As GalactiCraftPlanets is an optional mod, don't hardlink it here + * + * @return + */ + private ModContainer Setup_GalactiCraftPlanets() { + ModContainer modGCraftPlanets = new ModContainer("GalacticraftMars"); + ModDBMDef DBMMars = new ModDBMDef("tile.mars", 9); + ModDimensionDef dimMars = new ModDimensionDef( + "Mars", + "micdoodle8.mods.galacticraft.planets.mars.world.gen.ChunkProviderMars", + DimensionType.Planet, + singleToList(DBMMars)); + + // Overwrite ore blocks on mars with red granite ones. This will default to regular stone if not set + dimMars.setStoneType(GTOreTypes.RedGranite); + modGCraftPlanets.addDimensionDef(dimMars); + + ModDimensionDef dimAsteroids = new ModDimensionDef( + "Asteroids", + "micdoodle8.mods.galacticraft.planets.asteroids.world.gen.ChunkProviderAsteroids", + DimensionType.Asteroid); + dimAsteroids.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.BlackGranite)); + dimAsteroids.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.RedGranite)); + dimAsteroids.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.Netherrack)); + modGCraftPlanets.addDimensionDef(dimAsteroids); + + return modGCraftPlanets; + } + + /** + * Mod GalaxySpace by BlesseNtumble + */ + private ModContainer Setup_GalaxySpace() { + // First, we create a mod-container that will be populated with dimensions later. + // The Name must match your modID, as it is checked if this mod is loaded, in order + // to enable/disable the parsing/registering of dimensions + ModContainer modCGalaxySpace = new ModContainer("GalaxySpace"); + + // Now lets first define a block here for our dimension. You can add the modID, but you don't have to. + // It will automatically add the mods name that is defined in the modcontainer. + ModDBMDef DBMPhobos = new ModDBMDef("phobosstone"); + ModDBMDef DBMDeimos = new ModDBMDef("deimossubgrunt"); + ModDBMDef DBMCeres = new ModDBMDef("ceressubgrunt"); + ModDBMDef DBMIO = new ModDBMDef("iorock", 4); // This meta-4 is a copy&paste bug in GSpace and might not work in + // further versions + ModDBMDef DBMGanymede = new ModDBMDef("ganymedesubgrunt"); + ModDBMDef DBMCallisto = new ModDBMDef("callistosubice"); + ModDBMDef DBMVenus = new ModDBMDef("venussubgrunt"); + ModDBMDef DBMMercury = new ModDBMDef("mercurycore"); + ModDBMDef DBMEnceladus = new ModDBMDef("enceladusrock"); + ModDBMDef DBMTitan = new ModDBMDef("titanstone"); + ModDBMDef DBMOberon = new ModDBMDef("oberonstone"); + ModDBMDef DBMProteus = new ModDBMDef("proteusstone"); + ModDBMDef DBMTriton = new ModDBMDef("tritonstone"); + ModDBMDef DBMPluto = new ModDBMDef("plutostone"); + + // Now define the available dimensions, and their chunkprovider. + // Same as above, to not have any dependency in your code, you can just give it a string. + // But it's better to use the actual ChunkProvider class. The Name is used for the GalacticGreg config file. + // The resulting config setting will be: <ModID>_<Name you give here as arg0>_false = false + // make sure to never change this name once you've generated your config files, as it will overwrite everything! + + // 25.10.2015 GSpace v2.5 + modCGalaxySpace.addDimensionDef( + new ModDimensionDef( + "Pluto", + "blessentumble.planets.SolarSystem.pluto.dimension.ChunkProviderPluto", + DimensionType.Planet, + singleToList(DBMPluto))); + modCGalaxySpace.addDimensionDef( + new ModDimensionDef( + "Triton", + "blessentumble.moons.triton.dimension.ChunkProviderTriton", + DimensionType.Planet, + singleToList(DBMTriton))); + modCGalaxySpace.addDimensionDef( + new ModDimensionDef( + "Proteus", + "blessentumble.moons.proteus.dimension.ChunkProviderProteus", + DimensionType.Planet, + singleToList(DBMProteus))); + modCGalaxySpace.addDimensionDef( + new ModDimensionDef( + "Oberon", + "blessentumble.moons.oberon.dimension.ChunkProviderOberon", + DimensionType.Planet, + singleToList(DBMOberon))); + modCGalaxySpace.addDimensionDef( + new ModDimensionDef( + "Titan", + "blessentumble.moons.titan.dimension.ChunkProviderTitan", + DimensionType.Planet, + singleToList(DBMTitan))); + modCGalaxySpace.addDimensionDef( + new ModDimensionDef( + "Callisto", + "blessentumble.moons.SolarSystem.callisto.dimension.ChunkProviderCallisto", + DimensionType.Planet, + singleToList(DBMCallisto))); + modCGalaxySpace.addDimensionDef( + new ModDimensionDef( + "Ganymede", + "blessentumble.moons.ganymede.dimension.ChunkProviderGanymede", + DimensionType.Planet, + singleToList(DBMGanymede))); + modCGalaxySpace.addDimensionDef( + new ModDimensionDef( + "Ceres", + "blessentumble.planets.SolarSystem.ceres.dimension.ChunkProviderCeres", + DimensionType.Planet, + singleToList(DBMCeres))); + modCGalaxySpace.addDimensionDef( + new ModDimensionDef( + "Deimos", + "blessentumble.moons.SolarSystem.deimos.dimension.ChunkProviderDeimos", + DimensionType.Planet, + singleToList(DBMDeimos))); + modCGalaxySpace.addDimensionDef( + new ModDimensionDef( + "Enceladus", + "blessentumble.moons.SolarSystem.enceladus.dimension.ChunkProviderEnceladus", + DimensionType.Planet, + singleToList(DBMEnceladus))); + modCGalaxySpace.addDimensionDef( + new ModDimensionDef( + "Io", + "blessentumble.moons.io.dimension.ChunkProviderIo", + DimensionType.Planet, + singleToList(DBMIO))); + modCGalaxySpace.addDimensionDef( + new ModDimensionDef( + "Phobos", + "blessentumble.moons.phobos.dimension.ChunkProviderPhobos", + DimensionType.Planet, + singleToList(DBMPhobos))); + modCGalaxySpace.addDimensionDef( + new ModDimensionDef( + "Venus", + "blessentumble.planets.SolarSystem.venus.dimension.ChunkProviderVenus", + DimensionType.Planet, + singleToList(DBMVenus))); + modCGalaxySpace.addDimensionDef( + new ModDimensionDef( + "Mercury", + "blessentumble.planets.SolarSystem.mercury.dimension.ChunkProviderMercury", + DimensionType.Planet, + singleToList(DBMMercury))); + + // GSpace 2.2-Beta: Kupierbelt + ModDimensionDef dimKupierBelt = new ModDimensionDef( + "Kuiperbelt", + "blessentumble.planets.SolarSystem.kuiperbelt.dimension.ChunkProviderKuiper", + DimensionType.Asteroid); + dimKupierBelt.setDimensionType(DimensionType.Asteroid); + dimKupierBelt.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.RedGranite)); + dimKupierBelt.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.BlackGranite)); + modCGalaxySpace.addDimensionDef(dimKupierBelt); + + return modCGalaxySpace; + } +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/WorldGenGaGT.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/WorldGenGaGT.java new file mode 100644 index 0000000000..90f51ec7e1 --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/WorldGenGaGT.java @@ -0,0 +1,89 @@ +package bloodasp.galacticgreg; + +import gregtech.common.GT_Worldgen_GT_Ore_Layer; +import gregtech.common.GT_Worldgen_GT_Ore_SmallPieces; + +public class WorldGenGaGT implements Runnable { + + @Override + public void run() { + new GT_Worldgenerator_Space(); + + /* + * new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.copper", true, 60, 120, 32, Materials.Copper); new + * GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.tin", true, 60, 120, 32, Materials.Tin); new + * GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.bismuth", true, 80, 120, 8, Materials.Bismuth); new + * GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.coal", true, 60, 100, 24, Materials.Coal); new + * GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.iron", true, 40, 80, 16, Materials.Iron); new + * GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.lead", true, 40, 80, 16, Materials.Lead); new + * GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.zinc", true, 30, 60, 12, Materials.Zinc); new + * GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.gold", true, 20, 40, 8, Materials.Gold); new + * GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.silver", true, 20, 40, 8, Materials.Silver); new + * GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.nickel", true, 20, 40, 8, Materials.Nickel); new + * GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.lapis", true, 20, 40, 4, Materials.Lapis); new + * GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.diamond", true, 5, 10, 2, Materials.Diamond); new + * GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.redstone", true, 5, 20, 8, Materials.Redstone); new + * GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.platinum", true, 20, 40, 8, Materials.Platinum); new + * GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.iridium", true, 20, 40, 8, Materials.Iridium); new + * GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.netherquartz", true, 30, 120, 64, Materials.NetherQuartz); + * new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.saltpeter", true, 10, 60, 8, Materials.Saltpeter); new + * GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.sulfur_n", true, 10, 60, 32, Materials.Sulfur); new + * GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.sulfur_o", true, 5, 15, 8, Materials.Sulfur); new + * GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.emerald", true, 5, 250, 1, Materials.Emerald); new + * GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.ruby", true, 5, 250, 1, Materials.Ruby); new + * GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.sapphire", true, 5, 250, 1, Materials.Sapphire); new + * GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.greensapphire", true, 5, 250, 1, Materials.GreenSapphire); + * new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.olivine", true, 5, 250, 1, Materials.Olivine); new + * GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.topaz", true, 5, 250, 1, Materials.Topaz); new + * GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.tanzanite", true, 5, 250, 1, Materials.Tanzanite); new + * GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.amethyst", true, 5, 250, 1, Materials.Amethyst); new + * GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.opal", true, 5, 250, 1, Materials.Opal); new + * GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.jasper", true, 5, 250, 1, Materials.Jasper); new + * GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.bluetopaz", true, 5, 250, 1, Materials.BlueTopaz); new + * GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.amber", true, 5, 250, 1, Materials.Amber); new + * GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.foolsruby", true, 5, 250, 1, Materials.FoolsRuby); new + * GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.garnetred", true, 5, 250, 1, Materials.GarnetRed); new + * GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.garnetyellow", true, 5, 250, 1, Materials.GarnetYellow); + */ + /* + * This part here enables every GT Small Ore for Space Dims. + */ + for (int k = 0; k < GT_Worldgen_GT_Ore_SmallPieces.sList.size(); ++k) { + new GT_Worldgen_GT_Ore_SmallPieces_Space( + GT_Worldgen_GT_Ore_SmallPieces.sList.get(k).mWorldGenName, + GT_Worldgen_GT_Ore_SmallPieces.sList.get(k).mEnabled, + GT_Worldgen_GT_Ore_SmallPieces.sList.get(k).mMinY, + GT_Worldgen_GT_Ore_SmallPieces.sList.get(k).mMaxY, + GT_Worldgen_GT_Ore_SmallPieces.sList.get(k).mAmount, + GT_Worldgen_GT_Ore_SmallPieces.sList.get(k).mMeta); + } + + /* + * This part here enables every GT Ore for Space Dims. + */ + for (int k = 0; k < GT_Worldgen_GT_Ore_Layer.sList.size(); ++k) { + new GT_Worldgen_GT_Ore_Layer_Space( + GT_Worldgen_GT_Ore_Layer.sList.get(k).mWorldGenName, + GT_Worldgen_GT_Ore_Layer.sList.get(k).mEnabled, + GT_Worldgen_GT_Ore_Layer.sList.get(k).mMinY, + GT_Worldgen_GT_Ore_Layer.sList.get(k).mMaxY, + GT_Worldgen_GT_Ore_Layer.sList.get(k).mWeight, + GT_Worldgen_GT_Ore_Layer.sList.get(k).mDensity, + GT_Worldgen_GT_Ore_Layer.sList.get(k).mSize, + GT_Worldgen_GT_Ore_Layer.sList.get(k).mPrimaryMeta, + GT_Worldgen_GT_Ore_Layer.sList.get(k).mSecondaryMeta, + GT_Worldgen_GT_Ore_Layer.sList.get(k).mBetweenMeta, + GT_Worldgen_GT_Ore_Layer.sList.get(k).mSporadicMeta); + } + + /* + * int f = 0; for (int j = GregTech_API.sWorldgenFile.get("worldgen", "AmountOfCustomSmallOreSlots", 16); f < j; + * f++) { new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.custom." + (f < 10 ? "0" : "") + f, false, 0, 0, + * 0, Materials._NULL); } int i = 0; for (int j = GregTech_API.sWorldgenFile.get("worldgen", + * "AmountOfCustomLargeVeinSlots", 16); i < j; i++) { new GT_Worldgen_GT_Ore_Layer_Space("ore.mix.custom." + (i + * < 10 ? "0" : "") + i, false, 0, 0, 0, 0, 0, Materials._NULL, Materials._NULL, Materials._NULL, + * Materials._NULL); } + */ + } + +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/api/AsteroidBlockComb.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/api/AsteroidBlockComb.java new file mode 100644 index 0000000000..7976eadc0a --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/api/AsteroidBlockComb.java @@ -0,0 +1,77 @@ +package bloodasp.galacticgreg.api; + +import net.minecraft.block.Block; + +/** + * Class for a bit more advanced combinations for Asteroids, which supports Custom Blocks as base material and Values + * required to generate Gregtech ores + */ +public class AsteroidBlockComb extends BlockMetaComb { + + private final GTOreTypes _mGTOreMaterial; + + /** + * Create an advanced definition which uses the GregTech-OreType values for ores, and your own definition of Block + * for the asteroid material + * + * @param pOreType The GregTech oreType + * @param pBlock Your block + */ + public AsteroidBlockComb(GTOreTypes pOreType, Block pBlock) { + super(pBlock, 0); + _mGTOreMaterial = pOreType; + } + + /** + * Create an advanced definition which uses the GregTech-OreType values for ores, and your own definition of Block + * for the asteroid material + * + * @param pOreType The GregTech oreType + * @param pBlock Your block + * @param pMeta The metavalue for your block (If required) + */ + public AsteroidBlockComb(GTOreTypes pOreType, Block pBlock, int pMeta) { + super(pBlock, pMeta); + _mGTOreMaterial = pOreType; + } + + /** + * Create a simple definition which uses the GregTech-OreType values for both asteroidStone and ores + * + * @param pOreType The GregTech oreType + */ + public AsteroidBlockComb(GTOreTypes pOreType) { + super(pOreType.getBlock(), pOreType.getMeta()); + _mGTOreMaterial = pOreType; + } + + /** + * Internal function + * + * @return The GT Material for the oregen + */ + public GTOreTypes getOreMaterial() { + return _mGTOreMaterial; + } + + @Override + public boolean equals(Object other) { + if (other == null) return false; + if (other == this) return true; + if (!(other instanceof AsteroidBlockComb)) return false; + AsteroidBlockComb otherObj = (AsteroidBlockComb) other; + + boolean tFlag = true; + String otherName = Block.blockRegistry.getNameForObject(otherObj.getBlock()); + String thisName = Block.blockRegistry.getNameForObject(this.getBlock()); + if (otherName != null && thisName != null) { + if (!otherName.equals(thisName)) tFlag = false; + + if (!(otherObj.getMeta() == this.getMeta())) tFlag = false; + + if (!(otherObj.getOreMaterial() == this.getOreMaterial())) tFlag = false; + } else tFlag = false; + + return tFlag; + } +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/api/BlockMetaComb.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/api/BlockMetaComb.java new file mode 100644 index 0000000000..7bf504d144 --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/api/BlockMetaComb.java @@ -0,0 +1,50 @@ +package bloodasp.galacticgreg.api; + +import net.minecraft.block.Block; + +/** + * Class used for Simple Block - Meta constructs + */ +public class BlockMetaComb { + + private int mMeta; + private Block mBlock; + + /** + * Creates a simple instance for a block that has no meta value + * + * @param pBlock The Block in question. 0 is used as meta + */ + public BlockMetaComb(Block pBlock) { + this(pBlock, 0); + } + + /** + * Creates a simple instance for a block with a meta value + * + * @param pBlock The Block in question + * @param pMeta The MetaValue in question ([block]:[meta]) + */ + public BlockMetaComb(Block pBlock, int pMeta) { + mMeta = pMeta; + mBlock = pBlock; + } + + /** + * Internal function + * + * @return The metadata for this block + */ + public int getMeta() { + return mMeta; + } + + /** + * Internal function + * + * @return The block + */ + public Block getBlock() { + return mBlock; + } +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/api/Enums.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/api/Enums.java new file mode 100644 index 0000000000..0c8afaf243 --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/api/Enums.java @@ -0,0 +1,57 @@ +package bloodasp.galacticgreg.api; + +public class Enums { + + public enum SpaceObjectType { + OreAsteroid, + NonOreSchematic + } + + public enum TargetBlockPosition { + Invalid, + AsteroidInnerCore, + AsteroidCore, + AsteroidShell, + StructureBlock + } + + public enum AllowedBlockPosition { + AsteroidInnerCore, + AsteroidCore, + AsteroidShell, + AsteroidCoreAndShell + } + + public enum AirReplaceRule { + NeverReplaceAir, + AllowReplaceAir, + OnlyReplaceAir + } + + public enum ReplaceState { + Unknown, + Airblock, + CanReplace, + CannotReplace + } + + public enum DimensionType { + /** + * The Dimension is a void dimension and asteroids shall be generated. They will randomly spawn bewteen 0 and + * 250 Additional config values will be generated in worldconfig + */ + Asteroid, + + /** + * The Dimension is a planet, and only ores shall be generated in the ground + */ + Planet, + + /** + * The Dimension is a special dim where Asteroids *and* ores shall spawn. Additional config values will be + * generated in worldconfig + */ + AsteroidAndPlanet + } + +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/api/GTOreTypes.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/api/GTOreTypes.java new file mode 100644 index 0000000000..dedbc8f5cc --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/api/GTOreTypes.java @@ -0,0 +1,66 @@ +package bloodasp.galacticgreg.api; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; + +import gregtech.api.GregTech_API; + +/** + * Representation of the various GregTech ores, with their counterpart in VanillaBlocks, and the OreOffset that is + * required to generate the proper ores + */ +public enum GTOreTypes { + + /** + * The Definition for Gregtech's RedGranite + **/ + RedGranite(4000, GregTech_API.sBlockGranites, 8, 3), + /** + * The Definition for Gregtech's BlackGranite + */ + BlackGranite(3000, GregTech_API.sBlockGranites, 0, 3), + /** + * The Definition for EndStone + */ + EndStone(2000, Blocks.end_stone, 0, 0), + /** + * The Definition for Netherrack + */ + Netherrack(1000, Blocks.netherrack, 0, 0), // Unsure about blockupdate value! + /** + * The Definition for SmallOres (And BlockType Stone) + */ + SmallOres(16000, Blocks.stone, 0, 0), // Unsure about blockupdate value! + /** + * The Definition for Ores (And BlockType Stone) + */ + NormalOres(0, Blocks.stone, 0, 0); // Unsure about blockupdate value! + + private int _mOffset; + private Block _mStoneBlock; + private int _mBlockMeta; + private int _mUpdateMode; + + GTOreTypes(int pOffset, Block pBlock, int pMeta, int pUpdateMode) { + _mOffset = pOffset; + _mStoneBlock = pBlock; + _mBlockMeta = pMeta; + _mUpdateMode = pUpdateMode; + } + + public Block getBlock() { + return _mStoneBlock; + } + + public int getMeta() { + return _mBlockMeta; + } + + public int getOffset() { + return _mOffset; + } + + public int getUpdateMode() { + return _mUpdateMode; + } +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/api/ISpaceObjectGenerator.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/api/ISpaceObjectGenerator.java new file mode 100644 index 0000000000..881efa08eb --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/api/ISpaceObjectGenerator.java @@ -0,0 +1,58 @@ +package bloodasp.galacticgreg.api; + +import java.util.List; + +import net.minecraft.util.Vec3; + +import bloodasp.galacticgreg.api.Enums.SpaceObjectType; + +public interface ISpaceObjectGenerator { + + Vec3 getCenterPoint(); + + /** + * Set the center-point of the object to generate, by providing X, Y and Z directly + * + * @param pX + * @param pY + * @param pZ + */ + void setCenterPoint(int pX, int pY, int pZ); + + /** + * Set the center-point of the object to generate, by providing a Vec3 instance + * + * @param pCenter + */ + void setCenterPoint(Vec3 pCenter); + + List<StructureInformation> getStructure(); + + /** + * Calculate the structure Called after randomize() + */ + void calculate(); + + /** + * Randomize the structure. Called before calculate() + * + * @param pSizeMin The minimum size for the structure. It is up to you how you handle this value. it's what the user + * sets in his config file + * @param pSizeMax The maximum size for the structure. It is up to you how you handle this value. it's what the user + * sets in his config file + */ + void randomize(int pSizeMin, int pSizeMax); + + /** + * Define the type of the generator. OreAsteroid will be used to spawn ores at given coordinates, where + * NonOreSchematic will use the Blocks provided in the structural information to generate your structure + * + * @return + */ + SpaceObjectType getType(); + + /** + * This function is called every time the generator shall be reset in order to generate a blank, new structure + */ + void reset(); +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/api/ModContainer.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/api/ModContainer.java new file mode 100644 index 0000000000..b5416b164f --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/api/ModContainer.java @@ -0,0 +1,85 @@ +package bloodasp.galacticgreg.api; + +import java.util.ArrayList; +import java.util.List; + +/** + * Defines a Mod where this Generator shall be active. Note: This will only work (obviously) for Dimensions where + * either: - Gregtech has a hook in the OreGen or - For mods which are addons to GalactiCraft + * + */ +public class ModContainer { + + private String _mModName; + private List<ModDimensionDef> _mDimensionLookup; + private boolean _mEnabled = false; + + /** + * Internal function + * + * @return The state if the Registry could find the mod or not + */ + public boolean getEnabled() { + return _mEnabled; + } + + /** + * Internal function + * + * Never set this to true. This is an internal marker which is set by the registry if the mod could be found or not + * + * @param pEnabled + */ + public void setEnabled(boolean pEnabled) { + _mEnabled = pEnabled; + } + + /** + * Define a new Mod where GT OreGen shall be enabled + * + * @param pModName The modID. Make sure to use the proper mod-id, or it won't load correctly + */ + public ModContainer(String pModName) { + _mModName = pModName; + _mDimensionLookup = new ArrayList<>(); + } + + /** + * Internal function + * + * @return The mods name + */ + public String getModName() { + return _mModName; + } + + /** + * Internal function + * + * @return The list of attached dimensions for this mod + */ + public List<ModDimensionDef> getDimensionList() { + return _mDimensionLookup; + } + + /** + * Adds a new dimension to this modcontainer. Make sure you've added all blocks there first + * + * @param pDimDef The dimension definition to be added + * @return true if it could be added, false if not + */ + public boolean addDimensionDef(ModDimensionDef pDimDef) { + for (ModDimensionDef mdd : _mDimensionLookup) { + if (mdd.getChunkProviderName() + .equals(pDimDef.getChunkProviderName())) { + // Cannot add DimensionDefinition; The Given chunk-provider name is already taken! + return false; + } + } + + // Set the parent modName of this dimension. This will finalize it + pDimDef.setParentModName(_mModName); + _mDimensionLookup.add(pDimDef); + return true; + } +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/api/ModDBMDef.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/api/ModDBMDef.java new file mode 100644 index 0000000000..bd0df8652b --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/api/ModDBMDef.java @@ -0,0 +1,165 @@ +package bloodasp.galacticgreg.api; + +import net.minecraft.block.Block; + +import bloodasp.galacticgreg.api.Enums.ReplaceState; + +/** + * Mod "Dimension Block Meta Definition" Defines the Block-Meta combination for Blocks that can be replaced by the + * oregen. + * + */ +public class ModDBMDef { + + private String _targetBlockName; + private int _targetMeta; + private boolean _canAlwaysReplace; + + public String getBlockName() { + return _targetBlockName; + } + + public int getMeta() { + return _targetMeta; + } + + public boolean getCanAlwaysReplace() { + return _canAlwaysReplace; + } + + /** + * Internal function + * + * Check if the given Block is equal to the block in this instance + * + * @param pBlock the Block in question + * @return + */ + public ReplaceState blockEquals(Block pBlock) { + if (pBlock == null) return ReplaceState.Unknown; + + if (Block.blockRegistry.getNameForObject(pBlock) + .equals(_targetBlockName)) return ReplaceState.CanReplace; + else return ReplaceState.CannotReplace; + } + + /** + * Internal function + * + * Check if the given Block is equal to the block in this instance and matches the metadata + * + * @param pBlock the block in question + * @param pMeta the metadata in question + * @return + */ + public ReplaceState blockEquals(Block pBlock, int pMeta) { + ReplaceState tFlag = ReplaceState.Unknown; + if (blockEquals(pBlock) == ReplaceState.CanReplace) { + if (pMeta == _targetMeta || _canAlwaysReplace) tFlag = ReplaceState.CanReplace; + else tFlag = ReplaceState.CannotReplace; + } + + return tFlag; + } + + @Override + public boolean equals(Object other) { + if (other == null) return false; + if (other == this) return true; + if (!(other instanceof ModDBMDef)) return false; + ModDBMDef otherModDBMDef = (ModDBMDef) other; + return (otherModDBMDef._targetBlockName.equals(_targetBlockName) && otherModDBMDef._targetMeta == _targetMeta); + } + + /** + * Create a new "Block that can be replaced by ores" definition. Meta defaults to 0 here + * + * @param pTargetBlockName The unlocalizedName of the block + */ + public ModDBMDef(String pTargetBlockName) { + this(pTargetBlockName, 0, false); + } + + /** + * Create a new "Block that can be replaced by ores" definition + * + * @param pTargetBlockName The unlocalizedName of the block + * @param pMetaData The blocks metadata + */ + public ModDBMDef(String pTargetBlockName, int pMetaData) { + this(pTargetBlockName, pMetaData, false); + } + + /** + * Create a new "Block that can be replaced by ores" definition + * + * @param pTargetBlock The instance of the block that can be replaced + * @param pMetaData The blocks metadata + */ + public ModDBMDef(Block pTargetBlock, int pMetaData) { + this(Block.blockRegistry.getNameForObject(pTargetBlock), pMetaData, false); + } + + /** + * Create a new "Block that can be replaced by ores" definition. Meta defaults to 0 here + * + * @param pTargetBlock The instance of the block that can be replaced + */ + public ModDBMDef(Block pTargetBlock) { + this(Block.blockRegistry.getNameForObject(pTargetBlock), 0, false); + } + + /** + * Create a new "Block that can be replaced by ores" definition + * + * @param pTargetBlock + * @param pCanAlwaysReplace set to true if this block can always be replaced, regardless of it's metavalue. Like: + * [block]:* + */ + public ModDBMDef(Block pTargetBlock, boolean pCanAlwaysReplace) { + this(Block.blockRegistry.getNameForObject(pTargetBlock), -1, pCanAlwaysReplace); + } + + /** + * Create a new "Block that can be replaced by ores" definition + * + * @param pTargetBlockName The unlocalizedName of the block + * @param pCanAlwaysReplace set to true if this block can always be replaced, regardless of it's metavalue. Like: + * [block]:* + */ + public ModDBMDef(String pTargetBlockName, boolean pCanAlwaysReplace) { + this(pTargetBlockName, -1, false); + } + + /** + * Create a new "Block that can be replaced by ores" definition + * + * @param pTargetBlockName The unlocalizedName of the block + * @param pMetaData The blocks metadata + * @param pCanAlwaysReplace set to true if this block can always be replaced, regardless of it's metavalue. Like: + * [block]:* + */ + public ModDBMDef(String pTargetBlockName, int pMetaData, boolean pCanAlwaysReplace) { + _targetBlockName = pTargetBlockName; + _targetMeta = pMetaData; + _canAlwaysReplace = pCanAlwaysReplace; + } + + /** + * Internal function Never run this function. It is used to update the blocks name when GalacticGreg is initializing + * its internal structures + * + * @param pParentModName The modname to be attached to the block-name + */ + public void updateBlockName(String pParentModName) { + // Do we already have a FQBN? then do nothing + if (_targetBlockName.contains(":")) { + // GalacticGreg.Logger.trace("Not updating blockname, as it already contains a mods name: %s", + // _targetBlockName); + return; + } + // GalacticGreg.Logger.trace("Updating blockname: Old: %s new: %s:%s", _targetBlockName, pParentModName, + // _targetBlockName); + _targetBlockName = String.format("%s:%s", pParentModName, _targetBlockName); + } +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/api/ModDimensionDef.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/api/ModDimensionDef.java new file mode 100644 index 0000000000..4b634173f1 --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/api/ModDimensionDef.java @@ -0,0 +1,470 @@ +package bloodasp.galacticgreg.api; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.world.chunk.IChunkProvider; + +import bloodasp.galacticgreg.api.Enums.AirReplaceRule; +import bloodasp.galacticgreg.api.Enums.DimensionType; +import bloodasp.galacticgreg.api.Enums.ReplaceState; +import bloodasp.galacticgreg.api.Enums.SpaceObjectType; + +// import bloodasp.galacticgreg.GalacticGreg; + +/** + * Class to define a Dimension. Supposed to be added to a ModContainer + */ +public class ModDimensionDef { + + private static final String STR_NOTDEFINED = "iiznotdefined"; + private String _mDimensionName; + private String _mInternalDimIdentifier; + private String _mChunkProvider; + private AirReplaceRule _mDimAirSetting; + private ArrayList<ModDBMDef> _mReplaceableBlocks; + private DimensionType _mDimensionType; + + private List<ISpaceObjectGenerator> _mSpaceObjectsGenerators; + private List<ISpaceObjectGenerator> _mSpaceStructureGenerators; + + // Special Planets config settings + private int _mGroundOreMaxY = 64; + private int _mFloatingAsteroidsMinY = 128; + // ------ + + // Override for stonetype + private GTOreTypes _mStoneType; + + // Asteroid stuff + private List<AsteroidBlockComb> _mValidAsteroidMaterials; + private List<SpecialBlockComb> _mSpecialBlocksForAsteroids; + + private Random _mRandom = new Random(System.currentTimeMillis()); + + /** + * Internal function + * + * @return A list of possible asteroid-mixes that shall be generated + */ + public List<AsteroidBlockComb> getValidAsteroidMaterials() { + return _mValidAsteroidMaterials; + } + + // ================================================= + /** + * Internal function The only purpose of this functions is to get a default config value for this dim, that can be + * altered by the mod author which adds the dimension definition to his mod, but also provide the + * modpack-author/serveradmin to change these values aswell + */ + public int getPreConfiguratedGroundOreMaxY() { + return _mGroundOreMaxY; + } + + /** + * Internal function The only purpose of this functions is to get a default config value for this dim, that can be + * altered by the mod author which adds the dimension definition to his mod, but also provide the + * modpack-author/serveradmin to change these values aswell + */ + public int getPreConfiguratedFloatingAsteroidMinY() { + return _mFloatingAsteroidsMinY; + } + + /** + * Register new generator for objects in space. You can register as many as you want. If you don't register + * anything, no structures will generate and the default Asteroid-Generator will be used + * + * @param pSpaceObjectGenerator An instance of your own object generator + */ + public void registerSpaceObjectGenerator(ISpaceObjectGenerator pSpaceObjectGenerator) { + SpaceObjectType tType = pSpaceObjectGenerator.getType(); + switch (tType) { + case NonOreSchematic: + _mSpaceStructureGenerators.add(pSpaceObjectGenerator); + break; + case OreAsteroid: + _mSpaceObjectsGenerators.add(pSpaceObjectGenerator); + break; + default: + // GalacticGreg.Logger.error("registerSpaceObjectGenerator() found unhandled generator type %s. Please + // report asap, the author was lazy!", tType.toString()); + break; + + } + } + + /** + * Internal function Return a random generator for space objects + */ + public ISpaceObjectGenerator getRandomSOGenerator(SpaceObjectType pTargetType) { + ISpaceObjectGenerator tGen = null; + List<ISpaceObjectGenerator> tLst = null; + try { + switch (pTargetType) { + case NonOreSchematic: + tLst = _mSpaceStructureGenerators; + break; + case OreAsteroid: + tLst = _mSpaceObjectsGenerators; + break; + default: + break; + } + + if (tLst != null) { + if (tLst.size() == 1) tGen = tLst.get(0); + else if (tLst.size() > 1) tGen = tLst.get(_mRandom.nextInt(tLst.size())); + } + } catch (Exception e) { + e.printStackTrace(); + } + return tGen; + } + + /** + * Define the default values for the floating asteroids and the oregen here. As both generators run in the same + * dimension, and you probably don't want to have asteroids stuck in the ground, both generators are separated from + * each other. Basically, you can go with the default values. If you want to change them, make sure that pOregenMaxY + * is lower than pAsteroidMinY + * + * @param pOregenMaxY The maximum Y-height where ores will be allowed to spawn. Default: 64 + * @param pAsteroidMinY The minimum Y-height that has to be reached before asteroids will spawn. Default: 128 + * @throws IllegalArgumentException if the limits are invalid + * + */ + public void setAsteroidAndPlanetLimits(int pOregenMaxY, int pAsteroidMinY) { + if (pOregenMaxY >= pAsteroidMinY) + throw new IllegalArgumentException("pOregenMaxY must be LOWER than pAsteroidMinY!"); + + _mFloatingAsteroidsMinY = pAsteroidMinY; + _mGroundOreMaxY = pOregenMaxY; + } + // ================================================= + + /** + * Internal function + * + * @return A list of all special blocks that shall be used to generate the asteroids. + */ + public List<SpecialBlockComb> getSpecialBlocksForAsteroids() { + return _mSpecialBlocksForAsteroids; + } + + public List<ISpaceObjectGenerator> getSpaceObjectGenerators() { + return _mSpaceObjectsGenerators; + } + + /** + * Internal function + * + * @return The type for this dimension + */ + public DimensionType getDimensionType() { + return _mDimensionType; + } + + /** + * Set whether this DimensionDefinition defines an void-dimension that shall spawn asteroids instead of ores in + * stone + * + * @param pType The dimensiontype to be used + */ + public void setDimensionType(DimensionType pType) { + _mDimensionType = pType; + } + + /** + * Internal function + * + * @return The configuration for AirBlocks + */ + public AirReplaceRule getAirSetting() { + return _mDimAirSetting; + } + + /** + * Define how the oregen shall handle air-blocks. These settings should be pretty self-explandatory, but anyways: + * NeverReplaceAir: No matter what, if there is an Air-Block found, it will not replace it. AllowReplaceAir: This + * will generate Ores in Stones (defined by addBlockDefinition()) and air if found OnlyReplaceAir : This will not + * generate Ores in solid blocks, but only in air + * + * Note that "OnlyReplaceAir" is a special setting if you have a dimension that is not defined as "Asteroids" but + * you still need/want to generate ores in midair. + * + * @param pSetting + */ + public void setAirSetting(AirReplaceRule pSetting) { + _mDimAirSetting = pSetting; + } + + /** + * Internal function + * + * @return The dimension identifier that is used internally to identify the dimension + */ + public String getDimIdentifier() { + return _mInternalDimIdentifier; + } + + /** + * Set a manual override for ores that shall be generated. This setting is ignored if getIsAsteroidDimension() + * returns true + * + * For example, on GalactiCraft Mars, this value is set to GTOreTypes.RedGranite, because it matches the color + * better. If you don't set anything here, it will generate regular stone-ores. + * + * @param pStoneType + */ + public void setStoneType(GTOreTypes pStoneType) { + _mStoneType = pStoneType; + } + + /** + * Internal function + * + * @return The stone override for gregtech ores + */ + public GTOreTypes getStoneType() { + return _mStoneType; + } + + /** + * Internal function + * + * @return The attached chunk-provider for this dimension + */ + public String getChunkProviderName() { + return _mChunkProvider; + } + + /** + * Adds a new blockdefinition to this dimension. This block will then later be replaced by ores. You can add as many + * blocks as you want. Just don't add Blocks.Air, as there is another setting for allowing Air-Replacement + * + * @param pBlockDef + * @return + */ + public boolean addBlockDefinition(ModDBMDef pBlockDef) { + if (_mReplaceableBlocks.contains(pBlockDef)) { + // GalacticGreg.Logger.error("Cannot add Block %s:%d, as it is already existing!", pBlockDef.getBlockName(), + // pBlockDef.getMeta()); + return false; + } else { + _mReplaceableBlocks.add(pBlockDef); + return true; + } + } + + /** + * Internal function + * + * @return The DimensionName in a Human-readable format + */ + public String getDimensionName() { + return _mDimensionName; + } + + /** + * Internal function + * + * @return A list of all defined Blocks that can be replaced while generating ores + */ + public ArrayList<ModDBMDef> getReplaceableBlocks() { + return _mReplaceableBlocks; + } + + /** + * Define a new dimension + * + * @param pDimensionName The human-readable. Spaces will be removed + * @param pChunkProvider The chunkprovider class that shall be observed for the oregen + */ + public ModDimensionDef(String pDimensionName, Class<? extends IChunkProvider> pChunkProvider, + DimensionType pDimType) { + this( + pDimensionName, + pChunkProvider.toString() + .substring(6), + pDimType, + null); + } + + /** + * Define a new dimension + * + * @param pDimensionName The human-readable. Spaces will be removed + * @param pChunkProvider The chunkprovider class that shall be observed for the oregen + * @param pBlockDefinitions The list of predefined blocks to be replaced by ores + */ + public ModDimensionDef(String pDimensionName, Class<? extends IChunkProvider> pChunkProvider, + DimensionType pDimType, List<ModDBMDef> pBlockDefinitions) { + this( + pDimensionName, + pChunkProvider.toString() + .substring(6), + pDimType, + pBlockDefinitions); + } + + /** + * Define a new dimension + * + * @param pDimensionName The human-readable DimensionName. Spaces will be removed + * @param pChunkProviderName The human-readable, full-qualified classname for the chunkprovider + */ + public ModDimensionDef(String pDimensionName, String pChunkProviderName, DimensionType pDimType) { + this(pDimensionName, pChunkProviderName, pDimType, null); + } + + /** + * Define a new dimension + * + * @param pDimensionName The human-readable DimensionName. Spaces will be removed + * @param pChunkProviderName The human-readable, full-qualified classname for the chunkprovider + * @param pBlockDefinitions The list of predefined blocks to be replaced by ores + */ + public ModDimensionDef(String pDimensionName, String pChunkProviderName, DimensionType pDimType, + List<ModDBMDef> pBlockDefinitions) { + _mInternalDimIdentifier = STR_NOTDEFINED; + _mDimensionName = pDimensionName; + _mChunkProvider = pChunkProviderName; + _mDimensionType = pDimType; + + _mReplaceableBlocks = new ArrayList<>(); + if (pBlockDefinitions != null) _mReplaceableBlocks.addAll(pBlockDefinitions); + + _mValidAsteroidMaterials = new ArrayList<>(); + _mSpecialBlocksForAsteroids = new ArrayList<>(); + _mSpaceObjectsGenerators = new ArrayList<>(); + _mSpaceStructureGenerators = new ArrayList<>(); + } + + /** + * Internal function + * + * Do not call this function by yourself. Ever. It will cause explosions, water to blood, death of firstborn,... + * Seriously, don't do it. + */ + protected void setParentModName(String pModName) { + if (_mInternalDimIdentifier.equals(STR_NOTDEFINED)) { + _mInternalDimIdentifier = String.format("%s_%s", pModName, _mDimensionName); + // GalacticGreg.Logger.debug("Set Internal Identifier for Dimension %s to %s", _mDimensionName, + // _mInternalDimIdentifier); + } + + // Else Don't update, we're already set + + } + + /** + * Internal function + * + * Check if pBlock can be replaced by an ore + * + * @param pBlock + * @param pMeta + * @return + */ + public ReplaceState getReplaceStateForBlock(Block pBlock, int pMeta) { + ReplaceState tFlag = ReplaceState.Unknown; + + for (ModDBMDef pDef : _mReplaceableBlocks) { + ReplaceState tResult = pDef.blockEquals(pBlock, pMeta); + if (tResult == ReplaceState.Unknown) continue; + + if (tResult == ReplaceState.CanReplace) { + // GalacticGreg.Logger.trace("Targetblock found and metadata match. Replacement allowed"); + tFlag = ReplaceState.CanReplace; + } else if (tResult == ReplaceState.CannotReplace) { + // GalacticGreg.Logger.trace("Targetblock found but metadata mismatch. Replacement denied"); + tFlag = ReplaceState.CannotReplace; + } + break; + } + + return tFlag; + } + + /** + * Internal function + * + * Randomly select one material out of all defined materials + * + * @return + */ + public AsteroidBlockComb getRandomAsteroidMaterial() { + if (_mValidAsteroidMaterials.size() == 0) return null; + + if (_mValidAsteroidMaterials.size() == 1) return _mValidAsteroidMaterials.get(0); + else { + return _mValidAsteroidMaterials.get(_mRandom.nextInt(_mValidAsteroidMaterials.size())); + } + } + + /** + * Internal function + * + * Randomly select one special block to be placed in the asteroids + * + * @return + */ + public SpecialBlockComb getRandomSpecialAsteroidBlock() { + if (_mSpecialBlocksForAsteroids.size() == 0) return null; + + if (_mSpecialBlocksForAsteroids.size() == 1) return _mSpecialBlocksForAsteroids.get(0); + else { + return _mSpecialBlocksForAsteroids.get(_mRandom.nextInt(_mSpecialBlocksForAsteroids.size())); + } + } + + /** + * Define the material the asteroid shall be made of. Limited to GT-Based Ores and their stones + * + * @param pMaterial + */ + public void addAsteroidMaterial(GTOreTypes pMaterial) { + addAsteroidMaterial(new AsteroidBlockComb(pMaterial)); + } + + /** + * Define the material the asteroid shall be made of, more advanced option to specify your own blocks + * + * @param pBlockComb + */ + public void addAsteroidMaterial(AsteroidBlockComb pBlockComb) { + if (!_mValidAsteroidMaterials.contains(pBlockComb)) { + _mValidAsteroidMaterials.add(pBlockComb); + } + } + + /** + * Adds a new material for asteroid generation. These will spawn randomly in asteroids if enabled. You can basically + * add every block you can imagine. Be warned though, if you use Liquids (Water / Lava / ..), it can affect + * performance if the liquid is flowing down to the void. So make sure you define "AsteroidCore" as position + * + * @param pBlock Block-Meta Combination that shall be used + */ + public void addSpecialAsteroidBlock(SpecialBlockComb pBlock) { + if (!_mSpecialBlocksForAsteroids.contains(pBlock)) { + _mSpecialBlocksForAsteroids.add(pBlock); + } + } + + /** + * Internal function Called when GalacticGreg will finalize all its internal structures. You should never call this + * yourself + */ + public void finalizeReplaceableBlocks(String pParentModName) { + for (ModDBMDef rpb : _mReplaceableBlocks) { + try { + rpb.updateBlockName(pParentModName); + if (_mStoneType == null) _mStoneType = GTOreTypes.NormalOres; + } catch (Exception e) { + // GalacticGreg.Logger.error("Unable to finalize replaceable block with modname for block %s. Dimension + // %s will probably have problems generating ores", rpb.getBlockName(), _mDimensionName); + } + } + } +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/api/SpecialBlockComb.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/api/SpecialBlockComb.java new file mode 100644 index 0000000000..d5f6feb1ca --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/api/SpecialBlockComb.java @@ -0,0 +1,71 @@ +package bloodasp.galacticgreg.api; + +import net.minecraft.block.Block; + +import bloodasp.galacticgreg.api.Enums.AllowedBlockPosition; + +public class SpecialBlockComb extends BlockMetaComb { + + private AllowedBlockPosition _mBlockPosition; + + /** + * Creates a simple instance for a block that has a meta value and a block position it is allowed to spawn + * + * @param pBlock The Block in question + * @param pMeta The meta value of the block + * @param pBlockPosition The position this block is allowed to generate + */ + public SpecialBlockComb(Block pBlock, int pMeta, AllowedBlockPosition pBlockPosition) { + super(pBlock, pMeta); + _mBlockPosition = pBlockPosition; + } + + /** + * Creates a simple instance for a block that has no meta value but a position it is allowed to spawn + * + * @param pBlock The Block in question. 0 is used as meta + * @param pBlockPosition The position this block is allowed to generate + */ + public SpecialBlockComb(Block pBlock, AllowedBlockPosition pBlockPosition) { + super(pBlock, 0); + _mBlockPosition = pBlockPosition; + } + + /** + * Creates a simple instance for a block that has no meta value and is allowed to spawn everywhere + * + * @param pBlock The Block in question. 0 is used as meta, and "CoreAndShell" is used as position + */ + public SpecialBlockComb(Block pBlock) { + super(pBlock, 0); + _mBlockPosition = AllowedBlockPosition.AsteroidCoreAndShell; + } + + /** + * Internal function + * + * @return The position the block is supposed to spawn at + */ + public AllowedBlockPosition getBlockPosition() { + return _mBlockPosition; + } + + @Override + public boolean equals(Object other) { + if (other == null) return false; + if (other == this) return true; + if (!(other instanceof SpecialBlockComb)) return false; + SpecialBlockComb otherObj = (SpecialBlockComb) other; + + boolean tFlag = true; + String otherName = Block.blockRegistry.getNameForObject(otherObj.getBlock()); + String thisName = Block.blockRegistry.getNameForObject(this.getBlock()); + if (!otherName.equals(thisName)) tFlag = false; + + if (!(otherObj.getMeta() == this.getMeta())) tFlag = false; + + if (!(otherObj.getBlockPosition() == this.getBlockPosition())) tFlag = false; + + return tFlag; + } +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/api/StructureInformation.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/api/StructureInformation.java new file mode 100644 index 0000000000..db205e3ef7 --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/api/StructureInformation.java @@ -0,0 +1,59 @@ +package bloodasp.galacticgreg.api; + +import net.minecraft.util.Vec3; + +import bloodasp.galacticgreg.api.Enums.TargetBlockPosition; + +/** + * Structural information container. Holds X/Y/Z and block/meta information + */ +public class StructureInformation { + + private Vec3 _mCoordinates; + private TargetBlockPosition _mBlockPosition; + private BlockMetaComb _mBlockMetaComb; + + public TargetBlockPosition getBlockPosition() { + return _mBlockPosition; + } + + public int getX() { + return (int) Math.round(_mCoordinates.xCoord); + } + + public int getY() { + return (int) Math.round(_mCoordinates.yCoord); + } + + public int getZ() { + return (int) Math.round(_mCoordinates.zCoord); + } + + public BlockMetaComb getBlock() { + return _mBlockMetaComb; + } + + /** + * Init StructureInfo only with Coords and block position + * + * @param pCoordinates The coords in question + * @param pPosition The position-enum value + */ + public StructureInformation(Vec3 pCoordinates, TargetBlockPosition pPosition) { + this(pCoordinates, pPosition, null); + } + + /** + * Init StructureInfo with Coords, block position and a populated block/meta info + * + * @param pCoordinates The coords in question + * @param pPosition The position-enum value + * @param pTargetBlock The target block in question + */ + public StructureInformation(Vec3 pCoordinates, TargetBlockPosition pPosition, BlockMetaComb pTargetBlock) { + _mCoordinates = pCoordinates; + _mBlockPosition = pPosition; + _mBlockMetaComb = pTargetBlock; + } + +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/auxiliary/ConfigManager.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/auxiliary/ConfigManager.java new file mode 100644 index 0000000000..34f7a5cc8b --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/auxiliary/ConfigManager.java @@ -0,0 +1,79 @@ +package bloodasp.galacticgreg.auxiliary; + +import java.io.File; + +import net.minecraftforge.common.config.Configuration; + +import bloodasp.galacticgreg.GalacticGreg; + +/** + * config class to read/setup config files and folders + * + * @author Namikon + */ +public abstract class ConfigManager { + + private File _mainconfigDir = null; + private File _blocksconfigDir = null; + private String _mModCollection = ""; + private String _mModID = ""; + + protected Configuration _mainConfig = null; + + protected File _mConfigBaseDirectory; + public boolean DoDebugMessages = false; + + protected abstract void PreInit(); + + protected abstract void Init(); + + protected abstract void PostInit(); + + public ConfigManager(File pConfigBaseDirectory, String pModCollectionDirectory, String pModID) { + _mModCollection = pModCollectionDirectory; + _mModID = pModID; + _mConfigBaseDirectory = pConfigBaseDirectory; + } + + /** + * Load/init the config file + * + * @return true/false if the load/init was successful or not + */ + public boolean LoadConfig() { + try { + InitConfigDirs(); + if (_mainConfig == null) return false; + + PreInit(); + _mainConfig.load(); + Init(); + _mainConfig.save(); + PostInit(); + + return true; + } catch (Exception e) { + GalacticGreg.Logger.error("Unable to init config file"); + e.printStackTrace(); + return false; + } + } + + /** + * Search for required config-directory / file and create them if they can't be found + */ + private void InitConfigDirs() { + GalacticGreg.Logger.debug("Checking/creating config folders"); + + _mainconfigDir = new File(String.format("%s%s%s", _mConfigBaseDirectory, File.separator, _mModCollection)); + + if (!_mainconfigDir.exists()) { + GalacticGreg.Logger.info("Config folder not found. Creating..."); + _mainconfigDir.mkdir(); + } + + File tRealConfigFile = new File(String.format("%s%s%s%s", _mainconfigDir, File.separator, _mModID, ".cfg")); + + _mainConfig = new Configuration(tRealConfigFile); + } +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/auxiliary/GTOreGroup.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/auxiliary/GTOreGroup.java new file mode 100644 index 0000000000..8361a2bda9 --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/auxiliary/GTOreGroup.java @@ -0,0 +1,19 @@ +package bloodasp.galacticgreg.auxiliary; + +/** + * Just a simple container to wrap 4 GT Ore-Meta ids into one var + */ +public class GTOreGroup { + + public short PrimaryMeta; + public short SecondaryMeta; + public short SporadicBetweenMeta; + public short SporadicAroundMeta; + + public GTOreGroup(short pPrimaryMeta, short pSecondaryMeta, short pSporadicBetweenMeta, short pSporadicAroundMeta) { + PrimaryMeta = pPrimaryMeta; + SecondaryMeta = pSecondaryMeta; + SporadicBetweenMeta = pSporadicBetweenMeta; + SporadicAroundMeta = pSporadicAroundMeta; + } +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/auxiliary/GalacticGregConfig.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/auxiliary/GalacticGregConfig.java new file mode 100644 index 0000000000..156e620959 --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/auxiliary/GalacticGregConfig.java @@ -0,0 +1,141 @@ +package bloodasp.galacticgreg.auxiliary; + +import java.io.File; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; + +import bloodasp.galacticgreg.GalacticGreg; +import bloodasp.galacticgreg.api.BlockMetaComb; +import cpw.mods.fml.common.registry.GameRegistry; + +public class GalacticGregConfig extends ConfigManager { + + public GalacticGregConfig(File pConfigBaseDirectory, String pModCollectionDirectory, String pModID) { + super(pConfigBaseDirectory, pModCollectionDirectory, pModID); + + } + + public boolean ProfileOreGen; + public boolean ReportOreGenFailures; + public boolean PrintDebugMessagesToFMLLog; + public boolean PrintTraceMessagesToFMLLog; + + public boolean LootChestsEnabled; + public boolean EnableAEExportCommand; + public boolean SchematicsEnabled; + public String LootChestItemOverride; + public boolean QuietMode; + + public BlockMetaComb CustomLootChest; + + @Override + protected void PreInit() { + ProfileOreGen = false; + ReportOreGenFailures = false; + PrintDebugMessagesToFMLLog = false; + PrintTraceMessagesToFMLLog = false; + + LootChestsEnabled = true; + + // Default false, as it is WiP + EnableAEExportCommand = false; + SchematicsEnabled = false; + + LootChestItemOverride = ""; + QuietMode = false; + } + + @Override + protected void Init() { + ProfileOreGen = _mainConfig.getBoolean( + "ProfileOreGen", + "Debug", + ProfileOreGen, + "Enable to profile oregen and register the ingame command ggregprofiler"); + ReportOreGenFailures = _mainConfig.getBoolean( + "ReportOreGenFailures", + "Debug", + ReportOreGenFailures, + "Report if a ore tileentity could not be placed"); + PrintDebugMessagesToFMLLog = _mainConfig.getBoolean( + "PrintDebugMessagesToFMLLog", + "Debug", + PrintDebugMessagesToFMLLog, + "Enable debug output, not recommended for servers"); + PrintTraceMessagesToFMLLog = _mainConfig.getBoolean( + "PrintTraceMessagesToFMLLog", + "Debug", + PrintTraceMessagesToFMLLog, + "Enable trace output. Warning: This will produce gazillions of log entries"); + QuietMode = _mainConfig.getBoolean( + "QuietMode", + "Debug", + QuietMode, + "In quiet-mode only errors, warnings and fatals will be printed to the logfile/console"); + + LootChestsEnabled = _mainConfig.getBoolean( + "LootChestsEnabled", + "Extras", + LootChestsEnabled, + "Enables/disables the dungeon-chest generator system for asteroids. New config values will be generated if set to true"); + EnableAEExportCommand = _mainConfig.getBoolean( + "EnableAEExportCommand", + "Extras", + EnableAEExportCommand, + "If set to true, you can export any structure stored on a AE2 spatial storage disk. (Can't be spawned yet, WiP). Requires SchematicsEnabled to be true"); + SchematicsEnabled = _mainConfig.getBoolean( + "SchematicsEnabled", + "Extras", + SchematicsEnabled, + "Enable the experimental Schematics-handler to spawn exported schematics in dimensions. This is WiP, use at own risk"); + LootChestItemOverride = _mainConfig.getString( + "CustomLootChest", + "Extras", + LootChestItemOverride, + "Define the chest you wish to use as LootChest. use the <ModID>:<Name>:<meta> format or leave empty for the default Minecraft Chest"); + + GalacticGreg.Logger.setDebugOutput(PrintDebugMessagesToFMLLog); + GalacticGreg.Logger.setTraceOutput(PrintTraceMessagesToFMLLog); + GalacticGreg.Logger.setQuietMode(QuietMode); + } + + @Override + protected void PostInit() { + + } + + public boolean serverPostInit() { + CustomLootChest = new BlockMetaComb(Blocks.chest); + try { + if (LootChestItemOverride != "") { + String[] args = LootChestItemOverride.split(":"); + String tMod; + String tName; + int tMeta; + + if (args.length >= 2) { + tMod = args[0]; + tName = args[1]; + if (args.length == 3) tMeta = Integer.parseInt(args[2]); + else tMeta = 0; + + Block tBlock = GameRegistry.findBlock(tMod, tName); + if (tBlock != null) { + GalacticGreg.Logger + .debug("Found valid ChestOverride: %s. LootChest replaced", LootChestItemOverride); + CustomLootChest = new BlockMetaComb(tBlock, tMeta); + } + } + } + + return true; + } catch (Exception e) { + GalacticGreg.Logger.error( + "Unable to find custom chest override %s. Make sure item exists. Defaulting to Minecraft:chest", + LootChestItemOverride); + e.printStackTrace(); + return false; + } + } +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/auxiliary/LogHelper.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/auxiliary/LogHelper.java new file mode 100644 index 0000000000..c8b450c27a --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/auxiliary/LogHelper.java @@ -0,0 +1,267 @@ +package bloodasp.galacticgreg.auxiliary; + +import java.util.ArrayList; + +import org.apache.logging.log4j.Level; + +import cpw.mods.fml.common.FMLLog; + +/** + * Generic LogHelper to print stuff to the console + * + * @author Namikon + */ +public final class LogHelper { + + private ArrayList<String> _mReportedCategories = new ArrayList<>(); + private boolean doDebugLogs = false; + private boolean doTraceLogs = false; + private boolean quietMode = false; + private String _mModID = ""; + + private final static String STR_NOCAT = "ihaznocathegory"; + private final static String STR_TOKEN_ONETIMEMESSAGE = " OTM"; + + public LogHelper(String pModID) { + _mModID = pModID; + } + + /** + * If true, only error/fatal/warn messages will be printed + * + * @param pEnabled + */ + public void setQuietMode(boolean pEnabled) { + quietMode = pEnabled; + } + + /** + * Enable/Disable debug logs + * + * @param pEnabled + */ + public void setDebugOutput(boolean pEnabled) { + doDebugLogs = pEnabled; + } + + /** + * Enable/Disable trace logs + * + * @param pEnabled + */ + public void setTraceOutput(boolean pEnabled) { + doTraceLogs = pEnabled; + } + + /** + * Resets all One-Time categories, so they will be displayed again + */ + public void ResetCategories() { + _mReportedCategories = new ArrayList<>(); + } + + /** + * Print a log-message with built-in String.format(x) support. This message will only appear once. usefull for + * error/warnings within loops + * + * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will + * never be displayed + * @param pLogLevel The logLevel for this message + * @param pMessage The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void log(String pCategory, Level pLogLevel, String pMessage, Object... args) { + if (pLogLevel == Level.DEBUG && !doDebugLogs) return; + + if (pLogLevel == Level.TRACE && !doTraceLogs) return; + + if (pLogLevel != Level.ERROR && pLogLevel != Level.FATAL && pLogLevel != Level.WARN) if (quietMode) return; + + String tt = ""; + if (!pCategory.equals(STR_NOCAT)) { + tt = STR_TOKEN_ONETIMEMESSAGE; + if (_mReportedCategories.contains(pCategory)) return; + else { + _mReportedCategories.add(pCategory); + } + } + + FMLLog.log(_mModID.toUpperCase() + tt, pLogLevel, pMessage, args); + } + + /** + * Prints a one-time message with Category ALL + * + * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will + * never be displayed + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void ot_all(String pCategory, String object, Object... args) { + log(pCategory, Level.ALL, object, args); + } + + /** + * Prints a one-time message with Category DEBUG + * + * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will + * never be displayed + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void ot_debug(String pCategory, String object, Object... args) { + log(pCategory, Level.DEBUG, object, args); + } + + /** + * Prints a one-time message with Category ERROR + * + * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will + * never be displayed + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void ot_error(String pCategory, String object, Object... args) { + log(pCategory, Level.ERROR, object, args); + } + + /** + * Prints a one-time message with Category FATAL + * + * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will + * never be displayed + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void ot_fatal(String pCategory, String object, Object... args) { + log(pCategory, Level.FATAL, object, args); + } + + /** + * Prints a one-time message with Category INFO + * + * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will + * never be displayed + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void ot_info(String pCategory, String object, Object... args) { + log(pCategory, Level.INFO, object, args); + } + + /** + * Prints a one-time message with Category OFF + * + * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will + * never be displayed + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void ot_off(String pCategory, String object, Object... args) { + log(pCategory, Level.OFF, object, args); + } + + /** + * Prints a one-time message with Category TRACE + * + * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will + * never be displayed + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void ot_trace(String pCategory, String object, Object... args) { + log(pCategory, Level.TRACE, object, args); + } + + /** + * Prints a one-time message with Category WARN + * + * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will + * never be displayed + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void ot_warn(String pCategory, String object, Object... args) { + log(pCategory, Level.WARN, object, args); + } + + /** + * Prints a message with Category ALL + * + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void all(String object, Object... args) { + log(STR_NOCAT, Level.ALL, object, args); + } + + /** + * Prints a message with Category DEBUG + * + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void debug(String object, Object... args) { + log(STR_NOCAT, Level.DEBUG, object, args); + } + + /** + * Prints a message with Category ERROR + * + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void error(String object, Object... args) { + log(STR_NOCAT, Level.ERROR, object, args); + } + + /** + * Prints a message with Category FATAL + * + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void fatal(String object, Object... args) { + log(STR_NOCAT, Level.FATAL, object, args); + } + + /** + * Prints a message with Category INFO + * + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void info(String object, Object... args) { + log(STR_NOCAT, Level.INFO, object, args); + } + + /** + * Prints a message with Category OFF + * + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void off(String object, Object... args) { + log(STR_NOCAT, Level.OFF, object, args); + } + + /** + * Prints a message with Category TRACE + * + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void trace(String object, Object... args) { + log(STR_NOCAT, Level.TRACE, object, args); + } + + /** + * Prints a message with Category WARN + * + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void warn(String object, Object... args) { + log(STR_NOCAT, Level.WARN, object, args); + } +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/auxiliary/PlayerChatHelper.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/auxiliary/PlayerChatHelper.java new file mode 100644 index 0000000000..409775ea1a --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/auxiliary/PlayerChatHelper.java @@ -0,0 +1,106 @@ +package bloodasp.galacticgreg.auxiliary; + +import net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; + +/** + * Method to easily send chat-messages to EntityPlayer + * + * @author Namikon + * + */ +public class PlayerChatHelper { + + /** + * Meant for notifications that are being send to an admin/op Color will be GREEN + * + * @param pPlayer + * @param pMessage + */ + public static void SendInfo(ICommandSender pCommandSender, String pMessage) { + pCommandSender.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + pMessage)); + } + + /** + * Meant for notifications that are being send to an admin/op Color will be RED + * + * @param pPlayer + * @param pMessage + */ + public static void SendError(ICommandSender pCommandSender, String pMessage) { + pCommandSender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + pMessage)); + } + + /** + * Meant for notifications that are being send to an admin/op Color will be YELLOW + * + * @param pPlayer + * @param pMessage + */ + public static void SendWarn(ICommandSender pCommandSender, String pMessage) { + pCommandSender.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + pMessage)); + } + + /** + * Meant for notifications that are being send to an admin/op Color will be GREEN + * + * @param pPlayer + * @param pMessage + */ + public static void SendInfo(EntityPlayer pPlayer, String pMessage) { + pPlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + pMessage)); + } + + /** + * Meant for notifications that are being send to an admin/op Color will be RED + * + * @param pPlayer + * @param pMessage + */ + public static void SendError(EntityPlayer pPlayer, String pMessage) { + pPlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + pMessage)); + } + + /** + * Meant for notifications that are being send to an admin/op Color will be YELLOW + * + * @param pPlayer + * @param pMessage + */ + public static void SendWarn(EntityPlayer pPlayer, String pMessage) { + pPlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + pMessage)); + } + + /** + * Meant for ingame notifications that are being send to a player, not an admin/op Color will be DARK_GREEN + * + * @param pPlayer + * @param pMessage + */ + public static void SendNotifyPositive(EntityPlayer pPlayer, String pMessage) { + pPlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.DARK_GREEN + pMessage)); + } + + /** + * Meant for ingame notifications that are being send to a player, not an admin/op Color will be AQUA + * + * @param pPlayer + * @param pMessage + */ + public static void SendNotifyNormal(EntityPlayer pPlayer, String pMessage) { + pPlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.AQUA + pMessage)); + } + + /** + * Meant for ingame notifications that are being send to a player, not an admin/op Color will be DARK_PURPLE + * + * @param pPlayer + * @param pMessage + */ + public static void SendNotifyWarning(EntityPlayer pPlayer, String pMessage) { + pPlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.DARK_PURPLE + pMessage)); + } + +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/auxiliary/ProfilingStorage.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/auxiliary/ProfilingStorage.java new file mode 100644 index 0000000000..3510c31341 --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/auxiliary/ProfilingStorage.java @@ -0,0 +1,74 @@ +package bloodasp.galacticgreg.auxiliary; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import bloodasp.galacticgreg.api.ModDimensionDef; + +/** + * A simple FIFO-storage for Long-values Will keep 50 values for each dimension in memory Doesn't need to be changed + * when adding new planets/mods + */ +public class ProfilingStorage { + + private Map<String, List<Long>> mProfilingMap; + + public ProfilingStorage() { + mProfilingMap = new HashMap<>(); + } + + /** + * Add a new time to the list of pDimension. Will be ignored it tTotalTime == 0 + * + * @param pDimension + * @param pTotalTime + */ + public void AddTimeToList(ModDimensionDef pDimension, long pTotalTime) { + try { + if (pTotalTime == 0) return; + + if (!mProfilingMap.containsKey(pDimension.getDimIdentifier())) + mProfilingMap.put(pDimension.getDimIdentifier(), new LinkedList<>()); + + LinkedList<Long> ll = (LinkedList<Long>) mProfilingMap.get(pDimension.getDimIdentifier()); + + ll.addLast(pTotalTime); + + while (ll.size() > 50) ll.removeFirst(); + } catch (Exception e) { + // Just do nothing. profiling is for debug purposes only anyways... + } + } + + /** + * Return the average time required to execute the oregen in Dimension pDimension + * + * @param pDimension The DimensionType in question + * @return + */ + public long GetAverageTime(ModDimensionDef pDimension) { + try { + if (!mProfilingMap.containsKey(pDimension.getDimIdentifier())) return -1; + + int tTotalVal = 0; + long tAverage = 0; + long tReturnVal = 0; + + LinkedList<Long> ll = (LinkedList<Long>) mProfilingMap.get(pDimension.getDimIdentifier()); + + if (ll != null) { + for (Long aLong : ll) { + tAverage += aLong; + tTotalVal++; + } + + tReturnVal = (long) ((float) (tAverage / tTotalVal)); + } + return tReturnVal; + } catch (Exception e) { + return -1; + } + } +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/bartworks/BW_Worldgen_Ore_Layer_Space.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/bartworks/BW_Worldgen_Ore_Layer_Space.java new file mode 100644 index 0000000000..ae5e6af7c5 --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/bartworks/BW_Worldgen_Ore_Layer_Space.java @@ -0,0 +1,271 @@ +package bloodasp.galacticgreg.bartworks; + +import static bloodasp.galacticgreg.GalacticGreg.oreVeinWorldgenList; + +import java.util.Map; +import java.util.Random; +import java.util.stream.Collectors; + +import net.minecraft.block.Block; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraft.world.chunk.IChunkProvider; + +import com.github.bartimaeusnek.bartworks.system.material.BW_MetaGeneratedOreTE; +import com.github.bartimaeusnek.bartworks.system.material.BW_MetaGenerated_Ores; +import com.github.bartimaeusnek.bartworks.system.material.BW_MetaGenerated_SmallOres; +import com.github.bartimaeusnek.bartworks.system.material.Werkstoff; +import com.github.bartimaeusnek.bartworks.system.oregen.BW_OreLayer; + +import bloodasp.galacticgreg.GT_TileEntity_Ores_Space; +import bloodasp.galacticgreg.api.Enums; +import bloodasp.galacticgreg.api.ModDBMDef; +import bloodasp.galacticgreg.api.ModDimensionDef; +import bloodasp.galacticgreg.dynconfig.DynamicOreMixWorldConfig; +import bloodasp.galacticgreg.registry.GalacticGregRegistry; +import gregtech.api.GregTech_API; +import gregtech.api.enums.Materials; +import gregtech.api.interfaces.ISubTagContainer; +import gregtech.common.blocks.GT_TileEntity_Ores; + +public class BW_Worldgen_Ore_Layer_Space extends BW_OreLayer { + + private ModDimensionDef pDimensionDef; + private String name; + private DynamicOreMixWorldConfig _mDynWorldConfig; + + /** + * Code-only Constructor Will work with NEI + * + * @param aName veinname, should start with mix. + * @param pDefault enabled? + * @param pMinY + * @param pMaxY + * @param pWeight + * @param pDensity + * @param pSize 5-32 at max + * @param primaryBW either a werkstoff or a materials + * @param secondaryBW either a werkstoff or a materials + * @param betweenBW either a werkstoff or a materials + * @param sporadicBW either a werkstoff or a materials + */ + public BW_Worldgen_Ore_Layer_Space(String aName, boolean pDefault, int pMinY, int pMaxY, int pWeight, int pDensity, + int pSize, ISubTagContainer primaryBW, ISubTagContainer secondaryBW, ISubTagContainer betweenBW, + ISubTagContainer sporadicBW) { + super(aName, pDefault, 0, 0, 0, 0, 0, primaryBW, secondaryBW, betweenBW, sporadicBW); + mMinY = ((short) GregTech_API.sWorldgenFile + .get("worldgen.GaGregBartworks." + this.mWorldGenName, "MinHeight", pMinY)); + mMaxY = ((short) Math.max( + this.mMinY + 5, + GregTech_API.sWorldgenFile.get("worldgen.GaGregBartworks." + this.mWorldGenName, "MaxHeight", pMaxY))); + mWeight = ((short) GregTech_API.sWorldgenFile + .get("worldgen.GaGregBartworks." + this.mWorldGenName, "RandomWeight", pWeight)); + mDensity = ((short) GregTech_API.sWorldgenFile + .get("worldgen.GaGregBartworks." + this.mWorldGenName, "Density", pDensity)); + mSize = ((short) Math + .max(1, GregTech_API.sWorldgenFile.get("worldgen.GaGregBartworks." + this.mWorldGenName, "Size", pSize))); + // short pPrimary = primaryBW instanceof Materials ? (short)((Materials)primaryBW).mMetaItemSubID : (primaryBW + // instanceof Werkstoff ? ((Werkstoff)primaryBW).getmID() : 0); + // short pSecondary = secondaryBW instanceof Materials ? (short)((Materials)secondaryBW).mMetaItemSubID : + // (secondaryBW instanceof Werkstoff ? ((Werkstoff)secondaryBW).getmID() : 0); + // short pBetween = betweenBW instanceof Materials ? (short)((Materials)betweenBW).mMetaItemSubID : (betweenBW + // instanceof Werkstoff ? ((Werkstoff)betweenBW).getmID() : 0); + // short pSporadic = sporadicBW instanceof Materials ? (short)((Materials)sporadicBW).mMetaItemSubID : + // (sporadicBW instanceof Werkstoff ? ((Werkstoff)sporadicBW).getmID() : 0); + // mPrimaryMeta = ((short) GregTech_API.sWorldgenFile.get("worldgen.GaGregBartworks." + this.mWorldGenName, + // "OrePrimaryLayer", pPrimary)); + // mSecondaryMeta = ((short) GregTech_API.sWorldgenFile.get("worldgen.GaGregBartworks." + this.mWorldGenName, + // "OreSecondaryLayer", pSecondary)); + // mBetweenMeta = ((short) GregTech_API.sWorldgenFile.get("worldgen.GaGregBartworks." + this.mWorldGenName, + // "OreSporadiclyInbetween", pBetween)); + // mSporadicMeta = ((short) GregTech_API.sWorldgenFile.get("worldgen.GaGregBartworks." + this.mWorldGenName, + // "OreSporaticlyAround", pSporadic)); + // bwOres = ((byte) GregTech_API.sWorldgenFile.get("worldgen.GaGregBartworks." + this.mWorldGenName, + // "BWGTlogic", bwOres)); + if (mEnabled) { + sWeight += this.mWeight; + oreVeinWorldgenList.add(this); + } + _mDynWorldConfig = new DynamicOreMixWorldConfig(mWorldGenName, true); + _mDynWorldConfig.InitDynamicConfig(); + + StringBuilder ret = new StringBuilder(); + for (Map.Entry<String, Boolean> key : _mDynWorldConfig.get_mDynWorldConfigMap() + .entrySet() + .stream() + .filter(Map.Entry::getValue) + .collect(Collectors.toSet())) + ret.append( + key.getKey() + .split("_")[1]) + .append("; "); + name = ret.substring(0, ret.length() - 1); + } + + /** + * Script Friendly Constructor, WONT WORK WITH NEI + * + * @param aName + * @param pDefault + * @param pMinY + * @param pMaxY + * @param pWeight + * @param pDensity + * @param pSize + * @param pPrimary + * @param pSecondary + * @param pBetween + * @param pSporadic + * @param primaryBW + * @param secondaryBW + * @param betweenBW + * @param sporadicBW + */ + public BW_Worldgen_Ore_Layer_Space(String aName, boolean pDefault, int pMinY, int pMaxY, int pWeight, int pDensity, + int pSize, int pPrimary, int pSecondary, int pBetween, int pSporadic, boolean primaryBW, boolean secondaryBW, + boolean betweenBW, boolean sporadicBW) { + super( + aName, + pDefault, + 0, + 0, + 0, + 0, + 0, + primaryBW ? Werkstoff.default_null_Werkstoff : Materials._NULL, + secondaryBW ? Werkstoff.default_null_Werkstoff : Materials._NULL, + betweenBW ? Werkstoff.default_null_Werkstoff : Materials._NULL, + sporadicBW ? Werkstoff.default_null_Werkstoff : Materials._NULL); + mMinY = ((short) GregTech_API.sWorldgenFile + .get("worldgen.GaGregBartworks." + this.mWorldGenName, "MinHeight", pMinY)); + mMaxY = ((short) Math.max( + this.mMinY + 5, + GregTech_API.sWorldgenFile.get("worldgen.GaGregBartworks." + this.mWorldGenName, "MaxHeight", pMaxY))); + mWeight = ((short) GregTech_API.sWorldgenFile + .get("worldgen.GaGregBartworks." + this.mWorldGenName, "RandomWeight", pWeight)); + mDensity = ((short) GregTech_API.sWorldgenFile + .get("worldgen.GaGregBartworks." + this.mWorldGenName, "Density", pDensity)); + mSize = ((short) Math + .max(1, GregTech_API.sWorldgenFile.get("worldgen.GaGregBartworks." + this.mWorldGenName, "Size", pSize))); + mPrimaryMeta = ((short) GregTech_API.sWorldgenFile + .get("worldgen.GaGregBartworks." + this.mWorldGenName, "OrePrimaryLayer", pPrimary)); + mSecondaryMeta = ((short) GregTech_API.sWorldgenFile + .get("worldgen.GaGregBartworks." + this.mWorldGenName, "OreSecondaryLayer", pSecondary)); + mBetweenMeta = ((short) GregTech_API.sWorldgenFile + .get("worldgen.GaGregBartworks." + this.mWorldGenName, "OreSporadiclyInbetween", pBetween)); + mSporadicMeta = ((short) GregTech_API.sWorldgenFile + .get("worldgen.GaGregBartworks." + this.mWorldGenName, "OreSporaticlyAround", pSporadic)); + bwOres = ((byte) GregTech_API.sWorldgenFile + .get("worldgen.GaGregBartworks." + this.mWorldGenName, "BWGTlogic", bwOres)); + _mDynWorldConfig = new DynamicOreMixWorldConfig(mWorldGenName, true); + _mDynWorldConfig.InitDynamicConfig(); + StringBuilder ret = new StringBuilder(); + for (Map.Entry<String, Boolean> key : _mDynWorldConfig.get_mDynWorldConfigMap() + .entrySet() + .stream() + .filter(Map.Entry::getValue) + .collect(Collectors.toSet())) + ret.append( + key.getKey() + .split("_")[1]) + .append("; "); + name = ret.length() == 0 ? "" : ret.substring(0, ret.length() - 1); + if (mEnabled) { + sWeight += this.mWeight; + oreVeinWorldgenList.add(this); + } + } + + /** + * Script Friendly Constructor, WONT WORK WITH NEI + * + * @param aName + * @param enabled + */ + public BW_Worldgen_Ore_Layer_Space(String aName, boolean enabled) { + this(aName, enabled, 0, 0, 0, 0, 0, 0, 0, 0, 0, true, true, true, true); + } + + public boolean isEnabledForDim(ModDimensionDef pDimensionDef) { + return _mDynWorldConfig.isEnabledInDim(pDimensionDef); + } + + @Override + public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX, + int aChunkZ, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { + ModDimensionDef tMDD = GalacticGregRegistry.getDimensionTypeByChunkGenerator(aChunkGenerator); + if (tMDD == null) return false; + pDimensionDef = tMDD; + return super.executeWorldgen( + aWorld, + aRandom, + aBiome, + aDimensionType, + aChunkX, + aChunkZ, + aChunkGenerator, + aChunkProvider); + } + + public boolean setOreBlock(World aWorld, int aX, int aY, int aZ, int aMetaData, boolean isSmallOre) { + TileEntity te = aWorld.getTileEntity(aX, aY, aZ); + if (!(te instanceof BW_MetaGeneratedOreTE) && !(te instanceof GT_TileEntity_Ores)) { + if (aMetaData == this.mSporadicMeta && (this.bwOres & 1) != 0 + || aMetaData == this.mBetweenMeta && (this.bwOres & 2) != 0 + || aMetaData == this.mPrimaryMeta && (this.bwOres & 8) != 0 + || aMetaData == this.mSecondaryMeta && (this.bwOres & 4) != 0) { + boolean wasSet; + for (ModDBMDef e : pDimensionDef.getReplaceableBlocks()) { + wasSet = isSmallOre + ? BW_MetaGenerated_SmallOres.setOreBlock( + aWorld, + aX, + aY, + aZ, + aMetaData, + pDimensionDef.getAirSetting() == Enums.AirReplaceRule.AllowReplaceAir, + (Block) Block.blockRegistry.getObject(e.getBlockName()), + new int[] { e.getMeta() }) + : BW_MetaGenerated_Ores.setOreBlock( + aWorld, + aX, + aY, + aZ, + aMetaData, + pDimensionDef.getAirSetting() == Enums.AirReplaceRule.AllowReplaceAir, + (Block) Block.blockRegistry.getObject(e.getBlockName()), + new int[] { e.getMeta() }); + if (wasSet) return true; + } + return false; + } else { + return GT_TileEntity_Ores_Space.setOuterSpaceOreBlock( + pDimensionDef, + aWorld, + aX, + aY, + aZ, + aMetaData, + pDimensionDef.getAirSetting() == Enums.AirReplaceRule.AllowReplaceAir); + } + } else { + return true; + } + } + + @Override + public Block getDefaultBlockToReplace() { + return null; + } + + @Override + public int[] getDefaultDamageToReplace() { + return null; + } + + @Override + public String getDimName() { + return name; + } + +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/bartworks/BW_Worldgen_Ore_SmallOre_Space.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/bartworks/BW_Worldgen_Ore_SmallOre_Space.java new file mode 100644 index 0000000000..78f169e054 --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/bartworks/BW_Worldgen_Ore_SmallOre_Space.java @@ -0,0 +1,165 @@ +package bloodasp.galacticgreg.bartworks; + +import static bloodasp.galacticgreg.GalacticGreg.smallOreWorldgenList; + +import java.util.Map; +import java.util.Random; +import java.util.stream.Collectors; + +import net.minecraft.block.Block; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraft.world.chunk.IChunkProvider; + +import com.github.bartimaeusnek.bartworks.system.material.BW_MetaGeneratedOreTE; +import com.github.bartimaeusnek.bartworks.system.material.BW_MetaGenerated_Ores; +import com.github.bartimaeusnek.bartworks.system.material.BW_MetaGenerated_SmallOres; +import com.github.bartimaeusnek.bartworks.system.material.Werkstoff; +import com.github.bartimaeusnek.bartworks.system.oregen.BW_OreLayer; + +import bloodasp.galacticgreg.GT_TileEntity_Ores_Space; +import bloodasp.galacticgreg.api.Enums; +import bloodasp.galacticgreg.api.ModDBMDef; +import bloodasp.galacticgreg.api.ModDimensionDef; +import bloodasp.galacticgreg.dynconfig.DynamicOreMixWorldConfig; +import bloodasp.galacticgreg.registry.GalacticGregRegistry; +import gregtech.api.GregTech_API; +import gregtech.api.enums.Materials; +import gregtech.api.interfaces.ISubTagContainer; +import gregtech.common.blocks.GT_TileEntity_Ores; + +public class BW_Worldgen_Ore_SmallOre_Space extends BW_OreLayer { + + private ModDimensionDef pDimensionDef; + private DynamicOreMixWorldConfig _mDynWorldConfig; + private String name; + + public BW_Worldgen_Ore_SmallOre_Space(String aName, boolean pDefault, int pMinY, int pMaxY, int pDensity, + int pPrimary, ISubTagContainer primaryBW) { + super(aName, pDefault, 0, 0, 0, 0, 0, primaryBW, Materials._NULL, Materials._NULL, Materials._NULL); + mMinY = ((short) GregTech_API.sWorldgenFile + .get("worldgen.GaGregBartworks." + this.mWorldGenName, "MinHeight", pMinY)); + mMaxY = ((short) Math.max( + this.mMinY + 1, + GregTech_API.sWorldgenFile.get("worldgen.GaGregBartworks." + this.mWorldGenName, "MaxHeight", pMaxY))); + mDensity = ((short) Math.max( + 1, + GregTech_API.sWorldgenFile.get("worldgen.GaGregBartworks." + this.mWorldGenName, "Amount", pDensity))); + mPrimaryMeta = ((short) GregTech_API.sWorldgenFile + .get("worldgen.GaGregBartworks." + this.mWorldGenName, "Meta", pPrimary)); + bwOres = ((byte) GregTech_API.sWorldgenFile + .get("worldgen.GaGregBartworks." + this.mWorldGenName, "BWGTlogic", bwOres)); + _mDynWorldConfig = new DynamicOreMixWorldConfig(mWorldGenName, true); + _mDynWorldConfig.InitDynamicConfig(); + StringBuilder ret = new StringBuilder(); + for (Map.Entry<String, Boolean> key : _mDynWorldConfig.get_mDynWorldConfigMap() + .entrySet() + .stream() + .filter(Map.Entry::getValue) + .collect(Collectors.toSet())) + ret.append( + key.getKey() + .split("_")[1]) + .append("; "); + name = ret.length() == 0 ? "" : ret.substring(0, ret.length() - 1); + if (mEnabled) { + smallOreWorldgenList.add(this); + } + + } + + /** + * Script Friendly Constructor, WONT WORK WITH NEI + * + * @param aName + * @param enabled + */ + public BW_Worldgen_Ore_SmallOre_Space(String aName, boolean enabled) { + this(aName, enabled, 0, 0, 0, 0, enabled ? Werkstoff.default_null_Werkstoff : Materials._NULL); + } + + public boolean isEnabledForDim(ModDimensionDef pDimensionDef) { + return _mDynWorldConfig.isEnabledInDim(pDimensionDef); + } + + @Override + public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX, + int aChunkZ, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { + ModDimensionDef tMDD = GalacticGregRegistry.getDimensionTypeByChunkGenerator(aChunkGenerator); + if (tMDD == null) return false; + pDimensionDef = tMDD; + if (this.mPrimaryMeta > 0) + for (int i = 0, j = Math.max(1, this.mDensity / 2 + aRandom.nextInt(this.mDensity) / 2); i < j; i++) { + this.setOreBlock( + aWorld, + aChunkX + aRandom.nextInt(16), + this.mMinY + aRandom.nextInt(Math.max(1, this.mMaxY - this.mMinY)), + aChunkZ + aRandom.nextInt(16), + this.mPrimaryMeta, + true); + } + return true; + } + + @Override + public boolean setOreBlock(World aWorld, int aX, int aY, int aZ, int aMetaData, boolean isSmallOre) { + TileEntity te = aWorld.getTileEntity(aX, aY, aZ); + if (!(te instanceof BW_MetaGeneratedOreTE) && !(te instanceof GT_TileEntity_Ores)) { + if (aMetaData == this.mSporadicMeta && (this.bwOres & 1) != 0 + || aMetaData == this.mBetweenMeta && (this.bwOres & 2) != 0 + || aMetaData == this.mPrimaryMeta && (this.bwOres & 8) != 0 + || aMetaData == this.mSecondaryMeta && (this.bwOres & 4) != 0) { + boolean wasSet; + for (ModDBMDef e : pDimensionDef.getReplaceableBlocks()) { + wasSet = isSmallOre + ? BW_MetaGenerated_SmallOres.setOreBlock( + aWorld, + aX, + aY, + aZ, + aMetaData, + pDimensionDef.getAirSetting() == Enums.AirReplaceRule.AllowReplaceAir, + (Block) Block.blockRegistry.getObject(e.getBlockName()), + new int[] { e.getMeta() }) + : BW_MetaGenerated_Ores.setOreBlock( + aWorld, + aX, + aY, + aZ, + aMetaData, + pDimensionDef.getAirSetting() == Enums.AirReplaceRule.AllowReplaceAir, + (Block) Block.blockRegistry.getObject(e.getBlockName()), + new int[] { e.getMeta() }); + if (wasSet) return true; + } + return false; + } else { + return GT_TileEntity_Ores_Space.setOuterSpaceOreBlock( + pDimensionDef, + aWorld, + aX, + aY, + aZ, + aMetaData, + pDimensionDef.getAirSetting() == Enums.AirReplaceRule.AllowReplaceAir); + } + } else { + return true; + } + } + + @Override + public Block getDefaultBlockToReplace() { + return null; + } + + @Override + public int[] getDefaultDamageToReplace() { + return null; + } + + @Override + public String getDimName() { + return name; + } +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/command/AEStorageCommand.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/command/AEStorageCommand.java new file mode 100644 index 0000000000..6192603bcd --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/command/AEStorageCommand.java @@ -0,0 +1,180 @@ +package bloodasp.galacticgreg.command; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.command.ICommand; +import net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.server.MinecraftServer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +import appeng.api.util.WorldCoord; +import appeng.items.storage.ItemSpatialStorageCell; +import bloodasp.galacticgreg.GalacticGreg; +import bloodasp.galacticgreg.auxiliary.PlayerChatHelper; +import bloodasp.galacticgreg.schematics.SpaceSchematic; +import bloodasp.galacticgreg.schematics.SpaceSchematicFactory; + +/** + * This command allows to export any structure that has been stored inside a spatial storage cell to a xml file that can + * later be enabled for spawning in dimensions. + */ +public class AEStorageCommand implements ICommand { + + private List<String> aliases; + + public AEStorageCommand() { + this.aliases = new ArrayList<>(); + this.aliases.add("exportae"); + } + + @Override + public String getCommandName() { + return "exportae"; + } + + @Override + public String getCommandUsage(ICommandSender pCommandSender) { + return "exportae <structure name>"; + } + + @Override + public List<String> getCommandAliases() { + return this.aliases; + } + + @Override + public void processCommand(ICommandSender pCommandSender, String[] pArgs) { + try { + if (pCommandSender instanceof EntityPlayer) { + if (pArgs.length < 1) return; + + String tName = pArgs[0]; + + EntityPlayer tEP = (EntityPlayer) pCommandSender; + // Check if item in hand is a spatial storage cell + ItemStack tIS = tEP.inventory.getCurrentItem(); + if (tIS.getItem() instanceof ItemSpatialStorageCell) { + ItemSpatialStorageCell tCell = (ItemSpatialStorageCell) tIS.getItem(); + World tSpatialWorld = tCell.getWorld(tIS); + WorldCoord storedSize = tCell.getStoredSize(tIS); + + // Check if SSC is filled + if (storedSize.x == 0 || storedSize.y == 0 || storedSize.z == 0) { + PlayerChatHelper.SendError(pCommandSender, "Error: This spatial storage is empty"); + return; + } + + // Export structure + GalacticGreg.Logger.info( + "Creating Structure from Spatial AE drive. Dimensions: X [%d] Y [%d] Z [%d]", + storedSize.x, + storedSize.y, + storedSize.z); + SpaceSchematic tSchematic = SpaceSchematicFactory.createSchematic(tName); + boolean tTEWarningSend = false; + + // Loop all 3 dimensions + for (int lX = 1; lX <= storedSize.x; lX++) { + for (int lY = 65; lY < 65 + storedSize.y; lY++) { + for (int lZ = 1; lZ <= storedSize.z; lZ++) { + + // Get the block + Block b = tSpatialWorld.getBlock(lX, lY, lZ); + // Get the meta + int bm = tSpatialWorld.getBlockMetadata(lX, lY, lZ); + + // Search for the blocks name + String tBlockName = Block.blockRegistry.getNameForObject(b); + + // Check if block is a tileentity + TileEntity bTE = tSpatialWorld.getTileEntity(lX, lY, lZ); + + String tMsg = String.format("[X-%d][Y-%d][Z-%d] ", lX, lY, lZ); + String nbtComp = ""; + // If block could be found... + if (b != null) { + tMsg += tBlockName; + // If block is a TileEntity + if (bTE != null) { + // Print a warning on the console + tMsg += " TE"; + GalacticGreg.Logger.warn( + "Warning: Found TileEntity at X[%d] Y[%d] Z[%d]. NBT States are not exported!", + lX, + lY, + lZ); + if (!tTEWarningSend) { + // Send a warning ingame, once per export command + tTEWarningSend = true; + PlayerChatHelper + .SendWarn(pCommandSender, "TileEntity states are not exported!"); + } + + } + + // If the block is not air, add it to the structure + if (b != Blocks.air) tSchematic + .addStructureInfo(SpaceSchematicFactory.createStructureInfo(lX, lY, lZ, b, bm)); + } + } + } + } + + // Save structure to disk + if (!GalacticGreg.SchematicHandler.SaveSpaceStructure(tSchematic)) { + // Something went wrong... + PlayerChatHelper.SendError(pCommandSender, "Something went wrong. Structure not saved"); + } else { + // All good, xml exported. Notify player that he needs to edit the file + PlayerChatHelper.SendInfo( + pCommandSender, + "Structure has been exported to " + tSchematic.getName() + + ".xml. It contains " + + tSchematic.coordInfo() + .size() + + " Blocks"); + PlayerChatHelper + .SendInfo(pCommandSender, "You have to edit the file before a reload will accept it!"); + } + } else PlayerChatHelper + .SendError(pCommandSender, "Error: Item in your hand is not a spatial storage drive!"); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public boolean canCommandSenderUseCommand(ICommandSender pCommandSender) { + // Command is only enabled for actual players and only if they are OP-ed + if (pCommandSender instanceof EntityPlayerMP) { + EntityPlayerMP tEP = (EntityPlayerMP) pCommandSender; + return MinecraftServer.getServer() + .getConfigurationManager() + .func_152596_g(tEP.getGameProfile()); + } else return false; + } + + @Override + public int compareTo(Object o) { + return 0; + } + + @SuppressWarnings("rawtypes") + @Override + public List addTabCompletionOptions(ICommandSender p_71516_1_, String[] p_71516_2_) { + return null; + } + + @Override + public boolean isUsernameIndex(String[] p_82358_1_, int p_82358_2_) { + return false; + } +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/command/ProfilingCommand.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/command/ProfilingCommand.java new file mode 100644 index 0000000000..be43da5a4c --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/command/ProfilingCommand.java @@ -0,0 +1,99 @@ +package bloodasp.galacticgreg.command; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.command.ICommand; +import net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.ChatComponentText; + +import bloodasp.galacticgreg.GalacticGreg; +import bloodasp.galacticgreg.api.ModContainer; +import bloodasp.galacticgreg.api.ModDimensionDef; +import bloodasp.galacticgreg.registry.GalacticGregRegistry; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.relauncher.Side; + +/** + * Ingame command to get the average oregen time(s) for the active dimensions Doesn't need to be changed when adding new + * planets/mods + * + */ +public class ProfilingCommand implements ICommand { + + private List<String> aliases; + + public ProfilingCommand() { + this.aliases = new ArrayList<>(); + this.aliases.add("ggregprofiler"); + } + + @Override + public String getCommandName() { + return "ggregprofiler"; + } + + @Override + public String getCommandUsage(ICommandSender pCommandSender) { + return "ggregprofiler"; + } + + @Override + public List<String> getCommandAliases() { + return this.aliases; + } + + @Override + public void processCommand(ICommandSender pCommandSender, String[] pArgs) { + pCommandSender.addChatMessage(new ChatComponentText("Average OreGen times:")); + + for (ModContainer mc : GalacticGregRegistry.getModContainers()) { + String tModName = mc.getModName(); + for (ModDimensionDef mdd : mc.getDimensionList()) { + long tTime = GalacticGreg.Profiler.GetAverageTime(mdd); + String tInfo; + if (tTime == -1) tInfo = "N/A"; + else tInfo = String.format("%d ms", tTime); + pCommandSender.addChatMessage( + new ChatComponentText( + String.format("%s (%s): %s", mdd.getDimIdentifier(), mdd.getDimensionName(), tInfo))); + } + } + } + + @Override + public boolean canCommandSenderUseCommand(ICommandSender pCommandSender) { + if (FMLCommonHandler.instance() + .getEffectiveSide() == Side.SERVER + && !FMLCommonHandler.instance() + .getMinecraftServerInstance() + .isDedicatedServer()) + return true; + + if (pCommandSender instanceof EntityPlayerMP) { + EntityPlayerMP tEP = (EntityPlayerMP) pCommandSender; + return MinecraftServer.getServer() + .getConfigurationManager() + .func_152596_g(tEP.getGameProfile()); + } + return false; + } + + @Override + public int compareTo(Object o) { + return 0; + } + + @SuppressWarnings("rawtypes") + @Override + public List addTabCompletionOptions(ICommandSender p_71516_1_, String[] p_71516_2_) { + return null; + } + + @Override + public boolean isUsernameIndex(String[] p_82358_1_, int p_82358_2_) { + return false; + } +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/dynconfig/DynamicDimensionConfig.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/dynconfig/DynamicDimensionConfig.java new file mode 100644 index 0000000000..5c419c7c13 --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/dynconfig/DynamicDimensionConfig.java @@ -0,0 +1,168 @@ +package bloodasp.galacticgreg.dynconfig; + +import java.util.HashMap; +import java.util.Map; + +import net.minecraftforge.common.ChestGenHooks; + +import bloodasp.galacticgreg.GalacticGreg; +import bloodasp.galacticgreg.api.Enums.DimensionType; +import bloodasp.galacticgreg.api.ModContainer; +import bloodasp.galacticgreg.api.ModDimensionDef; +import bloodasp.galacticgreg.registry.GalacticGregRegistry; +import gregtech.api.GregTech_API; + +/** + * This dynamic config is different to the OreMix one. This is used/bound to the ModDimensionDef, and the + * OreMixWorldConfig is bound to the veins. Don't get confused! + * + */ +public class DynamicDimensionConfig { + + public static class AsteroidConfig { + + public int MinSize; + public int MaxSize; + public int Probability; + public int OreChance; + public int OrePrimaryOffset; + public int SpecialBlockChance; + public int SmallOreChance; + public boolean ObeyHeightLimits; + public int OreGenMaxY; + public int FloatingAsteroidMinY; + public boolean HiddenOres; + public int LootChestChance; + public int LootChestTable; + public int NumLootItems; + public boolean RandomizeNumLootItems; + } + + private static Map<String, AsteroidConfig> _mDynamicAsteroidMap = new HashMap<>(); + + private static String getConfigKeyName(ModContainer pMC, ModDimensionDef pMDD) { + return String.format("galacticgreg.asteroids.%s.%s", pMC.getModName(), pMDD.getDimensionName()); + } + + private static String getConfigKeyName(ModContainer pMC, ModDimensionDef pMDD, String pSubCat) { + return String.format("%s.%s", getConfigKeyName(pMC, pMDD), pSubCat); + } + + public static AsteroidConfig getAsteroidConfig(ModDimensionDef pDimDef) { + return _mDynamicAsteroidMap.getOrDefault(pDimDef.getDimIdentifier(), null); + } + + public static boolean InitDynamicConfig() { + try { + for (ModContainer mc : GalacticGregRegistry.getModContainers()) { + if (!mc.getEnabled()) continue; + + for (ModDimensionDef mdd : mc.getDimensionList()) { + DimensionType dt = mdd.getDimensionType(); + if (dt == DimensionType.Asteroid || dt == DimensionType.AsteroidAndPlanet) { + String tDimIdentifier = mdd.getDimIdentifier(); + if (_mDynamicAsteroidMap.containsKey(tDimIdentifier)) GalacticGreg.Logger.warn( + "Found 2 Dimensions with the same Identifier! This should never happen, and you should report this to me. Identifier in question: %s", + tDimIdentifier); + else { + AsteroidConfig aConf = new AsteroidConfig(); + aConf.MinSize = GregTech_API.sWorldgenFile.get(getConfigKeyName(mc, mdd), "SizeMin", 5); + aConf.MaxSize = GregTech_API.sWorldgenFile.get(getConfigKeyName(mc, mdd), "SizeMax", 15); + aConf.Probability = GregTech_API.sWorldgenFile + .get(getConfigKeyName(mc, mdd), "Probability", 200); + aConf.SpecialBlockChance = GregTech_API.sWorldgenFile + .get(getConfigKeyName(mc, mdd), "SpecialBlockChance", 5); + + aConf.OreChance = GregTech_API.sWorldgenFile + .get(getConfigKeyName(mc, mdd, "orespawn"), "BaseOreChance", 5); + aConf.OrePrimaryOffset = GregTech_API.sWorldgenFile + .get(getConfigKeyName(mc, mdd, "orespawn"), "PrimaryToRareOreOffset", 5); + aConf.SmallOreChance = GregTech_API.sWorldgenFile + .get(getConfigKeyName(mc, mdd, "orespawn"), "SmallOreChance", 10); + aConf.ObeyHeightLimits = GregTech_API.sWorldgenFile + .get(getConfigKeyName(mc, mdd, "orespawn"), "ObeyHeightLimits", false); + aConf.HiddenOres = GregTech_API.sWorldgenFile + .get(getConfigKeyName(mc, mdd, "orespawn"), "OresOnlyInsideAsteroids", false); + + if (GalacticGreg.GalacticConfig.LootChestsEnabled) { + aConf.LootChestChance = GregTech_API.sWorldgenFile + .get(getConfigKeyName(mc, mdd, "loot"), "LootChestChance", 1); + aConf.LootChestTable = GregTech_API.sWorldgenFile + .get(getConfigKeyName(mc, mdd, "loot"), "LootChestTable", 3); + aConf.NumLootItems = GregTech_API.sWorldgenFile + .get(getConfigKeyName(mc, mdd, "loot"), "LootChestItemCount", 10); + aConf.RandomizeNumLootItems = GregTech_API.sWorldgenFile + .get(getConfigKeyName(mc, mdd, "loot"), "RandomizeLootItemCount", true); + } else { + aConf.LootChestChance = 0; + aConf.LootChestTable = 1; + aConf.NumLootItems = 0; + aConf.RandomizeNumLootItems = false; + } + + if (dt == DimensionType.AsteroidAndPlanet) { + int tDefaultMaxY = mdd.getPreConfiguratedGroundOreMaxY(); + int tDefaultMinY = mdd.getPreConfiguratedFloatingAsteroidMinY(); + aConf.OreGenMaxY = GregTech_API.sWorldgenFile + .get(getConfigKeyName(mc, mdd, "floating"), "OreGenMaxY", tDefaultMaxY); + aConf.FloatingAsteroidMinY = GregTech_API.sWorldgenFile + .get(getConfigKeyName(mc, mdd, "floating"), "FloatingAsteroidMinY", tDefaultMinY); + } + + if (aConf.MaxSize > 50) GalacticGreg.Logger.warn( + "Asteroid-MaxSize for dimID [%s] is larger than 50. This might cause memory-problems, as the maximum asteroid size will be larger than 50*50*50 blocks", + tDimIdentifier); + _mDynamicAsteroidMap.put(tDimIdentifier, aConf); + } + } + } + } + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * Convert numbers to actual loot-table entries + * + * @param pACfg + * @return + */ + public static String getLootChestTable(AsteroidConfig pACfg) { + String tLootTable = ChestGenHooks.MINESHAFT_CORRIDOR; + + switch (pACfg.LootChestTable) { + case 2: + tLootTable = ChestGenHooks.PYRAMID_DESERT_CHEST; + break; + case 3: + tLootTable = ChestGenHooks.PYRAMID_JUNGLE_CHEST; + break; + case 4: + tLootTable = ChestGenHooks.PYRAMID_JUNGLE_DISPENSER; + break; + case 5: + tLootTable = ChestGenHooks.STRONGHOLD_CORRIDOR; + break; + case 6: + tLootTable = ChestGenHooks.STRONGHOLD_LIBRARY; + break; + case 7: + tLootTable = ChestGenHooks.STRONGHOLD_CROSSING; + break; + case 8: + tLootTable = ChestGenHooks.VILLAGE_BLACKSMITH; + break; + case 9: + tLootTable = ChestGenHooks.BONUS_CHEST; + break; + case 10: + tLootTable = ChestGenHooks.DUNGEON_CHEST; + break; + } + + return tLootTable; + } +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/dynconfig/DynamicOreMixWorldConfig.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/dynconfig/DynamicOreMixWorldConfig.java new file mode 100644 index 0000000000..862bfd4e4e --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/dynconfig/DynamicOreMixWorldConfig.java @@ -0,0 +1,93 @@ +package bloodasp.galacticgreg.dynconfig; + +import java.util.HashMap; +import java.util.Map; + +import bloodasp.galacticgreg.GalacticGreg; +import bloodasp.galacticgreg.api.ModContainer; +import bloodasp.galacticgreg.api.ModDimensionDef; +import bloodasp.galacticgreg.registry.GalacticGregRegistry; +import gregtech.api.GregTech_API; + +/** + * This is the dynamic config class for every ore-vein that will generate config values according to the dimension and + * mod name + */ +public class DynamicOreMixWorldConfig { + + private String _mWorldGenName; + + public Map<String, Boolean> get_mDynWorldConfigMap() { + return new HashMap<>(_mDynWorldConfigMap != null ? _mDynWorldConfigMap : new HashMap<>()); + } + + private Map<String, Boolean> _mDynWorldConfigMap; + private final String _mConfigName; + + private String getConfigKeyName(ModContainer pMC, ModDimensionDef pMDD) { + return getConfigKeyName(pMC, pMDD, ""); + } + + private String getConfigKeyName(ModContainer pMC, ModDimensionDef pMDD, String pAdditionalName) { + String tRet = String.format("%s_%s", pMC.getModName(), pMDD.getDimensionName()); + if (pAdditionalName.length() > 1) tRet = String.format("%s_%s", tRet, pAdditionalName); + + return tRet; + } + + /** + * Init a new dynamic config for a given world-generator + * + * @param pWorldGenName + */ + public DynamicOreMixWorldConfig(String pWorldGenName) { + _mWorldGenName = pWorldGenName; + _mDynWorldConfigMap = new HashMap<>(); + _mConfigName = String.format("worldgen.%s", _mWorldGenName); + } + + public DynamicOreMixWorldConfig(String pWorldGenName, boolean bw) { + _mWorldGenName = pWorldGenName; + _mDynWorldConfigMap = new HashMap<>(); + _mConfigName = String.format("worldgen.gagregbartworks.%s", _mWorldGenName); + } + + /** + * Check if this OreGen is enabled for a given Dimension, represented by pMDD + * + * @param pMDD The dimension in question + * @return true or false if *this* oregen is enabled in the worldgen config + */ + public boolean isEnabledInDim(ModDimensionDef pMDD) { + String tDimIdentifier = pMDD.getDimIdentifier(); + return _mDynWorldConfigMap.getOrDefault(tDimIdentifier, false); + } + + /** + * Initializes the dynamic oregen config. This must be called *AFTER* InitModContainers() has done its work + * + * @return true or false if the config init was successfull + */ + public boolean InitDynamicConfig() { + try { + for (ModContainer mc : GalacticGregRegistry.getModContainers()) { + if (!mc.getEnabled()) continue; + + for (ModDimensionDef mdd : mc.getDimensionList()) { + String tDimIdentifier = mdd.getDimIdentifier(); + if (_mDynWorldConfigMap.containsKey(tDimIdentifier)) GalacticGreg.Logger.error( + "Found 2 Dimensions with the same Identifier: %s Dimension will not generate Ores", + tDimIdentifier); + else { + boolean tFlag = GregTech_API.sWorldgenFile.get(_mConfigName, getConfigKeyName(mc, mdd), false); + _mDynWorldConfigMap.put(tDimIdentifier, tFlag); + } + } + } + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/generators/GenEllipsoid.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/generators/GenEllipsoid.java new file mode 100644 index 0000000000..09d08a9923 --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/generators/GenEllipsoid.java @@ -0,0 +1,126 @@ +package bloodasp.galacticgreg.generators; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import net.minecraft.util.MathHelper; +import net.minecraft.util.Vec3; + +import bloodasp.galacticgreg.api.Enums.SpaceObjectType; +import bloodasp.galacticgreg.api.Enums.TargetBlockPosition; +import bloodasp.galacticgreg.api.ISpaceObjectGenerator; +import bloodasp.galacticgreg.api.StructureInformation; + +/** + * Simple ellipsoid-generator. Based on the formular created by Chrysator. Thanks for the help! + * + * Generates a simple ellipsoid with dynamic rotation, random size-values, random noise for the surface, etc. Can + * probably be tweaked even more, but works for now... + */ +public class GenEllipsoid implements ISpaceObjectGenerator { + + private Vec3 _mEllipsoidCenter; + private Random _mRandom; + private List<StructureInformation> _mStructure; + + private double _mCoreDensity = 0.7D; + private double _mSineFactor = 0.05D; + private float _mRandomInfluence; + private float _mRandomAngleX; + private float _mRandomAngleY; + private float _mRandomAngleZ; + + private int _mSizeA; + private int _mSizeB; + private int _mSizeC; + + public GenEllipsoid() { + reset(); + } + + @Override + public SpaceObjectType getType() { + return SpaceObjectType.OreAsteroid; + } + + @Override + public void randomize(int pSizeMin, int pSizeMax) { + _mRandom = new Random(System.currentTimeMillis()); + _mRandomAngleX = (float) (_mRandom.nextFloat() * Math.PI); + _mRandomAngleY = (float) (_mRandom.nextFloat() * Math.PI); + _mRandomAngleZ = (float) (_mRandom.nextFloat() * Math.PI); + + _mRandomInfluence = _mRandom.nextFloat(); + + _mSizeA = pSizeMin + _mRandom.nextInt(pSizeMax - pSizeMin) + 10; + _mSizeB = pSizeMin + _mRandom.nextInt(pSizeMax - pSizeMin) + 10; + _mSizeC = pSizeMin + _mRandom.nextInt(pSizeMax - pSizeMin) + 10; + } + + @Override + public void setCenterPoint(int pX, int pY, int pZ) { + _mEllipsoidCenter = Vec3.createVectorHelper(pX, pY, pZ); + } + + @Override + public void setCenterPoint(Vec3 pCenter) { + _mEllipsoidCenter = pCenter; + } + + @Override + public Vec3 getCenterPoint() { + return _mEllipsoidCenter; + } + + @Override + public List<StructureInformation> getStructure() { + return _mStructure; + } + + @Override + public void calculate() { + int Xmin = (int) (_mEllipsoidCenter.xCoord - _mSizeA); + int Xmax = (int) (_mEllipsoidCenter.xCoord + _mSizeA); + int Ymin = (int) (_mEllipsoidCenter.yCoord - _mSizeB); + int Ymax = (int) (_mEllipsoidCenter.yCoord + _mSizeB); + int Zmin = (int) (_mEllipsoidCenter.zCoord - _mSizeC); + int Zmax = (int) (_mEllipsoidCenter.zCoord + _mSizeC); + + for (int iX = Xmin; iX <= Xmax; iX++) { + for (int iY = Ymin; iY <= Ymax; iY++) { + for (int iZ = Zmin; iZ <= Zmax; iZ++) { + double tmpX = Math.pow(_mEllipsoidCenter.xCoord - iX, 2) / Math.pow(_mSizeA, 2); + double tmpY = Math.pow(_mEllipsoidCenter.yCoord - iY, 2) / Math.pow(_mSizeB, 2); + double tmpZ = Math.pow(_mEllipsoidCenter.zCoord - iZ, 2) / Math.pow(_mSizeC, 2); + double val = (tmpX + tmpY + tmpZ); + + Vec3 tPoint = Vec3.createVectorHelper(iX, iY, iZ); + tPoint.rotateAroundX(_mRandomAngleX); + tPoint.rotateAroundY(_mRandomAngleY); + tPoint.rotateAroundZ(_mRandomAngleZ); + + TargetBlockPosition tbp = TargetBlockPosition.Invalid; + + if (val <= 0.01D) tbp = TargetBlockPosition.AsteroidInnerCore; + + else if (val > 0.01D && val < _mCoreDensity) tbp = TargetBlockPosition.AsteroidCore; + + else if (val >= _mCoreDensity && val <= (1.0D + - (_mSineFactor * MathHelper.sin((iZ + iX + iY - _mRandom.nextFloat() * _mRandomInfluence))))) + tbp = TargetBlockPosition.AsteroidShell; + + if (tbp != TargetBlockPosition.Invalid) + _mStructure.add(new StructureInformation(Vec3.createVectorHelper(iX, iY, iZ), tbp)); + + } + } + } + } + + @Override + public void reset() { + _mStructure = new ArrayList<>(); + _mEllipsoidCenter = Vec3.createVectorHelper(0, 0, 0); + } +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/registry/GalacticGregRegistry.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/registry/GalacticGregRegistry.java new file mode 100644 index 0000000000..b45353da6e --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/registry/GalacticGregRegistry.java @@ -0,0 +1,181 @@ +package bloodasp.galacticgreg.registry; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import net.minecraft.world.chunk.IChunkProvider; + +import bloodasp.galacticgreg.GalacticGreg; +import bloodasp.galacticgreg.api.Enums.DimensionType; +import bloodasp.galacticgreg.api.ModContainer; +import bloodasp.galacticgreg.api.ModDimensionDef; +import bloodasp.galacticgreg.dynconfig.DynamicDimensionConfig; +import bloodasp.galacticgreg.generators.GenEllipsoid; +import cpw.mods.fml.common.Loader; + +/** + * GalacticGregs registry + * + */ +public class GalacticGregRegistry { + + private static final Map<String, ModContainer> _mModContainers = new HashMap<>(); + public static final String DIM_UNKNOWN = "GGREG_DIMENSION_UNKNOWN"; + private static boolean _mInitializationDone = false; + + /** + * Register new ModContainer in the registry. Call this after you've populated it with Dimensions and Blocks Must be + * called from your own PreInit or Init event + * + * @param pModContainer + * @return + */ + public static boolean registerModContainer(ModContainer pModContainer) { + if (_mInitializationDone) { + GalacticGreg.Logger.warn("Initialization is already done, you can't add more ModContainers!"); + return false; + } + + if (_mModContainers.containsKey(pModContainer.getModName())) { + GalacticGreg.Logger + .warn("There is already a mod registered with that name: [%s]", pModContainer.getModName()); + return false; + } else { + GalacticGreg.Logger.info( + "Registered new mod to generate ores: [%s] Dimensions provided: [%d]", + pModContainer.getModName(), + pModContainer.getDimensionList() + .size()); + _mModContainers.put(pModContainer.getModName(), pModContainer); + return true; + } + } + + /** + * Lookup the registered dimensions and try to find the DimensionDefinition that has the ChunkProvider that we have + * here + * + * @param pChunkProvider + * @return + */ + public static ModDimensionDef getDimensionTypeByChunkGenerator(IChunkProvider pChunkProvider) { + try { + if (!_mInitializationDone) return null; + + String tFQCPN = pChunkProvider.toString() + .split("@")[0]; + ModDimensionDef tReturnMDD = null; + + for (ModContainer mc : _mModContainers.values()) { + for (ModDimensionDef mdd : mc.getDimensionList()) { + if (mdd.getChunkProviderName() + .equals(tFQCPN)) { + tReturnMDD = mdd; + break; + } + } + } + + return tReturnMDD; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + /** + * Get all registered modcontainers. Can only be done after the initialization process is done + * + * @return + */ + public static Collection<ModContainer> getModContainers() { + if (!_mInitializationDone) return null; + + return _mModContainers.values(); + } + + /** + * Initializes the Registry. Never do this in your code, GalacticGreg will crash if you do so + */ + public static boolean InitRegistry() { + if (_mInitializationDone) // never run init twice! + return false; + + InitModContainers(); + + DynamicDimensionConfig.InitDynamicConfig(); + return true; + } + + /** + * Parse modcontainers and search for loaded mods. Enable found mods for generation + */ + private static void InitModContainers() { + for (ModContainer mc : _mModContainers.values()) { + if (!Loader.isModLoaded(mc.getModName()) && !mc.getModName() + .equalsIgnoreCase("vanilla")) { + GalacticGreg.Logger.warn( + "Ignoring ModRegistration for OreGen: [%s], because mod is not loaded. Did you misspell the name?", + mc.getModName()); + mc.setEnabled(false); + } else { + GalacticGreg.Logger.info("Mod [%s] is now enabled for OreGen by GalacticGreg", mc.getModName()); + mc.setEnabled(true); + for (ModDimensionDef md : mc.getDimensionList()) { + GalacticGreg.Logger.info( + "ModID: [%s] DimName: [%s] ValidBlocks: [%d] Identifier: [%s] Generators: [%d]", + mc.getModName(), + md.getDimensionName(), + md.getReplaceableBlocks() + .size(), + md.getDimIdentifier(), + md.getSpaceObjectGenerators() + .size()); + + // Register default generator if dimension is asteroid and no generator was added + if (md.getDimensionType() == DimensionType.AsteroidAndPlanet + || md.getDimensionType() == DimensionType.Asteroid) { + if (md.getSpaceObjectGenerators() + .size() == 0) { + GalacticGreg.Logger.debug("No generators found, adding build-in ellipsoid generator"); + md.registerSpaceObjectGenerator(new GenEllipsoid()); + } + GalacticGreg.Logger.info( + "Asteroid-Enabled dimension. Registered Generators: [%d]", + md.getSpaceObjectGenerators() + .size()); + } + + md.finalizeReplaceableBlocks(mc.getModName()); + } + } + } + _mInitializationDone = true; + } + + /** + * Returns ModContainer for given DimensionDefinition + * + * @param pDimensionDefinition + * @return + */ + public static ModContainer getModContainerForDimension(ModDimensionDef pDimensionDefinition) { + if (!_mInitializationDone) return null; + + try { + for (ModContainer mc : _mModContainers.values()) { + for (ModDimensionDef md : mc.getDimensionList()) { + if (pDimensionDefinition.getDimIdentifier() + .equals(md.getDimIdentifier())) { + return mc; + } + } + } + return null; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/schematics/SpaceSchematic.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/schematics/SpaceSchematic.java new file mode 100644 index 0000000000..222d786cb4 --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/schematics/SpaceSchematic.java @@ -0,0 +1,100 @@ +package bloodasp.galacticgreg.schematics; + +import java.util.ArrayList; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; + +import net.minecraft.block.Block; +import net.minecraft.util.Vec3; + +import bloodasp.galacticgreg.api.StructureInformation; + +/** + * Class for XML Structure files. You only should edit/use this file/class if you want to add/fix stuff with + * GalacticGreg itself, and never if you're a mod developer and want to add support for GGreg to your mod. However, feel + * free to copy this code to your own mod to implement structures. If you have questions, find me on github and ask + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlRootElement(name = "SpaceSchematic") +public class SpaceSchematic { + + @XmlAttribute(name = "enabled") + protected boolean _mStructureEnabled; + @XmlAttribute(name = "centerX") + protected int _mCenterX; + @XmlAttribute(name = "centerY") + protected int _mCenterY; + @XmlAttribute(name = "centerZ") + protected int _mCenterZ; + + @XmlElement(name = "StructureName") + protected String _mStructureName; + + @XmlElement(name = "Rarity") + protected int _mRarity; + + @XmlElementWrapper(name = "Coords") + @XmlElement(name = "block") + protected ArrayList<BaseStructureInfo> mStructureInfoList; + + public boolean isEnabled() { + return _mStructureEnabled; + } + + public Vec3 getStructureCenter() { + return Vec3.createVectorHelper(_mCenterX, _mCenterY, _mCenterZ); + } + + public int getRarity() { + return _mRarity; + } + + public String getName() { + return _mStructureName; + } + + public ArrayList<BaseStructureInfo> coordInfo() { + if (mStructureInfoList == null) mStructureInfoList = new ArrayList<>(); + + return mStructureInfoList; + } + + public void addStructureInfo(StructureInformation pStrucInfo) { + if (mStructureInfoList == null) mStructureInfoList = new ArrayList<>(); + mStructureInfoList.add(new BaseStructureInfo(pStrucInfo)); + } + + public static class BaseStructureInfo { + + @XmlAttribute(name = "X") + protected int posX; + @XmlAttribute(name = "Y") + protected int posY; + @XmlAttribute(name = "Z") + protected int posZ; + @XmlAttribute(name = "Block") + protected String blockName; + @XmlAttribute(name = "Meta") + protected int blockMeta; + + public BaseStructureInfo(StructureInformation pSI) { + posX = pSI.getX(); + posY = pSI.getY(); + posZ = pSI.getZ(); + blockName = Block.blockRegistry.getNameForObject( + pSI.getBlock() + .getBlock()); + blockMeta = pSI.getBlock() + .getMeta(); + } + + public Vec3 getVec3Pos() { + return Vec3.createVectorHelper(posX, posY, posZ); + } + } +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/schematics/SpaceSchematicFactory.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/schematics/SpaceSchematicFactory.java new file mode 100644 index 0000000000..5c76904a80 --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/schematics/SpaceSchematicFactory.java @@ -0,0 +1,33 @@ +package bloodasp.galacticgreg.schematics; + +import net.minecraft.block.Block; +import net.minecraft.util.Vec3; + +import bloodasp.galacticgreg.api.Enums.AllowedBlockPosition; +import bloodasp.galacticgreg.api.Enums.TargetBlockPosition; +import bloodasp.galacticgreg.api.SpecialBlockComb; +import bloodasp.galacticgreg.api.StructureInformation; + +/** + * Class for XML Structure files. You only should edit/use this file/class if you want to add/fix stuff with + * GalacticGreg itself, and never if you're a mod developer and want to add support for GGreg to your mod. However, feel + * free to copy this code to your own mod to implement structures. If you have questions, find me on github and ask + */ +public class SpaceSchematicFactory { + + public static SpaceSchematic createSchematic(String pName) { + SpaceSchematic tSchem = new SpaceSchematic(); + tSchem._mStructureName = pName; + tSchem._mRarity = 100; + tSchem._mStructureEnabled = false; + + return tSchem; + } + + public static StructureInformation createStructureInfo(int pX, int pY, int pZ, Block pBlock, int pMeta) { + return new StructureInformation( + Vec3.createVectorHelper(pX, pY, pZ), + TargetBlockPosition.Invalid, + new SpecialBlockComb(pBlock, pMeta, AllowedBlockPosition.AsteroidCoreAndShell)); + } +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/schematics/SpaceSchematicHandler.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/schematics/SpaceSchematicHandler.java new file mode 100644 index 0000000000..3300f98b92 --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/schematics/SpaceSchematicHandler.java @@ -0,0 +1,182 @@ +package bloodasp.galacticgreg.schematics; + +import java.io.File; +import java.io.FileOutputStream; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; + +import org.apache.commons.io.FileUtils; + +import bloodasp.galacticgreg.GalacticGreg; + +/** + * Class for XML Structure files. You only should edit/use this file/class if you want to add/fix stuff with + * GalacticGreg itself, and never if you're a mod developer and want to add support for GGreg to your mod. However, feel + * free to copy this code to your own mod to implement structures. If you have questions, find me on github and ask + */ +public class SpaceSchematicHandler { + + File _mConfigFolderName; + File _mSchematicsFolderName; + private List<SpaceSchematic> _mSpaceSchematics; + + @SuppressWarnings("ResultOfMethodCallIgnored") + public SpaceSchematicHandler(File pConfigFolder) { + _mConfigFolderName = new File(String.format("%s/%s", pConfigFolder.toString(), GalacticGreg.NICE_MODID)); + _mSchematicsFolderName = new File(String.format("%s/schematics", _mConfigFolderName)); + + _mSpaceSchematics = new ArrayList<>(); + + if (!_mSchematicsFolderName.exists()) _mSchematicsFolderName.mkdirs(); + } + + /** + * Get a random schematic to be placed. + * + * @return A schematic that can be spawned in space + */ + public SpaceSchematic getRandomSpaceSchematic() { + int tRandomChance = GalacticGreg.GalacticRandom.nextInt(100); + List<Integer> tRandomIDs = new ArrayList<>(); + SpaceSchematic tChoosenSchematic = null; + + if (_mSpaceSchematics == null) return null; + + if (_mSpaceSchematics.size() == 0) return null; + + if (_mSpaceSchematics.size() == 1) { + tChoosenSchematic = _mSpaceSchematics.get(0); + if (tChoosenSchematic.getRarity() < tRandomChance) tChoosenSchematic = null; + } else { + for (int i = 0; i < _mSpaceSchematics.size(); i++) { + if (_mSpaceSchematics.get(i) + .getRarity() >= tRandomChance) tRandomIDs.add(i); + } + } + + if (tRandomIDs.size() > 0) { + int tRnd = GalacticGreg.GalacticRandom.nextInt(tRandomIDs.size()); + tChoosenSchematic = _mSpaceSchematics.get(tRandomIDs.get(tRnd)); + } + + return tChoosenSchematic; + } + + /** + * Try to reload the schematics. Will not change the list of currently loaded schematics if any errors are detected, + * except if you force it to do so + * + * @return + */ + public boolean reloadSchematics(boolean pForceReload) { + try { + Collection<File> structureFiles = FileUtils + .listFiles(_mSchematicsFolderName, new String[] { "xml" }, false); + List<SpaceSchematic> tNewSpaceSchematics = new ArrayList<>(); + int tErrorsFound = 0; + + if (structureFiles.isEmpty()) return true; + + for (File tSchematic : structureFiles) { + try { + SpaceSchematic tSchematicObj = LoadSpaceSchematic(tSchematic); + if (tSchematicObj != null) tNewSpaceSchematics.add(tSchematicObj); + else { + GalacticGreg.Logger.warn("Could not load Schematic %s. Please check the syntax", tSchematic); + tErrorsFound++; + } + } catch (Exception e) { + GalacticGreg.Logger.error("Error while loading Schematic %s", tSchematic); + e.printStackTrace(); + } + + } + + GalacticGreg.Logger.info("Successfully loaded %d Schematics", tNewSpaceSchematics.size()); + boolean tDoReplace = true; + + if (tErrorsFound > 0) { + GalacticGreg.Logger.warn("Found %d errors while loading, not all schematics will be available"); + if (pForceReload) + GalacticGreg.Logger.info("Reload was forced, replacing currently active list with new one"); + else { + GalacticGreg.Logger.warn("Nothing was replaced. Fix any errors and reload again"); + tDoReplace = false; + } + } + + if (tDoReplace) _mSpaceSchematics = tNewSpaceSchematics; + + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * Saves the schematic to disk. The schematics name will be used as filename + * + * @param pSchematic + * @return + */ + public boolean SaveSpaceStructure(SpaceSchematic pSchematic) { + try { + if (pSchematic.getName() + .length() < 1) return false; + + JAXBContext tJaxbCtx = JAXBContext.newInstance(SpaceSchematic.class); + Marshaller jaxMarsh = tJaxbCtx.createMarshaller(); + jaxMarsh.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + jaxMarsh.marshal( + pSchematic, + new FileOutputStream(String.format("%s/%s.xml", _mSchematicsFolderName, pSchematic.getName()), false)); + + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * Load a schematic from disk by the schematic-name itself, without .xml or path + * + * @param pSchematicName + * @return + */ + public SpaceSchematic LoadSpaceSchematic(String pSchematicName) { + return LoadSpaceSchematic(new File(String.format("%s/%s.xml", _mSchematicsFolderName, pSchematicName))); + } + + /** + * Load a schematic file from disk by providing the actual file-object + * + * @param pName + * @return + */ + public SpaceSchematic LoadSpaceSchematic(File pName) { + SpaceSchematic tSchematic = null; + + try { + JAXBContext tJaxbCtx = JAXBContext.newInstance(SpaceSchematic.class); + if (!pName.exists()) { + GalacticGreg.Logger.error("SchematicFile %s could not be found", pName); + return null; + } + + Unmarshaller jaxUnmarsh = tJaxbCtx.createUnmarshaller(); + tSchematic = (SpaceSchematic) jaxUnmarsh.unmarshal(pName); + + } catch (Exception e) { + e.printStackTrace(); + } + + return tSchematic; + } +} diff --git a/galacticgreg/src/main/java/bloodasp/galacticgreg/schematics/SpaceSchematicWrapper.java b/galacticgreg/src/main/java/bloodasp/galacticgreg/schematics/SpaceSchematicWrapper.java new file mode 100644 index 0000000000..406b66c0a1 --- /dev/null +++ b/galacticgreg/src/main/java/bloodasp/galacticgreg/schematics/SpaceSchematicWrapper.java @@ -0,0 +1,104 @@ +package bloodasp.galacticgreg.schematics; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.util.Vec3; + +import bloodasp.galacticgreg.GalacticGreg; +import bloodasp.galacticgreg.api.BlockMetaComb; +import bloodasp.galacticgreg.api.Enums.SpaceObjectType; +import bloodasp.galacticgreg.api.Enums.TargetBlockPosition; +import bloodasp.galacticgreg.api.ISpaceObjectGenerator; +import bloodasp.galacticgreg.api.StructureInformation; +import bloodasp.galacticgreg.schematics.SpaceSchematic.BaseStructureInfo; +import cpw.mods.fml.common.registry.GameRegistry; + +/** + * Class for XML Structure files. You only should edit/use this file/class if you want to add/fix stuff with + * GalacticGreg itself, and never if you're a mod developer and want to add support for GGreg to your mod. However, feel + * free to copy this code to your own mod to implement structures. If you have questions, find me on github and ask + */ +public class SpaceSchematicWrapper implements ISpaceObjectGenerator { + + private SpaceSchematic _mSchematic; + private Vec3 _mCenter = Vec3.createVectorHelper(0, 0, 0); + private List<StructureInformation> _mFinalizedStructure; + + public SpaceSchematicWrapper(SpaceSchematic pSchematic) { + _mSchematic = pSchematic; + } + + public boolean isCalculated() { + return _mFinalizedStructure != null && _mFinalizedStructure.size() > 0; + } + + /** + * Recalculate the Structures position, center it around _mCenter + */ + private void RecalculatePosition() { + _mFinalizedStructure = new ArrayList<>(); + + for (BaseStructureInfo bsi : _mSchematic.coordInfo()) { + try { + String tModID = bsi.blockName.split(":")[0]; + String tBlockName = bsi.blockName.split(":")[1]; + + Block tBlock = GameRegistry.findBlock(tModID, tBlockName); + if (tBlock != null) { + BlockMetaComb bmc = new BlockMetaComb(tBlock, bsi.blockMeta); + Vec3 tCenteredPos = _mCenter.addVector(bsi.posX, bsi.posY, bsi.posZ); + StructureInformation tnewSI = new StructureInformation( + tCenteredPos, + TargetBlockPosition.StructureBlock, + bmc); + _mFinalizedStructure.add(tnewSI); + } else GalacticGreg.Logger + .warn("Block %s:%s could not be found. Schematic will be incomplete!", tModID, tBlockName); + } catch (Exception e) { + e.printStackTrace(); + GalacticGreg.Logger.error("Error while recalculating blocks position"); + } + } + } + + @Override + public Vec3 getCenterPoint() { + return _mCenter; + } + + @Override + public void setCenterPoint(int pX, int pY, int pZ) { + _mCenter = Vec3.createVectorHelper(pX, pY, pZ); + } + + @Override + public void setCenterPoint(Vec3 pCenter) { + _mCenter = pCenter; + } + + @Override + public List<StructureInformation> getStructure() { + return _mFinalizedStructure; + } + + @Override + public void calculate() { + RecalculatePosition(); + } + + @Override + public void randomize(int pSizeMin, int pSizeMax) {} + + @Override + public SpaceObjectType getType() { + return SpaceObjectType.NonOreSchematic; + } + + @Override + public void reset() { + + } + +} diff --git a/galacticgreg/src/main/resources/assets/galacticgreg/galacticgreg.png b/galacticgreg/src/main/resources/assets/galacticgreg/galacticgreg.png Binary files differnew file mode 100644 index 0000000000..204bdc8f0d --- /dev/null +++ b/galacticgreg/src/main/resources/assets/galacticgreg/galacticgreg.png diff --git a/galacticgreg/src/main/resources/mcmod.info b/galacticgreg/src/main/resources/mcmod.info new file mode 100644 index 0000000000..b968f4e6ef --- /dev/null +++ b/galacticgreg/src/main/resources/mcmod.info @@ -0,0 +1,16 @@ +[ +{ + "modid": "${modId}", + "name": "${modName}", + "description": "Adds Gregtech Oregen to Galacticraft Dimensions", + "version": "${modVersion}", + "mcversion": "${minecraftVersion}", + "url": "http://forum.industrial-craft.net/index.php?page=Thread&threadID=11039", + "updateUrl": "", + "authorList": ["Blood Asp, Namikon"], + "credits": "To GregoriusT and micdoodle8 for making such good Mods", + "logoFile": "assets/galacticgreg/galacticgreg.png", + "screenshots": [], + "dependencies": [] +} +] |