Skip to content

Commit a76bc4e

Browse files
committed
Added Recipe transfer handlers and CTRL+Click capability
1 parent 2205f30 commit a76bc4e

File tree

7 files changed

+78
-82
lines changed

7 files changed

+78
-82
lines changed

dependencies.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ dependencies {
4444
implementation rfg.deobf("curse.maven:baubles-227083:2518667")
4545
implementation rfg.deobf("curse.maven:nae2-884359:5380800")
4646

47-
4847
implementation rfg.deobf("curse.maven:ae2-extended-life-570458:5378163")
4948
//implementation rfg.deobf("curse.maven:ae2-fluid-crafting-rework-623955:4804730")
5049
compileOnlyApi rfg.deobf("curse.maven:jei-238222:4538010")

src/main/java/com/_0xc4de/ae2exttable/client/container/ContainerMEMonitorableTwo.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,9 @@ public IRecipe getRecipeMatchingGrid(InventoryCrafting ic) {
214214
}
215215
}
216216

217-
// Vanilla recipes work for 3x3, might fuck around and figure out how to make it possible for
218-
// Bigger tables, would require some custom mapping to find middle 3x3 of tables
219-
// This actually wouldn't be hard.
217+
// Vanilla recipes work for 3x3, these aren't 3x3 (except for basic),
218+
// so need to make a "fake" intermediary table that hold specifically the 3x3 inner-most grid depending on table size.
219+
// TODO: This
220220
if (ModConfig.confTableUseRecipes && ic.getWidth() == 3 && ic.getHeight() == 3) {
221221
for(IRecipe recipe : ForgeRegistries.RECIPES.getValuesCollection()) {
222222
if (recipe.matches(ic, world)) {

src/main/java/com/_0xc4de/ae2exttable/integration/JEIMissingItem.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
import mezz.jei.gui.recipes.RecipeLayout;
2424
import mezz.jei.gui.recipes.RecipeTransferButton;
2525
import net.minecraft.client.Minecraft;
26+
import net.minecraft.client.gui.GuiScreen;
2627
import net.minecraft.inventory.Container;
2728
import net.minecraft.item.ItemStack;
2829
import net.minecraft.util.text.translation.I18n;
30+
import net.minecraftforge.fml.common.Loader;
2931
import net.minecraftforge.items.IItemHandler;
3032
import net.minecraftforge.items.wrapper.PlayerMainInvWrapper;
3133

@@ -240,8 +242,30 @@ public void showError(Minecraft minecraft, int mouseX, int mouseY, @Nonnull IRec
240242
if (errored) {
241243
tooltipLines.add(I18n.translateToLocal("gui.tooltips.appliedenergistics2.MissingItem"));
242244
}
245+
246+
// Stolen from NAE2 again thanks @NotMyWing
247+
var inCount = recipeLayout.getItemStacks().getGuiIngredients().values().stream()
248+
.map(iGuiIngredient -> iGuiIngredient.isInput() && !iGuiIngredient.getAllIngredients().isEmpty() ? 1 : 0)
249+
.reduce(0, Integer::sum);
250+
243251
if (foundAnyCraftable) {
244252
tooltipLines.add(I18n.translateToLocal("gui.tooltips.appliedenergistics2.CraftableItem"));
253+
if (Loader.isModLoaded("nae2")) {
254+
tooltipLines.add("");
255+
if (foundAnyCraftable) {
256+
if (this.craftableSlots.size() + this.foundSlots.size() == inCount) {
257+
tooltipLines.add(I18n.translateToLocal("nae2.jei.missing.craft.1"));
258+
tooltipLines.add(I18n.translateToLocal("nae2.jei.missing.craft.2"));
259+
} else {
260+
tooltipLines.add(I18n.translateToLocal("nae2.jei.missing.partialcraft.1"));
261+
tooltipLines.add(I18n.translateToLocal("nae2.jei.missing.partialcraft.2"));
262+
}
263+
} else {
264+
tooltipLines.add(I18n.translateToLocal("nae2.jei.missing.bypasscraft.1"));
265+
tooltipLines.add(I18n.translateToLocal("nae2.jei.missing.bypasscraft.2"));
266+
}
267+
b.enabled = GuiScreen.isCtrlKeyDown();
268+
}
245269
}
246270
TooltipRenderer.drawHoveringText(minecraft, tooltipLines, mouseX, mouseY);
247271
}

src/main/java/com/_0xc4de/ae2exttable/integration/JEIPlugin.java

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,30 @@
2020

2121
import java.lang.reflect.Constructor;
2222
import java.lang.reflect.InvocationTargetException;
23+
import java.util.List;
2324

2425
@mezz.jei.api.JEIPlugin
2526
public class JEIPlugin implements IModPlugin {
2627
@Override
2728
public void register(IModRegistry registry) {
2829
IRecipeTransferRegistry transfer = registry.getRecipeTransferRegistry();
29-
try {
30-
Constructor constructor = new RecipeTransferHandlerWrapper().constructor;
31-
transfer.addRecipeTransferHandler((IRecipeTransferHandler<?>) constructor.newInstance(ContainerBasicCraftingTerminal.class), VanillaRecipeCategoryUid.CRAFTING);
32-
transfer.addRecipeTransferHandler((IRecipeTransferHandler<?>) constructor.newInstance(ContainerBasicCraftingTerminal.class), BasicTableCategory.UID);//, 1, 9, 10, 36);
3330

34-
transfer.addRecipeTransferHandler((IRecipeTransferHandler<?>) constructor.newInstance(
35-
ContainerBasicWirelessTerminal.class), VanillaRecipeCategoryUid.CRAFTING);
36-
transfer.addRecipeTransferHandler((IRecipeTransferHandler<?>) constructor.newInstance(ContainerBasicWirelessTerminal.class), BasicTableCategory.UID);//, 1, 9, 10, 36);
31+
// Basic term gets vanilla too
32+
transfer.addRecipeTransferHandler(new RecipeTransferHandler<>(ContainerBasicCraftingTerminal.class), VanillaRecipeCategoryUid.CRAFTING);
33+
transfer.addRecipeTransferHandler(new RecipeTransferHandler<>(ContainerBasicWirelessTerminal.class), VanillaRecipeCategoryUid.CRAFTING);
3734

38-
transfer.addRecipeTransferHandler((IRecipeTransferHandler<?>) constructor.newInstance(ContainerAdvancedCraftingTerminal.class), AdvancedTableCategory.UID);//, 1, 9, 10, 36);
39-
transfer.addRecipeTransferHandler((IRecipeTransferHandler<?>) constructor.newInstance(
40-
ContainerAdvancedWirelessTerminal.class), AdvancedTableCategory.UID);//, 1, 9, 10, 36);
35+
String[] UIDs = new String[]{UltimateTableCategory.UID, EliteTableCategory.UID, AdvancedTableCategory.UID, BasicTableCategory.UID};
36+
Class<?>[] termMappings = new Class[]{ContainerUltimateCraftingTerminal.class, ContainerEliteCraftingTerminal.class, ContainerAdvancedCraftingTerminal.class};
37+
Class<?>[] wirelessTermMappings = new Class[]{ContainerUltimateWirelessTerminal.class, ContainerEliteWirelessTerminal.class, ContainerAdvancedWirelessTerminal.class, ContainerBasicWirelessTerminal.class};
4138

42-
transfer.addRecipeTransferHandler((IRecipeTransferHandler<?>) constructor.newInstance(ContainerEliteCraftingTerminal.class), EliteTableCategory.UID);//, 1, 9, 10, 36);
43-
transfer.addRecipeTransferHandler((IRecipeTransferHandler<?>) constructor.newInstance(
44-
ContainerEliteWirelessTerminal.class), EliteTableCategory.UID);//, 1, 9, 10, 36);
39+
for (int i=0; i < termMappings.length; i++){
40+
Class<?> term = termMappings[i];
41+
Class<?> wirelessTerm = wirelessTermMappings[i];
4542

46-
transfer.addRecipeTransferHandler((IRecipeTransferHandler<?>) constructor.newInstance(ContainerUltimateCraftingTerminal.class), UltimateTableCategory.UID);//, 1, 9, 10, 36);
47-
transfer.addRecipeTransferHandler((IRecipeTransferHandler<?>) constructor.newInstance(
48-
ContainerUltimateWirelessTerminal.class), UltimateTableCategory.UID);//, 1, 9, 10, 36);
49-
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | InstantiationException |
50-
IllegalAccessException e) {
51-
throw new RuntimeException(e);
43+
for (int j = i; j < UIDs.length; j++){
44+
transfer.addRecipeTransferHandler(new RecipeTransferHandler<>(term), UIDs[j]);
45+
transfer.addRecipeTransferHandler(new RecipeTransferHandler<>(wirelessTerm), UIDs[j]);
46+
}
5247
}
5348
}
54-
}
49+
}

src/main/java/com/_0xc4de/ae2exttable/integration/RecipeTransferHandler.java

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
import appeng.core.sync.network.NetworkHandler;
1717
import appeng.core.sync.packets.PacketJEIRecipe;
1818
import com._0xc4de.ae2exttable.client.container.ContainerMEMonitorableTwo;
19-
import com._0xc4de.ae2exttable.client.container.terminals.ContainerAdvancedCraftingTerminal;
20-
import com._0xc4de.ae2exttable.client.container.terminals.ContainerEliteCraftingTerminal;
21-
import com._0xc4de.ae2exttable.client.container.terminals.ContainerUltimateCraftingTerminal;
2219
import com.blakebr0.extendedcrafting.compat.jei.tablecrafting.AdvancedTableCategory;
2320
import com.blakebr0.extendedcrafting.compat.jei.tablecrafting.BasicTableCategory;
2421
import com.blakebr0.extendedcrafting.compat.jei.tablecrafting.EliteTableCategory;
@@ -49,8 +46,8 @@ class RecipeTransferHandler<T extends Container> implements IRecipeTransferHandl
4946

5047
private final Class<T> containerClass;
5148

52-
RecipeTransferHandler(Class<T> containerClass) {
53-
this.containerClass = containerClass;
49+
RecipeTransferHandler(Class<?> containerClass) {
50+
this.containerClass = (Class<T>) containerClass;
5451
}
5552

5653
@Override
@@ -166,45 +163,33 @@ public IRecipeTransferError transferRecipe(@Nonnull T container, IRecipeLayout r
166163
Advanced: Advanced, Basic
167164
Basic: Basic, Vanilla Recipes
168165
169-
For some reason the bigger tables cannot accept vanilla recipes.
170-
171-
This means if I have an ordered mapping of each container, in increasing order (Basic:0, Advanced:1, ...) then each
172-
respective Recipe Layout can be calculated from current backwards, basically List[:index] inclusive, using known
173-
Layouts of each, the "slotIndex" can be adjusted to treat higher level slots as
166+
Also, for some reason the bigger tables cannot accept vanilla recipes, partially my fault but it's in Blake's code too
174167
*/
175168
private int getIndex(@Nonnull T container, String recipeType, int currentIndex) {
176-
// I know this pattern is bad, I just don't know how to do it better
177-
int ultimateSize = 9;
178-
int eliteSize = 7;
179-
int advancedSize = 5;
180-
int basicSize = 3;
181-
if (container instanceof ContainerUltimateCraftingTerminal) {
182-
183-
if (recipeType.equals(EliteTableCategory.UID)) {
184-
int size = ((ultimateSize-eliteSize)/2);
185-
// These matrices are always square, so rowSize=colSize => size
186-
return ((currentIndex/eliteSize + size) * ultimateSize) + ((currentIndex % eliteSize) + size);
187-
};
188-
if (recipeType.equals(AdvancedTableCategory.UID)) {
189-
int size = ((ultimateSize-eliteSize)/2);
190-
return (size + currentIndex) * 5 + (size + currentIndex);
191-
};
192-
if (recipeType.equals(BasicTableCategory.UID)) {
193-
194-
};
195-
} else if (container instanceof ContainerEliteCraftingTerminal) {
196-
if (recipeType.equals(AdvancedTableCategory.UID)) {
197-
198-
};
199-
if (recipeType.equals(BasicTableCategory.UID)) {
200-
201-
};
202-
} else if (container instanceof ContainerAdvancedCraftingTerminal) {
203-
if (recipeType.equals(BasicTableCategory.UID)) {
204-
205-
};
169+
final int ultimateSize = 9;
170+
final int eliteSize = 7;
171+
final int advancedSize = 5;
172+
final int basicSize = 3;
173+
final int thisSize = ((ContainerMEMonitorableTwo)container).getWidth();
174+
175+
final boolean basicRecipe = recipeType.equals(BasicTableCategory.UID) | recipeType.equals(VanillaRecipeCategoryUid.CRAFTING);
176+
if (recipeType.equals(EliteTableCategory.UID)) {
177+
int size = ((thisSize-eliteSize)/2);
178+
// These matrices are always square, so rowSize=colSize => size
179+
return ((currentIndex/eliteSize + size) * thisSize) + ((currentIndex % eliteSize) + size);
180+
}
181+
182+
if (recipeType.equals(AdvancedTableCategory.UID)) {
183+
int size = ((thisSize-advancedSize)/2);
184+
return ((currentIndex/advancedSize + size) * thisSize) + ((currentIndex % advancedSize) + size);
206185
}
207186

187+
if (basicRecipe) {
188+
int size = ((thisSize-basicSize)/2);
189+
return ((currentIndex/basicSize + size) * thisSize) + ((currentIndex % basicSize) + size);
190+
}
191+
192+
208193
return currentIndex;
209194
}
210195
}

src/main/java/com/_0xc4de/ae2exttable/integration/RecipeTransferHandlerWrapper.java

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/main/java/com/_0xc4de/ae2exttable/proxy/CommonProxy.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
import com._0xc4de.ae2exttable.client.gui.PartGuiHandler;
77
import com._0xc4de.ae2exttable.items.ItemRegistry;
88
import com._0xc4de.ae2exttable.network.ExtendedTerminalNetworkHandler;
9+
import com.blakebr0.extendedcrafting.crafting.table.TableRecipeManager;
10+
import com.blakebr0.extendedcrafting.item.ModItems;
11+
import net.minecraft.client.Minecraft;
12+
import net.minecraft.init.Blocks;
13+
import net.minecraft.init.Items;
14+
import net.minecraft.item.Item;
15+
import net.minecraft.item.ItemStack;
916
import net.minecraftforge.common.MinecraftForge;
1017
import net.minecraftforge.fml.common.FMLCommonHandler;
1118
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
@@ -29,6 +36,10 @@ public void init(FMLInitializationEvent event) {
2936
//NetworkRegistry.INSTANCE.registerGuiHandler(AE2ExtendedCraftingTable.instance, new GuiHandler());
3037
NetworkRegistry.INSTANCE.registerGuiHandler(AE2ExtendedCraftingTable.instance, new PartGuiHandler());
3138

39+
// TEST RECIPE
40+
//TableRecipeManager.getInstance().addShaped(new ItemStack(Blocks.DIRT),
41+
// "DDD", "ADA", "DDD", 'D', new ItemStack(Items.DIAMOND), 'A', new ItemStack(Items.AIR));
42+
3243
if (FMLCommonHandler.instance().getSide().isClient()) {
3344
ItemColors.registerItemColors();
3445
}

0 commit comments

Comments
 (0)