Search in sources :

Example 1 with Store

use of com.almuradev.almura.feature.store.Store in project Almura by AlmuraDev.

the class ClientStoreManager method handleBuyingItems.

public void handleBuyingItems(final String id, @Nullable final List<BuyingItem> items) {
    checkNotNull(id);
    // Ensure we have the store screen open
    final GuiScreen currentScreen = Minecraft.getMinecraft().currentScreen;
    if (!(currentScreen instanceof StoreScreen)) {
        return;
    }
    // Update our local store
    final Store store = this.stores.stream().filter(s -> s.getId().equals(id)).findAny().orElse(null);
    if (store != null) {
        // Clear existing items
        store.getBuyingItems().clear();
        if (items != null) {
            // Add new items
            store.getBuyingItems().addAll(items);
        }
        // Refresh the screen and create controls
        ((StoreScreen) currentScreen).refresh(true);
    } else {
        // Refresh the screen
        ((StoreScreen) currentScreen).refresh(false);
    }
}
Also used : StoreScreen(com.almuradev.almura.feature.store.client.gui.StoreScreen) Store(com.almuradev.almura.feature.store.Store) GuiScreen(net.minecraft.client.gui.GuiScreen)

Example 2 with Store

use of com.almuradev.almura.feature.store.Store in project Almura by AlmuraDev.

the class ClientboundStoresRegistryPacket method writeTo.

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

Example 3 with Store

use of com.almuradev.almura.feature.store.Store in project Almura by AlmuraDev.

the class ClientStoreManager method handleSellingItems.

public void handleSellingItems(final String id, @Nullable final List<SellingItem> items) {
    checkNotNull(id);
    // Ensure we have the store screen open
    final GuiScreen currentScreen = Minecraft.getMinecraft().currentScreen;
    if (!(currentScreen instanceof StoreScreen)) {
        return;
    }
    // Update our local store
    final Store store = this.stores.stream().filter(s -> s.getId().equals(id)).findAny().orElse(null);
    if (store != null) {
        // Clear existing items
        store.getSellingItems().clear();
        if (items != null) {
            // Add new items
            store.getSellingItems().addAll(items);
        }
        // Refresh the screen and create controls
        ((StoreScreen) currentScreen).refresh(true);
    } else {
        // Refresh the screen
        ((StoreScreen) currentScreen).refresh(false);
    }
}
Also used : StoreScreen(com.almuradev.almura.feature.store.client.gui.StoreScreen) Store(com.almuradev.almura.feature.store.Store) GuiScreen(net.minecraft.client.gui.GuiScreen)

Example 4 with Store

use of com.almuradev.almura.feature.store.Store in project Almura by AlmuraDev.

the class ClientStoreManager method filterLocalItems.

@SuppressWarnings("unchecked")
public <T extends StoreItem> List<T> filterLocalItems(final String id, @Nullable final String filter, @Nullable final String sort, final SideType targetSide) {
    checkNotNull(id);
    checkNotNull(targetSide);
    final Store axs = this.getStore(id);
    checkNotNull(axs);
    Stream<T> stream = targetSide == SideType.BUY ? (Stream<T>) axs.getBuyingItems().stream() : (Stream<T>) axs.getSellingItems().stream();
    if (filter != null) {
        final List<FilterRegistry.FilterElement<StoreItem>> elements = FilterRegistry.instance.getFilterElements(filter);
        stream = stream.filter(storeItem -> elements.stream().allMatch(element -> element.getFilter().test(storeItem, element.getValue())));
    }
    if (sort != null) {
        final List<FilterRegistry.SorterElement<StoreItem>> elements = FilterRegistry.instance.getSortingElements(sort);
        final Comparator<StoreItem> comparator = FilterRegistry.instance.buildSortingComparator(elements).orElse(null);
        if (comparator != null) {
            stream = stream.sorted(comparator);
        }
    }
    return stream.collect(Collectors.toList());
}
Also used : FMLNetworkEvent(net.minecraftforge.fml.common.network.FMLNetworkEvent) Almura(com.almuradev.almura.Almura) FilterRegistry(com.almuradev.almura.shared.feature.filter.FilterRegistry) Inject(com.google.inject.Inject) ServerboundListItemsRequestPacket(com.almuradev.almura.feature.store.network.ServerboundListItemsRequestPacket) Singleton(javax.inject.Singleton) StoreModifyType(com.almuradev.almura.feature.store.StoreModifyType) BuyingItem(com.almuradev.almura.feature.store.listing.BuyingItem) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) Lists(com.google.common.collect.Lists) Minecraft(net.minecraft.client.Minecraft) ServerboundDelistItemsPacket(com.almuradev.almura.feature.store.network.ServerboundDelistItemsPacket) SellingItem(com.almuradev.almura.feature.store.listing.SellingItem) StoreItem(com.almuradev.almura.feature.store.listing.StoreItem) StoreItemSegmentType(com.almuradev.almura.feature.store.StoreItemSegmentType) Nullable(javax.annotation.Nullable) VanillaStack(com.almuradev.almura.shared.item.VanillaStack) ServerboundItemTransactionPacket(com.almuradev.almura.feature.store.network.ServerboundItemTransactionPacket) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) FeatureConstants(com.almuradev.almura.shared.feature.FeatureConstants) Store(com.almuradev.almura.feature.store.Store) StoreScreen(com.almuradev.almura.feature.store.client.gui.StoreScreen) Set(java.util.Set) NetworkConfig(com.almuradev.almura.shared.network.NetworkConfig) SideType(com.almuradev.almura.feature.store.SideType) Collectors(java.util.stream.Collectors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) StoreManagementScreen(com.almuradev.almura.feature.store.client.gui.StoreManagementScreen) ChannelBinding(org.spongepowered.api.network.ChannelBinding) GuiScreen(net.minecraft.client.gui.GuiScreen) List(java.util.List) Stream(java.util.stream.Stream) Witness(com.almuradev.core.event.Witness) ServerboundModifyStorePacket(com.almuradev.almura.feature.store.network.ServerboundModifyStorePacket) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) ChannelId(org.spongepowered.api.network.ChannelId) Comparator(java.util.Comparator) ServerboundModifyItemsPacket(com.almuradev.almura.feature.store.network.ServerboundModifyItemsPacket) StoreItem(com.almuradev.almura.feature.store.listing.StoreItem) Store(com.almuradev.almura.feature.store.Store)

Aggregations

Store (com.almuradev.almura.feature.store.Store)4 StoreScreen (com.almuradev.almura.feature.store.client.gui.StoreScreen)3 GuiScreen (net.minecraft.client.gui.GuiScreen)3 Almura (com.almuradev.almura.Almura)1 SideType (com.almuradev.almura.feature.store.SideType)1 StoreItemSegmentType (com.almuradev.almura.feature.store.StoreItemSegmentType)1 StoreModifyType (com.almuradev.almura.feature.store.StoreModifyType)1 BasicStore (com.almuradev.almura.feature.store.basic.BasicStore)1 StoreManagementScreen (com.almuradev.almura.feature.store.client.gui.StoreManagementScreen)1 BuyingItem (com.almuradev.almura.feature.store.listing.BuyingItem)1 SellingItem (com.almuradev.almura.feature.store.listing.SellingItem)1 StoreItem (com.almuradev.almura.feature.store.listing.StoreItem)1 ServerboundDelistItemsPacket (com.almuradev.almura.feature.store.network.ServerboundDelistItemsPacket)1 ServerboundItemTransactionPacket (com.almuradev.almura.feature.store.network.ServerboundItemTransactionPacket)1 ServerboundListItemsRequestPacket (com.almuradev.almura.feature.store.network.ServerboundListItemsRequestPacket)1 ServerboundModifyItemsPacket (com.almuradev.almura.feature.store.network.ServerboundModifyItemsPacket)1 ServerboundModifyStorePacket (com.almuradev.almura.feature.store.network.ServerboundModifyStorePacket)1 FeatureConstants (com.almuradev.almura.shared.feature.FeatureConstants)1 FilterRegistry (com.almuradev.almura.shared.feature.filter.FilterRegistry)1 VanillaStack (com.almuradev.almura.shared.item.VanillaStack)1