|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package org.geysermc.connector.network.translators.bedrock; |
|
|
|
import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; |
|
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerChangeHeldItemPacket; |
|
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerUseItemPacket; |
|
import com.nukkitx.protocol.bedrock.data.inventory.ContainerId; |
|
import com.nukkitx.protocol.bedrock.packet.MobEquipmentPacket; |
|
import org.geysermc.connector.network.session.GeyserSession; |
|
import org.geysermc.connector.network.translators.PacketTranslator; |
|
import org.geysermc.connector.network.translators.Translator; |
|
import org.geysermc.connector.utils.CooldownUtils; |
|
import org.geysermc.connector.utils.InteractiveTagManager; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
@Translator(packet = MobEquipmentPacket.class) |
|
public class BedrockMobEquipmentTranslator extends PacketTranslator<MobEquipmentPacket> { |
|
|
|
@Override |
|
|
|
|
|
|
|
public void translate(GeyserSession session, MobEquipmentPacket packet) { |
|
if (!session.isSpawned() || packet.getHotbarSlot() > 8 || |
|
packet.getContainerId() != ContainerId.INVENTORY || session.getPlayerInventory().getHeldItemSlot() == packet.getHotbarSlot()) { |
|
|
|
return; |
|
} |
|
|
|
|
|
session.getBookEditCache().checkForSend(); |
|
|
|
session.getPlayerInventory().setHeldItemSlot(packet.getHotbarSlot()); |
|
|
|
ClientPlayerChangeHeldItemPacket changeHeldItemPacket = new ClientPlayerChangeHeldItemPacket(packet.getHotbarSlot()); |
|
session.sendDownstreamPacket(changeHeldItemPacket); |
|
|
|
if (session.isSneaking() && session.getPlayerInventory().getItemInHand().getJavaId() == session.getItemMappings().getStoredItems().shield().getJavaId()) { |
|
|
|
|
|
|
|
session.getConnector().getGeneralThreadPool().schedule(() -> session.sendDownstreamPacket(new ClientPlayerUseItemPacket(Hand.MAIN_HAND)), |
|
50, TimeUnit.MILLISECONDS); |
|
} |
|
|
|
|
|
CooldownUtils.sendCooldown(session); |
|
|
|
|
|
if (session.getMouseoverEntity() != null) { |
|
InteractiveTagManager.updateTag(session, session.getMouseoverEntity()); |
|
} |
|
} |
|
} |
|
|