|
24 | 24 |
|
25 | 25 | import net.minecraft.entity.player.EntityPlayer; |
26 | 26 | import net.minecraft.inventory.InventoryCrafting; |
| 27 | +import net.minecraft.item.Item; |
27 | 28 | import net.minecraft.item.ItemStack; |
28 | 29 | import net.minecraft.nbt.NBTTagCompound; |
29 | 30 | import net.minecraft.nbt.NBTTagList; |
30 | 31 | import net.minecraft.util.StatCollector; |
31 | 32 | import net.minecraftforge.common.util.ForgeDirection; |
| 33 | +import net.minecraftforge.oredict.OreDictionary; |
32 | 34 |
|
33 | 35 | import org.jetbrains.annotations.NotNull; |
34 | 36 | import org.jetbrains.annotations.Nullable; |
|
62 | 64 | import gregtech.api.interfaces.ITexture; |
63 | 65 | import gregtech.api.interfaces.metatileentity.IMetaTileEntity; |
64 | 66 | import gregtech.api.interfaces.tileentity.IGregTechTileEntity; |
| 67 | +import gregtech.api.objects.ItemData; |
65 | 68 | import gregtech.api.recipe.RecipeMap; |
66 | 69 | import gregtech.api.recipe.check.CheckRecipeResult; |
67 | 70 | import gregtech.api.recipe.check.CheckRecipeResultRegistry; |
|
72 | 75 | import gregtech.api.util.GT_Recipe; |
73 | 76 | import gregtech.api.util.GT_Utility; |
74 | 77 | import gtPlusPlus.core.block.ModBlocks; |
| 78 | +import scala.actors.migration.pattern; |
75 | 79 |
|
76 | 80 | public class TST_MegaCraftingCenter extends TT_MultiMachineBase_EM |
77 | 81 | implements ICraftingProvider, IActionHost, IGridProxyable, ISurvivalConstructable { |
@@ -103,6 +107,70 @@ public static ItemStack[] convertAEToMC(IAEItemStack... STACK) { |
103 | 107 | .toArray(ItemStack[]::new); |
104 | 108 | } |
105 | 109 |
|
| 110 | + /** |
| 111 | + * |
| 112 | + * @param r The find recipe of this pattern. |
| 113 | + * @param in The pattern input items. |
| 114 | + * @param out The pattern output item. |
| 115 | + * @return If this pattern is valid. |
| 116 | + */ |
| 117 | + protected static boolean checkPatternRecipe(GT_Recipe r, ItemStack[] in, ItemStack out) { |
| 118 | + ItemStack rOut = r.mOutputs[0]; |
| 119 | + if (out == null || out.getItem() == null || out.stackSize < 1) return false; |
| 120 | + if (!Utils.metaItemEqual(out, rOut)) return false; |
| 121 | + // check amount |
| 122 | + if (out.stackSize < rOut.stackSize || out.stackSize % rOut.stackSize != 0) return false; |
| 123 | + // the multiple of pattern |
| 124 | + int multiple = out.stackSize / rOut.stackSize; |
| 125 | + |
| 126 | + Map<TST_ItemID, Long> rItemMap = new HashMap<>(); |
| 127 | + Map<Item, Long> rWildcardMap = new HashMap<>(); |
| 128 | + for (ItemStack i : r.mInputs) { |
| 129 | + if (i == null || i.getItem() == null || i.stackSize < 1) continue; |
| 130 | + ItemData iData = GT_OreDictUnificator.getAssociation(i); |
| 131 | + if (iData != null) { |
| 132 | + rItemMap.merge(TST_ItemID.createNoNBT(iData.mUnificationTarget), (long) i.stackSize, Long::sum); |
| 133 | + } else if (i.getItemDamage() == OreDictionary.WILDCARD_VALUE) { |
| 134 | + rWildcardMap.merge(i.getItem(), (long) i.stackSize, Long::sum); |
| 135 | + } else { |
| 136 | + rItemMap.merge(TST_ItemID.createNoNBT(i), (long) i.stackSize, Long::sum); |
| 137 | + } |
| 138 | + } |
| 139 | + |
| 140 | + Map<TST_ItemID, Long> pItemMap = new HashMap<>(); |
| 141 | + Map<Item, Long> pWildcardMap = new HashMap<>(); |
| 142 | + for (ItemStack i : in) { |
| 143 | + if (i == null || i.getItem() == null || i.stackSize < 1) continue; |
| 144 | + ItemData iData = GT_OreDictUnificator.getAssociation(i); |
| 145 | + if (iData != null) { |
| 146 | + pItemMap.merge(TST_ItemID.createNoNBT(iData.mUnificationTarget), (long) i.stackSize, Long::sum); |
| 147 | + } else { |
| 148 | + Item ii = i.getItem(); |
| 149 | + if (rWildcardMap.containsKey(ii)) { |
| 150 | + pWildcardMap.merge(ii, (long) i.stackSize, Long::sum); |
| 151 | + } else { |
| 152 | + pItemMap.merge(TST_ItemID.createNoNBT(i), (long) i.stackSize, Long::sum); |
| 153 | + } |
| 154 | + |
| 155 | + } |
| 156 | + } |
| 157 | + |
| 158 | + if (rItemMap.size() != pItemMap.size() || rWildcardMap.size() != pWildcardMap.size()) return false; |
| 159 | + |
| 160 | + for (Map.Entry<TST_ItemID, Long> rItemEntry : rItemMap.entrySet()) { |
| 161 | + Long pAmount = pItemMap.get(rItemEntry.getKey()); |
| 162 | + if (pAmount == null || pAmount == 0 || !pAmount.equals(rItemEntry.getValue() * multiple)) return false; |
| 163 | + } |
| 164 | + |
| 165 | + for (Map.Entry<Item, Long> rWildcardEntry : rWildcardMap.entrySet()) { |
| 166 | + Long pAmount = pWildcardMap.get(rWildcardEntry.getKey()); |
| 167 | + if (pAmount == null || pAmount == 0 || !pAmount.equals(rWildcardEntry.getValue() * multiple)) return false; |
| 168 | + } |
| 169 | + |
| 170 | + return true; |
| 171 | + |
| 172 | + } |
| 173 | + |
106 | 174 | public static @Nullable ICraftingPatternDetails checkPattern(ItemStack pattern) { |
107 | 175 | if (pattern == null || pattern.stackSize < 1) return null; |
108 | 176 | if (pattern.getItem() instanceof ICraftingPatternItem patternItem) { |
@@ -132,85 +200,23 @@ public static ItemStack[] convertAEToMC(IAEItemStack... STACK) { |
132 | 200 | if (validResult.length == 1) { |
133 | 201 | if (validResult[0] == null) return null; |
134 | 202 |
|
135 | | - @NotNull |
136 | | - ItemStack rItems = validResult[0].mOutputs[0]; |
137 | | - if (Utils.metaItemEqual(pItems, rItems)) { |
138 | | - if (pItems.stackSize < rItems.stackSize || (pItems.stackSize & rItems.stackSize) != 0) |
139 | | - return null; |
140 | | - // allow to double pattern |
141 | | - int multiple = pItems.stackSize / rItems.stackSize; |
142 | | - if (multiple < 1) return null; |
143 | | - |
144 | | - ItemStack[] rInputs = validResult[0].mInputs; |
145 | | - Map<TST_ItemID, Long> rInputMap = new HashMap<>(); |
146 | | - for (int t = 0; t < rInputs.length; t++) { |
147 | | - rInputMap.merge( |
148 | | - TST_ItemID.createNoNBT(GT_OreDictUnificator.get_nocopy(rInputs[t])), |
149 | | - (long) rInputs[t].stackSize, |
150 | | - Long::sum); |
151 | | - } |
152 | | - |
153 | | - Map<TST_ItemID, Long> pInputMap = new HashMap<>(); |
154 | | - for (int t = 0; t < dInputs.length; t++) { |
155 | | - pInputMap.merge( |
156 | | - TST_ItemID.createNoNBT(GT_OreDictUnificator.get_nocopy(dInputs[t])), |
157 | | - (long) dInputs[t].stackSize, |
158 | | - Long::sum); |
159 | | - } |
160 | | - |
161 | | - if (rInputMap.size() != pInputMap.size()) return null; |
162 | | - |
163 | | - for (Map.Entry<TST_ItemID, Long> rEntry : rInputMap.entrySet()) { |
164 | | - Long pAmount = pInputMap.get(rEntry.getKey()); |
165 | | - if (pAmount == null || !pAmount.equals(rEntry.getValue() * multiple)) return null; |
166 | | - } |
167 | | - |
| 203 | + if (checkPatternRecipe(validResult[0], dInputs, pItems)) { |
168 | 204 | return d; |
169 | 205 | } else { |
170 | 206 | return null; |
171 | 207 | } |
172 | 208 |
|
173 | 209 | } else { |
174 | | - recipesLoop: for (int i = 0; i < validResult.length; i++) { |
175 | | - @NotNull |
176 | | - ItemStack rItems = validResult[i].mOutputs[0]; |
177 | | - if (Utils.metaItemEqual(pItems, rItems)) { |
178 | | - if (pItems.stackSize < rItems.stackSize || (pItems.stackSize & rItems.stackSize) != 0) |
179 | | - continue; |
180 | | - // allow to double pattern |
181 | | - int multiple = pItems.stackSize / rItems.stackSize; |
182 | | - if (multiple < 1) continue; |
183 | | - |
184 | | - ItemStack[] rInputs = validResult[i].mInputs; |
185 | | - Map<TST_ItemID, Long> rInputMap = new HashMap<>(); |
186 | | - for (int t = 0; t < rInputs.length; t++) { |
187 | | - rInputMap.merge( |
188 | | - TST_ItemID.createNoNBT(GT_OreDictUnificator.get_nocopy(rInputs[t])), |
189 | | - (long) rInputs[t].stackSize, |
190 | | - Long::sum); |
191 | | - } |
192 | | - |
193 | | - Map<TST_ItemID, Long> pInputMap = new HashMap<>(); |
194 | | - for (int t = 0; t < dInputs.length; t++) { |
195 | | - pInputMap.merge( |
196 | | - TST_ItemID.createNoNBT(GT_OreDictUnificator.get_nocopy(dInputs[t])), |
197 | | - (long) dInputs[t].stackSize, |
198 | | - Long::sum); |
199 | | - } |
200 | | - |
201 | | - if (rInputMap.size() != pInputMap.size()) continue; |
202 | | - for (Map.Entry<TST_ItemID, Long> rEntry : rInputMap.entrySet()) { |
203 | | - Long pAmount = pInputMap.get(rEntry.getKey()); |
204 | | - if (pAmount == null || !pAmount.equals(rEntry.getValue() * multiple)) |
205 | | - continue recipesLoop; |
206 | | - } |
207 | | - |
| 210 | + for (int i = 0; i < validResult.length; i++) { |
| 211 | + if (checkPatternRecipe(validResult[i], dInputs, pItems)) { |
208 | 212 | return d; |
209 | 213 | } |
210 | 214 | } |
| 215 | + |
211 | 216 | } |
212 | 217 | } |
213 | 218 | } |
| 219 | + |
214 | 220 | return null; |
215 | 221 | } |
216 | 222 |
|
|
0 commit comments