use of gregapi.tileentity.ITileEntityAdjacentInventoryUpdatable in project gregtech6 by GregTech6.
the class MultiTileEntityBasicMachine method checkRecipe.
/**
* Override this to check the Recipes yourself, super calls to this could be useful if you just want to add a special case
* I thought about Enum too, but Enum doesn't add support for people adding other return Systems.
* Funny how Eclipse marks the word Enum as not correctly spelled.
* @return see constants above
*/
public int checkRecipe(boolean aApplyRecipe, boolean aUseAutoInputs) {
mCouldUseRecipe = F;
if (mRecipes == null)
return DID_NOT_FIND_RECIPE;
byte tAutoInput = FACING_TO_SIDE[mFacing][mItemAutoInput];
if (aUseAutoInputs && !mDisabledItemInput && SIDES_VALID[tAutoInput]) {
ST.moveAll(getItemInputTarget(tAutoInput), delegator(tAutoInput));
}
int tInputItemsCount = 0, tInputFluidsCount = 0;
ItemStack[] tInputs = new ItemStack[mRecipes.mInputItemsCount];
for (int i = 0; i < mRecipes.mInputItemsCount; i++) {
tInputs[i] = slot(i);
if (ST.valid(tInputs[i]))
tInputItemsCount++;
}
tAutoInput = FACING_TO_SIDE[mFacing][mFluidAutoInput];
if (aUseAutoInputs && !mDisabledFluidInput && SIDES_VALID[tAutoInput]) {
DelegatorTileEntity<IFluidHandler> tTileEntity = getFluidInputTarget(tAutoInput);
if (tTileEntity != null && tTileEntity.mTileEntity != null) {
FluidTankInfo[] tInfos = tTileEntity.mTileEntity.getTankInfo(FORGE_DIR[tTileEntity.mSideOfTileEntity]);
if (tInfos != null)
for (FluidTankInfo tInfo : tInfos) if (tInfo != null && tInfo.fluid != null && tInfo.fluid.amount > 0 && getFluidTankFillable(SIDE_ANY, tInfo.fluid) != null) {
if (FL.move_(tTileEntity, delegator(tAutoInput), tInfo.fluid) > 0)
updateInventory();
}
}
}
for (FluidTankGT tTank : mTanksInput) if (tTank.has())
tInputFluidsCount++;
if (tInputItemsCount < mRecipes.mMinimalInputItems)
return DID_NOT_FIND_RECIPE;
if (tInputFluidsCount < mRecipes.mMinimalInputFluids)
return DID_NOT_FIND_RECIPE;
if (tInputItemsCount + tInputFluidsCount < mRecipes.mMinimalInputs)
return DID_NOT_FIND_RECIPE;
Recipe tRecipe = mRecipes.findRecipe(this, mLastRecipe, F, mEnergyTypeAccepted == TD.Energy.RF ? mInputMax / RF_PER_EU : mInputMax, slot(mRecipes.mInputItemsCount + mRecipes.mOutputItemsCount), mTanksInput, tInputs);
int tMaxProcessCount = 0;
if (tRecipe == null) {
if (!mCanUseOutputTanks)
return DID_NOT_FIND_RECIPE;
tRecipe = mRecipes.findRecipe(this, mLastRecipe, F, mEnergyTypeAccepted == TD.Energy.RF ? mInputMax / RF_PER_EU : mInputMax, slot(mRecipes.mInputItemsCount + mRecipes.mOutputItemsCount), mTanksOutput, tInputs);
if (tRecipe == null)
return DID_NOT_FIND_RECIPE;
if (tRecipe.mCanBeBuffered)
mLastRecipe = tRecipe;
tMaxProcessCount = canOutput(tRecipe);
if (tMaxProcessCount <= 0)
return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS;
if (aApplyRecipe)
aApplyRecipe = (!mRequiresIgnition || mIgnited > 0 || mActive);
if (!tRecipe.isRecipeInputEqual(aApplyRecipe, F, mTanksOutput, tInputs))
return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS;
mCouldUseRecipe = T;
if (!aApplyRecipe)
return FOUND_AND_COULD_HAVE_USED_RECIPE;
if (tMaxProcessCount > 1) {
if (!mParallelDuration && mEnergyTypeAccepted != TD.Energy.TU)
tMaxProcessCount = (int) UT.Code.bind(1, tMaxProcessCount, mInput / Math.max(1, (mEnergyTypeAccepted == TD.Energy.RF ? tRecipe.mEUt * RF_PER_EU : tRecipe.mEUt)));
tMaxProcessCount = 1 + tRecipe.isRecipeInputEqual(tMaxProcessCount - 1, mTanksOutput, tInputs);
}
} else {
if (tRecipe.mCanBeBuffered)
mLastRecipe = tRecipe;
tMaxProcessCount = canOutput(tRecipe);
if (tMaxProcessCount <= 0)
return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS;
if (aApplyRecipe)
aApplyRecipe = (!mRequiresIgnition || mIgnited > 0 || mActive);
if (!tRecipe.isRecipeInputEqual(aApplyRecipe, F, mTanksInput, tInputs))
return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS;
mCouldUseRecipe = T;
if (!aApplyRecipe)
return FOUND_AND_COULD_HAVE_USED_RECIPE;
if (tMaxProcessCount > 1) {
if (!mParallelDuration && mEnergyTypeAccepted != TD.Energy.TU)
tMaxProcessCount = (int) UT.Code.bind(1, tMaxProcessCount, mInput / Math.max(1, (mEnergyTypeAccepted == TD.Energy.RF ? tRecipe.mEUt * RF_PER_EU : tRecipe.mEUt)));
tMaxProcessCount = 1 + tRecipe.isRecipeInputEqual(tMaxProcessCount - 1, mTanksInput, tInputs);
}
}
for (byte tSide : ALL_SIDES_VALID_FIRST[FACING_TO_SIDE[mFacing][mItemAutoInput]]) if (FACE_CONNECTED[FACING_ROTATIONS[mFacing][tSide]][mItemInputs]) {
DelegatorTileEntity<IInventory> tDelegator = getItemInputTarget(tSide);
if (tDelegator != null && tDelegator.mTileEntity instanceof ITileEntityAdjacentInventoryUpdatable) {
((ITileEntityAdjacentInventoryUpdatable) tDelegator.mTileEntity).adjacentInventoryUpdated(tDelegator.mSideOfTileEntity, this);
}
}
if (mSpecialIsStartEnergy && (!mActive || (mCurrentRecipe != null && mCurrentRecipe != tRecipe)))
mChargeRequirement = tRecipe.mSpecialValue;
mCurrentRecipe = tRecipe;
mOutputItems = tRecipe.getOutputs(RNGSUS, tMaxProcessCount);
mOutputFluids = tRecipe.getFluidOutputs(RNGSUS, tMaxProcessCount);
if (tRecipe.mEUt < 0) {
mOutputEnergy = -tRecipe.mEUt;
mMaxProgress = tRecipe.mDuration;
mMinEnergy = 0;
} else {
if (mParallelDuration) {
mMinEnergy = Math.max(1, (mEnergyTypeAccepted == TD.Energy.RF ? tRecipe.mEUt * RF_PER_EU : mEnergyTypeAccepted == TD.Energy.TU ? tRecipe.mEUt : tRecipe.mEUt));
mMaxProgress = Math.max(1, UT.Code.units(mMinEnergy * Math.max(1, tRecipe.mDuration) * tMaxProcessCount, mEfficiency, 10000, T));
} else {
mMinEnergy = Math.max(1, (mEnergyTypeAccepted == TD.Energy.RF ? tRecipe.mEUt * RF_PER_EU * tMaxProcessCount : mEnergyTypeAccepted == TD.Energy.TU ? tRecipe.mEUt : tRecipe.mEUt * tMaxProcessCount));
mMaxProgress = Math.max(1, UT.Code.units(mMinEnergy * Math.max(1, tRecipe.mDuration), mEfficiency, 10000, T));
}
if (mMinEnergy > 0 && !mCheapOverclocking)
while (mMinEnergy < mInputMin && mMinEnergy * 4 <= mInputMax) {
mMinEnergy *= 4;
mMaxProgress *= 2;
}
}
removeAllDroppableNullStacks();
return FOUND_AND_SUCCESSFULLY_USED_RECIPE;
}
Aggregations