3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-03 14:50:19 +01:00

Update to 1.17.1-pre1

Dieser Commit ist enthalten in:
Camotoy 2021-06-20 12:35:48 -04:00
Ursprung 683ac1c763
Commit c60600e0f9
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
6 geänderte Dateien mit 48 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -152,9 +152,9 @@
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.github.GeyserMC</groupId> <groupId>com.github.steveice10</groupId>
<artifactId>MCProtocolLib</artifactId> <artifactId>mcprotocollib</artifactId>
<version>7248769</version> <version>1.17.1-pre1-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
<exclusions> <exclusions>
<exclusion> <exclusion>

Datei anzeigen

@ -40,6 +40,14 @@ public class Inventory {
@Getter @Getter
protected final int id; protected final int id;
/**
* If this is out of sync with the server, the server will resync items.
* Since Java Edition 1.17.1.
*/
@Getter
@Setter
private int stateId;
@Getter @Getter
protected final int size; protected final int size;

Datei anzeigen

@ -37,15 +37,24 @@ import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.network.translators.Translator;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@Translator(packet = BookEditPacket.class) @Translator(packet = BookEditPacket.class)
public class BedrockBookEditTranslator extends PacketTranslator<BookEditPacket> { public class BedrockBookEditTranslator extends PacketTranslator<BookEditPacket> {
private static final int MAXIMUM_PAGE_LENGTH = 8192 * 4;
private static final int MAXIMUM_TITLE_LENGTH = 128 * 4;
@Override @Override
public void translate(BookEditPacket packet, GeyserSession session) { public void translate(BookEditPacket packet, GeyserSession session) {
if (packet.getText() != null && !packet.getText().isEmpty() && packet.getText().getBytes(StandardCharsets.UTF_8).length > MAXIMUM_PAGE_LENGTH) {
session.getConnector().getLogger().warning("Page length greater than server allowed!");
return;
}
GeyserItemStack itemStack = session.getPlayerInventory().getItemInHand(); GeyserItemStack itemStack = session.getPlayerInventory().getItemInHand();
if (itemStack != null) { if (itemStack != null) {
CompoundTag tag = itemStack.getNbt() != null ? itemStack.getNbt() : new CompoundTag(""); CompoundTag tag = itemStack.getNbt() != null ? itemStack.getNbt() : new CompoundTag("");
@ -106,10 +115,29 @@ public class BedrockBookEditTranslator extends PacketTranslator<BookEditPacket>
} }
} }
tag.put(new ListTag("pages", pages)); tag.put(new ListTag("pages", pages));
// Update local copy
session.getPlayerInventory().setItem(36 + session.getPlayerInventory().getHeldItemSlot(), GeyserItemStack.from(bookItem), session); session.getPlayerInventory().setItem(36 + session.getPlayerInventory().getHeldItemSlot(), GeyserItemStack.from(bookItem), session);
session.getInventoryTranslator().updateInventory(session, session.getPlayerInventory()); session.getInventoryTranslator().updateInventory(session, session.getPlayerInventory());
session.getBookEditCache().setPacket(new ClientEditBookPacket(bookItem, packet.getAction() == BookEditPacket.Action.SIGN_BOOK, session.getPlayerInventory().getHeldItemSlot())); List<String> networkPages = new ArrayList<>();
for (Tag pageTag : pages) {
networkPages.add(((StringTag) pageTag).getValue());
}
String title;
if (packet.getAction() == BookEditPacket.Action.SIGN_BOOK) {
// Add title to packet so the server knows we're signing
if (packet.getTitle().getBytes(StandardCharsets.UTF_8).length > MAXIMUM_TITLE_LENGTH) {
session.getConnector().getLogger().warning("Book title larger than server allows!");
return;
}
title = packet.getTitle();
} else {
title = null;
}
session.getBookEditCache().setPacket(new ClientEditBookPacket(session.getPlayerInventory().getHeldItemSlot(), networkPages, title));
// There won't be any more book updates after this, so we can try sending the edit packet immediately // There won't be any more book updates after this, so we can try sending the edit packet immediately
if (packet.getAction() == BookEditPacket.Action.SIGN_BOOK) { if (packet.getAction() == BookEditPacket.Action.SIGN_BOOK) {
session.getBookEditCache().checkForSend(); session.getBookEditCache().checkForSend();

Datei anzeigen

@ -124,6 +124,7 @@ public class ClickPlan {
ClientWindowActionPacket clickPacket = new ClientWindowActionPacket( ClientWindowActionPacket clickPacket = new ClientWindowActionPacket(
inventory.getId(), inventory.getId(),
inventory.getStateId(),
action.slot, action.slot,
action.click.windowAction, action.click.windowAction,
action.click.actionParam, action.click.actionParam,

Datei anzeigen

@ -72,6 +72,8 @@ public class JavaSetSlotTranslator extends PacketTranslator<ServerSetSlotPacket>
if (inventory == null) if (inventory == null)
return; return;
inventory.setStateId(packet.getStateId());
InventoryTranslator translator = session.getInventoryTranslator(); InventoryTranslator translator = session.getInventoryTranslator();
if (translator != null) { if (translator != null) {
if (session.getCraftingGridFuture() != null) { if (session.getCraftingGridFuture() != null) {

Datei anzeigen

@ -44,6 +44,8 @@ public class JavaWindowItemsTranslator extends PacketTranslator<ServerWindowItem
if (inventory == null) if (inventory == null)
return; return;
inventory.setStateId(packet.getStateId());
for (int i = 0; i < packet.getItems().length; i++) { for (int i = 0; i < packet.getItems().length; i++) {
GeyserItemStack newItem = GeyserItemStack.from(packet.getItems()[i]); GeyserItemStack newItem = GeyserItemStack.from(packet.getItems()[i]);
inventory.setItem(i, newItem, session); inventory.setItem(i, newItem, session);
@ -53,6 +55,9 @@ public class JavaWindowItemsTranslator extends PacketTranslator<ServerWindowItem
if (translator != null) { if (translator != null) {
translator.updateInventory(session, inventory); translator.updateInventory(session, inventory);
} }
session.getPlayerInventory().setCursor(GeyserItemStack.from(packet.getCarriedItem()), session);
InventoryUtils.updateCursor(session);
}); });
} }
} }