mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2024-12-04 21:01:02 -05:00
Add TradeListPacket
This commit is contained in:
parent
2f4a43f729
commit
49627dbc45
3 changed files with 182 additions and 4 deletions
|
@ -114,6 +114,7 @@ import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerOpenH
|
|||
import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerOpenWindowPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerPreparedCraftingGridPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerSetSlotPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerTradeListPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerWindowItemsPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerWindowPropertyPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerBlockBreakAnimPacket;
|
||||
|
@ -398,11 +399,11 @@ public class MinecraftProtocol extends PacketProtocol {
|
|||
// 0x24 Update Light - New
|
||||
this.registerIncoming(0x25, ServerJoinGamePacket.class);
|
||||
this.registerIncoming(0x26, ServerMapDataPacket.class);
|
||||
this.registerIncoming(0x27, ServerEntityMovementPacket.class);
|
||||
this.registerIncoming(0x27, ServerTradeListPacket.class);
|
||||
this.registerIncoming(0x28, ServerEntityPositionPacket.class);
|
||||
this.registerIncoming(0x29, ServerEntityPositionRotationPacket.class);
|
||||
this.registerIncoming(0x2A, ServerEntityRotationPacket.class);
|
||||
// 0x2B Entity?
|
||||
this.registerIncoming(0x2B, ServerEntityMovementPacket.class);
|
||||
this.registerIncoming(0x2C, ServerVehicleMovePacket.class);
|
||||
this.registerIncoming(0x2D, ServerOpenBookPacket.class);
|
||||
this.registerIncoming(0x2E, ServerOpenWindowPacket.class);
|
||||
|
@ -588,11 +589,11 @@ public class MinecraftProtocol extends PacketProtocol {
|
|||
// 0x24 Update Light - New
|
||||
this.registerOutgoing(0x25, ServerJoinGamePacket.class);
|
||||
this.registerOutgoing(0x26, ServerMapDataPacket.class);
|
||||
this.registerOutgoing(0x27, ServerEntityMovementPacket.class);
|
||||
this.registerOutgoing(0x27, ServerTradeListPacket.class);
|
||||
this.registerOutgoing(0x28, ServerEntityPositionPacket.class);
|
||||
this.registerOutgoing(0x29, ServerEntityPositionRotationPacket.class);
|
||||
this.registerOutgoing(0x2A, ServerEntityRotationPacket.class);
|
||||
// 0x2B Entity?
|
||||
this.registerOutgoing(0x2B, ServerEntityMovementPacket.class);
|
||||
this.registerOutgoing(0x2C, ServerVehicleMovePacket.class);
|
||||
this.registerOutgoing(0x2D, ServerOpenBookPacket.class);
|
||||
this.registerOutgoing(0x2E, ServerOpenWindowPacket.class);
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.window;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
||||
import com.github.steveice10.mc.protocol.util.NetUtil;
|
||||
import com.github.steveice10.packetlib.io.NetInput;
|
||||
import com.github.steveice10.packetlib.io.NetOutput;
|
||||
|
||||
public class VillagerTrade {
|
||||
|
||||
private ItemStack input1Item;
|
||||
private ItemStack input2Item;
|
||||
private ItemStack outputItem;
|
||||
private boolean tradeDisabled;
|
||||
private int numberOfUses;
|
||||
private int maxNumberOfUses;
|
||||
private int xp;
|
||||
private int specialPrice;
|
||||
private float priceMultiplier;
|
||||
|
||||
public VillagerTrade() {
|
||||
}
|
||||
|
||||
public VillagerTrade(ItemStack input1Item, ItemStack input2Item, ItemStack outputItem, boolean tradeDisabled, int numberOfUses, int maxNumberOfUses, int xp, int specialPrice, float priceMultiplier) {
|
||||
this.input1Item = input1Item;
|
||||
this.input2Item = input2Item;
|
||||
this.outputItem = outputItem;
|
||||
this.tradeDisabled = tradeDisabled;
|
||||
this.numberOfUses = numberOfUses;
|
||||
this.maxNumberOfUses = maxNumberOfUses;
|
||||
this.xp = xp;
|
||||
this.specialPrice = specialPrice;
|
||||
this.priceMultiplier = priceMultiplier;
|
||||
}
|
||||
|
||||
public ItemStack getInput1Item() {
|
||||
return input1Item;
|
||||
}
|
||||
|
||||
public ItemStack getInput2Item() {
|
||||
return input2Item;
|
||||
}
|
||||
|
||||
public ItemStack getOutputItem() {
|
||||
return outputItem;
|
||||
}
|
||||
|
||||
public boolean isTradeDisabled() {
|
||||
return tradeDisabled;
|
||||
}
|
||||
|
||||
public int getNumberOfUses() {
|
||||
return numberOfUses;
|
||||
}
|
||||
|
||||
public int getMaxNumberOfUses() {
|
||||
return maxNumberOfUses;
|
||||
}
|
||||
|
||||
public int getXp() {
|
||||
return xp;
|
||||
}
|
||||
|
||||
public int getSpecialPrice() {
|
||||
return specialPrice;
|
||||
}
|
||||
|
||||
public float getPriceMultiplier() {
|
||||
return priceMultiplier;
|
||||
}
|
||||
|
||||
public void read(NetInput in) throws IOException {
|
||||
this.input1Item = NetUtil.readItem(in);
|
||||
this.outputItem = NetUtil.readItem(in);
|
||||
boolean hasSecondItem = in.readBoolean();
|
||||
if (hasSecondItem) {
|
||||
this.input2Item = NetUtil.readItem(in);
|
||||
}
|
||||
this.tradeDisabled = in.readBoolean();
|
||||
this.numberOfUses = in.readInt();
|
||||
this.maxNumberOfUses = in.readInt();
|
||||
this.xp = in.readInt();
|
||||
this.specialPrice = in.readInt();
|
||||
this.priceMultiplier = in.readFloat();
|
||||
}
|
||||
|
||||
public void write(NetOutput out) throws IOException {
|
||||
NetUtil.writeItem(out, this.input1Item);
|
||||
NetUtil.writeItem(out, this.outputItem);
|
||||
boolean hasSecondItem = this.input2Item != null;
|
||||
out.writeBoolean(hasSecondItem);
|
||||
if (hasSecondItem) {
|
||||
NetUtil.writeItem(out, this.input2Item);
|
||||
}
|
||||
out.writeBoolean(this.tradeDisabled);
|
||||
out.writeInt(this.numberOfUses);
|
||||
out.writeInt(this.maxNumberOfUses);
|
||||
out.writeInt(this.xp);
|
||||
out.writeInt(this.specialPrice);
|
||||
out.writeFloat(this.priceMultiplier);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package com.github.steveice10.mc.protocol.packet.ingame.server.window;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.window.VillagerTrade;
|
||||
import com.github.steveice10.mc.protocol.packet.MinecraftPacket;
|
||||
import com.github.steveice10.packetlib.io.NetInput;
|
||||
import com.github.steveice10.packetlib.io.NetOutput;
|
||||
|
||||
public class ServerTradeListPacket extends MinecraftPacket {
|
||||
|
||||
private int windowId;
|
||||
private VillagerTrade[] trades;
|
||||
private int villagerLevel;
|
||||
private int experience;
|
||||
private boolean isRegularVillager;
|
||||
|
||||
public ServerTradeListPacket() {
|
||||
}
|
||||
|
||||
public ServerTradeListPacket(int windowId, VillagerTrade[] trades, int villagerLevel, int experience, boolean isRegularVillager) {
|
||||
this.windowId = windowId;
|
||||
this.trades = trades;
|
||||
this.villagerLevel = villagerLevel;
|
||||
this.experience = experience;
|
||||
this.isRegularVillager = isRegularVillager;
|
||||
}
|
||||
|
||||
public int getWindowId() {
|
||||
return windowId;
|
||||
}
|
||||
|
||||
public VillagerTrade[] getTrades() {
|
||||
return trades;
|
||||
}
|
||||
|
||||
public int getVillagerLevel() {
|
||||
return villagerLevel;
|
||||
}
|
||||
|
||||
public int getExperience() {
|
||||
return experience;
|
||||
}
|
||||
|
||||
public boolean isRegularVillager() {
|
||||
return isRegularVillager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(NetInput in) throws IOException {
|
||||
this.windowId = in.readVarInt();
|
||||
byte size = in.readByte();
|
||||
this.trades = new VillagerTrade[size];
|
||||
for (int i = 0; i < trades.length; i++) {
|
||||
trades[i] = new VillagerTrade();
|
||||
trades[i].read(in);
|
||||
}
|
||||
this.villagerLevel = in.readVarInt();
|
||||
this.experience = in.readVarInt();
|
||||
this.isRegularVillager = in.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(NetOutput out) throws IOException {
|
||||
out.writeVarInt(this.windowId);
|
||||
out.writeByte(this.trades.length);
|
||||
for (int i = 0; i < trades.length; i++) {
|
||||
this.trades[i].write(out);
|
||||
}
|
||||
out.writeVarInt(this.villagerLevel);
|
||||
out.writeVarInt(this.experience);
|
||||
out.writeBoolean(this.isRegularVillager);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue