diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java index 373132c98..602e4edaf 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java @@ -50,6 +50,7 @@ import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.network.translators.Translators; import org.geysermc.connector.network.translators.item.ItemEntry; import org.geysermc.connector.network.translators.item.ItemTranslator; +import org.geysermc.connector.network.translators.sound.EntitySoundInteractionHandler; import org.geysermc.connector.network.translators.world.block.BlockTranslator; import org.geysermc.connector.utils.InventoryUtils; @@ -160,6 +161,8 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator { + + /** + * Handles the block interaction when a player + * right-clicks a block. + * + * @param session the session interacting with the block + * @param position the position of the block + * @param identifier the identifier of the block + */ + static void handleBlockInteraction(GeyserSession session, Vector3f position, String identifier) { + for (Map.Entry> interactionEntry : SoundHandlerRegistry.INTERACTION_HANDLERS.entrySet()) { + if (!(interactionEntry.getValue() instanceof BlockSoundInteractionHandler)) { + continue; + } + if (interactionEntry.getKey().blocks().length != 0) { + boolean contains = false; + for (String blockIdentifier : interactionEntry.getKey().blocks()) { + if (identifier.contains(blockIdentifier)) { + contains = true; + break; + } + } + if (!contains) continue; + } + ItemStack itemInHand = session.getInventory().getItemInHand(); + if (interactionEntry.getKey().items().length != 0) { + if (itemInHand == null || itemInHand.getId() == 0) { + continue; + } + String handIdentifier = Translators.getItemTranslator().getItem(session.getInventory().getItemInHand()).getJavaIdentifier(); + boolean contains = false; + for (String itemIdentifier : interactionEntry.getKey().items()) { + if (handIdentifier.contains(itemIdentifier)) { + contains = true; + break; + } + } + if (!contains) continue; + } + if (session.isSneaking() && !interactionEntry.getKey().ignoreSneakingWhileHolding()) { + if (session.getInventory().getItemInHand() != null && session.getInventory().getItemInHand().getId() != 0) { + continue; + } + } + ((BlockSoundInteractionHandler) interactionEntry.getValue()).handleInteraction(session, position, identifier); + } + } +} diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/sound/EntitySoundInteractionHandler.java b/connector/src/main/java/org/geysermc/connector/network/translators/sound/EntitySoundInteractionHandler.java new file mode 100644 index 000000000..3e0626908 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/sound/EntitySoundInteractionHandler.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2019-2020 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + * + */ + +package org.geysermc.connector.network.translators.sound; + +import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack; +import com.nukkitx.math.vector.Vector3f; +import org.geysermc.connector.entity.Entity; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.Translators; + +import java.util.Map; + +/** + * Sound interaction handler for when an entity is right-clicked. + */ +public interface EntitySoundInteractionHandler extends SoundInteractionHandler { + + /** + * Handles the block interaction when a player + * right-clicks an entity. + * + * @param session the session interacting with the block + * @param position the position of the block + * @param entity the entity interacted with + */ + static void handleEntityInteraction(GeyserSession session, Vector3f position, Entity entity) { + for (Map.Entry> interactionEntry : SoundHandlerRegistry.INTERACTION_HANDLERS.entrySet()) { + if (!(interactionEntry.getValue() instanceof EntitySoundInteractionHandler)) { + continue; + } + if (interactionEntry.getKey().entities().length != 0) { + boolean contains = false; + for (String entityIdentifier : interactionEntry.getKey().entities()) { + if (entity.getEntityType().name().toLowerCase().contains(entityIdentifier)) { + contains = true; + break; + } + } + if (!contains) continue; + } + ItemStack itemInHand = session.getInventory().getItemInHand(); + if (interactionEntry.getKey().items().length != 0) { + if (itemInHand == null || itemInHand.getId() == 0) { + continue; + } + String handIdentifier = Translators.getItemTranslator().getItem(session.getInventory().getItemInHand()).getJavaIdentifier(); + boolean contains = false; + for (String itemIdentifier : interactionEntry.getKey().items()) { + if (handIdentifier.contains(itemIdentifier)) { + contains = true; + break; + } + } + if (!contains) continue; + } + if (session.isSneaking() && !interactionEntry.getKey().ignoreSneakingWhileHolding()) { + if (session.getInventory().getItemInHand() != null && session.getInventory().getItemInHand().getId() != 0) { + continue; + } + } + ((EntitySoundInteractionHandler) interactionEntry.getValue()).handleInteraction(session, position, entity); + } + } +} diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/sound/SoundHandler.java b/connector/src/main/java/org/geysermc/connector/network/translators/sound/SoundHandler.java index 0f22e2ac3..52a76aa3b 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/sound/SoundHandler.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/sound/SoundHandler.java @@ -38,8 +38,10 @@ public @interface SoundHandler { /** * The identifier(s) that the placed block must contain - * one of. - * Leave empty to ignore. + * one of. Leave empty to ignore. + * + * Only applies to interaction handlers that are an + * instance of {@link BlockSoundInteractionHandler}. * * @return the value the interacted block must contain */ @@ -47,13 +49,23 @@ public @interface SoundHandler { /** * The identifier(s) that the player's hand item - * must contain one of. - * Leave empty to ignore. + * must contain one of. Leave empty to ignore. * * @return the value the item in the player's hand must contain */ String[] items() default {}; + /** + * The identifier(s) that the interacted entity must have. + * Leave empty to ignore. + * + * Only applies to interaction handlers that are an + * instance of {@link BlockSoundInteractionHandler}. + * + * @return the value the item in the player's hand must contain + */ + String[] entities() default {}; + /** * Controls if the interaction should still be * called even if the player is sneaking while diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/sound/SoundHandlerRegistry.java b/connector/src/main/java/org/geysermc/connector/network/translators/sound/SoundHandlerRegistry.java index d5187f643..260efb416 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/sound/SoundHandlerRegistry.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/sound/SoundHandlerRegistry.java @@ -36,13 +36,13 @@ import java.util.Map; */ public class SoundHandlerRegistry { - static final Map INTERACTION_HANDLERS = new HashMap<>(); + static final Map> INTERACTION_HANDLERS = new HashMap<>(); static { Reflections ref = new Reflections("org.geysermc.connector.network.translators.sound"); for (Class clazz : ref.getTypesAnnotatedWith(SoundHandler.class)) { try { - SoundInteractionHandler interactionHandler = (SoundInteractionHandler) clazz.newInstance(); + SoundInteractionHandler interactionHandler = (SoundInteractionHandler) clazz.newInstance(); SoundHandler annotation = clazz.getAnnotation(SoundHandler.class); INTERACTION_HANDLERS.put(annotation, interactionHandler); } catch (InstantiationException | IllegalAccessException ex) { @@ -63,7 +63,7 @@ public class SoundHandlerRegistry { * * @return a map of the interaction handlers */ - public static Map getInteractionHandlers() { + public static Map> getInteractionHandlers() { return INTERACTION_HANDLERS; } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/sound/SoundInteractionHandler.java b/connector/src/main/java/org/geysermc/connector/network/translators/sound/SoundInteractionHandler.java index 364b93b8f..e68061ef4 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/sound/SoundInteractionHandler.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/sound/SoundInteractionHandler.java @@ -26,22 +26,20 @@ package org.geysermc.connector.network.translators.sound; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack; import com.nukkitx.math.vector.Vector3f; import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.translators.Translators; - -import java.util.Map; /** * Handler for playing sounds when right-clicking - * blocks. Due to Minecraft: Bedrock Edition + * various objects. Due to Minecraft: Bedrock Edition * expecting interaction sounds to be played serverside * and Minecraft: Java Edition handling them clientside, * this had to be made to handle scenarios like that. + * + * @param the value */ -public interface SoundInteractionHandler { +public interface SoundInteractionHandler { /** * Handles the interaction when a player @@ -49,51 +47,7 @@ public interface SoundInteractionHandler { * * @param session the session interacting with the block * @param position the position of the block - * @param identifier the identifier of the block + * @param value the value */ - void handleInteraction(GeyserSession session, Vector3f position, String identifier); - - /** - * Handles the block interaction when a player - * right-clicks a block. - * - * @param session the session interacting with the block - * @param position the position of the block - * @param identifier the identifier of the block - */ - static void handleBlockInteraction(GeyserSession session, Vector3f position, String identifier) { - for (Map.Entry interactionEntry : SoundHandlerRegistry.INTERACTION_HANDLERS.entrySet()) { - if (interactionEntry.getKey().blocks().length != 0) { - boolean contains = false; - for (String blockIdentifier : interactionEntry.getKey().blocks()) { - if (identifier.contains(blockIdentifier)) { - contains = true; - break; - } - } - if (!contains) continue; - } - ItemStack itemInHand = session.getInventory().getItemInHand(); - if (interactionEntry.getKey().items().length != 0) { - if (itemInHand == null || itemInHand.getId() == 0) { - continue; - } - String handIdentifier = Translators.getItemTranslator().getItem(session.getInventory().getItemInHand()).getJavaIdentifier(); - boolean contains = false; - for (String itemIdentifier : interactionEntry.getKey().items()) { - if (handIdentifier.contains(itemIdentifier)) { - contains = true; - break; - } - } - if (!contains) continue; - } - if (session.isSneaking() && !interactionEntry.getKey().ignoreSneakingWhileHolding()) { - if (session.getInventory().getItemInHand() != null && session.getInventory().getItemInHand().getId() != 0) { - continue; - } - } - interactionEntry.getValue().handleInteraction(session, position, identifier); - } - } + void handleInteraction(GeyserSession session, Vector3f position, T value); } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/sound/BucketSoundInteractionHandler.java b/connector/src/main/java/org/geysermc/connector/network/translators/sound/block/BucketSoundInteractionHandler.java similarity index 90% rename from connector/src/main/java/org/geysermc/connector/network/translators/sound/BucketSoundInteractionHandler.java rename to connector/src/main/java/org/geysermc/connector/network/translators/sound/block/BucketSoundInteractionHandler.java index 4a79d1af0..00269cc7f 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/sound/BucketSoundInteractionHandler.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/sound/block/BucketSoundInteractionHandler.java @@ -24,17 +24,18 @@ * */ -package org.geysermc.connector.network.translators.sound; +package org.geysermc.connector.network.translators.sound.block; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.SoundEvent; import com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket; - import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.Translators; +import org.geysermc.connector.network.translators.sound.BlockSoundInteractionHandler; +import org.geysermc.connector.network.translators.sound.SoundHandler; @SoundHandler(items = "bucket") -public class BucketSoundInteractionHandler implements SoundInteractionHandler { +public class BucketSoundInteractionHandler implements BlockSoundInteractionHandler { @Override public void handleInteraction(GeyserSession session, Vector3f position, String identifier) { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/sound/DoorSoundInteractionHandler.java b/connector/src/main/java/org/geysermc/connector/network/translators/sound/block/DoorSoundInteractionHandler.java similarity index 86% rename from connector/src/main/java/org/geysermc/connector/network/translators/sound/DoorSoundInteractionHandler.java rename to connector/src/main/java/org/geysermc/connector/network/translators/sound/block/DoorSoundInteractionHandler.java index c547292f9..3cf5955f5 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/sound/DoorSoundInteractionHandler.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/sound/block/DoorSoundInteractionHandler.java @@ -24,16 +24,17 @@ * */ -package org.geysermc.connector.network.translators.sound; +package org.geysermc.connector.network.translators.sound.block; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.LevelEventType; import com.nukkitx.protocol.bedrock.packet.LevelEventPacket; - import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.sound.BlockSoundInteractionHandler; +import org.geysermc.connector.network.translators.sound.SoundHandler; @SoundHandler(blocks = "door") -public class DoorSoundInteractionHandler implements SoundInteractionHandler { +public class DoorSoundInteractionHandler implements BlockSoundInteractionHandler { @Override public void handleInteraction(GeyserSession session, Vector3f position, String identifier) { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/sound/FlintAndSteelInteractionHandler.java b/connector/src/main/java/org/geysermc/connector/network/translators/sound/block/FlintAndSteelInteractionHandler.java similarity index 87% rename from connector/src/main/java/org/geysermc/connector/network/translators/sound/FlintAndSteelInteractionHandler.java rename to connector/src/main/java/org/geysermc/connector/network/translators/sound/block/FlintAndSteelInteractionHandler.java index 2a03f4af9..b28133b34 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/sound/FlintAndSteelInteractionHandler.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/sound/block/FlintAndSteelInteractionHandler.java @@ -24,16 +24,17 @@ * */ -package org.geysermc.connector.network.translators.sound; +package org.geysermc.connector.network.translators.sound.block; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.SoundEvent; import com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket; - import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.sound.BlockSoundInteractionHandler; +import org.geysermc.connector.network.translators.sound.SoundHandler; @SoundHandler(items = "flint_and_steel", ignoreSneakingWhileHolding = true) -public class FlintAndSteelInteractionHandler implements SoundInteractionHandler { +public class FlintAndSteelInteractionHandler implements BlockSoundInteractionHandler { @Override public void handleInteraction(GeyserSession session, Vector3f position, String identifier) { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/sound/GrassPathInteractionHandler.java b/connector/src/main/java/org/geysermc/connector/network/translators/sound/block/GrassPathInteractionHandler.java similarity index 88% rename from connector/src/main/java/org/geysermc/connector/network/translators/sound/GrassPathInteractionHandler.java rename to connector/src/main/java/org/geysermc/connector/network/translators/sound/block/GrassPathInteractionHandler.java index 10d1df91a..e29571036 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/sound/GrassPathInteractionHandler.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/sound/block/GrassPathInteractionHandler.java @@ -24,17 +24,18 @@ * */ -package org.geysermc.connector.network.translators.sound; +package org.geysermc.connector.network.translators.sound.block; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.SoundEvent; import com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket; - import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.sound.BlockSoundInteractionHandler; +import org.geysermc.connector.network.translators.sound.SoundHandler; import org.geysermc.connector.network.translators.world.block.BlockTranslator; @SoundHandler(blocks = "grass_path", items = "shovel", ignoreSneakingWhileHolding = true) -public class GrassPathInteractionHandler implements SoundInteractionHandler { +public class GrassPathInteractionHandler implements BlockSoundInteractionHandler { @Override public void handleInteraction(GeyserSession session, Vector3f position, String identifier) { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/sound/block/HoeInteractionHandler.java b/connector/src/main/java/org/geysermc/connector/network/translators/sound/block/HoeInteractionHandler.java new file mode 100644 index 000000000..c9d4299b4 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/sound/block/HoeInteractionHandler.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2019-2020 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + * + */ + +package org.geysermc.connector.network.translators.sound.block; + +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.SoundEvent; +import com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.sound.BlockSoundInteractionHandler; +import org.geysermc.connector.network.translators.sound.SoundHandler; +import org.geysermc.connector.network.translators.world.block.BlockTranslator; + +@SoundHandler(blocks = "farmland", items = "hoe", ignoreSneakingWhileHolding = true) +public class HoeInteractionHandler implements BlockSoundInteractionHandler { + + @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.getUpstream().sendPacket(levelSoundEventPacket); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/sound/LeverSoundInteractionHandler.java b/connector/src/main/java/org/geysermc/connector/network/translators/sound/block/LeverSoundInteractionHandler.java similarity index 86% rename from connector/src/main/java/org/geysermc/connector/network/translators/sound/LeverSoundInteractionHandler.java rename to connector/src/main/java/org/geysermc/connector/network/translators/sound/block/LeverSoundInteractionHandler.java index 0c3b69c5f..0175f9277 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/sound/LeverSoundInteractionHandler.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/sound/block/LeverSoundInteractionHandler.java @@ -24,15 +24,17 @@ * */ -package org.geysermc.connector.network.translators.sound; +package org.geysermc.connector.network.translators.sound.block; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.LevelEventType; import com.nukkitx.protocol.bedrock.packet.LevelEventPacket; import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.sound.BlockSoundInteractionHandler; +import org.geysermc.connector.network.translators.sound.SoundHandler; @SoundHandler(blocks = "lever") -public class LeverSoundInteractionHandler implements SoundInteractionHandler { +public class LeverSoundInteractionHandler implements BlockSoundInteractionHandler { @Override public void handleInteraction(GeyserSession session, Vector3f position, String identifier) { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/sound/entity/MilkCowSoundInteractionHandler.java b/connector/src/main/java/org/geysermc/connector/network/translators/sound/entity/MilkCowSoundInteractionHandler.java new file mode 100644 index 000000000..d4046eea7 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/sound/entity/MilkCowSoundInteractionHandler.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2019-2020 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + * + */ + +package org.geysermc.connector.network.translators.sound.entity; + +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.SoundEvent; +import com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket; +import org.geysermc.connector.entity.Entity; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.Translators; +import org.geysermc.connector.network.translators.sound.EntitySoundInteractionHandler; +import org.geysermc.connector.network.translators.sound.SoundHandler; + +@SoundHandler(entities = "cow", items = "bucket") +public class MilkCowSoundInteractionHandler implements EntitySoundInteractionHandler { + + @Override + public void handleInteraction(GeyserSession session, Vector3f position, Entity value) { + if (!Translators.getItemTranslator().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.getUpstream().sendPacket(levelSoundEventPacket); + } +} diff --git a/connector/src/main/resources/mappings b/connector/src/main/resources/mappings index e28b12703..9d801ea70 160000 --- a/connector/src/main/resources/mappings +++ b/connector/src/main/resources/mappings @@ -1 +1 @@ -Subproject commit e28b127030a81330d9fabef30efda8cbfdf4e5e3 +Subproject commit 9d801ea70edf1ae36f38b91a5c17bf2245315a68