Search in sources :

Example 6 with BasicListItem

use of com.almuradev.almura.feature.exchange.basic.listing.BasicListItem in project Almura by AlmuraDev.

the class ClientboundForSaleItemsResponsePacket method readFrom.

@Override
public void readFrom(final ChannelBuf buf) {
    this.id = buf.readString();
    final int count = buf.readInteger();
    if (count > 0) {
        this.forSaleItems = new ArrayList<>();
        for (int i = 0; i < count; i++) {
            final int listItemRecNo = buf.readInteger();
            final ResourceLocation location = new ResourceLocation(buf.readString(), buf.readString());
            final Item item = ForgeRegistries.ITEMS.getValue(location);
            if (item == null) {
                new IOException("Unknown item id when receiving for sale item! Id [" + location + "]. Skipping...").printStackTrace();
                continue;
            }
            final int quantity = buf.readInteger();
            final int metadata = buf.readInteger();
            final Instant listItemCreated;
            try {
                listItemCreated = SerializationUtil.bytesToObject(buf.readBytes(buf.readInteger()));
            } catch (IOException | ClassNotFoundException e) {
                e.printStackTrace();
                continue;
            }
            final UUID seller = buf.readUniqueId();
            final String sellerName = buf.readBoolean() ? buf.readString() : null;
            final int index = buf.readInteger();
            BigDecimal lastKnownPrice = null;
            if (buf.readBoolean()) {
                lastKnownPrice = ByteBufUtil.readBigDecimal((ByteBuf) buf);
            }
            final int compoundDataLength = buf.readInteger();
            NBTTagCompound compound = null;
            if (compoundDataLength > 0) {
                try {
                    compound = SerializationUtil.compoundFromBytes(buf.readBytes(compoundDataLength));
                } catch (IOException e) {
                    e.printStackTrace();
                    continue;
                }
            }
            final BasicListItem basicListItem = new BasicListItem(listItemRecNo, listItemCreated, seller, item, quantity, metadata, index, lastKnownPrice, compound);
            if (Sponge.getPlatform().getExecutionType().isClient()) {
                basicListItem.setSellerName(sellerName);
            }
            final int forSaleItemRecNo = buf.readInteger();
            // ForSaleItem
            final Instant forSaleItemCreated;
            try {
                forSaleItemCreated = SerializationUtil.bytesToObject(buf.readBytes(buf.readInteger()));
            } catch (IOException | ClassNotFoundException e) {
                e.printStackTrace();
                continue;
            }
            final BigDecimal price = ByteBufUtil.readBigDecimal((ByteBuf) buf);
            final BasicForSaleItem basicForSaleItem = new BasicForSaleItem(basicListItem, forSaleItemRecNo, forSaleItemCreated, price);
            this.forSaleItems.add(basicForSaleItem);
        }
    }
    this.preLimitCount = buf.readInteger();
}
Also used : Instant(java.time.Instant) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IOException(java.io.IOException) BasicListItem(com.almuradev.almura.feature.exchange.basic.listing.BasicListItem) ByteBuf(io.netty.buffer.ByteBuf) BigDecimal(java.math.BigDecimal) Item(net.minecraft.item.Item) ForSaleItem(com.almuradev.almura.feature.exchange.listing.ForSaleItem) ListItem(com.almuradev.almura.feature.exchange.listing.ListItem) BasicForSaleItem(com.almuradev.almura.feature.exchange.basic.listing.BasicForSaleItem) BasicListItem(com.almuradev.almura.feature.exchange.basic.listing.BasicListItem) BasicForSaleItem(com.almuradev.almura.feature.exchange.basic.listing.BasicForSaleItem) ResourceLocation(net.minecraft.util.ResourceLocation) UUID(java.util.UUID)

Aggregations

BasicListItem (com.almuradev.almura.feature.exchange.basic.listing.BasicListItem)6 ListItem (com.almuradev.almura.feature.exchange.listing.ListItem)6 BasicForSaleItem (com.almuradev.almura.feature.exchange.basic.listing.BasicForSaleItem)5 ForSaleItem (com.almuradev.almura.feature.exchange.listing.ForSaleItem)4 BigDecimal (java.math.BigDecimal)4 AxsForSaleItem (com.almuradev.generated.axs.tables.AxsForSaleItem)3 AxsListItem (com.almuradev.generated.axs.tables.AxsListItem)3 IOException (java.io.IOException)3 Instant (java.time.Instant)3 UUID (java.util.UUID)3 Item (net.minecraft.item.Item)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 ClientboundListItemsSaleStatusPacket (com.almuradev.almura.feature.exchange.network.ClientboundListItemsSaleStatusPacket)2 AxsForSaleItemRecord (com.almuradev.generated.axs.tables.records.AxsForSaleItemRecord)2 ByteBuf (io.netty.buffer.ByteBuf)2 Timestamp (java.sql.Timestamp)2 ArrayList (java.util.ArrayList)2 Exchange (com.almuradev.almura.feature.exchange.Exchange)1 BasicExchange (com.almuradev.almura.feature.exchange.basic.BasicExchange)1