Search in sources :

Example 1 with LevelSoundEventPacket

use of com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket in project Geyser by GeyserMC.

the class BucketSoundInteractionTranslator method translate.

@Override
public void translate(GeyserSession session, Vector3f position, String identifier) {
    if (session.getBucketScheduledFuture() == null) {
        // No bucket was really interacted with
        return;
    }
    GeyserItemStack itemStack = session.getPlayerInventory().getItemInHand();
    String handItemIdentifier = itemStack.getMapping(session).getJavaIdentifier();
    if (!BlockSoundInteractionTranslator.canInteract(session, itemStack, identifier)) {
        return;
    }
    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;
            } else if (identifier.contains("powder_snow")) {
                soundEvent = SoundEvent.BUCKET_FILL_POWDER_SNOW;
            }
            break;
        case "minecraft:lava_bucket":
            soundEvent = SoundEvent.BUCKET_EMPTY_LAVA;
            break;
        case "minecraft:axolotl_bucket":
        case "minecraft:cod_bucket":
        case "minecraft:salmon_bucket":
        case "minecraft:pufferfish_bucket":
        case "minecraft:tropical_fish_bucket":
            soundEvent = SoundEvent.BUCKET_EMPTY_FISH;
            break;
        case "minecraft:water_bucket":
            soundEvent = SoundEvent.BUCKET_EMPTY_WATER;
            break;
        case "minecraft:powder_snow_bucket":
            soundEvent = SoundEvent.BUCKET_EMPTY_POWDER_SNOW;
            break;
    }
    if (soundEvent != null) {
        soundEventPacket.setSound(soundEvent);
        session.sendUpstreamPacket(soundEventPacket);
        session.setBucketScheduledFuture(null);
    }
}
Also used : SoundEvent(com.nukkitx.protocol.bedrock.data.SoundEvent) LevelSoundEventPacket(com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket) GeyserItemStack(org.geysermc.geyser.inventory.GeyserItemStack)

Example 2 with LevelSoundEventPacket

use of com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket in project Geyser by GeyserMC.

the class GrassPathInteractionTranslator method translate.

@Override
public void translate(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(session.getBlockMappings().getBedrockBlockId(BlockRegistries.JAVA_IDENTIFIERS.get(identifier)));
    session.sendUpstreamPacket(levelSoundEventPacket);
}
Also used : LevelSoundEventPacket(com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket)

Example 3 with LevelSoundEventPacket

use of com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket in project Geyser by GeyserMC.

the class GeyserSpigotBlockPlaceListener method place.

@EventHandler
public void place(final BlockPlaceEvent event) {
    GeyserSession session = geyser.connectionByUuid(event.getPlayer().getUniqueId());
    if (session == null) {
        return;
    }
    LevelSoundEventPacket placeBlockSoundPacket = new LevelSoundEventPacket();
    placeBlockSoundPacket.setSound(SoundEvent.PLACE);
    placeBlockSoundPacket.setPosition(Vector3f.from(event.getBlockPlaced().getX(), event.getBlockPlaced().getY(), event.getBlockPlaced().getZ()));
    placeBlockSoundPacket.setBabySound(false);
    if (worldManager.isLegacy()) {
        placeBlockSoundPacket.setExtraData(session.getBlockMappings().getBedrockBlockId(worldManager.getBlockAt(session, event.getBlockPlaced().getX(), event.getBlockPlaced().getY(), event.getBlockPlaced().getZ())));
    } else {
        String javaBlockId = event.getBlockPlaced().getBlockData().getAsString();
        placeBlockSoundPacket.setExtraData(session.getBlockMappings().getBedrockBlockId(BlockRegistries.JAVA_IDENTIFIERS.get().getOrDefault(javaBlockId, BlockStateValues.JAVA_AIR_ID)));
    }
    placeBlockSoundPacket.setIdentifier(":");
    session.sendUpstreamPacket(placeBlockSoundPacket);
    session.setLastBlockPlacePosition(null);
    session.setLastBlockPlacedId(null);
}
Also used : GeyserSession(org.geysermc.geyser.session.GeyserSession) LevelSoundEventPacket(com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket) EventHandler(org.bukkit.event.EventHandler)

Example 4 with LevelSoundEventPacket

use of com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket in project Geyser by GeyserMC.

the class JavaBlockUpdateTranslator method checkPlace.

