From 0c268277909d47f5cdbbfd8fbd5df0677ada0577 Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 17 Jan 2024 19:48:35 +0000 Subject: [PATCH] Add advancement for killing mobs with a horseshoe --- .../unicopia/entity/damage/UDamageTypes.java | 1 + .../unicopia/item/HorseShoeItem.java | 2 ++ .../PhysicsBodyProjectileEntity.java | 21 ++++++++++- .../resources/assets/unicopia/lang/en_us.json | 8 ++++- .../unicopia/earth/dead_ringer.json | 36 +++++++++++++++++++ .../unicopia/earth/sticks_and_stones.json | 12 +++---- .../tags/damage_type/from_horseshoes.json | 6 ++++ 7 files changed, 78 insertions(+), 8 deletions(-) create mode 100644 src/main/resources/data/unicopia/advancements/unicopia/earth/dead_ringer.json create mode 100644 src/main/resources/data/unicopia/tags/damage_type/from_horseshoes.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 737f7775..b28faeea 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/damage/UDamageTypes.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/damage/UDamageTypes.java @@ -30,6 +30,7 @@ public interface UDamageTypes { RegistryKey SUNLIGHT = register("sunlight"); RegistryKey PETRIFIED = register("petrified"); RegistryKey ROCK = register("rock"); + RegistryKey HORSESHOE = register("horseshoe"); 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/item/HorseShoeItem.java b/src/main/java/com/minelittlepony/unicopia/item/HorseShoeItem.java index a7899e8d..a9ed6129 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/HorseShoeItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/HorseShoeItem.java @@ -9,6 +9,7 @@ import com.google.common.collect.Multimap; import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.Unicopia; +import com.minelittlepony.unicopia.entity.damage.UDamageTypes; import com.minelittlepony.unicopia.entity.mob.UEntityAttributes; import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.projectile.PhysicsBodyProjectileEntity; @@ -75,6 +76,7 @@ public class HorseShoeItem extends HeavyProjectileItem { @Override protected PhysicsBodyProjectileEntity createProjectile(ItemStack stack, World world, @Nullable PlayerEntity player) { PhysicsBodyProjectileEntity projectile = super.createProjectile(stack, world, player); + projectile.setDamageType(UDamageTypes.HORSESHOE); float degradation = (stack.getDamage() / (float)stack.getMaxDamage()); diff --git a/src/main/java/com/minelittlepony/unicopia/projectile/PhysicsBodyProjectileEntity.java b/src/main/java/com/minelittlepony/unicopia/projectile/PhysicsBodyProjectileEntity.java index 13d49ce9..531f670e 100644 --- a/src/main/java/com/minelittlepony/unicopia/projectile/PhysicsBodyProjectileEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/projectile/PhysicsBodyProjectileEntity.java @@ -1,5 +1,7 @@ package com.minelittlepony.unicopia.projectile; +import java.util.Optional; + import org.jetbrains.annotations.Nullable; import com.minelittlepony.unicopia.USounds; @@ -19,6 +21,7 @@ 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.damage.DamageType; import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedDataHandlerRegistry; @@ -27,9 +30,13 @@ import net.minecraft.entity.projectile.PersistentProjectileEntity; import net.minecraft.inventory.Inventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; +import net.minecraft.nbt.NbtElement; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.tag.BlockTags; import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvent; +import net.minecraft.util.Identifier; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.EntityHitResult; import net.minecraft.util.math.BlockPos; @@ -46,6 +53,8 @@ public class PhysicsBodyProjectileEntity extends PersistentProjectileEntity impl private int inWaterTime; + private RegistryKey damageType = UDamageTypes.ROCK; + public PhysicsBodyProjectileEntity(EntityType type, World world) { super(type, world); } @@ -74,6 +83,10 @@ public class PhysicsBodyProjectileEntity extends PersistentProjectileEntity impl return getDataTracker().get(ITEM); } + public void setDamageType(RegistryKey damageType) { + this.damageType = damageType; + } + @Override protected ItemStack asItemStack() { return getStack(); @@ -149,7 +162,7 @@ public class PhysicsBodyProjectileEntity extends PersistentProjectileEntity impl return new DamageSources(getWorld().getRegistryManager()) { @Override public DamageSource arrow(PersistentProjectileEntity source, @Nullable Entity attacker) { - return create(UDamageTypes.ROCK, source, attacker); + return create(damageType, source, attacker); } }; } @@ -262,11 +275,17 @@ public class PhysicsBodyProjectileEntity extends PersistentProjectileEntity impl if (!stack.isEmpty()) { nbt.put("Item", stack.writeNbt(new NbtCompound())); } + nbt.putString("damageType", damageType.getValue().toString()); } @Override public void readCustomDataFromNbt(NbtCompound nbt) { super.readCustomDataFromNbt(nbt); setStack(ItemStack.fromNbt(nbt.getCompound("Item"))); + if (nbt.contains("damageType", NbtElement.STRING_TYPE)) { + Optional.ofNullable(Identifier.tryParse(nbt.getString("damageType"))).ifPresent(id -> { + setDamageType(RegistryKey.of(RegistryKeys.DAMAGE_TYPE, id)); + }); + } } } diff --git a/src/main/resources/assets/unicopia/lang/en_us.json b/src/main/resources/assets/unicopia/lang/en_us.json index 87ec41e1..97196487 100644 --- a/src/main/resources/assets/unicopia/lang/en_us.json +++ b/src/main/resources/assets/unicopia/lang/en_us.json @@ -993,6 +993,10 @@ "death.attack.unicopia.rock.self": "%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.attack.unicopia.horseshoe": "%1$s went ding", + "death.attack.unicopia.horseshoe.self": "%1$s dinged himself", + "death.attack.unicopia.horseshoe.item": "%1$s was dinged by %2$s using %3$s", + "death.attack.unicopia.horseshoe.player": "%1$s was dinged 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", @@ -1158,7 +1162,9 @@ "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.sticks_and_stones.description": "Kill a mob by throwing rocks at it", + "advancements.unicopia.dead_ringer.title": "Dead Ringer", + "advancements.unicopia.dead_ringer.description": "Kill a mob with a horseshoe", "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/dead_ringer.json b/src/main/resources/data/unicopia/advancements/unicopia/earth/dead_ringer.json new file mode 100644 index 00000000..881e8c8d --- /dev/null +++ b/src/main/resources/data/unicopia/advancements/unicopia/earth/dead_ringer.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/advancements/unicopia/earth/sticks_and_stones.json b/src/main/resources/data/unicopia/advancements/unicopia/earth/sticks_and_stones.json index 881e8c8d..591e4616 100644 --- 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 @@ -2,13 +2,13 @@ "parent": "unicopia:unicopia/earth/born_on_a_rock_farm", "display": { "icon": { - "item": "unicopia:rock" + "item": "unicopia:horseshoe" }, "title": { - "translate": "advancements.unicopia.sticks_and_stones.title" + "translate": "advancements.unicopia.dead_ringer.title" }, "description": { - "translate": "advancements.unicopia.sticks_and_stones.description" + "translate": "advancements.unicopia.dead_ringer.description" }, "frame": "task", "show_toast": true, @@ -16,13 +16,13 @@ "hidden": true }, "criteria": { - "killed_entity_with_rock": { + "killed_entity_with_horseshoe": { "trigger": "minecraft:player_killed_entity", "conditions": { "killing_blow": { "tags": [ { - "id": "unicopia:from_rocks", + "id": "unicopia:from_horseshoes", "expected": true } ] @@ -31,6 +31,6 @@ } }, "requirements": [ - [ "killed_entity_with_rock" ] + [ "killed_entity_with_horseshoe" ] ] } diff --git a/src/main/resources/data/unicopia/tags/damage_type/from_horseshoes.json b/src/main/resources/data/unicopia/tags/damage_type/from_horseshoes.json new file mode 100644 index 00000000..276d2073 --- /dev/null +++ b/src/main/resources/data/unicopia/tags/damage_type/from_horseshoes.json @@ -0,0 +1,6 @@ +{ + "replace": false, + "values": [ + "unicopia:horseshoe" + ] +}