use of net.minecraft.item.crafting.Ingredient in project Charset by CharsetMC.
the class BarrelUpgradeOutputSupplier method getCraftingResult.
@Override
public ItemStack getCraftingResult(RecipeCharset recipe, IngredientMatcher matcher, InventoryCrafting inv) {
for (Ingredient i : matcher.getMatchedIngredients()) {
ItemStack is = matcher.getStack(i);
if (is.getItem() instanceof ItemDayBarrel || is.getItem() instanceof ItemMinecartDayBarrel) {
is = is.copy();
is.setCount(1);
return TileEntityDayBarrel.addUpgrade(is, upgradeType);
}
}
return null;
}
use of net.minecraft.item.crafting.Ingredient in project Charset by CharsetMC.
the class LockOutputSupplier method getCraftingResult.
@Override
public ItemStack getCraftingResult(RecipeCharset recipe, IngredientMatcher matcher, InventoryCrafting inv) {
for (Ingredient i : matcher.getMatchedIngredients()) {
ItemStack key = matcher.getStack(i);
if (!key.isEmpty() && key.getItem() instanceof ItemKey) {
ItemStack result = output.copy();
result.setTagCompound(new NBTTagCompound());
if (key.hasTagCompound() && key.getTagCompound().hasKey("color")) {
result.getTagCompound().setTag("color", key.getTagCompound().getTag("color"));
}
result.getTagCompound().setString("key", ((ItemKey) key.getItem()).getKey(key));
return result;
}
}
return null;
}
use of net.minecraft.item.crafting.Ingredient in project Charset by CharsetMC.
the class InventoryCraftingIterator method next.
@Override
public InventoryCrafting next() {
int permPos = i;
Map<Ingredient, Object> stackMap = new HashMap<>();
for (Map.Entry<Ingredient, Object> entry : permutatingIngredients.entrySet()) {
Object stacks = entry.getValue();
if (stacks instanceof ItemStack[][]) {
int length = ((ItemStack[][]) stacks).length;
ItemStack[] stackSet = ((ItemStack[][]) stacks)[permPos % length];
if (stackSet.length == 1) {
stackMap.put(entry.getKey(), stackSet[0]);
} else {
stackMap.put(entry.getKey(), stackSet);
}
permPos /= length;
} else if (stacks instanceof ItemStack[]) {
stackMap.put(entry.getKey(), ((ItemStack[]) stacks)[permPos % ((ItemStack[]) stacks).length]);
permPos /= ((ItemStack[]) stacks).length;
} else {
throw new RuntimeException("Unknown stacks type in InventoryCraftingIterator.next(): " + stacks.getClass().getName());
}
}
for (int i = 0; i < recipe.input.size(); i++) {
Ingredient ing = recipe.input.get(i);
if (permutatingIngredients.containsKey(ing)) {
Object o = stackMap.get(ing);
if (o instanceof ItemStack[]) {
ItemStack[] stacks = (ItemStack[]) o;
setInventorySlotContents(i, stacks.length > 0 ? stacks[0] : ItemStack.EMPTY);
inputReal[i] = Arrays.asList(stacks);
} else if (o instanceof ItemStack) {
setInventorySlotContents(i, (ItemStack) o);
inputReal[i] = stackMap.get(ing);
} else {
throw new RuntimeException("Unknown stacks type in InventoryCraftingIterator.next(): " + o.getClass().getName());
}
} else {
ItemStack[] stacks = ing.getMatchingStacks();
setInventorySlotContents(i, stacks.length > 0 ? stacks[0] : ItemStack.EMPTY);
inputReal[i] = ing;
}
}
i++;
return this;
}
use of net.minecraft.item.crafting.Ingredient in project Charset by CharsetMC.
the class RecipeCharset method matchedOrNull.
protected IngredientMatcher matchedOrNull(InventoryCrafting inv) {
if (shapeless) {
Set<Ingredient> objectSet = new HashSet<>();
objectSet.addAll(input);
IngredientMatcher matcher = new IngredientMatcher(this);
for (int y = 0; y < inv.getHeight(); y++) {
for (int x = 0; x < inv.getWidth(); x++) {
ItemStack stack = inv.getStackInRowAndColumn(x, y);
if (!stack.isEmpty()) {
boolean matches = false;
for (Ingredient o : objectSet) {
if (o.apply(stack)) {
matches = true;
matcher.add(stack, o);
objectSet.remove(o);
break;
}
}
if (!matches) {
return null;
}
}
}
}
return objectSet.size() == 0 ? matcher : null;
} else {
for (int yo = 0; yo <= inv.getHeight() - height; yo++) {
for (int xo = 0; xo <= inv.getWidth() - width; xo++) {
IngredientMatcher matcher = new IngredientMatcher(this);
boolean matches = false;
for (int iIdx = 0; iIdx < input.size(); iIdx++) {
int i = (shapedOrdering != null ? shapedOrdering[iIdx] : iIdx);
int x = i % width + xo;
int y = i / width + yo;
matches = matcher.add(inv.getStackInRowAndColumn(x, y), input.get(i));
if (!matches)
break;
}
if (!matches && mirrored) {
matcher = new IngredientMatcher(this);
matches = false;
for (int iIdx = 0; iIdx < input.size(); iIdx++) {
int i = (shapedOrdering != null ? shapedOrdering[iIdx] : iIdx);
int x = ((width - 1) - (i % width)) + xo;
int y = i / width + yo;
matches = matcher.add(inv.getStackInRowAndColumn(x, y), input.get(i));
if (!matches)
break;
}
}
if (matches)
return matcher;
}
}
return null;
}
}
use of net.minecraft.item.crafting.Ingredient in project Charset by CharsetMC.
the class RecipeReplacement method replaceIngredient.
@Nullable
private Ingredient replaceIngredient(Ingredient ing) {
if (ing.getClass() == Ingredient.class || ing.getClass() == IngredientNBT.class) {
boolean checkNBT = ing.getClass() == IngredientNBT.class;
ItemStack[] matchingStacks = ing.getMatchingStacks();
ItemStack[] matchingStacksNew = null;
int replacementOreMatches = 0;
String replacementOre = null;
boolean dirty = false;
for (int j = 0; j < matchingStacks.length; j++) {
ItemStack stack = matchingStacks[j];
if (stack.isEmpty())
continue;
ItemStack newStack = null;
Object replacement = null;
for (int i : OreDictionary.getOreIDs(stack)) {
if (replaceableOres.containsKey(i)) {
replacement = replaceableOres.get(i);
break;
}
}
if (replacement == null) {
if (replacements.containsKey(stack)) {
replacement = replacements.get(stack);
} else if (!checkNBT && replaceableItems.containsKey(stack.getItem())) {
replacement = replaceableItems.get(stack.getItem());
}
}
if (replacement instanceof Item) {
newStack = new ItemStack((Item) replacement, stack.getCount(), stack.getItemDamage());
newStack.setTagCompound(stack.getTagCompound());
} else if (replacement instanceof ItemStack) {
newStack = ((ItemStack) replacements.get(stack)).copy();
newStack.setCount(stack.getCount());
} else if (replacement instanceof String) {
replacementOreMatches++;
replacementOre = (String) replacement;
}
if (newStack != null) {
if (!dirty) {
matchingStacksNew = new ItemStack[matchingStacks.length];
System.arraycopy(matchingStacks, 0, matchingStacksNew, 0, matchingStacks.length);
dirty = true;
}
matchingStacksNew[j] = newStack;
}
}
if (replacementOre != null && replacementOreMatches == matchingStacks.length) {
return new OreIngredient(replacementOre);
} else {
if (matchingStacksNew != null) {
return Ingredient.fromStacks(matchingStacksNew);
}
}
} else if (ing.getClass() == OreIngredient.class) {
try {
NonNullList<ItemStack> list = (NonNullList<ItemStack>) ORES_GETTER.invokeExact((OreIngredient) ing);
if (list.isEmpty()) {
return null;
}
TIntIterator it = replaceableOres.keySet().iterator();
while (it.hasNext()) {
int oreId = it.next();
NonNullList<ItemStack> oreList = OreDictionary.getOres(OreDictionary.getOreName(oreId));
if (!oreList.isEmpty() && list == oreList) {
Object replacement = replaceableOres.get(oreId);
if (replacement instanceof Item) {
return Ingredient.fromItem((Item) replacement);
} else if (replacement instanceof ItemStack) {
return Ingredient.fromStacks((ItemStack) replacement);
} else if (replacement instanceof String) {
return new OreIngredient((String) replacement);
}
}
}
} catch (Throwable t) {
t.printStackTrace();
}
}
return null;
}
Aggregations