Skip to content

Commit

Permalink
Add advancement for killing mobs with a horseshoe
Browse files Browse the repository at this point in the history
  • Loading branch information
Sollace committed Jan 17, 2024
1 parent 5ac68a3 commit 0c26827
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public interface UDamageTypes {
RegistryKey<DamageType> SUNLIGHT = register("sunlight");
RegistryKey<DamageType> PETRIFIED = register("petrified");
RegistryKey<DamageType> ROCK = register("rock");
RegistryKey<DamageType> HORSESHOE = register("horseshoe");

private static RegistryKey<DamageType> register(String name) {
var key = RegistryKey.of(RegistryKeys.DAMAGE_TYPE, Unicopia.id(name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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;
Expand Down Expand Up @@ -75,6 +76,7 @@ public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> too
@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());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.minelittlepony.unicopia.projectile;

import java.util.Optional;

import org.jetbrains.annotations.Nullable;

import com.minelittlepony.unicopia.USounds;
Expand All @@ -19,6 +21,7 @@
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;
Expand All @@ -27,9 +30,13 @@
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;
Expand All @@ -46,6 +53,8 @@ public class PhysicsBodyProjectileEntity extends PersistentProjectileEntity impl

private int inWaterTime;

private RegistryKey<DamageType> damageType = UDamageTypes.ROCK;

public PhysicsBodyProjectileEntity(EntityType<PhysicsBodyProjectileEntity> type, World world) {
super(type, world);
}
Expand Down Expand Up @@ -74,6 +83,10 @@ public ItemStack getStack() {
return getDataTracker().get(ITEM);
}

public void setDamageType(RegistryKey<DamageType> damageType) {
this.damageType = damageType;
}

@Override
protected ItemStack asItemStack() {
return getStack();
Expand Down Expand Up @@ -149,7 +162,7 @@ public DamageSources getDamageSources() {
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);
}
};
}
Expand Down Expand Up @@ -262,11 +275,17 @@ public void writeCustomDataToNbt(NbtCompound nbt) {
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));
});
}
}
}
8 changes: 7 additions & 1 deletion src/main/resources/assets/unicopia/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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" ]
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@
"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,
"announce_to_chat": true,
"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
}
]
Expand All @@ -31,6 +31,6 @@
}
},
"requirements": [
[ "killed_entity_with_rock" ]
[ "killed_entity_with_horseshoe" ]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"unicopia:horseshoe"
]
}

0 comments on commit 0c26827

Please sign in to comment.