use of mcjty.rftools.craftinggrid.CraftingRecipe in project RFTools by McJty.
the class CrafterBaseTE method writeRecipesToNBT.
private void writeRecipesToNBT(NBTTagCompound tagCompound) {
NBTTagList recipeTagList = new NBTTagList();
for (CraftingRecipe recipe : recipes) {
NBTTagCompound nbtTagCompound = new NBTTagCompound();
recipe.writeToNBT(nbtTagCompound);
recipeTagList.appendTag(nbtTagCompound);
}
tagCompound.setTag("Recipes", recipeTagList);
}
use of mcjty.rftools.craftinggrid.CraftingRecipe in project RFTools by McJty.
the class GuiCrafter method applyRecipe.
private void applyRecipe() {
int selected = recipeList.getSelected();
if (selected == -1) {
return;
}
if (selected >= tileEntity.getSupportedRecipes()) {
recipeList.setSelected(-1);
return;
}
CraftingRecipe craftingRecipe = tileEntity.getRecipe(selected);
InventoryCrafting inv = craftingRecipe.getInventory();
for (int i = 0; i < 9; i++) {
ItemStack oldStack = inv.getStackInSlot(i);
ItemStack newStack = inventorySlots.getSlot(i).getStack();
if (!itemStacksEqual(oldStack, newStack)) {
inv.setInventorySlotContents(i, newStack);
}
}
// Compare current contents to avoid unneeded slot update.
IRecipe recipe = CraftingRecipe.findRecipe(mc.world, inv);
ItemStack newResult;
if (recipe == null) {
newResult = ItemStack.EMPTY;
} else {
newResult = recipe.getCraftingResult(inv);
}
ItemStack oldResult = inventorySlots.getSlot(9).getStack();
if (!itemStacksEqual(oldResult, newResult)) {
inventorySlots.getSlot(9).putStack(newResult);
}
craftingRecipe.setResult(newResult);
updateRecipe();
populateList();
}
use of mcjty.rftools.craftinggrid.CraftingRecipe in project RFTools by McJty.
the class GuiCrafter method populateList.
private void populateList() {
recipeList.removeChildren();
for (int i = 0; i < tileEntity.getSupportedRecipes(); i++) {
CraftingRecipe recipe = tileEntity.getRecipe(i);
addRecipeLine(recipe.getResult());
}
}
use of mcjty.rftools.craftinggrid.CraftingRecipe in project RFTools by McJty.
the class CrafterBaseTE method selectRecipe.
public void selectRecipe(int index) {
CraftingRecipe recipe = recipes[index];
setInventorySlotContents(CrafterContainer.SLOT_CRAFTOUTPUT, recipe.getResult());
InventoryCrafting inv = recipe.getInventory();
int size = inv.getSizeInventory();
for (int i = 0; i < size; ++i) {
setInventorySlotContents(CrafterContainer.SLOT_CRAFTINPUT + i, inv.getStackInSlot(i));
}
}
use of mcjty.rftools.craftinggrid.CraftingRecipe in project RFTools by McJty.
the class CrafterBaseTE method craftOneItemNew.
private boolean craftOneItemNew(CraftingRecipe craftingRecipe) {
IRecipe recipe = craftingRecipe.getCachedRecipe(getWorld());
if (recipe == null) {
return false;
}
Map<Integer, ItemStack> undo = new HashMap<>();
if (!testAndConsumeCraftingItems(craftingRecipe, undo, true)) {
undo(undo);
if (!testAndConsumeCraftingItems(craftingRecipe, undo, false)) {
undo(undo);
return false;
}
}
// ItemStack result = recipe.getCraftingResult(craftingRecipe.getInventory());
ItemStack result = ItemStack.EMPTY;
try {
result = recipe.getCraftingResult(workInventory);
} catch (RuntimeException e) {
// Ignore this error for now to make sure we don't crash on bad recipes.
Logging.logError("Problem with recipe!", e);
}
// Try to merge the output. If there is something that doesn't fit we undo everything.
CraftingRecipe.CraftMode mode = craftingRecipe.getCraftMode();
if (!result.isEmpty() && placeResult(mode, result, undo)) {
List<ItemStack> remaining = recipe.getRemainingItems(workInventory);
if (remaining != null) {
CraftingRecipe.CraftMode remainingMode = mode == EXTC ? INT : mode;
for (ItemStack s : remaining) {
if (!s.isEmpty()) {
if (!placeResult(remainingMode, s, undo)) {
// Not enough room.
undo(undo);
return false;
}
}
}
}
return true;
} else {
// We don't have place. Undo the operation.
undo(undo);
return false;
}
}
Aggregations