Как предотвратить проигрышность издавать звуки в Minecraft Fabric 1.21.1?JAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Как предотвратить проигрышность издавать звуки в Minecraft Fabric 1.21.1?

Сообщение Anonymous »

Я пытаюсь сделать мод, который добавляет новый материал, который можно превратить в броню, инструменты, и в какой -то момент некоторые другие вещи. Материал называется вибралом, и он обнаруживается в глубоких темных и древних городах, и дает скрытные бонусы при ношении или удерживании. Я успешно сделал микшин для класса Playentity и класса Entity , чтобы предотвратить воспроизведение звуков плавания. Тем не менее, я могу, казалось бы, что только толпы не воспроизводили какие -либо звуки. < /P>

Код: Выделить всё

PlayerEntityMixin
:

Код: Выделить всё

package net.zadezapper.vibral.mixin;

import net.minecraft.entity.*;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.sound.SoundEvent;
import net.zadezapper.vibral.item.ModItems;
import net.zadezapper.vibral.sound.ModSoundEvents;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(value = PlayerEntity.class, priority = 4096)
public abstract class PlayerEntityMixin {
@Unique
public PlayerEntity entity = ((PlayerEntity)(Object)this);

@Inject(at = @At("HEAD"), method = "getSwimSound", cancellable = true)
public void getSwimSound(CallbackInfoReturnable callbackInfoReturnable) {
if (entity != null) {
if (isWearingFullVibralArmorSet(entity)) {
callbackInfoReturnable.setReturnValue(ModSoundEvents.SILENT);
callbackInfoReturnable.cancel();
}
}
}

@Inject(at = @At("HEAD"), method = "getSplashSound", cancellable = true)
public void getSplashSound(CallbackInfoReturnable callbackInfoReturnable) {
if (entity != null) {
if (isWearingFullVibralArmorSet(entity)) {
callbackInfoReturnable.setReturnValue(ModSoundEvents.SILENT);
callbackInfoReturnable.cancel();
}
}
}

@Inject(at = @At("HEAD"), method = "getHighSpeedSplashSound", cancellable = true)
public void getHighSpeedSplashSound(CallbackInfoReturnable callbackInfoReturnable) {
if (entity != null) {
if (isWearingFullVibralArmorSet(entity)) {
callbackInfoReturnable.setReturnValue(ModSoundEvents.SILENT);
callbackInfoReturnable.cancel();
}
}
}

@Inject(at = @At("HEAD"), method = "getMoveEffect", cancellable = true)
public void getMoveEffect(CallbackInfoReturnable callbackInfoReturnable) {
if (isWearingFullVibralArmorSet(entity)) {
callbackInfoReturnable.setReturnValue(Entity.MoveEffect.EVENTS);
callbackInfoReturnable.cancel();
}
}

@Inject(at = @At("HEAD"), method = "playSound", cancellable = true)
public void playSound(SoundEvent sound, float volume, float pitch, CallbackInfo callbackInfo) {
callbackInfo.cancel();
return;
}

@Unique
private boolean isWearingFullVibralArmorSet(Entity entity) {
if (entity instanceof LivingEntity) {
return (
((LivingEntity) entity).getEquippedStack(EquipmentSlot.HEAD).isOf(ModItems.VIBRAL_HELMET)
&& ((LivingEntity) entity).getEquippedStack(EquipmentSlot.CHEST).isOf(ModItems.VIBRAL_CHESTPLATE)
&& ((LivingEntity) entity).getEquippedStack(EquipmentSlot.LEGS).isOf(ModItems.VIBRAL_LEGGINGS)
&&  ((LivingEntity) entity).getEquippedStack(EquipmentSlot.FEET).isOf(ModItems.VIBRAL_BOOTS)
);
} else {
return false;
}
}

@Unique
private boolean isHoldingVibralTool(Entity entity) {
if (entity instanceof LivingEntity) {
return (
((LivingEntity) entity).getEquippedStack(EquipmentSlot.MAINHAND).isOf(ModItems.VIBRAL_SWORD)
|| ((LivingEntity) entity).getEquippedStack(EquipmentSlot.MAINHAND).isOf(ModItems.VIBRAL_PICKAXE)
|| ((LivingEntity) entity).getEquippedStack(EquipmentSlot.MAINHAND).isOf(ModItems.VIBRAL_AXE)
|| ((LivingEntity) entity).getEquippedStack(EquipmentSlot.MAINHAND).isOf(ModItems.VIBRAL_SHOVEL)
|| ((LivingEntity) entity).getEquippedStack(EquipmentSlot.MAINHAND).isOf(ModItems.VIBRAL_HOE)
);
} else {
return false;
}
}
}
< /code>
EntityMixin
:

