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
Advancements API #1554
Conversation
* @param criteria The other criteria | ||
* @return The and operation | ||
*/ | ||
static AdvancementCriterion buildAnd(AdvancementCriterion... criteria) { |
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 think the build
prefix is needed here
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.
Otherwise will it conflict with the non-static and
method.
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.
You can make it static AdvancementCriterion and(AdvancementCriterion adv1, AdvancementCriterion... therest)
This should target the |
* Some that has a style within a advancement tree. Either an | ||
* {@link AdvancementTree} or an {@link Advancement}. | ||
*/ | ||
public interface Styled extends CatalogType, TextRepresentable { |
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.
This name should be more specific.
@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? |
@Cybermaxke I'd say it's better to target |
@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 { |
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.
@ CatalogedBy(AdvancementTypes.class)
|
||
/** | ||
* Notification appearance: | ||
* Challenge Complete! |
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.
Add a method for this in AdvancementType
Something like List<Text> format(Advancement adv);
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.
Should it be a List
? Or maybe just a Text
object where the lines are separated with \n
.
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.
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) { |
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.
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 { |
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.
@ CatalogedBy(TriggerTypes.class)
* @param criterion The score criterion | ||
* @return The score criterion progress | ||
*/ | ||
default ScoreCriterionProgress tryGet(ScoreAdvancementCriterion criterion) { |
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.
getUnchecked
?
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.
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,
c441d18
to
45474d0
Compare
7478cad
to
401b69a
Compare
Please rebase your PR on the latest bleeding branch. |
@Cybermaxke Are you working on rebasing this? |
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. |
What's the status on this? |
6c48a4f
to
1be6ae1
Compare
@randombyte-developer I am going to start with the implementation, I already updated the API. ;) |
@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"); |
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.
"CONSUME_ITEM" again ?
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.
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"); |
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.
This should be before CONSTRUCT_BEACON.
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.
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.
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 run sortfield once more and it will be fine.
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.
@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.
Some triggers are missing, is that on purpose ? (effects_changed, levitation, ecc.) |
@ImMorpheus No, that's not intentional, they probably added more triggers after I designed the API. |
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. |
@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. |
@XakepSDK Ah yes, that is possible. The example should give a good idea how to do it. |
For example - dig dirt. Where do you say, that player should "dig" dirt?
Only icon differs. Does advancement icon means action? E.g. shovel = dig,
furnace = smelt?
|
@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); |
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.
@gabizou Should I move to id
to a separate method, to be consistent with the keys builder you added?
49102ff
to
cd34a08
Compare
…d from trigger, it's not accessible in this form.
- Don't use a specific collection type in the api - Moved events to inner classes - Replaced the advancement tree layout transformer with a event, this is the only moment that you can modify the layout. - Minor changes.
…API. Be consistent with added key builder.
c0b3bf5
to
4124309
Compare
@@ -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 |
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.
Nested classes will not link properly in Java 8's javadoc generator. They need to be fully qualified to work.
Signed-off-by: Gabriel Harris-Rouquette <gabizou@me.com>
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.Advancement
s 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 aAdvancementTreeEvent.GenerateLayout
event.AdvancementCondition
s 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
Trigger
s that can be applied to theAdvancementCondition
, the details of vanilla triggers are not exposed in the API (the configuration). However you can create your ownTrigger
s 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 atrigger_times
property to the trigger.Extras:
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.