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:
Ursprung
95297e4047
Commit
2366559694
@ -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.EntityMetadata;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.VillagerData;
|
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.math.vector.Vector3f;
|
||||||
import com.nukkitx.protocol.bedrock.data.EntityData;
|
import com.nukkitx.protocol.bedrock.data.EntityData;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import org.geysermc.connector.entity.type.EntityType;
|
import org.geysermc.connector.entity.type.EntityType;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
|
|
||||||
@ -69,10 +66,6 @@ public class VillagerEntity extends AbstractMerchantEntity {
|
|||||||
VILLAGER_REGIONS.put(6, 6);
|
VILLAGER_REGIONS.put(6, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
private VillagerTrade[] villagerTrades;
|
|
||||||
|
|
||||||
public VillagerEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
|
public VillagerEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
|
||||||
super(entityId, geyserId, entityType, position, motion, rotation);
|
super(entityId, geyserId, entityType, position, motion, rotation);
|
||||||
}
|
}
|
||||||
|
@ -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.SubProtocol;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
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.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.data.game.world.block.BlockState;
|
||||||
import com.github.steveice10.mc.protocol.packet.handshake.client.HandshakePacket;
|
import com.github.steveice10.mc.protocol.packet.handshake.client.HandshakePacket;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket;
|
||||||
@ -150,9 +151,6 @@ public class GeyserSession implements CommandSender {
|
|||||||
@Setter
|
@Setter
|
||||||
private boolean interacting;
|
private boolean interacting;
|
||||||
|
|
||||||
@Setter
|
|
||||||
private long lastInteractedVillagerEid;
|
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
private Vector3i lastInteractionPosition;
|
private Vector3i lastInteractionPosition;
|
||||||
|
|
||||||
@ -164,6 +162,9 @@ public class GeyserSession implements CommandSender {
|
|||||||
@Setter
|
@Setter
|
||||||
private int craftSlot = 0;
|
private int craftSlot = 0;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
private VillagerTrade[] villagerTrades;
|
||||||
|
|
||||||
private MinecraftProtocol protocol;
|
private MinecraftProtocol protocol;
|
||||||
|
|
||||||
public GeyserSession(GeyserConnector connector, BedrockServerSession bedrockServerSession) {
|
public GeyserSession(GeyserConnector connector, BedrockServerSession bedrockServerSession) {
|
||||||
|
@ -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.github.steveice10.mc.protocol.packet.ingame.client.window.ClientSelectTradePacket;
|
||||||
import com.nukkitx.protocol.bedrock.data.EntityData;
|
import com.nukkitx.protocol.bedrock.data.EntityData;
|
||||||
import com.nukkitx.protocol.bedrock.packet.EntityEventPacket;
|
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.inventory.Inventory;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
@ -51,15 +51,12 @@ public class BedrockEntityEventTranslator extends PacketTranslator<EntityEventPa
|
|||||||
ClientSelectTradePacket selectTradePacket = new ClientSelectTradePacket(packet.getData());
|
ClientSelectTradePacket selectTradePacket = new ClientSelectTradePacket(packet.getData());
|
||||||
session.getDownstream().getSession().send(selectTradePacket);
|
session.getDownstream().getSession().send(selectTradePacket);
|
||||||
|
|
||||||
VillagerEntity villager = (VillagerEntity) session.getEntityCache().getEntityByGeyserId(session.getLastInteractedVillagerEid());
|
Entity villager = session.getPlayerEntity();
|
||||||
if (villager == null) {
|
|
||||||
session.getConnector().getLogger().debug("Could not find villager with entity id: " + session.getLastInteractedVillagerEid());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Inventory openInventory = session.getInventoryCache().getOpenInventory();
|
Inventory openInventory = session.getInventoryCache().getOpenInventory();
|
||||||
if (openInventory != null && openInventory.getWindowType() == WindowType.MERCHANT) {
|
if (openInventory != null && openInventory.getWindowType() == WindowType.MERCHANT) {
|
||||||
if (packet.getData() >= 0 && packet.getData() < villager.getVillagerTrades().length) {
|
VillagerTrade[] trades = session.getVillagerTrades();
|
||||||
VillagerTrade trade = villager.getVillagerTrades()[packet.getData()];
|
if (trades != null && packet.getData() >= 0 && packet.getData() < trades.length) {
|
||||||
|
VillagerTrade trade = session.getVillagerTrades()[packet.getData()];
|
||||||
openInventory.setItem(2, trade.getOutput());
|
openInventory.setItem(2, trade.getOutput());
|
||||||
villager.getMetadata().put(EntityData.TRADE_XP, trade.getXp() + villager.getMetadata().getInt(EntityData.TRADE_XP));
|
villager.getMetadata().put(EntityData.TRADE_XP, trade.getXp() + villager.getMetadata().getInt(EntityData.TRADE_XP));
|
||||||
villager.updateBedrockMetadata(session);
|
villager.updateBedrockMetadata(session);
|
||||||
|
@ -188,10 +188,6 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
|
|||||||
session.sendDownstreamPacket(interactAtPacket);
|
session.sendDownstreamPacket(interactAtPacket);
|
||||||
|
|
||||||
EntitySoundInteractionHandler.handleEntityInteraction(session, vector, entity);
|
EntitySoundInteractionHandler.handleEntityInteraction(session, vector, entity);
|
||||||
|
|
||||||
if (entity instanceof VillagerEntity) {
|
|
||||||
session.setLastInteractedVillagerEid(packet.getRuntimeEntityId());
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 1: //Attack
|
case 1: //Attack
|
||||||
ClientPlayerInteractEntityPacket attackPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
|
ClientPlayerInteractEntityPacket attackPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
|
||||||
|
@ -93,7 +93,7 @@ public class MerchantInventoryTranslator extends BaseInventoryTranslator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void closeInventory(GeyserSession session, Inventory inventory) {
|
public void closeInventory(GeyserSession session, Inventory inventory) {
|
||||||
session.setLastInteractedVillagerEid(-1);
|
session.setVillagerTrades(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -35,7 +35,7 @@ import com.nukkitx.protocol.bedrock.data.ContainerType;
|
|||||||
import com.nukkitx.protocol.bedrock.data.EntityData;
|
import com.nukkitx.protocol.bedrock.data.EntityData;
|
||||||
import com.nukkitx.protocol.bedrock.data.ItemData;
|
import com.nukkitx.protocol.bedrock.data.ItemData;
|
||||||
import com.nukkitx.protocol.bedrock.packet.UpdateTradePacket;
|
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.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
import org.geysermc.connector.network.translators.Translator;
|
import org.geysermc.connector.network.translators.Translator;
|
||||||
@ -50,12 +50,8 @@ public class JavaTradeListTranslator extends PacketTranslator<ServerTradeListPac
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translate(ServerTradeListPacket packet, GeyserSession session) {
|
public void translate(ServerTradeListPacket packet, GeyserSession session) {
|
||||||
VillagerEntity villager = (VillagerEntity) session.getEntityCache().getEntityByGeyserId(session.getLastInteractedVillagerEid());
|
Entity villager = session.getPlayerEntity();
|
||||||
if (villager == null) {
|
session.setVillagerTrades(packet.getTrades());
|
||||||
session.getConnector().getLogger().debug("Could not find villager with entity id: " + session.getLastInteractedVillagerEid());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
villager.setVillagerTrades(packet.getTrades());
|
|
||||||
villager.getMetadata().put(EntityData.TRADE_TIER, packet.getVillagerLevel() - 1);
|
villager.getMetadata().put(EntityData.TRADE_TIER, packet.getVillagerLevel() - 1);
|
||||||
villager.getMetadata().put(EntityData.MAX_TRADE_TIER, 4);
|
villager.getMetadata().put(EntityData.MAX_TRADE_TIER, 4);
|
||||||
villager.getMetadata().put(EntityData.TRADE_XP, packet.getExperience());
|
villager.getMetadata().put(EntityData.TRADE_XP, packet.getExperience());
|
||||||
@ -70,7 +66,7 @@ public class JavaTradeListTranslator extends PacketTranslator<ServerTradeListPac
|
|||||||
updateTradePacket.setScreen2(true);
|
updateTradePacket.setScreen2(true);
|
||||||
updateTradePacket.setWilling(true);
|
updateTradePacket.setWilling(true);
|
||||||
updateTradePacket.setPlayerUniqueEntityId(session.getPlayerEntity().getGeyserId());
|
updateTradePacket.setPlayerUniqueEntityId(session.getPlayerEntity().getGeyserId());
|
||||||
updateTradePacket.setTraderUniqueEntityId(session.getLastInteractedVillagerEid());
|
updateTradePacket.setTraderUniqueEntityId(session.getPlayerEntity().getGeyserId());
|
||||||
CompoundTagBuilder builder = CompoundTagBuilder.builder();
|
CompoundTagBuilder builder = CompoundTagBuilder.builder();
|
||||||
List<CompoundTag> tags = new ArrayList<>();
|
List<CompoundTag> tags = new ArrayList<>();
|
||||||
for (VillagerTrade trade : packet.getTrades()) {
|
for (VillagerTrade trade : packet.getTrades()) {
|
||||||
@ -94,7 +90,7 @@ public class JavaTradeListTranslator extends PacketTranslator<ServerTradeListPac
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Hidden trade to fix visual experience bug
|
//Hidden trade to fix visual experience bug
|
||||||
if (packet.getVillagerLevel() < 5) {
|
if (packet.isRegularVillager() && packet.getVillagerLevel() < 5) {
|
||||||
tags.add(CompoundTagBuilder.builder()
|
tags.add(CompoundTagBuilder.builder()
|
||||||
.intTag("maxUses", 0)
|
.intTag("maxUses", 0)
|
||||||
.intTag("traderExp", 0)
|
.intTag("traderExp", 0)
|
||||||
@ -112,10 +108,10 @@ public class JavaTradeListTranslator extends PacketTranslator<ServerTradeListPac
|
|||||||
builder.listTag("Recipes", CompoundTag.class, tags);
|
builder.listTag("Recipes", CompoundTag.class, tags);
|
||||||
List<CompoundTag> expTags = new ArrayList<>();
|
List<CompoundTag> expTags = new ArrayList<>();
|
||||||
expTags.add(CompoundTagBuilder.builder().intTag("0", 0).buildRootTag());
|
expTags.add(CompoundTagBuilder.builder().intTag("0", 0).buildRootTag());
|
||||||
expTags.add(CompoundTagBuilder.builder().intTag("1", 11).buildRootTag());
|
expTags.add(CompoundTagBuilder.builder().intTag("1", 10).buildRootTag());
|
||||||
expTags.add(CompoundTagBuilder.builder().intTag("2", 71).buildRootTag());
|
expTags.add(CompoundTagBuilder.builder().intTag("2", 70).buildRootTag());
|
||||||
expTags.add(CompoundTagBuilder.builder().intTag("3", 151).buildRootTag());
|
expTags.add(CompoundTagBuilder.builder().intTag("3", 150).buildRootTag());
|
||||||
expTags.add(CompoundTagBuilder.builder().intTag("4", 251).buildRootTag());
|
expTags.add(CompoundTagBuilder.builder().intTag("4", 250).buildRootTag());
|
||||||
builder.listTag("TierExpRequirements", CompoundTag.class, expTags);
|
builder.listTag("TierExpRequirements", CompoundTag.class, expTags);
|
||||||
updateTradePacket.setOffers(builder.buildRootTag());
|
updateTradePacket.setOffers(builder.buildRootTag());
|
||||||
session.sendUpstreamPacket(updateTradePacket);
|
session.sendUpstreamPacket(updateTradePacket);
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren