Search in sources :

Example 1 with SPlaySoundEffectPacket

use of net.minecraft.network.play.server.SPlaySoundEffectPacket in project Magma-1.16.x by magmafoundation.

the class CraftPlayer method playNote.

@Override
public void playNote(Location loc, byte instrument, byte note) {
    if (getHandle().connection == null)
        return;
    String instrumentName = null;
    switch(instrument) {
        case 0:
            instrumentName = "harp";
            break;
        case 1:
            instrumentName = "basedrum";
            break;
        case 2:
            instrumentName = "snare";
            break;
        case 3:
            instrumentName = "hat";
            break;
        case 4:
            instrumentName = "bass";
            break;
        case 5:
            instrumentName = "flute";
            break;
        case 6:
            instrumentName = "bell";
            break;
        case 7:
            instrumentName = "guitar";
            break;
        case 8:
            instrumentName = "chime";
            break;
        case 9:
            instrumentName = "xylophone";
            break;
    }
    float f = (float) Math.pow(2.0D, (note - 12.0D) / 12.0D);
    getHandle().connection.send(new SPlaySoundEffectPacket(CraftSound.getSoundEffect("block.note_block." + instrumentName), net.minecraft.util.SoundCategory.RECORDS, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), 3.0f, f));
}
Also used : SPlaySoundEffectPacket(net.minecraft.network.play.server.SPlaySoundEffectPacket)

Example 2 with SPlaySoundEffectPacket

use of net.minecraft.network.play.server.SPlaySoundEffectPacket in project LoliServer by Loli-Server.

the class CraftPlayer method playSound.

@Override
public void playSound(Location loc, Sound sound, org.bukkit.SoundCategory category, float volume, float pitch) {
    if (loc == null || sound == null || category == null || getHandle().connection == null)
        return;
    SPlaySoundEffectPacket packet = new SPlaySoundEffectPacket(CraftSound.getSoundEffect(sound), net.minecraft.util.SoundCategory.valueOf(category.name()), loc.getX(), loc.getY(), loc.getZ(), volume, pitch);
    getHandle().connection.send(packet);
}
Also used : SPlaySoundEffectPacket(net.minecraft.network.play.server.SPlaySoundEffectPacket)

Example 3 with SPlaySoundEffectPacket

use of net.minecraft.network.play.server.SPlaySoundEffectPacket in project LoliServer by Loli-Server.

the class CraftPlayer method playNote.

@Override
public void playNote(Location loc, byte instrument, byte note) {
    if (getHandle().connection == null)
        return;
    String instrumentName = null;
    switch(instrument) {
        case 0:
            instrumentName = "harp";
            break;
        case 1:
            instrumentName = "basedrum";
            break;
        case 2:
            instrumentName = "snare";
            break;
        case 3:
            instrumentName = "hat";
            break;
        case 4:
            instrumentName = "bass";
            break;
        case 5:
            instrumentName = "flute";
            break;
        case 6:
            instrumentName = "bell";
            break;
        case 7:
            instrumentName = "guitar";
            break;
        case 8:
            instrumentName = "chime";
            break;
        case 9:
            instrumentName = "xylophone";
            break;
    }
    float f = (float) Math.pow(2.0D, (note - 12.0D) / 12.0D);
    getHandle().connection.send(new SPlaySoundEffectPacket(CraftSound.getSoundEffect("block.note_block." + instrumentName), net.minecraft.util.SoundCategory.RECORDS, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), 3.0f, f));
}
Also used : SPlaySoundEffectPacket(net.minecraft.network.play.server.SPlaySoundEffectPacket)

Example 4 with SPlaySoundEffectPacket

use of net.minecraft.network.play.server.SPlaySoundEffectPacket in project Create_Aeronautics by Eriksonnaren.

the class ServerWorldEventMixin method playSound.

/**
 * @author RyanHCode
 */
