mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-11-30 04:02:40 +01:00
Show villager display name
This commit is contained in:
parent
4c5d80e2e9
commit
afb12e923b
4 changed files with 16 additions and 2 deletions
|
@ -30,7 +30,6 @@ import com.github.steveice10.mc.auth.exception.request.InvalidCredentialsExcepti
|
|||
import com.github.steveice10.mc.auth.exception.request.RequestException;
|
||||
import com.github.steveice10.mc.protocol.MinecraftProtocol;
|
||||
import com.github.steveice10.mc.protocol.data.SubProtocol;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
||||
import com.github.steveice10.mc.protocol.data.game.window.VillagerTrade;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.block.BlockState;
|
||||
|
@ -173,6 +172,8 @@ public class GeyserSession implements CommandSender {
|
|||
|
||||
@Setter
|
||||
private VillagerTrade[] villagerTrades;
|
||||
@Setter
|
||||
private long lastInteractedVillagerEid;
|
||||
|
||||
private MinecraftProtocol protocol;
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ import com.nukkitx.protocol.bedrock.packet.InventoryTransactionPacket;
|
|||
|
||||
import org.geysermc.connector.entity.Entity;
|
||||
import org.geysermc.connector.entity.ItemFrameEntity;
|
||||
import org.geysermc.connector.entity.living.merchant.AbstractMerchantEntity;
|
||||
import org.geysermc.connector.inventory.Inventory;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||
|
@ -198,6 +199,10 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
|
|||
session.sendDownstreamPacket(interactAtPacket);
|
||||
|
||||
EntitySoundInteractionHandler.handleEntityInteraction(session, vector, entity);
|
||||
|
||||
if (entity instanceof AbstractMerchantEntity) {
|
||||
session.setLastInteractedVillagerEid(packet.getRuntimeEntityId());
|
||||
}
|
||||
break;
|
||||
case 1: //Attack
|
||||
ClientPlayerInteractEntityPacket attackPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
|
||||
|
|
|
@ -93,6 +93,7 @@ public class MerchantInventoryTranslator extends BaseInventoryTranslator {
|
|||
|
||||
@Override
|
||||
public void closeInventory(GeyserSession session, Inventory inventory) {
|
||||
session.setLastInteractedVillagerEid(-1);
|
||||
session.setVillagerTrades(null);
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,14 @@ public class JavaTradeListTranslator extends PacketTranslator<ServerTradeListPac
|
|||
updateTradePacket.setTradeTier(packet.getVillagerLevel() - 1);
|
||||
updateTradePacket.setWindowId((short) packet.getWindowId());
|
||||
updateTradePacket.setWindowType((short) ContainerType.TRADING.id());
|
||||
updateTradePacket.setDisplayName("Villager");
|
||||
String displayName;
|
||||
Entity realVillager = session.getEntityCache().getEntityByGeyserId(session.getLastInteractedVillagerEid());
|
||||
if (realVillager != null && realVillager.getMetadata().containsKey(EntityData.NAMETAG) && realVillager.getMetadata().getString(EntityData.NAMETAG) != null) {
|
||||
displayName = realVillager.getMetadata().getString(EntityData.NAMETAG);
|
||||
} else {
|
||||
displayName = packet.isRegularVillager() ? "Villager" : "Wandering Trader";
|
||||
}
|
||||
updateTradePacket.setDisplayName(displayName);
|
||||
updateTradePacket.setUnknownInt(0);
|
||||
updateTradePacket.setScreen2(true);
|
||||
updateTradePacket.setWilling(true);
|
||||
|
|
Loading…
Reference in a new issue