Skip to content

Commit

Permalink
+ Crafting Module recipe transfer from JEI
Browse files Browse the repository at this point in the history
+ partial Tools support
  • Loading branch information
EJaxx committed Nov 10, 2019
1 parent 1a57ed9 commit 0af42ae
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 35 deletions.
10 changes: 5 additions & 5 deletions common/logisticspipes/LPConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ public static void loadedCoremod() {
}

public static final String ToolFilters[] = {
"GregTech Community Edition:Integrated circuit.+",
"GregTech Community Edition:Extruder Shape .+",
"GregTech Community Edition:Mold .+",
"GregTech Community Edition:.+ Lens.+",
"!GregTech Community Edition:Integrated circuit.+",
"!GregTech Community Edition:Extruder Shape .+",
"!GregTech Community Edition:Mold .+",
"!GregTech Community Edition:.+ Lens.+",
"Logistics Pipes:Logistics Programmer.+",
"{GT.ToolStats:{.+}",
"\\{GT.ToolStats:\\{.+\\}",
};

}
13 changes: 13 additions & 0 deletions common/logisticspipes/gui/GuiCraftingPipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import logisticspipes.gui.popup.GuiSelectSatellitePopup;
import logisticspipes.modules.ModuleCrafter;
import logisticspipes.network.PacketHandler;
import logisticspipes.network.packets.SetGhostItemPacket;
import logisticspipes.network.packets.cpipe.CPipeCleanupImport;
import logisticspipes.network.packets.cpipe.CPipeCleanupToggle;
import logisticspipes.network.packets.pipe.CraftingPipeSetSatellitePacket;
Expand Down Expand Up @@ -211,6 +212,18 @@ public void initGui() {
}
}

public void transferRecipe(ItemStack[] craftIngredients, ItemStack craftTarget) {
try {
for (int i = 0; i < 9; i++)
MainProxy.sendPacketToServer(
PacketHandler.getPacket(SetGhostItemPacket.class).setInteger(36 + i).setStack(craftIngredients[i] == null ? ItemStack.EMPTY : craftIngredients[i]));
MainProxy.sendPacketToServer(
PacketHandler.getPacket(SetGhostItemPacket.class).setInteger(36 + 9).setStack(craftTarget));
} catch (Exception e) {
e.printStackTrace();
}
}

