mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-07 22:16:44 +01:00
Standardise sound playing
This commit is contained in:
parent
88ba52efc5
commit
7b60248514
5 changed files with 52 additions and 12 deletions
|
@ -12,12 +12,12 @@ import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
|
||||||
import com.minelittlepony.unicopia.entity.Physics;
|
import com.minelittlepony.unicopia.entity.Physics;
|
||||||
import com.minelittlepony.unicopia.entity.PonyContainer;
|
import com.minelittlepony.unicopia.entity.PonyContainer;
|
||||||
import com.minelittlepony.unicopia.particle.ParticleSource;
|
import com.minelittlepony.unicopia.particle.ParticleSource;
|
||||||
|
import com.minelittlepony.unicopia.util.SoundEmitter;
|
||||||
import com.minelittlepony.unicopia.util.VecHelper;
|
import com.minelittlepony.unicopia.util.VecHelper;
|
||||||
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.sound.SoundEvent;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.world.GameRules;
|
import net.minecraft.world.GameRules;
|
||||||
|
@ -26,7 +26,7 @@ import net.minecraft.world.World;
|
||||||
/**
|
/**
|
||||||
* Interface for any magically capable entities that can cast or persist spells.
|
* Interface for any magically capable entities that can cast or persist spells.
|
||||||
*/
|
*/
|
||||||
public interface Caster<E extends LivingEntity> extends Owned<E>, Levelled, Affine, ParticleSource {
|
public interface Caster<E extends LivingEntity> extends Owned<E>, Levelled, Affine, ParticleSource, SoundEmitter {
|
||||||
|
|
||||||
Physics getPhysics();
|
Physics getPhysics();
|
||||||
|
|
||||||
|
@ -74,10 +74,6 @@ public interface Caster<E extends LivingEntity> extends Owned<E>, Levelled, Affi
|
||||||
return getReferenceWorld().getGameRules().getBoolean(GameRules.DO_MOB_GRIEFING);
|
return getReferenceWorld().getGameRules().getBoolean(GameRules.DO_MOB_GRIEFING);
|
||||||
}
|
}
|
||||||
|
|
||||||
default void playSound(SoundEvent sound, float volume, float pitch) {
|
|
||||||
getReferenceWorld().playSound(null, getEntity().getX(), getEntity().getY(), getEntity().getZ(), sound, getEntity().getSoundCategory(), volume, pitch);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the desired amount of mana or health from this caster in exchange for a spell's benefits.
|
* Removes the desired amount of mana or health from this caster in exchange for a spell's benefits.
|
||||||
* <p>
|
* <p>
|
||||||
|
|
|
@ -30,7 +30,6 @@ import net.minecraft.entity.projectile.ProjectileEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NbtCompound;
|
import net.minecraft.nbt.NbtCompound;
|
||||||
import net.minecraft.particle.ParticleTypes;
|
import net.minecraft.particle.ParticleTypes;
|
||||||
import net.minecraft.sound.SoundCategory;
|
|
||||||
import net.minecraft.sound.SoundEvents;
|
import net.minecraft.sound.SoundEvents;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
@ -183,7 +182,7 @@ public abstract class Living<T extends LivingEntity> implements Equine<T>, Caste
|
||||||
ItemStack broken = UItems.BROKEN_SUNGLASSES.getDefaultStack();
|
ItemStack broken = UItems.BROKEN_SUNGLASSES.getDefaultStack();
|
||||||
broken.setNbt(glasses.getNbt());
|
broken.setNbt(glasses.getNbt());
|
||||||
TrinketsDelegate.getInstance().setEquippedStack(entity, TrinketsDelegate.FACE, broken);
|
TrinketsDelegate.getInstance().setEquippedStack(entity, TrinketsDelegate.FACE, broken);
|
||||||
entity.world.playSound(null, entity.getX(), entity.getY(), entity.getZ(), SoundEvents.BLOCK_GLASS_BREAK, SoundCategory.PLAYERS, 1, 1);
|
playSound(SoundEvents.BLOCK_GLASS_BREAK, 1, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -232,4 +231,15 @@ public abstract class Living<T extends LivingEntity> implements Equine<T>, Caste
|
||||||
public void fromNBT(NbtCompound compound) {
|
public void fromNBT(NbtCompound compound) {
|
||||||
enchants.fromNBT(compound);
|
enchants.fromNBT(compound);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateVelocity() {
|
||||||
|
updateVelocity(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updateVelocity(Entity entity) {
|
||||||
|
entity.velocityModified = true;
|
||||||
|
//if (entity instanceof ServerPlayerEntity ply) {
|
||||||
|
// ply.networkHandler.sendPacket(new EntityVelocityUpdateS2CPacket(ply));
|
||||||
|
//}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.minelittlepony.unicopia.entity.behaviour;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||||
|
import com.minelittlepony.unicopia.util.SoundEmitter;
|
||||||
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.ai.RangedAttackMob;
|
import net.minecraft.entity.ai.RangedAttackMob;
|
||||||
|
@ -35,9 +36,7 @@ public class RangedAttackBehaviour<T extends Entity & RangedAttackMob> extends E
|
||||||
spit.setOwner(player.getMaster());
|
spit.setOwner(player.getMaster());
|
||||||
|
|
||||||
if (!entity.isSilent()) {
|
if (!entity.isSilent()) {
|
||||||
entity.world.playSound(null, entity.getX(), entity.getY(), entity.getZ(),
|
SoundEmitter.playSoundAt(entity, sound, 1, 1 + (entity.world.random.nextFloat() - entity.world.random.nextFloat()) * 0.2F);
|
||||||
sound, entity.getSoundCategory(), 1,
|
|
||||||
1 + (entity.world.random.nextFloat() - entity.world.random.nextFloat()) * 0.2F);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
entity.world.spawnEntity(spit);
|
entity.world.spawnEntity(spit);
|
||||||
|
|
|
@ -4,6 +4,7 @@ import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.projectile.MagicProjectileEntity;
|
import com.minelittlepony.unicopia.projectile.MagicProjectileEntity;
|
||||||
import com.minelittlepony.unicopia.projectile.ProjectileDelegate;
|
import com.minelittlepony.unicopia.projectile.ProjectileDelegate;
|
||||||
|
import com.minelittlepony.unicopia.util.SoundEmitter;
|
||||||
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.entity.projectile.ProjectileEntity;
|
import net.minecraft.entity.projectile.ProjectileEntity;
|
||||||
|
@ -34,7 +35,7 @@ abstract class ProjectileItem extends Item implements ProjectileDelegate {
|
||||||
|
|
||||||
ItemStack stack = player.getStackInHand(hand);
|
ItemStack stack = player.getStackInHand(hand);
|
||||||
|
|
||||||
world.playSound(null, player.getX(), player.getY(), player.getZ(),
|
SoundEmitter.playSoundAt(player,
|
||||||
getThrowSound(stack), SoundCategory.NEUTRAL,
|
getThrowSound(stack), SoundCategory.NEUTRAL,
|
||||||
0.5F,
|
0.5F,
|
||||||
0.4F / (world.random.nextFloat() * 0.4F + 0.8F));
|
0.4F / (world.random.nextFloat() * 0.4F + 0.8F));
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.minelittlepony.unicopia.util;
|
||||||
|
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.sound.SoundCategory;
|
||||||
|
import net.minecraft.sound.SoundEvent;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
public interface SoundEmitter {
|
||||||
|
|
||||||
|
World getReferenceWorld();
|
||||||
|
|
||||||
|
Entity getEntity();
|
||||||
|
|
||||||
|
|
||||||
|
default void playSound(SoundEvent sound, float volume, float pitch) {
|
||||||
|
playSoundAt(getEntity(), sound, volume, pitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void playSound(SoundEvent sound, float volume) {
|
||||||
|
playSound(sound, volume, getRandomPitch());
|
||||||
|
}
|
||||||
|
|
||||||
|
default float getRandomPitch() {
|
||||||
|
return (float)getReferenceWorld().getRandom().nextTriangular(0.5F, 0.2F);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void playSoundAt(Entity entity, SoundEvent sound, float pitch, float volume) {
|
||||||
|
playSoundAt(entity, sound, entity.getSoundCategory(), volume, pitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void playSoundAt(Entity entity, SoundEvent sound, SoundCategory category, float pitch, float volume) {
|
||||||
|
entity.world.playSound(null, entity.getX(), entity.getY(), entity.getZ(), sound, category, volume, pitch);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue