Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-20 06:50:09 +01:00
Fix updating villager trade experience (#3906)
* Fix villager experience not updating Remove unnecessary fake trade experience stuff * Hide trade level for wandering traders
Dieser Commit ist enthalten in:
Ursprung
50d7f56aaf
Commit
70db98eeaf
@ -67,10 +67,6 @@ public class SessionPlayerEntity extends PlayerEntity {
|
||||
*/
|
||||
@Getter
|
||||
private boolean isRidingInFront;
|
||||
/**
|
||||
* Used for villager inventory emulation.
|
||||
*/
|
||||
private int fakeTradeXp;
|
||||
|
||||
public SessionPlayerEntity(GeyserSession session) {
|
||||
super(session, -1, 1, null, Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0, null, null);
|
||||
@ -175,11 +171,6 @@ public class SessionPlayerEntity extends PlayerEntity {
|
||||
this.isRidingInFront = position != null && position.getX() > 0;
|
||||
}
|
||||
|
||||
public void addFakeTradeExperience(int tradeXp) {
|
||||
fakeTradeXp += tradeXp;
|
||||
dirtyMetadata.put(EntityDataTypes.TRADE_EXPERIENCE, fakeTradeXp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttributeData createHealthAttribute() {
|
||||
// Max health must be divisible by two in bedrock
|
||||
|
@ -30,6 +30,7 @@ import com.github.steveice10.mc.protocol.data.game.inventory.VillagerTrade;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.inventory.ClientboundMerchantOffersPacket;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
|
||||
import org.geysermc.geyser.entity.type.Entity;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
|
||||
@ -40,6 +41,8 @@ public class MerchantContainer extends Container {
|
||||
private VillagerTrade[] villagerTrades;
|
||||
@Getter @Setter
|
||||
private ClientboundMerchantOffersPacket pendingOffersPacket;
|
||||
@Getter @Setter
|
||||
private int tradeExperience;
|
||||
|
||||
public MerchantContainer(String title, int id, int size, ContainerType containerType, PlayerInventory playerInventory) {
|
||||
super(title, id, size, containerType, playerInventory);
|
||||
@ -49,9 +52,10 @@ public class MerchantContainer extends Container {
|
||||
if (villagerTrades != null && slot >= 0 && slot < villagerTrades.length) {
|
||||
VillagerTrade trade = villagerTrades[slot];
|
||||
setItem(2, GeyserItemStack.from(trade.getOutput()), session);
|
||||
// TODO this logic doesn't add up
|
||||
session.getPlayerEntity().addFakeTradeExperience(trade.getXp());
|
||||
session.getPlayerEntity().updateBedrockMetadata();
|
||||
|
||||
tradeExperience += trade.getXp();
|
||||
villager.getDirtyMetadata().put(EntityDataTypes.TRADE_EXPERIENCE, tradeExperience);
|
||||
villager.updateBedrockMetadata();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -73,9 +73,17 @@ public class JavaMerchantOffersTranslator extends PacketTranslator<ClientboundMe
|
||||
public static void openMerchant(GeyserSession session, ClientboundMerchantOffersPacket packet, MerchantContainer merchantInventory) {
|
||||
// Retrieve the fake villager involved in the trade, and update its metadata to match with the window information
|
||||
merchantInventory.setVillagerTrades(packet.getTrades());
|
||||
merchantInventory.setTradeExperience(packet.getExperience());
|
||||
|
||||
Entity villager = merchantInventory.getVillager();
|
||||
villager.getDirtyMetadata().put(EntityDataTypes.TRADE_TIER, packet.getVillagerLevel() - 1);
|
||||
villager.getDirtyMetadata().put(EntityDataTypes.MAX_TRADE_TIER, 4);
|
||||
if (packet.isRegularVillager()) {
|
||||
villager.getDirtyMetadata().put(EntityDataTypes.TRADE_TIER, packet.getVillagerLevel() - 1);
|
||||
villager.getDirtyMetadata().put(EntityDataTypes.MAX_TRADE_TIER, 4);
|
||||
} else {
|
||||
// Don't show trade level for wandering traders
|
||||
villager.getDirtyMetadata().put(EntityDataTypes.TRADE_TIER, 0);
|
||||
villager.getDirtyMetadata().put(EntityDataTypes.MAX_TRADE_TIER, 0);
|
||||
}
|
||||
villager.getDirtyMetadata().put(EntityDataTypes.TRADE_EXPERIENCE, packet.getExperience());
|
||||
villager.updateBedrockMetadata();
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren