Search in sources :

Example 1 with BasicVanillaStack

use of com.almuradev.almura.shared.item.BasicVanillaStack 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 2 with BasicVanillaStack

use of com.almuradev.almura.shared.item.BasicVanillaStack in project Almura by AlmuraDev.

the class ServerboundListItemsRequestPacket method readFrom.

@Override
public void readFrom(final ChannelBuf buf) {
    this.id = buf.readString();
    final int count = buf.readInteger();
    checkState(count > 0);
    this.actions = new ArrayList<>();
    for (int i = 0; i < count; i++) {
        final InventoryAction.Direction direction = InventoryAction.Direction.valueOf(buf.readString());
        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 list item! . Skipping...").printStackTrace();
            continue;
        }
        final int quantity = buf.readInteger();
        final int metadata = 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 BasicVanillaStack stack = new BasicVanillaStack(item, quantity, metadata, compound);
        this.actions.add(new InventoryAction(direction, stack));
    }
}
Also used : Item(net.minecraft.item.Item) ResourceLocation(net.minecraft.util.ResourceLocation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IOException(java.io.IOException) BasicVanillaStack(com.almuradev.almura.shared.item.BasicVanillaStack) InventoryAction(com.almuradev.almura.feature.exchange.InventoryAction)

Example 3 with BasicVanillaStack

use of com.almuradev.almura.shared.item.BasicVanillaStack in project Almura by AlmuraDev.

the class ServerboundListItemsRequestPacket 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) {
        this.candidates = new ArrayList<>();
        for (int i = 0; i < count; i++) {
            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;
                }
            }
            this.candidates.add(new ListCandidate(new BasicVanillaStack(item, quantity, metadata, compound), index, price));
        }
    }
}
Also used : Item(net.minecraft.item.Item) ResourceLocation(net.minecraft.util.ResourceLocation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IOException(java.io.IOException) BasicVanillaStack(com.almuradev.almura.shared.item.BasicVanillaStack) BigDecimal(java.math.BigDecimal)

Example 4 with BasicVanillaStack

use of com.almuradev.almura.shared.item.BasicVanillaStack in project Almura by AlmuraDev.

the class UIItemList method insertItem.

@Override
@Nonnull
public ItemStack insertItem(final int slot, @Nonnull final ItemStack stack, final boolean simulate) {
    if (simulate) {
        throw new UnsupportedOperationException("Simulation not supported!");
    }
    // Copy before changes because Vanilla
    final ItemStack diffStack = stack.copy();
    int amountUsed = 0;
    final ItemStack stackInSlot = this.getStackInSlot(slot);
    final int stackInSlotLimit = this.enforceStackLimit ? stackInSlot.getMaxStackSize() : this.maxSlotStackSize;
    if (ItemHandlerHelper.canItemStacksStack(stackInSlot, stack)) {
        final int toAdd = Math.min(Math.min(stackInSlotLimit, stack.getCount()), stackInSlotLimit - stackInSlot.getCount());
        amountUsed += toAdd;
        stackInSlot.grow(toAdd);
        this.markDirty();
    } else if (stackInSlot.isEmpty()) {
        final VanillaStack newStack = new BasicVanillaStack(stack);
        newStack.setQuantity(Math.min(stackInSlotLimit, stack.getCount()));
        this.addItem(slot, newStack);
        amountUsed += newStack.getQuantity();
    }
    diffStack.setCount(stack.getCount() - amountUsed);
    return diffStack;
}
Also used : ItemStack(net.minecraft.item.ItemStack) BasicVanillaStack(com.almuradev.almura.shared.item.BasicVanillaStack) VanillaStack(com.almuradev.almura.shared.item.VanillaStack) BasicVanillaStack(com.almuradev.almura.shared.item.BasicVanillaStack) Nonnull(javax.annotation.Nonnull)

Example 5 with BasicVanillaStack

use of com.almuradev.almura.shared.item.BasicVanillaStack in project Almura by AlmuraDev.

the class ExchangeOfferScreen method construct.

@Override
public void construct() {
    this.guiscreenBackground = false;
    // Form
    final BasicForm form = new BasicForm(this, 400, 325, I18n.format("almura.feature.exchange.title.offer"));
    // Fixes issue overlapping draws from parent
    form.setZIndex(10);
    form.setBackgroundAlpha(255);
    // OK/Cancel buttons
    final UIButton buttonOk = new UIButtonBuilder(this).width(40).text(I18n.format("almura.button.ok")).x(1).anchor(Anchor.BOTTOM | Anchor.RIGHT).onClick(this::transact).build("button.ok");
    final UIButton buttonCancel = new UIButtonBuilder(this).width(40).text(I18n.format("almura.button.cancel")).x(getPaddedX(buttonOk, 2, Anchor.RIGHT)).anchor(Anchor.BOTTOM | Anchor.RIGHT).onClick(this::close).build("button.cancel");
    // Swap container
    final NonNullList<ItemStack> mainInventory = Minecraft.getMinecraft().player.inventory.mainInventory;
    final int totalItemsForSale = this.exchange.getForSaleItemsFor(Minecraft.getMinecraft().player.getUniqueID()).map(List::size).orElse(0);
    this.offerContainer = new UIExchangeOfferContainer(this, getPaddedWidth(form), getPaddedHeight(form) - 20, TextFormatting.WHITE + I18n.format("almura.feature.exchange.text.inventory"), TextFormatting.WHITE + I18n.format("almura.feature.exchange.text.unlisted_items"), mainInventory.size(), this.limit, totalItemsForSale);
    this.offerContainer.register(this);
    // Populate offer container
    final List<VanillaStack> inventoryOffers = new ArrayList<>();
    mainInventory.stream().filter(i -> !i.isEmpty() && i.getItem() != null).forEach(i -> inventoryOffers.add(new BasicVanillaStack(i)));
    this.offerContainer.setItems(this.pendingItems, BasicDualListContainer.SideType.RIGHT);
    this.offerContainer.setItems(inventoryOffers, BasicDualListContainer.SideType.LEFT);
    form.add(this.offerContainer, buttonOk, buttonCancel);
    addToScreen(form);
}
Also used : UIButton(net.malisis.core.client.gui.component.interaction.UIButton) VanillaStack(com.almuradev.almura.shared.item.VanillaStack) ClientExchangeManager(com.almuradev.almura.feature.exchange.client.ClientExchangeManager) InventoryAction(com.almuradev.almura.feature.exchange.InventoryAction) TextFormatting(net.minecraft.util.text.TextFormatting) UIButtonBuilder(net.malisis.core.client.gui.component.interaction.button.builder.UIButtonBuilder) UIExchangeOfferContainer(com.almuradev.almura.feature.exchange.client.gui.component.UIExchangeOfferContainer) BasicVanillaStack(com.almuradev.almura.shared.item.BasicVanillaStack) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) BasicForm(net.malisis.core.client.gui.component.container.BasicForm) I18n(net.minecraft.client.resources.I18n) Inject(javax.inject.Inject) ItemStack(net.minecraft.item.ItemStack) List(java.util.List) Minecraft(net.minecraft.client.Minecraft) Side(net.minecraftforge.fml.relauncher.Side) Anchor(net.malisis.core.client.gui.Anchor) BasicDualListContainer(net.malisis.core.client.gui.component.container.BasicDualListContainer) Subscribe(com.google.common.eventbus.Subscribe) BasicScreen(net.malisis.core.client.gui.BasicScreen) NonNullList(net.minecraft.util.NonNullList) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Exchange(com.almuradev.almura.feature.exchange.Exchange) BasicForm(net.malisis.core.client.gui.component.container.BasicForm) UIButtonBuilder(net.malisis.core.client.gui.component.interaction.button.builder.UIButtonBuilder) UIExchangeOfferContainer(com.almuradev.almura.feature.exchange.client.gui.component.UIExchangeOfferContainer) UIButton(net.malisis.core.client.gui.component.interaction.UIButton) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) BasicVanillaStack(com.almuradev.almura.shared.item.BasicVanillaStack) VanillaStack(com.almuradev.almura.shared.item.VanillaStack) BasicVanillaStack(com.almuradev.almura.shared.item.BasicVanillaStack)

Aggregations

BasicVanillaStack (com.almuradev.almura.shared.item.BasicVanillaStack)6 InventoryAction (com.almuradev.almura.feature.exchange.InventoryAction)3 VanillaStack (com.almuradev.almura.shared.item.VanillaStack)3 BigDecimal (java.math.BigDecimal)3 Exchange (com.almuradev.almura.feature.exchange.Exchange)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 Minecraft (net.minecraft.client.Minecraft)2 Item (net.minecraft.item.Item)2 ItemStack (net.minecraft.item.ItemStack)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 Almura (com.almuradev.almura.Almura)1 ExchangeModifyType (com.almuradev.almura.feature.exchange.ExchangeModifyType)1 ExchangeModule (com.almuradev.almura.feature.exchange.ExchangeModule)1 ListStatusType (com.almuradev.almura.feature.exchange.ListStatusType)1 BasicForSaleItem (com.almuradev.almura.feature.exchange.basic.listing.BasicForSaleItem)1