@Overwrite(remap = false)
public void playSound(@Nullable PlayerEntity pPlayer, double pX, double pY, double pZ, SoundEvent pSound, SoundCategory pCategory, float pVolume, float pPitch) {
    if (((Object) this) instanceof ServerWorld && ((ServerWorld) (Object) this).dimension() == AirshipDimensionManager.WORLD_ID) {
        // get position of entity
        Vector3d pos = new Vector3d(pX, pY, pZ);
        BlockPos bPos = new BlockPos(pos);
        // get airship plot id
        int id = AirshipManager.getIdFromPlotPos(bPos);
        BlockPos plotPos = AirshipManager.getPlotPosFromId(id);
        // get airship
        AirshipContraptionEntity airship = AirshipManager.INSTANCE.AllAirships.get(id);
        if (airship != null) {
            Vector3d position = new Vector3d(bPos.getX(), bPos.getY(), bPos.getZ());
            position = position.subtract(plotPos.getX(), plotPos.getY(), plotPos.getZ());
            position = airship.toGlobalVector(position, 1.0f);
            airship.level.playSound(pPlayer, position.x, position.y, position.z, pSound, pCategory, pVolume, pPitch);
            return;
        }
    }
    net.minecraftforge.event.entity.PlaySoundAtEntityEvent event = net.minecraftforge.event.ForgeEventFactory.onPlaySoundAtEntity(pPlayer, pSound, pCategory, pVolume, pPitch);
    if (event.isCanceled() || event.getSound() == null)
        return;
    pSound = event.getSound();
    pCategory = event.getCategory();
    pVolume = event.getVolume();
    server.getPlayerList().broadcast(pPlayer, pX, pY, pZ, pVolume > 1.0F ? (double) (16.0F * pVolume) : 16.0D, ((ServerWorld) (Object) this).dimension(), new SPlaySoundEffectPacket(pSound, pCategory, pX, pY, pZ, pVolume, pPitch));
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) AirshipContraptionEntity(com.eriksonn.createaeronautics.contraptions.AirshipContraptionEntity) Vector3d(net.minecraft.util.math.vector.Vector3d) BlockPos(net.minecraft.util.math.BlockPos) SPlaySoundEffectPacket(net.minecraft.network.play.server.SPlaySoundEffectPacket) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 5 with SPlaySoundEffectPacket

use of net.minecraft.network.play.server.SPlaySoundEffectPacket in project Magma-1.16.x by magmafoundation.

the class CraftPlayer method playSound.

@Override
public void playSound(Location loc, Sound sound, org.bukkit.SoundCategory category, float volume, float pitch) {
    if (loc == null || sound == null || category == null || getHandle().connection == null)
        return;
    SPlaySoundEffectPacket packet = new SPlaySoundEffectPacket(CraftSound.getSoundEffect(sound), net.minecraft.util.SoundCategory.valueOf(category.name()), loc.getX(), loc.getY(), loc.getZ(), volume, pitch);
    getHandle().connection.send(packet);
}
Also used : SPlaySoundEffectPacket(net.minecraft.network.play.server.SPlaySoundEffectPacket)

Aggregations

SPlaySoundEffectPacket (net.minecraft.network.play.server.SPlaySoundEffectPacket)9 Vector3d (net.minecraft.util.math.vector.Vector3d)2 AirshipContraptionEntity (com.eriksonn.createaeronautics.contraptions.AirshipContraptionEntity)1 ItemEntity (net.minecraft.entity.item.ItemEntity)1 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1 ItemStack (net.minecraft.item.ItemStack)1 CompoundNBT (net.minecraft.nbt.CompoundNBT)1 SPlaySoundPacket (net.minecraft.network.play.server.SPlaySoundPacket)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 SoundEvent (net.minecraft.util.SoundEvent)1 BlockPos (net.minecraft.util.math.BlockPos)1 ServerWorld (net.minecraft.world.server.ServerWorld)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1