More advancements, I say, more!

This commit is contained in:
Sollace 2021-08-19 14:43:15 +02:00
parent 76be400a32
commit a2512f293a
11 changed files with 183 additions and 9 deletions

View file

@ -9,6 +9,7 @@ import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.USounds;
import com.minelittlepony.unicopia.ability.data.Hit;
import com.minelittlepony.unicopia.ability.magic.spell.SpellType;
import com.minelittlepony.unicopia.advancement.UCriteria;
import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.util.MagicalDamageSource;
@ -79,9 +80,10 @@ public class BatEeeeAbility implements Ability<Hit> {
if (rng.nextInt(20000) == 0) {
player.getMaster().damage(MagicalDamageSource.create("eeee", player), 0.1F);
UCriteria.SCREECH_SELF.trigger(player.getMaster());
}
player.findAllEntitiesInRange(5).forEach(e -> {
int total = player.findAllEntitiesInRange(5).mapToInt(e -> {
if (e instanceof LivingEntity && !HAS_SHIELD.test(e)) {
boolean isEarthPony = EquinePredicates.PLAYER_EARTH.test(e);
e.damage(MagicalDamageSource.create("eeee", player), isEarthPony ? 0.1F : 0.3F);
@ -92,7 +94,12 @@ public class BatEeeeAbility implements Ability<Hit> {
e.addVelocity(0, 0.1, 0);
}
}
});
return 1;
}).sum();
if (total >= 20) {
UCriteria.SCREECH_TWENTY_MOBS.trigger(player.getMaster());
}
}
@Override

View file

@ -40,7 +40,8 @@ public class CustomEventCriterion extends AbstractCriterion<CustomEventCriterion
return new Conditions(
playerPredicate,
JsonHelper.getString(json, "event"),
races
races,
json.has("flying") ? json.get("flying").getAsBoolean() : null
);
}
@ -61,14 +62,19 @@ public class CustomEventCriterion extends AbstractCriterion<CustomEventCriterion
private final Set<Race> races;
public Conditions(Extended playerPredicate, String event, Set<Race> races) {
private final Boolean flying;
public Conditions(Extended playerPredicate, String event, Set<Race> races, Boolean flying) {
super(ID, playerPredicate);
this.event = event;
this.races = races;
this.flying = flying;
}
public boolean test(String event, ServerPlayerEntity player) {
return this.event.equalsIgnoreCase(event) && (races.isEmpty() || races.contains(Pony.of(player).getSpecies()));
return this.event.equalsIgnoreCase(event)
&& (races.isEmpty() || races.contains(Pony.of(player).getSpecies()))
&& (flying == null || flying == Pony.of(player).getPhysics().isFlying());
}
@Override
@ -80,6 +86,9 @@ public class CustomEventCriterion extends AbstractCriterion<CustomEventCriterion
races.forEach(r -> arr.add(r.name().toLowerCase()));
json.add("race", arr);
}
if (flying != null) {
json.addProperty("flying", flying);
}
return json;
}
}

View file

@ -0,0 +1,57 @@
package com.minelittlepony.unicopia.advancement;
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;
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 RaceChangeCriterion extends AbstractCriterion<RaceChangeCriterion.Conditions> {
private static final Identifier ID = new Identifier("unicopia", "player_change_race");
@Override
public Identifier getId() {
return ID;
}
@Override
protected Conditions conditionsFromJson(JsonObject json, Extended playerPredicate, AdvancementEntityPredicateDeserializer deserializer) {
return new Conditions(playerPredicate, Race.fromName(JsonHelper.getString(json, "race")));
}
public void trigger(PlayerEntity player) {
if (player instanceof ServerPlayerEntity) {
test((ServerPlayerEntity)player, c -> c.test((ServerPlayerEntity)player));
}
}
public static class Conditions extends AbstractCriterionConditions {
private final Race race;
public Conditions(Extended playerPredicate, Race race) {
super(ID, playerPredicate);
this.race = race;
}
public boolean test(ServerPlayerEntity player) {
return Pony.of(player).getSpecies() == race;
}
@Override
public JsonObject toJson(AdvancementEntityPredicateSerializer serializer) {
JsonObject json = super.toJson(serializer);
json.addProperty("race", race.name().toLowerCase());
return json;
}
}
}

View file

