Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-26 16:12:46 +01:00
Fix villagers accepting books (#1605)
* Hopefully fix villagers accepting books Fixes a couple of inconsistencies getting books from the creative menu. * Fix fake news
Dieser Commit ist enthalten in:
Ursprung
eb687e6638
Commit
ffd0c211fc
@ -42,13 +42,13 @@ public class BedrockEntityEventTranslator extends PacketTranslator<EntityEventPa
|
||||
@Override
|
||||
public void translate(EntityEventPacket packet, GeyserSession session) {
|
||||
switch (packet.getType()) {
|
||||
// Resend the packet so we get the eating sounds
|
||||
case EATING_ITEM:
|
||||
// Resend the packet so we get the eating sounds
|
||||
session.sendUpstreamPacket(packet);
|
||||
return;
|
||||
case COMPLETE_TRADE:
|
||||
ClientSelectTradePacket selectTradePacket = new ClientSelectTradePacket(packet.getData());
|
||||
session.getDownstream().getSession().send(selectTradePacket);
|
||||
session.sendDownstreamPacket(selectTradePacket);
|
||||
|
||||
Entity villager = session.getPlayerEntity();
|
||||
Inventory openInventory = session.getInventoryCache().getOpenInventory();
|
||||
|
@ -27,7 +27,6 @@ package org.geysermc.connector.network.translators.inventory;
|
||||
|
||||
import com.nukkitx.protocol.bedrock.data.inventory.ContainerId;
|
||||
import com.nukkitx.protocol.bedrock.data.inventory.InventoryActionData;
|
||||
import com.nukkitx.protocol.bedrock.data.inventory.InventorySource;
|
||||
import org.geysermc.connector.inventory.Inventory;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.inventory.updater.CursorInventoryUpdater;
|
||||
|
@ -52,6 +52,12 @@ public class ItemRegistry {
|
||||
|
||||
private static final Map<String, ItemEntry> JAVA_IDENTIFIER_MAP = new HashMap<>();
|
||||
|
||||
/**
|
||||
* A list of all identifiers that only exist on Java. Used to prevent creative items from becoming these unintentionally.
|
||||
*/
|
||||
private static final List<String> JAVA_ONLY_ITEMS = Arrays.asList("minecraft:spectral_arrow", "minecraft:debug_stick",
|
||||
"minecraft:knowledge_book");
|
||||
|
||||
public static final ItemData[] CREATIVE_ITEMS;
|
||||
|
||||
public static final List<StartGamePacket.ItemEntry> ITEMS = new ArrayList<>();
|
||||
@ -245,7 +251,10 @@ public class ItemRegistry {
|
||||
if (itemEntry.getBedrockId() == data.getId() && (itemEntry.getBedrockData() == data.getDamage() ||
|
||||
// Make exceptions for potions and tipped arrows, whose damage values can vary
|
||||
(itemEntry.getJavaIdentifier().endsWith("potion") || itemEntry.getJavaIdentifier().equals("minecraft:arrow")))) {
|
||||
return itemEntry;
|
||||
if (!JAVA_ONLY_ITEMS.contains(itemEntry.getJavaIdentifier())) {
|
||||
// From a Bedrock item data, we aren't getting one of these items
|
||||
return itemEntry;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,6 +111,10 @@ public abstract class ItemTranslator {
|
||||
translator.translateToJava(itemStack.getNbt(), javaItem);
|
||||
}
|
||||
}
|
||||
if (itemStack.getNbt().isEmpty()) {
|
||||
// Otherwise, seems to causes issues with villagers accepting books, and I don't see how this will break anything else. - Camotoy
|
||||
itemStack = new ItemStack(itemStack.getId(), itemStack.getAmount(), null);
|
||||
}
|
||||
}
|
||||
return itemStack;
|
||||
}
|
||||
@ -126,7 +130,7 @@ public abstract class ItemTranslator {
|
||||
|
||||
// This is a fallback for maps with no nbt
|
||||
if (nbt == null && bedrockItem.getJavaIdentifier().equals("minecraft:filled_map")) {
|
||||
nbt = new com.github.steveice10.opennbt.tag.builtin.CompoundTag("");
|
||||
nbt = new CompoundTag("");
|
||||
nbt.put(new IntTag("map", 0));
|
||||
}
|
||||
|
||||
@ -218,7 +222,7 @@ public abstract class ItemTranslator {
|
||||
NbtMapBuilder builder = NbtMap.builder();
|
||||
if (tag.getValue() != null && !tag.getValue().isEmpty()) {
|
||||
for (String str : tag.getValue().keySet()) {
|
||||
com.github.steveice10.opennbt.tag.builtin.Tag javaTag = tag.get(str);
|
||||
Tag javaTag = tag.get(str);
|
||||
Object translatedTag = translateToBedrockNBT(javaTag);
|
||||
if (translatedTag == null)
|
||||
continue;
|
||||
@ -287,21 +291,21 @@ public abstract class ItemTranslator {
|
||||
return new NbtList(type, tagList);
|
||||
}
|
||||
|
||||
if (tag instanceof com.github.steveice10.opennbt.tag.builtin.CompoundTag) {
|
||||
com.github.steveice10.opennbt.tag.builtin.CompoundTag compoundTag = (com.github.steveice10.opennbt.tag.builtin.CompoundTag) tag;
|
||||
if (tag instanceof CompoundTag) {
|
||||
CompoundTag compoundTag = (CompoundTag) tag;
|
||||
return translateNbtToBedrock(compoundTag);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public com.github.steveice10.opennbt.tag.builtin.CompoundTag translateToJavaNBT(String name, NbtMap tag) {
|
||||
com.github.steveice10.opennbt.tag.builtin.CompoundTag javaTag = new com.github.steveice10.opennbt.tag.builtin.CompoundTag(name);
|
||||
Map<String, com.github.steveice10.opennbt.tag.builtin.Tag> javaValue = javaTag.getValue();
|
||||
public CompoundTag translateToJavaNBT(String name, NbtMap tag) {
|
||||
CompoundTag javaTag = new CompoundTag(name);
|
||||
Map<String, Tag> javaValue = javaTag.getValue();
|
||||
if (tag != null && !tag.isEmpty()) {
|
||||
for (String str : tag.keySet()) {
|
||||
Object bedrockTag = tag.get(str);
|
||||
com.github.steveice10.opennbt.tag.builtin.Tag translatedTag = translateToJavaNBT(str, bedrockTag);
|
||||
Tag translatedTag = translateToJavaNBT(str, bedrockTag);
|
||||
if (translatedTag == null)
|
||||
continue;
|
||||
|
||||
@ -313,7 +317,7 @@ public abstract class ItemTranslator {
|
||||
return javaTag;
|
||||
}
|
||||
|
||||
private com.github.steveice10.opennbt.tag.builtin.Tag translateToJavaNBT(String name, Object object) {
|
||||
private Tag translateToJavaNBT(String name, Object object) {
|
||||
if (object instanceof int[]) {
|
||||
return new IntArrayTag(name, (int[]) object);
|
||||
}
|
||||
@ -355,10 +359,10 @@ public abstract class ItemTranslator {
|
||||
}
|
||||
|
||||
if (object instanceof List) {
|
||||
List<com.github.steveice10.opennbt.tag.builtin.Tag> tags = new ArrayList<>();
|
||||
List<Tag> tags = new ArrayList<>();
|
||||
|
||||
for (Object value : (List<?>) object) {
|
||||
com.github.steveice10.opennbt.tag.builtin.Tag javaTag = translateToJavaNBT("", value);
|
||||
Tag javaTag = translateToJavaNBT("", value);
|
||||
if (javaTag != null)
|
||||
tags.add(javaTag);
|
||||
}
|
||||
|
@ -29,12 +29,10 @@ import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerSetSl
|
||||
import org.geysermc.connector.inventory.Inventory;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||
import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
|
||||
import org.geysermc.connector.network.translators.Translator;
|
||||
import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
|
||||
import org.geysermc.connector.utils.InventoryUtils;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Translator(packet = ServerSetSlotPacket.class)
|
||||
public class JavaSetSlotTranslator extends PacketTranslator<ServerSetSlotPacket> {
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren