use of blusunrize.immersiveengineering.api.crafting.FermenterRecipe in project ImmersiveEngineering by BluSunrize.
the class Fermenter method addRecipe.
@ZenMethod
public static void addRecipe(IItemStack output, ILiquidStack fluid, IIngredient input, int energy) {
if (CraftTweakerHelper.toObject(input) == null)
return;
//Either output or fluid must not be null.
if (CraftTweakerHelper.toStack(output) == null && (CraftTweakerHelper.toFluidStack(fluid) == null || CraftTweakerHelper.toFluidStack(fluid).getFluid() == null))
return;
FermenterRecipe r = new FermenterRecipe(CraftTweakerHelper.toFluidStack(fluid), CraftTweakerHelper.toStack(output), CraftTweakerHelper.toObject(input), energy);
MineTweakerAPI.apply(new Add(r));
}
use of blusunrize.immersiveengineering.api.crafting.FermenterRecipe in project ImmersiveEngineering by BluSunrize.
the class TileEntityFermenter method update.
@Override
public void update() {
super.update();
if (isDummy() || isRSDisabled())
return;
if (!worldObj.isRemote) {
boolean update = false;
if (energyStorage.getEnergyStored() > 0 && processQueue.size() < this.getProcessQueueMaxLength()) {
final int[] usedInvSlots = new int[8];
for (MultiblockProcess process : processQueue) if (process instanceof MultiblockProcessInMachine)
for (int i : ((MultiblockProcessInMachine) process).inputSlots) usedInvSlots[i]++;
Integer[] preferredSlots = new Integer[] { 0, 1, 2, 3, 4, 5, 6, 7 };
Arrays.sort(preferredSlots, 0, 8, new Comparator<Integer>() {
@Override
public int compare(Integer arg0, Integer arg1) {
return Integer.compare(usedInvSlots[arg0], usedInvSlots[arg1]);
}
});
for (int slot : preferredSlots) {
ItemStack stack = this.getInventory()[slot];
if (stack != null) {
stack = stack.copy();
stack.stackSize -= usedInvSlots[slot];
}
if (stack != null && stack.stackSize > 0) {
FermenterRecipe recipe = this.findRecipeForInsertion(stack);
if (recipe != null) {
MultiblockProcessInMachine<FermenterRecipe> process = new MultiblockProcessInMachine(recipe, slot);
if (this.addProcessToQueue(process, true)) {
this.addProcessToQueue(process, false);
update = true;
}
}
}
}
}
EnumFacing fw = mirrored ? facing.rotateYCCW() : facing.rotateY();
if (this.tanks[0].getFluidAmount() > 0) {
FluidStack out = Utils.copyFluidStackWithAmount(this.tanks[0].getFluid(), Math.min(this.tanks[0].getFluidAmount(), 80), false);
BlockPos outputPos = this.getPos().add(0, -1, 0).offset(fw, 2);
IFluidHandler output = FluidUtil.getFluidHandler(worldObj, outputPos, fw.getOpposite());
if (output != null) {
int accepted = output.fill(out, false);
if (accepted > 0) {
int drained = output.fill(Utils.copyFluidStackWithAmount(out, Math.min(out.amount, accepted), false), true);
this.tanks[0].drain(drained, true);
update = true;
}
}
ItemStack empty = getInventory()[9];
if (empty != null && tanks[0].getFluidAmount() > 0) {
ItemStack full = Utils.fillFluidContainer(tanks[0], empty, getInventory()[10], null);
if (full != null) {
if (getInventory()[10] != null && OreDictionary.itemMatches(full, getInventory()[10], true))
getInventory()[10].stackSize += full.stackSize;
else
getInventory()[10] = full;
if (--inventory[9].stackSize <= 0)
inventory[9] = null;
}
}
}
if (inventory[8] != null && worldObj.getTotalWorldTime() % 8 == 0) {
BlockPos outputPos = this.getPos().offset(fw);
TileEntity outputTile = this.worldObj.getTileEntity(outputPos);
if (outputTile != null) {
ItemStack stack = Utils.copyStackWithAmount(inventory[8], 1);
stack = Utils.insertStackIntoInventory(outputTile, stack, fw.getOpposite());
if (stack == null)
if ((--this.inventory[8].stackSize) <= 0)
this.inventory[8] = null;
}
}
if (update) {
this.markDirty();
this.markContainingBlockForUpdate(null);
}
}
}
Aggregations