Skip to content

Commit

Permalink
BoughtFromTradingStationCriterion: Fix regression
Browse files Browse the repository at this point in the history
The "item" property in the JSON format was accidentally
made required in the 1.20.2 update.
  • Loading branch information
Juuxel committed Oct 8, 2023
1 parent e1cd4cd commit 707a5c3
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package juuxel.adorn.criterion

import com.google.gson.JsonNull
import com.google.gson.JsonObject
import com.google.gson.JsonParseException
import net.minecraft.advancement.criterion.AbstractCriterion
import net.minecraft.advancement.criterion.AbstractCriterionConditions
import net.minecraft.item.ItemStack
Expand All @@ -18,23 +18,21 @@ class BoughtFromTradingStationCriterion : AbstractCriterion<BoughtFromTradingSta
predicateDeserializer: AdvancementEntityPredicateDeserializer
): Conditions = Conditions(
playerPredicate,
ItemPredicate.fromJson(json["item"]).orElseThrow {
JsonParseException("Missing item in bought_from_trading_station criterion")
}
ItemPredicate.fromJson(json["item"]).orElse(null)
)

fun trigger(player: ServerPlayerEntity, soldItem: ItemStack) {
trigger(player) { it.matches(soldItem) }
}

class Conditions(playerPredicate: Optional<LootContextPredicate>, private val soldItem: ItemPredicate) :
class Conditions(playerPredicate: Optional<LootContextPredicate>, private val soldItem: ItemPredicate?) :
AbstractCriterionConditions(playerPredicate) {
fun matches(stack: ItemStack): Boolean =
soldItem.test(stack)
soldItem == null || soldItem.test(stack)

override fun toJson(): JsonObject {
val json = super.toJson()
json.add("sold_item", soldItem.toJson())
json.add("sold_item", soldItem?.toJson() ?: JsonNull.INSTANCE)
return json
}
}
Expand Down

0 comments on commit 707a5c3

Please sign in to comment.