Skip to content
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

Advancements API #1554

Merged
merged 15 commits into from Dec 31, 2017
Merged

Conversation

Cybermaxke
Copy link
Contributor

@Cybermaxke Cybermaxke commented May 10, 2017

API | Common | Forge | Vanilla

This PR adds the advancements API, with additions extra to the features provided in vanilla Minecraft. Implementations will follow when 1.12 is released.

The AdvancementTree represents a advancement Tab, it can be build with a root advancement. Advancements that are attached to the root advancement will be present in the tree. The layout of the tree can also be customized, which means that you can move the advancements around in the tab though a AdvancementTreeEvent.GenerateLayout event.

AdvancementConditions are the conditions that should be met before an advancement is unlocked. I provided AND and OR operations that can be applied. There is not limit in the complexity like in the json files.

There is also Triggers that can be applied to the AdvancementCondition, the details of vanilla triggers are not exposed in the API (the configuration). However you can create your own Triggers which will be parsed in the advancement json files.
http://minecraft.gamepedia.com/Advancements#Triggers

Additionally there is a ScoreAdvancementCriterion which requires a specific goal value to be achieved before it gets done, this is also supported by triggers. The trigger will need to trigger the criteria multiple times until the goal is reached, this is also supported in the json files by adding a trigger_times property to the trigger.

Extras:

  • Generic Events - Used for the registrations of advancements and trees.
  • ScoreAdvancementCriterion - Allows you to provide a goal value and when the score reaches its goal the advancement will be unlocked. Also supported in json files.
  • Complex AND and OR condition operations
  • Custom triggers (configurable) and supported in json
  • Customize the advancement tree layout.

@stephan-gh stephan-gh added the api: 7 (u) version: 1.12 label May 10, 2017
* @param criteria The other criteria
* @return The and operation
*/
static AdvancementCriterion buildAnd(AdvancementCriterion... criteria) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the build prefix is needed here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise will it conflict with the non-static and method.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can make it static AdvancementCriterion and(AdvancementCriterion adv1, AdvancementCriterion... therest)

@kashike
Copy link
Contributor

kashike commented May 10, 2017

This should target the 1.12 branch.

