Skip to content

Commit 5afddda

Browse files
committed
finished #37 and fix some bugs
1 parent 7b7618a commit 5afddda

File tree

17 files changed

+118
-11
lines changed

17 files changed

+118
-11
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ dependencies {
8282
deobfCompile "mezz.jei:jei_${mc_version}:${jei_version}"
8383
// compile "curse.maven:modularui-624243:3895901"
8484
// AE2 Unofficial Extended Life
85-
// deobfCompile "curse.maven:ae2-extended-life-570458:4094223"
85+
// deobfCompile "curse.maven:ae2-extended-life-570458:4264378"
8686
deobfCompile "curse.maven:applied-energistics-2-223794:2747063"
8787
deobfCompile "curse.maven:wireless-crafting-terminal-244559:2830252"
8888
compile "curse.maven:ae2wtlib-304024:2830114"

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ org.gradle.daemon=false
55
# General Specifications
66
mc_version=1.12.2
77
jei_version=4.16.1.302
8-
mod_version=2.0.1
8+
mod_version=2.0.3
99
forge_version=14.23.5.2847
1010
mod_group=com.github.vfyjxf.neenergistics
1111
mod_id=neenergistics

src/main/java/com/github/vfyjxf/nee/block/tile/TilePatternInterface.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ public class TilePatternInterface extends AENetworkInvTile implements IGridTicka
6969
private final List<ICraftingPatternDetails> craftingList;
7070
private List<ItemStack> waitingToSend;
7171
private final MachineSource source;
72+
private boolean processing = false;
73+
private String recipeType = "";
7274

7375
private final boolean[] workStarted = new boolean[9];
7476

@@ -317,6 +319,8 @@ public void readFromNBT(NBTTagCompound data) {
317319
}
318320
this.patterns.readFromNBT(data, "patterns");
319321
this.ejectInv.readFromNBT(data, "ejectInv");
322+
this.processing = data.getBoolean("processing");
323+
this.recipeType = data.getString("recipeType");
320324

321325
}
322326

