Java Code Examples for com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket#setRelativeVolumeDisabled()

The following examples show how to use com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket#setRelativeVolumeDisabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MilkCowSoundInteractionHandler.java    From Geyser with MIT License 5 votes vote down vote up
@Override
public void handleInteraction(GeyserSession session, Vector3f position, Entity value) {
    if (!ItemRegistry.getItem(session.getInventory().getItemInHand()).getJavaIdentifier().equals("minecraft:bucket")) {
        return;
    }
    LevelSoundEventPacket levelSoundEventPacket = new LevelSoundEventPacket();
    levelSoundEventPacket.setPosition(position);
    levelSoundEventPacket.setBabySound(false);
    levelSoundEventPacket.setRelativeVolumeDisabled(false);
    levelSoundEventPacket.setIdentifier(":");
    levelSoundEventPacket.setSound(SoundEvent.MILK);
    levelSoundEventPacket.setExtraData(-1);
    session.sendUpstreamPacket(levelSoundEventPacket);
}
 
Example 2
Source File: GrassPathInteractionHandler.java    From Geyser with MIT License 5 votes vote down vote up
@Override
public void handleInteraction(GeyserSession session, Vector3f position, String identifier) {
    LevelSoundEventPacket levelSoundEventPacket = new LevelSoundEventPacket();
    levelSoundEventPacket.setPosition(position);
    levelSoundEventPacket.setBabySound(false);
    levelSoundEventPacket.setRelativeVolumeDisabled(false);
    levelSoundEventPacket.setIdentifier(":");
    levelSoundEventPacket.setSound(SoundEvent.ITEM_USE_ON);
    levelSoundEventPacket.setExtraData(BlockTranslator.getBedrockBlockId(BlockTranslator.getJavaBlockState(identifier)));
    session.sendUpstreamPacket(levelSoundEventPacket);
}
 
Example 3
Source File: BucketSoundInteractionHandler.java    From Geyser with MIT License 5 votes vote down vote up
@Override
public void handleInteraction(GeyserSession session, Vector3f position, String identifier) {
    String handItemIdentifier = ItemRegistry.getItem(session.getInventory().getItemInHand()).getJavaIdentifier();
    LevelSoundEventPacket soundEventPacket = new LevelSoundEventPacket();
    soundEventPacket.setPosition(position);
    soundEventPacket.setIdentifier(":");
    soundEventPacket.setRelativeVolumeDisabled(false);
    soundEventPacket.setBabySound(false);
    soundEventPacket.setExtraData(-1);
    SoundEvent soundEvent = null;
    switch (handItemIdentifier) {
        case "minecraft:bucket":
            if (identifier.contains("water[")) {
                soundEvent = SoundEvent.BUCKET_FILL_WATER;
            } else if (identifier.contains("lava[")) {
                soundEvent = SoundEvent.BUCKET_FILL_LAVA;
            }
            break;
        case "minecraft:lava_bucket":
            soundEvent = SoundEvent.BUCKET_EMPTY_LAVA;
            break;
        case "minecraft:fish_bucket":
            soundEvent = SoundEvent.BUCKET_EMPTY_FISH;
            break;
        case "minecraft:water_bucket":
            soundEvent = SoundEvent.BUCKET_EMPTY_WATER;
            break;
    }
    if (soundEvent != null) {
        soundEventPacket.setSound(soundEvent);
        session.sendUpstreamPacket(soundEventPacket);
    }
}
 
Example 4
Source File: HoeInteractionHandler.java    From Geyser with MIT License 5 votes vote down vote up
@Override
public void handleInteraction(GeyserSession session, Vector3f position, String identifier) {
    LevelSoundEventPacket levelSoundEventPacket = new LevelSoundEventPacket();
    levelSoundEventPacket.setPosition(position);
    levelSoundEventPacket.setBabySound(false);
    levelSoundEventPacket.setRelativeVolumeDisabled(false);
    levelSoundEventPacket.setIdentifier(":");
    levelSoundEventPacket.setSound(SoundEvent.ITEM_USE_ON);
    levelSoundEventPacket.setExtraData(BlockTranslator.getBedrockBlockId(BlockTranslator.getJavaBlockState(identifier)));
    session.sendUpstreamPacket(levelSoundEventPacket);
}
 
Example 5
Source File: FlintAndSteelInteractionHandler.java    From Geyser with MIT License 5 votes vote down vote up
@Override
public void handleInteraction(GeyserSession session, Vector3f position, String identifier) {
    LevelSoundEventPacket levelSoundEventPacket = new LevelSoundEventPacket();
    levelSoundEventPacket.setPosition(position);
    levelSoundEventPacket.setBabySound(false);
    levelSoundEventPacket.setRelativeVolumeDisabled(false);
    levelSoundEventPacket.setIdentifier(":");
    levelSoundEventPacket.setSound(SoundEvent.IGNITE);
    levelSoundEventPacket.setExtraData(-1);
    session.sendUpstreamPacket(levelSoundEventPacket);
}
 
Example 6
Source File: LevelSoundEvent3Serializer_v354.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, LevelSoundEventPacket packet) {
    packet.setSound(SOUNDS.get(VarInts.readUnsignedInt(buffer)));
    packet.setPosition(BedrockUtils.readVector3f(buffer));
    packet.setExtraData(VarInts.readInt(buffer));
    packet.setIdentifier(BedrockUtils.readString(buffer));
    packet.setBabySound(buffer.readBoolean());
    packet.setRelativeVolumeDisabled(buffer.readBoolean());
}
 