@ -6,12 +6,15 @@ import net.minecraft.advancement.criterion.Criterion;
public interface UCriteria {
CustomEventCriterion CUSTOM_EVENT = register(new CustomEventCriterion());
RaceChangeCriterion PLAYER_CHANGE_RACE = register(new RaceChangeCriterion());
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");
CustomEventCriterion.Trigger SCREECH_SELF = CUSTOM_EVENT.createTrigger("screech_self");
CustomEventCriterion.Trigger SCREECH_TWENTY_MOBS = CUSTOM_EVENT.createTrigger("screech_twenty_mobs");
private static <T extends Criterion<?>> T register(T obj) {
return MixinCriteria.register(obj);

View file

@ -130,6 +130,8 @@ public class Pony extends Living<PlayerEntity> implements Transmittable, Copieab
gravity.updateFlightState();
entity.sendAbilitiesUpdate();
UCriteria.PLAYER_CHANGE_RACE.trigger(entity);
}
public MagicReserves getMagicalReserves() {

View file

@ -403,6 +403,7 @@
"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",
@ -412,5 +413,12 @@
"advancements.unicopia.sweet_apple_acres.title": "Sweet Apple Acres",
"advancements.unicopia.sweet_apple_acres.description": "Obtain one of every apple",
"advancements.unicopia.brew_cider.title": "Applejack's Finest",
"advancements.unicopia.brew_cider.description": "Brew some cider"
"advancements.unicopia.brew_cider.description": "Brew some cider",
"advancements.unicopia.night_route.title": "I Am The Night",
"advancements.unicopia.night_route.description": "Walth the path of night",
"advancements.unicopia.screech_twenty_mobs.title": "Terror From The Skies",
"advancements.unicopia.screech_twenty_mobs.description": "Rain down terror on at least 20 mobs at once",
"advancements.unicopia.screech_self.title": "Jeepers!",
"advancements.unicopia.screech_self.description": "Be so terrifying that you even scared your self a little"
}

View file

@ -1,8 +1,8 @@
{
"parent": "unicopia:unicopia/praise_the_sun",
"parent": "unicopia:unicopia/bat/praise_the_sun",
"display": {
"icon": {
"item": "minecraft:potato"
"item": "minecraft:carved_pumpkin"
},
"title": {
"translate": "advancements.unicopia.cool_potato.title"

View file

@ -0,0 +1,29 @@
{
"parent": "unicopia:unicopia/root",
"display": {
"icon": {
"item": "minecraft:black_candle"
},
"title": {
"translate": "advancements.unicopia.night_path.title"
},
"description": {
"translate": "advancements.unicopia.night_path.description"
},
"frame": "task",
"show_toast": true,
"announce_to_chat": true,
"hidden": false
},
"criteria": {
"be_bat": {
"trigger": "unicopia:player_change_race",
"conditions": {
"race": "bat"
}
}
},
"requirements": [
[ "be_bat" ]
]
}

View file

@ -1,5 +1,5 @@
{
"parent": "unicopia:unicopia/root",
"parent": "unicopia:unicopia/bat/night_route",
"display": {
"icon": {
"item": "minecraft:light"

View file

@ -0,0 +1,29 @@
{
"parent": "unicopia:unicopia/bat/night_route",
"display": {
"icon": {
"item": "minecraft:black_candle"
},
"title": {
"translate": "advancements.unicopia.screech_self.title"
},
"description": {
"translate": "advancements.unicopia.screech_self.description"
},
"frame": "challenge",
"show_toast": true,
"announce_to_chat": true,
"hidden": true
},
"criteria": {
"screech_self": {
"trigger": "unicopia:custom",
"conditions": {
"event": "screech_self"
}
}
},
"requirements": [
[ "screech_self" ]
]
}

View file

@ -0,0 +1,30 @@
{
"parent": "unicopia:unicopia/bat/night_route",
"display": {
"icon": {
"item": "minecraft:black_candle"
},
"title": {
"translate": "advancements.unicopia.screech_twenty_mobs.title"
},
"description": {
"translate": "advancements.unicopia.screech_twenty_mobs.description"
},
"frame": "challenge",
"show_toast": true,
"announce_to_chat": true,
"hidden": false
},
"criteria": {
"screech_twenty_mobs": {
"trigger": "unicopia:custom",
"conditions": {
"event": "screech_twenty_mobs",
"flying": true
}
}
},
"requirements": [
[ "screech_twenty_mobs" ]
]
}