@@ -325,6 +329,8 @@ public NBTTagCompound writeToNBT(NBTTagCompound data) {
325329
super.writeToNBT(data);
326330
this.patterns.writeToNBT(data, "patterns");
327331
this.ejectInv.writeToNBT(data, "ejectInv");
332+
data.setBoolean("processing", this.processing);
333+
data.setString("recipeType", this.recipeType);
328334

329335
final NBTTagList waitingToSend = new NBTTagList();
330336
if (this.waitingToSend != null) {

src/main/java/com/github/vfyjxf/nee/helper/IngredientRequester.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public boolean requestNext() {
3737
} catch (Exception e) {
3838
LOGGER.error("Fail to request ingredient: {} ,try to request next ingredient.", ingredient.getIdentifier().getDisplayName());
3939
currentIndex++;
40+
finished = currentIndex >= requested.size();
4041
return requestNext();
4142
}
4243
finished = currentIndex >= requested.size();

src/main/java/com/github/vfyjxf/nee/helper/RecipeAnalyzer.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616
import net.minecraft.client.gui.inventory.GuiContainer;
1717
import net.minecraft.item.ItemStack;
1818
import net.minecraftforge.fml.common.Optional;
19+
import org.apache.commons.lang3.tuple.Pair;
1920
import p455w0rd.wct.client.gui.GuiWCT;
2021

2122
import javax.annotation.Nonnull;
2223
import java.awt.*;
2324
import java.util.ArrayList;
2425
import java.util.Collections;
2526
import java.util.List;
27+
import java.util.function.Consumer;
2628
import java.util.stream.Collectors;
2729
import java.util.stream.Stream;
2830

@@ -35,6 +37,7 @@ public class RecipeAnalyzer {
3537

3638
private static boolean shouldCleanCache = false;
3739

40+
private static final List<Consumer<Pair<List<IAEItemStack>, List<IAEItemStack>>>> updateListener = new ArrayList<>();
3841
@Nonnull
3942
private static List<IAEItemStack> craftableCache = new ArrayList<>();
4043
@Nonnull
@@ -76,7 +79,7 @@ public RecipeAnalyzer(GuiCraftingTerm craftingTerm, boolean cleanCache) {
7679
}
7780

7881
/**
79-
*For some reason, we can't explicitly reference GuiWCT。
82+
* For some reason, we can't explicitly reference GuiWCT。
8083
*/
8184
public RecipeAnalyzer(GuiContainer wirelessTerm) {
8285
this(wirelessTerm, shouldCleanCache);
@@ -94,6 +97,10 @@ public static void setCleanCache(boolean cleanCache) {
9497
RecipeAnalyzer.shouldCleanCache = cleanCache;
9598
}
9699

100+
public static void addUpdateListener(Consumer<Pair<List<IAEItemStack>, List<IAEItemStack>>> listener) {
101+
updateListener.add(listener);
102+
}
103+
97104
public List<RecipeIngredient> analyzeRecipe(IRecipeLayout recipeLayout) {
98105
if (ingredientsCache != null) return ingredientsCache;
99106
Stream<List<IGuiIngredient<ItemStack>>> merged = mergeIngredients(recipeLayout).stream();
@@ -114,6 +121,20 @@ public List<RecipeIngredient> analyzeRecipe(IRecipeLayout recipeLayout) {
114121

115122
}
116123

124+
@Nonnull
125+
public static List<IAEItemStack> getAllStacks() {
126+
return allStacksCache;
127+
}
128+
129+
@Nonnull
130+
public static List<IAEItemStack> getCraftables() {
131+
return craftableCache;
132+
}
133+
134+
public GuiContainer getTerm() {
135+
return term;
136+
}
137+
117138
public void addAvailableIngredient(@Nonnull ItemStack stack) {
118139
if (stack.isEmpty()) return;
119140
boolean find = availableItems.stream()
@@ -202,6 +223,7 @@ private void updateCache() {
202223
} else {
203224
allStacksCache = getStorage();
204225
}
226+
updateListener.forEach(listener -> listener.accept(Pair.of(craftableCache, allStacksCache)));
205227
this.ingredientsCache = null;
206228
}
207229

src/main/java/com/github/vfyjxf/nee/jei/CraftingInfoError.java

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
11
package com.github.vfyjxf.nee.jei;
22

3+
import appeng.api.storage.data.IAEItemStack;
4+
import appeng.api.storage.data.IAEStack;
5+
import appeng.container.AEBaseContainer;
6+
import appeng.core.sync.network.NetworkHandler;
7+
import appeng.core.sync.packets.PacketInventoryAction;
8+
import appeng.helpers.InventoryAction;
9+
import appeng.util.item.AEItemStack;
310
import com.github.vfyjxf.nee.config.NEEConfig;
411
import com.github.vfyjxf.nee.helper.RecipeAnalyzer;
512
import com.github.vfyjxf.nee.utils.IngredientStatus;
13+
import com.google.common.base.Stopwatch;
614
import mezz.jei.api.gui.IRecipeLayout;
15+
import mezz.jei.api.gui.ITooltipCallback;
716
import mezz.jei.api.recipe.transfer.IRecipeTransferError;
817
import mezz.jei.gui.TooltipRenderer;
918
import net.minecraft.client.Minecraft;
1019
import net.minecraft.client.resources.I18n;
20+
import net.minecraft.item.ItemStack;
1121
import net.minecraft.util.text.TextFormatting;
1222
import org.lwjgl.input.Keyboard;
23+
import org.lwjgl.input.Mouse;
1324

1425
import javax.annotation.Nonnull;
1526
import java.util.ArrayList;
1627
import java.util.List;
28+
import java.util.concurrent.TimeUnit;
29+
import java.util.stream.Collectors;
1730

1831
import static com.github.vfyjxf.nee.config.KeyBindings.AUTO_CRAFT_WITH_PREVIEW;
1932
import static com.github.vfyjxf.nee.jei.CraftingTransferHandler.isIsPatternInterfaceExists;
@@ -25,9 +38,11 @@ public class CraftingInfoError implements IRecipeTransferError {
2538
private final RecipeAnalyzer analyzer;
2639

2740

28-
public CraftingInfoError(RecipeAnalyzer analyzer, boolean isCrafting) {
41+
public CraftingInfoError(RecipeAnalyzer analyzer, IRecipeLayout recipeLayout, boolean isCrafting) {
2942
this.analyzer = analyzer;
3043
this.crafting = isCrafting;
44+
recipeLayout.getItemStacks().addTooltipCallback(new CraftingInfoCallback(analyzer));
45+
//TODO:AE2FC supports
3146
}
3247

3348
/**
@@ -85,4 +100,53 @@ public void showError(@Nonnull Minecraft minecraft, int mouseX, int mouseY, @Non
85100
TooltipRenderer.drawHoveringText(minecraft, tooltips, mouseX, mouseY);
86101
}
87102

103+
/**
104+
* Feature from pae2
105+
*/
106+
private static class CraftingInfoCallback implements ITooltipCallback<ItemStack> {
107+
108+
private final Stopwatch lastClicked = Stopwatch.createStarted();
109+
private final RecipeAnalyzer analyzer;
110+
private List<ItemStack> craftables;
111+
112+
private CraftingInfoCallback(RecipeAnalyzer analyzer) {
113+
this.analyzer = analyzer;
114+
this.craftables = RecipeAnalyzer.getCraftables()
115+
.stream()
116+
.map(stack -> stack.getDefinition().copy())
117+
.collect(Collectors.toList());
118+
RecipeAnalyzer.addUpdateListener(pair -> {
119+
List<IAEItemStack> stacks = pair.getLeft().isEmpty() ?
120+
pair.getRight().stream().filter(IAEStack::isCraftable).collect(Collectors.toList()) :
121+
pair.getLeft();
122+
craftables = stacks.stream()
123+
.map(stack -> stack.getDefinition().copy())
124+
.collect(Collectors.toList());
125+
});
126+
}
127+
128+
@Override
129+
public void onTooltip(int slotIndex, boolean input, @Nonnull ItemStack ingredient, @Nonnull List<String> tooltip) {
130+
analyzer.update();
131+
if (!input | ingredient.isEmpty() | craftables.isEmpty()) return;
132+
boolean anyMatch = craftables.stream().anyMatch(ingredient::isItemEqual);
133+
if (anyMatch) {
134+
tooltip.add(TextFormatting.BLUE + String.format("[%s]", I18n.format("jei.tooltip.nee.helper.craftable")));
135+
136+
if (Mouse.isButtonDown(2) && this.lastClicked.elapsed(TimeUnit.MILLISECONDS) > 200) {
137+
this.lastClicked.reset().start();
138+
IAEItemStack target = AEItemStack.fromItemStack(ingredient);
139+
if (target != null && analyzer.getTerm().inventorySlots instanceof AEBaseContainer) {
140+
AEBaseContainer container = (AEBaseContainer) analyzer.getTerm().inventorySlots;
141+
container.setTargetStack(target);
142+
NetworkHandler.instance().sendToServer(
143+
new PacketInventoryAction(InventoryAction.AUTO_CRAFT, container.getInventory().size(), 0)
144+
);
145+
}
146+
}
147+
}
148+
149+
}
150+
}
151+
88152
}

src/main/java/com/github/vfyjxf/nee/jei/CraftingTransferHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public IRecipeTransferError transferRecipe(@Nonnull C container, @Nonnull IRecip
8282
} else {
8383
RecipeAnalyzer analyzer = createAnalyzer(parent);
8484
if (analyzer == null) return null;
85-
return new CraftingInfoError(initAnalyzer(analyzer, craftingTerm, recipeLayout, player), true);
85+
return new CraftingInfoError(initAnalyzer(analyzer, craftingTerm, recipeLayout, player), recipeLayout, true);
8686
}
8787
}
8888
return null;

src/main/java/com/github/vfyjxf/nee/jei/PatternTransferHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public IRecipeTransferError transferRecipe(@Nonnull ContainerPatternTerm contain
7979
}
8080
} else {
8181
//TODO:Wireless Pattern Term support?
82-
return new CraftingInfoError(new RecipeAnalyzer(patternTerm), false);
82+
return new CraftingInfoError(new RecipeAnalyzer(patternTerm), recipeLayout, false);
8383
}
8484
}
8585

@@ -120,7 +120,7 @@ private Pair<NBTTagCompound, NBTTagCompound> packRecipe(ItemRepo repo, Container
120120
inputsList.add(current);
121121
}
122122
} else {
123-
if (outputIndex >= 3 || stack.isEmpty() || (container.isCraftingMode())) {
123+
if (outputIndex >= 3 || stack.isEmpty() || isCraftingRecipe) {
124124
continue;
125125
}
126126
outputs.setTag(OUTPUT_KEY + outputIndex, stack.writeToNBT(new NBTTagCompound()));
@@ -181,7 +181,7 @@ private boolean shouldMerge(String recipeType) {
181181

182182
private List<StackWrapper> mapToPreference(List<StackWrapper> wrappers, String recipeType) {
183183
return wrappers.stream()
184-
.map(wrapper -> new StackWrapper(getFromPreference(wrapper.getIngredients(), wrapper.getStack(), recipeType), wrapper.getIngredients()))
184+
.map(wrapper -> new StackWrapper(getFromPreference(wrapper.getIngredients(), wrapper.getStack(), recipeType), wrapper.getIngredients(), wrapper.getCount()))
185185
.collect(Collectors.toList());
186186
}
187187

src/main/java/com/github/vfyjxf/nee/network/packet/PacketCraftingRequest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ public static class Handler implements IMessageHandler<PacketCraftingRequest, IM
117117
public IMessage onMessage(PacketCraftingRequest message, MessageContext ctx) {
118118
EntityPlayerMP player = ctx.getServerHandler().player;
119119
Container container = player.openContainer;
120+
if(!(container instanceof AEBaseContainer)) return null;
120121
player.getServerWorld().addScheduledTask(() -> {
121122
AEBaseContainer baseContainer = (AEBaseContainer) container;
122123
Object target = baseContainer.getTarget();

src/main/java/com/github/vfyjxf/nee/network/packet/PacketRecipeTransfer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import net.minecraftforge.items.IItemHandler;
2020

2121
import javax.annotation.Nonnull;
22-
2322
import java.lang.reflect.InvocationTargetException;
2423
import java.lang.reflect.Method;
2524
import java.util.HashSet;

0 commit comments

Comments
 (0)