@@ -12,6 +12,7 @@ import net.minecraft.inventory.InventoryCrafting;
|
|||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.crafting.CraftingManager;
|
import net.minecraft.item.crafting.CraftingManager;
|
||||||
import net.minecraft.item.crafting.IRecipe;
|
import net.minecraft.item.crafting.IRecipe;
|
||||||
|
import net.minecraft.util.NonNullList;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||||
@@ -20,6 +21,7 @@ import javax.annotation.Nullable;
|
|||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class CraftingPattern implements ICraftingPattern {
|
public class CraftingPattern implements ICraftingPattern {
|
||||||
private ICraftingPatternContainer container;
|
private ICraftingPatternContainer container;
|
||||||
@@ -80,18 +82,20 @@ public class CraftingPattern implements ICraftingPattern {
|
|||||||
} else if (input instanceof ItemStack) {
|
} else if (input instanceof ItemStack) {
|
||||||
ItemStack stripped = Comparer.stripTags(((ItemStack) input).copy());
|
ItemStack stripped = Comparer.stripTags(((ItemStack) input).copy());
|
||||||
if (stripped.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
|
if (stripped.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
|
||||||
stripped.setItemDamage(0);
|
oreInputs.add(getSubItems(stripped));
|
||||||
}
|
} else {
|
||||||
oreInputs.add(Collections.singletonList(stripped));
|
oreInputs.add(Collections.singletonList(stripped));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
List<ItemStack> cleaned = new LinkedList<>();
|
List<ItemStack> cleaned = new LinkedList<>();
|
||||||
for (ItemStack in : (List<ItemStack>) input) {
|
for (ItemStack in : (List<ItemStack>) input) {
|
||||||
ItemStack stripped = Comparer.stripTags(in.copy());
|
ItemStack stripped = Comparer.stripTags(in.copy());
|
||||||
if (stripped.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
|
if (stripped.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
|
||||||
stripped.setItemDamage(0);
|
cleaned.addAll(getSubItems(stripped));
|
||||||
}
|
} else {
|
||||||
cleaned.add(stripped);
|
cleaned.add(stripped);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
oreInputs.add(cleaned);
|
oreInputs.add(cleaned);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -118,7 +122,7 @@ public class CraftingPattern implements ICraftingPattern {
|
|||||||
if (ids == null || ids.length == 0) {
|
if (ids == null || ids.length == 0) {
|
||||||
oreInputs.add(Collections.singletonList(Comparer.stripTags(input)));
|
oreInputs.add(Collections.singletonList(Comparer.stripTags(input)));
|
||||||
} else {
|
} else {
|
||||||
oreInputs.add(Arrays.stream(ids)
|
List<ItemStack> oredict = Arrays.stream(ids)
|
||||||
.mapToObj(OreDictionary::getOreName)
|
.mapToObj(OreDictionary::getOreName)
|
||||||
.map(OreDictionary::getOres)
|
.map(OreDictionary::getOres)
|
||||||
.flatMap(List::stream)
|
.flatMap(List::stream)
|
||||||
@@ -128,8 +132,11 @@ public class CraftingPattern implements ICraftingPattern {
|
|||||||
s.setCount(input.getCount());
|
s.setCount(input.getCount());
|
||||||
return s;
|
return s;
|
||||||
})
|
})
|
||||||
.collect(Collectors.toList())
|
.flatMap(this::checkOreDictWildcard)
|
||||||
);
|
.collect(Collectors.toList());
|
||||||
|
// Add original stack as first, should prevent some issues
|
||||||
|
oredict.add(0, Comparer.stripTags(input.copy()));
|
||||||
|
oreInputs.add(oredict);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -147,6 +154,22 @@ public class CraftingPattern implements ICraftingPattern {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Stream<ItemStack> checkOreDictWildcard(ItemStack stack) {
|
||||||
|
List<ItemStack> list = new LinkedList<>();
|
||||||
|
if (stack.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
|
||||||
|
list.addAll(getSubItems(stack));
|
||||||
|
} else {
|
||||||
|
list.add(stack);
|
||||||
|
}
|
||||||
|
return list.stream();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ItemStack> getSubItems(ItemStack stack) {
|
||||||
|
NonNullList<ItemStack> subItems = NonNullList.create();
|
||||||
|
stack.getItem().getSubItems(stack.getItem(), stack.getItem().getCreativeTab(), subItems);
|
||||||
|
return subItems.stream().map(Comparer::stripTags).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ICraftingPatternContainer getContainer() {
|
public ICraftingPatternContainer getContainer() {
|
||||||
return container;
|
return container;
|
||||||
|
@@ -42,7 +42,7 @@ public class CraftingStepCraft extends CraftingStep {
|
|||||||
if (!super.canStartProcessing()) {
|
if (!super.canStartProcessing()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int compare = CraftingTask.DEFAULT_COMPARE | (pattern.isOredict() ? IComparer.COMPARE_OREDICT : 0);
|
int compare = CraftingTask.DEFAULT_COMPARE;
|
||||||
for (ItemStack stack : getToInsert()) {
|
for (ItemStack stack : getToInsert()) {
|
||||||
// This will be a tool, like a hammer
|
// This will be a tool, like a hammer
|
||||||
if (stack.isItemStackDamageable()) {
|
if (stack.isItemStackDamageable()) {
|
||||||
@@ -66,12 +66,11 @@ public class CraftingStepCraft extends CraftingStep {
|
|||||||
@Override
|
@Override
|
||||||
public void execute(Deque<ItemStack> toInsertItems, Deque<FluidStack> toInsertFluids) {
|
public void execute(Deque<ItemStack> toInsertItems, Deque<FluidStack> toInsertFluids) {
|
||||||
List<ItemStack> actualInputs = new LinkedList<>();
|
List<ItemStack> actualInputs = new LinkedList<>();
|
||||||
int compare = CraftingTask.DEFAULT_COMPARE | (getPattern().isOredict() ? IComparer.COMPARE_OREDICT : 0);
|
if (extractItems(actualInputs, CraftingTask.DEFAULT_COMPARE, toInsertItems)) {
|
||||||
if (extractItems(actualInputs, compare, toInsertItems)) {
|
|
||||||
IStackList<ItemStack> stackList = API.instance().createItemStackList();
|
IStackList<ItemStack> stackList = API.instance().createItemStackList();
|
||||||
actualInputs.forEach(stackList::add);
|
actualInputs.forEach(stackList::add);
|
||||||
|
|
||||||
ItemStack[] took = StackListItem.toCraftingGrid(stackList, toInsert, compare);
|
ItemStack[] took = StackListItem.toCraftingGrid(stackList, toInsert, CraftingTask.DEFAULT_COMPARE);
|
||||||
|
|
||||||
List<ItemStack> outputs = pattern.isOredict() ? pattern.getOutputs(took) : pattern.getOutputs();
|
List<ItemStack> outputs = pattern.isOredict() ? pattern.getOutputs(took) : pattern.getOutputs();
|
||||||
if (outputs == null) {
|
if (outputs == null) {
|
||||||
|
@@ -95,7 +95,7 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
int compare = DEFAULT_COMPARE | (pattern.isOredict() ? IComparer.COMPARE_OREDICT : 0);
|
int compare = DEFAULT_COMPARE;
|
||||||
|
|
||||||
IStackList<ItemStack> inputs = API.instance().createItemStackList();
|
IStackList<ItemStack> inputs = API.instance().createItemStackList();
|
||||||
IStackList<ItemStack> actualInputs = API.instance().createItemStackList();
|
IStackList<ItemStack> actualInputs = API.instance().createItemStackList();
|
||||||
|
Reference in New Issue
Block a user