Skip to content

Commit 4ca2c8e

Browse files
committed
Making more sounds work
1 parent b0e2001 commit 4ca2c8e

2 files changed

Lines changed: 85 additions & 0 deletions

File tree

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package dev.sygii.variantapi.mixin.entity.enderman;
2+
3+
import org.spongepowered.asm.mixin.Mixin;
4+
5+
@Mixin(targets = "net.minecraft.entity.mob.EndermanEntity.TeleportTowardsPlayerGoal")
6+
public abstract class InnerEndermanEntityMixin {
7+
8+
/*@ModifyConstant(
9+
method = "tick",
10+
constant = @Constant(doubleValue = 16.0)
11+
)
12+
private double onCreateChild(double constant) {
13+
return constant;
14+
}
15+
16+
@ModifyConstant(
17+
method = "tick",
18+
constant = @Constant(doubleValue = 256)
19+
)
20+
private double onCreateChild2(double constant) {
21+
return 8.0;
22+
}*/
23+
}

0 commit comments

Comments
 (0)