Compare commits

..

34 Commits

Author SHA1 Message Date
dfsek 54e6fb0587 begin work on terrain samplers 2021-04-15 09:52:51 -07:00
dfsek 798f3423a5 interpolator resolutions 2021-04-13 11:07:44 -07:00
dfsek 111f6b05ba refactor interpolators 2021-04-13 00:16:40 -07:00
dfsek 0693b03bba delete unused gen classes 2021-04-13 00:13:24 -07:00
dfsek 5397df57b8 Merge pull request #125 from PolyhedralDev/dev/profiler
Implement fancy stack-based profiler
2021-04-12 09:30:26 -07:00
dfsek aa0de88821 @SuppressWarnings go brrr 2021-04-12 09:23:02 -07:00
dfsek bd3136ca92 fix stack size assumption at profiler start 2021-04-12 09:19:03 -07:00
dfsek 339413c0de profile more things 2021-04-12 08:46:56 -07:00
dfsek 31b55ca682 fancy unicode symbols B) 2021-04-12 01:16:26 -07:00
dfsek aaf0830d66 fix % parent issue 2021-04-12 00:46:00 -07:00
dfsek f78ee70609 implement terrascript profiling 2021-04-12 00:45:52 -07:00
dfsek 9c1a35f444 implement new profiler 2021-04-12 00:24:13 -07:00
dfsek f4716cb28f add autocloseable option 2021-04-12 00:07:22 -07:00
dfsek b3e3c28276 implement TerraPlugin#getProfier 2021-04-12 00:05:53 -07:00
dfsek 4eadbb7d83 improve performance in deep operations 2021-04-11 23:24:44 -07:00
dfsek 7b3b341627 improve data output 2021-04-11 23:08:32 -07:00
dfsek 89267ce8cb basic profiler implementation 2021-04-11 22:54:55 -07:00
dfsek 78e3575d9b Merge pull request #118 from PolyhedralDev/dev/directories
Remove hard-coded registries, allow addons to register custom config types, remove strict directory requirements
2021-04-11 21:26:36 -07:00
dfsek e671ef783f completely dynamic registries 2021-04-11 20:56:15 -07:00
dfsek 91144dc8f8 Merge remote-tracking branch 'origin/master' into dev/directories
# Conflicts:
#	build.gradle.kts
2021-04-11 18:57:33 -07:00
dfsek 4202875675 dynamic registris in WorldConfig 2021-04-11 03:15:44 -07:00
dfsek 4237657dad remove most hard coded registries 2021-04-11 02:39:21 -07:00
dfsek 75cb6be36f resolve merge issues 2021-04-11 00:53:21 -07:00
dfsek 88a7397bbe Merge branch 'ver/5.1.3' into dev/directories
# Conflicts:
#	common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java
#	common/src/main/java/com/dfsek/terra/registry/OpenRegistry.java
2021-04-11 00:51:51 -07:00
dfsek a6a1810b4a bump version 2021-04-05 17:08:57 -07:00
dfsek da4aebe498 fix parser EOF NPE 2021-04-05 17:08:50 -07:00
dfsek 03ebafc7b6 working config loading 2021-04-05 12:26:54 -07:00
dfsek a78e64a9bb rename ore "type" to "algorithm" 2021-04-05 09:59:52 -07:00
dfsek 6374b0ab08 add ConfigPack#getConfigTypeRegistry 2021-04-05 09:52:47 -07:00
dfsek 473ed45dee add config type registry to ConfigPack loader registry 2021-04-05 09:50:07 -07:00
dfsek d96d834a08 redo ConfigType and loading 2021-04-05 09:48:11 -07:00
dfsek f756ebef44 fix unhandled exception 2021-04-05 01:36:39 -07:00
dfsek e6931a53d6 basic implementation 2021-04-05 01:31:22 -07:00
dfsek 58b5f3a5fe bump Tectonic version 2021-04-05 00:27:58 -07:00
286 changed files with 2791 additions and 8516 deletions
+1 -1
View File
@@ -342,6 +342,6 @@ ij_json_wrap_long_lines = false
indent_size = 2
ij_yaml_keep_indents_on_empty_lines = true
ij_yaml_keep_line_breaks = true
ij_yaml_space_before_colon = false
ij_yaml_space_before_colon = true
ij_yaml_spaces_within_braces = true
ij_yaml_spaces_within_brackets = true
-19
View File
@@ -1,19 +0,0 @@
# Global owners, automatically request review when pull request is submitted
* @dfsek @solonovamax
# Platforms
## dfsek wrote the majority of the platform impls
/platforms/bukkit/ @dfsek
/platforms/fabric/ @dfsek
/platforms/forge/ @dfsek
/platforms/sponge/ @dfsek
## solonovamax is working on the region generator (unless duplexsystem takes it over)
/platforms/region/ @solonovamax
# Common
/common/ @dfsek @solonovamax
# Gradle Stuff
## Most gradle stuff was written by solonovamax
/buildSrc/ @solonovamax
*.gradle.kts @solonovamax
-105
View File
@@ -1,105 +0,0 @@
---
name: "Bug Report"
about: "Open a bug report to help us identify issues with Terra."
title: "[Bug] <Put your title here>"
labels: "Type: Bug, Status: Pending"
assignees: ""
---
<!--
##############################################################################
## WARNING! ##
## IGNORING THE FOLLOWING TEMPLATE WILL RESULT IN YOUR ISSUE BEING CLOSED ##
##############################################################################
-->
## Pre-Issue Checklist
<!--
Please go through this checklist item by item and make sure you have successfully completed each of these steps.
- You must be on the LATEST version of Terra to receive any support. There is no support for older versions of Terra.
- Make sure that this is not a *specific* compatibility issue with another terrain generation mod.
Do not request *specific* compatibility with mods or plugins (e.g. "Compatibility with TechCraft v7").
That should be implemented in an addon, **not** in the main project.
*General* compatibility (e.g. "Ability to pull Vanilla/Modded features from parent biomes") will be considered in the main project.
- Make sure that there are no already existing issues open with your problem. If you open a duplicate, it will be closed as such.
- Make sure that it is actually Terra causing the issue, and not another mod/plugin.
You can do this by testing to see if you can recreate the issue without Terra installed.
- Make sure that this is not an issue with a specific Terra *pack* or Terra *addon*, and instead applies to all of Terra.
- Make sure that you attach a copy of the latest.log file.
Putting *just* the exception IS NOT ENOUGH. We need to be able to check that there wasn't anything else before that caused it.
- Make sure that you have filled out all the required information and given descriptions of everything.
You must put an x in all the boxes you have completed. (Like this: [x])
To make sure that your issue is rendered properly, you may check the "Preview" tab (below the title) to see a rendered version of it before you submit it.
-->
- [ ] I have checked that I am on the latest version of Terra.
- [ ] I have searched the github issue tracker for similar issues, including closed ones.
- [ ] I have made sure that this is not a bug with another mod or plugin, and it is Terra that is causing the issue.
- [ ] I have checked that this is an issue with Terra and not an issue with the pack I am using.
<!-- If this is an issue with the default Terra pack, please open an issue on the pack repo: https://github.com/PolyhedralDev/TerraDefaultConfig/issues/new -->
- [ ] I have attached a copy of the `latest.log` file
- [ ] I have filled out and provided all the appropriate information.
## Environment
<!-- You can fill out the different items by putting the correct value beside each cell. -->
| Name | Value |
|------------------------------|-------|
| Terra Version | <!-- Put your Terra version here. (remove the comment) -->
| Platform / Platform Version | <!-- Put your platform and platform version here. (remove the comment) (eg. Spigot, Fabric, Paper, etc.) (If you are using the Region generator, put that here instead) -->
| Any External Plugins or Mods | <!-- Put a list of all the plugins or mods you have installed here. (remove the comment) (Make sure to NOT include any new lines) -->
| Terra Packs In Use | <!-- Put a list of all the Terra packs you have installed here. (remove the comment) (Make sure to NOT include any new lines) (/te packs may be used to get a list) -->
| Terra Addons In Use | <!-- Put a list of all the Terra addons you have installed here. (remove the comment) (Make sure to NOT include any new lines) (/te addons may be used to get a list) -->
## Issue Description
<!--
Put a quick description of the issue here.
Example: 'When generating terrain, something causes the chunks to not load properly', etc.
-->
### Steps to reproduce
<!--
Describe what you were doing when this happened.
Make sure to include ALL information. Including anything you were doing before that may have caused it.
-->
1. <!-- Put step #1 here. -->
2. <!-- Put step #2 here. -->
3. <!-- etc. -->
### Expected behavior
<!-- Describe what you think *should* happen here: -->
### Actual behavior
<!-- Describe what *actually* happens here: -->
<!-- example: When I do _______, it actually does _______ -->
### Full stacktrace
<details>
<summary>Exception Stacktrace</summary>
<!--
If Terra logs an exception, please put it in the following section: (You will find any error logs in your console, or your latest.log)
Note: this *must* be included, in ADDITION to the latest.log file.
-->
```
```
</details>
### Additional details
<!-- Any other information you think should be added -->
-70
View File
@@ -1,70 +0,0 @@
---
name: "Feature Request"
about: "Give us suggestions of features we could add to Terra."
title: "[Feature] <Put your title here>"
labels: "Type: Enhancement, Status: Pending"
assignees: ""
---
<!--
########################################################################################
## WARNING! ##
## IGNORING THE FOLLOWING TEMPLATE WILL RESULT IN YOUR FEATURE REQUEST BEING CLOSED ##
########################################################################################
-->
### Pre-Request Checklist
<!--
Please go through this checklist item by item and make sure you have successfully completed each of these steps.
- You must be on the LATEST version of Terra to make sure your feature hasn't been added yet.
- Make sure that there are no already existing feature requests similar to yours. (Including closed!) If you open a duplicate, it will be closed as such.
- Make sure that this is actually in the scope of Terra.
- Make sure that this is not a feature request that should be made for a specific Terra *pack*, and instead applies to all of Terra.
- Make sure that you attach a copy of the latest.log file, if there are any exceptions thrown in the console.
Putting *just* the exception IS NOT ENOUGH. We need to be able to check that there wasn't anything else before that caused it.
You must put an x in all the boxes you have completed. (Like this: [x])
To make sure that your issue is rendered properly, you may check the "Preview" tab (below the title) to see a rendered version of it before you submit it.
-->
- [ ] I have checked that I am on the latest version of Terra.
- [ ] I have searched github for similar features requests, including closed ones, and found none.
- [ ] I believe this is within the scope of Terra.
- [ ] This feature request is for *all* of Terra, and isn't something that should be implemented by a pack or addon.
## Feature Description
<!--
Quickly describe the basics of your feature request.
Example: 'More noise presets should be added to Terra.'
-->
### What Problem Does This Solve?
<!--
Describe here what the issue is that you have.
Examples: 'When I do _______, it annoys me that _______ does _______.' or 'There is not enough customization in _______ to do _______.'
NOTE: This should NOT be used for a bug report. If this is unintentional, then please submit a bug report instead.
-->
### A Solution You'd Like
<!-- Provide a clear and accurate description of how you would like this to be solved. -->
### Alternative Solutions
<!-- Provide a description of alternatives you have considered to this. -->
1. <!-- Alternative #1. -->
2. <!-- Alternative #2. -->
3. <!-- Alternative #3. -->
### Additonal Context
<!--
Is there any additional context you would like to add?
If not, you may remove this section.
-->
-11
View File
@@ -1,11 +0,0 @@
---
name: "Other Issue"
about: "Use this template if your issue doesn't accurately fit into any of the other categories."
title: ""
labels: "Type: Question, Status: Pending"
assignees: ""
---
## Describe the issue
<!-- Please describe the issue as clearly and as concisely as possible, without missing any details. -->
-11
View File
@@ -1,11 +0,0 @@
blank_issues_enabled: false
contact_links:
- name: Which Issue Template do I Choose?
url: https://github.com/PolyhedralDev/Terra/wiki/How-To-Choose-An-Issue-Template
about: Click this if you don't know which issue template to select. This will help you make sure you choose the right one and provide enough information for us to help you.
- name: Terra Wiki
url: https://github.com/PolyhedralDev/Terra/wiki
about: Documentation for all things Terra.
- name: Join the Support Discord
url: https://discord.dfsek.com
about: If you have a basic support question, join the Discord instead.
-114
View File
@@ -1,114 +0,0 @@
# Pull Request
## Brief description.
<!-- Please provide a brief description of the goals of your PR -->
<!--
###########################################################################
## WARNING! ##
## IGNORING THE FOLLOWING TEMPLATE WILL RESULT IN YOUR PR BEING CLOSED ##
###########################################################################
-->
<!--
Please go through this checklist item by item and make sure you have successfully completed each of these steps.
- Your pull request MUST be either on the latest version of Terra, or on a branch for a future release.
- Make sure that there are no already existing PRs that fix this. If so, it will be closed as a duplicate.
- Make sure that this change is actually within the scope of Terra and is something a terrain generator should be doing.
- Make sure that this is not an issue with a specific Terra *pack*, and instead applies to all of Terra.
- Make sure that you have filled out all the required information and given descriptions of everything.
-->
<!-- You can erase any parts of this template not applicable to your Pull Request. -->
### What Issues Does This Fix?
<!--
Put Fix #XXXX or Closes #XXXX here if there are any open issues that this PR fixes.
This is to automatically close the relevant issues.
You may remove this if there is no issue for this PR.
But unless this is a very small change, you should make an issue for it.
-->
## Licensing
<!-- In order to be accepted, your changes must be under the GPLv3 license. Please check one of the following: -->
- [ ] I am the original author of this code, and I am willing to release it under [GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html).
- [ ] I am not the original author of this code, but it is in public domain or released
under [GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html) or a compatible license.
<!--
Please provide reliable evidence of this.
NOTE: for compatible licenses, you must make sure to add the included license somewhere in the program, if so required.
(And even if it's not required, it's still nice to do it. Also add attribution somewhere.)
-->
## Goal of the PR
<!--
What is the goal of the PR?
Put a checklist here of what has been done
(and what *hasn't*, but you plan to do),
so we can easily know what was changed.
Note: this is only required for PRs that add new features.
If your PR is not adding new features, only fixing bugs or adding translations, then you may delete this section.
-->
- [ ] <!-- First thing -->
- [ ] <!-- A requirement of the first thing. -->
- [ ] <!-- A second requirement of the first thing. -->
- [ ] <!-- Second thing -->
- [ ] <!-- etc. -->
## Affects of the PR
<!---
What types of changes does your code introduce? (Select any that apply. You may select multiple.)
You must put an x in all the boxes that it applies to. (Like this: [x])
-->
#### Types of changes
- [ ] Bug Fix <!-- Anything which fixes an issue in Terra. -->
- [ ] Build system <!-- Anything which pretain to the build system. -->
- [ ] Documentation <!-- Anything which adds or improves documentation for existing features. -->
- [ ] New Feature <!-- Anything which adds new functionality to Terra. -->
- [ ] Performance <!-- Anything which is imrpoves the performance of Terra. -->
- [ ] Refactoring <!-- Anything which does not add any new code, only moves code around. -->
- [ ] Repository <!-- Anything which affects the repository. Eg. changes to the `README.md` file. -->
- [ ] Revert <!-- Anything which reverts previous commits. -->
- [ ] Style <!-- Anything which updates style. -->
- [ ] Tests <!-- Anything which adds or updates tests. -->
- [ ] Translation <!-- Anything which is internationalizing the Terra program to other languages. -->
#### Compatiblity
- [ ] Breaking change <!-- A fix, or a feature, that breaks some previous functionality to Terra. -->
- [ ] Non-Breaking change.
<!--
A change which does not break *any* previous functionality of Terra.
(ie. is backwards compatible and will work with *any* previously existing supported features.
Note: if a feature is annotated with @Incubating, @Preview, @Experimental,
or is in a package called something similar to the previous annotations,
then you may push breaking changes to only THOSE parts of Terra.)
-->
#### Contribution Guidelines.
- [ ] I have read the [`CONTRIBUTING.md`](https://github.com/PolyhedralDev/Terra/blob/master/CONTRIBUTING.md) document in the root of the
git repository.
- [ ] My code follows the code style for this
project. <!-- There is an included `.editorconfig` file in the base of the repo. Please use a plugin for your IDE of choice that follows those settings. -->
#### Documentation
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
#### Testing
- [ ] I have added tests to cover my changes.
- [ ] All new and existing tests passed.
<!--
If it only introduces small changes, you don't need to add tests.
But if you add big changes, you should probably at least write *some* testing, where applicable.
-->
+14 -11
View File
@@ -85,14 +85,14 @@ hs_err_pid*
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
.idea/artifacts
.idea/compiler.xml
.idea/jarRepositories.xml
.idea/modules.xml
.idea/**.iml
.idea/modules
*.iml
*.ipr
.idea/artifacts
.idea/compiler.xml
.idea/jarRepositories.xml
.idea/modules.xml
.idea/*.iml
.idea/modules
*.iml
*.ipr
# CMake
cmake-build-*/
@@ -137,7 +137,10 @@ build
.idea/modules/**.iml
!lib/*.jar
.idea/Terra.iml
/run/
idea/**
testDir/
.idea/**.iml
/lang/
/packs/
/config.yml
/region/
-337
View File
@@ -1,337 +0,0 @@
# Terra Community Code of Conduct
# TL;DR
Polyhedral Development is dedicated to providing a harassment-free experience for everyone, regardless of gender, gender identity and
expression, preferred pronouns, sexual orientation, disability, physical appearance, age, race, religion, etc. We do not tolerate harassment
of participants in any form.
This code of conduct applies to all Terra community spaces, including the github discussions tab, our
[community discord server](https://discord.gg/PXUEbbF), the [community subreddit](https://reddit.com/r/TerraGenerator), or any other Terra
space, both online and off. Anyone in violation of this code, as determined by the applicable moderators, may be subject to verbal warning,
expulsion from these spaces, or future events and activities for an undetermined amount of time.
Some Terra community spaces may have additional rules in place, which will be made clearly available to all participants. Participants are
responsible for knowing and abiding by these rules.
# Longer version
Polyhedral Development is dedicated to providing a harassment-free experience for everyone. We do not tolerate harassment of participants in
any form.
## When and How to Use These Guidelines
This code of conduct applies to all Terra community spaces, both online and off. This applies to the github discussion tab,
the [Polyhedral Development community discord server](https://discord.gg/PXUEbbF), and any other Terra community. In addition, we may choose
to invoke them in instances of harassment outside the Terra communities, and we will punish the responsible individuals appropriately. We
will not tolerate harassment in any form, even outside of Terra.
Some Terra spaces may have additional rules in place, which will be made clearly available to participants. Participants are responsible for
knowing and abiding by these rules, in addition to this code of conduct.
## Expected Behavior
The following behaviors are expected of all members of the Terra community:
### Be Respectful
Value each other's ideas, styles and viewpoints. We may not always agree, but disagreement is no excuse for poor manners. Be open to
different possibilities and to being wrong. Be respectful in all interactions and communications, especially when debating the merits of
different options. Be aware of your impact and how intense interactions may be affecting people. Be direct, constructive and positive. Take
responsibility for your impact, and your mistakes if someone says they have been harmed through your words or actions, listen carefully,
apologize sincerely, and correct the behavior going forward.
#### Be Prepared to Admit When You are Wrong
Any member of the Terra community should always be open to new ideas and must always be open to the possibility of being wrong. Nobody can
always be right, and we are only human; we are [fallible](https://www.merriam-webster.com/dictionary/fallible) by nature. It is okay to make
mistakes, but we must be willing to admit when we make one.
### Be Direct but Professional
We are likely to have some discussions about if and when criticism is respectful and when it's not. We must be able to speak directly when
we disagree and when we think we need to improve. We cannot withhold hard truths. Doing so respectfully is hard, doing so when others don't
seem to be listening is harder, and hearing such comments when one is the recipient can be even harder still. We need to be honest and
direct, as well as respectful.
### Be Inclusive
Seek diverse perspectives. Diversity of views and of people on teams powers innovation, even if it is not always comfortable. Encourage all
voices. Help new perspectives be heard and listen actively. If you find yourself dominating a discussion, it is especially important to step
back and encourage other voices to join in. Be aware of how much time is taken up by dominant members of the group. Provide alternative ways
to contribute or participate when possible.
Be inclusive of everyone in an interaction, respecting and facilitating people's participation whether they are:
- Not native language speakers
- Coming from a different culture
- Using pronouns other than "he", "she", or "they"
- Living in a different time zone
- Facing other challenges to participate
- Or anything else. Be respectful of *everyone* at *all times*.
Think about how you might facilitate alternative ways to contribute or participate. If you find yourself dominating a discussion, step back.
Make way for other voices and listen actively to them.
### Understand Different Perspectives
Our goal should not be to "win" every disagreement or argument. A more productive goal is to be open to ideas that make our own ideas
better. Strive to be an example for inclusive thinking. "Winning" is when different perspectives make our work richer and stronger. That
means, you must pay attention to all ideas proposed. Don't disregard one without giving it the attention it deserves.
### Appreciate and Accommodate Our Similarities and Differences
People come from many cultures and backgrounds. Cultural differences can encompass everything from official religious observances to
personal habits to clothing. Be respectful of anyone with different cultural practices, attitudes and beliefs. Work to eliminate your own
biases, prejudices and discriminatory practices. Think of others' needs from their point of view. Use preferred titles (including
pronouns<sup>[\[1\]](#1)</sup>) and the appropriate tone of voice. Respect people's right to privacy and confidentiality. Be open to
learning from and educating others as well as educating yourself; it is unrealistic to expect someone to know the cultural practices of
every ethnic and cultural group. Therefore we must be ready to correct someone if they make a mistake, and must be ready ourselves to change
and learn if we make a mistake.
### Lead by Example
By matching your actions with your words, you become a person others want to follow. Your actions influence others to behave and respond in
ways that are valuable and appropriate for our organizational outcomes. Design your community and your work for inclusion. Hold yourself and
others accountable for inclusive behaviors.
## Behavior That Will Not Be Tolerated
The following behaviors are considered to be unacceptable and will not be tolerated:
### Violence and Threats of Violence
Violence and threats of violence are not acceptable - online or offline. This includes incitement of violence toward any individual,
including encouraging a person to commit self-harm, engage in self-harm, or put themselves in a negative position (e.g. one which can lead
to an increase of depression, etc.).
### Personal Attacks
Conflicts will inevitably arise, but frustration should never turn into a personal attack. It is not okay to insult, demean or belittle
others. Attacking someone for their opinions, beliefs and ideas is not acceptable. It is important to speak directly when we disagree and
when we think we need to improve, but such discussions must be conducted respectfully and professionally, remaining focused on the issue at
hand.
### Derogatory Language
Offensive, unwelcome, or hurtful comments related to:
- Gender
- Gender identity or expression
- Preferred pronouns<sup>[\[1\]](#1)</sup>
- Marital status
- Sex
- Sexual orientation or identity
- Native language
- Age
- (Dis)ability
- Mental illness
- Neuro(a)typicality
- Race and/or ethnicity
- Physical appearance
- A person's lifestyle choices or practices,
- A person's physical condition
- A person's mental condition
- Socioeconomic status
- Religion
- Employment
- Or anything really. Just don't be offensive towards people, insult them, or make unwanted comments.
is not acceptable. This includes deliberately referring to someone by a gender that they do not identify with, and/or questioning the
legitimacy of an individual's gender identity. If you're unsure if a word is derogatory, don't use it. This also includes repeated subtle
and/or indirect discrimination; when asked to stop, stop the behavior in question.
### Unwelcome Sexual Attention or Physical Contact
Unwelcome sexual attention or unwelcome physical contact is not acceptable. This includes sexualized comments, jokes or imagery in
interactions, communications or presentation materials, as well as inappropriate touching, groping, or sexual advances. Additionally,
touching a person without permission, including sensitive areas such as their hair, pregnant stomach, mobility device (wheelchair, scooter,
etc) or tattoos is unacceptable. This includes physically blocking or intimidating another person. Physical contact or simulated physical
contact (e.g. emojis like ":&#8203;kiss:", ":hug:", or ":kiss_mark:", textual descriptions like "\*hug\*", "\*backrub\*", or "\*kisses
you\*", etc.) without affirmative consent or after a request to stop will not be accepted.
### Sexual Behaviour Where it is Not Appropriate
Uninvited or off-topic sexual images, text, or behaviour in spaces where they're not appropriate will not be accepted whatsoever. We are an
open community, which means spaces must be appropriate for all ages, and everybody must feel comfortable. Discussion of sexual things, will
be prohibited unless otherwise noted.
### Discussion of Sensitive Topics
Discussion of sensitive topics when asked to stop, or when not appropriate. Including, but not limited to:
- Anything sexual
- Gore
- Suicide
- Self harm
- Anything related to death
- Or really anything that someone may be sensitive about.
shall not be tolerated. As a community for all ages and all kinds of people, we must cater to everyone, and must make sure everyone feels
comfortable here. Repeatedly breaking someone else's boundaries will not be tolerated.
### Disruptive Behavior
Sustained disruption of events, forums, or meetings, online or otherwise, including talks and presentations, will not be tolerated. This
includes:
- 'Talking over', 'heckling', or otherwise disrupting speakers.
- Making derogatory comments about someone else's choices, pushing people to do something they do not wish to do, talking about their
choices or personal preferences to others, or pressuring them to do something they don't wish to - physically or through jeering.
- Behaviour that intentionally disrupts an event.
- Otherwise influencing actions that may cause hostility in the session.
### Influencing Unacceptable Behavior
We will treat influencing or leading such activities the same way we treat the activities themselves, and thus the same consequences apply.
To make someone do something bad is the same thing as if you were to do it yourself, and we will not tolerate it.
### Stalking or Following
Stalking or following in any form (offline or online) is unnacceptable. In addition, you may not take pictures or record video of others
without their express permission or when asked to stop. Any individual may also request for you to delete all footage you have of them, even
if you took it with their prior consent.
### Publication of Personal Information
The publication of personally identifying information (commonly known as "[doxxing](https://en.wikipedia.org/wiki/Doxing)") is directly
prohibited. You may not publish information that someone wants to keep private, unless it is necessary to protect vulnerable people from
intentional abuse. Addditionally, you may not deliberately "out" any aspect of a person's identity without their consent, this includes
gender, pronouns, sexual identity, etc.
Unless it pretains to a case of harassment, as outlined here, in which case some personally identifying information may need to be brought
up in private with the appropriate moderation team to help aid our efforts in keeping the community safe.
### Deliberate Misuse of Pronouns<sup>[\[1\]](#1)</sup> or Names
As an inclusive community, we must respect everyone. That means respecting the pronouns or names they wish for us to use. Deliberate
misgendering, misuse of preferred pronouns<sup>[\[1\]](#1)</sup>, or use of 'dead' or rejected names is not to be tolerated. (If someone
*accidentally* uses the incorrect pronouns, gender, or name, politely ask them to use the correct pronouns/gender/name. But if they are to
continue using the incorrect pronouns, gender, or name, then you should escalate and report them to us.)
### Not Stopping After Multiple Requests
If someone asks you to stop doing something, then you should stop. Continuing to do it may be considered harassment, and can lead you to be
removed from our community.
## Complains We May Ignore
Additionally, Terra prioritizes marginalized people's safety over privileged people's comfort. We reserve the right to ignore complaints
regarding:
- Claims of discrimination against non-marginalized or oppressed groups (eg. being 'superphobic', meaning to not support people who are
'superstraight', which is a dog whistle for transphobic groups, or being 'cisphobic' without large amounts of evidence, etc.), or claims
of discrimination with no evidence. (Basically, don't report 'cisphobia' to us, because it doesn't exist. But if someone is mocking you or
making fun of you for being cis, and it is *really* getting out of hand, then do tell us.)
- Reasonable communication of boundaries, such as "leave me alone," "go away," or "I'm not discussing this with you." (If someone is asking
you to stop, that is not reason for you to report them as harassing you.)
- Communicating in a 'tone' you don't find [congenial](https://www.thefreedictionary.com/congenial). (You may not report someone for
harassment for being 'annoyed with you' or 'talking sternly to you')
- Criticizing or calling out racist, sexist, discriminatory, or otherwise oppressive behavior or assumptions. (You may not say that someone
is harassing you if they are telling you to stop discriminating against someone.)
- Disagreements that do not qualify as harassment. If you have a simple disagreement with someone, and they have not been discriminating to
anyone, in any form, then we will not take action against them. Two people are allowed to disagree on things without it getting toxic.
We may also additionally choose to enact punishment for submitting a complaint in bad-faith or without adequate justification, if we deem
necessary; if you're submitting a complaint just to troll or to annoy people, we may choose to have you banned or removed from the community
spaces. Don't waste our time.
In order to protect volunteers from abuse and burnout, we reserve the right to reject any report we believe to have been made in bad faith
or with misintent. Reports intended to silence legitimate criticism may be deleted without response.
## Reporting
Terra has a global moderation team which is currently comprised of the following members:
- solonovamax
- discord: [@solonovamax#6983](https://discord.com/channels/@me/566146322273402881)*
- github: [@solonovamax](https://github.com/solonovamax)
- email: [solonovamax@12oclockpoint.com](mailto:solonovamax@12oclockpoint.com)
- dfsek
- discord: [@dfsek#4208](https://discord.com/channels/@me/378350362236682240)*
- github: [@dfsek](https://github.com/dfsek)
- email: [dfsek@protonmail.com](mailto:dfsek@protonmail.com)
- duplex (duplexsystem)
- discord: [@Duplex#0797](https://discord.com/channels/@me/356822848641171456)*
- github: [@duplexsystem](https://github.com/duplexsystem)
- email: [duplexsys@protonmail.com](mailto:duplexsys@protonmail.com)
\* The preferred method of communication is through discord. Although we will still be responsive on the other platforms, we will be more
responsive on discord.
These are people you can contact for anything regarding this code of conduct.
If you are being harassed by a member of the Terra community, or by someone in a Terra community space, notice that someone else is being
harassed, or have any other concerns, please contact a moderator of the platform it occurred on, or someone on the global moderation team.
If the person who is harassing you is on the global moderation team, they will [recuse](https://www.thefreedictionary.com/recuse) themselves
from handling your incident. (Meaning: if you are reporting someone on the team, they will not be involved in the discussion.) We will
respond within a reasonable time frame, but generally within about 1 day.
This code of conduct applies to Terra community spaces, but if you are being harassed by a member of Terra *outside* our spaces, we still
want to know about it as we may choose to take action within our community. We will take all good-faith reports seriously and will always
attempt to handle them appropriately. This includes harassment outside our spaces and harassment that took place at any point in time. The
moderation team reserves the right to exclude people from Terra communities based on their past behavior, including behavior outside Terra
spaces and behavior towards people who are not in Terra.
Note: although we only have the ability to moderate official community spaces, if you are being harassed by someone in a non-official
community space, and the moderation team of that platform refuses to do anything to help you (or even if they *do* help you), then you
should notify us so that we may take appropriate action.
We will respect confidentiality requests for the purpose of protecting victims of abuse. At our discretion, we may publicly name a person
which we have received harassment complaints about, or privately warn third parties about them, but only if we believe that doing so will
increase the safety of Terra community members or the general public. We will not name harassment victims or reporters of harassment
(assuming the report was made in good-faith) without their explicit consent; all reports will remain anonymous by default.
## Consequences of Unacceptable Behavior
Participants asked to stop any harassing behavior are expected to comply immediately. Whether or not you comply immediately, you may still
face consequences for you actions, but if the harasser doesn't comply immediately then we may choose to take additional actions to protect
the Terra community members or the individual being harassed.
Violation of this code can result in being asked to leave an event or online space, either temporarily or for the duration of the event, or
being banned from participation in spaces, or future events and activities in perpetuity. If a participant engages in harassing behavior,
the global moderation team may take any action they deem appropriate, up to and including expulsion from all Terra community spaces and
identification of the participant as a harasser to other Terra community members or the general public. Bad behavior from any community
member, including those with decision-making authority, will not be tolerated.
In addition, any participants who abuse the reporting process will be considered to be in violation of these guidelines and subject to
consequences. False reporting, especially to retaliate or exclude, will not be accepted or tolerated.
## Questions
if you have further questions for anything not addressed here, you may open an issue on this github repo, or contact a member of the global
moderation team.
## License and Attribution
This set of guidelines is distributed under a
[Creative Commons Attribution-ShareAlike license](https://creativecommons.org/licenses/by-sa/3.0/).
These guidelines have been adapted from
[Mozilla's Community Participation Guidelines](https://www.mozilla.org/en-US/about/governance/policies/participation/), which were adapted
from:
- Mozilla's original Community Participation Guidelines
- The [Ubuntu Code of Conduct](https://ubuntu.com/community/code-of-conduct)
- Mozilla's [View Source Conference Code of Conduct](https://viewsourceconf.org/berlin-2016/code-of-conduct/)
- And the [Rust Language Code of Conduct](https://www.rust-lang.org/policies/code-of-conduct)
which in turn were based on [Stumptown Syndicate's Citizen Code of Conduct](http://citizencodeofconduct.org/), along with some adapted text
from the [LGBTQ in Technology Code of Conduct](https://lgbtq.technology/coc.html) and
the [WisCon code of conduct](http://wiscon.net/policies/anti-harassment/code-of-conduct/).
It was then modified by solonovamax with various inclusions from
the [LGBTQ in Technology Code of Conduct](https://lgbtq.technology/coc.html) and a few other sources.
## Notes
#### \[1\]
You provide a set of pronouns that everyone is comfortable addressing you with. Although some people are comfortable
using [neopronouns](https://www.mypronouns.org/neopronouns), not everyone is. Therefore, if you use neopronouns, you should have at *least*
one set of more common pronouns (One of he/him, she/her, or they/them; it doesn't matter which one. Anyone who doesn't respect your basic
pronouns will be removed from the community.) that people may use, should they so choose, as some people are not comfortable
using [neopronouns](https://www.mypronouns.org/neopronouns). But if someone refuses to use your more common pronouns, you should report them
to us. Additionally, you may not ask people to use unreasonable pronouns, such as 'acab/acabself', 'that/bitch', 'ur/mom', or
'dream/dreamself' (pronouns related to real people, eg. the minecraft youtuber 'dreamwastaken'). Doing so will be considered mockery of
individuals who use non-standard pronouns and is very disrespectful.
-319
View File
@@ -1,319 +0,0 @@
# Contributing to Terra
First off, thank you for considering contributing to Terra. It's people like you that make Terra such a great tool.
Following these guidelines helps to effectively use the time of the developers managing and developing this open source project, making it
more enjoyable for all of us.
Terra is an open source project and we love to receive contributions from our community, you! There are many ways to contribute, from
writing tutorials or blog posts, improving the documentation, submitting bug reports and feature requests or writing code which can be
incorporated into Terra.
The following is a set of guidelines for contributing to Terra and its packages, which are hosted in
the [PolyhedralDev Organization](https://github.com/PolyhedralDev) on GitHub. These are mostly guidelines, not rules. Use your best
judgment, and feel free to propose changes to this document in a pull request.
#### Table Of Contents
[Code of Conduct](#code-of-conduct)
[I don't want to read this whole thing, I just have a question!!!](#i-dont-want-to-read-this-whole-thing-i-just-have-a-question)
[Getting Started](#getting-started)
- [Your First Contribution](#your-first-contribution)
- [Reporting Bugs](#reporting-bugs)
- [Before Submitting A Bug Report](#before-submitting-a-bug-report)
- [How Do I Submit A (Good) Bug Report?](#how-do-i-submit-a-good-bug-report)
- [Suggesting Enhancements](#suggesting-enhancements)
- [Before Submitting An Enhancement Suggestion](#before-submitting-an-enhancement-suggestion)
- [How Do I Submit A (Good) Enhancement Suggestion?](#how-do-i-submit-a-good-enhancement-suggestion)
- [Pull Requests](#pull-requests)
- [Before Submitting A Pull Request](#before-submitting-a-pull-request)
- [How Do I Submit A (Good) Pull Request?](#how-do-i-submit-a-good-pull-request)
[Styleguides](#styleguides)
- [Git Commits](#git-commits)
- [Committing](#committing)
- [Git Commit Messages](#git-commit-messages)
- [Code Styleguide](#code-styleguide)
- [Documentation Styleguide](#documentation-styleguide)
- TODO
[Coding Pratices](#coding-practices)
- [Compatibility](#compatibility)
- [General Compatibility](#general-compatibility)
- [Specific Compatibility](#specific-compatibility)
- [Platform-Agnostic Design](#platform-agnostic-design)
- [Data-Driven](#data-driven)
## Code of Conduct
This project and everyone participating in it is governed by the [Terra of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected
to uphold this code. Please report unacceptable behavior to [Terra global moderation team](CODE_OF_CONDUCT.md#Reporting).
## I don't want to read this whole thing I just have a question!!!
> **Note:** Please don't file an issue to ask a question. You'll get faster results by using the resources below.
We have an official discord server where you can request help from various users
- [The official PolyhedralDev discord server](https://discord.dfsek.com)
## Getting Started
### Your First Contribution
Unsure where to begin contributing to Terra? You can start by looking through "beginner" and "help wanted" issues:
- [Beginner issues](https://github.com/PolyhedralDev/Terra/labels/Note%3A%20Good%20First%20Issue) - issues which should be friendly to
anyone new to terra.
- [Help wanted issues](https://github.com/PolyhedralDev/Terra/labels/Note%3A%20Help%20Wanted) - issues which should be a bit more involved
than "beginner" issues.
New to github? Working on your first Pull Request? Check
out [How to Contribute to an Open Source Project on GitHub](https://app.egghead.io/playlists/how-to-contribute-to-an-open-source-project-on-github)
to get you up on your feet.
At this point, you're ready to make your changes! Feel free to ask for help; everyone is a beginner at first!
If a maintainer asks you to "rebase" your PR, they're saying that a lot of code has changed, and that you need to update your branch so it's
easier to merge.
### Reporting Bugs
This section guides you through submitting a bug report for Terra. Following these guidelines helps maintainers and the community understand
your report, and spend their time fixing the issue instead of understanding what you mean.
Before creating bug reports, please check [this list](#before-submitting-a-bug-report) as you might find out that you don't need to create
one. When you are creating a bug report, please [include as many details as possible](#how-do-i-submit-a-good-bug-report).
> **Note:** If you find a **Closed** issue that seems like it is the same thing that you're experiencing, open a new issue and include a link to the original issue in the body of your new one.
#### Before Submitting A Bug Report
- Join the [discord server](https://discord.dfsek.com) to help resolve simple issues.
- You must be on the LATEST version of Terra to receive any support. There is no support for older versions of Terra.
- Make sure that this is not a *specific* compatibility issue with another terrain generation mod. Do not request *specific* compatibility
with mods or plugins (e.g. "Compatibility with TechCraft v7"). That should be implemented in an addon, **not** in the main project.
*General* compatibility (e.g. "Ability to pull Vanilla/Modded features from parent biomes") will be considered in the main project.
- Search for any [already existing issues](https://github.com/PolyhedralDev/Terra/issues?q=is%3Aissue+) open with your problem. If you open
a duplicate, it will be closed as such.
- Make sure that it is actually Terra causing the issue, and not another mod/plugin. You can do this by testing to see if you can recreate
the issue without Terra installed.
- Double check that this is not an issue with a specific Terra *pack* or Terra *addon*, and instead applies to all of Terra.
- Include a copy of the latest.log file. Putting *just* the exception is not enough. We need to be able to check that there wasn't anything
else before that caused it.
- Be sure to fill out all the required information and give descriptions of everything.
#### How Do I Submit A (Good) Bug Report?
Bugs are tracked as [GitHub issues](https://guides.github.com/features/issues/)
. [Create an issue](https://github.com/PolyhedralDev/Terra/issues/new) and provide the prerequisite information by filling in the Bug Report
template.
Explain the problem and include additional details to help maintainers reproduce the problem:
- **Use a clear and descriptive title** for the issue to identify the problem.
- **Describe the exact steps which reproduce the problem** in as many details as possible. When listing steps, **don't just say what you
did, but explain how you did it**.
- **Provide specific examples to demonstrate the steps**.
- **Describe the behavior you observed after following the steps** and point out what exactly is the problem with that behavior.
- **Explain which behavior you expected to see instead and why.**
- **If the problem wasn't triggered by a specific action**, describe what you were doing before the problem happened and share more
information using the guidelines below.
Include details about your configuration and environment:
- **Which version of Terra are you using?** You can get the exact version by running `/te version`.
- **What's the name and version of the platform you're using**? (eg. Spigot, Fabric, Paper, etc.)
- **Which external plugins or mods do you have installed?**
- **Which Terra packs do you have installed?** You can get that list by running `/te packs`.
- **Which Terra addons do you have installed?** You can get that list by running `/te addons`.
### Suggesting Enhancements
This section guides you through submitting an enhancement suggestion for Terra, including completely new features and minor improvements to
existing functionality. Following these guidelines helps maintainers and the community understand your suggestion and find related
suggestions.
Before creating enhancement suggestions, please check [this list](#before-submitting-an-enhancement-suggestion) as you might find out that
you don't need to create one. When you are creating an enhancement suggestion,
please [include as many details as possible](#how-do-i-submit-a-good-enhancement-suggestion).
#### Before Submitting An Enhancement Suggestion
- You must be on the **LATEST** version of Terra to make sure your feature hasn't been added yet.
- Search for any [already existing issues](https://github.com/PolyhedralDev/Terra/issues?q=is%3Aissue+) (Including closed!) with your
problem. If you open a duplicate, it will be closed as such.
- Verify that this is actually within the scope of Terra.
- Be sure that this is not a feature request that should be made for a specific Terra *pack*, and instead applies to all of Terra.
- Be sure that this is not something that should be implemented as a Terra addon, and instead applies to all of Terra.
- Make sure that you attach a copy of the latest.log file, if there are any exceptions thrown in the console. Putting *just* the exception
**is not enough**. We need to be able to check that there wasn't anything else before that caused it.
#### How Do I Submit A (Good) Enhancement Suggestion?
Enhancement suggestions are tracked as [GitHub issues](https://guides.github.com/features/issues/). Create an issue on our main repository
and provide the following information:
- **Use a clear and descriptive title** for the issue to identify the suggestion.
- **Provide a step-by-step description of the suggested enhancement** in as many details as possible.
- **Provide specific examples to demonstrate the steps**.
- **Describe the current behavior** and **explain which behavior you expected to see instead** and why.
- **Explain why this enhancement would be useful** to most Terra users and isn't something that can or should be implemented as an addon.
### Pull Requests
This section guides you through submitting a pull request for Terra.
While the prerequisites above must be satisfied prior to having your pull request reviewed, the reviewer(s) may ask you to complete
additional design work, tests, or other changes before your pull request can be ultimately accepted.
#### Before Submitting A Pull Request
- You must be on the **LATEST** version of Terra to make sure your feature hasn't been added yet.
- Search for any [already existing issues](https://github.com/PolyhedralDev/Terra/issues?q=is%3Aissue+) (Including closed!) with your
problem. If you open a duplicate, it will be closed as such.
- Verify that this is actually within the scope of Terra.
- Be sure that this is not a feature request that should be made for a specific Terra *pack*, and instead applies to all of Terra.
- Be sure that this is not something that should be implemented as a Terra addon, and instead applies to all of Terra.
- Make sure that you attach a copy of the latest.log file, if there are any exceptions thrown in the console. Putting *just* the
exception **is not enough**. We need to be able to check that there wasn't anything else before that caused it.
#### How Do I Submit A (Good) Pull Request?
Pull Requests are tracked as [GitHub Pull Requests](https://guides.github.com/activities/forking/#making-a-pull-request). Create a pr on our
main repository and provide the following information:
- **Use a clear and descriptive title** to identify the pull request.
- **State what this pull request adds/fixes**.
- **Be sure that you are the owner of the code you contributed** or that it can be licensed under the GPLv3.
- **Provide a description goals and non-goals of the pull request** in as many details as possible.
- **Describe the current behavior** and **explain which behavior you expected to see instead** and why.
- **Explain why this enhancement would be useful** to most Terra users and isn't something that can or should be implemented as an addon.
## Styleguides
### Git Commits
Following this is not mandatory, but rather a set of guidelines. As long as your commit messages aren't absolutely awful, it's probably
fine. But it would be nice if you followed them.
#### Committing
When you commit code, try to avoid committing large amounts of code in a single go. Splitting up code into smaller commits is much nicer and
makes it easier to trace a feature to a single commit.
Try to stick to one feature/fix/etc. per commit. A good rule of thumb is if you need to use the word "and" in the subject line, then it
should probably™ be two commits.
#### Git Commit Messages
- Subject line must fit the following format: `<type>: <short summary>`. Type must be one of the following:
- Build: Changes that affect the build system or external dependencies.
- Docs: Documentation only changes.
- Feat: A new feature.
- Fix: A bug fix.
- Perf: Performance improvements.
- Refactor: Refactoring sections of the codebase.
- Repo: Changes to the repository structure that do not affect code. (Eg. modification of the `README.md` file, etc.)
- Revert: Revert a previous commit.
- Style: Code style updates.
- Test: Anything related to testing.
- Trans: Translation and localization of Terra to other languages.
- WIP: Work in progress.
- Separate the subject line from the body with a single blank line.
- Do not end subject line with a period.
- Limit the subject line to 50 or less.
- The subject line and all body lines should be in sentence case.
- Use the present tense. ("Add feature" not "Added feature")
- Use the imperative mood. ("Move cursor to..." not "Moves cursor to...")
- Reference relevant issues and pull requests in the body.
>
> Here is a template you can follow:
> ```
> Capitalized, short (50 chars or less) summary
>
> More detailed explanatory text, if necessary. Wrap it to about 72
> characters or so. In some contexts, the first line is treated as
> the subject of the commit and the rest of the text as the body. The
> blank line separating the summary from the body is critical (unless
> you omit the body entirely); various tools like `log`, `shortlog` and
> `rebase` can get confused if you run the two together.
>
> Explain the problem that this commit is solving. Focus on why you are
> making this change as opposed to how (the code explains that). Are
> there side effects or other unintuitive consequences of this
> change? Here's the place to explain them.
>
>
> Further paragraphs come after blank lines.
> - Bullet points are okay, too
> - Typically a hyphen or asterisk is used for the bullet, followed
> by a single space, with blank lines in between, but conventions vary
> here
> - Use a hanging indent
>
> Reference any relevant issues at the bottom, like so:
>
> Resolves: #123
> See also: #456, #789
> ```
### Code Styleguide
Use an IDE with support for `.editorconfig` files. There is an included editorconfig file in the base of the project so that your IDE should
automatically use the correct code style settings.
### Documentation Styleguide
TODO
## Coding Practices
### Compatibility
#### General Compatibility
General compatibility (example: injection of Vanilla structures/features/carvers into packs) is acceptable in the main project.
- General compatibility features should be *disabled by default*. Having things auto-injected causes unpredictable behaviour that is
annoying to diagnose. General-compatibility options should have config values attached which are disabled by default.
- These config options should also be *simple to use*. Think of the people who will be using these compatibility options. They want to flick
a switch and have things be compatible. That means that a majority of compatibility options should stay in `pack.yml`, to make it simple
to go into a pack and turn on specific compatibilities. This does *not* mean that more advanced compatibility options are off the table,
for example, look at Feature compatibility, where features can either be automatically injected, *or* configured individually per Terra
biome, depending on how much control the user wants.
#### Specific Compatibility
Specific compatibility should *not* be put in the main project. (Example: Adding the ability to generate TechCraft v7's doo-dads with a
TerraScript function)
Having specific compatibilities leads to tons of extra dependencies to keep track of, as well as adding lots of additional stuff to
maintain. It quickly becomes a mess. Especially when most users will never need to use this feature.
We have designed an addon API for exactly this purpose. **Specific compatibilities are welcome and encouraged, in the form of addons.**
### Platform-Agnostic Design
Terra must, at all times, remain platform agnostic. This means it must be able to run on theoretically any voxel based platform. Including
non-minecraft games like Terasology.
When adding a new feature to `common`, make no assumptions about what platform it'll be running on.
Examples:
- Don't assume the world height is 256.
- Don't assume that a specific block, item, or entity exists. (Eg. don't assume there exists a block called `minecraft:grass_block`)
### Data-Driven
When adding a new feature, make it abstract. Don't make assumptions about "specific use cases." If you can only think of a few use cases,
your idea should probably be generalized.
You must use configs effectively. Make configs that are *powerful* but also *make sense* and are \[easy\] to use.
+10 -26
View File
@@ -7,40 +7,24 @@ to your specifications, with no knowledge of Java required.
* Paper+ servers (Paper, Tuinity, Purpur, etc): [SpigotMC](https://www.spigotmc.org/resources/85151/)
* Fabric: [Modrinth](https://modrinth.com/mod/terra) / [CurseForge](https://www.curseforge.com/minecraft/mc-mods/terra-world-generator)
* Forge **(ALPHA - NOT PRODUCTION-READY)**: [Modrinth](https://modrinth.com/mod/terra) / [CurseForge](https://www.curseforge.com/minecraft/mc-mods/terra-world-generator)
## Building and Running Terra
## Building and running Terra
To build, simply run `./gradlew build` (`gradlew.bat build` on Windows). This will build all platforms, and
produce JARs in `platforms/<platform>/build/libs`
To build, simply run `./gradlew build` (`gradlew.bat build` on Windows). This will produce a jar in `build/libs`
called `Terra-[CURRENT VERSION].jar`. You can put this right into your plugins dir, along with the correct Gaea version.
### Production JARs:
* Bukkit: `Terra-<version>-shaded.jar`
* Fabric: `Terra-<version>-shaded-mapped.jar`
* Forge: `Terra-<version>-shaded.jar`
If you would like to test it with a default server config, just run `./gradlew setupServer` or
`./gradlew.bat setupServer` to set up the server, then `./gradlew testWithPaper` or `gradlew.bat testWithPaper` to run the server. If you
want a clean installation of the server, re-run the `setupServer` task. This will download a default server config
from [here](https://github.com/PolyhedralDev/WorldGenTestServer)
and install the server in the `target/server` directory, along with all the needed plugins.
### Building a Specific Platform
To build a specific platform, run `gradlew :platforms:<platform>:build`.
**Note: You will need to adjust the `NAME` variable `bukkit.yml` of the test server if you are not using the default Terra config.**
JARs are produced in `platforms/<platform>/build/libs`.
### Running Minecraft in the IDE
To run Minecraft with Terra in the IDE (for testing) use the following tasks:
* Bukkit
* `installPaper` - Install a [Paper](https://github.com/PaperMC/Paper) test server. (Only needs to be run once).
* `installPurpur` - Install a [Purpur](https://github.com/pl3xgaming/Purpur) test server. (Only needs to be run once).
* `runPaper` - Run the Paper test server with Terra (`installPaper` must have been run previously).
* `runPurpur` - Run the Purpur test server with Terra (`installPurpur` must have been run previously).
* Fabric
* `runClient` - Run a Minecraft Fabric client with Terra installed.
* `runServer` - Run a Minecraft Fabric server with Terra installed.
* Forge
* `runClient` - Run a Minecraft Forge client with Terra installed.
* `runServer` - Run a Minecraft Forge server with Terra installed.
## Contributing
Contributions are welcome! If you want to see a feature in Terra, please, open an issue, or implement it yourself and
submit a PR!
Join the discord [here](https://discord.gg/PXUEbbF) if you would like to talk more about the project!
## Beta
Terra is still in beta! While it is stable, it is not feature-complete. There is a lot to be added!
Terra is still in beta! While it is stable, it is not feature-complete. There is a lot to be added!
+1 -18
View File
@@ -1,27 +1,10 @@
import com.dfsek.terra.getGitHash
val versionObj = Version("5", "3", "3", true)
val versionObj = Version("6", "0", "0", true)
allprojects {
version = versionObj
group = "com.dfsek.terra"
tasks.withType<JavaCompile>().configureEach {
options.isFork = true
options.isIncremental = true
}
tasks.withType<Test>().configureEach {
useJUnitPlatform()
maxHeapSize = "2G"
ignoreFailures = false
failFast = true
maxParallelForks = (Runtime.getRuntime().availableProcessors() - 1).takeIf { it > 0 } ?: 1
reports.html.isEnabled = false
reports.junitXml.isEnabled = false
}
}
/**
* Version class that does version stuff.
@@ -7,11 +7,26 @@ import org.gradle.kotlin.dsl.withType
import java.io.ByteArrayOutputStream
fun Project.configureCommon() {
apply(plugin = "java-library")
apply(plugin = "maven-publish")
apply(plugin = "idea")
configureDependencies()
configureCompilation()
configureDistribution()
version = rootProject.version
tasks.withType<Test>().configureEach {
useJUnitPlatform()
maxHeapSize = "2G"
ignoreFailures = false
failFast = true
maxParallelForks = 12
}
}
fun Project.getGitHash(): String {
@@ -3,16 +3,14 @@ package com.dfsek.terra
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginConvention
import org.gradle.api.tasks.bundling.Jar
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.api.tasks.javadoc.Javadoc
import org.gradle.kotlin.dsl.*
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.filter
import org.gradle.kotlin.dsl.withType
import org.gradle.language.jvm.tasks.ProcessResources
fun Project.configureCompilation() {
apply(plugin = "maven-publish")
apply(plugin = "idea")
configure<JavaPluginConvention> {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
@@ -21,7 +19,7 @@ fun Project.configureCompilation() {
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
doFirst {
options.compilerArgs.add("-Xlint:all")
options.compilerArgs = mutableListOf("-Xlint:all")
}
}
@@ -29,12 +27,7 @@ fun Project.configureCompilation() {
include("**/*.*")
filter<org.apache.tools.ant.filters.ReplaceTokens>(
"tokens" to mapOf(
"VERSION" to project.version.toString(),
"DESCRIPTION" to project.properties["terra.description"],
"WIKI" to project.properties["terra.wiki"],
"SOURCE" to project.properties["terra.source"],
"ISSUES" to project.properties["terra.issues"],
"LICENSE" to project.properties["terra.license"]
"VERSION" to project.version.toString()
)
)
}
@@ -42,19 +35,4 @@ fun Project.configureCompilation() {
tasks.withType<Javadoc> {
options.encoding = "UTF-8"
}
tasks.withType<Jar> {
archiveBaseName.set("Terra-${archiveBaseName.get()}")
from("../LICENSE", "../../LICENSE")
}
tasks.register<Jar>("sourcesJar") {
archiveClassifier.set("sources")
}
tasks.register<Jar>("javadocJar") {
dependsOn("javadoc")
archiveClassifier.set("javadoc")
from(tasks.getByName<Javadoc>("javadoc").destinationDir)
}
}
@@ -1,27 +1,13 @@
package com.dfsek.terra
import org.gradle.api.Project
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.invoke
import org.gradle.kotlin.dsl.repositories
fun Project.configureDependencies() {
apply(plugin = "java")
apply(plugin = "java-library")
configurations {
val shaded = create("shaded")
val shadedApi = create("shadedApi")
shaded.extendsFrom(shadedApi)
getByName("api").extendsFrom(shadedApi)
val shadedImplementation = create("shadedImplementation")
shaded.extendsFrom(shadedImplementation)
getByName("implementation").extendsFrom(shadedImplementation)
}
repositories {
maven { url = uri("https://maven.enginehub.org/repo/") }
maven { url = uri("http://maven.enginehub.org/repo/") }
maven { url = uri("https://repo.codemc.org/repository/maven-public") }
maven { url = uri("https://papermc.io/repo/repository/maven-public/") }
maven { url = uri("https://maven.fabricmc.net/") }
@@ -33,6 +19,6 @@ fun Project.configureDependencies() {
dependencies {
"testImplementation"("org.junit.jupiter:junit-jupiter-api:5.7.0")
"testImplementation"("org.junit.jupiter:junit-jupiter-engine:5.7.0")
"api"("org.jetbrains:annotations:20.1.0")
"compileOnly"("org.jetbrains:annotations:20.1.0")
}
}
@@ -14,6 +14,17 @@ fun Project.configureDistribution() {
apply(plugin = "java-library")
apply(plugin = "com.github.johnrengelman.shadow")
configurations {
val shaded = create("shaded")
getByName("compile").extendsFrom(shaded)
val shadedApi = create("shadedApi")
shaded.extendsFrom(shadedApi)
getByName("api").extendsFrom(shadedApi)
val shadedImplementation = create("shadedImplementation")
shaded.extendsFrom(shadedImplementation)
getByName("implementation").extendsFrom(shadedImplementation)
}
val downloadDefaultPacks = tasks.create("downloadDefaultPacks") {
group = "terra"
doFirst {
@@ -27,6 +38,21 @@ fun Project.configureDistribution() {
}
tasks["processResources"].dependsOn(downloadDefaultPacks)
tasks.withType<Jar> {
archiveBaseName.set("Terra-${archiveBaseName.get()}")
from("../LICENSE", "../../LICENSE")
}
tasks.register<Jar>("sourcesJar") {
archiveClassifier.set("sources")
}
tasks.register<Jar>("javadocJar") {
dependsOn("javadoc")
archiveClassifier.set("javadoc")
from(tasks.getByName<Javadoc>("javadoc").destinationDir)
}
tasks.named<ShadowJar>("shadowJar") {
// Tell shadow to download the packs
dependsOn(downloadDefaultPacks)
+2 -5
View File
@@ -1,14 +1,11 @@
import com.dfsek.terra.configureCompilation
import com.dfsek.terra.configureDependencies
import com.dfsek.terra.configureCommon
plugins {
`java-library`
`maven-publish`
idea
}
configureCompilation()
configureDependencies()
configureCommon()
group = "com.dfsek.terra.common"
@@ -7,7 +7,6 @@ import com.dfsek.terra.api.platform.handle.WorldHandle;
import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.api.registry.CheckedRegistry;
import com.dfsek.terra.api.registry.LockedRegistry;
import com.dfsek.terra.api.util.JarUtil;
import com.dfsek.terra.api.util.logging.DebugLogger;
import com.dfsek.terra.api.util.logging.Logger;
import com.dfsek.terra.config.PluginConfig;
@@ -17,9 +16,6 @@ import com.dfsek.terra.profiler.Profiler;
import com.dfsek.terra.world.TerraWorld;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.jar.JarFile;
/**
* Represents a Terra mod/plugin instance.
@@ -71,8 +67,4 @@ public interface TerraPlugin extends LoaderRegistrar {
}
Profiler getProfiler();
default JarFile getModJar() throws URISyntaxException, IOException {
return JarUtil.getJarFile();
}
}
@@ -65,7 +65,7 @@ public class TerraCommandManager implements CommandManager {
return;
}
if(commandClass.isAnnotationPresent(WorldCommand.class) && (!(sender instanceof Player) || !(((Player) sender).getWorld()).isTerraWorld())) {
if(commandClass.isAnnotationPresent(WorldCommand.class) && (!(sender instanceof Player) || !TerraWorld.isTerraWorld(((Player) sender).getWorld()))) {
sender.sendMessage("Command must be executed in a Terra world.");
return;
}
@@ -1,7 +1,5 @@
package com.dfsek.terra.api.event.events.config;
import com.dfsek.tectonic.config.ConfigTemplate;
import com.dfsek.tectonic.exception.ConfigException;
import com.dfsek.terra.api.event.events.PackEvent;
import com.dfsek.terra.config.pack.ConfigPack;
@@ -10,28 +8,13 @@ import com.dfsek.terra.config.pack.ConfigPack;
*/
public abstract class ConfigPackLoadEvent implements PackEvent {
private final ConfigPack pack;
private final ExceptionalConsumer<ConfigTemplate> configLoader;
public ConfigPackLoadEvent(ConfigPack pack, ExceptionalConsumer<ConfigTemplate> configLoader) {
public ConfigPackLoadEvent(ConfigPack pack) {
this.pack = pack;
this.configLoader = configLoader;
}
@Override
public ConfigPack getPack() {
return pack;
}
/**
* Load a custom {@link ConfigTemplate} using the pack manifest.
*
* @param template Template to register.
*/
public void loadTemplate(ConfigTemplate template) throws ConfigException {
configLoader.accept(template);
}
public interface ExceptionalConsumer<T extends ConfigTemplate> {
void accept(T value) throws ConfigException;
}
}
@@ -1,13 +1,12 @@
package com.dfsek.terra.api.event.events.config;
import com.dfsek.tectonic.config.ConfigTemplate;
import com.dfsek.terra.config.pack.ConfigPack;
/**
* Called when a config pack has finished loading.
*/
public class ConfigPackPostLoadEvent extends ConfigPackLoadEvent {
public ConfigPackPostLoadEvent(ConfigPack pack, ExceptionalConsumer<ConfigTemplate> loader) {
super(pack, loader);
public ConfigPackPostLoadEvent(ConfigPack pack) {
super(pack);
}
}
@@ -1,14 +1,12 @@
package com.dfsek.terra.api.event.events.config;
import com.dfsek.tectonic.config.ConfigTemplate;
import com.dfsek.tectonic.exception.ConfigException;
import com.dfsek.terra.config.pack.ConfigPack;
/**
* Called before a config pack's registries are filled. At this point, the pack manifest has been loaded, and all registries are empty.
*/
public class ConfigPackPreLoadEvent extends ConfigPackLoadEvent {
public ConfigPackPreLoadEvent(ConfigPack pack, ExceptionalConsumer<ConfigTemplate> configLoader) {
super(pack, configLoader);
public ConfigPackPreLoadEvent(ConfigPack pack) {
super(pack);
}
}
@@ -1,7 +1,6 @@
package com.dfsek.terra.api.platform.inventory;
import com.dfsek.terra.api.platform.Handle;
import com.dfsek.terra.api.platform.inventory.item.Damageable;
import com.dfsek.terra.api.platform.inventory.item.ItemMeta;
public interface ItemStack extends Handle {
@@ -14,8 +13,4 @@ public interface ItemStack extends Handle {
ItemMeta getItemMeta();
void setItemMeta(ItemMeta meta);
default boolean isDamageable() {
return getItemMeta() instanceof Damageable;
}
}
@@ -6,8 +6,6 @@ import com.dfsek.terra.api.platform.block.Block;
import com.dfsek.terra.api.platform.entity.Entity;
import com.dfsek.terra.api.platform.entity.EntityType;
import com.dfsek.terra.api.platform.world.generator.ChunkGenerator;
import com.dfsek.terra.api.platform.world.generator.GeneratorWrapper;
import com.dfsek.terra.api.world.generation.TerraChunkGenerator;
import java.io.File;
import java.util.UUID;
@@ -19,12 +17,20 @@ public interface World extends Handle {
ChunkGenerator getGenerator();
String getName();
UUID getUID();
boolean isChunkGenerated(int x, int z);
Chunk getChunkAt(int x, int z);
default Chunk getChunkAt(Location location) {
return getChunkAt(location.getBlockX() >> 4, location.getBlockZ() >> 4);
}
File getWorldFolder();
Block getBlockAt(int x, int y, int z);
default Block getBlockAt(Location l) {
@@ -34,12 +40,4 @@ public interface World extends Handle {
Entity spawnEntity(Location location, EntityType entityType);
int getMinHeight();
default boolean isTerraWorld() {
return getGenerator().getHandle() instanceof GeneratorWrapper;
}
default TerraChunkGenerator getTerraGenerator() {
return ((GeneratorWrapper) getGenerator().getHandle()).getHandle();
}
}
@@ -6,6 +6,7 @@ import com.dfsek.terra.registry.OpenRegistry;
import com.dfsek.terra.registry.exception.DuplicateEntryException;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
@@ -68,7 +69,7 @@ public class CheckedRegistry<T> implements Registry<T> {
}
@Override
public Set<T> entries() {
public Collection<T> entries() {
return registry.entries();
}
@@ -4,6 +4,7 @@ import com.dfsek.tectonic.exception.LoadException;
import com.dfsek.tectonic.loading.ConfigLoader;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
@@ -41,7 +42,7 @@ public class LockedRegistry<T> implements Registry<T> {
}
@Override
public Set<T> entries() {
public Collection<T> entries() {
return registry.entries();
}
@@ -2,6 +2,7 @@ package com.dfsek.terra.api.registry;
import com.dfsek.tectonic.loading.TypeLoader;
import java.util.Collection;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
@@ -42,7 +43,7 @@ public interface Registry<T> extends TypeLoader<T> {
*
* @return Set containing all entries.
*/
Set<T> entries();
Collection<T> entries();
/**
* Get all the keys in this registry.
@@ -34,8 +34,8 @@ public class DamageFunction implements LootFunction {
@Override
public ItemStack apply(ItemStack original, Random r) {
if(original == null) return null;
if(!original.isDamageable()) return original;
ItemMeta meta = original.getItemMeta();
if(!(meta instanceof Damageable)) return original;
double itemDurability = (r.nextDouble() * (max - min)) + min;
Damageable damage = (Damageable) meta;
damage.setDamage((int) (original.getType().getMaxDurability() - (itemDurability / 100) * original.getType().getMaxDurability()));
@@ -3,10 +3,13 @@ package com.dfsek.terra.api.structures.script;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.math.vector.Location;
import com.dfsek.terra.api.platform.world.Chunk;
import com.dfsek.terra.api.registry.Registry;
import com.dfsek.terra.api.structures.loot.LootTable;
import com.dfsek.terra.api.structures.parser.Parser;
import com.dfsek.terra.api.structures.parser.exceptions.ParseException;
import com.dfsek.terra.api.structures.parser.lang.Block;
import com.dfsek.terra.api.structures.parser.lang.Returnable;
import com.dfsek.terra.api.structures.parser.lang.functions.FunctionBuilder;
import com.dfsek.terra.api.structures.script.builders.BinaryNumberFunctionBuilder;
import com.dfsek.terra.api.structures.script.builders.BiomeFunctionBuilder;
import com.dfsek.terra.api.structures.script.builders.BlockFunctionBuilder;
@@ -30,9 +33,6 @@ import com.dfsek.terra.api.structures.structure.buffer.Buffer;
import com.dfsek.terra.api.structures.structure.buffer.DirectBuffer;
import com.dfsek.terra.api.structures.structure.buffer.StructureBuffer;
import com.dfsek.terra.profiler.ProfileFrame;
import com.dfsek.terra.registry.config.FunctionRegistry;
import com.dfsek.terra.registry.config.LootRegistry;
import com.dfsek.terra.registry.config.ScriptRegistry;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import net.jafama.FastMath;
@@ -51,7 +51,7 @@ public class StructureScript {
private final TerraPlugin main;
private String tempID;
public StructureScript(InputStream inputStream, TerraPlugin main, ScriptRegistry registry, LootRegistry lootRegistry, FunctionRegistry functionRegistry) throws ParseException {
public StructureScript(InputStream inputStream, TerraPlugin main, Registry<StructureScript> registry, Registry<LootTable> lootRegistry, Registry<FunctionBuilder<?>> functionRegistry) throws ParseException {
Parser parser;
try {
parser = new Parser(IOUtils.toString(inputStream, Charset.defaultCharset()));
@@ -89,12 +89,6 @@ public class StructureScript {
.registerFunction("ceil", new UnaryNumberFunctionBuilder(number -> FastMath.ceil(number.doubleValue())))
.registerFunction("log", new UnaryNumberFunctionBuilder(number -> FastMath.log(number.doubleValue())))
.registerFunction("round", new UnaryNumberFunctionBuilder(number -> FastMath.round(number.doubleValue())))
.registerFunction("sin", new UnaryNumberFunctionBuilder(number -> FastMath.sin(number.doubleValue())))
.registerFunction("cos", new UnaryNumberFunctionBuilder(number -> FastMath.cos(number.doubleValue())))
.registerFunction("tan", new UnaryNumberFunctionBuilder(number -> FastMath.tan(number.doubleValue())))
.registerFunction("asin", new UnaryNumberFunctionBuilder(number -> FastMath.asin(number.doubleValue())))
.registerFunction("acos", new UnaryNumberFunctionBuilder(number -> FastMath.acos(number.doubleValue())))
.registerFunction("atan", new UnaryNumberFunctionBuilder(number -> FastMath.atan(number.doubleValue())))
.registerFunction("max", new BinaryNumberFunctionBuilder((number, number2) -> FastMath.max(number.doubleValue(), number2.doubleValue())))
.registerFunction("min", new BinaryNumberFunctionBuilder((number, number2) -> FastMath.min(number.doubleValue(), number2.doubleValue())));
@@ -1,21 +1,22 @@
package com.dfsek.terra.api.structures.script.builders;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.registry.Registry;
import com.dfsek.terra.api.structures.loot.LootTable;
import com.dfsek.terra.api.structures.parser.lang.Returnable;
import com.dfsek.terra.api.structures.parser.lang.functions.FunctionBuilder;
import com.dfsek.terra.api.structures.script.StructureScript;
import com.dfsek.terra.api.structures.script.functions.LootFunction;
import com.dfsek.terra.api.structures.tokenizer.Position;
import com.dfsek.terra.registry.config.LootRegistry;
import java.util.List;
public class LootFunctionBuilder implements FunctionBuilder<LootFunction> {
private final TerraPlugin main;
private final LootRegistry registry;
private final Registry<LootTable> registry;
private final StructureScript script;
public LootFunctionBuilder(TerraPlugin main, LootRegistry registry, StructureScript script) {
public LootFunctionBuilder(TerraPlugin main, Registry<LootTable> registry, StructureScript script) {
this.main = main;
this.registry = registry;
this.script = script;
@@ -1,21 +1,22 @@
package com.dfsek.terra.api.structures.script.builders;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.registry.Registry;
import com.dfsek.terra.api.structures.parser.exceptions.ParseException;
import com.dfsek.terra.api.structures.parser.lang.Returnable;
import com.dfsek.terra.api.structures.parser.lang.functions.FunctionBuilder;
import com.dfsek.terra.api.structures.script.StructureScript;
import com.dfsek.terra.api.structures.script.functions.StructureFunction;
import com.dfsek.terra.api.structures.tokenizer.Position;
import com.dfsek.terra.registry.config.ScriptRegistry;
import java.util.List;
import java.util.stream.Collectors;
public class StructureFunctionBuilder implements FunctionBuilder<StructureFunction> {
private final ScriptRegistry registry;
private final Registry<StructureScript> registry;
private final TerraPlugin main;
public StructureFunctionBuilder(ScriptRegistry registry, TerraPlugin main) {
public StructureFunctionBuilder(Registry<StructureScript> registry, TerraPlugin main) {
this.registry = registry;
this.main = main;
}
@@ -3,6 +3,7 @@ package com.dfsek.terra.api.structures.script.functions;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.math.vector.Vector2;
import com.dfsek.terra.api.math.vector.Vector3;
import com.dfsek.terra.api.registry.Registry;
import com.dfsek.terra.api.structures.loot.LootTable;
import com.dfsek.terra.api.structures.parser.lang.ImplementationArguments;
import com.dfsek.terra.api.structures.parser.lang.Returnable;
@@ -13,20 +14,19 @@ import com.dfsek.terra.api.structures.script.TerraImplementationArguments;
import com.dfsek.terra.api.structures.structure.RotationUtil;
import com.dfsek.terra.api.structures.structure.buffer.items.BufferedLootApplication;
import com.dfsek.terra.api.structures.tokenizer.Position;
import com.dfsek.terra.registry.config.LootRegistry;
import net.jafama.FastMath;
import java.util.Map;
public class LootFunction implements Function<Void> {
private final LootRegistry registry;
private final Registry<LootTable> registry;
private final Returnable<String> data;
private final Returnable<Number> x, y, z;
private final Position position;
private final TerraPlugin main;
private final StructureScript script;
public LootFunction(LootRegistry registry, Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Returnable<String> data, TerraPlugin main, Position position, StructureScript script) {
public LootFunction(Registry<LootTable> registry, Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Returnable<String> data, TerraPlugin main, Position position, StructureScript script) {
this.registry = registry;
this.position = position;
this.data = data;
@@ -3,6 +3,7 @@ package com.dfsek.terra.api.structures.script.functions;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.math.vector.Vector2;
import com.dfsek.terra.api.math.vector.Vector3;
import com.dfsek.terra.api.registry.Registry;
import com.dfsek.terra.api.structures.parser.lang.ImplementationArguments;
import com.dfsek.terra.api.structures.parser.lang.Returnable;
import com.dfsek.terra.api.structures.parser.lang.functions.Function;
@@ -13,21 +14,20 @@ import com.dfsek.terra.api.structures.structure.Rotation;
import com.dfsek.terra.api.structures.structure.RotationUtil;
import com.dfsek.terra.api.structures.structure.buffer.IntermediateBuffer;
import com.dfsek.terra.api.structures.tokenizer.Position;
import com.dfsek.terra.registry.config.ScriptRegistry;
import net.jafama.FastMath;
import java.util.List;
import java.util.Map;
public class StructureFunction implements Function<Boolean> {
private final ScriptRegistry registry;
private final Registry<StructureScript> registry;
private final Returnable<String> id;
private final Returnable<Number> x, y, z;
private final Position position;
private final TerraPlugin main;
private final List<Returnable<String>> rotations;
public StructureFunction(Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Returnable<String> id, List<Returnable<String>> rotations, ScriptRegistry registry, Position position, TerraPlugin main) {
public StructureFunction(Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Returnable<String> id, List<Returnable<String>> rotations, Registry<StructureScript> registry, Position position, TerraPlugin main) {
this.registry = registry;
this.id = id;
this.position = position;
@@ -19,6 +19,6 @@ public class BufferedEntity implements BufferedItem {
@Override
public void paste(Location origin) {
Entity entity = origin.clone().add(0.5, 0, 0.5).getWorld().spawnEntity(origin, type);
main.getEventManager().callEvent(new EntitySpawnEvent(entity.getWorld().getTerraGenerator().getConfigPack(), entity, entity.getLocation()));
main.getEventManager().callEvent(new EntitySpawnEvent(main.getWorld(entity.getWorld()).getGenerator().getConfigPack(), entity, entity.getLocation()));
}
}
@@ -32,7 +32,7 @@ public class BufferedLootApplication implements BufferedItem {
}
Container container = (Container) data;
LootPopulateEvent event = new LootPopulateEvent(block, container, table, block.getLocation().getWorld().getTerraGenerator().getConfigPack(), structure);
LootPopulateEvent event = new LootPopulateEvent(block, container, table, main.getWorld(block.getLocation().getWorld()).getGenerator().getConfigPack(), structure);
main.getEventManager().callEvent(event);
if(event.isCancelled()) return;
@@ -40,7 +40,7 @@ public class BufferedLootApplication implements BufferedItem {
data.update(false);
} catch(Exception e) {
main.logger().warning("Could not apply loot at " + origin + ": " + e.getMessage());
e.printStackTrace();
main.getDebugLogger().stack(e);
}
}
}
@@ -21,7 +21,7 @@ public class BufferedStateManipulator implements BufferedItem {
state.update(false);
} catch(Exception e) {
main.logger().warning("Could not apply BlockState at " + origin + ": " + e.getMessage());
e.printStackTrace();
main.getDebugLogger().stack(e);
}
}
}
@@ -15,6 +15,7 @@ public class Tokenizer {
private final Lookahead reader;
private final Stack<Token> brackets = new Stack<>();
private Token current;
private Token last;
public Tokenizer(String data) throws ParseException {
reader = new Lookahead(new StringReader(data + '\0'));
@@ -28,7 +29,7 @@ public class Tokenizer {
* @throws ParseException If token does not exist
*/
public Token get() throws ParseException {
if(!hasNext()) throw new ParseException("Unexpected end of input", current.getPosition());
if(!hasNext()) throw new ParseException("Unexpected end of input", last.getPosition());
return current;
}
@@ -39,7 +40,7 @@ public class Tokenizer {
* @throws ParseException If token does not exist
*/
public Token consume() throws ParseException {
if(!hasNext()) throw new ParseException("Unexpected end of input", current.getPosition());
if(!hasNext()) throw new ParseException("Unexpected end of input", last.getPosition());
Token temp = current;
current = fetchCheck();
return temp;
@@ -57,8 +58,9 @@ public class Tokenizer {
private Token fetchCheck() throws ParseException {
Token fetch = fetch();
if(fetch != null) {
if(fetch.getType().equals(Token.Type.BLOCK_BEGIN)) brackets.push(fetch); // Opening bracket
else if(fetch.getType().equals(Token.Type.BLOCK_END)) {
last = fetch;
if(fetch.getType() == Token.Type.BLOCK_BEGIN) brackets.push(fetch); // Opening bracket
else if(fetch.getType() == Token.Type.BLOCK_END) {
if(!brackets.isEmpty()) brackets.pop();
else throw new ParseException("Dangling opening brace", new Position(0, 0));
}
@@ -0,0 +1,8 @@
package com.dfsek.terra.api.transform;
public class NotNullValidator<T> implements Validator<T> {
@Override
public boolean validate(T value) {
return !(value == null);
}
}
@@ -1,12 +1,6 @@
package com.dfsek.terra.api.transform;
import java.util.Objects;
public interface Validator<T> {
boolean validate(T value) throws TransformException;
static <T> Validator<T> notNull() {
return Objects::nonNull;
}
}
@@ -1,13 +1,9 @@
package com.dfsek.terra.api.util;
import com.dfsek.terra.api.TerraPlugin;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
@@ -36,12 +32,4 @@ public class JarUtil {
}
}
}
public static JarFile getJarFile() throws URISyntaxException, IOException {
return new JarFile(new File(getJarURL().toURI()));
}
public static URL getJarURL() {
return TerraPlugin.class.getProtectionDomain().getCodeSource().getLocation();
}
}
@@ -1,10 +1,12 @@
package com.dfsek.terra.api.util.generic.pair;
public class ImmutablePair<L, R> {
public final class ImmutablePair<L, R> {
private final L left;
private final R right;
public ImmutablePair(L left, R right) {
private static final ImmutablePair<?, ?> NULL = new ImmutablePair<>(null, null);
private ImmutablePair(L left, R right) {
this.left = left;
this.right = right;
}
@@ -21,7 +23,12 @@ public class ImmutablePair<L, R> {
return left;
}
@SuppressWarnings("unchecked")
public static <L1, R1> ImmutablePair<L1, R1> ofNull() {
return (ImmutablePair<L1, R1>) NULL;
}
public Pair<L, R> mutable() {
return new Pair<>(left, right);
return Pair.of(left, right);
}
}
@@ -4,7 +4,7 @@ public class Pair<L, R> {
private L left;
private R right;
public Pair(L left, R right) {
private Pair(L left, R right) {
this.left = left;
this.right = right;
}
@@ -30,6 +30,6 @@ public class Pair<L, R> {
}
public ImmutablePair<L, R> immutable() {
return new ImmutablePair<>(left, right);
return ImmutablePair.of(left, right);
}
}
@@ -0,0 +1,9 @@
package com.dfsek.terra.api.util.seeded;
import com.dfsek.tectonic.loading.object.ObjectTemplate;
import java.util.function.Supplier;
@FunctionalInterface
public interface NoiseProvider extends Supplier<ObjectTemplate<NoiseSeeded>> {
}
@@ -1,14 +1,13 @@
package com.dfsek.terra.api.util.world;
import com.dfsek.terra.api.math.MathUtil;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.world.palette.Palette;
import com.dfsek.terra.api.world.palette.holder.PaletteHolder;
import com.dfsek.terra.config.templates.BiomeTemplate;
import com.dfsek.terra.world.generation.math.samplers.Sampler;
public final class PaletteUtil {
public static Palette<BlockData> getPalette(int x, int y, int z, BiomeTemplate c, Sampler sampler) {
public static Palette getPalette(int x, int y, int z, BiomeTemplate c, Sampler sampler) {
PaletteHolder slant = c.getSlantPalette();
if(slant != null && MathUtil.derivative(sampler, x, y, z) > c.getSlantThreshold()) {
return slant.getPalette(y);
@@ -1,8 +1,10 @@
package com.dfsek.terra.api.world.biome;
import com.dfsek.terra.api.math.noise.NoiseSampler;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.world.palette.Palette;
import com.dfsek.terra.world.generation.math.samplers.terrain.TerrainSampler;
import java.util.List;
public interface Generator {
/**
@@ -35,11 +37,13 @@ public interface Generator {
*
* @return BlocPalette - The biome's palette.
*/
Palette<BlockData> getPalette(int y);
Palette getPalette(int y);
NoiseSampler getBiomeNoise();
double getElevationWeight();
int getBlendStep();
List<TerrainSampler> getTerrainSamplers();
}
@@ -1,10 +1,11 @@
package com.dfsek.terra.api.world.palette;
import com.dfsek.terra.api.math.noise.NoiseSampler;
import com.dfsek.terra.api.platform.block.BlockData;
import java.util.List;
public class NoisePalette<E> extends Palette<E> {
public class NoisePalette extends Palette {
private final NoiseSampler sampler;
private final boolean is2D;
@@ -14,11 +15,11 @@ public class NoisePalette<E> extends Palette<E> {
}
@Override
public E get(int layer, double x, double y, double z) {
PaletteLayer<E> paletteLayer;
public BlockData get(int layer, double x, double y, double z) {
PaletteLayer paletteLayer;
if(layer > this.getSize()) paletteLayer = this.getLayers().get(this.getLayers().size() - 1);
else {
List<PaletteLayer<E>> pl = getLayers();
List<PaletteLayer> pl = getLayers();
if(layer >= pl.size()) paletteLayer = pl.get(pl.size() - 1);
else paletteLayer = pl.get(layer);
}
@@ -1,6 +1,7 @@
package com.dfsek.terra.api.world.palette;
import com.dfsek.terra.api.math.noise.NoiseSampler;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.util.GlueList;
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
@@ -11,8 +12,8 @@ import java.util.Random;
* A class representation of a "slice" of the world.
* Used to get a section of blocks, based on the depth at which they are found.
*/
public abstract class Palette<E> {
private final List<PaletteLayer<E>> pallet = new GlueList<>();
public abstract class Palette {
private final List<PaletteLayer> pallet = new GlueList<>();
/**
* Constructs a blank palette.
@@ -21,16 +22,16 @@ public abstract class Palette<E> {
}
public com.dfsek.terra.api.world.palette.Palette<E> add(E m, int layers, NoiseSampler sampler) {
public com.dfsek.terra.api.world.palette.Palette add(BlockData m, int layers, NoiseSampler sampler) {
for(int i = 0; i < layers; i++) {
pallet.add(new PaletteLayer<>(m, sampler));
pallet.add(new PaletteLayer(m, sampler));
}
return this;
}
public com.dfsek.terra.api.world.palette.Palette<E> add(ProbabilityCollection<E> m, int layers, NoiseSampler sampler) {
public com.dfsek.terra.api.world.palette.Palette add(ProbabilityCollection<BlockData> m, int layers, NoiseSampler sampler) {
for(int i = 0; i < layers; i++) {
pallet.add(new PaletteLayer<>(m, sampler));
pallet.add(new PaletteLayer(m, sampler));
}
return this;
}
@@ -41,25 +42,25 @@ public abstract class Palette<E> {
* @param layer - The layer at which to fetch the material.
* @return BlockData - The material fetched.
*/
public abstract E get(int layer, double x, double y, double z);
public abstract BlockData get(int layer, double x, double y, double z);
public int getSize() {
return pallet.size();
}
public List<PaletteLayer<E>> getLayers() {
public List<PaletteLayer> getLayers() {
return pallet;
}
/**
* Class representation of a layer of a BlockPalette.
*/
public static class PaletteLayer<E> {
public static class PaletteLayer {
private final boolean col; // Is layer using a collection?
private ProbabilityCollection<E> collection;
private ProbabilityCollection<BlockData> collection;
private final NoiseSampler sampler;
private E m;
private BlockData m;
/**
* Constructs a PaletteLayerHolder with a ProbabilityCollection of materials and a number of layers.
@@ -67,7 +68,7 @@ public abstract class Palette<E> {
* @param type The collection of materials to choose from.
* @param sampler Noise sampler to use
*/
public PaletteLayer(ProbabilityCollection<E> type, NoiseSampler sampler) {
public PaletteLayer(ProbabilityCollection<BlockData> type, NoiseSampler sampler) {
this.sampler = sampler;
this.col = true;
this.collection = type;
@@ -79,7 +80,7 @@ public abstract class Palette<E> {
* @param type The material to use.
* @param sampler Noise sampler to use
*/
public PaletteLayer(E type, NoiseSampler sampler) {
public PaletteLayer(BlockData type, NoiseSampler sampler) {
this.sampler = sampler;
this.col = false;
this.m = type;
@@ -94,18 +95,18 @@ public abstract class Palette<E> {
*
* @return Material - the material..
*/
public E get(Random random) {
public BlockData get(Random random) {
if(col) return this.collection.get(random);
return m;
}
public E get(NoiseSampler random, double x, double y, double z, boolean is2D) {
public BlockData get(NoiseSampler random, double x, double y, double z, boolean is2D) {
if(col && is2D) return this.collection.get(random, x, z);
else if(col) return this.collection.get(random, x, y, z);
return m;
}
public ProbabilityCollection<E> getCollection() {
public ProbabilityCollection<BlockData> getCollection() {
return collection;
}
}
@@ -1,14 +1,16 @@
package com.dfsek.terra.api.world.palette;
public class SinglePalette<E> extends Palette<E> {
private final E item;
import com.dfsek.terra.api.platform.block.BlockData;
public SinglePalette(E item) {
public class SinglePalette extends Palette {
private final BlockData item;
public SinglePalette(BlockData item) {
this.item = item;
}
@Override
public E get(int layer, double x, double y, double z) {
public BlockData get(int layer, double x, double y, double z) {
return item;
}
}
@@ -1,16 +1,15 @@
package com.dfsek.terra.api.world.palette.holder;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.world.palette.Palette;
public class PaletteHolder {
private final Palette<BlockData>[] palettes;
private final Palette[] palettes;
protected PaletteHolder(Palette<BlockData>[] palettes) {
protected PaletteHolder(Palette[] palettes) {
this.palettes = palettes;
}
public Palette<BlockData> getPalette(int y) {
public Palette getPalette(int y) {
return palettes[y];
}
}
@@ -1,6 +1,5 @@
package com.dfsek.terra.api.world.palette.holder;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.world.palette.Palette;
import net.jafama.FastMath;
@@ -8,19 +7,19 @@ import java.util.Map;
import java.util.TreeMap;
public class PaletteHolderBuilder {
private final TreeMap<Integer, Palette<BlockData>> paletteMap = new TreeMap<>();
private final TreeMap<Integer, Palette> paletteMap = new TreeMap<>();
public PaletteHolderBuilder add(int y, Palette<BlockData> palette) {
public PaletteHolderBuilder add(int y, Palette palette) {
paletteMap.put(y, palette);
return this;
}
@SuppressWarnings({"unchecked", "rawtypes", "RedundantSuppression"})
public PaletteHolder build() {
Palette<BlockData>[] palettes = new Palette[paletteMap.lastKey() + 1];
Palette[] palettes = new Palette[paletteMap.lastKey() + 1];
for(int y = 0; y <= FastMath.max(paletteMap.lastKey(), 255); y++) {
Palette<BlockData> d = null;
for(Map.Entry<Integer, Palette<BlockData>> e : paletteMap.entrySet()) {
Palette d = null;
for(Map.Entry<Integer, Palette> e : paletteMap.entrySet()) {
if(e.getKey() >= y) {
d = e.getValue();
break;
@@ -14,6 +14,6 @@ public class BiomeArgumentParser implements ArgumentParser<TerraBiome> {
@Override
public TerraBiome parse(CommandSender sender, String arg) {
Player player = (Player) sender;
return main.getWorld(player.getWorld()).getConfig().getBiomeRegistry().get(arg);
return main.getWorld(player.getWorld()).getConfig().getRegistry(TerraBiome.class).get(arg);
}
}
@@ -17,6 +17,6 @@ public class BiomeTabCompleter implements TabCompleter {
@Override
public List<String> complete(CommandSender sender) {
Player player = (Player) sender;
return main.getWorld(player.getWorld()).getConfig().getBiomeRegistry().entries().stream().map(TerraBiome::getID).collect(Collectors.toList());
return main.getWorld(player.getWorld()).getConfig().getRegistry(TerraBiome.class).entries().stream().map(TerraBiome::getID).collect(Collectors.toList());
}
}
@@ -13,6 +13,6 @@ public class ScriptArgumentParser implements ArgumentParser<StructureScript> {
@Override
public StructureScript parse(CommandSender sender, String arg) {
return main.getWorld(((Player) sender).getWorld()).getConfig().getScriptRegistry().get(arg);
return main.getWorld(((Player) sender).getWorld()).getConfig().getRegistry(StructureScript.class).get(arg);
}
}
@@ -13,6 +13,6 @@ public class StructureArgumentParser implements ArgumentParser<TerraStructure> {
@Override
public TerraStructure parse(CommandSender sender, String arg) {
return main.getWorld(((Player) sender).getWorld()).getConfig().getStructureRegistry().get(arg);
return main.getWorld(((Player) sender).getWorld()).getConfig().getRegistry(TerraStructure.class).get(arg);
}
}
@@ -16,6 +16,6 @@ public class ScriptCompleter implements TabCompleter {
@Override
public List<String> complete(CommandSender sender) {
return main.getWorld(((Player) sender).getWorld()).getConfig().getScriptRegistry().entries().stream().map(StructureScript::getId).collect(Collectors.toList());
return main.getWorld(((Player) sender).getWorld()).getConfig().getRegistry(StructureScript.class).entries().stream().map(StructureScript::getId).collect(Collectors.toList());
}
}
@@ -5,6 +5,7 @@ import com.dfsek.terra.api.command.tab.TabCompleter;
import com.dfsek.terra.api.injection.annotations.Inject;
import com.dfsek.terra.api.platform.CommandSender;
import com.dfsek.terra.api.platform.entity.Player;
import com.dfsek.terra.world.population.items.TerraStructure;
import java.util.ArrayList;
import java.util.List;
@@ -16,6 +17,6 @@ public class StructureCompleter implements TabCompleter {
@Override
public List<String> complete(CommandSender sender) {
Player player = (Player) sender;
return new ArrayList<>(main.getWorld(player.getWorld()).getConfig().getStructureRegistry().keys());
return new ArrayList<>(main.getWorld(player.getWorld()).getConfig().getRegistry(TerraStructure.class).keys());
}
}
@@ -69,12 +69,12 @@ public class PluginConfig implements ConfigTemplate {
ConfigLoader loader = new ConfigLoader();
loader.load(this, file);
if(dumpDefaultConfig) { // Don't dump default config if already loaded.
try(JarFile jar = main.getModJar()) {
try(JarFile jar = new JarFile(new File(TerraPlugin.class.getProtectionDomain().getCodeSource().getLocation().toURI()))) {
JarUtil.copyResourcesToDirectory(jar, "packs", new File(main.getDataFolder(), "packs").toString());
} catch(IOException | URISyntaxException e) {
main.getDebugLogger().error("Failed to dump default config files!");
e.printStackTrace();
main.getDebugLogger().error("Either you're on Forge, or this is a bug. If it's the latter, report this to Terra!");
main.getDebugLogger().error("Report this to Terra!");
}
}
} catch(ConfigException | IOException e) {
@@ -0,0 +1,147 @@
package com.dfsek.terra.config.builder;
import com.dfsek.paralithic.eval.parser.Scope;
import com.dfsek.paralithic.eval.tokenizer.ParseException;
import com.dfsek.terra.api.math.noise.NoiseSampler;
import com.dfsek.terra.api.math.noise.samplers.ExpressionSampler;
import com.dfsek.terra.api.math.noise.samplers.noise.ConstantSampler;
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
import com.dfsek.terra.api.world.palette.holder.PaletteHolder;
import com.dfsek.terra.config.loaders.config.function.FunctionTemplate;
import com.dfsek.terra.world.generation.WorldGenerator;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class GeneratorBuilder {
private final Map<Long, WorldGenerator> gens = Collections.synchronizedMap(new HashMap<>());
private String noiseEquation;
private String elevationEquation;
private String carvingEquation;
private Scope varScope;
private Map<String, NoiseSeeded> noiseBuilderMap;
private Map<String, FunctionTemplate> functionTemplateMap;
private PaletteHolder palettes;
private PaletteHolder slantPalettes;
private boolean preventInterpolation;
private boolean interpolateElevation;
private NoiseSeeded biomeNoise;
private double elevationWeight;
private int blendDistance;
private int blendStep;
private double blendWeight;
public WorldGenerator build(long seed) {
synchronized(gens) {
return gens.computeIfAbsent(seed, k -> {
NoiseSampler noise;
NoiseSampler elevation;
NoiseSampler carving;
try {
noise = new ExpressionSampler(noiseEquation, varScope, seed, noiseBuilderMap, functionTemplateMap);
elevation = elevationEquation == null ? new ConstantSampler(0) : new ExpressionSampler(elevationEquation, varScope, seed, noiseBuilderMap, functionTemplateMap);
carving = new ExpressionSampler(carvingEquation, varScope, seed, noiseBuilderMap, functionTemplateMap);
} catch(ParseException e) {
throw new RuntimeException(e);
}
return new WorldGenerator(palettes, slantPalettes, noise, elevation, carving, biomeNoise.apply(seed), elevationWeight, blendDistance, blendStep, blendWeight);
});
}
}
public void setBlendWeight(double blendWeight) {
this.blendWeight = blendWeight;
}
public void setFunctionTemplateMap(Map<String, FunctionTemplate> functionTemplateMap) {
this.functionTemplateMap = functionTemplateMap;
}
public void setBlendStep(int blendStep) {
this.blendStep = blendStep;
}
public void setBlendDistance(int blendDistance) {
this.blendDistance = blendDistance;
}
public void setBiomeNoise(NoiseSeeded biomeNoise) {
this.biomeNoise = biomeNoise;
}
public void setElevationWeight(double elevationWeight) {
this.elevationWeight = elevationWeight;
}
public void setNoiseEquation(String noiseEquation) {
this.noiseEquation = noiseEquation;
}
public void setElevationEquation(String elevationEquation) {
this.elevationEquation = elevationEquation;
}
public void setCarvingEquation(String carvingEquation) {
this.carvingEquation = carvingEquation;
}
public Scope getVarScope() {
return varScope;
}
public void setVarScope(Scope varScope) {
this.varScope = varScope;
}
public void setNoiseBuilderMap(Map<String, NoiseSeeded> noiseBuilderMap) {
this.noiseBuilderMap = noiseBuilderMap;
}
public PaletteHolder getPalettes() {
return palettes;
}
public void setPalettes(PaletteHolder palettes) {
this.palettes = palettes;
}
public PaletteHolder getSlantPalettes() {
return slantPalettes;
}
public void setSlantPalettes(PaletteHolder slantPalettes) {
this.slantPalettes = slantPalettes;
}
public boolean isPreventInterpolation() {
return preventInterpolation;
}
public void setPreventInterpolation(boolean preventInterpolation) {
this.preventInterpolation = preventInterpolation;
}
public void setInterpolateElevation(boolean interpolateElevation) {
this.interpolateElevation = interpolateElevation;
}
public boolean interpolateElevation() {
return interpolateElevation;
}
}
@@ -9,6 +9,9 @@ import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.api.platform.world.generator.ChunkGenerator;
import com.dfsek.terra.api.platform.world.generator.GeneratorWrapper;
import java.io.File;
import java.util.UUID;
public class DummyWorld implements World {
@Override
public Object getHandle() {
@@ -30,11 +33,31 @@ public class DummyWorld implements World {
return () -> (GeneratorWrapper) () -> null;
}
@Override
public String getName() {
return "DUMMY";
}
@Override
public UUID getUID() {
return UUID.randomUUID();
}
@Override
public boolean isChunkGenerated(int x, int z) {
return false;
}
@Override
public Chunk getChunkAt(int x, int z) {
throw new UnsupportedOperationException("Cannot get chunk in DummyWorld");
}
@Override
public File getWorldFolder() {
throw new UnsupportedOperationException("Cannot get folder of DummyWorld");
}
@Override
public Block getBlockAt(int x, int y, int z) {
throw new UnsupportedOperationException("Cannot get block in DummyWorld");
@@ -2,7 +2,6 @@ package com.dfsek.terra.config.factories;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.math.noise.samplers.noise.random.WhiteNoiseSampler;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.world.flora.Flora;
import com.dfsek.terra.api.world.palette.NoisePalette;
import com.dfsek.terra.api.world.palette.Palette;
@@ -13,7 +12,7 @@ import com.dfsek.terra.world.population.items.flora.TerraFlora;
public class FloraFactory implements ConfigFactory<FloraTemplate, Flora> {
@Override
public TerraFlora build(FloraTemplate config, TerraPlugin main) {
Palette<BlockData> palette = new NoisePalette<>(new WhiteNoiseSampler(2403), false);
Palette palette = new NoisePalette(new WhiteNoiseSampler(2403), false);
for(PaletteLayerHolder layer : config.getFloraPalette()) {
palette.add(layer.getLayer(), layer.getSize(), layer.getSampler());
}
@@ -1,16 +1,15 @@
package com.dfsek.terra.config.factories;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.world.palette.NoisePalette;
import com.dfsek.terra.api.world.palette.Palette;
import com.dfsek.terra.api.world.palette.holder.PaletteLayerHolder;
import com.dfsek.terra.config.templates.PaletteTemplate;
public class PaletteFactory implements ConfigFactory<PaletteTemplate, Palette<BlockData>> {
public class PaletteFactory implements ConfigFactory<PaletteTemplate, Palette> {
@Override
public Palette<BlockData> build(PaletteTemplate config, TerraPlugin main) {
NoisePalette<BlockData> palette = new NoisePalette<>(config.getNoise().apply(2403L), config.getNoise().getDimensions() == 2);
public Palette build(PaletteTemplate config, TerraPlugin main) {
NoisePalette palette = new NoisePalette(config.getNoise().apply(2403L), config.getNoise().getDimensions() == 2);
for(PaletteLayerHolder layer : config.getPalette()) {
palette.add(layer.getLayer(), layer.getSize(), layer.getSampler());
}
@@ -1,6 +1,5 @@
package com.dfsek.terra.config.fileloaders;
import com.dfsek.tectonic.config.Configuration;
import com.dfsek.tectonic.exception.ConfigException;
import com.dfsek.terra.api.util.GlueList;
@@ -19,12 +18,8 @@ public abstract class Loader {
*
* @param consumer Something to do with the streams.
*/
public Loader then(ExceptionalConsumer<List<Configuration>> consumer) throws ConfigException {
List<Configuration> list = new GlueList<>();
streams.forEach((id, stream) -> {
list.add(new Configuration(stream, id));
});
consumer.accept(list);
public Loader then(ExceptionalConsumer<List<InputStream>> consumer) throws ConfigException {
consumer.accept(new GlueList<>(streams.values()));
return this;
}
@@ -30,7 +30,7 @@ public class ZIPLoader extends Loader {
ZipEntry entry = entries.nextElement();
if(!entry.isDirectory() && entry.getName().startsWith(directory) && entry.getName().endsWith(extension)) {
try {
String rel = entry.getName().substring(directory.length() + 1);
String rel = entry.getName().substring(directory.length());
streams.put(rel, file.getInputStream(entry));
} catch(IOException e) {
e.printStackTrace();
@@ -17,7 +17,7 @@ public final class LangUtil {
public static void load(String langID, TerraPlugin main) {
Logger logger = main.logger();
File file = new File(main.getDataFolder(), "lang");
try(JarFile jar = main.getModJar()) {
try(JarFile jar = new JarFile(new File(TerraPlugin.class.getProtectionDomain().getCodeSource().getLocation().toURI()))) {
copyResourcesToDirectory(jar, "lang", file.toString());
} catch(IOException | URISyntaxException e) {
main.getDebugLogger().error("Failed to dump language files!");
@@ -5,7 +5,6 @@ import com.dfsek.terra.api.platform.world.Tree;
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
import com.dfsek.terra.api.world.biome.TerraBiome;
import com.dfsek.terra.api.world.flora.Flora;
import com.dfsek.terra.api.world.palette.Palette;
import java.lang.reflect.Type;
import java.util.Map;
@@ -15,7 +14,6 @@ import java.util.Map;
*/
@SuppressWarnings("unused")
public final class Types {
public static final Type BLOCK_DATA_PALETTE_TYPE;
public static final Type BLOCK_DATA_PROBABILITY_COLLECTION_TYPE;
public static final Type FLORA_PROBABILITY_COLLECTION_TYPE;
public static final Type TREE_PROBABILITY_COLLECTION_TYPE;
@@ -23,7 +21,6 @@ public final class Types {
public static final Type TERRA_BIOME_TERRA_BIOME_PROBABILITY_COLLECTION_MAP;
static {
BLOCK_DATA_PALETTE_TYPE = getType("blockDataPalette");
BLOCK_DATA_PROBABILITY_COLLECTION_TYPE = getType("blockDataProbabilityCollection");
FLORA_PROBABILITY_COLLECTION_TYPE = getType("floraProbabilityCollection");
TREE_PROBABILITY_COLLECTION_TYPE = getType("treeProbabilityCollection");
@@ -31,7 +28,6 @@ public final class Types {
TERRA_BIOME_TERRA_BIOME_PROBABILITY_COLLECTION_MAP = getType("terraBiomeProbabilityCollectionMap");
}
private Palette<BlockData> blockDataPalette;
private ProbabilityCollection<BlockData> blockDataProbabilityCollection;
private ProbabilityCollection<Flora> floraProbabilityCollection;
private ProbabilityCollection<Tree> treeProbabilityCollection;
@@ -6,8 +6,9 @@ import com.dfsek.tectonic.exception.LoadException;
import com.dfsek.tectonic.loading.ConfigLoader;
import com.dfsek.tectonic.loading.TypeLoader;
import com.dfsek.tectonic.loading.object.ObjectTemplate;
import com.dfsek.terra.api.registry.Registry;
import com.dfsek.terra.api.util.seeded.NoiseProvider;
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
import com.dfsek.terra.registry.config.NoiseRegistry;
import java.lang.reflect.Type;
import java.util.Locale;
@@ -15,9 +16,9 @@ import java.util.Map;
@SuppressWarnings("unchecked")
public class NoiseSamplerBuilderLoader implements TypeLoader<NoiseSeeded> {
private final NoiseRegistry noiseRegistry;
private final Registry<NoiseProvider> noiseRegistry;
public NoiseSamplerBuilderLoader(NoiseRegistry noiseRegistry) {
public NoiseSamplerBuilderLoader(Registry<NoiseProvider> noiseRegistry) {
this.noiseRegistry = noiseRegistry;
}
@@ -3,11 +3,9 @@ package com.dfsek.terra.config.loaders.palette;
import com.dfsek.tectonic.exception.LoadException;
import com.dfsek.tectonic.loading.ConfigLoader;
import com.dfsek.tectonic.loading.TypeLoader;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.world.palette.Palette;
import com.dfsek.terra.api.world.palette.holder.PaletteHolder;
import com.dfsek.terra.api.world.palette.holder.PaletteHolderBuilder;
import com.dfsek.terra.config.loaders.Types;
import java.lang.reflect.Type;
import java.util.List;
@@ -21,7 +19,7 @@ public class PaletteHolderLoader implements TypeLoader<PaletteHolder> {
PaletteHolderBuilder builder = new PaletteHolderBuilder();
for(Map<String, Integer> layer : palette) {
for(Map.Entry<String, Integer> entry : layer.entrySet()) {
builder.add(entry.getValue(), (Palette<BlockData>) configLoader.loadType(Types.BLOCK_DATA_PALETTE_TYPE, entry.getKey()));
builder.add(entry.getValue(), (Palette) configLoader.loadType(Palette.class, entry.getKey()));
}
}
return builder.build();
@@ -2,37 +2,27 @@ package com.dfsek.terra.config.pack;
import com.dfsek.paralithic.eval.parser.Scope;
import com.dfsek.tectonic.abstraction.AbstractConfigLoader;
import com.dfsek.tectonic.config.ConfigTemplate;
import com.dfsek.tectonic.config.Configuration;
import com.dfsek.tectonic.exception.ConfigException;
import com.dfsek.tectonic.exception.LoadException;
import com.dfsek.tectonic.loading.ConfigLoader;
import com.dfsek.tectonic.loading.TypeRegistry;
import com.dfsek.tectonic.loading.object.ObjectTemplate;
import com.dfsek.terra.api.LoaderRegistrar;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.event.events.config.ConfigPackPostLoadEvent;
import com.dfsek.terra.api.event.events.config.ConfigPackPreLoadEvent;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.platform.world.Tree;
import com.dfsek.terra.api.registry.CheckedRegistry;
import com.dfsek.terra.api.registry.Registry;
import com.dfsek.terra.api.structures.loot.LootTable;
import com.dfsek.terra.api.structures.parser.lang.functions.FunctionBuilder;
import com.dfsek.terra.api.structures.script.StructureScript;
import com.dfsek.terra.api.util.generic.pair.ImmutablePair;
import com.dfsek.terra.api.util.seeded.NoiseProvider;
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
import com.dfsek.terra.api.world.biome.provider.BiomeProvider;
import com.dfsek.terra.api.world.flora.Flora;
import com.dfsek.terra.api.world.palette.Palette;
import com.dfsek.terra.carving.UserDefinedCarver;
import com.dfsek.terra.config.builder.BiomeBuilder;
import com.dfsek.terra.config.dummy.DummyWorld;
import com.dfsek.terra.config.factories.BiomeFactory;
import com.dfsek.terra.config.factories.CarverFactory;
import com.dfsek.terra.config.factories.ConfigFactory;
import com.dfsek.terra.config.factories.FloraFactory;
import com.dfsek.terra.config.factories.OreFactory;
import com.dfsek.terra.config.factories.PaletteFactory;
import com.dfsek.terra.config.factories.StructureFactory;
import com.dfsek.terra.config.factories.TreeFactory;
import com.dfsek.terra.config.fileloaders.FolderLoader;
import com.dfsek.terra.config.fileloaders.Loader;
import com.dfsek.terra.config.fileloaders.ZIPLoader;
@@ -42,29 +32,16 @@ import com.dfsek.terra.config.loaders.config.biome.templates.provider.ImageProvi
import com.dfsek.terra.config.loaders.config.biome.templates.provider.SingleBiomeProviderTemplate;
import com.dfsek.terra.config.loaders.config.sampler.NoiseSamplerBuilderLoader;
import com.dfsek.terra.config.loaders.config.sampler.templates.ImageSamplerTemplate;
import com.dfsek.terra.config.templates.AbstractableTemplate;
import com.dfsek.terra.config.templates.BiomeTemplate;
import com.dfsek.terra.config.templates.CarverTemplate;
import com.dfsek.terra.config.templates.FloraTemplate;
import com.dfsek.terra.config.templates.OreTemplate;
import com.dfsek.terra.config.templates.PaletteTemplate;
import com.dfsek.terra.config.templates.StructureTemplate;
import com.dfsek.terra.config.templates.TreeTemplate;
import com.dfsek.terra.config.prototype.ConfigType;
import com.dfsek.terra.config.prototype.ProtoConfig;
import com.dfsek.terra.registry.OpenRegistry;
import com.dfsek.terra.registry.config.BiomeRegistry;
import com.dfsek.terra.registry.config.CarverRegistry;
import com.dfsek.terra.registry.config.FloraRegistry;
import com.dfsek.terra.registry.config.ConfigTypeRegistry;
import com.dfsek.terra.registry.config.FunctionRegistry;
import com.dfsek.terra.registry.config.LootRegistry;
import com.dfsek.terra.registry.config.NoiseRegistry;
import com.dfsek.terra.registry.config.OreRegistry;
import com.dfsek.terra.registry.config.PaletteRegistry;
import com.dfsek.terra.registry.config.ScriptRegistry;
import com.dfsek.terra.registry.config.StructureRegistry;
import com.dfsek.terra.registry.config.TreeRegistry;
import com.dfsek.terra.world.TerraWorld;
import com.dfsek.terra.world.population.items.TerraStructure;
import com.dfsek.terra.world.population.items.ores.Ore;
import org.apache.commons.io.IOUtils;
import org.json.simple.parser.ParseException;
@@ -75,12 +52,14 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@@ -90,40 +69,27 @@ import java.util.zip.ZipFile;
public class ConfigPack implements LoaderRegistrar {
private final ConfigPackTemplate template = new ConfigPackTemplate();
private final BiomeRegistry biomeRegistry = new BiomeRegistry();
private final StructureRegistry structureRegistry = new StructureRegistry();
private final PaletteRegistry paletteRegistry;
private final FloraRegistry floraRegistry;
private final OreRegistry oreRegistry = new OreRegistry();
private final TreeRegistry treeRegistry;
private final ScriptRegistry scriptRegistry = new ScriptRegistry();
private final LootRegistry lootRegistry = new LootRegistry();
private final CarverRegistry carverRegistry = new CarverRegistry();
private final NoiseRegistry noiseRegistry = new NoiseRegistry();
private final FunctionRegistry functionRegistry = new FunctionRegistry();
private final AbstractConfigLoader abstractConfigLoader = new AbstractConfigLoader();
private final ConfigLoader selfLoader = new ConfigLoader();
private final Scope varScope = new Scope();
private final TerraPlugin main;
private final Loader loader;
private final Configuration configuration;
private final BiomeProvider.BiomeProviderBuilder biomeProviderBuilder;
private final ConfigTypeRegistry configTypeRegistry;
private final Map<Class<?>, ImmutablePair<OpenRegistry<?>, CheckedRegistry<?>>> registryMap = newRegistryMap();
public ConfigPack(File folder, TerraPlugin main) throws ConfigException {
try {
this.configTypeRegistry = new ConfigTypeRegistry(this, main, (id, configType) -> {
OpenRegistry<?> openRegistry = configType.registrySupplier().get();
registryMap.put(configType.getTypeClass(), ImmutablePair.of(openRegistry, new CheckedRegistry<>(openRegistry)));
});
this.loader = new FolderLoader(folder.toPath());
this.main = main;
long l = System.nanoTime();
floraRegistry = new FloraRegistry(main);
paletteRegistry = new PaletteRegistry(main);
treeRegistry = new TreeRegistry();
register(abstractConfigLoader);
register(selfLoader);
@@ -133,15 +99,11 @@ public class ConfigPack implements LoaderRegistrar {
File pack = new File(folder, "pack.yml");
try {
configuration = new Configuration(new FileInputStream(pack));
selfLoader.load(template, configuration);
selfLoader.load(template, new FileInputStream(pack));
main.logger().info("Loading config pack \"" + template.getID() + "\"");
main.getEventManager().callEvent(new ConfigPackPreLoadEvent(this, template -> selfLoader.load(template, configuration)));
load(l, main);
ConfigPackPostTemplate packPostTemplate = new ConfigPackPostTemplate();
selfLoader.load(packPostTemplate, new FileInputStream(pack));
biomeProviderBuilder = packPostTemplate.getProviderBuilder();
@@ -159,17 +121,16 @@ public class ConfigPack implements LoaderRegistrar {
public ConfigPack(ZipFile file, TerraPlugin main) throws ConfigException {
try {
this.configTypeRegistry = new ConfigTypeRegistry(this, main, (id, configType) -> {
OpenRegistry<?> openRegistry = configType.registrySupplier().get();
registryMap.put(configType.getTypeClass(), ImmutablePair.of(openRegistry, new CheckedRegistry<>(openRegistry)));
});
this.loader = new ZIPLoader(file);
this.main = main;
long l = System.nanoTime();
floraRegistry = new FloraRegistry(main);
paletteRegistry = new PaletteRegistry(main);
treeRegistry = new TreeRegistry();
register(abstractConfigLoader);
register(selfLoader);
register(selfLoader);
main.register(selfLoader);
main.register(abstractConfigLoader);
try {
ZipEntry pack = null;
@@ -181,12 +142,9 @@ public class ConfigPack implements LoaderRegistrar {
if(pack == null) throw new LoadException("No pack.yml file found in " + file.getName());
configuration = new Configuration(file.getInputStream(pack));
selfLoader.load(template, configuration);
selfLoader.load(template, file.getInputStream(pack));
main.logger().info("Loading config pack \"" + template.getID() + "\"");
main.getEventManager().callEvent(new ConfigPackPreLoadEvent(this, template -> selfLoader.load(template, configuration)));
load(l, main);
ConfigPackPostTemplate packPostTemplate = new ConfigPackPostTemplate();
@@ -206,21 +164,39 @@ public class ConfigPack implements LoaderRegistrar {
toWorldConfig(new TerraWorld(new DummyWorld(), this, main)); // Build now to catch any errors immediately.
}
public static <C extends AbstractableTemplate, O> void buildAll(ConfigFactory<C, O> factory, OpenRegistry<O> registry, List<C> configTemplates, TerraPlugin main) throws LoadException {
for(C template : configTemplates) registry.add(template.getID(), factory.build(template, main));
@SuppressWarnings({"unchecked", "rawtypes"})
private Map<Class<?>, ImmutablePair<OpenRegistry<?>, CheckedRegistry<?>>> newRegistryMap() {
Map<Class<?>, ImmutablePair<OpenRegistry<?>, CheckedRegistry<?>>> map = new HashMap<Class<?>, ImmutablePair<OpenRegistry<?>, CheckedRegistry<?>>>() {
private static final long serialVersionUID = 4015855819914064466L;
@Override
public ImmutablePair<OpenRegistry<?>, CheckedRegistry<?>> put(Class<?> key, ImmutablePair<OpenRegistry<?>, CheckedRegistry<?>> value) {
selfLoader.registerLoader(key, value.getLeft());
abstractConfigLoader.registerLoader(key, value.getLeft());
return super.put(key, value);
}
};
putPair(map, NoiseProvider.class, new NoiseRegistry());
putPair(map, FunctionBuilder.class, (OpenRegistry<FunctionBuilder>) (Object) new FunctionRegistry());
putPair(map, LootTable.class, new LootRegistry());
putPair(map, StructureScript.class, new ScriptRegistry());
return map;
}
private <R> void putPair(Map<Class<?>, ImmutablePair<OpenRegistry<?>, CheckedRegistry<?>>> map, Class<R> key, OpenRegistry<R> l) {
map.put(key, ImmutablePair.of(l, new CheckedRegistry<>(l)));
}
private void checkDeadEntries(TerraPlugin main) {
biomeRegistry.getDeadEntries().forEach((id, value) -> main.getDebugLogger().warn("Dead entry in biome registry: '" + id + "'"));
paletteRegistry.getDeadEntries().forEach((id, value) -> main.getDebugLogger().warn("Dead entry in palette registry: '" + id + "'"));
floraRegistry.getDeadEntries().forEach((id, value) -> main.getDebugLogger().warn("Dead entry in flora registry: '" + id + "'"));
carverRegistry.getDeadEntries().forEach((id, value) -> main.getDebugLogger().warn("Dead entry in carver registry: '" + id + "'"));
treeRegistry.getDeadEntries().forEach((id, value) -> main.getDebugLogger().warn("Dead entry in tree registry: '" + id + "'"));
oreRegistry.getDeadEntries().forEach((id, value) -> main.getDebugLogger().warn("Dead entry in ore registry: '" + id + "'"));
registryMap.forEach((clazz, pair) -> pair.getLeft().getDeadEntries().forEach((id, value) -> main.getDebugLogger().warn("Dead entry in '" + clazz + "' registry: '" + id + "'")));
}
@SuppressWarnings({"unchecked", "rawtypes"})
private void load(long start, TerraPlugin main) throws ConfigException {
main.getEventManager().callEvent(new ConfigPackPreLoadEvent(this));
for(Map.Entry<String, Double> var : template.getVariables().entrySet()) {
varScope.create(var.getKey(), var.getValue());
}
@@ -228,8 +204,8 @@ public class ConfigPack implements LoaderRegistrar {
loader.open("structures/data", ".tesf").thenEntries(entries -> {
for(Map.Entry<String, InputStream> entry : entries) {
try(InputStream stream = entry.getValue()) {
StructureScript structureScript = new StructureScript(stream, main, scriptRegistry, lootRegistry, functionRegistry);
scriptRegistry.add(structureScript.getId(), structureScript);
StructureScript structureScript = new StructureScript(stream, main, getRegistry(StructureScript.class), getRegistry(LootTable.class), (Registry<FunctionBuilder<?>>) (Object) getRegistry(FunctionBuilder.class));
getOpenRegistry(StructureScript.class).add(structureScript.getId(), structureScript);
} catch(com.dfsek.terra.api.structures.parser.exceptions.ParseException | IOException e) {
throw new LoadException("Unable to load script \"" + entry.getKey() + "\"", e);
}
@@ -237,36 +213,38 @@ public class ConfigPack implements LoaderRegistrar {
}).close().open("structures/loot", ".json").thenEntries(entries -> {
for(Map.Entry<String, InputStream> entry : entries) {
try {
lootRegistry.add(entry.getKey(), new LootTable(IOUtils.toString(entry.getValue(), StandardCharsets.UTF_8), main));
getOpenRegistry(LootTable.class).add(entry.getKey(), new LootTable(IOUtils.toString(entry.getValue(), StandardCharsets.UTF_8), main));
} catch(ParseException | IOException | NullPointerException e) {
throw new LoadException("Unable to load loot table \"" + entry.getKey() + "\"", e);
}
}
}).close();
loader
.open("carving", ".yml").then(configs -> buildAll(new CarverFactory(this), carverRegistry, abstractConfigLoader.loadConfigs(configs, CarverTemplate::new), main)).close()
.open("palettes", ".yml").then(configs -> buildAll(new PaletteFactory(), paletteRegistry, abstractConfigLoader.loadConfigs(configs, PaletteTemplate::new), main)).close()
.open("ores", ".yml").then(configs -> buildAll(new OreFactory(), oreRegistry, abstractConfigLoader.loadConfigs(configs, OreTemplate::new), main)).close()
.open("structures/trees", ".yml").then(configs -> buildAll(new TreeFactory(), treeRegistry, abstractConfigLoader.loadConfigs(configs, TreeTemplate::new), main)).close()
.open("structures/structures", ".yml").then(configs -> buildAll(new StructureFactory(), structureRegistry, abstractConfigLoader.loadConfigs(configs, StructureTemplate::new), main)).close()
.open("flora", ".yml").then(configs -> buildAll(new FloraFactory(), floraRegistry, abstractConfigLoader.loadConfigs(configs, FloraTemplate::new), main)).close()
.open("biomes", ".yml").then(configs -> buildAll(new BiomeFactory(this), biomeRegistry, abstractConfigLoader.loadConfigs(configs, () -> new BiomeTemplate(this, main)), main)).close();
List<Configuration> configurations = new ArrayList<>();
main.getEventManager().callEvent(new ConfigPackPostLoadEvent(this, template -> selfLoader.load(template, configuration)));
loader.open("", ".yml").thenEntries(entries -> entries.forEach(stream -> configurations.add(new Configuration(stream.getValue(), stream.getKey()))));
Map<ConfigType<? extends ConfigTemplate, ?>, List<Configuration>> configs = new HashMap<>();
for(Configuration configuration : configurations) {
ProtoConfig config = new ProtoConfig();
selfLoader.load(config, configuration);
configs.computeIfAbsent(config.getType(), configType -> new ArrayList<>()).add(configuration);
}
for(ConfigType<?, ?> configType : configTypeRegistry.entries()) {
for(ConfigTemplate config : abstractConfigLoader.loadConfigs(configs.getOrDefault(configType, Collections.emptyList()), () -> configType.getTemplate(this, main))) {
((ConfigType) configType).callback(this, main, config);
}
}
main.getEventManager().callEvent(new ConfigPackPostLoadEvent(this));
main.logger().info("Loaded config pack \"" + template.getID() + "\" v" + template.getVersion() + " by " + template.getAuthor() + " in " + (System.nanoTime() - start) / 1000000D + "ms.");
}
public TerraStructure getStructure(String id) {
return structureRegistry.get(id);
}
public Set<TerraStructure> getStructures() {
return structureRegistry.entries();
}
public List<String> getStructureIDs() {
return structureRegistry.entries().stream().map(terraStructure -> terraStructure.getTemplate().getID()).collect(Collectors.toList());
return new HashSet<>(getRegistry(TerraStructure.class).entries());
}
public ConfigPackTemplate getTemplate() {
@@ -277,80 +255,45 @@ public class ConfigPack implements LoaderRegistrar {
return varScope;
}
@SuppressWarnings("unchecked")
public <T> CheckedRegistry<T> getRegistry(Class<T> clazz) {
return (CheckedRegistry<T>) registryMap.getOrDefault(clazz, ImmutablePair.ofNull()).getRight();
}
@SuppressWarnings("unchecked")
protected <T> OpenRegistry<T> getOpenRegistry(Class<T> clazz) {
return (OpenRegistry<T>) registryMap.getOrDefault(clazz, ImmutablePair.ofNull()).getLeft();
}
@Override
public void register(TypeRegistry registry) {
registry
.registerLoader(Palette.class, paletteRegistry)
.registerLoader(BiomeBuilder.class, biomeRegistry)
.registerLoader(Flora.class, floraRegistry)
.registerLoader(Ore.class, oreRegistry)
.registerLoader(Tree.class, treeRegistry)
.registerLoader(StructureScript.class, scriptRegistry)
.registerLoader(TerraStructure.class, structureRegistry)
.registerLoader(LootTable.class, lootRegistry)
.registerLoader(UserDefinedCarver.class, carverRegistry)
.registerLoader(ConfigType.class, configTypeRegistry)
.registerLoader(BufferedImage.class, new BufferedImageLoader(loader))
.registerLoader(NoiseSeeded.class, new NoiseSamplerBuilderLoader(noiseRegistry))
.registerLoader(SingleBiomeProviderTemplate.class, SingleBiomeProviderTemplate::new)
.registerLoader(BiomePipelineTemplate.class, () -> new BiomePipelineTemplate(main))
.registerLoader(ImageProviderTemplate.class, () -> new ImageProviderTemplate(biomeRegistry))
.registerLoader(ImageSamplerTemplate.class, () -> new ImageProviderTemplate(biomeRegistry));
}
public Set<UserDefinedCarver> getCarvers() {
return carverRegistry.entries();
.registerLoader(ImageProviderTemplate.class, () -> new ImageProviderTemplate(getRegistry(BiomeBuilder.class)))
.registerLoader(ImageSamplerTemplate.class, () -> new ImageProviderTemplate(getRegistry(BiomeBuilder.class)))
.registerLoader(NoiseSeeded.class, new NoiseSamplerBuilderLoader(getOpenRegistry(NoiseProvider.class)));
}
public BiomeProvider.BiomeProviderBuilder getBiomeProviderBuilder() {
return biomeProviderBuilder;
}
public CheckedRegistry<StructureScript> getScriptRegistry() {
return new CheckedRegistry<>(scriptRegistry);
}
public CheckedRegistry<BiomeBuilder> getBiomeRegistry() {
return new CheckedRegistry<>(biomeRegistry);
}
public CheckedRegistry<Tree> getTreeRegistry() {
return new CheckedRegistry<>(treeRegistry);
}
public CheckedRegistry<FunctionBuilder<?>> getFunctionRegistry() {
return new CheckedRegistry<>(functionRegistry);
}
public CheckedRegistry<Supplier<ObjectTemplate<NoiseSeeded>>> getNormalizerRegistry() {
return new CheckedRegistry<>(noiseRegistry);
}
public CheckedRegistry<UserDefinedCarver> getCarverRegistry() {
return new CheckedRegistry<>(carverRegistry);
}
public CheckedRegistry<Flora> getFloraRegistry() {
return new CheckedRegistry<>(floraRegistry);
}
public CheckedRegistry<LootTable> getLootRegistry() {
return new CheckedRegistry<>(lootRegistry);
}
public CheckedRegistry<Ore> getOreRegistry() {
return new CheckedRegistry<>(oreRegistry);
}
public CheckedRegistry<Palette<BlockData>> getPaletteRegistry() {
return new CheckedRegistry<>(paletteRegistry);
}
public CheckedRegistry<TerraStructure> getStructureRegistry() {
return new CheckedRegistry<>(structureRegistry);
}
public WorldConfig toWorldConfig(TerraWorld world){
public WorldConfig toWorldConfig(TerraWorld world) {
return new WorldConfig(world, this, main);
}
public CheckedRegistry<ConfigType<?, ?>> getConfigTypeRegistry() {
return new CheckedRegistry<ConfigType<?, ?>>(configTypeRegistry) {
@Override
@SuppressWarnings("deprecation")
public void addUnchecked(String identifier, ConfigType<?, ?> value) {
if(contains(identifier)) throw new UnsupportedOperationException("Cannot override values in ConfigTypeRegistry!");
}
};
}
}
@@ -1,62 +1,51 @@
package com.dfsek.terra.config.pack;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.platform.world.Tree;
import com.dfsek.terra.api.registry.LockedRegistry;
import com.dfsek.terra.api.structures.loot.LootTable;
import com.dfsek.terra.api.structures.script.StructureScript;
import com.dfsek.terra.api.world.biome.TerraBiome;
import com.dfsek.terra.api.world.biome.provider.BiomeProvider;
import com.dfsek.terra.api.world.flora.Flora;
import com.dfsek.terra.api.world.palette.Palette;
import com.dfsek.terra.carving.UserDefinedCarver;
import com.dfsek.terra.config.builder.BiomeBuilder;
import com.dfsek.terra.registry.OpenRegistry;
import com.dfsek.terra.world.TerraWorld;
import com.dfsek.terra.world.generation.math.SamplerCache;
import com.dfsek.terra.world.population.items.TerraStructure;
import com.dfsek.terra.world.population.items.ores.Ore;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class WorldConfig {
private final LockedRegistry<StructureScript> scriptRegistry;
private final LockedRegistry<TerraBiome> biomeRegistry;
private final SamplerCache samplerCache;
private final LockedRegistry<UserDefinedCarver> carverRegistry;
private final LockedRegistry<Tree> treeRegistry;
private final LockedRegistry<Flora> floraRegistry;
private final LockedRegistry<LootTable> lootRegistry;
private final LockedRegistry<Ore> oreRegistry;
private final LockedRegistry<Palette<BlockData>> paletteRegistry;
private final LockedRegistry<TerraStructure> structureRegistry;
private final BiomeProvider provider;
private final TerraWorld world;
private final ConfigPack pack;
private final Map<Class<?>, LockedRegistry<?>> registryMap = new HashMap<>();
public WorldConfig(TerraWorld world, ConfigPack pack, TerraPlugin main) {
this.world = world;
this.pack = pack;
this.samplerCache = new SamplerCache(main, world);
this.scriptRegistry = new LockedRegistry<>(pack.getScriptRegistry());
pack.getConfigTypeRegistry().forEach(configType -> registryMap.put(configType.getTypeClass(), new LockedRegistry<>(pack.getRegistry(configType.getTypeClass()))));
OpenRegistry<TerraBiome> biomeOpenRegistry = new OpenRegistry<>();
pack.getBiomeRegistry().forEach((id, biome) -> biomeOpenRegistry.add(id, biome.apply(world.getWorld().getSeed())));
this.biomeRegistry = new LockedRegistry<>(biomeOpenRegistry);
this.carverRegistry = new LockedRegistry<>(pack.getCarverRegistry());
this.treeRegistry = new LockedRegistry<>(pack.getTreeRegistry());
this.floraRegistry = new LockedRegistry<>(pack.getFloraRegistry());
this.lootRegistry = new LockedRegistry<>(pack.getLootRegistry());
this.oreRegistry = new LockedRegistry<>(pack.getOreRegistry());
this.paletteRegistry = new LockedRegistry<>(pack.getPaletteRegistry());
this.structureRegistry = new LockedRegistry<>(pack.getStructureRegistry());
pack.getRegistry(BiomeBuilder.class).forEach((id, biome) -> biomeOpenRegistry.add(id, biome.apply(world.getWorld().getSeed())));
registryMap.put(TerraBiome.class, new LockedRegistry<>(biomeOpenRegistry));
this.provider = pack.getBiomeProviderBuilder().build(world.getWorld().getSeed());
}
@SuppressWarnings("unchecked")
public <T> LockedRegistry<T> getRegistry(Class<T> clazz) {
return (LockedRegistry<T>) registryMap.get(clazz);
}
public TerraWorld getWorld() {
return world;
}
@@ -66,43 +55,7 @@ public class WorldConfig {
}
public Set<UserDefinedCarver> getCarvers() {
return carverRegistry.entries();
}
public LockedRegistry<StructureScript> getScriptRegistry() {
return scriptRegistry;
}
public LockedRegistry<TerraBiome> getBiomeRegistry() {
return biomeRegistry;
}
public LockedRegistry<Tree> getTreeRegistry() {
return treeRegistry;
}
public LockedRegistry<UserDefinedCarver> getCarverRegistry() {
return carverRegistry;
}
public LockedRegistry<Flora> getFloraRegistry() {
return floraRegistry;
}
public LockedRegistry<LootTable> getLootRegistry() {
return lootRegistry;
}
public LockedRegistry<Ore> getOreRegistry() {
return oreRegistry;
}
public LockedRegistry<Palette<BlockData>> getPaletteRegistry() {
return paletteRegistry;
}
public LockedRegistry<TerraStructure> getStructureRegistry() {
return structureRegistry;
return new HashSet<>(getRegistry(UserDefinedCarver.class).entries());
}
public BiomeProvider getProvider() {
@@ -110,7 +63,7 @@ public class WorldConfig {
}
public Set<TerraStructure> getStructures() {
return structureRegistry.entries();
return new HashSet<>(getRegistry(TerraStructure.class).entries());
}
public ConfigPackTemplate getTemplate() {
@@ -0,0 +1,19 @@
package com.dfsek.terra.config.prototype;
import com.dfsek.tectonic.config.ConfigTemplate;
import com.dfsek.tectonic.exception.LoadException;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.config.pack.ConfigPack;
import com.dfsek.terra.registry.OpenRegistry;
import java.util.function.Supplier;
public interface ConfigType<T extends ConfigTemplate, R> {
T getTemplate(ConfigPack pack, TerraPlugin main);
void callback(ConfigPack pack, TerraPlugin main, T loadedConfig) throws LoadException;
Class<R> getTypeClass();
Supplier<OpenRegistry<R>> registrySupplier();
}
@@ -0,0 +1,21 @@
package com.dfsek.terra.config.prototype;
import com.dfsek.tectonic.annotations.Value;
import com.dfsek.tectonic.config.ConfigTemplate;
public class ProtoConfig implements ConfigTemplate {
@Value("id")
private String id;
@Value("type")
private ConfigType<?, ?> type;
public String getId() {
return id;
}
public ConfigType<?, ?> getType() {
return type;
}
}
@@ -13,7 +13,6 @@ import com.dfsek.terra.api.math.noise.NoiseSampler;
import com.dfsek.terra.api.math.noise.samplers.noise.ConstantSampler;
import com.dfsek.terra.api.math.paralithic.BlankFunction;
import com.dfsek.terra.api.math.paralithic.defined.UserDefinedFunction;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.platform.block.BlockType;
import com.dfsek.terra.api.platform.world.Biome;
import com.dfsek.terra.api.util.GlueList;
@@ -124,7 +123,7 @@ public class BiomeTemplate extends AbstractableTemplate implements ValidatedConf
@Value("ocean.palette")
@Abstractable
@Default
private Palette<BlockData> oceanPalette;
private Palette oceanPalette;
@Value("elevation.equation")
@Default
@@ -159,12 +158,12 @@ public class BiomeTemplate extends AbstractableTemplate implements ValidatedConf
@Value("slabs.palettes")
@Abstractable
@Default
private Map<BlockType, Palette<BlockData>> slabPalettes;
private Map<BlockType, Palette> slabPalettes;
@Value("slabs.stair-palettes")
@Abstractable
@Default
private Map<BlockType, Palette<BlockData>> stairPalettes;
private Map<BlockType, Palette> stairPalettes;
@Value("slant.threshold")
@Abstractable
@@ -247,14 +246,6 @@ public class BiomeTemplate extends AbstractableTemplate implements ValidatedConf
return doSlabs;
}
public Map<BlockType, Palette<BlockData>> getSlabPalettes() {
return slabPalettes;
}
public Map<BlockType, Palette<BlockData>> getStairPalettes() {
return stairPalettes;
}
public BiomeTemplate(ConfigPack pack, TerraPlugin main) {
this.pack = pack;
biomeNoise = new NoiseSeeded() {
@@ -268,7 +259,15 @@ public class BiomeTemplate extends AbstractableTemplate implements ValidatedConf
return 2;
}
};
oceanPalette = new SinglePalette<>(main.getWorldHandle().createBlockData("minecraft:water"));
oceanPalette = new SinglePalette(main.getWorldHandle().createBlockData("minecraft:water"));
}
public Map<BlockType, Palette> getSlabPalettes() {
return slabPalettes;
}
public Map<BlockType, Palette> getStairPalettes() {
return stairPalettes;
}
public NoiseSeeded getBiomeNoise() {
@@ -291,7 +290,7 @@ public class BiomeTemplate extends AbstractableTemplate implements ValidatedConf
return seaLevel;
}
public Palette<BlockData> getOceanPalette() {
public Palette getOceanPalette() {
return oceanPalette;
}
@@ -17,7 +17,7 @@ public class OreTemplate extends AbstractableTemplate {
@Abstractable
private BlockData material;
@Value("type")
@Value("algorithm")
@Abstractable
@Default
private Ore.Type oreType = Ore.Type.VANILLA;
@@ -3,54 +3,22 @@ package com.dfsek.terra.profiler;
import java.util.Map;
public interface Profiler {
/**
* Push a frame to this profiler.
*
* @param frame ID of frame.
*/
void push(String frame);
/**
* Pop a frame from this profiler.
*
* @param frame ID of frame. Must match ID
* at the top of the profiler stack.
*/
void pop(String frame);
/**
* Start profiling.
*/
void start();
/**
* Stop profiling.
*/
void stop();
/**
* Get the profiler data.
*
* @return Profiler data.
*/
Map<String, Timings> getTimings();
/**
* Return a {@link AutoCloseable} implementation that
* may be used in a try-with-resources statement for
* more intuitive profiling, with auto-push/pop.
*
* @param frame ID of frame.
* @return {@link AutoCloseable} implementation for use
* in try-with-resources.
*/
default ProfileFrame profile(String frame) {
push(frame);
return new ProfileFrame(() -> pop(frame));
}
/**
* Clear the profiler data.
*/
void reset();
default void reset() {
// todo: impl
}
}
@@ -83,9 +83,4 @@ public class ProfilerImpl implements Profiler {
}));
return map;
}
@Override
public void reset() {
accessibleThreadMaps.forEach(Map::clear);
}
}
@@ -6,6 +6,7 @@ import com.dfsek.terra.api.registry.Registry;
import com.dfsek.terra.registry.exception.DuplicateEntryException;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@@ -19,7 +20,16 @@ import java.util.stream.Collectors;
* @param <T>
*/
public class OpenRegistry<T> implements Registry<T> {
private final Map<String, Entry<T>> objects = new HashMap<>();
private final Map<String, Entry<T>> objects;
private static final Entry<?> NULL = new Entry<>(null);
public OpenRegistry() {
objects = new HashMap<>();
}
protected OpenRegistry(Map<String, Entry<T>> init) {
this.objects = init;
}
@Override
public T load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
@@ -63,11 +73,10 @@ public class OpenRegistry<T> implements Registry<T> {
return objects.containsKey(identifier);
}
@SuppressWarnings("unchecked")
@Override
public T get(String identifier) {
Entry<T> entry = objects.get(identifier);
if(entry == null) return null;
return entry.getValue();
return objects.getOrDefault(identifier, (Entry<T>) NULL).getValue();
}
@Override
@@ -81,8 +90,8 @@ public class OpenRegistry<T> implements Registry<T> {
}
@Override
public Set<T> entries() {
return objects.values().stream().map(Entry::getRaw).collect(Collectors.toSet());
public Collection<T> entries() {
return objects.values().stream().map(Entry::getRaw).collect(Collectors.toList());
}
@Override
@@ -0,0 +1,117 @@
package com.dfsek.terra.registry.config;
import com.dfsek.tectonic.config.ConfigTemplate;
import com.dfsek.tectonic.exception.LoadException;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.platform.world.Tree;
import com.dfsek.terra.api.world.flora.Flora;
import com.dfsek.terra.api.world.palette.Palette;
import com.dfsek.terra.carving.UserDefinedCarver;
import com.dfsek.terra.config.builder.BiomeBuilder;
import com.dfsek.terra.config.factories.BiomeFactory;
import com.dfsek.terra.config.factories.CarverFactory;
import com.dfsek.terra.config.factories.ConfigFactory;
import com.dfsek.terra.config.factories.FloraFactory;
import com.dfsek.terra.config.factories.OreFactory;
import com.dfsek.terra.config.factories.PaletteFactory;
import com.dfsek.terra.config.factories.StructureFactory;
import com.dfsek.terra.config.factories.TreeFactory;
import com.dfsek.terra.config.pack.ConfigPack;
import com.dfsek.terra.config.prototype.ConfigType;
import com.dfsek.terra.config.templates.AbstractableTemplate;
import com.dfsek.terra.config.templates.BiomeTemplate;
import com.dfsek.terra.config.templates.CarverTemplate;
import com.dfsek.terra.config.templates.FloraTemplate;
import com.dfsek.terra.config.templates.OreTemplate;
import com.dfsek.terra.config.templates.PaletteTemplate;
import com.dfsek.terra.config.templates.StructureTemplate;
import com.dfsek.terra.config.templates.TreeTemplate;
import com.dfsek.terra.registry.OpenRegistry;
import com.dfsek.terra.world.population.items.TerraStructure;
import com.dfsek.terra.world.population.items.ores.Ore;
import java.util.LinkedHashMap;
import java.util.function.BiConsumer;
import java.util.function.Supplier;
public class ConfigTypeRegistry extends OpenRegistry<ConfigType<?, ?>> {
private final BiConsumer<String, ConfigType<?, ?>> callback;
public ConfigTypeRegistry(ConfigPack pack, TerraPlugin main, BiConsumer<String, ConfigType<?, ?>> callback) {
super(new LinkedHashMap<>()); // Ordered
this.callback = callback;
add("PALETTE", new ConfigBuilder<>(new PaletteFactory(), PaletteTemplate::new, Palette.class, () -> new PaletteRegistry(main)));
add("ORE", new ConfigBuilder<>(new OreFactory(), OreTemplate::new, Ore.class, OreRegistry::new));
add("FLORA", new ConfigBuilder<>(new FloraFactory(), FloraTemplate::new, Flora.class, () -> new FloraRegistry(main)));
add("CARVER", new ConfigBuilder<>(new CarverFactory(pack), CarverTemplate::new, UserDefinedCarver.class, CarverRegistry::new));
add("STRUCTURE", new ConfigBuilder<>(new StructureFactory(), StructureTemplate::new, TerraStructure.class, StructureRegistry::new));
add("TREE", new ConfigBuilder<>(new TreeFactory(), TreeTemplate::new, Tree.class, TreeRegistry::new));
add("BIOME", new ConfigBuilder<>(new BiomeFactory(pack), () -> new BiomeTemplate(pack, main), BiomeBuilder.class, BiomeRegistry::new));
add("PACK", new PackBuilder());
}
@Override
protected boolean add(String identifier, Entry<ConfigType<?, ?>> value) {
callback.accept(identifier, value.getValue());
return super.add(identifier, value);
}
private static final class PackBuilder implements ConfigType<ConfigTemplate, ConfigPack> {
@Override
public ConfigTemplate getTemplate(ConfigPack pack, TerraPlugin main) {
return new ConfigTemplate() {
};
}
@Override
public void callback(ConfigPack pack, TerraPlugin main, ConfigTemplate loadedConfig) {
}
@Override
public Class<ConfigPack> getTypeClass() {
return ConfigPack.class;
}
@Override
public Supplier<OpenRegistry<ConfigPack>> registrySupplier() {
return OpenRegistry::new;
}
}
private static final class ConfigBuilder<T extends AbstractableTemplate, O> implements ConfigType<T, O> {
private final ConfigFactory<T, O> factory;
private final Supplier<T> provider;
private final Class<O> clazz;
private final Supplier<OpenRegistry<O>> registrySupplier;
private ConfigBuilder(ConfigFactory<T, O> factory, Supplier<T> provider, Class<O> clazz, Supplier<OpenRegistry<O>> registrySupplier) {
this.factory = factory;
this.provider = provider;
this.clazz = clazz;
this.registrySupplier = registrySupplier;
}
@Override
public T getTemplate(ConfigPack pack, TerraPlugin main) {
return provider.get();
}
@SuppressWarnings("deprecation")
@Override
public void callback(ConfigPack pack, TerraPlugin main, T loadedConfig) throws LoadException {
pack.getRegistry(clazz).addUnchecked(loadedConfig.getID(), factory.build(loadedConfig, main));
}
@Override
public Class<O> getTypeClass() {
return clazz;
}
@Override
public Supplier<OpenRegistry<O>> registrySupplier() {
return registrySupplier;
}
}
}
@@ -68,4 +68,10 @@ public class FloraRegistry extends OpenRegistry<Flora> {
private BlockData data(String s) {
return main.getWorldHandle().createBlockData(s);
}
@Override
public Flora get(String identifier) {
return super.get(identifier);
}
}
@@ -1,6 +1,5 @@
package com.dfsek.terra.registry.config;
import com.dfsek.tectonic.loading.object.ObjectTemplate;
import com.dfsek.terra.api.math.noise.samplers.noise.random.GaussianNoiseSampler;
import com.dfsek.terra.api.math.noise.samplers.noise.random.WhiteNoiseSampler;
import com.dfsek.terra.api.math.noise.samplers.noise.simplex.OpenSimplex2SSampler;
@@ -9,7 +8,7 @@ import com.dfsek.terra.api.math.noise.samplers.noise.simplex.PerlinSampler;
import com.dfsek.terra.api.math.noise.samplers.noise.simplex.SimplexSampler;
import com.dfsek.terra.api.math.noise.samplers.noise.value.ValueCubicSampler;
import com.dfsek.terra.api.math.noise.samplers.noise.value.ValueSampler;
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
import com.dfsek.terra.api.util.seeded.NoiseProvider;
import com.dfsek.terra.config.loaders.config.sampler.templates.DomainWarpTemplate;
import com.dfsek.terra.config.loaders.config.sampler.templates.ImageSamplerTemplate;
import com.dfsek.terra.config.loaders.config.sampler.templates.KernelTemplate;
@@ -26,9 +25,7 @@ import com.dfsek.terra.config.loaders.config.sampler.templates.normalizer.Linear
import com.dfsek.terra.config.loaders.config.sampler.templates.normalizer.NormalNormalizerTemplate;
import com.dfsek.terra.registry.OpenRegistry;
import java.util.function.Supplier;
public class NoiseRegistry extends OpenRegistry<Supplier<ObjectTemplate<NoiseSeeded>>> {
public class NoiseRegistry extends OpenRegistry<NoiseProvider> {
public NoiseRegistry() {
add("LINEAR", LinearNormalizerTemplate::new);
add("NORMAL", NormalNormalizerTemplate::new);
@@ -1,22 +1,21 @@
package com.dfsek.terra.registry.config;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.world.palette.Palette;
import com.dfsek.terra.api.world.palette.SinglePalette;
import com.dfsek.terra.registry.OpenRegistry;
public class PaletteRegistry extends OpenRegistry<Palette<BlockData>> {
public class PaletteRegistry extends OpenRegistry<Palette> {
private final TerraPlugin main;
public PaletteRegistry(TerraPlugin main) {
this.main = main;
}
@Override
public Palette<BlockData> get(String identifier) {
public Palette get(String identifier) {
if(identifier.startsWith("BLOCK:"))
return new SinglePalette<>(main.getWorldHandle().createBlockData(identifier.substring(6))); // Return single palette for BLOCK: shortcut.
return new SinglePalette(main.getWorldHandle().createBlockData(identifier.substring(6))); // Return single palette for BLOCK: shortcut.
return super.get(identifier);
}
}
@@ -25,7 +25,7 @@ public class TerraWorld {
public TerraWorld(World w, ConfigPack c, TerraPlugin main) {
if(!w.isTerraWorld()) throw new IllegalArgumentException("World " + w + " is not a Terra World!");
if(!isTerraWorld(w)) throw new IllegalArgumentException("World " + w + " is not a Terra World!");
this.world = w;
config = c.toWorldConfig(this);
this.provider = config.getProvider();
@@ -34,11 +34,17 @@ public class TerraWorld {
safe = true;
}
public static boolean isTerraWorld(World w) {
return w.getGenerator().getHandle() instanceof GeneratorWrapper;
}
public World getWorld() {
return world;
}
public TerraChunkGenerator getGenerator() {
return ((GeneratorWrapper) world.getGenerator().getHandle()).getHandle();
}
public BiomeProvider getBiomeProvider() {
return provider;
@@ -63,7 +69,7 @@ public class TerraWorld {
*/
public BlockData getUngeneratedBlock(int x, int y, int z) {
UserDefinedBiome biome = (UserDefinedBiome) provider.getBiome(x, z);
Palette<BlockData> palette = biome.getGenerator(world).getPalette(y);
Palette palette = biome.getGenerator(world).getPalette(y);
Sampler sampler = config.getSamplerCache().get(x, z);
int fdX = FastMath.floorMod(x, 16);
int fdZ = FastMath.floorMod(z, 16);
@@ -1,10 +1,13 @@
package com.dfsek.terra.world.generation;
import com.dfsek.terra.api.math.noise.NoiseSampler;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.world.biome.Generator;
import com.dfsek.terra.api.world.palette.Palette;
import com.dfsek.terra.api.world.palette.holder.PaletteHolder;
import com.dfsek.terra.world.generation.math.samplers.terrain.TerrainSampler;
import java.util.Collections;
import java.util.List;
public class WorldGenerator implements Generator {
@SuppressWarnings({"unchecked", "rawtypes", "RedundantSuppression"})
@@ -67,7 +70,7 @@ public class WorldGenerator implements Generator {
* @return BlockPalette - The biome's palette.
*/
@Override
public Palette<BlockData> getPalette(int y) {
public Palette getPalette(int y) {
return palettes.getPalette(y);
}
@@ -86,7 +89,12 @@ public class WorldGenerator implements Generator {
return blendStep;
}
public Palette<BlockData> getSlantPalette(int y) {
@Override
public List<TerrainSampler> getTerrainSamplers() {
return Collections.emptyList();
}
public Palette getSlantPalette(int y) {
return slantPalettes.getPalette(y);
}
}
@@ -1,146 +0,0 @@
package com.dfsek.terra.world.generation.generators;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.math.Range;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.platform.world.BiomeGrid;
import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.api.platform.world.generator.ChunkData;
import com.dfsek.terra.api.util.world.PaletteUtil;
import com.dfsek.terra.api.world.biome.TerraBiome;
import com.dfsek.terra.api.world.biome.UserDefinedBiome;
import com.dfsek.terra.api.world.biome.provider.BiomeProvider;
import com.dfsek.terra.api.world.generation.TerraBlockPopulator;
import com.dfsek.terra.api.world.generation.TerraChunkGenerator;
import com.dfsek.terra.api.world.palette.Palette;
import com.dfsek.terra.config.pack.ConfigPack;
import com.dfsek.terra.config.templates.BiomeTemplate;
import com.dfsek.terra.profiler.ProfileFrame;
import com.dfsek.terra.world.Carver;
import com.dfsek.terra.world.TerraWorld;
import com.dfsek.terra.world.carving.NoiseCarver;
import com.dfsek.terra.world.generation.math.SamplerCache;
import com.dfsek.terra.world.generation.math.samplers.Sampler;
import com.dfsek.terra.world.generation.math.samplers.Sampler2D;
import com.dfsek.terra.world.population.CavePopulator;
import com.dfsek.terra.world.population.OrePopulator;
import com.dfsek.terra.world.population.StructurePopulator;
import com.dfsek.terra.world.population.TreePopulator;
import net.jafama.FastMath;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class DefaultChunkGenerator2D implements TerraChunkGenerator {
private final ConfigPack configPack;
private final TerraPlugin main;
private final Carver carver;
private final List<TerraBlockPopulator> blockPopulators = new ArrayList<>();
private final SamplerCache cache;
public DefaultChunkGenerator2D(ConfigPack c, TerraPlugin main, SamplerCache cache) {
this.configPack = c;
this.main = main;
blockPopulators.add(new CavePopulator(main));
blockPopulators.add(new StructurePopulator(main));
blockPopulators.add(new OrePopulator(main));
blockPopulators.add(new TreePopulator(main));
blockPopulators.add(new TreePopulator(main));
carver = new NoiseCarver(new Range(0, 255), main.getWorldHandle().createBlockData("minecraft:air"), main);
this.cache = cache;
}
@Override
public boolean isParallelCapable() {
return true;
}
@Override
public boolean shouldGenerateCaves() {
return configPack.getTemplate().vanillaCaves();
}
@Override
public boolean shouldGenerateDecorations() {
return configPack.getTemplate().vanillaDecorations();
}
@Override
public boolean shouldGenerateMobs() {
return configPack.getTemplate().vanillaMobs();
}
@Override
public boolean shouldGenerateStructures() {
return configPack.getTemplate().vanillaStructures();
}
@Override
public ConfigPack getConfigPack() {
return configPack;
}
@Override
public TerraPlugin getMain() {
return main;
}
@Override
@SuppressWarnings({"try"})
public ChunkData generateChunkData(@NotNull World world, Random random, int chunkX, int chunkZ, ChunkData chunk) {
TerraWorld tw = main.getWorld(world);
BiomeProvider grid = tw.getBiomeProvider();
try(ProfileFrame ignore = main.getProfiler().profile("chunk_base_2d")) {
if(!tw.isSafe()) return chunk;
int xOrig = (chunkX << 4);
int zOrig = (chunkZ << 4);
Sampler sampler = cache.getChunk(chunkX, chunkZ);
for(int x = 0; x < 16; x++) {
for(int z = 0; z < 16; z++) {
int paletteLevel = 0;
int seaPaletteLevel = 0;
int cx = xOrig + x;
int cz = zOrig + z;
TerraBiome b = grid.getBiome(xOrig + x, zOrig + z);
BiomeTemplate c = ((UserDefinedBiome) b).getConfig();
Palette<BlockData> seaPalette = c.getOceanPalette();
int height = FastMath.min((int) sampler.sample(x, 0, z), world.getMaxHeight() - 1);
for(int y = FastMath.max(height, c.getSeaLevel()); y >= 0; y--) {
BlockData data = y > height ? seaPalette.get(seaPaletteLevel++, cx, y, cz) : PaletteUtil.getPalette(x, y, z, c, sampler).get(paletteLevel++, cx, y, cz);
chunk.setBlock(x, y, z, data);
}
}
}
if(configPack.getTemplate().doBetaCarvers()) {
carver.carve(world, chunkX, chunkZ, chunk);
}
return chunk;
}
}
@Override
public void generateBiomes(@NotNull World world, @NotNull Random random, int chunkX, int chunkZ, @NotNull BiomeGrid biome) {
DefaultChunkGenerator3D.biomes(world, chunkX, chunkZ, biome, main);
}
@Override
public Sampler createSampler(int chunkX, int chunkZ, BiomeProvider provider, World world, int elevationSmooth) {
return new Sampler2D(chunkX, chunkZ, provider, world, elevationSmooth);
}
@Override
public List<TerraBlockPopulator> getPopulators() {
return blockPopulators;
}
}
@@ -45,11 +45,12 @@ public class DefaultChunkGenerator3D implements TerraChunkGenerator {
private final ConfigPack configPack;
private final TerraPlugin main;
private final BlockType water;
private final SinglePalette<BlockData> blank;
private final SinglePalette blank;
private final List<TerraBlockPopulator> blockPopulators = new ArrayList<>();
private final Carver carver;
public DefaultChunkGenerator3D(ConfigPack c, TerraPlugin main) {
this.configPack = c;
this.main = main;
@@ -62,7 +63,7 @@ public class DefaultChunkGenerator3D implements TerraChunkGenerator {
carver = new NoiseCarver(new Range(0, 255), main.getWorldHandle().createBlockData("minecraft:air"), main);
water = main.getWorldHandle().createBlockData("minecraft:water").getBlockType();
blank = new SinglePalette<>(main.getWorldHandle().createBlockData("minecraft:air"));
blank = new SinglePalette(main.getWorldHandle().createBlockData("minecraft:air"));
}
@Override
@@ -103,10 +104,9 @@ public class DefaultChunkGenerator3D implements TerraChunkGenerator {
@Override
@SuppressWarnings({"try"})
public ChunkData generateChunkData(@NotNull World world, Random random, int chunkX, int chunkZ, ChunkData chunk) {
TerraWorld tw = main.getWorld(world);
BiomeProvider grid = tw.getBiomeProvider();
try(ProfileFrame ignore = main.getProfiler().profile("chunk_base_3d")) {
TerraWorld tw = main.getWorld(world);
BiomeProvider grid = tw.getBiomeProvider();
if(!tw.isSafe()) return chunk;
int xOrig = (chunkX << 4);
int zOrig = (chunkZ << 4);
@@ -120,11 +120,11 @@ public class DefaultChunkGenerator3D implements TerraChunkGenerator {
int cx = xOrig + x;
int cz = zOrig + z;
TerraBiome b = grid.getBiome(cx, cz);
TerraBiome b = grid.getBiome(xOrig + x, zOrig + z);
BiomeTemplate c = ((UserDefinedBiome) b).getConfig();
int sea = c.getSeaLevel();
Palette<BlockData> seaPalette = c.getOceanPalette();
Palette seaPalette = c.getOceanPalette();
boolean justSet = false;
BlockData data = null;
@@ -162,11 +162,11 @@ public class DefaultChunkGenerator3D implements TerraChunkGenerator {
}
}
private void prepareBlockPartFloor(BlockData down, BlockData orig, ChunkData chunk, Vector3 block, Map<BlockType, Palette<BlockData>> slabs,
Map<BlockType, Palette<BlockData>> stairs, double thresh, Sampler sampler) {
private void prepareBlockPartFloor(BlockData down, BlockData orig, ChunkData chunk, Vector3 block, Map<BlockType, Palette> slabs,
Map<BlockType, Palette> stairs, double thresh, Sampler sampler) {
if(sampler.sample(block.getX(), block.getY() - 0.4, block.getZ()) > thresh) {
if(stairs != null) {
Palette<BlockData> stairPalette = stairs.get(down.getBlockType());
Palette stairPalette = stairs.get(down.getBlockType());
if(stairPalette != null) {
BlockData stair = stairPalette.get(0, block.getX(), block.getY(), block.getZ()).clone();
if(stair instanceof Stairs) {
@@ -183,11 +183,11 @@ public class DefaultChunkGenerator3D implements TerraChunkGenerator {
}
}
private void prepareBlockPartCeiling(BlockData up, BlockData orig, ChunkData chunk, Vector3 block, Map<BlockType, Palette<BlockData>> slabs,
Map<BlockType, Palette<BlockData>> stairs, double thresh, Sampler sampler) {
private void prepareBlockPartCeiling(BlockData up, BlockData orig, ChunkData chunk, Vector3 block, Map<BlockType, Palette> slabs,
Map<BlockType, Palette> stairs, double thresh, Sampler sampler) {
if(sampler.sample(block.getX(), block.getY() + 0.4, block.getZ()) > thresh) {
if(stairs != null) {
Palette<BlockData> stairPalette = stairs.get(up.getBlockType());
Palette stairPalette = stairs.get(up.getBlockType());
if(stairPalette != null) {
BlockData stair = stairPalette.get(0, block.getX(), block.getY(), block.getZ()).clone();
if(stair instanceof Stairs) {
@@ -227,20 +227,17 @@ public class DefaultChunkGenerator3D implements TerraChunkGenerator {
return false;
}
@SuppressWarnings({"try"})
static void biomes(@NotNull World world, int chunkX, int chunkZ, @NotNull BiomeGrid biome, TerraPlugin main) {
try(ProfileFrame ignore = main.getProfiler().profile("biomes")) {
int xOrig = (chunkX << 4);
int zOrig = (chunkZ << 4);
BiomeProvider grid = main.getWorld(world).getBiomeProvider();
for(int x = 0; x < 4; x++) {
for(int z = 0; z < 4; z++) {
int cx = xOrig + (x << 2);
int cz = zOrig + (z << 2);
TerraBiome b = grid.getBiome(cx, cz);
int xOrig = (chunkX << 4);
int zOrig = (chunkZ << 4);
BiomeProvider grid = main.getWorld(world).getBiomeProvider();
for(int x = 0; x < 4; x++) {
for(int z = 0; z < 4; z++) {
int cx = xOrig + (x << 2);
int cz = zOrig + (z << 2);
TerraBiome b = grid.getBiome(cx, cz);
biome.setBiome(cx, cz, b.getVanillaBiomes().get(b.getGenerator(world).getBiomeNoise(), cx, 0, cz));
}
biome.setBiome(cx, cz, b.getVanillaBiomes().get(b.getGenerator(world).getBiomeNoise(), cx, 0, cz));
}
}
}
@@ -25,7 +25,7 @@ public class SamplerCache {
public Sampler load(@NotNull Long key) {
int cx = (int) (key >> 32);
int cz = (int) key.longValue();
return world.getWorld().getTerraGenerator().createSampler(cx, cz, world.getBiomeProvider(), world.getWorld(), world.getConfig().getTemplate().getElevationBlend());
return world.getGenerator().createSampler(cx, cz, world.getBiomeProvider(), world.getWorld(), world.getConfig().getTemplate().getElevationBlend());
}
});
}
@@ -3,22 +3,26 @@ package com.dfsek.terra.world.generation.math.interpolation;
/**
* Class for bilinear interpolation of values arranged on a unit square.
*/
public class Interpolator {
public class BilinearInterpolator implements Interpolator2 {
private final double v0, v1, v2, v3;
private final double width, height;
/**
* Constructs an interpolator with given values as vertices of a unit square.
*
* @param v0 - (0,0)
* @param v0 - (0,0)
* @param v1 - (1,0)
* @param v2 - (0,1)
* @param v3 - (1,1)
* @param width
* @param height
*/
public Interpolator(double v0, double v1, double v2, double v3) {
public BilinearInterpolator(double v0, double v1, double v2, double v3, double width, double height) {
this.v0 = v0;
this.v1 = v1;
this.v2 = v2;
this.v3 = v3;
this.width = width;
this.height = height;
}
/**
@@ -40,7 +44,10 @@ public class Interpolator {
* @param t - Z value
* @return double - The interpolated value.
*/
public double bilerp(double s, double t) {
@Override
public double interpolate(double s, double t) {
s/=width;
t/=height;
double v01 = lerp(s, v0, v1);
double v23 = lerp(s, v2, v3);
return lerp(t, v01, v23);
@@ -1,88 +0,0 @@
package com.dfsek.terra.world.generation.math.interpolation;
import com.dfsek.terra.api.math.vector.Vector3;
import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.api.util.mutable.MutableInteger;
import com.dfsek.terra.api.world.biome.Generator;
import com.dfsek.terra.api.world.biome.provider.BiomeProvider;
import net.jafama.FastMath;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiFunction;
/**
* Class to abstract away the Interpolators needed to generate a chunk.<br>
* Contains method to get interpolated noise at a coordinate within the chunk.
*/
public class ChunkInterpolator2D implements ChunkInterpolator {
private final Interpolator[][] interpGrid = new Interpolator[4][4];
private final BiFunction<Generator, Vector3, Double> noiseGetter;
/**
* Instantiates a 3D ChunkInterpolator3D at a pair of chunk coordinates.
*
* @param chunkX X coordinate of the chunk.
* @param chunkZ Z coordinate of the chunk.
* @param provider Biome Provider to use for biome fetching.
*/
public ChunkInterpolator2D(World w, int chunkX, int chunkZ, BiomeProvider provider, BiFunction<Generator, Vector3, Double> noiseGetter) {
this.noiseGetter = noiseGetter;
int xOrigin = chunkX << 4;
int zOrigin = chunkZ << 4;
double[][] noiseStorage = new double[5][5];
for(int x = 0; x < 5; x++) {
for(int z = 0; z < 5; z++) {
Generator generator = provider.getBiome(xOrigin + (x << 2), zOrigin + (z << 2)).getGenerator(w);
Map<Generator, MutableInteger> genMap = new HashMap<>();
int step = generator.getBlendStep();
int blend = generator.getBlendDistance();
for(int xi = -blend; xi <= blend; xi++) {
for(int zi = -blend; zi <= blend; zi++) {
genMap.computeIfAbsent(provider.getBiome(xOrigin + (x << 2) + (xi * step), zOrigin + (z << 2) + (zi * step)).getGenerator(w), g -> new MutableInteger(0)).increment(); // Increment by 1
}
}
noiseStorage[x][z] = computeNoise(genMap, (x << 2) + xOrigin, 0, (z << 2) + zOrigin);
}
}
for(int x = 0; x < 4; x++) {
for(int z = 0; z < 4; z++) {
interpGrid[x][z] = new Interpolator(
noiseStorage[x][z],
noiseStorage[x + 1][z],
noiseStorage[x][z + 1],
noiseStorage[x + 1][z + 1]);
}
}
}
private static int reRange(int value, int high) {
return FastMath.max(FastMath.min(value, high), 0);
}
public double computeNoise(Generator generator, double x, double y, double z) {
return noiseGetter.apply(generator, new Vector3(x, y, z));
}
/**
* Gets the noise at a pair of internal chunk coordinates.
*
* @param x The internal X coordinate (0-15).
* @param z The internal Z coordinate (0-15).
* @return double - The interpolated noise at the coordinates.
*/
@Override
public double getNoise(double x, double y, double z) {
return interpGrid[reRange(((int) x) / 4, 3)][reRange(((int) z) / 4, 3)].bilerp((x % 4) / 4, (z % 4) / 4);
}
public double getNoise(int x, int y, int z) {
return interpGrid[x / 4][z / 4].bilerp((double) (x % 4) / 4, (double) (z % 4) / 4);
}
}
@@ -67,7 +67,7 @@ public class ChunkInterpolator3D implements ChunkInterpolator {
for(int x = 0; x < 4; x++) {
for(int z = 0; z < 4; z++) {
for(int y = 0; y < size; y++) {
interpGrid[x][y][z] = new Interpolator3(
interpGrid[x][y][z] = new TrilinearInterpolator(
noiseStorage[x][z][y],
noiseStorage[x + 1][z][y],
noiseStorage[x][z][y + 1],
@@ -75,7 +75,7 @@ public class ChunkInterpolator3D implements ChunkInterpolator {
noiseStorage[x][z + 1][y],
noiseStorage[x + 1][z + 1][y],
noiseStorage[x][z + 1][y + 1],
noiseStorage[x + 1][z + 1][y + 1]);
noiseStorage[x + 1][z + 1][y + 1], 4, 4, 4);
}
}
}
@@ -98,10 +98,10 @@ public class ChunkInterpolator3D implements ChunkInterpolator {
*/
@Override
public double getNoise(double x, double y, double z) {
return interpGrid[reRange(((int) x) / 4, 3)][FastMath.max(FastMath.min(((int) y), max), min) / 4][reRange(((int) z) / 4, 3)].trilerp((x % 4) / 4, (y % 4) / 4, (z % 4) / 4);
return interpGrid[reRange(((int) x) / 4, 3)][FastMath.max(FastMath.min(((int) y), max), min) / 4][reRange(((int) z) / 4, 3)].interpolate((x % 4), (y % 4), (z % 4));
}
public double getNoise(int x, int y, int z) {
return interpGrid[x / 4][y / 4][z / 4].trilerp((double) (x % 4) / 4, (double) (y % 4) / 4, (double) (z % 4) / 4);
return interpGrid[x / 4][y / 4][z / 4].interpolate(x % 4, y % 4, z % 4);
}
}
@@ -0,0 +1,12 @@
package com.dfsek.terra.world.generation.math.interpolation;
public interface Interpolator2 {
/**
* 2D Bilinear interpolation between 4 points on a unit square.
*
* @param s - X value
* @param t - Z value
* @return double - The interpolated value.
*/
double interpolate(double s, double t);
}
@@ -1,32 +1,5 @@
package com.dfsek.terra.world.generation.math.interpolation;
/**
* Class for bilinear interpolation of values arranged on a unit square.
*/
public class Interpolator3 {
private final Interpolator bottom;
private final Interpolator top;
/**
* Constructs an interpolator with given values as vertices of a unit cube.
* * @param _000 The value at <code>(t, u, v) = (0, 0, 0)</code>.
* * @param _100 The value at <code>(t, u, v) = (1, 0, 0)</code>.
* * @param _010 The value at <code>(t, u, v) = (0, 1, 0)</code>.
* * @param _110 The value at <code>(t, u, v) = (1, 1, 0)</code>.
* * @param _001 The value at <code>(t, u, v) = (0, 0, 1)</code>.
* * @param _101 The value at <code>(t, u, v) = (1, 0, 1)</code>.
* * @param _011 The value at <code>(t, u, v) = (0, 1, 1)</code>.
* * @param _111 The value at <code>(t, u, v) = (1, 1, 1)</code>.
*/
public Interpolator3(double _000, double _100,
double _010, double _110,
double _001, double _101,
double _011, double _111) {
this.top = new Interpolator(_000, _010, _001, _011);
this.bottom = new Interpolator(_100, _110, _101, _111);
}
public double trilerp(double x, double y, double z) {
return Interpolator.lerp(x, top.bilerp(y, z), bottom.bilerp(y, z));
}
}
public interface Interpolator3 {
double interpolate(double x, double y, double z);
}
@@ -0,0 +1,40 @@
package com.dfsek.terra.world.generation.math.interpolation;
/**
* Class for bilinear interpolation of values arranged on a unit square.
*/
public class TrilinearInterpolator implements Interpolator3 {
private final BilinearInterpolator bottom;
private final BilinearInterpolator top;
private final double length, width, height;
/**
* Constructs an interpolator with given values as vertices of a unit cube.
* * @param _000 The value at <code>(t, u, v) = (0, 0, 0)</code>.
* * @param _100 The value at <code>(t, u, v) = (1, 0, 0)</code>.
* * @param _010 The value at <code>(t, u, v) = (0, 1, 0)</code>.
* * @param _110 The value at <code>(t, u, v) = (1, 1, 0)</code>.
* * @param _001 The value at <code>(t, u, v) = (0, 0, 1)</code>.
* * @param _101 The value at <code>(t, u, v) = (1, 0, 1)</code>.
* * @param _011 The value at <code>(t, u, v) = (0, 1, 1)</code>.
* * @param _111 The value at <code>(t, u, v) = (1, 1, 1)</code>.
*/
public TrilinearInterpolator(double _000, double _100,
double _010, double _110,
double _001, double _101,
double _011, double _111, double length, double width, double height) {
this.length = length;
this.width = width;
this.height = height;
this.top = new BilinearInterpolator(_000, _010, _001, _011, 1, 1);
this.bottom = new BilinearInterpolator(_100, _110, _101, _111, 1, 1);
}
@Override
public double interpolate(double x, double y, double z) {
x/=length;
z/=width;
y/=height;
return BilinearInterpolator.lerp(x, top.interpolate(y, z), bottom.interpolate(y, z));
}
}
@@ -1,27 +0,0 @@
package com.dfsek.terra.world.generation.math.samplers;
import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.api.world.biome.provider.BiomeProvider;
import com.dfsek.terra.world.generation.math.interpolation.ChunkInterpolator2D;
import com.dfsek.terra.world.generation.math.interpolation.ElevationInterpolator;
import net.jafama.FastMath;
public class Sampler2D implements Sampler {
private final ChunkInterpolator2D interpolator;
private final ElevationInterpolator elevationInterpolator;
public Sampler2D(int x, int z, BiomeProvider provider, World world, int elevationSmooth) {
this.interpolator = new ChunkInterpolator2D(world, x, z, provider, (generator, coord) -> generator.getBaseSampler().getNoise(coord));
this.elevationInterpolator = new ElevationInterpolator(world, x, z, provider, elevationSmooth);
}
@Override
public double sample(double x, double y, double z) {
return interpolator.getNoise(x, 0, z) + elevationInterpolator.getElevation(FastMath.roundToInt(x), FastMath.roundToInt(z));
}
@Override
public double sample(int x, int y, int z) {
return interpolator.getNoise(x, 0, z) + elevationInterpolator.getElevation(FastMath.roundToInt(x), FastMath.roundToInt(z));
}
}
@@ -0,0 +1,22 @@
package com.dfsek.terra.world.generation.math.samplers.terrain;
import com.dfsek.paralithic.Expression;
import com.dfsek.terra.world.generation.math.interpolation.Interpolator3;
public class ExpressionSampler implements TerrainSampler {
private final Expression expression;
public ExpressionSampler(Expression expression) {
this.expression = expression;
}
@Override
public Interpolator3 sample(double x, double y, double z) {
return (i, i1, i2) -> expression.evaluate(x, y, z);
}
@Override
public int getXResolution() {
return 1;
}
}
@@ -0,0 +1,31 @@
package com.dfsek.terra.world.generation.math.samplers.terrain;
import com.dfsek.terra.world.generation.math.interpolation.Interpolator3;
public class InterpolatedSampler implements TerrainSampler {
private final InterpolatorSupplier supplier;
public InterpolatedSampler(InterpolatorSupplier supplier) {
this.supplier = supplier;
}
@Override
public Interpolator3 sample(double x, double y, double z) {
return null;
}
@Override
public int getXResolution() {
return supplier.getXResolution();
}
@Override
public int getYResolution() {
return supplier.getYResolution();
}
@Override
public int getZResolution() {
return supplier.getZResolution();
}
}
@@ -0,0 +1,19 @@
package com.dfsek.terra.world.generation.math.samplers.terrain;
import com.dfsek.terra.world.generation.math.interpolation.Interpolator2;
import com.dfsek.terra.world.generation.math.interpolation.Interpolator3;
import java.util.function.Supplier;
public interface InterpolatorSupplier {
int getXResolution();
int getYResolution();
int getZResolution();
Interpolator2 get(double t, double v0, double v1);
Interpolator3 get(double _000, double _100,
double _010, double _110,
double _001, double _101,
double _011, double _111);
}
@@ -0,0 +1,22 @@
package com.dfsek.terra.world.generation.math.samplers.terrain;
import com.dfsek.terra.world.generation.math.interpolation.Interpolator2;
import com.dfsek.terra.world.generation.math.interpolation.Interpolator3;
public interface TerrainSampler {
Interpolator3 sample(double x, double y, double z);
default Interpolator2 sample(double x, double z) {
return (s, t) -> sample(x, 0, z).interpolate(s, 0, t);
}
int getXResolution();
default int getYResolution() {
return getXResolution();
}
default int getZResolution() {
return getXResolution();
}
}
@@ -33,7 +33,7 @@ public class FloraPopulator implements TerraBlockPopulator {
public void populate(@NotNull World world, @NotNull Chunk chunk) {
TerraWorld tw = main.getWorld(world);
try(ProfileFrame ignore = main.getProfiler().profile("flora")) {
if(tw.getConfig().getTemplate().disableFlora()) return;
if(tw.getConfig().getTemplate().disableCarvers()) return;
if(!tw.isSafe()) return;
BiomeProvider provider = tw.getBiomeProvider();
@@ -28,7 +28,7 @@ public class OrePopulator implements TerraBlockPopulator {
public void populate(@NotNull World world, @NotNull Chunk chunk) {
TerraWorld tw = main.getWorld(world);
try(ProfileFrame ignore = main.getProfiler().profile("ore")) {
if(tw.getConfig().getTemplate().disableOres()) return;
if(tw.getConfig().getTemplate().disableCarvers()) return;
if(!tw.isSafe()) return;
for(int cx = -1; cx <= 1; cx++) {
@@ -32,7 +32,7 @@ public class StructurePopulator implements TerraBlockPopulator, Chunkified {
public void populate(@NotNull World world, @NotNull Chunk chunk) {
TerraWorld tw = main.getWorld(world);
try(ProfileFrame ignore = main.getProfiler().profile("structure")) {
if(tw.getConfig().getTemplate().disableStructures()) return;
if(tw.getConfig().getTemplate().disableCarvers()) return;
int cx = (chunk.getX() << 4);
int cz = (chunk.getZ() << 4);
@@ -33,7 +33,7 @@ public class TreePopulator implements TerraBlockPopulator {
public void populate(@NotNull World world, @NotNull Chunk chunk) {
TerraWorld tw = main.getWorld(world);
try(ProfileFrame ignore = main.getProfiler().profile("tree")) {
if(tw.getConfig().getTemplate().disableTrees()) return;
if(tw.getConfig().getTemplate().disableCarvers()) return;
if(!tw.isSafe()) return;
BiomeProvider provider = tw.getBiomeProvider();

Some files were not shown because too many files have changed in this diff Show More