@Override
protected void actionPerformed(GuiButton guibutton) throws IOException {
/*
Expand Down
20 changes: 17 additions & 3 deletions common/logisticspipes/gui/popup/GuiRecipeImport.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.function.Consumer;

import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;

import logisticspipes.gui.GuiCraftingPipe;
import logisticspipes.network.PacketHandler;
import logisticspipes.network.packets.NEISetCraftingRecipe;
import logisticspipes.network.packets.pipe.FindMostLikelyRecipeComponents;
Expand All @@ -36,11 +38,19 @@ public Canidates(Set<ItemIdentifierStack> set) {
int pos = 0;
}

private final TileEntity tile;
private TileEntity tile = null;
private GuiCraftingPipe cpGui = null;
private ItemStack craftTarget = null;
private final Canidates[] grid = new Canidates[9];
private final List<Canidates> list;
private Object[] tooltip = null;

public GuiRecipeImport(GuiCraftingPipe cpGui, ItemStack[][] stacks, ItemStack craftTarget) {
this(null, stacks);
this.cpGui = cpGui;
this.craftTarget = craftTarget;
}

public GuiRecipeImport(TileEntity tile, ItemStack[][] stacks) {
super(150, 200, 0, 0);
this.tile = tile;
Expand Down Expand Up @@ -189,10 +199,14 @@ protected void actionPerformed(GuiButton button) {
stack[i++] = canidate.order.get(canidate.pos).makeNormalStack();
}
NEISetCraftingRecipe packet = PacketHandler.getPacket(NEISetCraftingRecipe.class);
MainProxy.sendPacketToServer(packet.setContent(stack).setBlockPos(tile.getPos()));
if (tile != null)
MainProxy.sendPacketToServer(packet.setContent(stack).setBlockPos(tile.getPos()));
else
cpGui.transferRecipe(stack, craftTarget);
exitGui();
} else if (id == 1) {
MainProxy.sendPacketToServer(PacketHandler.getPacket(FindMostLikelyRecipeComponents.class).setContent(list).setTilePos(tile));
if (tile != null)
MainProxy.sendPacketToServer(PacketHandler.getPacket(FindMostLikelyRecipeComponents.class).setContent(list).setTilePos(tile));
} else if (id >= 10 && id < 30) {
int slot = id % 10;
boolean up = id < 20;
Expand Down
31 changes: 24 additions & 7 deletions common/logisticspipes/modplugins/jei/RecipeTransferHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ public IRecipeTransferError transferRecipe(@Nonnull Container container, @Nonnul
}

if (tile == null) {
return recipeTransferHandlerHelper.createInternalError();
// return recipeTransferHandlerHelper.createInternalError();
}

if (!recipeLayout.getRecipeCategory().getUid().equals(VanillaRecipeCategoryUid.CRAFTING)) {
return recipeTransferHandlerHelper.createInternalError();
// return recipeTransferHandlerHelper.createInternalError();
}

ItemStack[] stack = new ItemStack[9];
Expand All @@ -86,10 +86,16 @@ public IRecipeTransferError transferRecipe(@Nonnull Container container, @Nonnul
IGuiItemStackGroup guiItemStackGroup = recipeLayout.getItemStacks();
Map<Integer, ? extends IGuiIngredient<ItemStack>> guiIngredients = guiItemStackGroup.getGuiIngredients();

ItemStack craftTarget = null;
if (doTransfer) {
int slot = 0;
for (Map.Entry<Integer, ? extends IGuiIngredient<ItemStack>> ps : guiIngredients.entrySet()) {
if (!ps.getValue().isInput()) continue;
if (!ps.getValue().isInput()) {
List<ItemStack> ls = ps.getValue().getAllIngredients();
if (craftTarget == null && ls.size() > 0)
craftTarget = ls.get(0);
continue;
}

if (recipeLayout.getRecipeCategory().getUid().equals(VanillaRecipeCategoryUid.CRAFTING))
slot = ps.getKey() - 1;
Expand Down Expand Up @@ -120,14 +126,25 @@ public IRecipeTransferError transferRecipe(@Nonnull Container container, @Nonnul
slot++;
}

if (gui instanceof GuiCraftingPipe) {
GuiCraftingPipe cpGui = (GuiCraftingPipe) gui;
if (hasCanidates) {
gui.setSubGui(new GuiRecipeImport(cpGui, stacks, craftTarget));
} else
cpGui.transferRecipe(stack, craftTarget);
return null;
}

if (!recipeLayout.getRecipeCategory().getUid().equals(VanillaRecipeCategoryUid.CRAFTING)) {
return recipeTransferHandlerHelper.createInternalError();
}

if (hasCanidates) {
gui.setSubGui(new GuiRecipeImport(tile, stacks));
} else {
MainProxy.sendPacketToServer(packet.setContent(stack).setTilePos(tile));
if (tile != null) {
if (hasCanidates) {
gui.setSubGui(new GuiRecipeImport(tile, stacks));
} else {
MainProxy.sendPacketToServer(packet.setContent(stack).setTilePos(tile));
}
}
}
return null;
Expand Down
8 changes: 5 additions & 3 deletions common/logisticspipes/modules/CrafterBarrier.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void tryUnlock() {
}
if (elements.stream().allMatch(o -> o.arrived == 0 && o.tickets.isEmpty())) {
if (!shapeless && connectedTileEntity instanceof LogisticsCraftingTableTileEntity) {
if (!connectedInventory.getItemsAndCount().isEmpty())
if (connectedInventory.getItemsAndCount().keySet().stream().anyMatch(o -> !ModuleCrafter.isSharedTool(o)))
return;
}
parent.current = null;
Expand Down Expand Up @@ -139,6 +139,7 @@ public int canEnter(ItemIdentifierStack stack, int targetSlot, IRoutedItem trave
for (int i = 0; i < 9; i++) {
if (inventory.getIDStackInSlot(i) == null) continue;
ItemIdentifier invItem = inventory.getIDStackInSlot(i).getItem();
if (ModuleCrafter.isTool(invItem)) continue;
int inOrders = elements.get(i).orders.stream()
.filter(o -> o.getType() == IOrderInfoProvider.ResourceType.PROVIDER).mapToInt(LogisticsItemOrder::getAmount).sum();
int inTickets = elements.get(i).tickets.stream()
Expand All @@ -150,7 +151,8 @@ public int canEnter(ItemIdentifierStack stack, int targetSlot, IRoutedItem trave
inTickets += stack.getStackSize();
ticketSum = inTickets;
}
int room = shapeless ? connectedInventory.roomForItem(invItem) : connectedInventory.roomForItemToSlot(invItem, i);
int room = (shapeless || connectedTileEntity instanceof LogisticsCraftingTableTileEntity) ?
connectedInventory.roomForItem(invItem) : connectedInventory.roomForItemToSlot(invItem, i);
if (!shapeless && connectedTileEntity instanceof LogisticsCraftingTableTileEntity)
room = invItem.getMaxStackSize(); // matrix will be changed upon receipt of the first item
int arrived = elements.get(i).arrived;
Expand Down Expand Up @@ -257,7 +259,7 @@ public void addProbeInfo(ProbeMode mode, IProbeInfo probeInfo, EntityPlayer play
for (int i = 0; i < 9 && i < inventory.getSizeInventory(); i++) {
res = inventory.getIDStackInSlot(i);
it = elements.get(i);
if (it != null)
if (it != null && res != null)
probeInfo
.horizontal().item(res.getItem().makeNormalStack(1), new ItemStyle().width(16).height(8)).text(res.getItem().getFriendlyName())
.text(": a" + it.arrived
Expand Down
58 changes: 43 additions & 15 deletions common/logisticspipes/modules/ModuleCrafter.java
Original file line number Diff line number Diff line change
Expand Up @@ -610,15 +610,7 @@ public ICraftingTemplate addCrafting(IResource toCraft) {
if (resourceStack == null || resourceStack.getStackSize() == 0) {
continue;
}
boolean found = false;
for (String x : LPConstants.ToolFilters) {
ItemIdentifier it = resourceStack.getItem();
if (!x.startsWith("{"))
found |= it.toString().matches(x);
else if (it.tag != null)
found |= resourceStack.getItem().tag.toString().matches(x);
}
if (found)
if (isTool(resourceStack.getItem()))
continue;
IResource req;
if (getUpgradeManager().isFuzzyUpgrade() && fuzzyCraftingFlagArray[i].getBitSet().nextSetBit(0) != -1) {
Expand Down Expand Up @@ -667,6 +659,36 @@ else if (it.tag != null)
return template;
}

public static boolean isTool(ItemIdentifier it) {
for (String x : LPConstants.ToolFilters) {
if (x.startsWith("!"))
x = x.substring(1);
if (!x.startsWith("\\{")) {
if (it.toString().matches(x))
return true;
} else if (it.tag != null) {
if (it.tag.toString().matches(x))
return true;
}
}
return false;
}

public static boolean isSharedTool(ItemIdentifier it) {
for (String x : LPConstants.ToolFilters) {
if (x.startsWith("!"))
continue;
if (!x.startsWith("\\{")) {
if (it.toString().matches(x))
return true;
} else if (it.tag != null) {
if (it.tag.toString().matches(x))
return true;
}
}
return false;
}

public boolean isSatelliteConnected() {
//final List<ExitRoute> routes = getRouter().getIRoutersByCost();
if (!getUpgradeManager().isAdvancedSatelliteCrafter()) {
Expand Down Expand Up @@ -1120,7 +1142,11 @@ public void feedOrders(ItemStack extracted, EnumFacing direction) {
}

if (nextOrder.getDestination() != null && nextOrder.getInformation() instanceof CraftingChassieInformation &&
(nextOrder.getDestination() instanceof ModuleCrafter) && ((ModuleCrafter) nextOrder.getDestination()).slot != ModulePositionType.IN_PIPE) {
(nextOrder.getDestination() instanceof ModuleCrafter) && (((ModuleCrafter) nextOrder.getDestination()).slot != ModulePositionType.IN_PIPE)) {
if (nextOrder.getDestination().getRouter().getSimpleID() != getRouter().getSimpleID()) {
System.err.println("Loopback cancelled");
continue;
}
CrafterBarrier.LogisticsModuleValue destModule = new CrafterBarrier.LogisticsModuleValue();
int maxToSend = CrafterBarrier.maxSend(nextOrder, extracted.getCount(), destModule, true);
if (maxToSend <= 0) {
Expand All @@ -1129,7 +1155,7 @@ public void feedOrders(ItemStack extracted, EnumFacing direction) {
}

ItemStack stackToSend = extracted.splitStack(Math.min(maxToSend, nextOrder.getAmount()));
// System.err.println("Sent "+ItemIdentifierStack.getFromStack(stackToSend)+" to CraftingChassieInformation");
System.err.println("Sent "+ItemIdentifierStack.getFromStack(stackToSend)+" to CraftingChassieInformation");

IRoutedItem item = SimpleServiceLocator.routedItemHelper.createNewTravelItem(stackToSend);
item.setTransportMode(TransportMode.Active);
Expand All @@ -1149,7 +1175,7 @@ public void feedOrders(ItemStack extracted, EnumFacing direction) {

if (maxToSend >= 0) {
ItemStack stackToSend = extracted.splitStack(maxToSend);
// System.err.println("Sent "+ItemIdentifierStack.getFromStack(stackToSend)+" to IItemSpaceControl");
System.err.println("Sent "+ItemIdentifierStack.getFromStack(stackToSend)+" to IItemSpaceControl");

IRoutedItem item = SimpleServiceLocator.routedItemHelper.createNewTravelItem(stackToSend);
item.setTransportMode(TransportMode.Active);
Expand All @@ -1163,7 +1189,7 @@ public void feedOrders(ItemStack extracted, EnumFacing direction) {
}
} else {
ItemStack stackToSend = extracted.splitStack(nextOrder.getAmount());
// System.err.println("Sent "+ItemIdentifierStack.getFromStack(stackToSend)+" to simple");
System.err.println("Sent "+ItemIdentifierStack.getFromStack(stackToSend)+" to simple");

IRoutedItem item = SimpleServiceLocator.routedItemHelper.createNewTravelItem(stackToSend);
item.setTransportMode(TransportMode.Active);
Expand All @@ -1186,7 +1212,7 @@ public void feedOrders(ItemStack extracted, EnumFacing direction) {
}

ItemStack stackToSend = extracted.splitStack(nextOrder.getAmount());
// System.err.println("Stored up "+ItemIdentifierStack.getFromStack(stackToSend)+" for "+nextOrder.getDestination());
System.err.println("Stored up "+ItemIdentifierStack.getFromStack(stackToSend)+" for "+nextOrder.getDestination());

IRoutedItem item = SimpleServiceLocator.routedItemHelper.createNewTravelItem(stackToSend);
item.setTransportMode(TransportMode.Active);
Expand Down Expand Up @@ -1237,6 +1263,8 @@ public void enabledUpdateEntity() {
myBarrierRecipe.connectedTileEntity = firstNeighbor == null ? null : firstNeighbor.getTileEntity();
myBarrierRecipe.shapeless = !getUpgradeManager().hasPatternUpgrade();
}
if (myBarrierRecipe.parent != null && myBarrierRecipe.parent.current != null)
myBarrierRecipe.parent.current.tryUnlock();
}

if (!_service.isNthTick(6)) {
Expand Down Expand Up @@ -1316,7 +1344,7 @@ public void enabledUpdateEntity() {
_service.getCacheHolder().trigger(CacheTypes.Inventory);
lastAccessedCrafter = new WeakReference<>(adjacent.getTileEntity());
// send the new crafted items to the destination
// System.err.println("ModuleCrafter extracted "+ItemIdentifierStack.getFromStack(extracted));
System.err.println("ModuleCrafter extracted "+ItemIdentifierStack.getFromStack(extracted));
feedOrders(extracted, adjacent.getDirection());
if (adjacent.getTileEntity() instanceof LogisticsCraftingTableTileEntity && myBarrierRecipe.parent != null && myBarrierRecipe.parent.current != null)
myBarrierRecipe.parent.current.tryUnlock(); // still possible before extracting all
Expand Down
5 changes: 3 additions & 2 deletions common/logisticspipes/transport/PipeTransportLogistics.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import logisticspipes.LPConstants;
import logisticspipes.api.ILogisticsPowerProvider;
import logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity;
import logisticspipes.blocks.powertile.LogisticsPowerJunctionTileEntity;
import logisticspipes.interfaces.IBufferItems;
import logisticspipes.interfaces.IInventoryUtil;
Expand Down Expand Up @@ -560,8 +561,8 @@ protected final void handleTileReachedServer_internal(LPTravelingItemServer arri
}
}
}

if (getRoutedPipe().getUpgradeManager() != null && getRoutedPipe().getUpgradeManager() instanceof UpgradeManager && getRoutedPipe().getUpgradeManager().hasPatternUpgrade()) {
if (getRoutedPipe().getUpgradeManager() != null && getRoutedPipe().getUpgradeManager() instanceof UpgradeManager
&& getRoutedPipe().getUpgradeManager().hasPatternUpgrade() && !(tile instanceof LogisticsCraftingTableTileEntity)) {
if (arrivingItem.getAdditionalTargetInformation() instanceof ModuleCrafter.CraftingChassieInformation && util instanceof ISpecialInsertion) {
ModuleCrafter.CraftingChassieInformation information = (ModuleCrafter.CraftingChassieInformation) arrivingItem.getAdditionalTargetInformation();
int slot = information.getCraftingSlot();
Expand Down

0 comments on commit 0af42ae

Please sign in to comment.