mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Remove lectern/item frame dropping handling for pre 1.20.60
This commit is contained in:
parent
dc154915f0
commit
8be60b41bf
2 changed files with 34 additions and 111 deletions
|
@ -1,57 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019-2022 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.geyser.translator.protocol.bedrock;
|
|
||||||
|
|
||||||
import org.cloudburstmc.protocol.bedrock.packet.ItemFrameDropItemPacket;
|
|
||||||
import org.geysermc.geyser.entity.type.Entity;
|
|
||||||
import org.geysermc.geyser.entity.type.ItemFrameEntity;
|
|
||||||
import org.geysermc.geyser.session.GeyserSession;
|
|
||||||
import org.geysermc.geyser.translator.protocol.PacketTranslator;
|
|
||||||
import org.geysermc.geyser.translator.protocol.Translator;
|
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand;
|
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.InteractAction;
|
|
||||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundInteractPacket;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pre-1.16.210: used for both survival and creative item frame item removal
|
|
||||||
* <p>
|
|
||||||
* 1.16.210: only used in creative.
|
|
||||||
* 1.20.70: no longer used.
|
|
||||||
*/
|
|
||||||
@Translator(packet = ItemFrameDropItemPacket.class)
|
|
||||||
public class BedrockItemFrameDropItemTranslator extends PacketTranslator<ItemFrameDropItemPacket> {
|
|
||||||
|
|
||||||
// TODO: Remove when 1.20.60 is no longer supported
|
|
||||||
@Override
|
|
||||||
public void translate(GeyserSession session, ItemFrameDropItemPacket packet) {
|
|
||||||
Entity entity = ItemFrameEntity.getItemFrameEntity(session, packet.getBlockPosition());
|
|
||||||
if (entity != null) {
|
|
||||||
ServerboundInteractPacket interactPacket = new ServerboundInteractPacket(entity.getEntityId(),
|
|
||||||
InteractAction.ATTACK, Hand.MAIN_HAND, session.isSneaking());
|
|
||||||
session.sendDownstreamGamePacket(interactPacket);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -25,11 +25,6 @@
|
||||||
|
|
||||||
package org.geysermc.geyser.translator.protocol.bedrock;
|
package org.geysermc.geyser.translator.protocol.bedrock;
|
||||||
|
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction;
|
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand;
|
|
||||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundContainerButtonClickPacket;
|
|
||||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundContainerClosePacket;
|
|
||||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundUseItemOnPacket;
|
|
||||||
import org.cloudburstmc.protocol.bedrock.packet.LecternUpdatePacket;
|
import org.cloudburstmc.protocol.bedrock.packet.LecternUpdatePacket;
|
||||||
import org.geysermc.geyser.inventory.Inventory;
|
import org.geysermc.geyser.inventory.Inventory;
|
||||||
import org.geysermc.geyser.inventory.LecternContainer;
|
import org.geysermc.geyser.inventory.LecternContainer;
|
||||||
|
@ -38,6 +33,8 @@ import org.geysermc.geyser.translator.inventory.LecternInventoryTranslator;
|
||||||
import org.geysermc.geyser.translator.protocol.PacketTranslator;
|
import org.geysermc.geyser.translator.protocol.PacketTranslator;
|
||||||
import org.geysermc.geyser.translator.protocol.Translator;
|
import org.geysermc.geyser.translator.protocol.Translator;
|
||||||
import org.geysermc.geyser.util.InventoryUtils;
|
import org.geysermc.geyser.util.InventoryUtils;
|
||||||
|
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundContainerButtonClickPacket;
|
||||||
|
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundContainerClosePacket;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to translate moving pages, or closing the inventory
|
* Used to translate moving pages, or closing the inventory
|
||||||
|
@ -47,61 +44,44 @@ public class BedrockLecternUpdateTranslator extends PacketTranslator<LecternUpda
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translate(GeyserSession session, LecternUpdatePacket packet) {
|
public void translate(GeyserSession session, LecternUpdatePacket packet) {
|
||||||
// TODO: Remove dropping book check here when 1.20.60 is no longer supported
|
// Bedrock wants to either move a page or exit
|
||||||
if (packet.isDroppingBook()) {
|
if (!(session.getOpenInventory() instanceof LecternContainer lecternContainer)) {
|
||||||
// Bedrock drops the book outside of the GUI. Java drops it in the GUI
|
session.getGeyser().getLogger().debug("Expected lectern but it wasn't open!");
|
||||||
// So, we enter the GUI and then drop it! :)
|
return;
|
||||||
session.setDroppingLecternBook(true);
|
}
|
||||||
|
|
||||||
// Emulate an interact packet
|
if (lecternContainer.getCurrentBedrockPage() == packet.getPage()) {
|
||||||
ServerboundUseItemOnPacket blockPacket = new ServerboundUseItemOnPacket(
|
// The same page means Bedrock is closing the window
|
||||||
packet.getBlockPosition(),
|
ServerboundContainerClosePacket closeWindowPacket = new ServerboundContainerClosePacket(lecternContainer.getJavaId());
|
||||||
Direction.DOWN,
|
session.sendDownstreamGamePacket(closeWindowPacket);
|
||||||
Hand.MAIN_HAND,
|
InventoryUtils.closeInventory(session, lecternContainer.getJavaId(), false);
|
||||||
0, 0, 0, // Java doesn't care about these when dealing with a lectern
|
|
||||||
false,
|
|
||||||
session.getWorldCache().nextPredictionSequence());
|
|
||||||
session.sendDownstreamGamePacket(blockPacket);
|
|
||||||
} else {
|
} else {
|
||||||
// Bedrock wants to either move a page or exit
|
// Each "page" Bedrock gives to us actually represents two pages (think opening a book and seeing two pages)
|
||||||
if (!(session.getOpenInventory() instanceof LecternContainer lecternContainer)) {
|
// Each "page" on Java is just one page (think a spiral notebook folded back to only show one page)
|
||||||
session.getGeyser().getLogger().debug("Expected lectern but it wasn't open!");
|
int newJavaPage = (packet.getPage() * 2);
|
||||||
|
int currentJavaPage = (lecternContainer.getCurrentBedrockPage() * 2);
|
||||||
|
|
||||||
|
// So, fun fact: We need to separately handle fake lecterns!
|
||||||
|
// Since those are not actually a real lectern... the Java server won't respond to our requests.
|
||||||
|
if (!lecternContainer.isUsingRealBlock()) {
|
||||||
|
LecternInventoryTranslator translator = (LecternInventoryTranslator) session.getInventoryTranslator();
|
||||||
|
Inventory inventory = session.getOpenInventory();
|
||||||
|
translator.updateProperty(session, inventory, 0, newJavaPage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lecternContainer.getCurrentBedrockPage() == packet.getPage()) {
|
// Send as many click button packets as we need to
|
||||||
// The same page means Bedrock is closing the window
|
// Java has the option to specify exact page numbers by adding 100 to the number, but buttonId variable
|
||||||
ServerboundContainerClosePacket closeWindowPacket = new ServerboundContainerClosePacket(lecternContainer.getJavaId());
|
// is a byte when transmitted over the network and therefore this stops us at 128
|
||||||
session.sendDownstreamGamePacket(closeWindowPacket);
|
if (newJavaPage > currentJavaPage) {
|
||||||
InventoryUtils.closeInventory(session, lecternContainer.getJavaId(), false);
|
for (int i = currentJavaPage; i < newJavaPage; i++) {
|
||||||
} else {
|
ServerboundContainerButtonClickPacket clickButtonPacket = new ServerboundContainerButtonClickPacket(session.getOpenInventory().getJavaId(), 2);
|
||||||
// Each "page" Bedrock gives to us actually represents two pages (think opening a book and seeing two pages)
|
session.sendDownstreamGamePacket(clickButtonPacket);
|
||||||
// Each "page" on Java is just one page (think a spiral notebook folded back to only show one page)
|
|
||||||
int newJavaPage = (packet.getPage() * 2);
|
|
||||||
int currentJavaPage = (lecternContainer.getCurrentBedrockPage() * 2);
|
|
||||||
|
|
||||||
// So, fun fact: We need to separately handle fake lecterns!
|
|
||||||
// Since those are not actually a real lectern... the Java server won't respond to our requests.
|
|
||||||
if (!lecternContainer.isUsingRealBlock()) {
|
|
||||||
LecternInventoryTranslator translator = (LecternInventoryTranslator) session.getInventoryTranslator();
|
|
||||||
Inventory inventory = session.getOpenInventory();
|
|
||||||
translator.updateProperty(session, inventory, 0, newJavaPage);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
// Send as many click button packets as we need to
|
for (int i = currentJavaPage; i > newJavaPage; i--) {
|
||||||
// Java has the option to specify exact page numbers by adding 100 to the number, but buttonId variable
|
ServerboundContainerButtonClickPacket clickButtonPacket = new ServerboundContainerButtonClickPacket(session.getOpenInventory().getJavaId(), 1);
|
||||||
// is a byte when transmitted over the network and therefore this stops us at 128
|
session.sendDownstreamGamePacket(clickButtonPacket);
|
||||||
if (newJavaPage > currentJavaPage) {
|
|
||||||
for (int i = currentJavaPage; i < newJavaPage; i++) {
|
|
||||||
ServerboundContainerButtonClickPacket clickButtonPacket = new ServerboundContainerButtonClickPacket(session.getOpenInventory().getJavaId(), 2);
|
|
||||||
session.sendDownstreamGamePacket(clickButtonPacket);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (int i = currentJavaPage; i > newJavaPage; i--) {
|
|
||||||
ServerboundContainerButtonClickPacket clickButtonPacket = new ServerboundContainerButtonClickPacket(session.getOpenInventory().getJavaId(), 1);
|
|
||||||
session.sendDownstreamGamePacket(clickButtonPacket);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue