Search in sources :

Example 21 with Direction

use of net.minecraft.util.Direction 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)

Example 22 with Direction

use of net.minecraft.util.Direction in project BluePower by Qmunity.

the class TileBlulectricFurnace method tick.

@Override
public void 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(IRecipeType.SMELTING, this, this.level).isPresent()) {
                currentRecipe = this.level.getRecipeManager().getRecipeFor(IRecipeType.SMELTING, 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(this).getCount()) <= 64) || outputInventory.isEmpty())) {
                    currentProcessTime = 0;
                    if (!outputInventory.isEmpty()) {
                        outputInventory.setCount(outputInventory.getCount() + currentRecipe.assemble(this).getCount());
                    } else {
                        outputInventory = currentRecipe.assemble(this).copy();
                    }
                    this.removeItem(0, 1);
                    updatingRecipe = true;
                }
            } else {
                this.setIsActive(false);
            }
        } else {
            currentProcessTime = 0;
            this.setIsActive(false);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Refs(com.bluepowermod.reference.Refs) Container(net.minecraft.inventory.container.Container) INamedContainerProvider(net.minecraft.inventory.container.INamedContainerProvider) CompoundNBT(net.minecraft.nbt.CompoundNBT) CapabilityBlutricity(com.bluepowermod.api.power.CapabilityBlutricity) Direction(net.minecraft.util.Direction) IRecipeType(net.minecraft.item.crafting.IRecipeType) ITextComponent(net.minecraft.util.text.ITextComponent) LazyOptional(net.minecraftforge.common.util.LazyOptional) ContainerBlulectricFurnace(com.bluepowermod.container.ContainerBlulectricFurnace) ItemStack(net.minecraft.item.ItemStack) StringTextComponent(net.minecraft.util.text.StringTextComponent) BPTileEntityType(com.bluepowermod.tile.BPTileEntityType) NonNullList(net.minecraft.util.NonNullList) 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) FurnaceRecipe(net.minecraft.item.crafting.FurnaceRecipe) Capability(net.minecraftforge.common.capabilities.Capability) BlutricityStorage(com.bluepowermod.api.power.BlutricityStorage) ISidedInventory(net.minecraft.inventory.ISidedInventory) BlockBlulectricFurnace(com.bluepowermod.block.power.BlockBlulectricFurnace) TileEntity(net.minecraft.tileentity.TileEntity) Direction(net.minecraft.util.Direction)

Example 23 with Direction

use of net.minecraft.util.Direction in project BluePower by Qmunity.

the class TileWire method getCapability.

@Nonnull
@Override
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
    List<Direction> directions = new ArrayList<>(BlockBPCableBase.FACING.getPossibleValues());
    if (level != null) {
        BlockState state = getBlockState();
        if (state.getBlock() instanceof BlockAlloyWire) {
            // Remove upward connections
            directions.remove(state.getValue(BlockAlloyWire.FACING));
            // Make sure the cable is on the same side of the block
            directions.removeIf(d -> level.getBlockState(worldPosition.relative(d)).getBlock() instanceof BlockAlloyWire && level.getBlockState(worldPosition.relative(d)).getValue(BlockAlloyWire.FACING) != state.getValue(BlockAlloyWire.FACING));
        // Make sure the cable is the same color or none
        // if(device.getInsulationColor(null) != MinecraftColor.NONE)
        // directions.removeIf(d -> {
        // TileEntity tile = world.getBlockEntity(worldPosition.relative(d));
        // return tile instanceof TileWire
        // && !(((TileWire) tile).device.getInsulationColor(d) == device.getInsulationColor(d.getOpposite())
        // || ((TileWire) tile).device.getInsulationColor(d) == MinecraftColor.NONE);
        // });
        }
    }
    if (cap == CapabilityRedstoneDevice.UNINSULATED_CAPABILITY && (side == null || directions.contains(side))) {
        if (redstoneCap == null)
            redstoneCap = LazyOptional.of(() -> device);
        return redstoneCap.cast();
    }
    return LazyOptional.empty();
}
Also used : BlockState(net.minecraft.block.BlockState) ArrayList(java.util.ArrayList) BlockAlloyWire(com.bluepowermod.block.machine.BlockAlloyWire) Direction(net.minecraft.util.Direction) Nonnull(javax.annotation.Nonnull)

Example 24 with Direction

use of net.minecraft.util.Direction in project BluePower by Qmunity.

the class TileTransposer method pullItem.

protected void pullItem() {
    Direction dir = getOutputDirection().getOpposite();
    TileEntity inputTE = getTileCache(dir);
    ItemStack extractedStack = IOHelper.extractOneItem(inputTE, dir.getOpposite());
    if (!extractedStack.isEmpty())
        addItemToOutputBuffer(extractedStack);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ItemStack(net.minecraft.item.ItemStack) Direction(net.minecraft.util.Direction)

Example 25 with Direction

use of net.minecraft.util.Direction in project BluePower by Qmunity.

the class TileTransposer method redstoneChanged.

@Override
protected void redstoneChanged(boolean newValue) {
    super.redstoneChanged(newValue);
    Direction direction = getFacingDirection();
    if (!level.isClientSide && newValue) {
        if (level.isEmptyBlock(worldPosition.relative(direction))) {
            suckItems();
        } else {
            pullItem();
        }
    }
}
Also used : Direction(net.minecraft.util.Direction)

Aggregations

Direction (net.minecraft.util.Direction)50 BlockState (net.minecraft.block.BlockState)18 TileEntity (net.minecraft.tileentity.TileEntity)17 BlockPos (net.minecraft.util.math.BlockPos)15 ItemStack (net.minecraft.item.ItemStack)12 Block (net.minecraft.block.Block)10 Nonnull (javax.annotation.Nonnull)8 Nullable (javax.annotation.Nullable)8 CompoundNBT (net.minecraft.nbt.CompoundNBT)6 IPowerBase (com.bluepowermod.api.power.IPowerBase)5 PlayerEntity (net.minecraft.entity.player.PlayerEntity)5 World (net.minecraft.world.World)5 Capability (net.minecraftforge.common.capabilities.Capability)5 BlutricityStorage (com.bluepowermod.api.power.BlutricityStorage)4 CapabilityBlutricity (com.bluepowermod.api.power.CapabilityBlutricity)4 EnergyHelper (com.bluepowermod.helper.EnergyHelper)4 BPTileEntityType (com.bluepowermod.tile.BPTileEntityType)4 TileMachineBase (com.bluepowermod.tile.TileMachineBase)4 INBT (net.minecraft.nbt.INBT)4 LazyOptional (net.minecraftforge.common.util.LazyOptional)4