use of logisticspipes.utils.gui.LogisticsBaseGuiScreen in project LogisticsPipes by RS485.
the class GhostIngredientHandler method getTargets.
@Nonnull
@Override
public <I> List<Target<I>> getTargets(@Nonnull LogisticsBaseGuiScreen gui, @Nonnull I ingredient, boolean doStart) {
if (ingredient instanceof ItemStack) {
Stream<Target<I>> slotStream = gui.inventorySlots.inventorySlots.stream().filter(it -> it instanceof DummySlot).map(it -> (DummySlot) it).map(it -> new Target<I>() {
@Nonnull
@Override
public Rectangle getArea() {
return new Rectangle(gui.getGuiLeft() + it.xPos, gui.getGuiTop() + it.yPos, 17, 17);
}
@Override
public void accept(@Nonnull I ingredient) {
it.putStack((ItemStack) ingredient);
MainProxy.sendPacketToServer(PacketHandler.getPacket(SetGhostItemPacket.class).setInteger(it.slotNumber).setStack((ItemStack) ingredient));
}
});
if (FluidIdentifier.get((ItemStack) ingredient) != null) {
Stream<Target<I>> fluidStream = gui.inventorySlots.inventorySlots.stream().filter(it -> it instanceof FluidSlot).map(it -> (FluidSlot) it).map(it -> new Target<I>() {
@Nonnull
@Override
public Rectangle getArea() {
return new Rectangle(gui.getGuiLeft() + it.xPos, gui.getGuiTop() + it.yPos, 17, 17);
}
@Override
public void accept(@Nonnull I ingredient) {
FluidIdentifier ident = FluidIdentifier.get((ItemStack) ingredient);
if (ident != null) {
ItemStack stack = ident.getItemIdentifier().unsafeMakeNormalStack(1);
it.putStack(stack);
MainProxy.sendPacketToServer(PacketHandler.getPacket(SetGhostItemPacket.class).setInteger(it.slotNumber).setStack(stack));
}
}
});
slotStream = Stream.concat(slotStream, fluidStream);
}
return slotStream.collect(Collectors.toList());
} else if (ingredient instanceof FluidStack) {
return gui.inventorySlots.inventorySlots.stream().filter(it -> it instanceof FluidSlot).map(it -> (FluidSlot) it).map(it -> new Target<I>() {
@Nonnull
@Override
public Rectangle getArea() {
return new Rectangle(gui.getGuiLeft() + it.xPos, gui.getGuiTop() + it.yPos, 17, 17);
}
@Override
public void accept(@Nonnull I ingredient) {
FluidIdentifier ident = FluidIdentifier.get((FluidStack) ingredient);
if (ident != null) {
ItemStack stack = ident.getItemIdentifier().unsafeMakeNormalStack(1);
it.putStack(stack);
MainProxy.sendPacketToServer(PacketHandler.getPacket(SetGhostItemPacket.class).setInteger(it.slotNumber).setStack(stack));
}
}
}).collect(Collectors.toList());
}
return Collections.emptyList();
}
use of logisticspipes.utils.gui.LogisticsBaseGuiScreen in project LogisticsPipes by RS485.
the class RecipeTransferHandler method transferRecipe.
@Nullable
@Override
public IRecipeTransferError transferRecipe(@Nonnull DummyContainer container, @Nonnull IRecipeLayout recipeLayout, @Nonnull EntityPlayer player, boolean maxTransfer, boolean doTransfer) {
LogisticsBaseGuiScreen gui = container.guiHolderForJEI;
if (gui instanceof GuiLogisticsCraftingTable || gui instanceof GuiRequestTable) {
TileEntity tile;
if (gui instanceof GuiLogisticsCraftingTable) {
tile = ((GuiLogisticsCraftingTable) gui)._crafter;
} else {
tile = ((GuiRequestTable) gui)._table.container;
}
if (tile == null) {
return recipeTransferHandlerHelper.createInternalError();
}
if (!recipeLayout.getRecipeCategory().getUid().equals(VanillaRecipeCategoryUid.CRAFTING)) {
return recipeTransferHandlerHelper.createInternalError();
}
NEISetCraftingRecipe packet = PacketHandler.getPacket(NEISetCraftingRecipe.class);
NonNullList<ItemStack> stackList = packet.getStackList();
ItemStack[][] stacks = new ItemStack[9][];
boolean hasCanidates = false;
IGuiItemStackGroup guiItemStackGroup = recipeLayout.getItemStacks();
Map<Integer, ? extends IGuiIngredient<ItemStack>> guiIngredients = guiItemStackGroup.getGuiIngredients();
if (doTransfer) {
for (Map.Entry<Integer, ? extends IGuiIngredient<ItemStack>> ps : guiIngredients.entrySet()) {
if (!ps.getValue().isInput())
continue;
int slot = ps.getKey() - 1;
if (slot < 9) {
final ItemStack displayedIngredient = ps.getValue().getDisplayedIngredient();
stackList.set(slot, displayedIngredient == null ? ItemStack.EMPTY : displayedIngredient);
NonNullList<ItemStack> itemCandidateList = NonNullList.create();
// add all non-null non-empty ingredients to the itemCandidateList
ps.getValue().getAllIngredients().stream().filter(itemStack -> Objects.nonNull(itemStack) && !itemStack.isEmpty()).forEach(itemCandidateList::add);
if (!itemCandidateList.isEmpty()) {
Iterator<ItemStack> iter = itemCandidateList.iterator();
while (iter.hasNext()) {
ItemStack wildCardCheckStack = iter.next();
if (wildCardCheckStack.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
iter.remove();
final CreativeTabs creativeTab = wildCardCheckStack.getItem().getCreativeTab();
if (creativeTab != null) {
NonNullList<ItemStack> secondList = NonNullList.create();
wildCardCheckStack.getItem().getSubItems(creativeTab, secondList);
itemCandidateList.addAll(secondList);
}
iter = itemCandidateList.iterator();
}
}
stacks[slot] = itemCandidateList.toArray(new ItemStack[0]);
if (stacks[slot].length > 1) {
hasCanidates = true;
} else if (stacks[slot].length == 1) {
stackList.set(slot, stacks[slot][0]);
}
}
}
}
if (hasCanidates) {
gui.setSubGui(new GuiRecipeImport(tile, stacks));
} else {
MainProxy.sendPacketToServer(packet.setTilePos(tile));
}
}
return null;
}
return recipeTransferHandlerHelper.createInternalError();
}
use of logisticspipes.utils.gui.LogisticsBaseGuiScreen in project LogisticsPipes by RS485.
the class ClientProxy method openFluidSelectGui.
@Override
public void openFluidSelectGui(final int slotId) {
if (Minecraft.getMinecraft().currentScreen instanceof LogisticsBaseGuiScreen) {
final List<ItemIdentifierStack> list = new ArrayList<>();
for (FluidIdentifier fluid : FluidIdentifier.all()) {
if (fluid == null) {
continue;
}
list.add(fluid.getItemIdentifier().makeStack(1));
}
SelectItemOutOfList subGui = new SelectItemOutOfList(list, slot -> {
if (slot == -1)
return;
MainProxy.sendPacketToServer(PacketHandler.getPacket(DummyContainerSlotClick.class).setSlotId(slotId).setStack(list.get(slot).makeNormalStack()).setButton(0));
});
LogisticsBaseGuiScreen gui = (LogisticsBaseGuiScreen) Minecraft.getMinecraft().currentScreen;
if (!gui.hasSubGui()) {
gui.setSubGui(subGui);
} else {
SubGuiScreen nextGui = gui.getSubGui();
while (nextGui.hasSubGui()) {
nextGui = nextGui.getSubGui();
}
nextGui.setSubGui(subGui);
}
} else {
throw new UnsupportedOperationException(String.valueOf(Minecraft.getMinecraft().currentScreen));
}
}
Aggregations