use of forestry.api.recipes.IFabricatorRecipe in project ForestryMC by ForestryMC.
the class TileFabricator method hasWork.
@Override
public boolean hasWork() {
boolean hasRecipe = true;
boolean hasLiquidResources = true;
boolean hasResources = true;
ItemStack plan = getStackInSlot(InventoryFabricator.SLOT_PLAN);
RecipePair<IFabricatorRecipe> recipePair = FabricatorRecipeManager.findMatchingRecipe(plan, craftingInventory);
if (!recipePair.isEmpty()) {
IFabricatorRecipe recipe = recipePair.getRecipe();
NonNullList<ItemStack> crafting = InventoryUtil.getStacks(craftingInventory, InventoryGhostCrafting.SLOT_CRAFTING_1, InventoryGhostCrafting.SLOT_CRAFTING_COUNT);
hasResources = removeFromInventory(crafting, recipePair, false);
FluidStack toDrain = recipe.getLiquid();
FluidStack drained = moltenTank.drainInternal(toDrain, false);
hasLiquidResources = drained != null && drained.isFluidStackIdentical(toDrain);
} else {
hasRecipe = false;
}
IErrorLogic errorLogic = getErrorLogic();
errorLogic.setCondition(!hasRecipe, EnumErrorCode.NO_RECIPE);
errorLogic.setCondition(!hasLiquidResources, EnumErrorCode.NO_RESOURCE_LIQUID);
errorLogic.setCondition(!hasResources, EnumErrorCode.NO_RESOURCE_INVENTORY);
return hasRecipe;
}
use of forestry.api.recipes.IFabricatorRecipe in project ForestryMC by ForestryMC.
the class FabricatorRecipeCategory method setRecipe.
@Override
public void setRecipe(IRecipeLayout recipeLayout, FabricatorRecipeWrapper recipeWrapper, IIngredients ingredients) {
IGuiItemStackGroup guiItemStacks = recipeLayout.getItemStacks();
IGuiFluidStackGroup guiFluidStacks = recipeLayout.getFluidStacks();
guiItemStacks.init(planSlot, true, 118, 0);
guiItemStacks.init(smeltingInputSlot, true, 5, 4);
guiItemStacks.init(craftOutputSlot, false, 118, 36);
for (int y = 0; y < 3; ++y) {
for (int x = 0; x < 3; ++x) {
int index = craftInputSlot + x + y * 3;
guiItemStacks.init(index, true, 46 + x * 18, y * 18);
}
}
guiFluidStacks.init(inputTank, true, 6, 32, 16, 16, 2000, false, null);
IFabricatorRecipe recipe = recipeWrapper.getRecipe();
ItemStack plan = recipe.getPlan();
if (!plan.isEmpty()) {
guiItemStacks.set(planSlot, plan);
}
List<ItemStack> smeltingInput = new ArrayList<>();
Fluid recipeFluid = recipe.getLiquid().getFluid();
for (IFabricatorSmeltingRecipe s : getSmeltingInputs().get(recipeFluid)) {
smeltingInput.add(s.getResource());
}
if (!smeltingInput.isEmpty()) {
guiItemStacks.set(smeltingInputSlot, smeltingInput);
}
List<List<ItemStack>> itemOutputs = ingredients.getOutputs(ItemStack.class);
guiItemStacks.set(craftOutputSlot, itemOutputs.get(0));
List<List<ItemStack>> itemStackInputs = ingredients.getInputs(ItemStack.class);
craftingGridHelper.setInputs(guiItemStacks, itemStackInputs, recipe.getWidth(), recipe.getHeight());
List<List<FluidStack>> fluidInputs = ingredients.getInputs(FluidStack.class);
if (!fluidInputs.isEmpty()) {
guiFluidStacks.set(inputTank, fluidInputs.get(0));
}
}
use of forestry.api.recipes.IFabricatorRecipe in project ForestryMC by ForestryMC.
the class FabricatorRecipeManager method addRecipe.
@Override
public void addRecipe(ItemStack plan, FluidStack molten, ItemStack result, Object[] pattern) {
ShapedRecipeCustom patternRecipe = new ShapedRecipeCustom(result, pattern);
NonNullList<NonNullList<ItemStack>> ingredients = patternRecipe.getRawIngredients();
IFabricatorRecipe recipe = new FabricatorRecipe(plan, molten, result, ingredients, patternRecipe.getOreDicts(), patternRecipe.getWidth(), patternRecipe.getHeight());
addRecipe(recipe);
}
use of forestry.api.recipes.IFabricatorRecipe in project ForestryMC by ForestryMC.
the class TileFabricator method craftResult.
private void craftResult() {
RecipePair<IFabricatorRecipe> myRecipePair = getRecipe();
ItemStack craftResult = getResult(myRecipePair);
IFabricatorRecipe myRecipe = myRecipePair.getRecipe();
if (myRecipe != null && !craftResult.isEmpty() && getStackInSlot(InventoryFabricator.SLOT_RESULT).isEmpty()) {
FluidStack liquid = myRecipe.getLiquid();
// Remove resources
NonNullList<ItemStack> crafting = InventoryUtil.getStacks(craftingInventory, InventoryGhostCrafting.SLOT_CRAFTING_1, InventoryGhostCrafting.SLOT_CRAFTING_COUNT);
if (removeFromInventory(crafting, myRecipePair, false)) {
FluidStack drained = moltenTank.drainInternal(liquid, false);
if (drained != null && drained.isFluidStackIdentical(liquid)) {
removeFromInventory(crafting, myRecipePair, true);
moltenTank.drain(liquid.amount, true);
// Damage plan
if (!getStackInSlot(InventoryFabricator.SLOT_PLAN).isEmpty()) {
Item planItem = getStackInSlot(InventoryFabricator.SLOT_PLAN).getItem();
if (planItem instanceof ICraftingPlan) {
ItemStack planUsed = ((ICraftingPlan) planItem).planUsed(getStackInSlot(InventoryFabricator.SLOT_PLAN), craftResult);
setInventorySlotContents(InventoryFabricator.SLOT_PLAN, planUsed);
}
}
setInventorySlotContents(InventoryFabricator.SLOT_RESULT, craftResult);
}
}
}
}
use of forestry.api.recipes.IFabricatorRecipe in project ForestryMC by ForestryMC.
the class TileFabricator method getRecipe.
@Nullable
private RecipePair getRecipe() {
IInventoryAdapter inventory = getInternalInventory();
ItemStack plan = inventory.getStackInSlot(InventoryFabricator.SLOT_PLAN);
FluidStack liquid = moltenTank.getFluid();
RecipePair<IFabricatorRecipe> recipePair = FabricatorRecipeManager.findMatchingRecipe(plan, craftingInventory);
IFabricatorRecipe recipe = recipePair.getRecipe();
if (liquid != null && recipe != null && !liquid.containsFluid(recipe.getLiquid())) {
return RecipePair.EMPTY;
}
return recipePair;
}
Aggregations