Search in sources :

Example 1 with Exchange

use of com.almuradev.almura.feature.exchange.Exchange in project Almura by AlmuraDev.

the class ClientExchangeManager method handleListItemsSaleStatus.

public void handleListItemsSaleStatus(final String id, @Nullable final List<ClientboundListItemsSaleStatusPacket.ListedItemUpdate> itemCandidates, @Nullable final List<ClientboundListItemsSaleStatusPacket.LastKnownPriceUpdate> lastKnowPriceItemCandidates) {
    checkNotNull(id);
    final Exchange axs = this.getExchange(id);
    if (axs == null) {
        return;
    }
    final List<ListItem> listItems = axs.getListItemsFor(Minecraft.getMinecraft().player.getUniqueID()).orElse(null);
    if (listItems == null || listItems.isEmpty()) {
        return;
    }
    // Null out all for sale items, our candidates will have what we currently have
    listItems.forEach(item -> item.setForSaleItem(null));
    if (itemCandidates != null) {
        for (final ClientboundListItemsSaleStatusPacket.ListedItemUpdate itemCandidate : itemCandidates) {
            listItems.stream().filter(item -> item.getRecord() == itemCandidate.listItemRecNo).findAny().ifPresent(listItem -> listItem.setForSaleItem(new BasicForSaleItem((BasicListItem) listItem, itemCandidate.forSaleItemRecNo, itemCandidate.created, itemCandidate.price)));
        }
    }
    if (lastKnowPriceItemCandidates != null) {
        for (final ClientboundListItemsSaleStatusPacket.LastKnownPriceUpdate lastKnownPriceItemCandidate : lastKnowPriceItemCandidates) {
            listItems.stream().filter(item -> item.getRecord() == lastKnownPriceItemCandidate.listItemRecNo).findAny().ifPresent(listItem -> listItem.setLastKnownPrice(lastKnownPriceItemCandidate.lastKnownPrice));
        }
    }
}
Also used : Exchange(com.almuradev.almura.feature.exchange.Exchange) BasicForSaleItem(com.almuradev.almura.feature.exchange.basic.listing.BasicForSaleItem) ClientboundListItemsSaleStatusPacket(com.almuradev.almura.feature.exchange.network.ClientboundListItemsSaleStatusPacket) ListItem(com.almuradev.almura.feature.exchange.listing.ListItem) BasicListItem(com.almuradev.almura.feature.exchange.basic.listing.BasicListItem)

Example 2 with Exchange

use of com.almuradev.almura.feature.exchange.Exchange in project Almura by AlmuraDev.

the class ClientExchangeManager method handleExchangeSpecificOffer.

