Streamline Item Net ID getting; cartography table finished

This commit is contained in:
Camotoy 2020-12-26 16:41:50 -05:00
parent 06f346b30b
commit 078af59249
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
12 changed files with 52 additions and 25 deletions

View file

@ -73,6 +73,6 @@ public class GeyserEnchantOption {
} }
return new EnchantOptionData(xpCost, javaIndex + 16, EMPTY, return new EnchantOptionData(xpCost, javaIndex + 16, EMPTY,
Collections.singletonList(new EnchantData(bedrockEnchantIndex, enchantLevel)), EMPTY, Collections.singletonList(new EnchantData(bedrockEnchantIndex, enchantLevel)), EMPTY,
javaEnchantIndex == -1 ? "unknown" : ENCHANT_NAMES.get(javaEnchantIndex), session.getItemNetId().incrementAndGet()); javaEnchantIndex == -1 ? "unknown" : ENCHANT_NAMES.get(javaEnchantIndex), session.getNextItemNetId());
} }
} }

View file

@ -127,6 +127,10 @@ public class GeyserSession implements CommandSender {
@Setter @Setter
private InventoryTranslator inventoryTranslator = InventoryTranslator.PLAYER_INVENTORY_TRANSLATOR; private InventoryTranslator inventoryTranslator = InventoryTranslator.PLAYER_INVENTORY_TRANSLATOR;
/**
* Use {@link #getNextItemNetId()} instead for consistency
*/
@Getter(AccessLevel.NONE)
private final AtomicInteger itemNetId = new AtomicInteger(1); private final AtomicInteger itemNetId = new AtomicInteger(1);
@Getter(AccessLevel.NONE) @Getter(AccessLevel.NONE)
@ -727,12 +731,10 @@ public class GeyserSession implements CommandSender {
startGamePacket.setLevelName(serverName); startGamePacket.setLevelName(serverName);
startGamePacket.setPremiumWorldTemplateId("00000000-0000-0000-0000-000000000000"); startGamePacket.setPremiumWorldTemplateId("00000000-0000-0000-0000-000000000000");
// startGamePacket.setCurrentTick(0);
startGamePacket.setEnchantmentSeed(0); startGamePacket.setEnchantmentSeed(0);
startGamePacket.setMultiplayerCorrelationId(""); startGamePacket.setMultiplayerCorrelationId("");
startGamePacket.setItemEntries(ItemRegistry.ITEMS); startGamePacket.setItemEntries(ItemRegistry.ITEMS);
startGamePacket.setVanillaVersion("*"); startGamePacket.setVanillaVersion("*");
// startGamePacket.setMovementServerAuthoritative(true);
startGamePacket.setInventoriesServerAuthoritative(true); startGamePacket.setInventoriesServerAuthoritative(true);
startGamePacket.setAuthoritativeMovementMode(AuthoritativeMovementMode.CLIENT); startGamePacket.setAuthoritativeMovementMode(AuthoritativeMovementMode.CLIENT);
upstream.sendPacket(startGamePacket); upstream.sendPacket(startGamePacket);
@ -773,6 +775,13 @@ public class GeyserSession implements CommandSender {
} }
} }
/**
* @return the next Bedrock item network ID to use for a new item
*/
public int getNextItemNetId() {
return itemNetId.getAndIncrement();
}
public void addTeleport(TeleportCache teleportCache) { public void addTeleport(TeleportCache teleportCache) {
teleportMap.put(teleportCache.getTeleportConfirmId(), teleportCache); teleportMap.put(teleportCache.getTeleportConfirmId(), teleportCache);

View file

@ -40,7 +40,7 @@ public class BedrockFilterTextTranslator extends PacketTranslator<FilterTextPack
@Override @Override
public void translate(FilterTextPacket packet, GeyserSession session) { public void translate(FilterTextPacket packet, GeyserSession session) {
// TODO: Bedrock doesn't send this. Why? // TODO: Bedrock doesn't send this. Why?
System.out.println(packet.toString()); session.getConnector().getLogger().error(packet.toString());
packet.setFromServer(true); packet.setFromServer(true);
session.sendUpstreamPacket(packet); session.sendUpstreamPacket(packet);
} }

View file

@ -120,7 +120,7 @@ public abstract class InventoryTranslator {
* Should be overwritten in cases where specific inventories should reject an item being in a specific spot. * Should be overwritten in cases where specific inventories should reject an item being in a specific spot.
* For examples, looms use this to reject items that are dyes in Bedrock but not in Java. * For examples, looms use this to reject items that are dyes in Bedrock but not in Java.
* *
* javaSourceSlot will be -1 if the cursor is the source * The source/destination slot will be -1 if the cursor is the slot
* *
* @return true if this transfer should be rejected * @return true if this transfer should be rejected
*/ */
@ -191,7 +191,8 @@ public abstract class InventoryTranslator {
int sourceSlot = bedrockSlotToJava(transferAction.getSource()); int sourceSlot = bedrockSlotToJava(transferAction.getSource());
int destSlot = bedrockSlotToJava(transferAction.getDestination()); int destSlot = bedrockSlotToJava(transferAction.getDestination());
if (shouldRejectItemPlace(session, inventory, isCursor(transferAction.getSource()) ? -1 : sourceSlot, destSlot)) { if (shouldRejectItemPlace(session, inventory, isCursor(transferAction.getSource()) ? -1 : sourceSlot,
isCursor(transferAction.getDestination()) ? -1 : destSlot)) {
// This item would not be here in Java // This item would not be here in Java
return rejectRequest(request, false); return rejectRequest(request, false);
} }
@ -673,7 +674,7 @@ public abstract class InventoryTranslator {
ItemStack javaCreativeItem = ItemTranslator.translateToJava(creativeItem); ItemStack javaCreativeItem = ItemTranslator.translateToJava(creativeItem);
if (isCursor(transferAction.getDestination())) { if (isCursor(transferAction.getDestination())) {
session.getPlayerInventory().setCursor(GeyserItemStack.from(javaCreativeItem, session.getItemNetId().getAndIncrement())); session.getPlayerInventory().setCursor(GeyserItemStack.from(javaCreativeItem, session.getNextItemNetId()));
return acceptRequest(request, Collections.singletonList( return acceptRequest(request, Collections.singletonList(
new ItemStackResponsePacket.ContainerEntry(ContainerSlotType.CURSOR, new ItemStackResponsePacket.ContainerEntry(ContainerSlotType.CURSOR,
Collections.singletonList(makeItemEntry(session, 0, session.getPlayerInventory().getCursor()))))); Collections.singletonList(makeItemEntry(session, 0, session.getPlayerInventory().getCursor())))));
@ -685,7 +686,7 @@ public abstract class InventoryTranslator {
existingItem.setAmount(existingItem.getAmount() + transferAction.getCount()); existingItem.setAmount(existingItem.getAmount() + transferAction.getCount());
javaCreativeItem = existingItem.getItemStack(); javaCreativeItem = existingItem.getItemStack();
} else { } else {
inventory.setItem(javaSlot, GeyserItemStack.from(javaCreativeItem, session.getItemNetId().getAndIncrement())); inventory.setItem(javaSlot, GeyserItemStack.from(javaCreativeItem, session.getNextItemNetId()));
} }
ClientCreativeInventoryActionPacket creativeActionPacket = new ClientCreativeInventoryActionPacket( ClientCreativeInventoryActionPacket creativeActionPacket = new ClientCreativeInventoryActionPacket(
javaSlot, javaSlot,
@ -750,7 +751,7 @@ public abstract class InventoryTranslator {
public static ItemStackResponsePacket.ItemEntry makeItemEntry(GeyserSession session, int bedrockSlot, GeyserItemStack itemStack) { public static ItemStackResponsePacket.ItemEntry makeItemEntry(GeyserSession session, int bedrockSlot, GeyserItemStack itemStack) {
ItemStackResponsePacket.ItemEntry itemEntry; ItemStackResponsePacket.ItemEntry itemEntry;
if (!itemStack.isEmpty()) { if (!itemStack.isEmpty()) {
int newNetId = session.getItemNetId().getAndIncrement(); int newNetId = session.getNextItemNetId();
itemStack.setNetId(newNetId); itemStack.setNetId(newNetId);
itemEntry = new ItemStackResponsePacket.ItemEntry((byte) bedrockSlot, (byte) bedrockSlot, (byte) itemStack.getAmount(), newNetId, ""); itemEntry = new ItemStackResponsePacket.ItemEntry((byte) bedrockSlot, (byte) bedrockSlot, (byte) itemStack.getAmount(), newNetId, "");
} else { } else {

View file

@ -33,7 +33,6 @@ import org.geysermc.connector.inventory.Inventory;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.inventory.BedrockContainerSlot; import org.geysermc.connector.network.translators.inventory.BedrockContainerSlot;
import org.geysermc.connector.network.translators.inventory.updater.UIInventoryUpdater; import org.geysermc.connector.network.translators.inventory.updater.UIInventoryUpdater;
import org.geysermc.connector.network.translators.item.ItemRegistry;
public class CartographyInventoryTranslator extends AbstractBlockInventoryTranslator { public class CartographyInventoryTranslator extends AbstractBlockInventoryTranslator {
public CartographyInventoryTranslator() { public CartographyInventoryTranslator() {
@ -42,10 +41,14 @@ public class CartographyInventoryTranslator extends AbstractBlockInventoryTransl
@Override @Override
public boolean shouldRejectItemPlace(GeyserSession session, Inventory inventory, int javaSourceSlot, int javaDestinationSlot) { public boolean shouldRejectItemPlace(GeyserSession session, Inventory inventory, int javaSourceSlot, int javaDestinationSlot) {
if (javaDestinationSlot == 1) { if (javaDestinationSlot == 0) {
// Bedrock Edition can use paper in slot 0
GeyserItemStack itemStack = javaSourceSlot == -1 ? session.getPlayerInventory().getCursor() : inventory.getItem(javaSourceSlot);
return itemStack.getItemEntry().getJavaIdentifier().equals("minecraft:paper");
}if (javaDestinationSlot == 1) {
// Bedrock Edition can use a compass to create locator maps in the ADDITIONAL slot // Bedrock Edition can use a compass to create locator maps in the ADDITIONAL slot
GeyserItemStack itemStack = javaSourceSlot == -1 ? session.getPlayerInventory().getCursor() : inventory.getItem(javaSourceSlot); GeyserItemStack itemStack = javaSourceSlot == -1 ? session.getPlayerInventory().getCursor() : inventory.getItem(javaSourceSlot);
return ItemRegistry.getItem(itemStack.getItemStack()).getJavaIdentifier().equals("minecraft:compass"); return itemStack.getItemEntry().getJavaIdentifier().equals("minecraft:compass");
} else if (javaSourceSlot == 2) { } else if (javaSourceSlot == 2) {
// Java doesn't allow an item to be renamed; this is why CARTOGRAPHY_ADDITIONAL could remain empty for Bedrock // Java doesn't allow an item to be renamed; this is why CARTOGRAPHY_ADDITIONAL could remain empty for Bedrock
return inventory.getItem(1).isEmpty(); return inventory.getItem(1).isEmpty();

View file

@ -45,7 +45,6 @@ import org.geysermc.connector.inventory.Inventory;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.inventory.BedrockContainerSlot; import org.geysermc.connector.network.translators.inventory.BedrockContainerSlot;
import org.geysermc.connector.network.translators.inventory.updater.UIInventoryUpdater; import org.geysermc.connector.network.translators.inventory.updater.UIInventoryUpdater;
import org.geysermc.connector.network.translators.item.ItemRegistry;
import org.geysermc.connector.network.translators.item.translators.BannerTranslator; import org.geysermc.connector.network.translators.item.translators.BannerTranslator;
import java.util.Collections; import java.util.Collections;
@ -111,7 +110,7 @@ public class LoomInventoryTranslator extends AbstractBlockInventoryTranslator {
} }
// Reject the item if Bedrock is attempting to put in a dye that is not a dye in Java Edition // Reject the item if Bedrock is attempting to put in a dye that is not a dye in Java Edition
return !ItemRegistry.getItem(itemStack.getItemStack()).getJavaIdentifier().contains("_dye"); return !itemStack.getItemEntry().getJavaIdentifier().endsWith("_dye");
} }
@Override @Override
@ -145,7 +144,7 @@ public class LoomInventoryTranslator extends AbstractBlockInventoryTranslator {
session.sendDownstreamPacket(packet); session.sendDownstreamPacket(packet);
GeyserItemStack inputCopy = inventory.getItem(0).copy(); GeyserItemStack inputCopy = inventory.getItem(0).copy();
inputCopy.setNetId(session.getItemNetId().incrementAndGet()); inputCopy.setNetId(session.getNextItemNetId());
// Add the pattern manually, for better item synchronization // Add the pattern manually, for better item synchronization
if (inputCopy.getNbt() == null) { if (inputCopy.getNbt() == null) {
inputCopy.setNbt(new CompoundTag("")); inputCopy.setNbt(new CompoundTag(""));

View file

@ -79,7 +79,7 @@ public class StonecutterInventoryTranslator extends AbstractBlockInventoryTransl
session.sendDownstreamPacket(packet); session.sendDownstreamPacket(packet);
if (inventory.getItem(1).getId() != javaOutput.getId()) { if (inventory.getItem(1).getId() != javaOutput.getId()) {
// We don't know there is an output here, so we tell ourselves that there is // We don't know there is an output here, so we tell ourselves that there is
inventory.setItem(1, GeyserItemStack.from(javaOutput, session.getItemNetId().incrementAndGet())); inventory.setItem(1, GeyserItemStack.from(javaOutput, session.getNextItemNetId()));
} }
return translateRequest(session, inventory, request); return translateRequest(session, inventory, request);
} }

View file

@ -42,7 +42,8 @@ public abstract class ChestedHorseInventoryTranslator extends AbstractHorseInven
/** /**
* @param size the total Java size of the inventory * @param size the total Java size of the inventory
* @param equipSlot the Java equipment slot. For * @param equipSlot the Java equipment slot. Java always has two slots - one for armor and one for saddle. Chested horses
* on Bedrock only acknowledge one slot.
*/ */
public ChestedHorseInventoryTranslator(int size, int equipSlot) { public ChestedHorseInventoryTranslator(int size, int equipSlot) {
super(size); super(size);
@ -103,10 +104,10 @@ public abstract class ChestedHorseInventoryTranslator extends AbstractHorseInven
horseItems[i] = inventory.getItem(i + 1).getItemData(session); horseItems[i] = inventory.getItem(i + 1).getItemData(session);
} }
InventoryContentPacket llamaPacket = new InventoryContentPacket(); InventoryContentPacket horseContentsPacket = new InventoryContentPacket();
llamaPacket.setContainerId(inventory.getId()); horseContentsPacket.setContainerId(inventory.getId());
llamaPacket.setContents(Arrays.asList(horseItems)); horseContentsPacket.setContents(Arrays.asList(horseItems));
System.out.println(llamaPacket); System.out.println(horseContentsPacket);
session.sendUpstreamPacket(llamaPacket); session.sendUpstreamPacket(horseContentsPacket);
} }
} }

View file

@ -80,6 +80,12 @@ public class RecipeRegistry {
*/ */
public static final List<CraftingData> TIPPED_ARROW_RECIPES = new ObjectArrayList<>(); public static final List<CraftingData> TIPPED_ARROW_RECIPES = new ObjectArrayList<>();
/**
* Recipe data that, when sent to the client, enables cartography features.
* This does not have a Java equivalent.
*/
public static final List<CraftingData> CARTOGRAPHY_RECIPE_DATA = new ObjectArrayList<>();
/** /**
* Recipe data that, when sent to the client, enables book cloning * Recipe data that, when sent to the client, enables book cloning
*/ */
@ -108,6 +114,11 @@ public class RecipeRegistry {
MAP_EXTENDING_RECIPE_DATA = CraftingData.fromMulti(UUID.fromString("d392b075-4ba1-40ae-8789-af868d56f6ce"), LAST_RECIPE_NET_ID++); MAP_EXTENDING_RECIPE_DATA = CraftingData.fromMulti(UUID.fromString("d392b075-4ba1-40ae-8789-af868d56f6ce"), LAST_RECIPE_NET_ID++);
MAP_CLONING_RECIPE_DATA = CraftingData.fromMulti(UUID.fromString("85939755-ba10-4d9d-a4cc-efb7a8e943c4"), LAST_RECIPE_NET_ID++); MAP_CLONING_RECIPE_DATA = CraftingData.fromMulti(UUID.fromString("85939755-ba10-4d9d-a4cc-efb7a8e943c4"), LAST_RECIPE_NET_ID++);
BANNER_DUPLICATING_RECIPE_DATA = CraftingData.fromMulti(UUID.fromString("b5c5d105-75a2-4076-af2b-923ea2bf4bf0"), LAST_RECIPE_NET_ID++); BANNER_DUPLICATING_RECIPE_DATA = CraftingData.fromMulti(UUID.fromString("b5c5d105-75a2-4076-af2b-923ea2bf4bf0"), LAST_RECIPE_NET_ID++);
CARTOGRAPHY_RECIPE_DATA.add(CraftingData.fromMulti(UUID.fromString("8b36268c-1829-483c-a0f1-993b7156a8f2"), LAST_RECIPE_NET_ID++)); // Map extending
CARTOGRAPHY_RECIPE_DATA.add(CraftingData.fromMulti(UUID.fromString("442d85ed-8272-4543-a6f1-418f90ded05d"), LAST_RECIPE_NET_ID++)); // Map cloning
CARTOGRAPHY_RECIPE_DATA.add(CraftingData.fromMulti(UUID.fromString("98c84b38-1085-46bd-b1ce-dd38c159e6cc"), LAST_RECIPE_NET_ID++)); // Map upgrading
CARTOGRAPHY_RECIPE_DATA.add(CraftingData.fromMulti(UUID.fromString("602234e4-cac1-4353-8bb7-b1ebff70024b"), LAST_RECIPE_NET_ID++)); // Map locking
// https://github.com/pmmp/PocketMine-MP/blob/stable/src/pocketmine/inventory/MultiRecipe.php // https://github.com/pmmp/PocketMine-MP/blob/stable/src/pocketmine/inventory/MultiRecipe.php
// Get all recipes that are not directly sent from a Java server // Get all recipes that are not directly sent from a Java server

View file

@ -149,6 +149,9 @@ public class JavaDeclareRecipesTranslator extends PacketTranslator<ServerDeclare
} }
} }
} }
// Add all cartography table recipe UUIDs, so we can use the cartography table
craftingDataPacket.getCraftingData().addAll(RecipeRegistry.CARTOGRAPHY_RECIPE_DATA);
craftingDataPacket.getPotionMixData().addAll(PotionMixRegistry.POTION_MIXES); craftingDataPacket.getPotionMixData().addAll(PotionMixRegistry.POTION_MIXES);
Int2ObjectMap<IntList> stonecutterRecipeMap = new Int2ObjectOpenHashMap<>(); Int2ObjectMap<IntList> stonecutterRecipeMap = new Int2ObjectOpenHashMap<>();

View file

@ -47,7 +47,7 @@ public class JavaSetSlotTranslator extends PacketTranslator<ServerSetSlotPacket>
if (newItem.getItemData(session).equals(oldItem.getItemData(session))) { if (newItem.getItemData(session).equals(oldItem.getItemData(session))) {
newItem.setNetId(oldItem.getNetId()); newItem.setNetId(oldItem.getNetId());
} else { } else {
newItem.setNetId(session.getItemNetId().getAndIncrement()); newItem.setNetId(session.getNextItemNetId());
} }
session.getPlayerInventory().setCursor(newItem); session.getPlayerInventory().setCursor(newItem);
InventoryUtils.updateCursor(session); InventoryUtils.updateCursor(session);
@ -67,7 +67,7 @@ public class JavaSetSlotTranslator extends PacketTranslator<ServerSetSlotPacket>
newItem.setNetId(oldItem.getNetId()); newItem.setNetId(oldItem.getNetId());
System.out.println("OLD: " + newItem.getNetId()); System.out.println("OLD: " + newItem.getNetId());
} else { } else {
newItem.setNetId(session.getItemNetId().getAndIncrement()); newItem.setNetId(session.getNextItemNetId());
System.out.println("NEW: " + newItem.getNetId()); System.out.println("NEW: " + newItem.getNetId());
} }
inventory.setItem(packet.getSlot(), newItem); inventory.setItem(packet.getSlot(), newItem);

View file

@ -50,7 +50,7 @@ public class JavaWindowItemsTranslator extends PacketTranslator<ServerWindowItem
if (newItem.getItemData(session).equals(oldItem.getItemData(session), false, false, false)) { if (newItem.getItemData(session).equals(oldItem.getItemData(session), false, false, false)) {
newItem.setNetId(oldItem.getNetId()); newItem.setNetId(oldItem.getNetId());
} else { } else {
newItem.setNetId(session.getItemNetId().getAndIncrement()); newItem.setNetId(session.getNextItemNetId());
} }
inventory.setItem(i, newItem); inventory.setItem(i, newItem);
} }