Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-04 23:30:17 +01:00
More review fixes and make beacon more reliable
Dieser Commit ist enthalten in:
Ursprung
d4c21bb74c
Commit
23ab69702d
@ -74,7 +74,7 @@ public class BlockInventoryHolder extends InventoryHolder {
|
||||
// Check to see if there is an existing block we can use that the player just selected.
|
||||
// First, verify that the player's position has not changed, so we don't try to select a block wildly out of range.
|
||||
// (This could be a virtual inventory that the player is opening)
|
||||
if (session.getLastInteractionPlayerPosition().equals(session.getPlayerEntity().getPosition())) {
|
||||
if (checkInteractionPosition(session)) {
|
||||
// Then, check to see if the interacted block is valid for this inventory by ensuring the block state identifier is valid
|
||||
int javaBlockId = session.getConnector().getWorldManager().getBlockAt(session, session.getLastInteractionBlockPosition());
|
||||
String[] javaBlockString = BlockTranslator.getJavaIdBlockMap().inverse().getOrDefault(javaBlockId, "minecraft:air").split("\\[");
|
||||
@ -101,6 +101,16 @@ public class BlockInventoryHolder extends InventoryHolder {
|
||||
setCustomName(session, position, inventory, defaultJavaBlockState);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will be overwritten in the beacon inventory translator to remove the check, since virtual inventories can't exist.
|
||||
*
|
||||
* @return if the player's last interaction position and current position match. Used to ensure that we don't select
|
||||
* a block to hold the inventory that's wildly out of range.
|
||||
*/
|
||||
protected boolean checkInteractionPosition(GeyserSession session) {
|
||||
return session.getLastInteractionPlayerPosition().equals(session.getPlayerEntity().getPosition());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if this Java block ID can be used for player inventory.
|
||||
*/
|
||||
|
@ -44,13 +44,40 @@ import org.geysermc.connector.inventory.Inventory;
|
||||
import org.geysermc.connector.inventory.PlayerInventory;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.inventory.BedrockContainerSlot;
|
||||
import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
|
||||
import org.geysermc.connector.network.translators.inventory.holder.BlockInventoryHolder;
|
||||
import org.geysermc.connector.network.translators.inventory.updater.UIInventoryUpdater;
|
||||
import org.geysermc.connector.utils.InventoryUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
public class BeaconInventoryTranslator extends AbstractBlockInventoryTranslator {
|
||||
public BeaconInventoryTranslator() {
|
||||
super(1, "minecraft:beacon", ContainerType.BEACON, UIInventoryUpdater.INSTANCE);
|
||||
super(1, new BlockInventoryHolder("minecraft:beacon", ContainerType.BEACON) {
|
||||
@Override
|
||||
public void prepareInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory) {
|
||||
if (!session.getConnector().getConfig().isCacheChunks()) {
|
||||
// Beacons cannot work without knowing their physical location
|
||||
return;
|
||||
}
|
||||
super.prepareInventory(translator, session, inventory);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkInteractionPosition(GeyserSession session) {
|
||||
// Since we can't fall back to a virtual inventory, let's make opening one easier
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory) {
|
||||
if (!session.getConnector().getConfig().isCacheChunks() || !((BeaconContainer) inventory).isUsingRealBlock()) {
|
||||
InventoryUtils.closeInventory(session, inventory.getId(), false);
|
||||
return;
|
||||
}
|
||||
super.openInventory(translator, session, inventory);
|
||||
}
|
||||
}, UIInventoryUpdater.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -59,14 +59,14 @@ public class CartographyInventoryTranslator extends AbstractBlockInventoryTransl
|
||||
|
||||
@Override
|
||||
public int bedrockSlotToJava(StackRequestSlotInfoData slotInfoData) {
|
||||
if (slotInfoData.getContainer() == ContainerSlotType.CARTOGRAPHY_INPUT) {
|
||||
return 0;
|
||||
}
|
||||
if (slotInfoData.getContainer() == ContainerSlotType.CARTOGRAPHY_ADDITIONAL) {
|
||||
return 1;
|
||||
}
|
||||
if (slotInfoData.getContainer() == ContainerSlotType.CARTOGRAPHY_RESULT || slotInfoData.getContainer() == ContainerSlotType.CREATIVE_OUTPUT) {
|
||||
return 2;
|
||||
switch (slotInfoData.getContainer()) {
|
||||
case CARTOGRAPHY_INPUT:
|
||||
return 0;
|
||||
case CARTOGRAPHY_ADDITIONAL:
|
||||
return 1;
|
||||
case CARTOGRAPHY_RESULT:
|
||||
case CREATIVE_OUTPUT:
|
||||
return 2;
|
||||
}
|
||||
return super.bedrockSlotToJava(slotInfoData);
|
||||
}
|
||||
|
@ -58,6 +58,7 @@ public class JavaTradeListTranslator extends PacketTranslator<ServerTradeListPac
|
||||
return;
|
||||
}
|
||||
|
||||
// Retrieve the fake villager involved in the trade, and update its metadata to match with the window information
|
||||
MerchantContainer merchantInventory = (MerchantContainer) openInventory;
|
||||
merchantInventory.setVillagerTrades(packet.getTrades());
|
||||
Entity villager = merchantInventory.getVillager();
|
||||
@ -66,6 +67,7 @@ public class JavaTradeListTranslator extends PacketTranslator<ServerTradeListPac
|
||||
villager.getMetadata().put(EntityData.TRADE_XP, packet.getExperience());
|
||||
villager.updateBedrockMetadata(session);
|
||||
|
||||
// Construct the packet that opens the trading window
|
||||
UpdateTradePacket updateTradePacket = new UpdateTradePacket();
|
||||
updateTradePacket.setTradeTier(packet.getVillagerLevel() - 1);
|
||||
updateTradePacket.setContainerId((short) packet.getWindowId());
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren