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();
}
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));
}
}
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));
}
}
}
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;
}
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);
}
Aggregations