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

The following examples show how to use com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket#setBabySound() . 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: GeyserBukkitBlockPlaceListener.java    From Geyser with MIT License 6 votes vote down vote up
@EventHandler
public void place(final BlockPlaceEvent event) {
    for (GeyserSession session : connector.getPlayers().values()) {
        if (event.getPlayer() == Bukkit.getPlayer(session.getPlayerEntity().getUsername())) {
            LevelSoundEventPacket placeBlockSoundPacket = new LevelSoundEventPacket();
            placeBlockSoundPacket.setSound(SoundEvent.PLACE);
            placeBlockSoundPacket.setPosition(Vector3f.from(event.getBlockPlaced().getX(), event.getBlockPlaced().getY(), event.getBlockPlaced().getZ()));
            placeBlockSoundPacket.setBabySound(false);
            String javaBlockId;
            if (isLegacy) {
                javaBlockId = BlockTranslator.getJavaIdBlockMap().inverse().get(GeyserBukkitWorldManager.getLegacyBlock(session,
                        event.getBlockPlaced().getX(), event.getBlockPlaced().getY(), event.getBlockPlaced().getZ(), isViaVersion));
            } else {
                javaBlockId = event.getBlockPlaced().getBlockData().getAsString();
            }
            placeBlockSoundPacket.setExtraData(BlockTranslator.getBedrockBlockId(BlockTranslator.getJavaIdBlockMap().get(javaBlockId)));
            placeBlockSoundPacket.setIdentifier(":");
            session.sendUpstreamPacket(placeBlockSoundPacket);
            session.setLastBlockPlacePosition(null);
            session.setLastBlockPlacedId(null);
            break;
        }
    }
}
 
Example 2
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 3
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 4
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 5
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 6
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 7
Source File: JavaBlockChangeTranslator.java    From Geyser with MIT License 5 votes vote down vote up
private boolean checkPlace(GeyserSession session, ServerBlockChangePacket packet) {
    Vector3i lastPlacePos = session.getLastBlockPlacePosition();
    if (lastPlacePos == null) {
        return false;
    }
    if ((lastPlacePos.getX() != packet.getRecord().getPosition().getX()
            || lastPlacePos.getY() != packet.getRecord().getPosition().getY()
            || lastPlacePos.getZ() != packet.getRecord().getPosition().getZ())) {
        return false;
    }

    // We need to check if the identifier is the same, else a packet with the sound of what the
    // player has in their hand is played, despite if the block is being placed or not
    boolean contains = false;
    String identifier = BlockTranslator.getJavaIdBlockMap().inverse().get(packet.getRecord().getBlock()).split("\\[")[0];
    if (identifier.equals(session.getLastBlockPlacedId())) {
        contains = true;
    }

    if (!contains) {
        session.setLastBlockPlacePosition(null);
        session.setLastBlockPlacedId(null);
        return false;
    }

    // This is not sent from the server, so we need to send it this way
    LevelSoundEventPacket placeBlockSoundPacket = new LevelSoundEventPacket();
    placeBlockSoundPacket.setSound(SoundEvent.PLACE);
    placeBlockSoundPacket.setPosition(lastPlacePos.toFloat());
    placeBlockSoundPacket.setBabySound(false);
    placeBlockSoundPacket.setExtraData(BlockTranslator.getBedrockBlockId(packet.getRecord().getBlock()));
    placeBlockSoundPacket.setIdentifier(":");
    session.sendUpstreamPacket(placeBlockSoundPacket);
    session.setLastBlockPlacePosition(null);
    session.setLastBlockPlacedId(null);
    return true;
}
 
Example 8
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 9
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 10
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 11
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 12
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 13
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);
}