From 236f8afb024f9e219c97b0ec6accb1ad3263e04f Mon Sep 17 00:00:00 2001 From: Sollace Date: Sun, 3 Sep 2023 21:51:50 +0100 Subject: [PATCH] Add an advancement for killing a mob with a rock --- .../unicopia/entity/damage/UDamageTypes.java | 1 + .../PhysicsBodyProjectileEntity.java | 14 ++++++++ .../resources/assets/unicopia/lang/en_us.json | 5 +++ .../unicopia/earth/sticks_and_stones.json | 36 +++++++++++++++++++ .../unicopia/tags/damage_type/from_rocks.json | 6 ++++ 5 files changed, 62 insertions(+) create mode 100644 src/main/resources/data/unicopia/advancements/unicopia/earth/sticks_and_stones.json create mode 100644 src/main/resources/data/unicopia/tags/damage_type/from_rocks.json diff --git a/src/main/java/com/minelittlepony/unicopia/entity/damage/UDamageTypes.java b/src/main/java/com/minelittlepony/unicopia/entity/damage/UDamageTypes.java index 51b6a882..737f7775 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/damage/UDamageTypes.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/damage/UDamageTypes.java @@ -29,6 +29,7 @@ public interface UDamageTypes { RegistryKey SUN = register("sun"); RegistryKey SUNLIGHT = register("sunlight"); RegistryKey PETRIFIED = register("petrified"); + RegistryKey ROCK = register("rock"); private static RegistryKey register(String name) { var key = RegistryKey.of(RegistryKeys.DAMAGE_TYPE, Unicopia.id(name)); diff --git a/src/main/java/com/minelittlepony/unicopia/projectile/PhysicsBodyProjectileEntity.java b/src/main/java/com/minelittlepony/unicopia/projectile/PhysicsBodyProjectileEntity.java index 2ac09472..93eb890f 100644 --- a/src/main/java/com/minelittlepony/unicopia/projectile/PhysicsBodyProjectileEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/projectile/PhysicsBodyProjectileEntity.java @@ -5,6 +5,7 @@ import org.jetbrains.annotations.Nullable; import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.UTags; import com.minelittlepony.unicopia.ability.magic.Caster; +import com.minelittlepony.unicopia.entity.damage.UDamageTypes; import com.minelittlepony.unicopia.entity.mob.UEntities; import net.minecraft.block.BlockState; @@ -12,10 +13,13 @@ import net.minecraft.block.ButtonBlock; import net.minecraft.block.HopperBlock; import net.minecraft.block.LeverBlock; import net.minecraft.block.entity.BlockEntity; +import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.entity.FlyingItemEntity; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.MovementType; +import net.minecraft.entity.damage.DamageSource; +import net.minecraft.entity.damage.DamageSources; import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedDataHandlerRegistry; @@ -131,6 +135,16 @@ public class PhysicsBodyProjectileEntity extends PersistentProjectileEntity impl super.onEntityHit(hit); } + @Override + public DamageSources getDamageSources() { + return new DamageSources(getWorld().getRegistryManager()) { + @Override + public DamageSource arrow(PersistentProjectileEntity source, @Nullable Entity attacker) { + return create(UDamageTypes.ROCK, source, attacker); + } + }; + } + @Override protected void onBlockHit(BlockHitResult hit) { BlockPos buttonPos = hit.getBlockPos().offset(hit.getSide()); diff --git a/src/main/resources/assets/unicopia/lang/en_us.json b/src/main/resources/assets/unicopia/lang/en_us.json index 83add8c2..a9d5e07c 100644 --- a/src/main/resources/assets/unicopia/lang/en_us.json +++ b/src/main/resources/assets/unicopia/lang/en_us.json @@ -734,6 +734,9 @@ "death.attack.unicopia.steamroller.player": "%2$s steamrolled %1$s", "death.attack.unicopia.stalagmite.pegasus": "%1$s tried to perch on a stalagmite", "death.attack.unicopia.stalagmite.pegasus.player": "%1$s flew into a stalagmite whilst fighting %2$s", + "death.attack.unicopia.rock": "%1$s was pummeled", + "death.attack.unicopia.rock.item": "%1$s was pummelled by %2$s using %3$s", + "death.attack.unicopia.rock.player": "%1$s was pummelled by %2$s", "death.fell.accident.ladder.pegasus": "%1$s forgot they could fly and fell off a ladder", "death.fell.accident.vines.pegasus": "%1$s forgot they could fly and fell off some vines", @@ -879,6 +882,8 @@ "advancements.unicopia.earth_route.title": "Path of the Pony", "advancements.unicopia.earth_route.description": "Join the Apple Clan", + "advancements.unicopia.sticks_and_stones.title": "Sticks and Stones", + "advancements.unicopia.sticks_and_stones.description": "Kill an mob by throwing rocks at it", "advancements.unicopia.born_on_a_rock_farm.title": "Born on a Rock Farm", "advancements.unicopia.born_on_a_rock_farm.description": "Successfully farm your first rock", "advancements.unicopia.thats_unusual.title": "That's Unusual", diff --git a/src/main/resources/data/unicopia/advancements/unicopia/earth/sticks_and_stones.json b/src/main/resources/data/unicopia/advancements/unicopia/earth/sticks_and_stones.json new file mode 100644 index 00000000..881e8c8d --- /dev/null +++ b/src/main/resources/data/unicopia/advancements/unicopia/earth/sticks_and_stones.json @@ -0,0 +1,36 @@ +{ + "parent": "unicopia:unicopia/earth/born_on_a_rock_farm", + "display": { + "icon": { + "item": "unicopia:rock" + }, + "title": { + "translate": "advancements.unicopia.sticks_and_stones.title" + }, + "description": { + "translate": "advancements.unicopia.sticks_and_stones.description" + }, + "frame": "task", + "show_toast": true, + "announce_to_chat": true, + "hidden": true + }, + "criteria": { + "killed_entity_with_rock": { + "trigger": "minecraft:player_killed_entity", + "conditions": { + "killing_blow": { + "tags": [ + { + "id": "unicopia:from_rocks", + "expected": true + } + ] + } + } + } + }, + "requirements": [ + [ "killed_entity_with_rock" ] + ] +} diff --git a/src/main/resources/data/unicopia/tags/damage_type/from_rocks.json b/src/main/resources/data/unicopia/tags/damage_type/from_rocks.json new file mode 100644 index 00000000..9ab866dd --- /dev/null +++ b/src/main/resources/data/unicopia/tags/damage_type/from_rocks.json @@ -0,0 +1,6 @@ +{ + "replace": false, + "values": [ + "unicopia:rock" + ] +}