Search in sources :

Example 1 with IAlloyFurnaceRecipe

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);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Refs(com.bluepowermod.reference.Refs) ContainerBlulectricAlloyFurnace(com.bluepowermod.container.ContainerBlulectricAlloyFurnace) Container(net.minecraft.inventory.container.Container) INamedContainerProvider(net.minecraft.inventory.container.INamedContainerProvider) CompoundNBT(net.minecraft.nbt.CompoundNBT) CapabilityBlutricity(com.bluepowermod.api.power.CapabilityBlutricity) AlloyFurnaceRegistry(com.bluepowermod.recipe.AlloyFurnaceRegistry) Direction(net.minecraft.util.Direction) ITextComponent(net.minecraft.util.text.ITextComponent) LazyOptional(net.minecraftforge.common.util.LazyOptional) ItemStack(net.minecraft.item.ItemStack) IAlloyFurnaceRecipe(com.bluepowermod.api.recipe.IAlloyFurnaceRecipe) StringTextComponent(net.minecraft.util.text.StringTextComponent) BPTileEntityType(com.bluepowermod.tile.BPTileEntityType) NonNullList(net.minecraft.util.NonNullList) BlockBlulectricAlloyFurnace(com.bluepowermod.block.power.BlockBlulectricAlloyFurnace) BlockState(net.minecraft.block.BlockState) Nonnull(javax.annotation.Nonnull) INBT(net.minecraft.nbt.INBT) Nullable(javax.annotation.Nullable) PlayerInventory(net.minecraft.entity.player.PlayerInventory) PlayerEntity(net.minecraft.entity.player.PlayerEntity) IPowerBase(com.bluepowermod.api.power.IPowerBase) IIntArray(net.minecraft.util.IIntArray) EnergyHelper(com.bluepowermod.helper.EnergyHelper) TileMachineBase(com.bluepowermod.tile.TileMachineBase) Capability(net.minecraftforge.common.capabilities.Capability) BlutricityStorage(com.bluepowermod.api.power.BlutricityStorage) ISidedInventory(net.minecraft.inventory.ISidedInventory) TileEntity(net.minecraft.tileentity.TileEntity) Direction(net.minecraft.util.Direction)

Aggregations

BlutricityStorage (com.bluepowermod.api.power.BlutricityStorage)1 CapabilityBlutricity (com.bluepowermod.api.power.CapabilityBlutricity)1 IPowerBase (com.bluepowermod.api.power.IPowerBase)1 IAlloyFurnaceRecipe (com.bluepowermod.api.recipe.IAlloyFurnaceRecipe)1 BlockBlulectricAlloyFurnace (com.bluepowermod.block.power.BlockBlulectricAlloyFurnace)1 ContainerBlulectricAlloyFurnace (com.bluepowermod.container.ContainerBlulectricAlloyFurnace)1 EnergyHelper (com.bluepowermod.helper.EnergyHelper)1 AlloyFurnaceRegistry (com.bluepowermod.recipe.AlloyFurnaceRegistry)1 Refs (com.bluepowermod.reference.Refs)1 BPTileEntityType (com.bluepowermod.tile.BPTileEntityType)1 TileMachineBase (com.bluepowermod.tile.TileMachineBase)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 BlockState (net.minecraft.block.BlockState)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 PlayerInventory (net.minecraft.entity.player.PlayerInventory)1 ISidedInventory (net.minecraft.inventory.ISidedInventory)1 Container (net.minecraft.inventory.container.Container)1 INamedContainerProvider (net.minecraft.inventory.container.INamedContainerProvider)1 ItemStack (net.minecraft.item.ItemStack)1