From 40ac0dfb00e24a4759572527328adb5628bb6aea Mon Sep 17 00:00:00 2001 From: Sollace Date: Mon, 9 Aug 2021 15:20:33 +0200 Subject: [PATCH] Added some advancements for bat ponies --- .../com/minelittlepony/unicopia/UTags.java | 2 +- .../com/minelittlepony/unicopia/Unicopia.java | 2 + .../advancement/CustomEventCriterion.java | 60 +++++++++++++++++++ .../unicopia/advancement/UCriteria.java | 18 ++++++ .../unicopia/entity/player/Pony.java | 11 ++++ .../unicopia/mixin/MixinCriteria.java | 15 +++++ .../resources/assets/unicopia/lang/en_us.json | 9 ++- .../advancements/unicopia/cool_potato.json | 29 +++++++++ .../advancements/unicopia/praise_the_sun.json | 29 +++++++++ .../unicopia/advancements/unicopia/root.json | 31 ++++++++++ src/main/resources/unicopia.mixin.json | 1 + 11 files changed, 205 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/minelittlepony/unicopia/advancement/CustomEventCriterion.java create mode 100644 src/main/java/com/minelittlepony/unicopia/advancement/UCriteria.java create mode 100644 src/main/java/com/minelittlepony/unicopia/mixin/MixinCriteria.java create mode 100644 src/main/resources/data/unicopia/advancements/unicopia/cool_potato.json create mode 100644 src/main/resources/data/unicopia/advancements/unicopia/praise_the_sun.json create mode 100644 src/main/resources/data/unicopia/advancements/unicopia/root.json diff --git a/src/main/java/com/minelittlepony/unicopia/UTags.java b/src/main/java/com/minelittlepony/unicopia/UTags.java index d6e838db..a193770b 100644 --- a/src/main/java/com/minelittlepony/unicopia/UTags.java +++ b/src/main/java/com/minelittlepony/unicopia/UTags.java @@ -16,7 +16,7 @@ public interface UTags { Tag MAGIC_FEATHERS = item("magic_feathers"); - Tag SHADES = item("sun_blockers"); + Tag SHADES = item("shades"); Tag FRAGILE = block("fragile"); Tag INTERESTING = block("interesting"); diff --git a/src/main/java/com/minelittlepony/unicopia/Unicopia.java b/src/main/java/com/minelittlepony/unicopia/Unicopia.java index cb18b016..bf685958 100644 --- a/src/main/java/com/minelittlepony/unicopia/Unicopia.java +++ b/src/main/java/com/minelittlepony/unicopia/Unicopia.java @@ -10,6 +10,7 @@ import java.util.Optional; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import com.minelittlepony.unicopia.advancement.UCriteria; import com.minelittlepony.unicopia.command.Commands; import com.minelittlepony.unicopia.entity.effect.UPotions; import com.minelittlepony.unicopia.entity.player.Pony; @@ -40,6 +41,7 @@ public class Unicopia implements ModInitializer { public void onInitialize() { Channel.bootstrap(); UTags.bootstrap(); + UCriteria.bootstrap(); Commands.bootstrap(); ServerTickEvents.END_WORLD_TICK.register(w -> { diff --git a/src/main/java/com/minelittlepony/unicopia/advancement/CustomEventCriterion.java b/src/main/java/com/minelittlepony/unicopia/advancement/CustomEventCriterion.java new file mode 100644 index 00000000..06bdc04c --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/advancement/CustomEventCriterion.java @@ -0,0 +1,60 @@ +package com.minelittlepony.unicopia.advancement; + +import com.google.gson.JsonObject; + +import net.minecraft.advancement.criterion.AbstractCriterion; +import net.minecraft.advancement.criterion.AbstractCriterionConditions; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer; +import net.minecraft.predicate.entity.AdvancementEntityPredicateSerializer; +import net.minecraft.predicate.entity.EntityPredicate.Extended; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.Identifier; +import net.minecraft.util.JsonHelper; + +public class CustomEventCriterion extends AbstractCriterion { + + private static final Identifier ID = new Identifier("unicopia", "custom"); + + @Override + public Identifier getId() { + return ID; + } + + @Override + protected Conditions conditionsFromJson(JsonObject json, Extended player, AdvancementEntityPredicateDeserializer deserializer) { + return new Conditions(player, JsonHelper.getString(json, "event")); + } + + public CustomEventCriterion.Trigger createTrigger(String name) { + return player -> { + if (player instanceof ServerPlayerEntity) { + test((ServerPlayerEntity)player, c -> c.test(name)); + } + }; + } + + public interface Trigger { + void trigger(PlayerEntity player); + } + + public static class Conditions extends AbstractCriterionConditions { + private final String event; + + public Conditions(Extended playerPredicate, String event) { + super(ID, playerPredicate); + this.event = event; + } + + public boolean test(String event) { + return this.event.equalsIgnoreCase(event); + } + + @Override + public JsonObject toJson(AdvancementEntityPredicateSerializer serializer) { + JsonObject json = super.toJson(serializer); + json.addProperty("event", event); + return json; + } + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/advancement/UCriteria.java b/src/main/java/com/minelittlepony/unicopia/advancement/UCriteria.java new file mode 100644 index 00000000..968d9c86 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/advancement/UCriteria.java @@ -0,0 +1,18 @@ +package com.minelittlepony.unicopia.advancement; + +import com.minelittlepony.unicopia.mixin.MixinCriteria; + +import net.minecraft.advancement.criterion.Criterion; + +public interface UCriteria { + CustomEventCriterion CUSTOM_EVENT = register(new CustomEventCriterion()); + + CustomEventCriterion.Trigger LOOK_INTO_SUN = CUSTOM_EVENT.createTrigger("look_into_sun"); + CustomEventCriterion.Trigger WEAR_SHADES = CUSTOM_EVENT.createTrigger("wear_shades"); + + private static > T register(T obj) { + return MixinCriteria.register(obj); + } + + static void bootstrap() { } +} diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java index 6d44a6a2..30bcdf34 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java @@ -13,10 +13,12 @@ import com.minelittlepony.unicopia.client.sound.LoopingSoundInstance; import com.minelittlepony.unicopia.InteractionManager; import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.USounds; +import com.minelittlepony.unicopia.UTags; import com.minelittlepony.unicopia.WorldTribeManager; import com.minelittlepony.unicopia.ability.AbilityDispatcher; import com.minelittlepony.unicopia.ability.magic.Spell; import com.minelittlepony.unicopia.ability.magic.spell.SpellType; +import com.minelittlepony.unicopia.advancement.UCriteria; import com.minelittlepony.unicopia.entity.Physics; import com.minelittlepony.unicopia.entity.PonyContainer; import com.minelittlepony.unicopia.entity.Living; @@ -41,6 +43,7 @@ import com.mojang.authlib.GameProfile; import net.minecraft.block.BlockState; import net.minecraft.client.MinecraftClient; import net.minecraft.entity.Entity; +import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.attribute.DefaultAttributeContainer; import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.data.DataTracker; @@ -94,6 +97,7 @@ public class Pony extends Living implements Transmittable, Copieab private boolean invisible = false; private int ticksInSun; + private boolean hasShades; public Pony(PlayerEntity player) { super(player, EFFECT); @@ -291,6 +295,7 @@ public class Pony extends Living implements Transmittable, Copieab if (ticksInSun == 1) { entity.addStatusEffect(new StatusEffectInstance(SunBlindnessStatusEffect.INSTANCE, SunBlindnessStatusEffect.MAX_DURATION * 10, 1, true, false)); + UCriteria.LOOK_INTO_SUN.trigger(entity); if (isClient()) { MinecraftClient.getInstance().getSoundManager().play(new LoopingSoundInstance<>(entity, e -> e.hasStatusEffect(SunBlindnessStatusEffect.INSTANCE), USounds.ENTITY_PLAYER_EARS_RINGING, 1F, 1F)); @@ -299,6 +304,12 @@ public class Pony extends Living implements Transmittable, Copieab } else if (ticksInSun > 0) { ticksInSun--; } + + boolean hasShades = entity.getEquippedStack(EquipmentSlot.HEAD).isIn(UTags.SHADES); + if (!this.hasShades && hasShades) { + UCriteria.WEAR_SHADES.trigger(entity); + } + this.hasShades = hasShades; } tickers.forEach(Tickable::tick); diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/MixinCriteria.java b/src/main/java/com/minelittlepony/unicopia/mixin/MixinCriteria.java new file mode 100644 index 00000000..33fdb976 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/mixin/MixinCriteria.java @@ -0,0 +1,15 @@ +package com.minelittlepony.unicopia.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +import net.minecraft.advancement.criterion.Criteria; +import net.minecraft.advancement.criterion.Criterion; + +@Mixin(Criteria.class) +public interface MixinCriteria { + @Invoker("register") + static > T register(T object) { + return null; + } +} diff --git a/src/main/resources/assets/unicopia/lang/en_us.json b/src/main/resources/assets/unicopia/lang/en_us.json index 1cecbfa7..1048a48a 100644 --- a/src/main/resources/assets/unicopia/lang/en_us.json +++ b/src/main/resources/assets/unicopia/lang/en_us.json @@ -375,5 +375,12 @@ "unicopia.subtitle.slime_advance": "Squealch", "unicopia.subtitle.slime_retract": "Sqonk", "unicopia.subtitle.changeling_buzz": "Drone Buzzing", - "unicopia.subtitle.batpony_eeee": "Batpony Screeches" + "unicopia.subtitle.batpony_eeee": "Batpony Screeches", + + "advancements.unicopia.root.title": "Unicopia", + "advancements.unicopia.root.description": "A world of magic and adventure", + "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" } diff --git a/src/main/resources/data/unicopia/advancements/unicopia/cool_potato.json b/src/main/resources/data/unicopia/advancements/unicopia/cool_potato.json new file mode 100644 index 00000000..eae9ca6e --- /dev/null +++ b/src/main/resources/data/unicopia/advancements/unicopia/cool_potato.json @@ -0,0 +1,29 @@ +{ + "parent": "unicopia:unicopia/praise_the_sun", + "display": { + "icon": { + "item": "minecraft:potato" + }, + "title": { + "translate": "advancements.unicopia.cool_potato.title" + }, + "description": { + "translate": "advancements.unicopia.cool_potato.description" + }, + "frame": "task", + "show_toast": true, + "announce_to_chat": true, + "hidden": false + }, + "criteria": { + "wear_shades": { + "trigger": "unicopia:custom", + "conditions": { + "event": "wear_shades" + } + } + }, + "requirements": [ + [ "wear_shades" ] + ] +} diff --git a/src/main/resources/data/unicopia/advancements/unicopia/praise_the_sun.json b/src/main/resources/data/unicopia/advancements/unicopia/praise_the_sun.json new file mode 100644 index 00000000..a45e81d0 --- /dev/null +++ b/src/main/resources/data/unicopia/advancements/unicopia/praise_the_sun.json @@ -0,0 +1,29 @@ +{ + "parent": "unicopia:unicopia/root", + "display": { + "icon": { + "item": "minecraft:light" + }, + "title": { + "translate": "advancements.unicopia.praise_the_sun.title" + }, + "description": { + "translate": "advancements.unicopia.praise_the_sun.description" + }, + "frame": "task", + "show_toast": true, + "announce_to_chat": true, + "hidden": false + }, + "criteria": { + "look_into_sun": { + "trigger": "unicopia:custom", + "conditions": { + "event": "look_into_sun" + } + } + }, + "requirements": [ + [ "look_into_sun" ] + ] +} diff --git a/src/main/resources/data/unicopia/advancements/unicopia/root.json b/src/main/resources/data/unicopia/advancements/unicopia/root.json new file mode 100644 index 00000000..5db3b254 --- /dev/null +++ b/src/main/resources/data/unicopia/advancements/unicopia/root.json @@ -0,0 +1,31 @@ +{ + "display": { + "icon": { + "item": "unicopia:pegasus_feather" + }, + "title": { + "translate": "advancements.unicopia.root.title" + }, + "description": { + "translate": "advancements.unicopia.root.description" + }, + "frame": "task", + "show_toast": false, + "announce_to_chat": false, + "hidden": false, + "background": "minecraft:textures/gui/advancements/backgrounds/stone.png" + }, + "criteria": { + "crafting_table": { + "trigger": "minecraft:inventory_changed", + "conditions": { + "items": [ + { "item": "minecraft:crafting_table" } + ] + } + } + }, + "requirements": [ + [ "crafting_table" ] + ] +} diff --git a/src/main/resources/unicopia.mixin.json b/src/main/resources/unicopia.mixin.json index 1d63abe7..12f060bd 100644 --- a/src/main/resources/unicopia.mixin.json +++ b/src/main/resources/unicopia.mixin.json @@ -9,6 +9,7 @@ "MixinBlockEntity", "MixinBlockItem", "MixinBrain", + "MixinCriteria", "MixinDamageSource", "MixinEntity", "MixinFallingBlock",