feat: client mixin
This commit is contained in:
parent
b4bf198af6
commit
021d61ad13
2 changed files with 44 additions and 0 deletions
|
@ -0,0 +1,43 @@
|
|||
package dev.newty.projectileding.mixin.client;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.projectile.PersistentProjectileEntity;
|
||||
import net.minecraft.entity.projectile.ProjectileEntity;
|
||||
import net.minecraft.sound.SoundEvent;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.util.hit.EntityHitResult;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(PersistentProjectileEntity.class)
|
||||
public abstract class PersistentProjectileEntityMixin {
|
||||
@Shadow public abstract void setSound(SoundEvent sound);
|
||||
|
||||
@Inject(method = "onEntityHit", at = @At("HEAD"))
|
||||
private void changeSound(EntityHitResult entityHitResult, CallbackInfo ci) {
|
||||
Entity target = entityHitResult.getEntity();
|
||||
|
||||
// ensure that the target is alive
|
||||
if (target instanceof LivingEntity) {
|
||||
ClientPlayerEntity player = MinecraftClient.getInstance().player;
|
||||
ProjectileEntity projectile = (ProjectileEntity) (Object) this;
|
||||
|
||||
if (player != null && player.equals(projectile.getOwner())) {
|
||||
// change the sound to the custom sound
|
||||
this.setSound(SoundEvents.ENTITY_ARROW_HIT_PLAYER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "onEntityHit", at = @At("TAIL"))
|
||||
private void revertSound(EntityHitResult entityHitResult, CallbackInfo ci) {
|
||||
// revert the sound back to default, even if it hasn't been changed
|
||||
this.setSound(SoundEvents.ENTITY_ARROW_HIT);
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@
|
|||
"compatibilityLevel": "JAVA_21",
|
||||
"minVersion": "0.8",
|
||||
"client": [
|
||||
"client.PersistentProjectileEntityMixin"
|
||||
],
|
||||
"mixins": [
|
||||
],
|
||||
|
|
Loading…
Reference in a new issue