diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/SoundDataProvider.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/SoundDataProvider.kt index eb5539c1a..79e01991e 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/SoundDataProvider.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/SoundDataProvider.kt @@ -34,6 +34,11 @@ class SoundDataProvider(event: GatherDataEvent) : SoundDefinitionsProvider(event add(MSoundEvents.ANDROID_SHOCKWAVE, definition().subtitle("otm.sound.android.shockwave") .with(SoundDefinition.Sound.sound(modLocation("android/shockwave"), SoundDefinition.SoundType.SOUND))) + + add(MSoundEvents.ANDROID_PROJ_PARRY, + definition().subtitle("otm.sound.android.projectile_parry") + .with(SoundDefinition.Sound.sound(modLocation("android/punch_projectile"), SoundDefinition.SoundType.SOUND)) + ) } private inline fun add(value: SoundEvent, block: SoundDefinition.() -> Unit) { diff --git a/src/main/java/ru/dbotthepony/mc/otm/mixin/MixinAbstractHurtingProjectile.java b/src/main/java/ru/dbotthepony/mc/otm/mixin/MixinAbstractHurtingProjectile.java new file mode 100644 index 000000000..aa61faf9a --- /dev/null +++ b/src/main/java/ru/dbotthepony/mc/otm/mixin/MixinAbstractHurtingProjectile.java @@ -0,0 +1,36 @@ +package ru.dbotthepony.mc.otm.mixin; + +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.projectile.AbstractHurtingProjectile; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import ru.dbotthepony.mc.otm.capability.MatteryCapability; +import ru.dbotthepony.mc.otm.registry.MSoundEvents; + +@Mixin(AbstractHurtingProjectile.class) +public class MixinAbstractHurtingProjectile { + @Inject( + method = "hurt(Lnet/minecraft/world/damagesource/DamageSource;F)Z", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/entity/projectile/AbstractHurtingProjectile;markHurt()V", + ordinal = 0 + ) + ) + public void onProjectileHit(DamageSource pSource, float pAmount, CallbackInfoReturnable cir) { + Entity entity = pSource.getEntity(); + if (entity == null) return; + + entity.getCapability(MatteryCapability.MATTERY_PLAYER).ifPresent(cap -> { + AbstractHurtingProjectile proj = (AbstractHurtingProjectile)(Object)this; + + if (cap.isAndroid() && proj.getOwner() != entity) { + entity.level.playSound(entity, proj.blockPosition(), MSoundEvents.INSTANCE.getANDROID_PROJ_PARRY(), SoundSource.PLAYERS, 1.0f, 0.95f + entity.level.random.nextFloat() * 0.1f); + } + }); + } +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MSoundEvents.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MSoundEvents.kt index 6a92474ae..d1c3d73b7 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MSoundEvents.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MSoundEvents.kt @@ -23,6 +23,7 @@ object MSoundEvents { val ANDROID_JUMP_BOOST: SoundEvent by make("android.jump_boost") val ANDROID_SHOCKWAVE: SoundEvent by make("android.shockwave") + val ANDROID_PROJ_PARRY: SoundEvent by make("android.projectile_parry") internal fun register(bus: IEventBus) { registry.register(bus) diff --git a/src/main/resources/assets/overdrive_that_matters/sounds/android/punch_projectile.ogg b/src/main/resources/assets/overdrive_that_matters/sounds/android/punch_projectile.ogg new file mode 100644 index 000000000..fd1d63941 Binary files /dev/null and b/src/main/resources/assets/overdrive_that_matters/sounds/android/punch_projectile.ogg differ diff --git a/src/main/resources/overdrive_that_matters.mixins.json b/src/main/resources/overdrive_that_matters.mixins.json index 1ff29e66e..c0527a2d9 100644 --- a/src/main/resources/overdrive_that_matters.mixins.json +++ b/src/main/resources/overdrive_that_matters.mixins.json @@ -8,6 +8,7 @@ "mixins": [ "MixinPatchProjectileFinder", "MixinLivingEntity", - "MixinAnvilBlock" + "MixinAnvilBlock", + "MixinAbstractHurtingProjectile" ] }