Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-19 14:30:17 +01:00
Compiles
Dieser Commit ist enthalten in:
Ursprung
8bd2df0828
Commit
ab8832b771
@ -69,7 +69,7 @@ public class BedrockBlockPickRequestTranslator extends PacketTranslator<BlockPic
|
||||
|
||||
BlockMapping blockMapping = BlockRegistries.JAVA_BLOCKS.getOrDefault(blockToPick, BlockMapping.DEFAULT);
|
||||
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)
|
||||
.whenComplete((tag, ex) -> session.ensureInEventLoop(() -> {
|
||||
if (tag == null) {
|
||||
@ -94,7 +94,7 @@ public class BedrockBlockPickRequestTranslator extends PacketTranslator<BlockPic
|
||||
InventoryUtils.findOrCreateItem(session, itemStack);
|
||||
}));
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
|
||||
pickItem(session, blockMapping);
|
||||
}
|
||||
|
@ -26,13 +26,11 @@
|
||||
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.component.DataComponentType;
|
||||
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.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.geysermc.geyser.inventory.GeyserItemStack;
|
||||
import org.geysermc.geyser.item.type.WrittenBookItem;
|
||||
@ -57,8 +55,14 @@ public class BedrockBookEditTranslator extends PacketTranslator<BookEditPacket>
|
||||
if (itemStack != null) {
|
||||
DataComponents components = itemStack.getComponents() != null ? itemStack.getComponents() : new DataComponents(new HashMap<>());
|
||||
ItemStack bookItem = new ItemStack(itemStack.getJavaId(), itemStack.getAmount(), components);
|
||||
WritableBookContent
|
||||
List<Tag> pages = tag.contains("pages") ? new LinkedList<>(((ListTag) tag.get("pages")).getValue()) : new LinkedList<>();
|
||||
List<String> pages = 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();
|
||||
if (page < 0 || WrittenBookItem.MAXIMUM_PAGE_COUNT <= page) {
|
||||
@ -69,21 +73,21 @@ public class BedrockBookEditTranslator extends PacketTranslator<BookEditPacket>
|
||||
case ADD_PAGE: {
|
||||
// Add empty pages in between
|
||||
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;
|
||||
}
|
||||
// Called whenever a page is modified
|
||||
case REPLACE_PAGE: {
|
||||
if (page < pages.size()) {
|
||||
pages.set(page, new StringTag("", MessageTranslator.convertToPlainText(packet.getText())));
|
||||
pages.set(page, MessageTranslator.convertToPlainText(packet.getText()));
|
||||
} else {
|
||||
// Add empty pages in between
|
||||
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;
|
||||
}
|
||||
@ -100,33 +104,29 @@ public class BedrockBookEditTranslator extends PacketTranslator<BookEditPacket>
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SIGN_BOOK: {
|
||||
tag.put(new StringTag("author", MessageTranslator.convertToPlainText(packet.getAuthor())));
|
||||
tag.put(new StringTag("title", MessageTranslator.convertToPlainText(packet.getTitle())));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return;
|
||||
}
|
||||
// Remove empty pages at the end
|
||||
while (pages.size() > 0) {
|
||||
StringTag currentPage = (StringTag) pages.get(pages.size() - 1);
|
||||
if (currentPage.getValue() == null || currentPage.getValue().isEmpty()) {
|
||||
while (!pages.isEmpty()) {
|
||||
String currentPage = pages.get(pages.size() - 1);
|
||||
if (currentPage.isEmpty()) {
|
||||
pages.remove(pages.size() - 1);
|
||||
} else {
|
||||
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
|
||||
session.getPlayerInventory().setItem(36 + session.getPlayerInventory().getHeldItemSlot(), GeyserItemStack.from(bookItem), session);
|
||||
session.getInventoryTranslator().updateInventory(session, session.getPlayerInventory());
|
||||
|
||||
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
|
||||
@ -139,7 +139,7 @@ public class BedrockBookEditTranslator extends PacketTranslator<BookEditPacket>
|
||||
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
|
||||
if (packet.getAction() == BookEditPacket.Action.SIGN_BOOK) {
|
||||
session.getBookEditCache().checkForSend();
|
||||
|
@ -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
|
||||
GeyserItemStack item = session.getPlayerInventory().getItemInHand();
|
||||
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);
|
||||
SkullCache.Skull skull = session.getSkullCache().getSkulls().get(vector);
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren