From 0a47d5d8a588b00766748128402171def86a273a Mon Sep 17 00:00:00 2001 From: Anselm Brehme Date: Thu, 28 Sep 2023 04:26:12 +0200 Subject: [PATCH] MC 1.20.2 API breaks --- .../api/advancement/Advancement.java | 23 ++--------- .../{TreeLayout.java => AdvancementNode.java} | 32 ++++++--------- .../api/advancement/AdvancementTemplate.java | 23 ++++++++++- .../api/advancement/AdvancementTree.java | 39 +++++++++++++++---- .../api/advancement/TreeLayoutElement.java | 2 +- .../criteria/AdvancementCriterion.java | 12 +++++- .../criteria/trigger/FilteredTrigger.java | 18 +-------- .../advancement/criteria/trigger/Trigger.java | 7 ++-- .../api/command/selector/Selector.java | 9 +++-- .../living/player/server/ServerPlayer.java | 3 +- .../event/advancement/AdvancementEvent.java | 8 ++++ .../advancement/AdvancementTreeEvent.java | 9 +---- .../api/event/advancement/CriterionEvent.java | 9 +++++ .../api/event/block/entity/CookingEvent.java | 3 ++ .../event/item/inventory/CraftItemEvent.java | 3 ++ .../spongepowered/api/item/recipe/Recipe.java | 3 +- 16 files changed, 115 insertions(+), 88 deletions(-) rename src/main/java/org/spongepowered/api/advancement/{TreeLayout.java => AdvancementNode.java} (62%) diff --git a/src/main/java/org/spongepowered/api/advancement/Advancement.java b/src/main/java/org/spongepowered/api/advancement/Advancement.java index 93836ae23ed..98daddb4395 100644 --- a/src/main/java/org/spongepowered/api/advancement/Advancement.java +++ b/src/main/java/org/spongepowered/api/advancement/Advancement.java @@ -26,34 +26,17 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.ComponentLike; -import org.spongepowered.api.ResourceKeyed; +import org.spongepowered.api.ResourceKey; import org.spongepowered.api.advancement.criteria.AdvancementCriterion; import org.spongepowered.api.data.persistence.DataSerializable; -import java.util.Collection; import java.util.List; import java.util.Optional; /** * An advancement. */ -public interface Advancement extends ComponentLike, ResourceKeyed, DataSerializable { - - /** - * Gets the {@link AdvancementTree} this advancement is located in, - * will only be present if the root advancement was used to create - * a {@link AdvancementTree}. - * - * @return The advancement tree - */ - Optional tree(); - - /** - * Gets all the children {@link Advancement}s. - * - * @return The children advancements - */ - Collection children(); +public interface Advancement extends ComponentLike, DataSerializable { /** * Gets all the {@link AdvancementCriterion} that should be achieved @@ -72,7 +55,7 @@ public interface Advancement extends ComponentLike, ResourceKeyed, DataSerializa * * @return The parent advancement, if present */ - Optional parent(); + Optional parent(); /** * Gets the {@link DisplayInfo} of this advancement, if present. diff --git a/src/main/java/org/spongepowered/api/advancement/TreeLayout.java b/src/main/java/org/spongepowered/api/advancement/AdvancementNode.java similarity index 62% rename from src/main/java/org/spongepowered/api/advancement/TreeLayout.java rename to src/main/java/org/spongepowered/api/advancement/AdvancementNode.java index 8a9b4a15ab8..02bef84fab1 100644 --- a/src/main/java/org/spongepowered/api/advancement/TreeLayout.java +++ b/src/main/java/org/spongepowered/api/advancement/AdvancementNode.java @@ -24,37 +24,29 @@ */ package org.spongepowered.api.advancement; +import org.spongepowered.api.ResourceKeyed; +import org.spongepowered.api.entity.living.player.Player; + import java.util.Collection; -import java.util.Optional; /** - * Represents the tree (tab) layout of a {@link AdvancementTree}. + * A node in a {@link AdvancementTree} + * visible to a {@link Player} once the root {@link Advancement} gets achieved. */ -public interface TreeLayout { - - /** - * Gets the {@link AdvancementTree} this layout is assigned to. - * - * @return The tree - */ - AdvancementTree tree(); +public interface AdvancementNode extends ResourceKeyed { /** - * Gets all the {@link TreeLayoutElement}s that are - * present in this layout. + * Gets the root {@link Advancement}. * - * @return The tree layout elements + * @return The root advancement */ - Collection elements(); + Advancement rootAdvancement(); /** - * Gets the {@link TreeLayoutElement} for the specified {@link Advancement}, - * {@link Optional#empty()} will be returned if the advancement is not present - * in the tree or if there is no {@link DisplayInfo} present. + * Gets all the children {@link Advancement}s. * - * @param advancement The advancement - * @return The tree layout element + * @return The children advancements */ - Optional element(Advancement advancement); + Collection children(); } diff --git a/src/main/java/org/spongepowered/api/advancement/AdvancementTemplate.java b/src/main/java/org/spongepowered/api/advancement/AdvancementTemplate.java index 8fa72685338..7388e885696 100644 --- a/src/main/java/org/spongepowered/api/advancement/AdvancementTemplate.java +++ b/src/main/java/org/spongepowered/api/advancement/AdvancementTemplate.java @@ -31,6 +31,8 @@ import org.spongepowered.api.datapack.DataPackEntry; import org.spongepowered.api.util.ResourceKeyedBuilder; +import java.util.Optional; + /** * A template for an {@link Advancement}. */ @@ -52,19 +54,36 @@ static Builder builder() { */ Advancement advancement(); + /** + * Gets the {@link AdvancementTree} of this advancement + * will only be present if it is a root advancement. + * + * @return The advancement tree + */ + Optional tree(); + /** * A builder to create {@link Advancement}s. */ interface Builder extends ResourceKeyedBuilder { /** - * Sets the parent {@link Advancement}. + * Sets the parent {@link Advancement} template. + *

For the root advancement use {@link #root}

+ * + * @param parent The parent advancement + * @return This builder, for chaining + */ + Builder parent(AdvancementTemplate parent); + + /** + * Sets the parent {@link Advancement} key. *

For the root advancement use {@link #root}

* * @param parent The parent advancement * @return This builder, for chaining */ - Builder parent(Advancement parent); + Builder parent(ResourceKey parent); /** * Sets this advancement as root. diff --git a/src/main/java/org/spongepowered/api/advancement/AdvancementTree.java b/src/main/java/org/spongepowered/api/advancement/AdvancementTree.java index 2f892b76e05..a477132c2dd 100644 --- a/src/main/java/org/spongepowered/api/advancement/AdvancementTree.java +++ b/src/main/java/org/spongepowered/api/advancement/AdvancementTree.java @@ -27,26 +27,49 @@ import org.spongepowered.api.ResourceKey; import org.spongepowered.api.entity.living.player.Player; +import java.util.Collection; import java.util.Optional; /** * Represents a {@link Advancement} tree or tab menu. The tree will become - * visible to a {@link Player} once the root {@link Advancement} gets achieved. + * visible to a {@link Player} once the {@link #rootAdvancement() root advancement} gets achieved. */ -public interface AdvancementTree { +public interface AdvancementTree extends AdvancementNode { /** - * Gets the root {@link Advancement}. + * Gets the background texture of this tree. * - * @return The root advancement + * @return The background texture */ - Advancement rootAdvancement(); + Optional backgroundPath(); /** - * Gets the background texture of this tree. + * Gets all the {@link TreeLayoutElement}s that are + * present in this layout. * - * @return The background texture + * @return The tree layout elements */ - Optional backgroundPath(); + Collection layoutElements(); + + /** + * Gets the {@link TreeLayoutElement} for the specified {@link Advancement}, + * {@link Optional#empty()} will be returned if the advancement is not present + * in the tree or if there is no {@link DisplayInfo} present. + * + * @param advancement The advancement + * @return The tree layout element + */ + Optional layoutElement(AdvancementTemplate advancement); + + + /** + * Gets the {@link TreeLayoutElement} for the specified {@link Advancement}, + * {@link Optional#empty()} will be returned if the advancement is not present + * in the tree or if there is no {@link DisplayInfo} present. + * + * @param advancementKey The advancement key + * @return The tree layout element + */ + Optional layoutElement(ResourceKey advancementKey); } diff --git a/src/main/java/org/spongepowered/api/advancement/TreeLayoutElement.java b/src/main/java/org/spongepowered/api/advancement/TreeLayoutElement.java index 5cd0e00993d..3e84bab4173 100644 --- a/src/main/java/org/spongepowered/api/advancement/TreeLayoutElement.java +++ b/src/main/java/org/spongepowered/api/advancement/TreeLayoutElement.java @@ -27,7 +27,7 @@ import org.spongepowered.math.vector.Vector2d; /** - * Represents a element in the {@link TreeLayout}. + * Represents a layout element in the {@link AdvancementTree}. */ public interface TreeLayoutElement { diff --git a/src/main/java/org/spongepowered/api/advancement/criteria/AdvancementCriterion.java b/src/main/java/org/spongepowered/api/advancement/criteria/AdvancementCriterion.java index 08c8959914b..9477ef1b44d 100644 --- a/src/main/java/org/spongepowered/api/advancement/criteria/AdvancementCriterion.java +++ b/src/main/java/org/spongepowered/api/advancement/criteria/AdvancementCriterion.java @@ -27,6 +27,8 @@ import org.spongepowered.api.Sponge; import org.spongepowered.api.advancement.Advancement; import org.spongepowered.api.advancement.criteria.trigger.FilteredTrigger; +import org.spongepowered.api.advancement.criteria.trigger.FilteredTriggerConfiguration; +import org.spongepowered.api.advancement.criteria.trigger.Trigger; import org.spongepowered.api.util.CopyableBuilder; import org.spongepowered.api.util.Nameable; @@ -127,6 +129,13 @@ static Builder builder() { */ Optional> trigger(); + /** + * Gets the {@link Trigger} of this {@link AdvancementCriterion}, if present. + * + * @return The trigger + */ + Optional> type(); + /** * A builder to create {@link AdvancementCriterion}s. */ @@ -142,10 +151,11 @@ interface BaseBuilder trigger); + B trigger(Trigger type, FilteredTrigger trigger); /** * Sets the name of the {@link AdvancementCriterion}. Names can be diff --git a/src/main/java/org/spongepowered/api/advancement/criteria/trigger/FilteredTrigger.java b/src/main/java/org/spongepowered/api/advancement/criteria/trigger/FilteredTrigger.java index d9169ec070b..2a542d9a8d6 100644 --- a/src/main/java/org/spongepowered/api/advancement/criteria/trigger/FilteredTrigger.java +++ b/src/main/java/org/spongepowered/api/advancement/criteria/trigger/FilteredTrigger.java @@ -44,13 +44,6 @@ static Builder builder() { return Sponge.game().builderProvider().provide(Builder.class); } - /** - * Gets the {@link Trigger}. - * - * @return The type - */ - Trigger type(); - /** * Gets the {@link FilteredTriggerConfiguration} of this trigger. * @@ -66,22 +59,13 @@ static Builder builder() { interface Builder extends org.spongepowered.api.util.Builder, Builder>, CopyableBuilder, Builder> { - /** - * Sets the {@link Trigger}. - * - * @param type The trigger type - * @param The configuration type - * @return This builder, for chaining - */ - Builder type(Trigger type); - /** * Sets the {@link FilteredTriggerConfiguration}. * * @param config The configuration * @return This builder, for chaining */ - Builder config(C config); + Builder config(T config); /** * Builds the {@link FilteredTrigger}. diff --git a/src/main/java/org/spongepowered/api/advancement/criteria/trigger/Trigger.java b/src/main/java/org/spongepowered/api/advancement/criteria/trigger/Trigger.java index 1252514036f..3d276758640 100644 --- a/src/main/java/org/spongepowered/api/advancement/criteria/trigger/Trigger.java +++ b/src/main/java/org/spongepowered/api/advancement/criteria/trigger/Trigger.java @@ -26,7 +26,6 @@ import com.google.gson.Gson; import io.leangen.geantyref.TypeToken; -import org.spongepowered.api.ResourceKeyed; import org.spongepowered.api.Sponge; import org.spongepowered.api.advancement.criteria.AdvancementCriterion; import org.spongepowered.api.config.ConfigManager; @@ -37,8 +36,8 @@ import org.spongepowered.api.event.advancement.CriterionEvent; import org.spongepowered.api.registry.DefaultedRegistryValue; import org.spongepowered.api.scoreboard.criteria.Criterion; +import org.spongepowered.api.util.Builder; import org.spongepowered.api.util.CopyableBuilder; -import org.spongepowered.api.util.ResourceKeyedBuilder; import org.spongepowered.api.util.annotation.CatalogedBy; import org.spongepowered.configurate.ConfigurationOptions; import org.spongepowered.configurate.serialize.TypeSerializer; @@ -55,7 +54,7 @@ */ @SuppressWarnings("unchecked") @CatalogedBy(Triggers.class) -public interface Trigger extends DefaultedRegistryValue, ResourceKeyed { +public interface Trigger extends DefaultedRegistryValue { /** * Creates a new {@link Builder} which can be used to create @@ -103,7 +102,7 @@ static Builder builder() { * * @param The configuration type */ - interface Builder extends ResourceKeyedBuilder, Builder>, + interface Builder extends org.spongepowered.api.util.Builder, Builder>, CopyableBuilder, Builder> { /** diff --git a/src/main/java/org/spongepowered/api/command/selector/Selector.java b/src/main/java/org/spongepowered/api/command/selector/Selector.java index 7174e46420a..e00251ca20c 100644 --- a/src/main/java/org/spongepowered/api/command/selector/Selector.java +++ b/src/main/java/org/spongepowered/api/command/selector/Selector.java @@ -26,6 +26,7 @@ import org.spongepowered.api.Sponge; import org.spongepowered.api.advancement.Advancement; +import org.spongepowered.api.advancement.AdvancementTemplate; import org.spongepowered.api.advancement.criteria.AdvancementCriterion; import org.spongepowered.api.command.CommandCause; import org.spongepowered.api.data.persistence.DataView; @@ -204,7 +205,7 @@ interface Builder extends org.spongepowered.api.util.Builder * @param advancement The advancement that players must have. * @return This builder, for chaining */ - Builder addAdvancement(Advancement advancement); + Builder addAdvancement(AdvancementTemplate advancement); /** * Adds an {@link Advancement} constraint to this selector, requiring @@ -213,7 +214,7 @@ interface Builder extends org.spongepowered.api.util.Builder * @param advancement The advancement that players must not have. * @return This builder, for chaining */ - Builder addNotAdvancement(Advancement advancement); + Builder addNotAdvancement(AdvancementTemplate advancement); /** * Adds an {@link AdvancementCriterion} constraint to this selector, @@ -224,7 +225,7 @@ interface Builder extends org.spongepowered.api.util.Builder * @param criterion The criterion the player must have * @return This builder, for chaining */ - Builder addAdvancementCriterion(Advancement advancement, AdvancementCriterion criterion); + Builder addAdvancementCriterion(AdvancementTemplate advancement, AdvancementCriterion criterion); /** * Adds an {@link AdvancementCriterion} constraint to this selector, @@ -235,7 +236,7 @@ interface Builder extends org.spongepowered.api.util.Builder * @param criterion The criterion the player must not have * @return This builder, for chaining */ - Builder addNotAdvancementCriterion(Advancement advancement, AdvancementCriterion criterion); + Builder addNotAdvancementCriterion(AdvancementTemplate advancement, AdvancementCriterion criterion); /** * Adds an {@link DataView} as an NBT style constraint. diff --git a/src/main/java/org/spongepowered/api/entity/living/player/server/ServerPlayer.java b/src/main/java/org/spongepowered/api/entity/living/player/server/ServerPlayer.java index 76ee0653359..f408b4f2740 100644 --- a/src/main/java/org/spongepowered/api/entity/living/player/server/ServerPlayer.java +++ b/src/main/java/org/spongepowered/api/entity/living/player/server/ServerPlayer.java @@ -30,6 +30,7 @@ import org.spongepowered.api.Server; import org.spongepowered.api.advancement.Advancement; import org.spongepowered.api.advancement.AdvancementProgress; +import org.spongepowered.api.advancement.AdvancementTemplate; import org.spongepowered.api.advancement.AdvancementTree; import org.spongepowered.api.data.Keys; import org.spongepowered.api.data.type.SkinPart; @@ -280,7 +281,7 @@ default SetValue.Mutable displayedSkinParts() { * @param advancement The advancement * @return The advancement progress */ - AdvancementProgress progress(Advancement advancement); + AdvancementProgress progress(AdvancementTemplate advancement); /** * Gets all the {@link AdvancementTree}s that this diff --git a/src/main/java/org/spongepowered/api/event/advancement/AdvancementEvent.java b/src/main/java/org/spongepowered/api/event/advancement/AdvancementEvent.java index b71a7c111da..16348f97a78 100644 --- a/src/main/java/org/spongepowered/api/event/advancement/AdvancementEvent.java +++ b/src/main/java/org/spongepowered/api/event/advancement/AdvancementEvent.java @@ -24,6 +24,7 @@ */ package org.spongepowered.api.event.advancement; +import org.spongepowered.api.ResourceKey; import org.spongepowered.api.advancement.Advancement; import org.spongepowered.api.advancement.criteria.AdvancementCriterion; import org.spongepowered.api.entity.living.player.server.ServerPlayer; @@ -52,6 +53,13 @@ public interface AdvancementEvent extends Event { */ Advancement advancement(); + /** + * Gets the {@link Advancement} that is being targeted. + * + * @return The advancement + */ + ResourceKey advancementKey(); + /** * Is called when a {@link Advancement} is granted/unlocked. * diff --git a/src/main/java/org/spongepowered/api/event/advancement/AdvancementTreeEvent.java b/src/main/java/org/spongepowered/api/event/advancement/AdvancementTreeEvent.java index 8b07fb33e7a..880b5237187 100644 --- a/src/main/java/org/spongepowered/api/event/advancement/AdvancementTreeEvent.java +++ b/src/main/java/org/spongepowered/api/event/advancement/AdvancementTreeEvent.java @@ -25,7 +25,6 @@ package org.spongepowered.api.event.advancement; import org.spongepowered.api.advancement.AdvancementTree; -import org.spongepowered.api.advancement.TreeLayout; import org.spongepowered.api.event.Event; /** @@ -43,16 +42,10 @@ public interface AdvancementTreeEvent extends Event { /** * Is called when the layout of a {@link AdvancementTree} gets * updated, this is done after the vanilla game generates the - * layout. You can safely move elements in the {@link TreeLayout} + * layout. You can safely move layout elements in the {@link AdvancementTree} * within this event. */ interface GenerateLayout extends AdvancementTreeEvent { - /** - * Gets the {@link TreeLayout} that got generated. - * - * @return The tree layout - */ - TreeLayout layout(); } } diff --git a/src/main/java/org/spongepowered/api/event/advancement/CriterionEvent.java b/src/main/java/org/spongepowered/api/event/advancement/CriterionEvent.java index bc0bf1982fb..f3a4606f48a 100644 --- a/src/main/java/org/spongepowered/api/event/advancement/CriterionEvent.java +++ b/src/main/java/org/spongepowered/api/event/advancement/CriterionEvent.java @@ -28,6 +28,7 @@ import org.spongepowered.api.advancement.criteria.ScoreAdvancementCriterion; import org.spongepowered.api.advancement.criteria.trigger.FilteredTrigger; import org.spongepowered.api.advancement.criteria.trigger.FilteredTriggerConfiguration; +import org.spongepowered.api.advancement.criteria.trigger.Trigger; import org.spongepowered.api.event.Cancellable; import org.spongepowered.api.event.Cause; import org.spongepowered.api.event.GenericEvent; @@ -129,6 +130,14 @@ interface Trigger extends CriterionEvent */ FilteredTrigger trigger(); + /** + * Gets the {@link FilteredTrigger} + * that is being processed. + * + * @return The trigger + */ + org.spongepowered.api.advancement.criteria.trigger.Trigger type(); + /** * Gets the result of the trigger event. * diff --git a/src/main/java/org/spongepowered/api/event/block/entity/CookingEvent.java b/src/main/java/org/spongepowered/api/event/block/entity/CookingEvent.java index acedf03258d..c71c95e4faa 100644 --- a/src/main/java/org/spongepowered/api/event/block/entity/CookingEvent.java +++ b/src/main/java/org/spongepowered/api/event/block/entity/CookingEvent.java @@ -24,6 +24,7 @@ */ package org.spongepowered.api.event.block.entity; +import org.spongepowered.api.ResourceKey; import org.spongepowered.api.block.entity.BlockEntity; import org.spongepowered.api.event.Cancellable; import org.spongepowered.api.event.Event; @@ -62,6 +63,8 @@ public interface CookingEvent extends Event { */ Optional recipe(); + Optional recipeKey(); + /** * The first tick of an item cooking. */ diff --git a/src/main/java/org/spongepowered/api/event/item/inventory/CraftItemEvent.java b/src/main/java/org/spongepowered/api/event/item/inventory/CraftItemEvent.java index 84f3abd6bbe..6341cff580c 100644 --- a/src/main/java/org/spongepowered/api/event/item/inventory/CraftItemEvent.java +++ b/src/main/java/org/spongepowered/api/event/item/inventory/CraftItemEvent.java @@ -24,6 +24,7 @@ */ package org.spongepowered.api.event.item.inventory; +import org.spongepowered.api.ResourceKey; import org.spongepowered.api.event.item.inventory.container.ClickContainerEvent; import org.spongepowered.api.item.inventory.ItemStackSnapshot; import org.spongepowered.api.item.inventory.Slot; @@ -51,6 +52,8 @@ public interface CraftItemEvent extends ChangeInventoryEvent { */ Optional recipe(); + Optional recipeKey(); + /** * This event is fired before the item is taken out of the * output slot but after completing the recipe in the grid. diff --git a/src/main/java/org/spongepowered/api/item/recipe/Recipe.java b/src/main/java/org/spongepowered/api/item/recipe/Recipe.java index ba0fd6c65b4..f3d263619c7 100644 --- a/src/main/java/org/spongepowered/api/item/recipe/Recipe.java +++ b/src/main/java/org/spongepowered/api/item/recipe/Recipe.java @@ -24,7 +24,6 @@ */ package org.spongepowered.api.item.recipe; -import org.spongepowered.api.ResourceKeyed; import org.spongepowered.api.block.BlockTypes; import org.spongepowered.api.block.entity.carrier.Campfire; import org.spongepowered.api.block.entity.carrier.furnace.BlastFurnace; @@ -58,7 +57,7 @@ *

{@link StoneCutterRecipe} for recipes in a {@link BlockTypes#STONECUTTER} block

*

{@link SmithingRecipe} for recipes in a {@link BlockTypes#SMITHING_TABLE} block

*/ -public interface Recipe extends ResourceKeyed { +public interface Recipe { /** * Checks if the given inventory fits the required constraints to make a valid recipe