3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-19 14:30:17 +01:00
Dieser Commit ist enthalten in:
AJ Ferguson 2024-04-21 01:09:23 -04:00 committet von Camotoy
Ursprung 8bd2df0828
Commit ab8832b771
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
3 geänderte Dateien mit 29 neuen und 29 gelöschten Zeilen

Datei anzeigen

@ -69,7 +69,7 @@ public class BedrockBlockPickRequestTranslator extends PacketTranslator<BlockPic
BlockMapping blockMapping = BlockRegistries.JAVA_BLOCKS.getOrDefault(blockToPick, BlockMapping.DEFAULT); BlockMapping blockMapping = BlockRegistries.JAVA_BLOCKS.getOrDefault(blockToPick, BlockMapping.DEFAULT);
boolean addNbtData = packet.isAddUserData() && blockMapping.isBlockEntity(); // Holding down CTRL boolean addNbtData = packet.isAddUserData() && blockMapping.isBlockEntity(); // Holding down CTRL
if (BlockStateValues.getBannerColor(blockToPick) != -1 || addNbtData) { /*if (BlockStateValues.getBannerColor(blockToPick) != -1 || addNbtData) { //TODO
session.getGeyser().getWorldManager().getPickItemNbt(session, vector.getX(), vector.getY(), vector.getZ(), addNbtData) session.getGeyser().getWorldManager().getPickItemNbt(session, vector.getX(), vector.getY(), vector.getZ(), addNbtData)
.whenComplete((tag, ex) -> session.ensureInEventLoop(() -> { .whenComplete((tag, ex) -> session.ensureInEventLoop(() -> {
if (tag == null) { if (tag == null) {
@ -94,7 +94,7 @@ public class BedrockBlockPickRequestTranslator extends PacketTranslator<BlockPic
InventoryUtils.findOrCreateItem(session, itemStack); InventoryUtils.findOrCreateItem(session, itemStack);
})); }));
return; return;
} }*/
pickItem(session, blockMapping); pickItem(session, blockMapping);
} }

Datei anzeigen

