-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API for registering custom world preset editors #9436
API for registering custom world preset editors #9436
Conversation
…ft into one hook squashme
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't done any testing yet though does seem like it will end up being useful, but left a couple comments/questions about various parts of the code.
*/ | ||
public void register(ResourceKey<WorldPreset> key, PresetEditor editor) | ||
{ | ||
this.editors.put(key, editor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know enough about usage people would have, but is this something that would make sense to validate against overriding? The main reason I ask is that because vanilla's entries get added before the event is fired which means that modders can override the preset editor's for vanilla presets which just feels wrong when the name itself specifies they are meant as a specific "preset"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"PresetEditor" means editor of a WorldPreset, not editor-that-has-already-been-set.
I like the idea of allowing mods to override the vanilla editors here but we can open that to further discussion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will defer then to both you and other people who do world gen mods and the like what use cases there are and if it makes more sense for this to be overridable or not, but will give it at least a few days to give other devs a chance to weigh in on this
src/main/java/net/minecraftforge/client/event/RegisterPresetEditorsEvent.java
Show resolved
Hide resolved
src/main/java/net/minecraftforge/client/PresetEditorManager.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested this and it seems to work, but one small change that should be made for the test mod is adding a lang value for the preset generator.custom_preset_editor_test.custom_preset_editor_test
just so that it is clearer to people trying to figure out how it works from the test mod that a lang entry should also be set.
@Commoble, this pull request has conflicts, please resolve them for this PR to move forward. |
@Commoble, this pull request has conflicts, please resolve them for this PR to move forward. |
|
||
@OnlyIn(Dist.CLIENT) | ||
public interface PresetEditor { | ||
+ @Deprecated /** @deprecated see {@link net.minecraftforge.client.PresetEditorManager} */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note: Patches do not have to be minimized, as long as the # of hunk lines is not changed. Merging these on the same line is not necessary. Compare this to, for example, what we do in BuiltinRegistries.java.patch
. Having a Forge:
prefix is preferred for the case where mapping providers document the field alongside Forge, and then it is good to know which is which or where something came from (even if it is obvious in the case).
} | ||
|
||
/** | ||
* {@return Retrieves the PresetEditor for the given WorldPreset key, or null if no such PresetEditor exists.} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another note: This makes the javadoc output look like Returns Retrieves the PresetEditor for the given WorldPreset key, or null if no such PresetEditor exists..
The trailing period is added by javadoc for you. Additionally, the verb of Returns
is already present, so another verb should be avoided.
Minecraft provides the ability for datapacks to declare "world presets", a list of default dimensions over which individual dimension jsons (also from datapacks) are then merged on top of. World presets can be chosen when creating a new save. This system replaced the older "world type" system.
For singleplayer worlds, minecraft also allows specific world presets to be further edited by the user via guis assigned to world preset IDs; currently, this "registry" is hardcoded to an immutable map of guis for vanilla's flat, buffet, and single biome world presets. This map is an immutable map in a static final field in an interface, making adding additional screen factories to this map infeasible as it currently stands.
To allow mods to add PresetEditors (screen factories) for their own world presets, we create our own map, fire an event during client init to register additional PresetEditors, and redirect vanilla's queries to forge's map.
Mods can subscribe to the RegisterPresetEditorsEvent (mod bus, client only) to register their own PresetEditors. A test mod is included with a very basic example screen that allows the user to select a swamp world or a desert world.