Sounds not playing #2018
-
I'm trying to implement custom sounds for my entity. I've added everything needed, however the sounds don't play in-game. This is the main mod file package net.backrooms.smp.content;
import net.backrooms.smp.content.entity.WrogglerEntity;
import net.backrooms.smp.content.spawns.SpawnInit;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder;
import net.minecraft.entity.EntityDimensions;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.item.FoodComponent;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
public class BackroomsSMP implements ModInitializer {
public static final Item PURE_FLESH = new Item(new Item.Settings().group(ItemGroup.FOOD).food(new FoodComponent.Builder().hunger(5).saturationModifier(3f).meat().build()));
public static final EntityType<WrogglerEntity> WROGGLER = Registry.register(
Registry.ENTITY_TYPE,
new Identifier("backroomssmp", "wroggler"),
FabricEntityTypeBuilder.create(SpawnGroup.MONSTER, WrogglerEntity::new).dimensions(EntityDimensions.fixed(0.6f, 1.99f)).build()
);
public static final Identifier WROGGLER_HURT = new Identifier("backroomssmp:wroggler_hurt1");
public static SoundEvent wroggler_hurt = new SoundEvent(WROGGLER_HURT);
public static final Identifier WROGGLER_AMBIENT = new Identifier("backroomssmp:wroggler_ambient1");
public static SoundEvent wroggler_ambient = new SoundEvent(WROGGLER_AMBIENT);
public static final Identifier WROGGLER_DEATH = new Identifier("backroomssmp:wroggler_death");
public static SoundEvent wroggler_death = new SoundEvent(WROGGLER_DEATH);
@Override
public void onInitialize() {
Registry.register(Registry.ITEM, new Identifier("backroomssmp", "pure_flesh"), PURE_FLESH);
FabricDefaultAttributeRegistry.register(WROGGLER, WrogglerEntity.createWrogglerAttributes());
SpawnInit.init();
Registry.register(Registry.SOUND_EVENT, BackroomsSMP.WROGGLER_HURT, wroggler_hurt);
Registry.register(Registry.SOUND_EVENT, BackroomsSMP.WROGGLER_AMBIENT, wroggler_ambient);
Registry.register(Registry.SOUND_EVENT, BackroomsSMP.WROGGLER_DEATH, wroggler_death);
}
} This is the sound.json file {
"wroggler_hurt1": {
"sounds": [
"backroomssmp:wroggler_hurt1"
]
},
"wroggler_ambient1": {
"sounds": [
"backroomssmp:wroggler_ambient1"
]
},
"wroggler_death": {
"sounds": [
"backroomssmp:wroggler_death"
]
}
} This is the entity file. package net.backrooms.smp.content.entity;
import net.backrooms.smp.content.BackroomsSMP;
import net.minecraft.block.BlockState;
import net.minecraft.entity.EntityGroup;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ai.goal.FollowTargetGoal;
import net.minecraft.entity.ai.goal.LookAroundGoal;
import net.minecraft.entity.ai.goal.LookAtEntityGoal;
import net.minecraft.entity.ai.goal.MeleeAttackGoal;
import net.minecraft.entity.ai.goal.WanderAroundFarGoal;
import net.minecraft.entity.attribute.DefaultAttributeContainer;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.mob.HostileEntity;
import net.minecraft.entity.passive.IronGolemEntity;
import net.minecraft.entity.passive.MerchantEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldView;
public class WrogglerEntity extends HostileEntity{
public boolean wrogglerCanSpawn = true;
public WrogglerEntity(EntityType<? extends HostileEntity> entityType, World world) {
super(entityType, world);
}
protected void initGoals() {
this.goalSelector.add(8, new LookAtEntityGoal(this, PlayerEntity.class, 8.0F));
this.goalSelector.add(8, new LookAroundGoal(this));
this.initCustomGoals();
}
protected void initCustomGoals() {
this.goalSelector.add(2, new MeleeAttackGoal(this, 1.0D, false));
this.goalSelector.add(7, new WanderAroundFarGoal(this, 1.0D));
this.targetSelector.add(2, new FollowTargetGoal<>(this, PlayerEntity.class, true));
this.targetSelector.add(3, new FollowTargetGoal<>(this, MerchantEntity.class, false));
this.targetSelector.add(3, new FollowTargetGoal<>(this, IronGolemEntity.class, true));
}
public static DefaultAttributeContainer.Builder createWrogglerAttributes() {
return HostileEntity.createHostileAttributes()
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 35)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.36D)
.add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 5.0D)
.add(EntityAttributes.GENERIC_MAX_HEALTH, 40)
.add(EntityAttributes.GENERIC_ARMOR, 5.0D);
}
@Override
public boolean canSpawn(WorldView view) {
BlockPos blockunderentity = new BlockPos(this.getX(), this.getY() - 1, this.getZ());
BlockPos posentity = new BlockPos(this.getX(), this.getY(), this.getZ());
return view.intersectsEntities(this) && !world.containsFluid(this.getBoundingBox())
&& this.world.getBlockState(posentity).getBlock().canMobSpawnInside()
&& this.world.getBlockState(blockunderentity).allowsSpawning(view, blockunderentity, BackroomsSMP.WROGGLER)
&& wrogglerCanSpawn;
}
protected SoundEvent getAmbientSound() {
return BackroomsSMP.wroggler_ambient;
}
protected SoundEvent getHurtSound(DamageSource source) {
return BackroomsSMP.wroggler_hurt;
}
protected SoundEvent getDeathSound() {
return BackroomsSMP.wroggler_death;
}
protected SoundEvent getStepSound() {
return SoundEvents.ENTITY_ZOMBIE_STEP;
}
protected void playStepSound(BlockPos pos, BlockState state) {
this.playSound(this.getStepSound(), 0.15F, 1.0F);
}
public EntityGroup getGroup() {
return EntityGroup.UNDEAD;
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The first thing to check is that the sounds are getting loaded. Resource loading doesn't give errors unless there is something seriously wrong.
Failing that, you will just have to debug it to see why the sounds are not playing, either by adding breakpoints, adding log messages at strategic points to print out what is happening, or simulating what minecraft does to load/play the sounds to see if you can find the problem. |
Beta Was this translation helpful? Give feedback.
The first thing to check is that the sounds are getting loaded.
Resource loading doesn't give errors unless there is something seriously wrong.
Instead you get warnings or it will just ignore you if it is confused or doesn't understand.
These will be after where it prints the list of mods when it does the "Reloading Resource Manager"
playsound
commandhttps://minecraft.fandom.com/wiki/Commands/playsound