Example 7
Source File: LevelSoundEvent3Serializer_v388.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, LevelSoundEventPacket packet) {
    packet.setSound(SOUNDS.get(VarInts.readUnsignedInt(buffer)));
    packet.setPosition(BedrockUtils.readVector3f(buffer));
    packet.setExtraData(VarInts.readInt(buffer));
    packet.setIdentifier(BedrockUtils.readString(buffer));
    packet.setBabySound(buffer.readBoolean());
    packet.setRelativeVolumeDisabled(buffer.readBoolean());
}
 
Example 8
Source File: LevelSoundEvent3Serializer_v340.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, LevelSoundEventPacket packet) {
    packet.setSound(SOUNDS.get(VarInts.readUnsignedInt(buffer)));
    packet.setPosition(BedrockUtils.readVector3f(buffer));
    packet.setExtraData(VarInts.readInt(buffer));
    packet.setIdentifier(BedrockUtils.readString(buffer));
    packet.setBabySound(buffer.readBoolean());
    packet.setRelativeVolumeDisabled(buffer.readBoolean());
}
 
Example 9
Source File: LevelSoundEvent3Serializer_v361.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, LevelSoundEventPacket packet) {
    packet.setSound(SOUNDS.get(VarInts.readUnsignedInt(buffer)));
    packet.setPosition(BedrockUtils.readVector3f(buffer));
    packet.setExtraData(VarInts.readInt(buffer));
    packet.setIdentifier(BedrockUtils.readString(buffer));
    packet.setBabySound(buffer.readBoolean());
    packet.setRelativeVolumeDisabled(buffer.readBoolean());
}
 
Example 10
Source File: LevelSoundEvent3Serializer_v332.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, LevelSoundEventPacket packet) {
    packet.setSound(SOUNDS.get(VarInts.readUnsignedInt(buffer)));
    packet.setPosition(BedrockUtils.readVector3f(buffer));
    packet.setExtraData(VarInts.readInt(buffer));
    packet.setIdentifier(BedrockUtils.readString(buffer));
    packet.setBabySound(buffer.readBoolean());
    packet.setRelativeVolumeDisabled(buffer.readBoolean());
}
 
Example 11
Source File: JavaPlayBuiltinSoundTranslator.java    From Geyser with MIT License 4 votes vote down vote up
@Override
public void translate(ServerPlayBuiltinSoundPacket packet, GeyserSession session) {
    String packetSound = packet.getSound().getName();

    SoundRegistry.SoundMapping soundMapping = SoundRegistry.fromJava(packetSound);
    if (soundMapping == null) {
        session.getConnector().getLogger().debug("[Builtin] Sound mapping " + packetSound + " not found - " + packet.toString());
        return;
    }

    if (soundMapping.isLevelEvent()) {
        LevelEventPacket levelEventPacket = new LevelEventPacket();
        levelEventPacket.setPosition(Vector3f.from(packet.getX(), packet.getY(), packet.getZ()));
        levelEventPacket.setData(0);
        levelEventPacket.setType(LevelEventType.valueOf(soundMapping.getBedrock()));
        session.sendUpstreamPacket(levelEventPacket);
        return;
    }
    LevelSoundEventPacket soundPacket = new LevelSoundEventPacket();
    SoundEvent sound = SoundRegistry.toSoundEvent(soundMapping.getBedrock());
    if (sound == null) {
        sound = SoundRegistry.toSoundEvent(soundMapping.getBedrock());
    }
    if (sound == null) {
        sound = SoundRegistry.toSoundEvent(packetSound);
    }
    if (sound == null) {
        session.getConnector().getLogger().debug("[Builtin] Sound for original " + packetSound + " to mappings " + soundPacket
                        + " was not a playable level sound, or has yet to be mapped to an enum in "
                        + "NukkitX SoundEvent ");

    }
    soundPacket.setSound(sound);
    soundPacket.setPosition(Vector3f.from(packet.getX(), packet.getY(), packet.getZ()));
    soundPacket.setIdentifier(soundMapping.getIdentifier());
    if (sound == SoundEvent.NOTE) {
        // Minecraft Wiki: 2^(x/12) = Java pitch where x is -12 to 12
        // Java sends the note value as above starting with -12 and ending at 12
        // Bedrock has a number for each type of note, then proceeds up the scale by adding to that number
        soundPacket.setExtraData(soundMapping.getExtraData() + (int)(Math.round((Math.log10(packet.getPitch()) / Math.log10(2)) * 12)) + 12);
    } else if (sound == SoundEvent.PLACE && soundMapping.getExtraData() == -1) {
        soundPacket.setExtraData(BlockTranslator.getBedrockBlockId(BlockTranslator.getJavaBlockState(soundMapping.getIdentifier())));
        soundPacket.setIdentifier(":");
    } else {
        soundPacket.setExtraData(soundMapping.getExtraData());
    }


    soundPacket.setBabySound(false); // might need to adjust this in the future
    soundPacket.setRelativeVolumeDisabled(false);
    session.sendUpstreamPacket(soundPacket);
}