Код: Выделить всё

package net.zadezapper.vibral.mixin;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.sound.SoundEvent;
import net.zadezapper.vibral.item.ModItems;
import net.zadezapper.vibral.sound.ModSoundEvents;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(value = Entity.class, priority = 2048)
public abstract class EntityMixin {
@Unique
public Entity entity = ((Entity)(Object)this);

@Inject(at = @At("HEAD"), method = "getSwimSound", cancellable = true)
public void getSwimSound(CallbackInfoReturnable callbackInfoReturnable) {
if (entity != null) {
if (isWearingFullVibralArmorSet(entity)) {
callbackInfoReturnable.setReturnValue(ModSoundEvents.SILENT);
callbackInfoReturnable.cancel();
}
}
}

@Inject(at = @At("HEAD"), method = "getSplashSound", cancellable = true)
public void getSplashSound(CallbackInfoReturnable callbackInfoReturnable) {
if (entity != null) {
if (isWearingFullVibralArmorSet(entity)) {
callbackInfoReturnable.setReturnValue(ModSoundEvents.SILENT);
callbackInfoReturnable.cancel();
}
}
}

@Inject(at = @At("HEAD"), method = "getHighSpeedSplashSound", cancellable = true)
public void getHighSpeedSplashSound(CallbackInfoReturnable callbackInfoReturnable) {
if (entity != null) {
if (isWearingFullVibralArmorSet(entity)) {
callbackInfoReturnable.setReturnValue(ModSoundEvents.SILENT);
callbackInfoReturnable.cancel();
}
}
}

@Inject(at = @At("HEAD"), method = "getMoveEffect", cancellable = true)
public void getMoveEffect(CallbackInfoReturnable callbackInfoReturnable) {
if (isWearingFullVibralArmorSet(entity)) {
callbackInfoReturnable.setReturnValue(Entity.MoveEffect.EVENTS);
callbackInfoReturnable.cancel();
}
}

@Inject(at = @At("HEAD"), method = "isSilent", cancellable = true)
public void isSilent(CallbackInfoReturnable callbackInfoReturnable) {
if (entity != null) {
if (isWearingFullVibralArmorSet(entity)) {
callbackInfoReturnable.setReturnValue(true);
callbackInfoReturnable.cancel();
} else {
callbackInfoReturnable.setReturnValue(false);
}
}
}

@Inject(at = @At("HEAD"), method = "bypassesSteppingEffects", cancellable = true)
public void bypassesSteppingEffects(CallbackInfoReturnable  callbackInfoReturnable) {
if (entity != null) {
if (isWearingFullVibralArmorSet(entity)) {
callbackInfoReturnable.setReturnValue(true);
callbackInfoReturnable.cancel();
}
}
}

@Unique
private boolean isWearingFullVibralArmorSet(Entity entity) {
if (entity instanceof LivingEntity) {
ItemStack headItemStack = ((LivingEntity) entity).getEquippedStack(EquipmentSlot.HEAD);
ItemStack chestItemStack = ((LivingEntity) entity).getEquippedStack(EquipmentSlot.CHEST);
ItemStack legsItemStack = ((LivingEntity) entity).getEquippedStack(EquipmentSlot.LEGS);
ItemStack feetItemStack = ((LivingEntity) entity).getEquippedStack(EquipmentSlot.FEET);

return (headItemStack.isOf(ModItems.VIBRAL_HELMET)
&& chestItemStack.isOf(ModItems.VIBRAL_CHESTPLATE)
&& legsItemStack.isOf(ModItems.VIBRAL_LEGGINGS)
&& feetItemStack.isOf(ModItems.VIBRAL_BOOTS));
} else {
return false;
}
}

@Unique
private boolean isHoldingVibralTool(Entity entity) {
if (entity instanceof LivingEntity) {
return (
((LivingEntity) entity).getEquippedStack(EquipmentSlot.MAINHAND).isOf(ModItems.VIBRAL_SWORD)
|| ((LivingEntity) entity).getEquippedStack(EquipmentSlot.MAINHAND).isOf(ModItems.VIBRAL_PICKAXE)
|| ((LivingEntity) entity).getEquippedStack(EquipmentSlot.MAINHAND).isOf(ModItems.VIBRAL_AXE)
|| ((LivingEntity) entity).getEquippedStack(EquipmentSlot.MAINHAND).isOf(ModItems.VIBRAL_SHOVEL)
|| ((LivingEntity) entity).getEquippedStack(EquipmentSlot.MAINHAND).isOf(ModItems.VIBRAL_HOE)
);
} else {
return false;
}
}
}
< /code>
WorldMixin
:

Код: Выделить всё

package net.zadezapper.vibral.mixin;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.zadezapper.vibral.Vibral;
import net.zadezapper.vibral.item.ModItems;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(value = World.class, priority = 2048)
public abstract class WorldMixin {
@Inject(at = @At("HEAD"), method = "playSound(Lnet/minecraft/entity/player/PlayerEntity;DDDLnet/minecraft/sound/SoundEvent;Lnet/minecraft/sound/SoundCategory;)V", cancellable = true)
public void playSound(PlayerEntity source, double x, double y, double z, SoundEvent sound, SoundCategory category, CallbackInfo callbackInfo) {
if (source != null) {
if (isWearingFullVibralArmorSet(source)) {
Vibral.LOGGER.info(source + " Made sound1: "  + sound.getId().toString());
callbackInfo.cancel();
}
}
}

/*
@Inject(at = @At("HEAD"), method = "playSound(DDDLnet/minecraft/sound/SoundEvent;Lnet/minecraft/sound/SoundCategory;FFZ)V", cancellable = true)
public void playSound(double x, double y, double z, SoundEvent sound, SoundCategory category, float volume, float pitch, boolean useDistance, CallbackInfo callbackInfo) {
if (entity != null) {
if (isWearingFullVibralArmorSet(entity)) {
callbackInfo.cancel();
}
}
}
*/

@Inject(at = @At("HEAD"), method = "playSound(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/sound/SoundEvent;Lnet/minecraft/sound/SoundCategory;FF)V", cancellable = true)
public void playSound(Entity source, BlockPos pos, SoundEvent sound, SoundCategory category, float volume, float pitch, CallbackInfo callbackInfo) {
if (source != null) {
if (isWearingFullVibralArmorSet(source)) {
Vibral.LOGGER.info(source + " Made sound2: " + sound.getId().toString());
callbackInfo.cancel();
}
}
}

@Inject(at = @At("HEAD"), method = "playSound(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/sound/SoundEvent;Lnet/minecraft/sound/SoundCategory;FF)V", cancellable = true)
public void playSound(PlayerEntity source, BlockPos pos, SoundEvent sound, SoundCategory category, float volume, float pitch, CallbackInfo callbackInfo) {
if (source != null) {
if (isWearingFullVibralArmorSet(source)) {
Vibral.LOGGER.info(source + " Made sound3: " + sound.getId().toString());
callbackInfo.cancel();
}
}
}

@Inject(at = @At("HEAD"), method = "playSound(Lnet/minecraft/entity/player/PlayerEntity;DDDLnet/minecraft/sound/SoundEvent;Lnet/minecraft/sound/SoundCategory;FFJ)V", cancellable = true)
public void playSound(PlayerEntity source, double x, double y, double z, SoundEvent sound, SoundCategory category, float volume, float pitch, long seed, CallbackInfo callbackInfo) {
if (source != null) {
if (isWearingFullVibralArmorSet(source)) {
Vibral.LOGGER.info(source + " Made sound4: " + sound.getId().toString());
callbackInfo.cancel();
}
}
}

@Inject(at = @At("HEAD"), method = "playSound(Lnet/minecraft/entity/player/PlayerEntity;DDDLnet/minecraft/sound/SoundEvent;Lnet/minecraft/sound/SoundCategory;FF)V", cancellable = true)
public void playSound(PlayerEntity source, double x, double y, double z, SoundEvent sound, SoundCategory category, float volume, float pitch, CallbackInfo callbackInfo) {
if (source != null) {
if (isWearingFullVibralArmorSet(source)) {
Vibral.LOGGER.info(source + " Made sound5: " + sound.getId().toString());
callbackInfo.cancel();
}
}
}

@Inject(at = @At("HEAD"), method = "playSound(Lnet/minecraft/entity/player/PlayerEntity;DDDLnet/minecraft/registry/entry/RegistryEntry;Lnet/minecraft/sound/SoundCategory;FF)V", cancellable = true)
public void playSound(@Nullable PlayerEntity source, double x, double y, double z, RegistryEntry sound, SoundCategory category, float volume, float pitch, CallbackInfo callbackInfo) {
if (source != null) {
if (isWearingFullVibralArmorSet(source)) {
Vibral.LOGGER.info(source + " Made sound6: " + sound.getIdAsString());
callbackInfo.cancel();
}
}
}

@Unique
private boolean isWearingFullVibralArmorSet(Entity entity) {
if (entity instanceof LivingEntity) {
ItemStack headItemStack = ((LivingEntity) entity).getEquippedStack(EquipmentSlot.HEAD);
ItemStack chestItemStack = ((LivingEntity) entity).getEquippedStack(EquipmentSlot.CHEST);
ItemStack legsItemStack = ((LivingEntity) entity).getEquippedStack(EquipmentSlot.LEGS);
ItemStack feetItemStack = ((LivingEntity) entity).getEquippedStack(EquipmentSlot.FEET);

return (headItemStack.isOf(ModItems.VIBRAL_HELMET)
&& chestItemStack.isOf(ModItems.VIBRAL_CHESTPLATE)
&&  legsItemStack.isOf(ModItems.VIBRAL_LEGGINGS)
&& feetItemStack.isOf(ModItems.VIBRAL_BOOTS));
} else {
return false;
}
}

@Unique
private boolean isHoldingVibralTool(Entity entity) {
if (entity instanceof LivingEntity) {
return (
((LivingEntity) entity).getEquippedStack(EquipmentSlot.MAINHAND).isOf(ModItems.VIBRAL_SWORD)
|| ((LivingEntity) entity).getEquippedStack(EquipmentSlot.MAINHAND).isOf(ModItems.VIBRAL_PICKAXE)
|| ((LivingEntity) entity).getEquippedStack(EquipmentSlot.MAINHAND).isOf(ModItems.VIBRAL_AXE)
|| ((LivingEntity) entity).getEquippedStack(EquipmentSlot.MAINHAND).isOf(ModItems.VIBRAL_SHOVEL)
|| ((LivingEntity) entity).getEquippedStack(EquipmentSlot.MAINHAND).isOf(ModItems.VIBRAL_HOE)
);
} else {
return false;
}
}
}
< /code>
I tried Injecting into the playSound()
Функция в классе Pllayentity , но независимо от того, что я сделал, это не имело никакого эффекта. Размещение CallbackInfo.cancel () и вернуть , как единственное, что там не делало буквально ничего.

Код: Выделить всё

public void playSound(SoundEvent sound, float volume, float pitch) {
this.getWorld().playSound(null, this.getX(), this.getY(), this.getZ(), sound, this.getSoundCategory(), volume, pitch);
}
< /code>
I tried Injecting into the World class which had like 8 different playSound() functions, but that either crashed my game or did nothing.
The playSound()
Функции в World.class :
public void playSound(@Nullable Entity source, BlockPos pos, SoundEvent sound, SoundCategory category, float volume, float pitch) {
this.playSound(source instanceof PlayerEntity playerEntity ? playerEntity : null, pos, sound, category, volume, pitch);
}

@Override
public void playSound(@Nullable PlayerEntity source, BlockPos pos, SoundEvent sound, SoundCategory category, float volume, float pitch) {
this.playSound(source, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, sound, category, volume, pitch);
}

public abstract void playSound(
@Nullable PlayerEntity source, double x, double y, double z, RegistryEntry sound, SoundCategory category, float volume, float pitch, long seed
);

public void playSound(
@Nullable PlayerEntity source, double x, double y, double z, SoundEvent sound, SoundCategory category, float volume, float pitch, long seed
) {
this.playSound(source, x, y, z, Registries.SOUND_EVENT.getEntry(sound), category, volume, pitch, seed);
}

public void playSound(@Nullable PlayerEntity source, double x, double y, double z, SoundEvent sound, SoundCategory category) {
this.playSound(source, x, y, z, sound, category, 1.0F, 1.0F);
}
public void playSound(@Nullable PlayerEntity source, double x, double y, double z, SoundEvent sound, SoundCategory category, float volume, float pitch) {
this.playSound(source, x, y, z, sound, category, volume, pitch, this.threadSafeRandom.nextLong());
}

public void playSound(
@Nullable PlayerEntity source, double x, double y, double z, RegistryEntry sound, SoundCategory category, float volume, float pitch
) {
this.playSound(source, x, y, z, sound, category, volume, pitch, this.threadSafeRandom.nextLong());
}

public void playSound(double x, double y, double z, SoundEvent sound, SoundCategory category, float volume, float pitch, boolean useDistance) {
}
< /code>
The full project can be found on my Github

Подробнее здесь: https://stackoverflow.com/questions/797 ... ric-1-21-1
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»