105 lines
2.8 KiB
Java
Executable file
105 lines
2.8 KiB
Java
Executable file
package game.packet;
|
|
|
|
import java.io.IOException;
|
|
|
|
import game.item.ItemStack;
|
|
import game.network.IClientPlayer;
|
|
import game.network.Packet;
|
|
import game.network.PacketBuffer;
|
|
import game.village.MerchantRecipe;
|
|
import game.village.MerchantRecipeList;
|
|
|
|
public class SPacketTrades implements Packet<IClientPlayer>
|
|
{
|
|
private MerchantRecipeList recipes;
|
|
private int windowId;
|
|
|
|
public SPacketTrades()
|
|
{
|
|
}
|
|
|
|
public SPacketTrades(MerchantRecipeList recipesIn, int windowIdIn)
|
|
{
|
|
this.recipes = recipesIn;
|
|
this.windowId = windowIdIn;
|
|
}
|
|
|
|
/**
|
|
* Reads the raw packet data from the data stream.
|
|
*/
|
|
public void readPacketData(PacketBuffer buf) throws IOException
|
|
{
|
|
this.windowId = buf.readInt();
|
|
this.recipes = new MerchantRecipeList();
|
|
int i = buf.readByte() & 255;
|
|
|
|
for (int j = 0; j < i; ++j)
|
|
{
|
|
ItemStack itemstack = buf.readItemStackFromBuffer();
|
|
ItemStack itemstack1 = buf.readItemStackFromBuffer();
|
|
ItemStack itemstack2 = null;
|
|
|
|
if (buf.readBoolean())
|
|
{
|
|
itemstack2 = buf.readItemStackFromBuffer();
|
|
}
|
|
|
|
// boolean flag = buf.readBoolean();
|
|
// int k = buf.readInt();
|
|
// int l = buf.readInt();
|
|
MerchantRecipe merchantrecipe = new MerchantRecipe(itemstack, itemstack2, itemstack1); // , k, l);
|
|
|
|
// if (flag)
|
|
// {
|
|
// merchantrecipe.compensateToolUses();
|
|
// }
|
|
|
|
this.recipes.add(merchantrecipe);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Writes the raw packet data to the data stream.
|
|
*/
|
|
public void writePacketData(PacketBuffer buf) throws IOException
|
|
{
|
|
buf.writeInt(this.windowId);
|
|
buf.writeByte((byte)(this.recipes.size() & 255));
|
|
|
|
for (int i = 0; i < this.recipes.size(); ++i)
|
|
{
|
|
MerchantRecipe merchantrecipe = (MerchantRecipe)this.recipes.get(i);
|
|
buf.writeItemStackToBuffer(merchantrecipe.getItemToBuy());
|
|
buf.writeItemStackToBuffer(merchantrecipe.getItemToSell());
|
|
ItemStack itemstack = merchantrecipe.getSecondItemToBuy();
|
|
buf.writeBoolean(itemstack != null);
|
|
|
|
if (itemstack != null)
|
|
{
|
|
buf.writeItemStackToBuffer(itemstack);
|
|
}
|
|
|
|
// buf.writeBoolean(merchantrecipe.isRecipeDisabled());
|
|
// buf.writeInt(merchantrecipe.getToolUses());
|
|
// buf.writeInt(merchantrecipe.getMaxTradeUses());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Passes this Packet on to the NetHandler for processing.
|
|
*/
|
|
public void processPacket(IClientPlayer handler)
|
|
{
|
|
handler.handleTrades(this);
|
|
}
|
|
|
|
public MerchantRecipeList getTrades()
|
|
{
|
|
return this.recipes;
|
|
}
|
|
|
|
public int getWindowId()
|
|
{
|
|
return this.windowId;
|
|
}
|
|
}
|