diff --git a/src/main/java/com/minelittlepony/unicopia/advancement/CustomEventCriterion.java b/src/main/java/com/minelittlepony/unicopia/advancement/CustomEventCriterion.java index 06bdc04c..13fe240d 100644 --- a/src/main/java/com/minelittlepony/unicopia/advancement/CustomEventCriterion.java +++ b/src/main/java/com/minelittlepony/unicopia/advancement/CustomEventCriterion.java @@ -1,6 +1,12 @@ package com.minelittlepony.unicopia.advancement; +import java.util.HashSet; +import java.util.Set; + +import com.google.gson.JsonArray; import com.google.gson.JsonObject; +import com.minelittlepony.unicopia.Race; +import com.minelittlepony.unicopia.entity.player.Pony; import net.minecraft.advancement.criterion.AbstractCriterion; import net.minecraft.advancement.criterion.AbstractCriterionConditions; @@ -22,14 +28,26 @@ public class CustomEventCriterion extends AbstractCriterion races = new HashSet<>(); + if (json.has("race")) { + json.get("race").getAsJsonArray().forEach(el -> { + races.add(Race.fromName(el.getAsString())); + }); + } + + return new Conditions( + playerPredicate, + JsonHelper.getString(json, "event"), + races + ); } public CustomEventCriterion.Trigger createTrigger(String name) { return player -> { if (player instanceof ServerPlayerEntity) { - test((ServerPlayerEntity)player, c -> c.test(name)); + test((ServerPlayerEntity)player, c -> c.test(name, (ServerPlayerEntity)player)); } }; } @@ -41,19 +59,27 @@ public class CustomEventCriterion extends AbstractCriterion races; + + public Conditions(Extended playerPredicate, String event, Set races) { super(ID, playerPredicate); this.event = event; + this.races = races; } - public boolean test(String event) { - return this.event.equalsIgnoreCase(event); + public boolean test(String event, ServerPlayerEntity player) { + return this.event.equalsIgnoreCase(event) && (races.isEmpty() || races.contains(Pony.of(player).getSpecies())); } @Override public JsonObject toJson(AdvancementEntityPredicateSerializer serializer) { JsonObject json = super.toJson(serializer); json.addProperty("event", event); + if (!races.isEmpty()) { + JsonArray arr = new JsonArray(); + races.forEach(r -> arr.add(r.name().toLowerCase())); + json.add("race", arr); + } return json; } } diff --git a/src/main/java/com/minelittlepony/unicopia/advancement/UCriteria.java b/src/main/java/com/minelittlepony/unicopia/advancement/UCriteria.java index 968d9c86..4271e618 100644 --- a/src/main/java/com/minelittlepony/unicopia/advancement/UCriteria.java +++ b/src/main/java/com/minelittlepony/unicopia/advancement/UCriteria.java @@ -9,6 +9,9 @@ public interface UCriteria { CustomEventCriterion.Trigger LOOK_INTO_SUN = CUSTOM_EVENT.createTrigger("look_into_sun"); CustomEventCriterion.Trigger WEAR_SHADES = CUSTOM_EVENT.createTrigger("wear_shades"); + CustomEventCriterion.Trigger LIGHTNING_STRUCK = CUSTOM_EVENT.createTrigger("lightning_struck_player"); + CustomEventCriterion.Trigger EAT_TRICK_APPLE = CUSTOM_EVENT.createTrigger("eat_trick_apple"); + CustomEventCriterion.Trigger FEED_TRICK_APPLE = CUSTOM_EVENT.createTrigger("feed_trick_apple"); private static > T register(T obj) { return MixinCriteria.register(obj); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java index b75be8df..84d76149 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java @@ -5,6 +5,7 @@ import com.minelittlepony.unicopia.InteractionManager; import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.ability.magic.spell.SpellType; +import com.minelittlepony.unicopia.advancement.UCriteria; import com.minelittlepony.unicopia.entity.Creature; import com.minelittlepony.unicopia.entity.EntityPhysics; import com.minelittlepony.unicopia.entity.Jumper; @@ -525,6 +526,7 @@ public class PlayerPhysics extends EntityPhysics implements Tickab lightning.refreshPositionAfterTeleport(entity.getX(), entity.getY(), entity.getZ()); entity.world.spawnEntity(lightning); + UCriteria.LIGHTNING_STRUCK.trigger(entity); } } diff --git a/src/main/java/com/minelittlepony/unicopia/item/ZapAppleItem.java b/src/main/java/com/minelittlepony/unicopia/item/ZapAppleItem.java index 45637102..c28c92ba 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/ZapAppleItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/ZapAppleItem.java @@ -4,6 +4,7 @@ package com.minelittlepony.unicopia.item; import java.util.Optional; import com.minelittlepony.unicopia.UTags; +import com.minelittlepony.unicopia.advancement.UCriteria; import com.minelittlepony.unicopia.item.toxin.Toxicity; import com.minelittlepony.unicopia.util.MagicalDamageSource; import com.minelittlepony.unicopia.util.RayTraceHelper; @@ -18,6 +19,7 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; import net.minecraft.predicate.entity.EntityPredicates; +import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; import net.minecraft.text.Text; import net.minecraft.util.ActionResult; @@ -58,6 +60,9 @@ public class ZapAppleItem extends AppleItem implements ChameleonItem { lightning.refreshPositionAfterTeleport(player.getX(), player.getY(), player.getZ()); w.spawnEntity(lightning); + if (player instanceof PlayerEntity) { + UCriteria.EAT_TRICK_APPLE.trigger((PlayerEntity)player); + } } return stack; @@ -72,11 +77,17 @@ public class ZapAppleItem extends AppleItem implements ChameleonItem { public TypedActionResult onFedTo(ItemStack stack, PlayerEntity player, Entity e) { LightningEntity lightning = EntityType.LIGHTNING_BOLT.create(e.world); - lightning.refreshPositionAfterTeleport(player.getX(), player.getY(), player.getZ()); + lightning.refreshPositionAfterTeleport(e.getX(), e.getY(), e.getZ()); + lightning.setCosmetic(true); + if (player instanceof ServerPlayerEntity) { + lightning.setChanneler((ServerPlayerEntity)player); + } if (e.world instanceof ServerWorld) { e.onStruckByLightning((ServerWorld)e.world, lightning); + UCriteria.FEED_TRICK_APPLE.trigger(player); } + player.world.spawnEntity(lightning); if (!player.getAbilities().creativeMode) { stack.decrement(1); diff --git a/src/main/resources/assets/unicopia/lang/en_us.json b/src/main/resources/assets/unicopia/lang/en_us.json index ee724e07..efa37cf3 100644 --- a/src/main/resources/assets/unicopia/lang/en_us.json +++ b/src/main/resources/assets/unicopia/lang/en_us.json @@ -388,5 +388,27 @@ "advancements.unicopia.praise_the_sun.title": "Praise the Sun!", "advancements.unicopia.praise_the_sun.description": "Experience Celestia's unbridled glory", "advancements.unicopia.cool_potato.title": "Cool Potato", - "advancements.unicopia.cool_potato.description": "Protect your eyes from the sun" + "advancements.unicopia.cool_potato.description": "Protect your eyes from the sun", + "advancements.unicopia.mid_flight_interruption.title": "Mid-Flight Interruption", + "advancements.unicopia.mid_flight_interruption.description": "Get struck by lightning whilst flying in a storm", + "advancements.unicopia.lightning_bug.title": "Lightning Bug", + "advancements.unicopia.lightning_bug.description": "Attract 10 lightning strikes", + "advancements.unicopia.jar.title": "Oh wow. What's this?", + "advancements.unicopia.jar.description": "Find an empty jar", + "advancements.unicopia.gotcha.title": "Got'cha!", + "advancements.unicopia.gotcha.description": "Capture a storm", + "advancements.unicopia.trick_apple.title": "Apple of Discord", + "advancements.unicopia.trick_apple.description": "Find your first zap apple", + "advancements.unicopia.feed_trick_apple.title": "Here, Try This", + "advancements.unicopia.feed_trick_apple.description": "Feed a zap apple to a mob", + "advancements.unicopia.eat_trick_apple.title": "Crunchy", + "advancements.unicopia.eat_trick_apple.description": "Bite into a zap apple", + "advancements.unicopia.burn_juice.title": "That doesn't seem right", + "advancements.unicopia.burn_juice.description": "Burn the juice", + "advancements.unicopia.apple_route.title": "Apple, Apple, Apple", + "advancements.unicopia.apple_route.description": "Start your journey towards the apple of legend", + "advancements.unicopia.juice.title": "Refreshing", + "advancements.unicopia.juice.description": "Finally a use for all these apples", + "advancements.unicopia.sweet_apple_acres.title": "Sweet Apple Acres", + "advancements.unicopia.sweet_apple_acres.description": "Obtain one of every apple" } diff --git a/src/main/resources/data/unicopia/advancements/unicopia/apple_route.json b/src/main/resources/data/unicopia/advancements/unicopia/apple_route.json new file mode 100644 index 00000000..3867fd42 --- /dev/null +++ b/src/main/resources/data/unicopia/advancements/unicopia/apple_route.json @@ -0,0 +1,31 @@ +{ + "parent": "unicopia:unicopia/root", + "display": { + "icon": { + "item": "unicopia:green_apple" + }, + "title": { + "translate": "advancements.unicopia.apple_route.title" + }, + "description": { + "translate": "advancements.unicopia.apple_route.description" + }, + "frame": "task", + "show_toast": true, + "announce_to_chat": false, + "hidden": true + }, + "criteria": { + "has_apple": { + "trigger": "minecraft:inventory_changed", + "conditions": { + "items": [ + { "tag": "unicopia:apples" } + ] + } + } + }, + "requirements": [ + [ "has_apple" ] + ] +} diff --git a/src/main/resources/data/unicopia/advancements/unicopia/burn_juice.json b/src/main/resources/data/unicopia/advancements/unicopia/burn_juice.json new file mode 100644 index 00000000..3382e4fb --- /dev/null +++ b/src/main/resources/data/unicopia/advancements/unicopia/burn_juice.json @@ -0,0 +1,31 @@ +{ + "parent": "unicopia:unicopia/juice", + "display": { + "icon": { + "item": "unicopia:burned_juice" + }, + "title": { + "translate": "advancements.unicopia.burn_juice.title" + }, + "description": { + "translate": "advancements.unicopia.burn_juice.description" + }, + "frame": "task", + "show_toast": true, + "announce_to_chat": true, + "hidden": true + }, + "criteria": { + "has_burned_juice": { + "trigger": "minecraft:inventory_changed", + "conditions": { + "items": [ + { "item": "unicopia:burned_juice" } + ] + } + } + }, + "requirements": [ + [ "has_burned_juice" ] + ] +} diff --git a/src/main/resources/data/unicopia/advancements/unicopia/eat_trick_apple.json b/src/main/resources/data/unicopia/advancements/unicopia/eat_trick_apple.json new file mode 100644 index 00000000..98a60749 --- /dev/null +++ b/src/main/resources/data/unicopia/advancements/unicopia/eat_trick_apple.json @@ -0,0 +1,29 @@ +{ + "parent": "unicopia:unicopia/trick_apple", + "display": { + "icon": { + "item": "unicopia:zap_apple" + }, + "title": { + "translate": "advancements.unicopia.eat_trick_apple.title" + }, + "description": { + "translate": "advancements.unicopia.eat_trick_apple.description" + }, + "frame": "task", + "show_toast": true, + "announce_to_chat": true, + "hidden": false + }, + "criteria": { + "eat_trick_apple": { + "trigger": "unicopia:custom", + "conditions": { + "event": "eat_trick_apple" + } + } + }, + "requirements": [ + [ "eat_trick_apple" ] + ] +} diff --git a/src/main/resources/data/unicopia/advancements/unicopia/feed_trick_apple.json b/src/main/resources/data/unicopia/advancements/unicopia/feed_trick_apple.json new file mode 100644 index 00000000..20d98e4e --- /dev/null +++ b/src/main/resources/data/unicopia/advancements/unicopia/feed_trick_apple.json @@ -0,0 +1,29 @@ +{ + "parent": "unicopia:unicopia/trick_apple", + "display": { + "icon": { + "item": "unicopia:zap_apple" + }, + "title": { + "translate": "advancements.unicopia.feed_trick_apple.title" + }, + "description": { + "translate": "advancements.unicopia.feed_trick_apple.description" + }, + "frame": "task", + "show_toast": true, + "announce_to_chat": true, + "hidden": false + }, + "criteria": { + "eat_trick_apple": { + "trigger": "unicopia:custom", + "conditions": { + "event": "feed_trick_apple" + } + } + }, + "requirements": [ + [ "eat_trick_apple" ] + ] +} diff --git a/src/main/resources/data/unicopia/advancements/unicopia/gotcha.json b/src/main/resources/data/unicopia/advancements/unicopia/gotcha.json new file mode 100644 index 00000000..4811b5cc --- /dev/null +++ b/src/main/resources/data/unicopia/advancements/unicopia/gotcha.json @@ -0,0 +1,32 @@ +{ + "parent": "unicopia:unicopia/jar", + "display": { + "icon": { + "item": "unicopia:rain_cloud_jar" + }, + "title": { + "translate": "advancements.unicopia.gotcha.title" + }, + "description": { + "translate": "advancements.unicopia.gotcha.description" + }, + "frame": "goal", + "show_toast": true, + "announce_to_chat": true, + "hidden": false + }, + "criteria": { + "has_the_jar": { + "trigger": "minecraft:inventory_changed", + "conditions": { + "items": [ + { "item": "unicopia:rain_cloud_jar" }, + { "item": "unicopia:storm_cloud_jar" } + ] + } + } + }, + "requirements": [ + [ "has_the_jar" ] + ] +} diff --git a/src/main/resources/data/unicopia/advancements/unicopia/jar.json b/src/main/resources/data/unicopia/advancements/unicopia/jar.json new file mode 100644 index 00000000..f0b65ca4 --- /dev/null +++ b/src/main/resources/data/unicopia/advancements/unicopia/jar.json @@ -0,0 +1,31 @@ +{ + "parent": "unicopia:unicopia/root", + "display": { + "icon": { + "item": "unicopia:empty_jar" + }, + "title": { + "translate": "advancements.unicopia.jar.title" + }, + "description": { + "translate": "advancements.unicopia.jar.description" + }, + "frame": "task", + "show_toast": true, + "announce_to_chat": true, + "hidden": false + }, + "criteria": { + "has_the_jar": { + "trigger": "minecraft:inventory_changed", + "conditions": { + "items": [ + { "item": "unicopia:empty_jar" } + ] + } + } + }, + "requirements": [ + [ "has_the_jar" ] + ] +} diff --git a/src/main/resources/data/unicopia/advancements/unicopia/juice.json b/src/main/resources/data/unicopia/advancements/unicopia/juice.json new file mode 100644 index 00000000..f77b7bbf --- /dev/null +++ b/src/main/resources/data/unicopia/advancements/unicopia/juice.json @@ -0,0 +1,31 @@ +{ + "parent": "unicopia:unicopia/apple_route", + "display": { + "icon": { + "item": "unicopia:juice" + }, + "title": { + "translate": "advancements.unicopia.juice.title" + }, + "description": { + "translate": "advancements.unicopia.juice.description" + }, + "frame": "task", + "show_toast": true, + "announce_to_chat": true, + "hidden": false + }, + "criteria": { + "has_juice": { + "trigger": "minecraft:inventory_changed", + "conditions": { + "items": [ + { "item": "unicopia:juice" } + ] + } + } + }, + "requirements": [ + [ "has_juice" ] + ] +} diff --git a/src/main/resources/data/unicopia/advancements/unicopia/lightning_bug.json b/src/main/resources/data/unicopia/advancements/unicopia/lightning_bug.json new file mode 100644 index 00000000..4a67de15 --- /dev/null +++ b/src/main/resources/data/unicopia/advancements/unicopia/lightning_bug.json @@ -0,0 +1,102 @@ +{ + "parent": "unicopia:unicopia/mid_flight_interruption", + "display": { + "icon": { + "item": "unicopia:lightning_jar" + }, + "title": { + "translate": "advancements.unicopia.lightning_bug.title" + }, + "description": { + "translate": "advancements.unicopia.lightning_bug.description" + }, + "frame": "challenge", + "show_toast": true, + "announce_to_chat": true, + "hidden": false + }, + "criteria": { + "one": { + "trigger": "unicopia:custom", + "conditions": { + "event": "lightning_struck_player", + "race": ["bat"] + } + }, + "two": { + "trigger": "unicopia:custom", + "conditions": { + "event": "lightning_struck_player", + "race": ["bat"] + } + }, + "three": { + "trigger": "unicopia:custom", + "conditions": { + "event": "lightning_struck_player", + "race": ["bat"] + } + }, + "four": { + "trigger": "unicopia:custom", + "conditions": { + "event": "lightning_struck_player", + "race": ["bat"] + } + }, + "five": { + "trigger": "unicopia:custom", + "conditions": { + "event": "lightning_struck_player", + "race": ["bat"] + } + }, + "six": { + "trigger": "unicopia:custom", + "conditions": { + "event": "lightning_struck_player", + "race": ["bat"] + } + }, + "seven": { + "trigger": "unicopia:custom", + "conditions": { + "event": "lightning_struck_player", + "race": ["bat"] + } + }, + "eight": { + "trigger": "unicopia:custom", + "conditions": { + "event": "lightning_struck_player", + "race": ["bat"] + } + }, + "nine": { + "trigger": "unicopia:custom", + "conditions": { + "event": "lightning_struck_player", + "race": ["bat"] + } + }, + "ten": { + "trigger": "unicopia:custom", + "conditions": { + "event": "lightning_struck_player", + "race": ["bat"] + } + } + }, + "requirements": [ + [ "one" ], + [ "two" ], + [ "three" ], + [ "four" ], + [ "five" ], + [ "six" ], + [ "seven" ], + [ "eight" ], + [ "nine" ], + [ "ten" ] + ] +} diff --git a/src/main/resources/data/unicopia/advancements/unicopia/mid_flight_interruption.json b/src/main/resources/data/unicopia/advancements/unicopia/mid_flight_interruption.json new file mode 100644 index 00000000..c1d8774d --- /dev/null +++ b/src/main/resources/data/unicopia/advancements/unicopia/mid_flight_interruption.json @@ -0,0 +1,29 @@ +{ + "parent": "unicopia:unicopia/root", + "display": { + "icon": { + "item": "unicopia:pegasus_feather" + }, + "title": { + "translate": "advancements.unicopia.mid_flight_interruption.title" + }, + "description": { + "translate": "advancements.unicopia.mid_flight_interruption.description" + }, + "frame": "challenge", + "show_toast": true, + "announce_to_chat": true, + "hidden": false + }, + "criteria": { + "lightning_strike": { + "trigger": "unicopia:custom", + "conditions": { + "event": "lightning_struck_player" + } + } + }, + "requirements": [ + [ "lightning_strike" ] + ] +} diff --git a/src/main/resources/data/unicopia/advancements/unicopia/sweet_apple_acres.json b/src/main/resources/data/unicopia/advancements/unicopia/sweet_apple_acres.json new file mode 100644 index 00000000..be944480 --- /dev/null +++ b/src/main/resources/data/unicopia/advancements/unicopia/sweet_apple_acres.json @@ -0,0 +1,94 @@ +{ + "parent": "unicopia:unicopia/apple_route", + "display": { + "icon": { + "item": "unicopia:sweet_apple" + }, + "title": { + "translate": "advancements.unicopia.sweet_apple_acres.title" + }, + "description": { + "translate": "advancements.unicopia.sweet_apple_acres.description" + }, + "frame": "challenge", + "show_toast": true, + "announce_to_chat": true, + "hidden": true + }, + "criteria": { + "red_apple": { + "trigger": "minecraft:inventory_changed", + "conditions": { + "items": [ + { "item": "minecraft:apple" } + ] + } + }, + "green_apple": { + "trigger": "minecraft:inventory_changed", + "conditions": { + "items": [ + { "item": "unicopia:green_apple" } + ] + } + }, + "sweet_apple": { + "trigger": "minecraft:inventory_changed", + "conditions": { + "items": [ + { "item": "unicopia:sweet_apple" } + ] + } + }, + "sour_apple": { + "trigger": "minecraft:inventory_changed", + "conditions": { + "items": [ + { "item": "unicopia:sour_apple" } + ] + } + }, + "rotten_apple": { + "trigger": "minecraft:inventory_changed", + "conditions": { + "items": [ + { "item": "unicopia:rotten_apple" } + ] + } + }, + "zap_apple": { + "trigger": "minecraft:inventory_changed", + "conditions": { + "items": [ + { "item": "unicopia:zap_apple" } + ] + } + }, + "cooked_zap_apple": { + "trigger": "minecraft:inventory_changed", + "conditions": { + "items": [ + { "item": "unicopia:cooked_zap_apple" } + ] + } + }, + "golden_apple": { + "trigger": "minecraft:inventory_changed", + "conditions": { + "items": [ + { "item": "unicopia:golden_apple" } + ] + } + } + }, + "requirements": [ + [ "red_apple" ], + [ "green_apple" ], + [ "sweet_apple" ], + [ "sour_apple" ], + [ "rotten_apple" ], + [ "zap_apple" ], + [ "cooked_zap_apple" ], + [ "golden_apple" ] + ] +} diff --git a/src/main/resources/data/unicopia/advancements/unicopia/trick_apple.json b/src/main/resources/data/unicopia/advancements/unicopia/trick_apple.json new file mode 100644 index 00000000..91b8199d --- /dev/null +++ b/src/main/resources/data/unicopia/advancements/unicopia/trick_apple.json @@ -0,0 +1,31 @@ +{ + "parent": "unicopia:unicopia/apple_route", + "display": { + "icon": { + "item": "minecraft:enchanted_golden_apple" + }, + "title": { + "translate": "advancements.unicopia.trick_apple.title" + }, + "description": { + "translate": "advancements.unicopia.trick_apple.description" + }, + "frame": "task", + "show_toast": true, + "announce_to_chat": false, + "hidden": false + }, + "criteria": { + "has_apple": { + "trigger": "minecraft:inventory_changed", + "conditions": { + "items": [ + { "item": "unicopia:zap_apple" } + ] + } + } + }, + "requirements": [ + [ "has_apple" ] + ] +}