public void handleExchangeSpecificOffer(final String id) {
    checkNotNull(id);
    final GuiScreen currentScreen = Minecraft.getMinecraft().currentScreen;
    if (!(currentScreen instanceof ExchangeScreen)) {
        return;
    }
    final Exchange axs = this.getExchange(id);
    if (axs == null) {
        ((ExchangeScreen) currentScreen).close();
        return;
    }
    final ExchangeScreen axsScreen = (ExchangeScreen) currentScreen;
    new ExchangeOfferScreen(axsScreen, axs, axsScreen.listItemList.getItems().stream().filter(item -> !item.getForSaleItem().isPresent()).map(item -> new BasicVanillaStack(item.asRealStack())).collect(Collectors.toList()), axsScreen.limit).display();
}
Also used : Exchange(com.almuradev.almura.feature.exchange.Exchange) ExchangeModifyType(com.almuradev.almura.feature.exchange.ExchangeModifyType) FMLNetworkEvent(net.minecraftforge.fml.common.network.FMLNetworkEvent) Almura(com.almuradev.almura.Almura) ClientboundListItemsSaleStatusPacket(com.almuradev.almura.feature.exchange.network.ClientboundListItemsSaleStatusPacket) ServerboundModifyForSaleItemListStatusRequestPacket(com.almuradev.almura.feature.exchange.network.ServerboundModifyForSaleItemListStatusRequestPacket) ServerboundTransactionRequestPacket(com.almuradev.almura.feature.exchange.network.ServerboundTransactionRequestPacket) ListStatusType(com.almuradev.almura.feature.exchange.ListStatusType) Singleton(javax.inject.Singleton) ForSaleItem(com.almuradev.almura.feature.exchange.listing.ForSaleItem) ListItem(com.almuradev.almura.feature.exchange.listing.ListItem) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) BigDecimal(java.math.BigDecimal) Minecraft(net.minecraft.client.Minecraft) Side(net.minecraftforge.fml.relauncher.Side) BasicForSaleItem(com.almuradev.almura.feature.exchange.basic.listing.BasicForSaleItem) ExchangeModule(com.almuradev.almura.feature.exchange.ExchangeModule) ServerboundModifyExchangePacket(com.almuradev.almura.feature.exchange.network.ServerboundModifyExchangePacket) ExchangeOfferScreen(com.almuradev.almura.feature.exchange.client.gui.ExchangeOfferScreen) ExchangeScreen(com.almuradev.almura.feature.exchange.client.gui.ExchangeScreen) BasicListItem(com.almuradev.almura.feature.exchange.basic.listing.BasicListItem) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Nullable(javax.annotation.Nullable) Exchange(com.almuradev.almura.feature.exchange.Exchange) ExchangeManagementScreen(com.almuradev.almura.feature.exchange.client.gui.ExchangeManagementScreen) SoundEvents(net.minecraft.init.SoundEvents) ServerboundListItemsRequestPacket(com.almuradev.almura.feature.exchange.network.ServerboundListItemsRequestPacket) InventoryAction(com.almuradev.almura.feature.exchange.InventoryAction) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) ServerboundForSaleFilterResponsePacket(com.almuradev.almura.feature.exchange.network.ServerboundForSaleFilterResponsePacket) FeatureConstants(com.almuradev.almura.shared.feature.FeatureConstants) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) NetworkConfig(com.almuradev.almura.shared.network.NetworkConfig) BasicVanillaStack(com.almuradev.almura.shared.item.BasicVanillaStack) Collectors(java.util.stream.Collectors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) ChannelBinding(org.spongepowered.api.network.ChannelBinding) GuiScreen(net.minecraft.client.gui.GuiScreen) List(java.util.List) Witness(com.almuradev.core.event.Witness) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) ChannelId(org.spongepowered.api.network.ChannelId) ServerboundExchangeSpecificOfferRequestPacket(com.almuradev.almura.feature.exchange.network.ServerboundExchangeSpecificOfferRequestPacket) ExchangeOfferScreen(com.almuradev.almura.feature.exchange.client.gui.ExchangeOfferScreen) GuiScreen(net.minecraft.client.gui.GuiScreen) BasicVanillaStack(com.almuradev.almura.shared.item.BasicVanillaStack) ExchangeScreen(com.almuradev.almura.feature.exchange.client.gui.ExchangeScreen)

Example 3 with Exchange

use of com.almuradev.almura.feature.exchange.Exchange in project Almura by AlmuraDev.

the class ClientExchangeManager method handleForSaleItems.

public void handleForSaleItems(final String id, @Nullable final List<ForSaleItem> forSaleItems, int preLimitCount) {
    checkNotNull(id);
    final Exchange axs = this.getExchange(id);
    if (axs == null) {
        return;
    }
    final GuiScreen currentScreen = Minecraft.getMinecraft().currentScreen;
    if (currentScreen instanceof ExchangeScreen) {
        if (axs != ((ExchangeScreen) currentScreen).getExchange()) {
            return;
        }
        if (forSaleItems == null) {
            axs.putForSaleItems(null);
        } else {
            axs.putForSaleItems(forSaleItems.stream().collect(Collectors.groupingBy(k -> k.getListItem().getSeller(), ConcurrentHashMap::new, Collectors.toCollection(ArrayList::new))));
        }
        ((ExchangeScreen) currentScreen).refreshForSaleItemResults(forSaleItems, preLimitCount);
    }
}
Also used : Exchange(com.almuradev.almura.feature.exchange.Exchange) GuiScreen(net.minecraft.client.gui.GuiScreen) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ExchangeScreen(com.almuradev.almura.feature.exchange.client.gui.ExchangeScreen)

