#Silence Effect does not silence the player

25 messages · Page 1 of 1 (latest)

cosmic fog
#

I'm trying to make a potion of silence, but calling entity.setSilent(true) doesn't do anything :(

package net.magmabits.echoing_depths.util.effects;

import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectCategory;

public class SilenceEffect extends StatusEffect {
    public SilenceEffect(StatusEffectCategory category, int color) {
        super(category, color);
    }

    @Override
    public void applyUpdateEffect(LivingEntity entity, int amplifier) {
        entity.setSilent(true);
    }

    @Override
    public boolean canApplyUpdateEffect(int duration, int amplifier) {
        return true;
    }
}

solar sleet
#

what do you expect it to do

#

what do you expect "silencing" the player to do

cosmic fog
#

to not pick up vibrations

#

sensors and wardens shouldn't be able to pick up vibrations

solar sleet
#

nope. that is not what silence does at all

cosmic fog
#

whar

solar sleet
#

it prevents mobs from making ambient and hurt sounds

cosmic fog
#

ohhh

#

so how do i silence a player then

cosmic fog
solar sleet
#

no, sounds are only coupled with vibrations for gameplay purposes. they're separate events

#

you will want to find where the game emits the various vibration game events, and use a mixin to suppress it most likely. a good place to start would be Vibrations.class

cosmic fog
#

aka

package net.magmabits.echoing_depths.mixin;

import net.magmabits.echoing_depths.util.effects.SilenceEffect;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffectCategory;
import net.minecraft.world.event.GameEvent;
import net.minecraft.world.event.Vibrations;
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;

@Mixin(Vibrations.Callback.class)
public interface VibrationsCallbackMixin {
    @Inject(method = "canAccept", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;isSpectator()Z"), cancellable = true)
    private void returnIfEntityHasCustomEffect(GameEvent gameEvent, GameEvent.Emitter emitter, CallbackInfoReturnable<Boolean> cir) {
        if (emitter.sourceEntity() instanceof LivingEntity livingSourceEntity && livingSourceEntity.hasStatusEffect(new SilenceEffect(StatusEffectCategory.BENEFICIAL, 0x4fd5de))) {
            cir.setReturnValue(false);
        }
    }
}
#

that also does not work

solar sleet
#

I don't think it's quite right to be creating a new StatusEffect every time you check. StatusEffects are types, so you should be using a reference to where you define & register the effect instead

#

eg like how vanilla uses StatusEffects.POISON when it needs to check if an entity has poison

cosmic fog
#

so you mean

package net.magmabits.echoing_depths.mixin;

import net.magmabits.echoing_depths.util.effects.ModEffects;
import net.magmabits.echoing_depths.util.effects.SilenceEffect;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffectCategory;
import net.minecraft.world.event.GameEvent;
import net.minecraft.world.event.Vibrations;
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;

@Mixin(Vibrations.Callback.class)
public interface VibrationsCallbackMixin {
    @Inject(method = "canAccept", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;isSpectator()Z"), cancellable = true)
    private void returnIfEntityHasCustomEffect(GameEvent gameEvent, GameEvent.Emitter emitter, CallbackInfoReturnable<Boolean> cir) {
        if (emitter.sourceEntity() instanceof LivingEntity livingSourceEntity && livingSourceEntity.hasStatusEffect(ModEffects.SILENCE)) {
            cir.setReturnValue(false);
        }
    }
}
``` this?
#

(took so long cuz i added the code for my ModEffects class)

solar sleet
#

yes that looks more correct

#

im on mobile so i can't say for sure whether that is actually where you want to inject or not though

cosmic fog
#

woah it works now!!

#

thank you!

solar sleet
#

👍

#

since you know it works i suggest you change to a modifyreturnvalue. injects are brittle and not very compatible