Search in sources :

Example 1 with OMEnergyStorage

use of omtteam.omlib.power.OMEnergyStorage in project OpenModularTurrets by OpenModularTurretsTeam.

the class LeverBlock method clOnBlockActivated.

@Override
protected boolean clOnBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (TurretHeadUtil.getTurretBaseFacing(worldIn, pos) == EnumFacing.DOWN || TurretHeadUtil.getTurretBaseFacing(worldIn, pos) == EnumFacing.UP) {
        return true;
    }
    TurretBase base = getTurretBase(worldIn, pos);
    LeverTileEntity lever = (LeverTileEntity) worldIn.getTileEntity(pos);
    OMEnergyStorage storage = (OMEnergyStorage) base.getCapability(CapabilityEnergy.ENERGY, EnumFacing.DOWN);
    if (storage == null) {
        return true;
    }
    if (lever != null && (worldIn.getBlockState(pos).getValue(ROTATION) * 90) == 0 && isBaseValid(worldIn.getTileEntity(new BlockPos(pos.getX(), pos.getY(), pos.getZ() + 1)))) {
        base = (TurretBase) worldIn.getTileEntity(new BlockPos(pos.getX(), pos.getY(), pos.getZ() + 1));
        if (base != null) {
            lever.isTurning = true;
            if (lever.rotation == 0F) {
                //worldIn.playSound(pos.getX(), pos.getY(), pos.getZ(), "omtteam.openmodularturrets:windup", 1.0F, 1.0F);
                storage.receiveEnergy(50, false);
            }
        }
    }
    if (lever != null && (worldIn.getBlockState(pos).getValue(ROTATION) * 90) == 90 && isBaseValid(worldIn.getTileEntity(new BlockPos(pos.getX() - 1, pos.getY(), pos.getZ())))) {
        base = (TurretBase) worldIn.getTileEntity(new BlockPos(pos.getX() - 1, pos.getY(), pos.getZ()));
        if (base != null) {
            lever.isTurning = true;
            if (lever.rotation == 0F) {
                //worldIn.playSoundEffect(pos.getX(), pos.getY(), pos.getZ(), "omtteam.openmodularturrets:windup", 1.0F, 1.0F);
                storage.receiveEnergy(50, false);
            }
        }
    }
    if (lever != null && (worldIn.getBlockState(pos).getValue(ROTATION) * 90) == 180 && isBaseValid(worldIn.getTileEntity(new BlockPos(pos.getX(), pos.getY(), pos.getZ() - 1)))) {
        base = (TurretBase) worldIn.getTileEntity(new BlockPos(pos.getX(), pos.getY(), pos.getZ() - 1));
        if (base != null) {
            lever.isTurning = true;
            if (lever.rotation == 0F) {
                //worldIn.playSoundEffect(pos.getX(), pos.getY(), pos.getZ(), "omtteam.openmodularturrets:windup", 1.0F, 1.0F);
                storage.receiveEnergy(50, false);
            }
        }
    }
    if (lever != null && (worldIn.getBlockState(pos).getValue(ROTATION) * 90) == 270 && isBaseValid(worldIn.getTileEntity(new BlockPos(pos.getX() + 1, pos.getY(), pos.getZ())))) {
        base = (TurretBase) worldIn.getTileEntity(new BlockPos(pos.getX() + 1, pos.getY(), pos.getZ()));
        if (base != null) {
            lever.isTurning = true;
            if (lever.rotation == 0F) {
                //worldIn.playSoundEffect(pos.getX(), pos.getY(), pos.getZ(), "omtteam.openmodularturrets:windup", 1.0F, 1.0F);
                storage.receiveEnergy(50, false);
            }
        }
    }
    return true;
}
Also used : LeverTileEntity(omtteam.openmodularturrets.tileentity.LeverTileEntity) TurretBase(omtteam.openmodularturrets.tileentity.TurretBase) TurretHeadUtil.getTurretBase(omtteam.openmodularturrets.util.TurretHeadUtil.getTurretBase) OMEnergyStorage(omtteam.omlib.power.OMEnergyStorage) BlockPos(net.minecraft.util.math.BlockPos)

Example 2 with OMEnergyStorage

use of omtteam.omlib.power.OMEnergyStorage in project OpenModularTurrets by OpenModularTurretsTeam.

the class TurretBase method updateRedstoneReactor.

private static void updateRedstoneReactor(TurretBase base) {
    OMEnergyStorage storage = (OMEnergyStorage) base.getCapability(CapabilityEnergy.ENERGY, EnumFacing.DOWN);
    if (!TurretHeadUtil.hasRedstoneReactor(base) || storage == null) {
        return;
    }
    if (ConfigHandler.getRedstoneReactorAddonGen() < (storage.getMaxEnergyStored() - storage.getEnergyStored())) {
        //Prioritise redstone blocks
        ItemStack redstoneBlock = TurretHeadUtil.getSpecificItemStackBlockFromBase(base, new ItemStack(Blocks.REDSTONE_BLOCK));
        if (redstoneBlock == ItemStackTools.getEmptyStack()) {
            redstoneBlock = TurretHeadUtil.getSpecificItemFromInvExpanders(base.getWorld(), new ItemStack(Blocks.REDSTONE_BLOCK), base);
        }
        if (redstoneBlock != ItemStackTools.getEmptyStack() && ConfigHandler.getRedstoneReactorAddonGen() * 9 < (storage.getMaxEnergyStored() - storage.getEnergyStored())) {
            base.storage.modifyEnergyStored(ConfigHandler.getRedstoneReactorAddonGen() * 9);
            return;
        }
        ItemStack redstone = TurretHeadUtil.getSpecificItemStackItemFromBase(base, new ItemStack(Items.REDSTONE));
        if (redstone == ItemStackTools.getEmptyStack()) {
            redstone = TurretHeadUtil.getSpecificItemFromInvExpanders(base.getWorld(), new ItemStack(Items.REDSTONE), base);
        }
        if (redstone != ItemStackTools.getEmptyStack()) {
            storage.modifyEnergyStored(ConfigHandler.getRedstoneReactorAddonGen());
        }
    }
}
Also used : OMEnergyStorage(omtteam.omlib.power.OMEnergyStorage) ItemStack(net.minecraft.item.ItemStack)

Aggregations

OMEnergyStorage (omtteam.omlib.power.OMEnergyStorage)2 ItemStack (net.minecraft.item.ItemStack)1 BlockPos (net.minecraft.util.math.BlockPos)1 LeverTileEntity (omtteam.openmodularturrets.tileentity.LeverTileEntity)1 TurretBase (omtteam.openmodularturrets.tileentity.TurretBase)1 TurretHeadUtil.getTurretBase (omtteam.openmodularturrets.util.TurretHeadUtil.getTurretBase)1