Example 4 with Exchange

use of com.almuradev.almura.feature.exchange.Exchange in project Almura by AlmuraDev.

the class ClientboundExchangeRegistryPacket method writeTo.

@Override
public void writeTo(final ChannelBuf buf) {
    buf.writeInteger(this.exchanges == null ? 0 : this.exchanges.size());
    if (this.exchanges != null) {
        for (final Exchange axs : this.exchanges) {
            buf.writeString(axs.getId());
            buf.writeString(axs.getName());
            try {
                final byte[] createdData = SerializationUtil.objectToBytes(axs.getCreated());
                buf.writeInteger(createdData.length);
                buf.writeBytes(createdData);
            } catch (IOException e) {
                e.printStackTrace();
                continue;
            }
            final byte[] creatorData = SerializationUtil.toBytes(axs.getCreator());
            buf.writeInteger(creatorData.length);
            buf.writeBytes(creatorData);
            final String creatorName = axs.getCreatorName().orElse(null);
            buf.writeBoolean(creatorName != null);
            if (creatorName != null) {
                buf.writeString(creatorName);
            }
            buf.writeString(axs.getPermission());
            buf.writeBoolean(axs.isHidden());
        }
    }
}
Also used : BasicExchange(com.almuradev.almura.feature.exchange.basic.BasicExchange) Exchange(com.almuradev.almura.feature.exchange.Exchange) IOException(java.io.IOException)

Example 5 with Exchange

use of com.almuradev.almura.feature.exchange.Exchange in project Almura by AlmuraDev.

the class ClientExchangeManager method handleExchangeSpecific.

public void handleExchangeSpecific(final String id, final int limit) {
    checkState(limit >= FeatureConstants.UNLIMITED);
    final Exchange axs = this.getExchange(id);
    if (axs != null) {
        this.clearFilterCache();
        new ExchangeScreen(axs, limit).display();
    }
}
Also used : Exchange(com.almuradev.almura.feature.exchange.Exchange) ExchangeScreen(com.almuradev.almura.feature.exchange.client.gui.ExchangeScreen)

Aggregations

Exchange (com.almuradev.almura.feature.exchange.Exchange)6 ExchangeScreen (com.almuradev.almura.feature.exchange.client.gui.ExchangeScreen)4 GuiScreen (net.minecraft.client.gui.GuiScreen)3 BasicForSaleItem (com.almuradev.almura.feature.exchange.basic.listing.BasicForSaleItem)2 BasicListItem (com.almuradev.almura.feature.exchange.basic.listing.BasicListItem)2 ListItem (com.almuradev.almura.feature.exchange.listing.ListItem)2 ClientboundListItemsSaleStatusPacket (com.almuradev.almura.feature.exchange.network.ClientboundListItemsSaleStatusPacket)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Almura (com.almuradev.almura.Almura)1 ExchangeModifyType (com.almuradev.almura.feature.exchange.ExchangeModifyType)1 ExchangeModule (com.almuradev.almura.feature.exchange.ExchangeModule)1 InventoryAction (com.almuradev.almura.feature.exchange.InventoryAction)1 ListStatusType (com.almuradev.almura.feature.exchange.ListStatusType)1 BasicExchange (com.almuradev.almura.feature.exchange.basic.BasicExchange)1 ExchangeManagementScreen (com.almuradev.almura.feature.exchange.client.gui.ExchangeManagementScreen)1 ExchangeOfferScreen (com.almuradev.almura.feature.exchange.client.gui.ExchangeOfferScreen)1 ForSaleItem (com.almuradev.almura.feature.exchange.listing.ForSaleItem)1 ServerboundExchangeSpecificOfferRequestPacket (com.almuradev.almura.feature.exchange.network.ServerboundExchangeSpecificOfferRequestPacket)1 ServerboundForSaleFilterResponsePacket (com.almuradev.almura.feature.exchange.network.ServerboundForSaleFilterResponsePacket)1 ServerboundListItemsRequestPacket (com.almuradev.almura.feature.exchange.network.ServerboundListItemsRequestPacket)1