use of com.bluepowermod.api.recipe.IAlloyFurnaceRecipe in project BluePower by Qmunity.
the class TileBlulectricAlloyFurnace method tick.
/**
* Function gets called every tick. Do not forget to call the super method!
*/
@Override
public void tick() {
super.tick();
if (level != null && !level.isClientSide) {
storage.resetCurrent();
// Balance power of attached blulectric blocks.
for (Direction facing : Direction.values()) {
TileEntity tile = level.getBlockEntity(worldPosition.relative(facing));
if (tile != null)
tile.getCapability(CapabilityBlutricity.BLUTRICITY_CAPABILITY, facing.getOpposite()).ifPresent(exStorage -> EnergyHelper.balancePower(exStorage, storage));
}
if (updatingRecipe) {
if (this.level.getRecipeManager().getRecipeFor(AlloyFurnaceRegistry.ALLOYFURNACE_RECIPE, this, this.level).isPresent()) {
currentRecipe = (IAlloyFurnaceRecipe) this.level.getRecipeManager().getRecipeFor(AlloyFurnaceRegistry.ALLOYFURNACE_RECIPE, this, this.level).get();
} else {
currentRecipe = null;
}
updatingRecipe = false;
}
if (currentRecipe != null) {
if ((storage.getEnergy() / storage.getMaxEnergy()) > 0.5) {
storage.addEnergy(-1, false);
this.setIsActive(true);
// Check if progress completed, and output slot is empty and less then a stack of the same item.
if (++currentProcessTime >= (100 / (storage.getEnergy() / storage.getMaxEnergy())) && ((outputInventory.getItem() == currentRecipe.getResultItem().getItem() && (outputInventory.getCount() + currentRecipe.assemble(inventory, this.level.getRecipeManager()).getCount()) <= 64) || outputInventory.isEmpty())) {
currentProcessTime = 0;
if (!outputInventory.isEmpty()) {
outputInventory.setCount(outputInventory.getCount() + currentRecipe.assemble(inventory, this.level.getRecipeManager()).getCount());
} else {
outputInventory = currentRecipe.assemble(inventory, this.level.getRecipeManager()).copy();
}
currentRecipe.useItems(inventory, this.level.getRecipeManager());
updatingRecipe = true;
}
} else {
this.setIsActive(false);
}
} else {
currentProcessTime = 0;
this.setIsActive(false);
}
}
}
Aggregations