use of com.almuradev.almura.feature.store.basic.listing.AbstractStoreItem in project Almura by AlmuraDev.
the class ClientboundListItemsResponsePacket method readFrom.
@Override
public void readFrom(final ChannelBuf buf) {
this.id = buf.readString();
this.type = StoreItemSegmentType.valueOf(buf.readString());
final int count = buf.readInteger();
if (count > 0) {
if (type == StoreItemSegmentType.SELLING) {
this.storeItems = new ArrayList<SellingItem>();
} else {
this.storeItems = new ArrayList<BuyingItem>();
}
for (int i = 0; i < count; i++) {
final int record = buf.readInteger();
final Instant created;
try {
created = SerializationUtil.bytesToObject(buf.readBytes(buf.readInteger()));
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
continue;
}
final ResourceLocation location = new ResourceLocation(buf.readString(), buf.readString());
final Item item = ForgeRegistries.ITEMS.getValue(location);
if (item == null) {
new IOException("Unknown item id '" + location.toString() + "' when receiving item! . Skipping...").printStackTrace();
continue;
}
final int quantity = buf.readInteger();
final int metadata = buf.readInteger();
final BigDecimal price = ByteBufUtil.readBigDecimal((ByteBuf) buf);
final int index = buf.readInteger();
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 Constructor<? extends AbstractStoreItem> constructor;
try {
constructor = this.type.getItemClass().getConstructor(Integer.TYPE, Instant.class, Item.class, Integer.TYPE, Integer.TYPE, BigDecimal.class, Integer.TYPE, NBTTagCompound.class);
final AbstractStoreItem storeItem = constructor.newInstance(record, created, item, quantity, metadata, price, index, compound);
if (this.type == StoreItemSegmentType.SELLING) {
((List<SellingItem>) this.storeItems).add((SellingItem) storeItem);
} else {
((List<BuyingItem>) this.storeItems).add((BuyingItem) storeItem);
}
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
Aggregations