Added advancements and recipes for crafting muffins

This commit is contained in:
Sollace 2022-04-01 00:40:39 +02:00
parent a878fd0d6c
commit d94626e094
8 changed files with 100 additions and 7 deletions

View file

@ -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<CustomEventCriterion
protected Conditions conditionsFromJson(JsonObject json, Extended playerPredicate, AdvancementEntityPredicateDeserializer deserializer) {
Set<Race> 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<CustomEventCriterion
public CustomEventCriterion.Trigger createTrigger(String name) {
return player -> {
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 {

View file

@ -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 extends Criterion<?>> T register(T obj) {
return MixinCriteria.register(obj);

View file

@ -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);

View file

@ -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;
}
}

View file

@ -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",

View file

@ -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"
]
]
}

View file

@ -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" ]
]
}

View file

@ -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
}
}