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);
}
}
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);
}
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);
}
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;
}
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);
}
}
Aggregations