private boolean checkPlace(GeyserSession session, ClientboundBlockUpdatePacket packet) {
    Vector3i lastPlacePos = session.getLastBlockPlacePosition();
    if (lastPlacePos == null) {
        return false;
    }
    if ((lastPlacePos.getX() != packet.getEntry().getPosition().getX() || lastPlacePos.getY() != packet.getEntry().getPosition().getY() || lastPlacePos.getZ() != packet.getEntry().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 = BlockRegistries.JAVA_BLOCKS.get(packet.getEntry().getBlock()).getItemIdentifier();
    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(session.getBlockMappings().getBedrockBlockId(packet.getEntry().getBlock()));
    placeBlockSoundPacket.setIdentifier(":");
    session.sendUpstreamPacket(placeBlockSoundPacket);
    session.setLastBlockPlacePosition(null);
    session.setLastBlockPlacedId(null);
    return true;
}
Also used : Vector3i(com.nukkitx.math.vector.Vector3i) LevelSoundEventPacket(com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket)

Example 5 with LevelSoundEventPacket

use of com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket in project Geyser by GeyserMC.

the class JavaExplodeTranslator method translate.

@Override
public void translate(GeyserSession session, ClientboundExplodePacket packet) {
    for (Position position : packet.getExploded()) {
        Vector3i pos = Vector3i.from(packet.getX() + position.getX(), packet.getY() + position.getY(), packet.getZ() + position.getZ());
        ChunkUtils.updateBlock(session, BlockStateValues.JAVA_AIR_ID, pos);
    }
    Vector3f pos = Vector3f.from(packet.getX(), packet.getY(), packet.getZ());
    // Since bedrock does not play an explosion sound and particles sound, we have to manually do so
    LevelEventPacket levelEventPacket = new LevelEventPacket();
    levelEventPacket.setType(packet.getRadius() >= 2.0f ? LevelEventType.PARTICLE_HUGE_EXPLODE : LevelEventType.PARTICLE_EXPLOSION);
    levelEventPacket.setData(0);
    levelEventPacket.setPosition(pos);
    session.sendUpstreamPacket(levelEventPacket);
    LevelSoundEventPacket levelSoundEventPacket = new LevelSoundEventPacket();
    levelSoundEventPacket.setRelativeVolumeDisabled(false);
    levelSoundEventPacket.setBabySound(false);
    levelSoundEventPacket.setExtraData(-1);
    levelSoundEventPacket.setSound(SoundEvent.EXPLODE);
    levelSoundEventPacket.setIdentifier(":");
    levelSoundEventPacket.setPosition(pos);
    session.sendUpstreamPacket(levelSoundEventPacket);
    if (packet.getPushX() != 0f || packet.getPushY() != 0f || packet.getPushZ() != 0f) {
        SetEntityMotionPacket motionPacket = new SetEntityMotionPacket();
        motionPacket.setRuntimeEntityId(session.getPlayerEntity().getGeyserId());
        motionPacket.setMotion(Vector3f.from(packet.getPushX(), packet.getPushY(), packet.getPushZ()));
        session.sendUpstreamPacket(motionPacket);
    }
}
Also used : SetEntityMotionPacket(com.nukkitx.protocol.bedrock.packet.SetEntityMotionPacket) Position(com.github.steveice10.mc.protocol.data.game.entity.metadata.Position) LevelEventPacket(com.nukkitx.protocol.bedrock.packet.LevelEventPacket) Vector3f(com.nukkitx.math.vector.Vector3f) Vector3i(com.nukkitx.math.vector.Vector3i) LevelSoundEventPacket(com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket)

Aggregations

LevelSoundEventPacket (com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket)8 Vector3i (com.nukkitx.math.vector.Vector3i)2 SoundEvent (com.nukkitx.protocol.bedrock.data.SoundEvent)2 LevelEventPacket (com.nukkitx.protocol.bedrock.packet.LevelEventPacket)2 Position (com.github.steveice10.mc.protocol.data.game.entity.metadata.Position)1 Vector3f (com.nukkitx.math.vector.Vector3f)1 SetEntityMotionPacket (com.nukkitx.protocol.bedrock.packet.SetEntityMotionPacket)1 EventHandler (org.bukkit.event.EventHandler)1 GeyserItemStack (org.geysermc.geyser.inventory.GeyserItemStack)1 SoundMapping (org.geysermc.geyser.registry.type.SoundMapping)1 GeyserSession (org.geysermc.geyser.session.GeyserSession)1