Add an advancement for breaking through a window as a pegasus

This commit is contained in:
Sollace 2022-10-01 23:51:10 +02:00
parent 8e052f2472
commit 63481f9c64
11 changed files with 127 additions and 48 deletions

View file

@ -22,6 +22,8 @@ public interface UTags {
TagKey<Item> POLEARMS = item("polearms");
TagKey<Item> APPLE_SEEDS = item("apple_seeds");
TagKey<Block> GLASS_PANES = block("glass_panes");
TagKey<Block> GLASS_BLOCKS = block("glass_blocks");
TagKey<Block> FRAGILE = block("fragile");
TagKey<Block> INTERESTING = block("interesting");

View file

@ -9,6 +9,7 @@ import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.EquinePredicates;
import com.minelittlepony.unicopia.Owned;
import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
import com.minelittlepony.unicopia.block.data.ModificationType;
import com.minelittlepony.unicopia.entity.Physics;
import com.minelittlepony.unicopia.entity.PonyContainer;
import com.minelittlepony.unicopia.particle.ParticleSource;
@ -63,15 +64,24 @@ public interface Caster<E extends LivingEntity> extends Owned<E>, Levelled, Affi
}
default boolean canModifyAt(BlockPos pos) {
return canModifyAt(pos, ModificationType.EITHER);
}
if (!canCastAt(Vec3d.ofCenter(pos))) {
default boolean canModifyAt(BlockPos pos, ModificationType mod) {
if (mod.checkPhysical()) {
if (getMaster() instanceof PlayerEntity player) {
if (!getReferenceWorld().canPlayerModifyAt(player, pos)) {
return false;
}
if (getMaster() instanceof PlayerEntity) {
return getReferenceWorld().canPlayerModifyAt((PlayerEntity)getMaster(), pos);
} else {
if (!getReferenceWorld().getGameRules().getBoolean(GameRules.DO_MOB_GRIEFING)) {
return false;
}
return getReferenceWorld().getGameRules().getBoolean(GameRules.DO_MOB_GRIEFING);
}
}
return !mod.checkMagical() || canCastAt(Vec3d.ofCenter(pos));
}
/**

View file

@ -19,6 +19,7 @@ public interface UCriteria {
CustomEventCriterion.Trigger THROW_MUFFIN = CUSTOM_EVENT.createTrigger("throw_muffin");
CustomEventCriterion.Trigger SEND_OATS = CUSTOM_EVENT.createTrigger("send_oats");
CustomEventCriterion.Trigger RECEIVE_OATS = CUSTOM_EVENT.createTrigger("receive_oats");
CustomEventCriterion.Trigger BREAK_WINDOW = CUSTOM_EVENT.createTrigger("break_window");
private static <T extends Criterion<?>> T register(T obj) {
return MixinCriteria.register(obj);

View file

@ -0,0 +1,15 @@
package com.minelittlepony.unicopia.block.data;
public enum ModificationType {
MAGICAL,
PHYSICAL,
EITHER;
public boolean checkMagical() {
return this == MAGICAL || this == EITHER;
}
public boolean checkPhysical() {
return this == PHYSICAL || this == EITHER;
}
}

View file

@ -1,12 +1,10 @@
package com.minelittlepony.unicopia.entity.player;
import com.minelittlepony.unicopia.FlightType;
import com.minelittlepony.unicopia.InteractionManager;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.USounds;
import com.minelittlepony.unicopia.*;
import com.minelittlepony.unicopia.ability.magic.SpellPredicate;
import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
import com.minelittlepony.unicopia.advancement.UCriteria;
import com.minelittlepony.unicopia.block.data.ModificationType;
import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation;
import com.minelittlepony.unicopia.entity.*;
import com.minelittlepony.unicopia.entity.duck.LivingEntityDuck;
@ -14,6 +12,7 @@ import com.minelittlepony.unicopia.entity.player.MagicReserves.Bar;
import com.minelittlepony.unicopia.item.AmuletItem;
import com.minelittlepony.unicopia.item.UItems;
import com.minelittlepony.unicopia.item.enchantment.UEnchantments;
import com.minelittlepony.unicopia.particle.*;
import com.minelittlepony.unicopia.projectile.ProjectileUtil;
import com.minelittlepony.unicopia.util.*;
@ -589,17 +588,22 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
Vec3d orientation = entity.getRotationVec(1).multiply(speed);
entity.addVelocity(orientation.x, orientation.y, orientation.z);
int damage = TraceHelper.findBlocks(entity, speed + 4, 1, state -> state.isOf(Blocks.GLASS_PANE)).stream()
int damage = TraceHelper.findBlocks(entity, speed + 4, 1, state -> state.isIn(UTags.GLASS_PANES)).stream()
.flatMap(pos -> BlockPos.streamOutwards(pos, 2, 2, 2))
.filter(pos -> entity.world.getBlockState(pos).isOf(Blocks.GLASS_PANE))
.reduce(0, (u, pos) -> {
if (pony.canModifyAt(pos, ModificationType.PHYSICAL)) {
entity.world.breakBlock(pos, true);
} else {
ParticleUtils.spawnParticles(new MagicParticleEffect(0x00AAFF), entity.world, Vec3d.ofCenter(pos), 15);
}
return 1;
}, Integer::sum);
if (damage > 0) {
pony.subtractEnergyCost(damage / 5F);
entity.damage(DamageSource.FLY_INTO_WALL, Math.min(damage, entity.getHealth() - 1));
UCriteria.BREAK_WINDOW.trigger(entity);
}
pony.updateVelocity();

View file

@ -597,6 +597,9 @@
"advancements.unicopia.molting_season_3.title": "Molting Season 3",
"advancements.unicopia.molting_season_3.description": "Drop 15 feathers whilst flying",
"advancements.unicopia.rainbow_crash.title": "Dammit, Rainbow",
"advancements.unicopia.rainbow_crash.description": "Wage war on the evil glass window nation",
"unicopia.toast.discoveries.title": "New Discoveries!",
"unicopia.toast.discoveries.description": "Check your spellbook"
}

View file

@ -0,0 +1,29 @@
{
"parent": "unicopia:unicopia/pegasus/sky_route",
"display": {
"icon": {
"item": "minecraft:glass_pane"
},
"title": {
"translate": "advancements.unicopia.rainbow_crash.title"
},
"description": {
"translate": "advancements.unicopia.rainbow_crash.description"
},
"frame": "task",
"show_toast": true,
"announce_to_chat": true,
"hidden": false
},
"criteria": {
"break_window": {
"trigger": "unicopia:custom",
"conditions": {
"event": "break_window"
}
}
},
"requirements": [
[ "break_window" ]
]
}

View file

@ -10,7 +10,7 @@
"description": {
"translate": "advancements.unicopia.sky_route.description"
},
"frame": "task",
"frame": "challenge",
"show_toast": true,
"announce_to_chat": true,
"hidden": false
@ -25,5 +25,8 @@
},
"requirements": [
[ "be_birb" ]
]
],
"rewards": {
"experience": 100
}
}

View file

@ -1,40 +1,8 @@
{
"replace": false,
"values": [
"minecraft:glass",
"minecraft:glass_pane",
"minecraft:white_stained_glass",
"minecraft:orange_stained_glass",
"minecraft:magenta_stained_glass",
"minecraft:light_blue_stained_glass",
"minecraft:yellow_stained_glass",
"minecraft:lime_stained_glass",
"minecraft:pink_stained_glass",
"minecraft:gray_stained_glass",
"minecraft:light_gray_stained_glass",
"minecraft:cyan_stained_glass",
"minecraft:purple_stained_glass",
"minecraft:blue_stained_glass",
"minecraft:brown_stained_glass",
"minecraft:green_stained_glass",
"minecraft:red_stained_glass",
"minecraft:black_stained_glass",
"minecraft:white_stained_glass_pane",
"minecraft:orange_stained_glass_pane",
"minecraft:magenta_stained_glass_pane",
"minecraft:light_blue_stained_glass_pane",
"minecraft:yellow_stained_glass_pane",
"minecraft:lime_stained_glass_pane",
"minecraft:pink_stained_glass_pane",
"minecraft:gray_stained_glass_pane",
"minecraft:light_gray_stained_glass_pane",
"minecraft:cyan_stained_glass_pane",
"minecraft:purple_stained_glass_pane",
"minecraft:blue_stained_glass_pane",
"minecraft:brown_stained_glass_pane",
"minecraft:green_stained_glass_pane",
"minecraft:red_stained_glass_pane",
"minecraft:black_stained_glass_pane",
"#unicopia:glass_blocks",
"#unicopia:glass_panes",
"minecraft:vine",
"minecraft:lily_pad"
]

View file

@ -0,0 +1,22 @@
{
"replace": false,
"values": [
"minecraft:glass",
"minecraft:white_stained_glass",
"minecraft:orange_stained_glass",
"minecraft:magenta_stained_glass",
"minecraft:light_blue_stained_glass",
"minecraft:yellow_stained_glass",
"minecraft:lime_stained_glass",
"minecraft:pink_stained_glass",
"minecraft:gray_stained_glass",
"minecraft:light_gray_stained_glass",
"minecraft:cyan_stained_glass",
"minecraft:purple_stained_glass",
"minecraft:blue_stained_glass",
"minecraft:brown_stained_glass",
"minecraft:green_stained_glass",
"minecraft:red_stained_glass",
"minecraft:black_stained_glass"
]
}

View file

@ -0,0 +1,22 @@
{
"replace": false,
"values": [
"minecraft:glass_pane",
"minecraft:white_stained_glass_pane",
"minecraft:orange_stained_glass_pane",
"minecraft:magenta_stained_glass_pane",
"minecraft:light_blue_stained_glass_pane",
"minecraft:yellow_stained_glass_pane",
"minecraft:lime_stained_glass_pane",
"minecraft:pink_stained_glass_pane",
"minecraft:gray_stained_glass_pane",
"minecraft:light_gray_stained_glass_pane",
"minecraft:cyan_stained_glass_pane",
"minecraft:purple_stained_glass_pane",
"minecraft:blue_stained_glass_pane",
"minecraft:brown_stained_glass_pane",
"minecraft:green_stained_glass_pane",
"minecraft:red_stained_glass_pane",
"minecraft:black_stained_glass_pane"
]
}