@ -26,13 +26,11 @@
package org.geysermc.geyser.translator.protocol.bedrock; package org.geysermc.geyser.translator.protocol.bedrock;
import com.github.steveice10.mc.protocol.data.game.item.ItemStack; import com.github.steveice10.mc.protocol.data.game.item.ItemStack;
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponentType;
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents; import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents;
import com.github.steveice10.mc.protocol.data.game.item.component.Filterable;
import com.github.steveice10.mc.protocol.data.game.item.component.WritableBookContent; import com.github.steveice10.mc.protocol.data.game.item.component.WritableBookContent;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundEditBookPacket; import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundEditBookPacket;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import org.cloudburstmc.protocol.bedrock.packet.BookEditPacket; import org.cloudburstmc.protocol.bedrock.packet.BookEditPacket;
import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.inventory.GeyserItemStack;
import org.geysermc.geyser.item.type.WrittenBookItem; import org.geysermc.geyser.item.type.WrittenBookItem;
@ -57,8 +55,14 @@ public class BedrockBookEditTranslator extends PacketTranslator<BookEditPacket>
if (itemStack != null) { if (itemStack != null) {
DataComponents components = itemStack.getComponents() != null ? itemStack.getComponents() : new DataComponents(new HashMap<>()); DataComponents components = itemStack.getComponents() != null ? itemStack.getComponents() : new DataComponents(new HashMap<>());
ItemStack bookItem = new ItemStack(itemStack.getJavaId(), itemStack.getAmount(), components); ItemStack bookItem = new ItemStack(itemStack.getJavaId(), itemStack.getAmount(), components);
WritableBookContent List<String> pages = new LinkedList<>();
List<Tag> pages = tag.contains("pages") ? new LinkedList<>(((ListTag) tag.get("pages")).getValue()) : new LinkedList<>();
WritableBookContent writableBookContent = components.get(DataComponentType.WRITABLE_BOOK_CONTENT);
if (writableBookContent != null) {
for (Filterable<String> page : writableBookContent.getPages()) {
pages.add(page.getRaw());
}
}
int page = packet.getPageNumber(); int page = packet.getPageNumber();
if (page < 0 || WrittenBookItem.MAXIMUM_PAGE_COUNT <= page) { if (page < 0 || WrittenBookItem.MAXIMUM_PAGE_COUNT <= page) {
@ -69,21 +73,21 @@ public class BedrockBookEditTranslator extends PacketTranslator<BookEditPacket>
case ADD_PAGE: { case ADD_PAGE: {
// Add empty pages in between // Add empty pages in between
for (int i = pages.size(); i < page; i++) { for (int i = pages.size(); i < page; i++) {
pages.add(i, new StringTag("", "")); pages.add(i, "");
} }
pages.add(page, new StringTag("", MessageTranslator.convertToPlainText(packet.getText()))); pages.add(page, MessageTranslator.convertToPlainText(packet.getText()));
break; break;
} }
// Called whenever a page is modified // Called whenever a page is modified
case REPLACE_PAGE: { case REPLACE_PAGE: {
if (page < pages.size()) { if (page < pages.size()) {
pages.set(page, new StringTag("", MessageTranslator.convertToPlainText(packet.getText()))); pages.set(page, MessageTranslator.convertToPlainText(packet.getText()));
} else { } else {
// Add empty pages in between // Add empty pages in between
for (int i = pages.size(); i < page; i++) { for (int i = pages.size(); i < page; i++) {
pages.add(i, new StringTag("", "")); pages.add(i, "");
} }
pages.add(page, new StringTag("", MessageTranslator.convertToPlainText(packet.getText()))); pages.add(page, MessageTranslator.convertToPlainText(packet.getText()));
} }
break; break;
} }
@ -100,33 +104,29 @@ public class BedrockBookEditTranslator extends PacketTranslator<BookEditPacket>
} }
break; break;
} }
case SIGN_BOOK: {
tag.put(new StringTag("author", MessageTranslator.convertToPlainText(packet.getAuthor())));
tag.put(new StringTag("title", MessageTranslator.convertToPlainText(packet.getTitle())));
break;
}
default: default:
return; return;
} }
// Remove empty pages at the end // Remove empty pages at the end
while (pages.size() > 0) { while (!pages.isEmpty()) {
StringTag currentPage = (StringTag) pages.get(pages.size() - 1); String currentPage = pages.get(pages.size() - 1);
if (currentPage.getValue() == null || currentPage.getValue().isEmpty()) { if (currentPage.isEmpty()) {
pages.remove(pages.size() - 1); pages.remove(pages.size() - 1);
} else { } else {
break; break;
} }
} }
tag.put(new ListTag("pages", pages));
List<Filterable<String>> filterablePages = new ArrayList<>(pages.size());
for (String raw : pages) {
filterablePages.add(new Filterable<>(raw, null));
}
components.put(DataComponentType.WRITABLE_BOOK_CONTENT, new WritableBookContent(filterablePages));
// Update local copy // 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());
List<String> networkPages = new ArrayList<>();
for (Tag pageTag : pages) {
networkPages.add(((StringTag) pageTag).getValue());
}
String title; String title;
if (packet.getAction() == BookEditPacket.Action.SIGN_BOOK) { if (packet.getAction() == BookEditPacket.Action.SIGN_BOOK) {
// Add title to packet so the server knows we're signing // Add title to packet so the server knows we're signing
@ -139,7 +139,7 @@ public class BedrockBookEditTranslator extends PacketTranslator<BookEditPacket>
title = null; title = null;
} }
session.getBookEditCache().setPacket(new ServerboundEditBookPacket(session.getPlayerInventory().getHeldItemSlot(), networkPages, title)); session.getBookEditCache().setPacket(new ServerboundEditBookPacket(session.getPlayerInventory().getHeldItemSlot(), pages, 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

@ -168,7 +168,7 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
// If the block is custom or the breaking item is custom, we must keep track of break time ourselves // If the block is custom or the breaking item is custom, we must keep track of break time ourselves
GeyserItemStack item = session.getPlayerInventory().getItemInHand(); GeyserItemStack item = session.getPlayerInventory().getItemInHand();
ItemMapping mapping = item.getMapping(session); ItemMapping mapping = item.getMapping(session);
ItemDefinition customItem = mapping.isTool() ? CustomItemTranslator.getCustomItem(item.getNbt(), mapping) : null; ItemDefinition customItem = mapping.isTool() ? CustomItemTranslator.getCustomItem(item.getComponents(), mapping) : null;
CustomBlockState blockStateOverride = BlockRegistries.CUSTOM_BLOCK_STATE_OVERRIDES.get(blockState); CustomBlockState blockStateOverride = BlockRegistries.CUSTOM_BLOCK_STATE_OVERRIDES.get(blockState);
SkullCache.Skull skull = session.getSkullCache().getSkulls().get(vector); SkullCache.Skull skull = session.getSkullCache().getSkulls().get(vector);