|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package org.geysermc.connector.network.translators.bedrock; |
|
|
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; |
|
import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; |
|
import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace; |
|
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPlaceBlockPacket; |
|
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientClickWindowButtonPacket; |
|
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCloseWindowPacket; |
|
import com.nukkitx.protocol.bedrock.packet.LecternUpdatePacket; |
|
import org.geysermc.connector.inventory.LecternContainer; |
|
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.InventoryUtils; |
|
|
|
|
|
|
|
|
|
@Translator(packet = LecternUpdatePacket.class) |
|
public class BedrockLecternUpdateTranslator extends PacketTranslator<LecternUpdatePacket> { |
|
|
|
@Override |
|
|
|
|
|
|
|
public void translate(GeyserSession session, LecternUpdatePacket packet) { |
|
if (packet.isDroppingBook()) { |
|
|
|
|
|
session.setDroppingLecternBook(true); |
|
|
|
|
|
ClientPlayerPlaceBlockPacket blockPacket = new ClientPlayerPlaceBlockPacket( |
|
new Position(packet.getBlockPosition().getX(), packet.getBlockPosition().getY(), packet.getBlockPosition().getZ()), |
|
BlockFace.DOWN, |
|
Hand.MAIN_HAND, |
|
0, 0, 0, |
|
false); |
|
session.sendDownstreamPacket(blockPacket); |
|
} else { |
|
|
|
if (!(session.getOpenInventory() instanceof LecternContainer)) { |
|
session.getConnector().getLogger().debug("Expected lectern but it wasn't open!"); |
|
return; |
|
} |
|
|
|
LecternContainer lecternContainer = (LecternContainer) session.getOpenInventory(); |
|
if (lecternContainer.getCurrentBedrockPage() == packet.getPage()) { |
|
|
|
ClientCloseWindowPacket closeWindowPacket = new ClientCloseWindowPacket(lecternContainer.getId()); |
|
session.sendDownstreamPacket(closeWindowPacket); |
|
InventoryUtils.closeInventory(session, lecternContainer.getId(), false); |
|
} else { |
|
|
|
|
|
int newJavaPage = (packet.getPage() * 2); |
|
int currentJavaPage = (lecternContainer.getCurrentBedrockPage() * 2); |
|
|
|
|
|
|
|
|
|
if (newJavaPage > currentJavaPage) { |
|
for (int i = currentJavaPage; i < newJavaPage; i++) { |
|
ClientClickWindowButtonPacket clickButtonPacket = new ClientClickWindowButtonPacket(session.getOpenInventory().getId(), 2); |
|
session.sendDownstreamPacket(clickButtonPacket); |
|
} |
|
} else { |
|
for (int i = currentJavaPage; i > newJavaPage; i--) { |
|
ClientClickWindowButtonPacket clickButtonPacket = new ClientClickWindowButtonPacket(session.getOpenInventory().getId(), 1); |
|
session.sendDownstreamPacket(clickButtonPacket); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|