* Some that has a style within a advancement tree. Either an
* {@link AdvancementTree} or an {@link Advancement}.
*/
public interface Styled extends CatalogType, TextRepresentable {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name should be more specific.

@Cybermaxke
Copy link
Contributor Author

Cybermaxke commented May 10, 2017

@kashike I don't think that this PR will be finished before the 1.12 branch is merged. Or is there going to be separate development between 1.11 and 1.12 for a while?

@kashike
Copy link
Contributor

kashike commented May 10, 2017

@Cybermaxke I'd say it's better to target 1.12 - there are changes there for 1.12, not in bleeding, and this PR targets 1.12.

@stephan-gh
Copy link
Contributor

@Cybermaxke You can easily change the target branch again once we merge 1.12. Until it is merged it should target 1.12 so you get all the updated dependencies etc. (you will also not be able to implement it by targeting bleeding)

* Changes the frame around the {@link Advancement} icon and
* also the appearance in the notifications.
*/
public interface AdvancementType extends CatalogType {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ CatalogedBy(AdvancementTypes.class)


/**
* Notification appearance:
* Challenge Complete!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a method for this in AdvancementType

Something like List<Text> format(Advancement adv);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be a List? Or maybe just a Text object where the lines are separated with \n.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use embedded special characters. Collection where Collection is List, Set, etc.. is the right approach. Please, no magic format characters in the data. Use the Library.

* @param criteria The other criteria
* @return The and operation
*/
static AdvancementCriterion buildAnd(AdvancementCriterion... criteria) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can make it static AdvancementCriterion and(AdvancementCriterion adv1, AdvancementCriterion... therest)

/**
* Represents a source that can trigger a {@link AdvancementCriterion}.
*/
public interface TriggerType extends CatalogType {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ CatalogedBy(TriggerTypes.class)

* @param criterion The score criterion
* @return The score criterion progress
*/
default ScoreCriterionProgress tryGet(ScoreAdvancementCriterion criterion) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getUnchecked?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe require similar to the data methods?
https://github.com/SpongePowered/SpongeAPI/blob/bleeding/src/main/java/org/spongepowered/api/data/value/ValueContainer.java
getUnchecked isn't used anywhere else as far I know,

@Cybermaxke Cybermaxke changed the base branch from bleeding to 1.12 May 31, 2017 22:27
@stephan-gh stephan-gh force-pushed the 1.12 branch 2 times, most recently from 7478cad to 401b69a Compare June 9, 2017 08:50
@stephan-gh stephan-gh changed the base branch from 1.12 to bleeding June 10, 2017 11:05
@stephan-gh
Copy link
Contributor

Please rebase your PR on the latest bleeding branch.

@kashike
Copy link
Contributor

kashike commented Jun 17, 2017

@Cybermaxke Are you working on rebasing this?

@Cybermaxke
Copy link
Contributor Author

I will try to get back on this in a week or so, then I will have more time. I will also start implementing at that time.

@randombyte-developer
Copy link

What's the status on this?

@Cybermaxke
Copy link
Contributor Author

@randombyte-developer I am going to start with the implementation, I already updated the API. ;)

@parlough
Copy link
Contributor

parlough commented Dec 4, 2017

@Cybermaxke The hero we all want but don't deserve.


public static final TriggerType CONSUME_ITEM = DummyObjectProvider.createFor(TriggerType.class, "CONSUME_ITEM");

public static final TriggerType CURSE_ZOMBIE_VILLAGER = DummyObjectProvider.createFor(TriggerType.class, "CONSUME_ITEM");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"CONSUME_ITEM" again ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically, we use labels like Dummy to mean something that does absolutely nothing. But here you're using it to do something meaningful. Why not maker ObjectProvider generic FooObjectProvider seems to be a factory. See also, Design Patterns, GoF. etc..


public static final TriggerType VILLAGER_TRADE = DummyObjectProvider.createFor(TriggerType.class, "VILLAGER_TRADE");

public static final TriggerType CHANGED_DIMENSION = DummyObjectProvider.createFor(TriggerType.class, "CHANGED_DIMENSION");
Copy link
Contributor

@ImMorpheus ImMorpheus Dec 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be before CONSTRUCT_BEACON.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these string labels "VILLAGER_TRADE" should be moved into a class holding static final strings. I am loathe to see embedded literal strings in code as much as possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just run sortfield once more and it will be fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sibomots The strings here are used only for debugging. the dummy objects are nearly useless and as far as I'm aware don't even necessarily need correct names outside of logging in the case that something goes terribly wrong.

If Java had a way of copying the variable name or line number into a parameter that'd be the ideal solution.

Yes the dummy objects are a gross hack, but it's a gross hack that was decided on by the core team a long while ago, and isn't the subject of this PR outside correcting the incorrect debug text.

@ImMorpheus
Copy link
Contributor

Some triggers are missing, is that on purpose ? (effects_changed, levitation, ecc.)

@Cybermaxke
Copy link
Contributor Author

@ImMorpheus No, that's not intentional, they probably added more triggers after I designed the API.

@sibomots
Copy link

sibomots commented Dec 6, 2017

AND, OR.. but not NOT ?

It's also remarkable how many bugs you might find and defects uncover by elaborating the JavaDocs. Please attempt to flesh those out and scratch off the work item "java docs can be improved."

Ie., writing the docs will uncover some defects and deliver aid for those who want to understand the PR.

@Cybermaxke
Copy link
Contributor Author

@sibomots AND and OR operations are the only ones supported in vanilla minecraft. I already added a custom one for a "score" criterion. Do you know a usecase where a NOT operation could be used, this would complicate the internals a lot more so I will only added it if it's worth adding.

I will also document the javadocs a bit more when the implementation is finished, since things can still change.

@Cybermaxke
Copy link
Contributor Author

@XakepSDK Ah yes, that is possible. The example should give a good idea how to do it.

@XakepSDK
Copy link

XakepSDK commented Dec 25, 2017 via email

@Cybermaxke
Copy link
Contributor Author

@XakepSDK You trigger the advancements by listening to events for specific actions, for example within the break block event, join event, etc. You have to trigger them by manually. The icon is just visual, it has nothing to do with the triggering

* @param id The identifier
* @return The advancement tree
*/
AdvancementTree build(String id);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gabizou Should I move to id to a separate method, to be consistent with the keys builder you added?

@Cybermaxke Cybermaxke changed the title [WIP] Advancements API Advancements API Dec 27, 2017
@@ -222,7 +223,10 @@
* is not supported
* @throws CatalogTypeAlreadyRegisteredException if the type cannot be
* registered because a matching type was already registered
* @deprecated Is scheduled to be removed in API 8, the
* {@link GameRegistryEvent.Register} should be used instead
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nested classes will not link properly in Java 8's javadoc generator. They need to be fully qualified to work.

gabizou added a commit that referenced this pull request Dec 31, 2017
Signed-off-by: Gabriel Harris-Rouquette <gabizou@me.com>
@gabizou gabizou merged commit 4124309 into SpongePowered:bleeding Dec 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet