From d94626e0945e30876b4acd491096eaf47a12dd09 Mon Sep 17 00:00:00 2001 From: Sollace Date: Fri, 1 Apr 2022 00:40:39 +0200 Subject: [PATCH] Added advancements and recipes for crafting muffins --- .../advancement/CustomEventCriterion.java | 11 +++--- .../unicopia/advancement/UCriteria.java | 1 + .../unicopia/item/HeavyProjectileItem.java | 4 +- .../unicopia/item/MuffinItem.java | 6 ++- .../resources/assets/unicopia/lang/en_us.json | 2 + .../advancements/recipes/food/muffin.json | 38 +++++++++++++++++++ .../advancements/unicopia/baked_bads.json | 31 +++++++++++++++ .../data/unicopia/recipes/muffin.json | 14 +++++++ 8 files changed, 100 insertions(+), 7 deletions(-) create mode 100644 src/main/resources/data/unicopia/advancements/recipes/food/muffin.json create mode 100644 src/main/resources/data/unicopia/advancements/unicopia/baked_bads.json create mode 100644 src/main/resources/data/unicopia/recipes/muffin.json diff --git a/src/main/java/com/minelittlepony/unicopia/advancement/CustomEventCriterion.java b/src/main/java/com/minelittlepony/unicopia/advancement/CustomEventCriterion.java index 87fe6db3..afbb7e40 100644 --- a/src/main/java/com/minelittlepony/unicopia/advancement/CustomEventCriterion.java +++ b/src/main/java/com/minelittlepony/unicopia/advancement/CustomEventCriterion.java @@ -3,6 +3,8 @@ package com.minelittlepony.unicopia.advancement; import java.util.HashSet; import java.util.Set; +import org.jetbrains.annotations.Nullable; + import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.minelittlepony.unicopia.Race; @@ -31,6 +33,7 @@ public class CustomEventCriterion extends AbstractCriterion races = new HashSet<>(); + if (json.has("race")) { json.get("race").getAsJsonArray().forEach(el -> { races.add(Race.fromName(el.getAsString())); @@ -48,18 +51,16 @@ public class CustomEventCriterion extends AbstractCriterion { - - if (player instanceof ServerPlayerEntity) { - ServerPlayerEntity p = (ServerPlayerEntity)player; + if (player instanceof ServerPlayerEntity p) { int counter = Pony.of(player).getAdvancementProgress().compute(name, (key, i) -> i == null ? 1 : i + 1); - trigger((ServerPlayerEntity)player, c -> c.test(name, counter, p)); + trigger(p, c -> c.test(name, counter, p)); } }; } public interface Trigger { - void trigger(PlayerEntity player); + void trigger(@Nullable PlayerEntity player); } public static class Conditions extends AbstractCriterionConditions { diff --git a/src/main/java/com/minelittlepony/unicopia/advancement/UCriteria.java b/src/main/java/com/minelittlepony/unicopia/advancement/UCriteria.java index 0959f761..47aeffce 100644 --- a/src/main/java/com/minelittlepony/unicopia/advancement/UCriteria.java +++ b/src/main/java/com/minelittlepony/unicopia/advancement/UCriteria.java @@ -16,6 +16,7 @@ public interface UCriteria { CustomEventCriterion.Trigger SCREECH_SELF = CUSTOM_EVENT.createTrigger("screech_self"); CustomEventCriterion.Trigger SCREECH_TWENTY_MOBS = CUSTOM_EVENT.createTrigger("screech_twenty_mobs"); CustomEventCriterion.Trigger SHED_FEATHER = CUSTOM_EVENT.createTrigger("shed_feather"); + CustomEventCriterion.Trigger THROW_MUFFIN = CUSTOM_EVENT.createTrigger("throw_muffin"); private static > T register(T obj) { return MixinCriteria.register(obj); diff --git a/src/main/java/com/minelittlepony/unicopia/item/HeavyProjectileItem.java b/src/main/java/com/minelittlepony/unicopia/item/HeavyProjectileItem.java index ef749972..b5d7a75d 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/HeavyProjectileItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/HeavyProjectileItem.java @@ -1,5 +1,7 @@ package com.minelittlepony.unicopia.item; +import org.jetbrains.annotations.Nullable; + import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.UTags; import com.minelittlepony.unicopia.entity.PhysicsBodyProjectileEntity; @@ -33,7 +35,7 @@ public class HeavyProjectileItem extends ProjectileItem { } @Override - protected PhysicsBodyProjectileEntity createProjectile(ItemStack stack, World world, PlayerEntity player) { + protected PhysicsBodyProjectileEntity createProjectile(ItemStack stack, World world, @Nullable PlayerEntity player) { PhysicsBodyProjectileEntity projectile = player == null ? new PhysicsBodyProjectileEntity(world) : new PhysicsBodyProjectileEntity(world, player); if (player != null) { projectile.setVelocity(player, player.getPitch(), player.getYaw(), 0, 1.5F, 1); diff --git a/src/main/java/com/minelittlepony/unicopia/item/MuffinItem.java b/src/main/java/com/minelittlepony/unicopia/item/MuffinItem.java index 1fa08900..c7557aba 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/MuffinItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/MuffinItem.java @@ -1,5 +1,8 @@ package com.minelittlepony.unicopia.item; +import org.jetbrains.annotations.Nullable; + +import com.minelittlepony.unicopia.advancement.UCriteria; import com.minelittlepony.unicopia.entity.PhysicsBodyProjectileEntity; import net.minecraft.entity.player.PlayerEntity; @@ -13,10 +16,11 @@ public class MuffinItem extends HeavyProjectileItem { } @Override - protected PhysicsBodyProjectileEntity createProjectile(ItemStack stack, World world, PlayerEntity player) { + protected PhysicsBodyProjectileEntity createProjectile(ItemStack stack, World world, @Nullable PlayerEntity player) { PhysicsBodyProjectileEntity projectile = super.createProjectile(stack, world, player); projectile.setBouncy(); projectile.setDamage(0); + UCriteria.THROW_MUFFIN.trigger(player); return projectile; } } diff --git a/src/main/resources/assets/unicopia/lang/en_us.json b/src/main/resources/assets/unicopia/lang/en_us.json index fdef1163..72ad489b 100644 --- a/src/main/resources/assets/unicopia/lang/en_us.json +++ b/src/main/resources/assets/unicopia/lang/en_us.json @@ -489,6 +489,8 @@ "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.baked_bads.title": "Baked Bads", + "advancements.unicopia.baked_bads.description": "Bake a delicious muffin", "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", diff --git a/src/main/resources/data/unicopia/advancements/recipes/food/muffin.json b/src/main/resources/data/unicopia/advancements/recipes/food/muffin.json new file mode 100644 index 00000000..12fc8008 --- /dev/null +++ b/src/main/resources/data/unicopia/advancements/recipes/food/muffin.json @@ -0,0 +1,38 @@ +{ + "parent": "minecraft:recipes/root", + "rewards": { + "recipes": [ + "unicopia:muffin" + ] + }, + "criteria": { + "has_ingredients": { + "trigger": "minecraft:inventory_changed", + "conditions": { + "items": [ + { + "items": [ + "minecraft:sugar", + "minecraft:egg", + "minecraft:potato", + "unicopia:juice", + "unicopia:wheat_worms" + ] + } + ] + } + }, + "has_the_recipe": { + "trigger": "minecraft:recipe_unlocked", + "conditions": { + "recipe": "unicopia:muffin" + } + } + }, + "requirements": [ + [ + "has_ingredients", + "has_the_recipe" + ] + ] +} \ No newline at end of file diff --git a/src/main/resources/data/unicopia/advancements/unicopia/baked_bads.json b/src/main/resources/data/unicopia/advancements/unicopia/baked_bads.json new file mode 100644 index 00000000..5de87f15 --- /dev/null +++ b/src/main/resources/data/unicopia/advancements/unicopia/baked_bads.json @@ -0,0 +1,31 @@ +{ + "parent": "unicopia:unicopia/root", + "display": { + "icon": { + "item": "unicopia:muffin" + }, + "title": { + "translate": "advancements.unicopia.baked_bads.title" + }, + "description": { + "translate": "advancements.unicopia.baked_bads.description" + }, + "frame": "task", + "show_toast": true, + "announce_to_chat": true, + "hidden": true + }, + "criteria": { + "throw_muffin": { + "trigger": "minecraft:inventory_changed", + "conditions": { + "items": [ + { "items": [ "unicopia:muffin" ] } + ] + } + } + }, + "requirements": [ + [ "throw_muffin" ] + ] +} diff --git a/src/main/resources/data/unicopia/recipes/muffin.json b/src/main/resources/data/unicopia/recipes/muffin.json new file mode 100644 index 00000000..f78266a5 --- /dev/null +++ b/src/main/resources/data/unicopia/recipes/muffin.json @@ -0,0 +1,14 @@ +{ + "type": "minecraft:crafting_shapeless", + "ingredients": [ + { "item": "minecraft:sugar" }, + { "item": "minecraft:egg" }, + { "item": "minecraft:potato" }, + { "item": "unicopia:juice" }, + { "item": "unicopia:wheat_worms" } + ], + "result": { + "item": "unicopia:muffin", + "count": 12 + } +}