|
| 1 | +package dev.sygii.variantapi.mixin.entity.enderman; |
| 2 | + |
| 3 | +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; |
| 4 | +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; |
| 5 | +import dev.sygii.variantapi.acess.EntityAccess; |
| 6 | +import dev.sygii.variantapi.variants.feature.CustomSoundsFeature; |
| 7 | +import dev.sygii.variantapi.variants.feature.server.WaterImmuneFeature; |
| 8 | +import net.minecraft.entity.mob.EndermanEntity; |
| 9 | +import net.minecraft.entity.player.PlayerEntity; |
| 10 | +import net.minecraft.sound.SoundCategory; |
| 11 | +import net.minecraft.sound.SoundEvent; |
| 12 | +import net.minecraft.world.World; |
| 13 | +import org.spongepowered.asm.mixin.Debug; |
| 14 | +import org.spongepowered.asm.mixin.Mixin; |
| 15 | +import org.spongepowered.asm.mixin.injection.At; |
| 16 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 17 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; |
| 18 | + |
| 19 | +@Debug(export = true) |
| 20 | +@Mixin(EndermanEntity.class) |
| 21 | +public abstract class EndermanEntityMixin { |
| 22 | + |
| 23 | + EndermanEntity entity = ((EndermanEntity)(Object)this); |
| 24 | + |
| 25 | + |
| 26 | + @WrapOperation(method = "playAngrySound", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;playSound(DDDLnet/minecraft/sound/SoundEvent;Lnet/minecraft/sound/SoundCategory;FFZ)V")) |
| 27 | + protected void modifyAngrySound(World instance, double x, double y, double z, SoundEvent sound, SoundCategory category, float volume, float pitch, boolean useDistance, Operation<Void> original) { |
| 28 | + |
| 29 | + if (((EntityAccess)entity).getVariant().getFeatures().containsKey(CustomSoundsFeature.ID)) { |
| 30 | + if (((CustomSoundsFeature)((EntityAccess)entity).getVariant().getFeatures().get(CustomSoundsFeature.ID)).getSoundMap().containsKey(sound.getId())) { |
| 31 | + CustomSoundsFeature.CustomSound newSound = ((CustomSoundsFeature)((EntityAccess)entity).getVariant().getFeatures().get(CustomSoundsFeature.ID)).getSoundMap().get(sound.getId()); |
| 32 | + original.call(instance, x, y, z, newSound.event(), category, newSound.volume() == 5.0f ? volume : newSound.volume(), newSound.pitch() == 5.0f ? pitch : newSound.pitch(), useDistance); |
| 33 | + } |
| 34 | + }else { |
| 35 | + original.call(instance, x, y, z, sound, category, volume, pitch, useDistance); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + @WrapOperation(method = "teleportTo(DDD)Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;playSound(Lnet/minecraft/entity/player/PlayerEntity;DDDLnet/minecraft/sound/SoundEvent;Lnet/minecraft/sound/SoundCategory;FF)V")) |
| 40 | + protected void modifyTeleportSound(World instance, PlayerEntity except, double x, double y, double z, SoundEvent sound, SoundCategory category, float volume, float pitch, Operation<Void> original) { |
| 41 | + |
| 42 | + if (((EntityAccess)entity).getVariant().getFeatures().containsKey(CustomSoundsFeature.ID)) { |
| 43 | + if (((CustomSoundsFeature)((EntityAccess)entity).getVariant().getFeatures().get(CustomSoundsFeature.ID)).getSoundMap().containsKey(sound.getId())) { |
| 44 | + CustomSoundsFeature.CustomSound newSound = ((CustomSoundsFeature)((EntityAccess)entity).getVariant().getFeatures().get(CustomSoundsFeature.ID)).getSoundMap().get(sound.getId()); |
| 45 | + original.call(instance, except, x, y, z, newSound.event(), category, newSound.volume() == 5.0f ? volume : newSound.volume(), newSound.pitch() == 5.0f ? pitch : newSound.pitch()); |
| 46 | + } |
| 47 | + }else { |
| 48 | + original.call(instance, except, x, y, z, sound, category, volume, pitch); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + @Inject( |
| 53 | + method = "hurtByWater", |
| 54 | + at = @At(value = "RETURN"), |
| 55 | + cancellable = true |
| 56 | + ) |
| 57 | + private void onCreateChild(CallbackInfoReturnable<Boolean> cir) { |
| 58 | + if ((((EntityAccess)entity).getVariant().getFeatures().containsKey(WaterImmuneFeature.ID))) { |
| 59 | + cir.setReturnValue(false); |
| 60 | + } |
| 61 | + } |
| 62 | +} |
0 commit comments