3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-26 16:12:46 +01:00

Store villager data in the player and fix wandering trader

Dieser Commit ist enthalten in:
AJ Ferguson 2020-05-19 09:41:44 -08:00
Ursprung 95297e4047
Commit 2366559694
6 geänderte Dateien mit 19 neuen und 36 gelöschten Zeilen

Datei anzeigen

@ -27,13 +27,10 @@ package org.geysermc.connector.entity.living.merchant;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.VillagerData;
import com.github.steveice10.mc.protocol.data.game.window.VillagerTrade;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.EntityData;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import lombok.Getter;
import lombok.Setter;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
@ -69,10 +66,6 @@ public class VillagerEntity extends AbstractMerchantEntity {
VILLAGER_REGIONS.put(6, 6);
}
@Getter
@Setter
private VillagerTrade[] villagerTrades;
public VillagerEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
super(entityId, geyserId, entityType, position, motion, rotation);
}

Datei anzeigen

@ -32,6 +32,7 @@ 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;
import com.github.steveice10.mc.protocol.packet.handshake.client.HandshakePacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket;
@ -150,9 +151,6 @@ public class GeyserSession implements CommandSender {
@Setter
private boolean interacting;
@Setter
private long lastInteractedVillagerEid;
@Setter
private Vector3i lastInteractionPosition;
@ -164,6 +162,9 @@ public class GeyserSession implements CommandSender {
@Setter
private int craftSlot = 0;
@Setter
private VillagerTrade[] villagerTrades;
private MinecraftProtocol protocol;
public GeyserSession(GeyserConnector connector, BedrockServerSession bedrockServerSession) {

Datei anzeigen

@ -31,7 +31,7 @@ import com.github.steveice10.mc.protocol.data.game.window.WindowType;
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientSelectTradePacket;
import com.nukkitx.protocol.bedrock.data.EntityData;
import com.nukkitx.protocol.bedrock.packet.EntityEventPacket;
import org.geysermc.connector.entity.living.merchant.VillagerEntity;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.inventory.Inventory;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
@ -51,15 +51,12 @@ public class BedrockEntityEventTranslator extends PacketTranslator<EntityEventPa
ClientSelectTradePacket selectTradePacket = new ClientSelectTradePacket(packet.getData());
session.getDownstream().getSession().send(selectTradePacket);
VillagerEntity villager = (VillagerEntity) session.getEntityCache().getEntityByGeyserId(session.getLastInteractedVillagerEid());
if (villager == null) {
session.getConnector().getLogger().debug("Could not find villager with entity id: " + session.getLastInteractedVillagerEid());
return;
}
Entity villager = session.getPlayerEntity();
Inventory openInventory = session.getInventoryCache().getOpenInventory();
if (openInventory != null && openInventory.getWindowType() == WindowType.MERCHANT) {
if (packet.getData() >= 0 && packet.getData() < villager.getVillagerTrades().length) {
VillagerTrade trade = villager.getVillagerTrades()[packet.getData()];
VillagerTrade[] trades = session.getVillagerTrades();
if (trades != null && packet.getData() >= 0 && packet.getData() < trades.length) {
VillagerTrade trade = session.getVillagerTrades()[packet.getData()];
openInventory.setItem(2, trade.getOutput());
villager.getMetadata().put(EntityData.TRADE_XP, trade.getXp() + villager.getMetadata().getInt(EntityData.TRADE_XP));
villager.updateBedrockMetadata(session);

Datei anzeigen

@ -188,10 +188,6 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
session.sendDownstreamPacket(interactAtPacket);
EntitySoundInteractionHandler.handleEntityInteraction(session, vector, entity);
if (entity instanceof VillagerEntity) {
session.setLastInteractedVillagerEid(packet.getRuntimeEntityId());
}
break;
case 1: //Attack
ClientPlayerInteractEntityPacket attackPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),

Datei anzeigen

@ -93,7 +93,7 @@ public class MerchantInventoryTranslator extends BaseInventoryTranslator {
@Override
public void closeInventory(GeyserSession session, Inventory inventory) {
session.setLastInteractedVillagerEid(-1);
session.setVillagerTrades(null);
}
@Override

Datei anzeigen

@ -35,7 +35,7 @@ import com.nukkitx.protocol.bedrock.data.ContainerType;
import com.nukkitx.protocol.bedrock.data.EntityData;
import com.nukkitx.protocol.bedrock.data.ItemData;
import com.nukkitx.protocol.bedrock.packet.UpdateTradePacket;
import org.geysermc.connector.entity.living.merchant.VillagerEntity;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
@ -50,12 +50,8 @@ public class JavaTradeListTranslator extends PacketTranslator<ServerTradeListPac
@Override
public void translate(ServerTradeListPacket packet, GeyserSession session) {
VillagerEntity villager = (VillagerEntity) session.getEntityCache().getEntityByGeyserId(session.getLastInteractedVillagerEid());
if (villager == null) {
session.getConnector().getLogger().debug("Could not find villager with entity id: " + session.getLastInteractedVillagerEid());
return;
}
villager.setVillagerTrades(packet.getTrades());
Entity villager = session.getPlayerEntity();
session.setVillagerTrades(packet.getTrades());
villager.getMetadata().put(EntityData.TRADE_TIER, packet.getVillagerLevel() - 1);
villager.getMetadata().put(EntityData.MAX_TRADE_TIER, 4);
villager.getMetadata().put(EntityData.TRADE_XP, packet.getExperience());
@ -70,7 +66,7 @@ public class JavaTradeListTranslator extends PacketTranslator<ServerTradeListPac
updateTradePacket.setScreen2(true);
updateTradePacket.setWilling(true);
updateTradePacket.setPlayerUniqueEntityId(session.getPlayerEntity().getGeyserId());
updateTradePacket.setTraderUniqueEntityId(session.getLastInteractedVillagerEid());
updateTradePacket.setTraderUniqueEntityId(session.getPlayerEntity().getGeyserId());
CompoundTagBuilder builder = CompoundTagBuilder.builder();
List<CompoundTag> tags = new ArrayList<>();
for (VillagerTrade trade : packet.getTrades()) {
@ -94,7 +90,7 @@ public class JavaTradeListTranslator extends PacketTranslator<ServerTradeListPac
}
//Hidden trade to fix visual experience bug
if (packet.getVillagerLevel() < 5) {
if (packet.isRegularVillager() && packet.getVillagerLevel() < 5) {
tags.add(CompoundTagBuilder.builder()
.intTag("maxUses", 0)
.intTag("traderExp", 0)
@ -112,10 +108,10 @@ public class JavaTradeListTranslator extends PacketTranslator<ServerTradeListPac
builder.listTag("Recipes", CompoundTag.class, tags);
List<CompoundTag> expTags = new ArrayList<>();
expTags.add(CompoundTagBuilder.builder().intTag("0", 0).buildRootTag());
expTags.add(CompoundTagBuilder.builder().intTag("1", 11).buildRootTag());
expTags.add(CompoundTagBuilder.builder().intTag("2", 71).buildRootTag());
expTags.add(CompoundTagBuilder.builder().intTag("3", 151).buildRootTag());
expTags.add(CompoundTagBuilder.builder().intTag("4", 251).buildRootTag());
expTags.add(CompoundTagBuilder.builder().intTag("1", 10).buildRootTag());
expTags.add(CompoundTagBuilder.builder().intTag("2", 70).buildRootTag());
expTags.add(CompoundTagBuilder.builder().intTag("3", 150).buildRootTag());
expTags.add(CompoundTagBuilder.builder().intTag("4", 250).buildRootTag());
builder.listTag("TierExpRequirements", CompoundTag.class, expTags);
updateTradePacket.setOffers(builder.buildRootTag());
session.sendUpstreamPacket(updateTradePacket);