Change up game rules to be more flexible and follow Sponge practices#1745
Change up game rules to be more flexible and follow Sponge practices#1745parlough wants to merge 1 commit intoSpongePowered:bleedingfrom
Conversation
7321518 to
c497773
Compare
|
Locally the file |
c497773 to
a4dc697
Compare
| import java.util.Optional; | ||
|
|
||
| /** | ||
| * Someone who holds various {@link GameRule}s and the values they point to. |
There was a problem hiding this comment.
Someone? Were you going to delegate per user gamerules to the world properties that currently controls them?
There was a problem hiding this comment.
I meant "Something", just in-case an implementation wants to allow gamerules to extend beyond just a WorldProperties.
|
If you are going to refactor GameRules I'm expecting that you are going to come up with some sort of sharing context? e.g. nether and the_end and modded dimenson-worlds by default on sponge delegate to the overworld gamerules? Where as Sponge worlds can share a 'multiverse'/world that contains the gamerules for a group of dimensions? Note: My use of multiverse is just to convey concept, I am utterly aware how much of a Pain in the ass it would be to globally have support for true multiverses separating out inventory, stats, recipes. plugins etc on a Mojang based server. I just can't help but think that the concept would be valuable, even if it only see's limited use on SpongeForge / SpongeVanilla. There isn't anything really forcing Lantern to having such limitations. |
| * @param <T> The value type of the game rule | ||
| */ | ||
| @CatalogedBy(GameRuleTypes.class) | ||
| public interface GameRuleType<T> extends CatalogType { |
There was a problem hiding this comment.
I think I'll introduce a builder for this to make it easier to create a new one.
| * @param <T> The value type of the game rule | ||
| */ | ||
| @CatalogedBy(GameRules.class) | ||
| public interface GameRule<T> extends CatalogType { |
There was a problem hiding this comment.
Will create a builder for this as well.
| * | ||
| * @return This type's deserializer | ||
| */ | ||
| Function<String, T> getDeserializer(); |
There was a problem hiding this comment.
It’s not really a serializer, it’s more of a printer/parser combination, isn’t it?
| @@ -334,28 +332,6 @@ default Difficulty getDifficulty() { | |||
| return getProperties().getDifficulty(); | |||
| } | |||
|
|
|||
There was a problem hiding this comment.
Can you make the world also a GameRuleHolder? And then delegate all the methods to the properties.
There was a problem hiding this comment.
Yeah, I will just specify in the Javadoc that most implementations delegate the methods to the properties.
| * @param value The value to set the game rule to | ||
| * @param <T> The value type of the game rule | ||
| */ | ||
| <T> void setGameRule(GameRule<T> gameRule, T value); |
There was a problem hiding this comment.
This method should also call the ChangeWorldGameRuleEvent, so return a boolean whether it was successful? That said, the ChangeWorldGameRuleEvent should also be refactored for the new API.
There was a problem hiding this comment.
Ah yes I forgot to do this, thanks for reminding me. Will make these changes.
|
While I know we're breaking commands and text for API 8 without deprecations, here, I'd argue deprecations serve a purpose. Deprecations will emit a warning on compilers that use the code to point them in the right direction - while we'll really hammer the change in commands when API 8 is out, game rules and smaller, easier to deprecate systems might end up falling by the wayside. We should make sure we are in the mindset of deprecating when we can, not just using major API versions as a reason to break with no consequence. That being said, looking at this, I suspect it's possible for both systems to coexist peacefully with no breaking changes. Do you think you could do that in time for 7.1? If so, maybe that's a route forward - a deprecation in 7.1 with the new methods, removal in 8. |
|
@dualspiral I believe this is doable to an extent, the only problem would be for the events. I could introduce an event with a different name or package that supports the new changes while deprecating the old one. How would you feel about that solution? |
|
@dualspiral I disagree with trying to maintain deprecation policy for the bleeding branch. As we're already doing massive refactors left and right (Text has already changed, Value API is about to change, DataRegistration is partially changing due to values changing, Extent API is 100% rewritten at this point, Scheduling tasks will change as soon as we expose the client in the process, CauseStackManager is getting a rename, some major events are being redone, Inventory API changed, commands are going to be changing), I don't feel it necessary to keep something as simple as game rules deprecated for a version and then break it in a little way afterwards. Not to mention that documentation alone for the migration from API 7 to API 8 will be somewhat extensive at that point given the PR's that were used to make all these changes, it'll be easy to show the migration via test plugin changes needed between the various pr's. |
|
@gabizou With the extent of changes since, where before, it was impossible to know with clarity how much we would need to change, sure. Deprecations do serve a purpose and we should still pay mind to their use, but given how much we've changed since this was opened, I see the point. Do bear in mind I made that comment 7 months ago, just after 7 was released. Things have changed! |
Of course, just resuscitating PR's (having went through I think all the open PR's currently) and making sure their either alive, or relegated for future development/management. |
|
The game rule is already refactored in the api-8 branch, comment on the status PR #1995 if there's anything missing. |
Follows the style the rest of Sponge uses better while also providing a more flexible system.
Looking for some input on the set-up I have so far, then I will flesh out the rest of the API and write the implementation.
@Cybermaxke Any input here?